Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1 | /* |
| 2 | * S5P/EXYNOS4 SoC series camera host interface media device driver |
| 3 | * |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 4 | * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. |
| 5 | * Sylwester Nawrocki <s.nawrocki@samsung.com> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published |
| 9 | * by the Free Software Foundation, either version 2 of the License, |
| 10 | * or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/bug.h> |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/i2c.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/list.h> |
| 19 | #include <linux/module.h> |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 20 | #include <linux/of.h> |
| 21 | #include <linux/of_platform.h> |
| 22 | #include <linux/of_device.h> |
| 23 | #include <linux/of_i2c.h> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 24 | #include <linux/platform_device.h> |
| 25 | #include <linux/pm_runtime.h> |
| 26 | #include <linux/types.h> |
| 27 | #include <linux/slab.h> |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 28 | #include <media/v4l2-ctrls.h> |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 29 | #include <media/v4l2-of.h> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 30 | #include <media/media-device.h> |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 31 | #include <media/s5p_fimc.h> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 32 | |
Sylwester Nawrocki | 56fa1a6 | 2013-03-24 16:54:25 +0100 | [diff] [blame] | 33 | #include "media-dev.h" |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 34 | #include "fimc-core.h" |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 35 | #include "fimc-is.h" |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 36 | #include "fimc-lite.h" |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 37 | #include "mipi-csis.h" |
| 38 | |
| 39 | static int __fimc_md_set_camclk(struct fimc_md *fmd, |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 40 | struct fimc_source_info *si, |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 41 | bool on); |
| 42 | /** |
| 43 | * fimc_pipeline_prepare - update pipeline information with subdevice pointers |
Sylwester Nawrocki | 39bb6df6 | 2013-03-08 08:58:34 -0300 | [diff] [blame] | 44 | * @me: media entity terminating the pipeline |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 45 | * |
| 46 | * Caller holds the graph mutex. |
| 47 | */ |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 48 | static void fimc_pipeline_prepare(struct fimc_pipeline *p, |
| 49 | struct media_entity *me) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 50 | { |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 51 | struct v4l2_subdev *sd; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 52 | int i; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 53 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 54 | for (i = 0; i < IDX_MAX; i++) |
| 55 | p->subdevs[i] = NULL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 56 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 57 | while (1) { |
Sylwester Nawrocki | 39bb6df6 | 2013-03-08 08:58:34 -0300 | [diff] [blame] | 58 | struct media_pad *pad = NULL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 59 | |
Sylwester Nawrocki | 39bb6df6 | 2013-03-08 08:58:34 -0300 | [diff] [blame] | 60 | /* Find remote source pad */ |
| 61 | for (i = 0; i < me->num_pads; i++) { |
| 62 | struct media_pad *spad = &me->pads[i]; |
| 63 | if (!(spad->flags & MEDIA_PAD_FL_SINK)) |
| 64 | continue; |
| 65 | pad = media_entity_remote_source(spad); |
| 66 | if (pad) |
| 67 | break; |
| 68 | } |
| 69 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 70 | if (pad == NULL || |
| 71 | media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV) |
| 72 | break; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 73 | sd = media_entity_to_v4l2_subdev(pad->entity); |
| 74 | |
| 75 | switch (sd->grp_id) { |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 76 | case GRP_ID_FIMC_IS_SENSOR: |
| 77 | case GRP_ID_SENSOR: |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 78 | p->subdevs[IDX_SENSOR] = sd; |
| 79 | break; |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 80 | case GRP_ID_CSIS: |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 81 | p->subdevs[IDX_CSIS] = sd; |
| 82 | break; |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 83 | case GRP_ID_FLITE: |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 84 | p->subdevs[IDX_FLITE] = sd; |
| 85 | break; |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 86 | case GRP_ID_FIMC: |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 87 | /* No need to control FIMC subdev through subdev ops */ |
| 88 | break; |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 89 | case GRP_ID_FIMC_IS: |
| 90 | p->subdevs[IDX_IS_ISP] = sd; |
| 91 | break; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 92 | default: |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 93 | break; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 94 | } |
Sylwester Nawrocki | 39bb6df6 | 2013-03-08 08:58:34 -0300 | [diff] [blame] | 95 | me = &sd->entity; |
| 96 | if (me->num_pads == 1) |
| 97 | break; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * __subdev_set_power - change power state of a single subdev |
| 103 | * @sd: subdevice to change power state for |
| 104 | * @on: 1 to enable power or 0 to disable |
| 105 | * |
| 106 | * Return result of s_power subdev operation or -ENXIO if sd argument |
| 107 | * is NULL. Return 0 if the subdevice does not implement s_power. |
| 108 | */ |
| 109 | static int __subdev_set_power(struct v4l2_subdev *sd, int on) |
| 110 | { |
| 111 | int *use_count; |
| 112 | int ret; |
| 113 | |
| 114 | if (sd == NULL) |
| 115 | return -ENXIO; |
| 116 | |
| 117 | use_count = &sd->entity.use_count; |
| 118 | if (on && (*use_count)++ > 0) |
| 119 | return 0; |
| 120 | else if (!on && (*use_count == 0 || --(*use_count) > 0)) |
| 121 | return 0; |
| 122 | ret = v4l2_subdev_call(sd, core, s_power, on); |
| 123 | |
| 124 | return ret != -ENOIOCTLCMD ? ret : 0; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * fimc_pipeline_s_power - change power state of all pipeline subdevs |
| 129 | * @fimc: fimc device terminating the pipeline |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 130 | * @state: true to power on, false to power off |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 131 | * |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 132 | * Needs to be called with the graph mutex held. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 133 | */ |
Sylwester Nawrocki | f8bca4f | 2012-11-20 08:54:22 -0300 | [diff] [blame] | 134 | static int fimc_pipeline_s_power(struct fimc_pipeline *p, bool on) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 135 | { |
Sylwester Nawrocki | f8bca4f | 2012-11-20 08:54:22 -0300 | [diff] [blame] | 136 | static const u8 seq[2][IDX_MAX - 1] = { |
| 137 | { IDX_IS_ISP, IDX_SENSOR, IDX_CSIS, IDX_FLITE }, |
| 138 | { IDX_CSIS, IDX_FLITE, IDX_SENSOR, IDX_IS_ISP }, |
| 139 | }; |
| 140 | int i, ret = 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 141 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 142 | if (p->subdevs[IDX_SENSOR] == NULL) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 143 | return -ENXIO; |
| 144 | |
Sylwester Nawrocki | f8bca4f | 2012-11-20 08:54:22 -0300 | [diff] [blame] | 145 | for (i = 0; i < IDX_MAX - 1; i++) { |
| 146 | unsigned int idx = seq[on][i]; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 147 | |
Sylwester Nawrocki | f8bca4f | 2012-11-20 08:54:22 -0300 | [diff] [blame] | 148 | ret = __subdev_set_power(p->subdevs[idx], on); |
| 149 | |
| 150 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 151 | if (ret < 0 && ret != -ENXIO) |
Sylwester Nawrocki | f8bca4f | 2012-11-20 08:54:22 -0300 | [diff] [blame] | 152 | goto error; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 153 | } |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 154 | return 0; |
Sylwester Nawrocki | f8bca4f | 2012-11-20 08:54:22 -0300 | [diff] [blame] | 155 | error: |
| 156 | for (; i >= 0; i--) { |
| 157 | unsigned int idx = seq[on][i]; |
| 158 | __subdev_set_power(p->subdevs[idx], !on); |
| 159 | } |
| 160 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /** |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 164 | * __fimc_pipeline_open - update the pipeline information, enable power |
| 165 | * of all pipeline subdevs and the sensor clock |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 166 | * @me: media entity to start graph walk with |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 167 | * @prepare: true to walk the current pipeline and acquire all subdevs |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 168 | * |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 169 | * Called with the graph mutex held. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 170 | */ |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 171 | static int __fimc_pipeline_open(struct fimc_pipeline *p, |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 172 | struct media_entity *me, bool prepare) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 173 | { |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 174 | struct fimc_md *fmd = entity_to_fimc_mdev(me); |
| 175 | struct v4l2_subdev *sd; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 176 | int ret; |
| 177 | |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 178 | if (WARN_ON(p == NULL || me == NULL)) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 179 | return -EINVAL; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 180 | |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 181 | if (prepare) |
| 182 | fimc_pipeline_prepare(p, me); |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 183 | |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 184 | sd = p->subdevs[IDX_SENSOR]; |
| 185 | if (sd == NULL) |
| 186 | return -EINVAL; |
| 187 | |
| 188 | /* Disable PXLASYNC clock if this pipeline includes FIMC-IS */ |
| 189 | if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP]) { |
| 190 | ret = clk_prepare_enable(fmd->wbclk[CLK_IDX_WB_B]); |
| 191 | if (ret < 0) |
| 192 | return ret; |
| 193 | } |
| 194 | ret = fimc_md_set_camclk(sd, true); |
| 195 | if (ret < 0) |
| 196 | goto err_wbclk; |
| 197 | |
| 198 | ret = fimc_pipeline_s_power(p, 1); |
| 199 | if (!ret) |
| 200 | return 0; |
| 201 | |
| 202 | fimc_md_set_camclk(sd, false); |
| 203 | |
| 204 | err_wbclk: |
| 205 | if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP]) |
| 206 | clk_disable_unprepare(fmd->wbclk[CLK_IDX_WB_B]); |
| 207 | |
| 208 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 209 | } |
| 210 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 211 | /** |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 212 | * __fimc_pipeline_close - disable the sensor clock and pipeline power |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 213 | * @fimc: fimc device terminating the pipeline |
| 214 | * |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 215 | * Disable power of all subdevs and turn the external sensor clock off. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 216 | */ |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 217 | static int __fimc_pipeline_close(struct fimc_pipeline *p) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 218 | { |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 219 | struct v4l2_subdev *sd = p ? p->subdevs[IDX_SENSOR] : NULL; |
| 220 | struct fimc_md *fmd; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 221 | int ret = 0; |
| 222 | |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 223 | if (WARN_ON(sd == NULL)) |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 224 | return -EINVAL; |
| 225 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 226 | if (p->subdevs[IDX_SENSOR]) { |
| 227 | ret = fimc_pipeline_s_power(p, 0); |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 228 | fimc_md_set_camclk(sd, false); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 229 | } |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 230 | |
| 231 | fmd = entity_to_fimc_mdev(&sd->entity); |
| 232 | |
| 233 | /* Disable PXLASYNC clock if this pipeline includes FIMC-IS */ |
| 234 | if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP]) |
| 235 | clk_disable_unprepare(fmd->wbclk[CLK_IDX_WB_B]); |
| 236 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 237 | return ret == -ENXIO ? 0 : ret; |
| 238 | } |
| 239 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 240 | /** |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 241 | * __fimc_pipeline_s_stream - call s_stream() on pipeline subdevs |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 242 | * @pipeline: video pipeline structure |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 243 | * @on: passed as the s_stream() callback argument |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 244 | */ |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 245 | static int __fimc_pipeline_s_stream(struct fimc_pipeline *p, bool on) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 246 | { |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 247 | static const u8 seq[2][IDX_MAX] = { |
| 248 | { IDX_FIMC, IDX_SENSOR, IDX_IS_ISP, IDX_CSIS, IDX_FLITE }, |
| 249 | { IDX_CSIS, IDX_FLITE, IDX_FIMC, IDX_SENSOR, IDX_IS_ISP }, |
| 250 | }; |
| 251 | int i, ret = 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 252 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 253 | if (p->subdevs[IDX_SENSOR] == NULL) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 254 | return -ENODEV; |
| 255 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 256 | for (i = 0; i < IDX_MAX; i++) { |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 257 | unsigned int idx = seq[on][i]; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 258 | |
| 259 | ret = v4l2_subdev_call(p->subdevs[idx], video, s_stream, on); |
| 260 | |
| 261 | if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 262 | goto error; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 263 | } |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 264 | return 0; |
Sylwester Nawrocki | 8d274e7 | 2012-11-13 14:35:22 -0300 | [diff] [blame] | 265 | error: |
| 266 | for (; i >= 0; i--) { |
| 267 | unsigned int idx = seq[on][i]; |
| 268 | v4l2_subdev_call(p->subdevs[idx], video, s_stream, !on); |
| 269 | } |
| 270 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 271 | } |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 272 | |
| 273 | /* Media pipeline operations for the FIMC/FIMC-LITE video device driver */ |
| 274 | static const struct fimc_pipeline_ops fimc_pipeline_ops = { |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 275 | .open = __fimc_pipeline_open, |
| 276 | .close = __fimc_pipeline_close, |
| 277 | .set_stream = __fimc_pipeline_s_stream, |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 278 | }; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 279 | |
| 280 | /* |
| 281 | * Sensor subdevice helper functions |
| 282 | */ |
| 283 | static struct v4l2_subdev *fimc_md_register_sensor(struct fimc_md *fmd, |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 284 | struct fimc_source_info *si) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 285 | { |
| 286 | struct i2c_adapter *adapter; |
| 287 | struct v4l2_subdev *sd = NULL; |
| 288 | |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 289 | if (!si || !fmd) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 290 | return NULL; |
Sylwester Nawrocki | 88fa831 | 2013-03-20 10:44:39 -0300 | [diff] [blame] | 291 | /* |
| 292 | * If FIMC bus type is not Writeback FIFO assume it is same |
| 293 | * as sensor_bus_type. |
| 294 | */ |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 295 | si->fimc_bus_type = si->sensor_bus_type; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 296 | |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 297 | adapter = i2c_get_adapter(si->i2c_bus_num); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 298 | if (!adapter) { |
| 299 | v4l2_warn(&fmd->v4l2_dev, |
| 300 | "Failed to get I2C adapter %d, deferring probe\n", |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 301 | si->i2c_bus_num); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 302 | return ERR_PTR(-EPROBE_DEFER); |
| 303 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 304 | sd = v4l2_i2c_new_subdev_board(&fmd->v4l2_dev, adapter, |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 305 | si->board_info, NULL); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 306 | if (IS_ERR_OR_NULL(sd)) { |
Sylwester Nawrocki | 7acde02 | 2011-09-13 14:07:09 -0300 | [diff] [blame] | 307 | i2c_put_adapter(adapter); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 308 | v4l2_warn(&fmd->v4l2_dev, |
| 309 | "Failed to acquire subdev %s, deferring probe\n", |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 310 | si->board_info->type); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 311 | return ERR_PTR(-EPROBE_DEFER); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 312 | } |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 313 | v4l2_set_subdev_hostdata(sd, si); |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 314 | sd->grp_id = GRP_ID_SENSOR; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 315 | |
| 316 | v4l2_info(&fmd->v4l2_dev, "Registered sensor subdevice %s\n", |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 317 | sd->name); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 318 | return sd; |
| 319 | } |
| 320 | |
| 321 | static void fimc_md_unregister_sensor(struct v4l2_subdev *sd) |
| 322 | { |
| 323 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Sylwester Nawrocki | 7acde02 | 2011-09-13 14:07:09 -0300 | [diff] [blame] | 324 | struct i2c_adapter *adapter; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 325 | |
| 326 | if (!client) |
| 327 | return; |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 328 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 329 | v4l2_device_unregister_subdev(sd); |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 330 | |
| 331 | if (!client->dev.of_node) { |
| 332 | adapter = client->adapter; |
| 333 | i2c_unregister_device(client); |
| 334 | if (adapter) |
| 335 | i2c_put_adapter(adapter); |
| 336 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 337 | } |
| 338 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 339 | #ifdef CONFIG_OF |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 340 | /* Register I2C client subdev associated with @node. */ |
| 341 | static int fimc_md_of_add_sensor(struct fimc_md *fmd, |
| 342 | struct device_node *node, int index) |
| 343 | { |
| 344 | struct fimc_sensor_info *si; |
| 345 | struct i2c_client *client; |
| 346 | struct v4l2_subdev *sd; |
| 347 | int ret; |
| 348 | |
| 349 | if (WARN_ON(index >= ARRAY_SIZE(fmd->sensor))) |
| 350 | return -EINVAL; |
| 351 | si = &fmd->sensor[index]; |
| 352 | |
| 353 | client = of_find_i2c_device_by_node(node); |
| 354 | if (!client) |
| 355 | return -EPROBE_DEFER; |
| 356 | |
| 357 | device_lock(&client->dev); |
| 358 | |
| 359 | if (!client->driver || |
| 360 | !try_module_get(client->driver->driver.owner)) { |
| 361 | ret = -EPROBE_DEFER; |
| 362 | v4l2_info(&fmd->v4l2_dev, "No driver found for %s\n", |
| 363 | node->full_name); |
| 364 | goto dev_put; |
| 365 | } |
| 366 | |
| 367 | /* Enable sensor's master clock */ |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 368 | ret = __fimc_md_set_camclk(fmd, &si->pdata, true); |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 369 | if (ret < 0) |
| 370 | goto mod_put; |
| 371 | sd = i2c_get_clientdata(client); |
| 372 | |
| 373 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 374 | __fimc_md_set_camclk(fmd, &si->pdata, false); |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 375 | if (ret < 0) |
| 376 | goto mod_put; |
| 377 | |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 378 | v4l2_set_subdev_hostdata(sd, &si->pdata); |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 379 | if (si->pdata.fimc_bus_type == FIMC_BUS_TYPE_ISP_WRITEBACK) |
| 380 | sd->grp_id = GRP_ID_FIMC_IS_SENSOR; |
| 381 | else |
| 382 | sd->grp_id = GRP_ID_SENSOR; |
| 383 | |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 384 | si->subdev = sd; |
| 385 | v4l2_info(&fmd->v4l2_dev, "Registered sensor subdevice: %s (%d)\n", |
| 386 | sd->name, fmd->num_sensors); |
| 387 | fmd->num_sensors++; |
| 388 | |
| 389 | mod_put: |
| 390 | module_put(client->driver->driver.owner); |
| 391 | dev_put: |
| 392 | device_unlock(&client->dev); |
| 393 | put_device(&client->dev); |
| 394 | return ret; |
| 395 | } |
| 396 | |
| 397 | /* Parse port node and register as a sub-device any sensor specified there. */ |
| 398 | static int fimc_md_parse_port_node(struct fimc_md *fmd, |
| 399 | struct device_node *port, |
| 400 | unsigned int index) |
| 401 | { |
| 402 | struct device_node *rem, *ep, *np; |
| 403 | struct fimc_source_info *pd; |
| 404 | struct v4l2_of_endpoint endpoint; |
| 405 | int ret; |
| 406 | u32 val; |
| 407 | |
| 408 | pd = &fmd->sensor[index].pdata; |
| 409 | |
| 410 | /* Assume here a port node can have only one endpoint node. */ |
| 411 | ep = of_get_next_child(port, NULL); |
| 412 | if (!ep) |
| 413 | return 0; |
| 414 | |
| 415 | v4l2_of_parse_endpoint(ep, &endpoint); |
| 416 | if (WARN_ON(endpoint.port == 0) || index >= FIMC_MAX_SENSORS) |
| 417 | return -EINVAL; |
| 418 | |
| 419 | pd->mux_id = (endpoint.port - 1) & 0x1; |
| 420 | |
| 421 | rem = v4l2_of_get_remote_port_parent(ep); |
| 422 | of_node_put(ep); |
| 423 | if (rem == NULL) { |
| 424 | v4l2_info(&fmd->v4l2_dev, "Remote device at %s not found\n", |
| 425 | ep->full_name); |
| 426 | return 0; |
| 427 | } |
| 428 | if (!of_property_read_u32(rem, "samsung,camclk-out", &val)) |
| 429 | pd->clk_id = val; |
| 430 | |
| 431 | if (!of_property_read_u32(rem, "clock-frequency", &val)) |
| 432 | pd->clk_frequency = val; |
| 433 | |
| 434 | if (pd->clk_frequency == 0) { |
| 435 | v4l2_err(&fmd->v4l2_dev, "Wrong clock frequency at node %s\n", |
| 436 | rem->full_name); |
| 437 | of_node_put(rem); |
| 438 | return -EINVAL; |
| 439 | } |
| 440 | |
| 441 | if (fimc_input_is_parallel(endpoint.port)) { |
| 442 | if (endpoint.bus_type == V4L2_MBUS_PARALLEL) |
| 443 | pd->sensor_bus_type = FIMC_BUS_TYPE_ITU_601; |
| 444 | else |
| 445 | pd->sensor_bus_type = FIMC_BUS_TYPE_ITU_656; |
| 446 | pd->flags = endpoint.bus.parallel.flags; |
| 447 | } else if (fimc_input_is_mipi_csi(endpoint.port)) { |
| 448 | /* |
| 449 | * MIPI CSI-2: only input mux selection and |
| 450 | * the sensor's clock frequency is needed. |
| 451 | */ |
| 452 | pd->sensor_bus_type = FIMC_BUS_TYPE_MIPI_CSI2; |
| 453 | } else { |
| 454 | v4l2_err(&fmd->v4l2_dev, "Wrong port id (%u) at node %s\n", |
| 455 | endpoint.port, rem->full_name); |
| 456 | } |
| 457 | /* |
| 458 | * For FIMC-IS handled sensors, that are placed under i2c-isp device |
| 459 | * node, FIMC is connected to the FIMC-IS through its ISP Writeback |
| 460 | * input. Sensors are attached to the FIMC-LITE hostdata interface |
| 461 | * directly or through MIPI-CSIS, depending on the external media bus |
| 462 | * used. This needs to be handled in a more reliable way, not by just |
| 463 | * checking parent's node name. |
| 464 | */ |
| 465 | np = of_get_parent(rem); |
| 466 | |
| 467 | if (np && !of_node_cmp(np->name, "i2c-isp")) |
| 468 | pd->fimc_bus_type = FIMC_BUS_TYPE_ISP_WRITEBACK; |
| 469 | else |
| 470 | pd->fimc_bus_type = pd->sensor_bus_type; |
| 471 | |
| 472 | ret = fimc_md_of_add_sensor(fmd, rem, index); |
| 473 | of_node_put(rem); |
| 474 | |
| 475 | return ret; |
| 476 | } |
| 477 | |
| 478 | /* Register all SoC external sub-devices */ |
| 479 | static int fimc_md_of_sensors_register(struct fimc_md *fmd, |
| 480 | struct device_node *np) |
| 481 | { |
| 482 | struct device_node *parent = fmd->pdev->dev.of_node; |
| 483 | struct device_node *node, *ports; |
| 484 | int index = 0; |
| 485 | int ret; |
| 486 | |
| 487 | /* Attach sensors linked to MIPI CSI-2 receivers */ |
| 488 | for_each_available_child_of_node(parent, node) { |
| 489 | struct device_node *port; |
| 490 | |
| 491 | if (of_node_cmp(node->name, "csis")) |
| 492 | continue; |
| 493 | /* The csis node can have only port subnode. */ |
| 494 | port = of_get_next_child(node, NULL); |
| 495 | if (!port) |
| 496 | continue; |
| 497 | |
| 498 | ret = fimc_md_parse_port_node(fmd, port, index); |
| 499 | if (ret < 0) |
| 500 | return ret; |
| 501 | index++; |
| 502 | } |
| 503 | |
| 504 | /* Attach sensors listed in the parallel-ports node */ |
| 505 | ports = of_get_child_by_name(parent, "parallel-ports"); |
| 506 | if (!ports) |
| 507 | return 0; |
| 508 | |
| 509 | for_each_child_of_node(ports, node) { |
| 510 | ret = fimc_md_parse_port_node(fmd, node, index); |
| 511 | if (ret < 0) |
| 512 | break; |
| 513 | index++; |
| 514 | } |
| 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 519 | static int __of_get_csis_id(struct device_node *np) |
| 520 | { |
| 521 | u32 reg = 0; |
| 522 | |
| 523 | np = of_get_child_by_name(np, "port"); |
| 524 | if (!np) |
| 525 | return -EINVAL; |
| 526 | of_property_read_u32(np, "reg", ®); |
| 527 | return reg - FIMC_INPUT_MIPI_CSI2_0; |
| 528 | } |
| 529 | #else |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 530 | #define fimc_md_of_sensors_register(fmd, np) (-ENOSYS) |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 531 | #define __of_get_csis_id(np) (-ENOSYS) |
| 532 | #endif |
| 533 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 534 | static int fimc_md_register_sensor_entities(struct fimc_md *fmd) |
| 535 | { |
| 536 | struct s5p_platform_fimc *pdata = fmd->pdev->dev.platform_data; |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 537 | struct device_node *of_node = fmd->pdev->dev.of_node; |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 538 | int num_clients = 0; |
| 539 | int ret, i; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 540 | |
| 541 | /* |
| 542 | * Runtime resume one of the FIMC entities to make sure |
| 543 | * the sclk_cam clocks are not globally disabled. |
| 544 | */ |
Sylwester Nawrocki | 3e20c34 | 2013-03-21 14:47:17 -0300 | [diff] [blame] | 545 | if (!fmd->pmf) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 546 | return -ENXIO; |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 547 | |
Sylwester Nawrocki | 3e20c34 | 2013-03-21 14:47:17 -0300 | [diff] [blame] | 548 | ret = pm_runtime_get_sync(fmd->pmf); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 549 | if (ret < 0) |
| 550 | return ret; |
| 551 | |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 552 | if (of_node) { |
| 553 | fmd->num_sensors = 0; |
| 554 | ret = fimc_md_of_sensors_register(fmd, of_node); |
| 555 | } else if (pdata) { |
| 556 | WARN_ON(pdata->num_clients > ARRAY_SIZE(fmd->sensor)); |
| 557 | num_clients = min_t(u32, pdata->num_clients, |
| 558 | ARRAY_SIZE(fmd->sensor)); |
| 559 | fmd->num_sensors = num_clients; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 560 | |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 561 | for (i = 0; i < num_clients; i++) { |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 562 | struct fimc_sensor_info *si = &fmd->sensor[i]; |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 563 | struct v4l2_subdev *sd; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 564 | |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 565 | si->pdata = pdata->source_info[i]; |
| 566 | ret = __fimc_md_set_camclk(fmd, &si->pdata, true); |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 567 | if (ret) |
| 568 | break; |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 569 | sd = fimc_md_register_sensor(fmd, &si->pdata); |
| 570 | ret = __fimc_md_set_camclk(fmd, &si->pdata, false); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 571 | |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 572 | if (IS_ERR(sd)) { |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 573 | si->subdev = NULL; |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 574 | ret = PTR_ERR(sd); |
| 575 | break; |
| 576 | } |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 577 | si->subdev = sd; |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 578 | if (ret) |
| 579 | break; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 580 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 581 | } |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 582 | |
Sylwester Nawrocki | 3e20c34 | 2013-03-21 14:47:17 -0300 | [diff] [blame] | 583 | pm_runtime_put(fmd->pmf); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 584 | return ret; |
| 585 | } |
| 586 | |
| 587 | /* |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 588 | * MIPI-CSIS, FIMC and FIMC-LITE platform devices registration. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 589 | */ |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 590 | |
| 591 | static int register_fimc_lite_entity(struct fimc_md *fmd, |
| 592 | struct fimc_lite *fimc_lite) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 593 | { |
Sachin Kamat | 8163ec0 | 2012-10-25 10:56:00 -0300 | [diff] [blame] | 594 | struct v4l2_subdev *sd; |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 595 | int ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 596 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 597 | if (WARN_ON(fimc_lite->index >= FIMC_LITE_MAX_DEVS || |
| 598 | fmd->fimc_lite[fimc_lite->index])) |
| 599 | return -EBUSY; |
| 600 | |
| 601 | sd = &fimc_lite->subdev; |
| 602 | sd->grp_id = GRP_ID_FLITE; |
| 603 | v4l2_set_subdev_hostdata(sd, (void *)&fimc_pipeline_ops); |
| 604 | |
| 605 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
| 606 | if (!ret) |
| 607 | fmd->fimc_lite[fimc_lite->index] = fimc_lite; |
| 608 | else |
| 609 | v4l2_err(&fmd->v4l2_dev, "Failed to register FIMC.LITE%d\n", |
| 610 | fimc_lite->index); |
| 611 | return ret; |
| 612 | } |
| 613 | |
| 614 | static int register_fimc_entity(struct fimc_md *fmd, struct fimc_dev *fimc) |
| 615 | { |
| 616 | struct v4l2_subdev *sd; |
| 617 | int ret; |
| 618 | |
| 619 | if (WARN_ON(fimc->id >= FIMC_MAX_DEVS || fmd->fimc[fimc->id])) |
| 620 | return -EBUSY; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 621 | |
Sachin Kamat | 8163ec0 | 2012-10-25 10:56:00 -0300 | [diff] [blame] | 622 | sd = &fimc->vid_cap.subdev; |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 623 | sd->grp_id = GRP_ID_FIMC; |
Sylwester Nawrocki | 97d66c4 | 2012-11-22 06:17:19 -0300 | [diff] [blame] | 624 | v4l2_set_subdev_hostdata(sd, (void *)&fimc_pipeline_ops); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 625 | |
| 626 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 627 | if (!ret) { |
Sylwester Nawrocki | 3e20c34 | 2013-03-21 14:47:17 -0300 | [diff] [blame] | 628 | if (!fmd->pmf && fimc->pdev) |
| 629 | fmd->pmf = &fimc->pdev->dev; |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 630 | fmd->fimc[fimc->id] = fimc; |
| 631 | fimc->vid_cap.user_subdev_api = fmd->user_subdev_api; |
| 632 | } else { |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 633 | v4l2_err(&fmd->v4l2_dev, "Failed to register FIMC.%d (%d)\n", |
| 634 | fimc->id, ret); |
| 635 | } |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 636 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 637 | } |
| 638 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 639 | static int register_csis_entity(struct fimc_md *fmd, |
| 640 | struct platform_device *pdev, |
| 641 | struct v4l2_subdev *sd) |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 642 | { |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 643 | struct device_node *node = pdev->dev.of_node; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 644 | int id, ret; |
| 645 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 646 | id = node ? __of_get_csis_id(node) : max(0, pdev->id); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 647 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 648 | if (WARN_ON(id < 0 || id >= CSIS_MAX_ENTITIES)) |
| 649 | return -ENOENT; |
| 650 | |
| 651 | if (WARN_ON(fmd->csis[id].sd)) |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 652 | return -EBUSY; |
| 653 | |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 654 | sd->grp_id = GRP_ID_CSIS; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 655 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 656 | if (!ret) |
| 657 | fmd->csis[id].sd = sd; |
| 658 | else |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 659 | v4l2_err(&fmd->v4l2_dev, |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 660 | "Failed to register MIPI-CSIS.%d (%d)\n", id, ret); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 661 | return ret; |
| 662 | } |
| 663 | |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 664 | static int register_fimc_is_entity(struct fimc_md *fmd, struct fimc_is *is) |
| 665 | { |
| 666 | struct v4l2_subdev *sd = &is->isp.subdev; |
| 667 | int ret; |
| 668 | |
| 669 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
| 670 | if (ret) { |
| 671 | v4l2_err(&fmd->v4l2_dev, |
| 672 | "Failed to register FIMC-ISP (%d)\n", ret); |
| 673 | return ret; |
| 674 | } |
| 675 | |
| 676 | fmd->fimc_is = is; |
| 677 | return 0; |
| 678 | } |
| 679 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 680 | static int fimc_md_register_platform_entity(struct fimc_md *fmd, |
| 681 | struct platform_device *pdev, |
| 682 | int plat_entity) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 683 | { |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 684 | struct device *dev = &pdev->dev; |
| 685 | int ret = -EPROBE_DEFER; |
| 686 | void *drvdata; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 687 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 688 | /* Lock to ensure dev->driver won't change. */ |
| 689 | device_lock(dev); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 690 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 691 | if (!dev->driver || !try_module_get(dev->driver->owner)) |
| 692 | goto dev_unlock; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 693 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 694 | drvdata = dev_get_drvdata(dev); |
| 695 | /* Some subdev didn't probe succesfully id drvdata is NULL */ |
| 696 | if (drvdata) { |
| 697 | switch (plat_entity) { |
| 698 | case IDX_FIMC: |
| 699 | ret = register_fimc_entity(fmd, drvdata); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 700 | break; |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 701 | case IDX_FLITE: |
| 702 | ret = register_fimc_lite_entity(fmd, drvdata); |
| 703 | break; |
| 704 | case IDX_CSIS: |
| 705 | ret = register_csis_entity(fmd, pdev, drvdata); |
| 706 | break; |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 707 | case IDX_IS_ISP: |
| 708 | ret = register_fimc_is_entity(fmd, drvdata); |
| 709 | break; |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 710 | default: |
| 711 | ret = -ENODEV; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 712 | } |
| 713 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 714 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 715 | module_put(dev->driver->owner); |
| 716 | dev_unlock: |
| 717 | device_unlock(dev); |
| 718 | if (ret == -EPROBE_DEFER) |
| 719 | dev_info(&fmd->pdev->dev, "deferring %s device registration\n", |
| 720 | dev_name(dev)); |
| 721 | else if (ret < 0) |
| 722 | dev_err(&fmd->pdev->dev, "%s device registration failed (%d)\n", |
| 723 | dev_name(dev), ret); |
| 724 | return ret; |
| 725 | } |
| 726 | |
| 727 | static int fimc_md_pdev_match(struct device *dev, void *data) |
| 728 | { |
| 729 | struct platform_device *pdev = to_platform_device(dev); |
| 730 | int plat_entity = -1; |
| 731 | int ret; |
| 732 | char *p; |
| 733 | |
| 734 | if (!get_device(dev)) |
| 735 | return -ENODEV; |
| 736 | |
| 737 | if (!strcmp(pdev->name, CSIS_DRIVER_NAME)) { |
| 738 | plat_entity = IDX_CSIS; |
| 739 | } else if (!strcmp(pdev->name, FIMC_LITE_DRV_NAME)) { |
| 740 | plat_entity = IDX_FLITE; |
| 741 | } else { |
| 742 | p = strstr(pdev->name, "fimc"); |
| 743 | if (p && *(p + 4) == 0) |
| 744 | plat_entity = IDX_FIMC; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 745 | } |
| 746 | |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 747 | if (plat_entity >= 0) |
| 748 | ret = fimc_md_register_platform_entity(data, pdev, |
| 749 | plat_entity); |
| 750 | put_device(dev); |
| 751 | return 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 752 | } |
| 753 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 754 | /* Register FIMC, FIMC-LITE and CSIS media entities */ |
| 755 | #ifdef CONFIG_OF |
| 756 | static int fimc_md_register_of_platform_entities(struct fimc_md *fmd, |
| 757 | struct device_node *parent) |
| 758 | { |
| 759 | struct device_node *node; |
| 760 | int ret = 0; |
| 761 | |
| 762 | for_each_available_child_of_node(parent, node) { |
| 763 | struct platform_device *pdev; |
| 764 | int plat_entity = -1; |
| 765 | |
| 766 | pdev = of_find_device_by_node(node); |
| 767 | if (!pdev) |
| 768 | continue; |
| 769 | |
| 770 | /* If driver of any entity isn't ready try all again later. */ |
| 771 | if (!strcmp(node->name, CSIS_OF_NODE_NAME)) |
| 772 | plat_entity = IDX_CSIS; |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 773 | else if (!strcmp(node->name, FIMC_IS_OF_NODE_NAME)) |
| 774 | plat_entity = IDX_IS_ISP; |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 775 | else if (!strcmp(node->name, FIMC_LITE_OF_NODE_NAME)) |
| 776 | plat_entity = IDX_FLITE; |
| 777 | else if (!strcmp(node->name, FIMC_OF_NODE_NAME) && |
| 778 | !of_property_read_bool(node, "samsung,lcd-wb")) |
| 779 | plat_entity = IDX_FIMC; |
| 780 | |
| 781 | if (plat_entity >= 0) |
| 782 | ret = fimc_md_register_platform_entity(fmd, pdev, |
| 783 | plat_entity); |
| 784 | put_device(&pdev->dev); |
| 785 | if (ret < 0) |
| 786 | break; |
| 787 | } |
| 788 | |
| 789 | return ret; |
| 790 | } |
| 791 | #else |
| 792 | #define fimc_md_register_of_platform_entities(fmd, node) (-ENOSYS) |
| 793 | #endif |
| 794 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 795 | static void fimc_md_unregister_entities(struct fimc_md *fmd) |
| 796 | { |
| 797 | int i; |
| 798 | |
| 799 | for (i = 0; i < FIMC_MAX_DEVS; i++) { |
| 800 | if (fmd->fimc[i] == NULL) |
| 801 | continue; |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 802 | v4l2_device_unregister_subdev(&fmd->fimc[i]->vid_cap.subdev); |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 803 | fmd->fimc[i]->pipeline_ops = NULL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 804 | fmd->fimc[i] = NULL; |
| 805 | } |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 806 | for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { |
| 807 | if (fmd->fimc_lite[i] == NULL) |
| 808 | continue; |
| 809 | v4l2_device_unregister_subdev(&fmd->fimc_lite[i]->subdev); |
Sylwester Nawrocki | 248ac36 | 2013-01-11 07:06:28 -0300 | [diff] [blame] | 810 | fmd->fimc_lite[i]->pipeline_ops = NULL; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 811 | fmd->fimc_lite[i] = NULL; |
| 812 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 813 | for (i = 0; i < CSIS_MAX_ENTITIES; i++) { |
| 814 | if (fmd->csis[i].sd == NULL) |
| 815 | continue; |
| 816 | v4l2_device_unregister_subdev(fmd->csis[i].sd); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 817 | module_put(fmd->csis[i].sd->owner); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 818 | fmd->csis[i].sd = NULL; |
| 819 | } |
| 820 | for (i = 0; i < fmd->num_sensors; i++) { |
| 821 | if (fmd->sensor[i].subdev == NULL) |
| 822 | continue; |
| 823 | fimc_md_unregister_sensor(fmd->sensor[i].subdev); |
| 824 | fmd->sensor[i].subdev = NULL; |
| 825 | } |
Sylwester Nawrocki | 7b43a6f | 2012-12-12 08:16:05 -0300 | [diff] [blame] | 826 | v4l2_info(&fmd->v4l2_dev, "Unregistered all entities\n"); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 827 | } |
| 828 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 829 | /** |
| 830 | * __fimc_md_create_fimc_links - create links to all FIMC entities |
| 831 | * @fmd: fimc media device |
| 832 | * @source: the source entity to create links to all fimc entities from |
| 833 | * @sensor: sensor subdev linked to FIMC[fimc_id] entity, may be null |
| 834 | * @pad: the source entity pad index |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 835 | * @link_mask: bitmask of the fimc devices for which link should be enabled |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 836 | */ |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 837 | static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd, |
| 838 | struct media_entity *source, |
| 839 | struct v4l2_subdev *sensor, |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 840 | int pad, int link_mask) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 841 | { |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 842 | struct fimc_source_info *si = NULL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 843 | struct media_entity *sink; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 844 | unsigned int flags = 0; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 845 | int i, ret = 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 846 | |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 847 | if (sensor) { |
| 848 | si = v4l2_get_subdev_hostdata(sensor); |
| 849 | /* Skip direct FIMC links in the logical FIMC-IS sensor path */ |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 850 | if (si && si->fimc_bus_type == FIMC_BUS_TYPE_ISP_WRITEBACK) |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 851 | ret = 1; |
| 852 | } |
| 853 | |
| 854 | for (i = 0; !ret && i < FIMC_MAX_DEVS; i++) { |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 855 | if (!fmd->fimc[i]) |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 856 | continue; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 857 | /* |
| 858 | * Some FIMC variants are not fitted with camera capture |
| 859 | * interface. Skip creating a link from sensor for those. |
| 860 | */ |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 861 | if (!fmd->fimc[i]->variant->has_cam_if) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 862 | continue; |
| 863 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 864 | flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 865 | |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 866 | sink = &fmd->fimc[i]->vid_cap.subdev.entity; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 867 | ret = media_entity_create_link(source, pad, sink, |
Sylwester Nawrocki | 88fa831 | 2013-03-20 10:44:39 -0300 | [diff] [blame] | 868 | FIMC_SD_PAD_SINK_CAM, flags); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 869 | if (ret) |
| 870 | return ret; |
| 871 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 872 | /* Notify FIMC capture subdev entity */ |
| 873 | ret = media_entity_call(sink, link_setup, &sink->pads[0], |
| 874 | &source->pads[pad], flags); |
| 875 | if (ret) |
| 876 | break; |
| 877 | |
Sylwester Nawrocki | 542fb08 | 2012-10-25 05:48:19 -0300 | [diff] [blame] | 878 | v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]\n", |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 879 | source->name, flags ? '=' : '-', sink->name); |
| 880 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 881 | if (flags == 0 || sensor == NULL) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 882 | continue; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 883 | |
| 884 | if (!WARN_ON(si == NULL)) { |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 885 | unsigned long irq_flags; |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 886 | struct fimc_sensor_info *inf = source_to_sensor_info(si); |
| 887 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 888 | spin_lock_irqsave(&fmd->slock, irq_flags); |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 889 | inf->host = fmd->fimc[i]; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 890 | spin_unlock_irqrestore(&fmd->slock, irq_flags); |
| 891 | } |
| 892 | } |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 893 | |
| 894 | for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { |
| 895 | if (!fmd->fimc_lite[i]) |
| 896 | continue; |
| 897 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 898 | sink = &fmd->fimc_lite[i]->subdev.entity; |
| 899 | ret = media_entity_create_link(source, pad, sink, |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 900 | FLITE_SD_PAD_SINK, 0); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 901 | if (ret) |
| 902 | return ret; |
| 903 | |
| 904 | /* Notify FIMC-LITE subdev entity */ |
| 905 | ret = media_entity_call(sink, link_setup, &sink->pads[0], |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 906 | &source->pads[pad], 0); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 907 | if (ret) |
| 908 | break; |
| 909 | |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 910 | v4l2_info(&fmd->v4l2_dev, "created link [%s] -> [%s]\n", |
| 911 | source->name, sink->name); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 912 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 913 | return 0; |
| 914 | } |
| 915 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 916 | /* Create links from FIMC-LITE source pads to other entities */ |
| 917 | static int __fimc_md_create_flite_source_links(struct fimc_md *fmd) |
| 918 | { |
| 919 | struct media_entity *source, *sink; |
Sylwester Nawrocki | a26860b | 2012-12-05 13:43:05 -0300 | [diff] [blame] | 920 | int i, ret = 0; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 921 | |
| 922 | for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { |
| 923 | struct fimc_lite *fimc = fmd->fimc_lite[i]; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 924 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 925 | if (fimc == NULL) |
| 926 | continue; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 927 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 928 | source = &fimc->subdev.entity; |
Sylwester Nawrocki | 1bcd704 | 2012-07-26 07:13:08 -0300 | [diff] [blame] | 929 | sink = &fimc->vfd.entity; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 930 | /* FIMC-LITE's subdev and video node */ |
Sylwester Nawrocki | 6319d6a | 2012-11-28 15:41:01 -0300 | [diff] [blame] | 931 | ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA, |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 932 | sink, 0, 0); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 933 | if (ret) |
| 934 | break; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 935 | /* Link from FIMC-LITE to IS-ISP subdev */ |
| 936 | sink = &fmd->fimc_is->isp.subdev.entity; |
| 937 | ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_ISP, |
| 938 | sink, 0, 0); |
| 939 | if (ret) |
| 940 | break; |
| 941 | } |
| 942 | |
| 943 | return ret; |
| 944 | } |
| 945 | |
| 946 | /* Create FIMC-IS links */ |
| 947 | static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd) |
| 948 | { |
| 949 | struct media_entity *source, *sink; |
| 950 | int i, ret; |
| 951 | |
| 952 | source = &fmd->fimc_is->isp.subdev.entity; |
| 953 | |
| 954 | for (i = 0; i < FIMC_MAX_DEVS; i++) { |
| 955 | if (fmd->fimc[i] == NULL) |
| 956 | continue; |
| 957 | |
| 958 | /* Link from IS-ISP subdev to FIMC */ |
| 959 | sink = &fmd->fimc[i]->vid_cap.subdev.entity; |
| 960 | ret = media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_FIFO, |
| 961 | sink, FIMC_SD_PAD_SINK_FIFO, 0); |
| 962 | if (ret) |
| 963 | return ret; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | return ret; |
| 967 | } |
| 968 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 969 | /** |
| 970 | * fimc_md_create_links - create default links between registered entities |
| 971 | * |
| 972 | * Parallel interface sensor entities are connected directly to FIMC capture |
| 973 | * entities. The sensors using MIPI CSIS bus are connected through immutable |
| 974 | * link with CSI receiver entity specified by mux_id. Any registered CSIS |
| 975 | * entity has a link to each registered FIMC capture entity. Enabled links |
| 976 | * are created by default between each subsequent registered sensor and |
| 977 | * subsequent FIMC capture entity. The number of default active links is |
| 978 | * determined by the number of available sensors or FIMC entities, |
| 979 | * whichever is less. |
| 980 | */ |
| 981 | static int fimc_md_create_links(struct fimc_md *fmd) |
| 982 | { |
Sylwester Nawrocki | a8697ec | 2012-12-05 13:40:04 -0300 | [diff] [blame] | 983 | struct v4l2_subdev *csi_sensors[CSIS_MAX_ENTITIES] = { NULL }; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 984 | struct v4l2_subdev *sensor, *csis; |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame] | 985 | struct fimc_source_info *pdata; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 986 | struct media_entity *source, *sink; |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 987 | int i, pad, fimc_id = 0, ret = 0; |
| 988 | u32 flags, link_mask = 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 989 | |
| 990 | for (i = 0; i < fmd->num_sensors; i++) { |
| 991 | if (fmd->sensor[i].subdev == NULL) |
| 992 | continue; |
| 993 | |
| 994 | sensor = fmd->sensor[i].subdev; |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 995 | pdata = v4l2_get_subdev_hostdata(sensor); |
| 996 | if (!pdata) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 997 | continue; |
| 998 | |
| 999 | source = NULL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1000 | |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame] | 1001 | switch (pdata->sensor_bus_type) { |
| 1002 | case FIMC_BUS_TYPE_MIPI_CSI2: |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1003 | if (WARN(pdata->mux_id >= CSIS_MAX_ENTITIES, |
| 1004 | "Wrong CSI channel id: %d\n", pdata->mux_id)) |
| 1005 | return -EINVAL; |
| 1006 | |
| 1007 | csis = fmd->csis[pdata->mux_id].sd; |
| 1008 | if (WARN(csis == NULL, |
| 1009 | "MIPI-CSI interface specified " |
| 1010 | "but s5p-csis module is not loaded!\n")) |
Sylwester Nawrocki | d12392e | 2011-10-20 05:15:59 -0300 | [diff] [blame] | 1011 | return -EINVAL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1012 | |
Andrzej Hajda | 1c9f5bd | 2012-11-22 12:13:27 -0300 | [diff] [blame] | 1013 | pad = sensor->entity.num_pads - 1; |
| 1014 | ret = media_entity_create_link(&sensor->entity, pad, |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1015 | &csis->entity, CSIS_PAD_SINK, |
| 1016 | MEDIA_LNK_FL_IMMUTABLE | |
| 1017 | MEDIA_LNK_FL_ENABLED); |
| 1018 | if (ret) |
| 1019 | return ret; |
| 1020 | |
Sylwester Nawrocki | 969e877 | 2012-12-07 16:40:08 -0300 | [diff] [blame] | 1021 | v4l2_info(&fmd->v4l2_dev, "created link [%s] => [%s]\n", |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1022 | sensor->entity.name, csis->entity.name); |
| 1023 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 1024 | source = NULL; |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 1025 | csi_sensors[pdata->mux_id] = sensor; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1026 | break; |
| 1027 | |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame] | 1028 | case FIMC_BUS_TYPE_ITU_601...FIMC_BUS_TYPE_ITU_656: |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1029 | source = &sensor->entity; |
| 1030 | pad = 0; |
| 1031 | break; |
| 1032 | |
| 1033 | default: |
| 1034 | v4l2_err(&fmd->v4l2_dev, "Wrong bus_type: %x\n", |
Sylwester Nawrocki | 56bc911 | 2013-02-01 15:00:40 -0300 | [diff] [blame] | 1035 | pdata->sensor_bus_type); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1036 | return -EINVAL; |
| 1037 | } |
| 1038 | if (source == NULL) |
| 1039 | continue; |
| 1040 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 1041 | link_mask = 1 << fimc_id++; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 1042 | ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor, |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 1043 | pad, link_mask); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1044 | } |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 1045 | |
Sylwester Nawrocki | a8697ec | 2012-12-05 13:40:04 -0300 | [diff] [blame] | 1046 | for (i = 0; i < CSIS_MAX_ENTITIES; i++) { |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 1047 | if (fmd->csis[i].sd == NULL) |
| 1048 | continue; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 1049 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 1050 | source = &fmd->csis[i].sd->entity; |
| 1051 | pad = CSIS_PAD_SOURCE; |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 1052 | sensor = csi_sensors[i]; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 1053 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 1054 | link_mask = 1 << fimc_id++; |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 1055 | ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor, |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 1056 | pad, link_mask); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 1057 | } |
| 1058 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 1059 | /* Create immutable links between each FIMC's subdev and video node */ |
| 1060 | flags = MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED; |
| 1061 | for (i = 0; i < FIMC_MAX_DEVS; i++) { |
| 1062 | if (!fmd->fimc[i]) |
| 1063 | continue; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 1064 | |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1065 | source = &fmd->fimc[i]->vid_cap.subdev.entity; |
Sylwester Nawrocki | 31d34d9 | 2012-07-26 07:15:42 -0300 | [diff] [blame] | 1066 | sink = &fmd->fimc[i]->vid_cap.vfd.entity; |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 1067 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 1068 | ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE, |
| 1069 | sink, 0, flags); |
| 1070 | if (ret) |
| 1071 | break; |
| 1072 | } |
| 1073 | |
Sylwester Nawrocki | f998bb7 | 2012-11-27 13:29:48 -0300 | [diff] [blame] | 1074 | ret = __fimc_md_create_flite_source_links(fmd); |
| 1075 | if (ret < 0) |
| 1076 | return ret; |
| 1077 | |
| 1078 | if (fmd->use_isp) |
| 1079 | ret = __fimc_md_create_fimc_is_links(fmd); |
| 1080 | |
| 1081 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | /* |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 1085 | * The peripheral sensor and CAM_BLK (PIXELASYNCMx) clocks management. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1086 | */ |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1087 | static void fimc_md_put_clocks(struct fimc_md *fmd) |
| 1088 | { |
| 1089 | int i = FIMC_MAX_CAMCLKS; |
| 1090 | |
| 1091 | while (--i >= 0) { |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1092 | if (IS_ERR(fmd->camclk[i].clock)) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1093 | continue; |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1094 | clk_unprepare(fmd->camclk[i].clock); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1095 | clk_put(fmd->camclk[i].clock); |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1096 | fmd->camclk[i].clock = ERR_PTR(-EINVAL); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1097 | } |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 1098 | |
| 1099 | /* Writeback (PIXELASYNCMx) clocks */ |
| 1100 | for (i = 0; i < FIMC_MAX_WBCLKS; i++) { |
| 1101 | if (IS_ERR(fmd->wbclk[i])) |
| 1102 | continue; |
| 1103 | clk_put(fmd->wbclk[i]); |
| 1104 | fmd->wbclk[i] = ERR_PTR(-EINVAL); |
| 1105 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1106 | } |
| 1107 | |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1108 | static int fimc_md_get_clocks(struct fimc_md *fmd) |
| 1109 | { |
| 1110 | struct device *dev = NULL; |
| 1111 | char clk_name[32]; |
| 1112 | struct clk *clock; |
| 1113 | int ret, i; |
| 1114 | |
| 1115 | for (i = 0; i < FIMC_MAX_CAMCLKS; i++) |
| 1116 | fmd->camclk[i].clock = ERR_PTR(-EINVAL); |
| 1117 | |
| 1118 | if (fmd->pdev->dev.of_node) |
| 1119 | dev = &fmd->pdev->dev; |
| 1120 | |
| 1121 | for (i = 0; i < FIMC_MAX_CAMCLKS; i++) { |
| 1122 | snprintf(clk_name, sizeof(clk_name), "sclk_cam%u", i); |
| 1123 | clock = clk_get(dev, clk_name); |
| 1124 | |
| 1125 | if (IS_ERR(clock)) { |
| 1126 | dev_err(&fmd->pdev->dev, "Failed to get clock: %s\n", |
| 1127 | clk_name); |
| 1128 | ret = PTR_ERR(clock); |
| 1129 | break; |
| 1130 | } |
| 1131 | ret = clk_prepare(clock); |
| 1132 | if (ret < 0) { |
| 1133 | clk_put(clock); |
| 1134 | fmd->camclk[i].clock = ERR_PTR(-EINVAL); |
| 1135 | break; |
| 1136 | } |
| 1137 | fmd->camclk[i].clock = clock; |
| 1138 | } |
| 1139 | if (ret) |
| 1140 | fimc_md_put_clocks(fmd); |
| 1141 | |
Sylwester Nawrocki | 056f4f3 | 2013-03-21 14:43:17 -0300 | [diff] [blame] | 1142 | if (!fmd->use_isp) |
| 1143 | return 0; |
| 1144 | /* |
| 1145 | * For now get only PIXELASYNCM1 clock (Writeback B/ISP), |
| 1146 | * leave PIXELASYNCM0 out for the LCD Writeback driver. |
| 1147 | */ |
| 1148 | fmd->wbclk[CLK_IDX_WB_A] = ERR_PTR(-EINVAL); |
| 1149 | |
| 1150 | for (i = CLK_IDX_WB_B; i < FIMC_MAX_WBCLKS; i++) { |
| 1151 | snprintf(clk_name, sizeof(clk_name), "pxl_async%u", i); |
| 1152 | clock = clk_get(dev, clk_name); |
| 1153 | if (IS_ERR(clock)) { |
| 1154 | v4l2_err(&fmd->v4l2_dev, "Failed to get clock: %s\n", |
| 1155 | clk_name); |
| 1156 | ret = PTR_ERR(clock); |
| 1157 | break; |
| 1158 | } |
| 1159 | fmd->wbclk[i] = clock; |
| 1160 | } |
| 1161 | if (ret) |
| 1162 | fimc_md_put_clocks(fmd); |
| 1163 | |
Sylwester Nawrocki | 0e23cbb | 2013-01-18 15:34:37 -0300 | [diff] [blame] | 1164 | return ret; |
| 1165 | } |
| 1166 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1167 | static int __fimc_md_set_camclk(struct fimc_md *fmd, |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 1168 | struct fimc_source_info *si, |
Sylwester Nawrocki | e3fc82e | 2012-05-17 14:22:10 -0300 | [diff] [blame] | 1169 | bool on) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1170 | { |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1171 | struct fimc_camclk_info *camclk; |
| 1172 | int ret = 0; |
| 1173 | |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 1174 | if (WARN_ON(si->clk_id >= FIMC_MAX_CAMCLKS) || !fmd || !fmd->pmf) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1175 | return -EINVAL; |
| 1176 | |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 1177 | camclk = &fmd->camclk[si->clk_id]; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1178 | |
Sylwester Nawrocki | e3fc82e | 2012-05-17 14:22:10 -0300 | [diff] [blame] | 1179 | dbg("camclk %d, f: %lu, use_count: %d, on: %d", |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 1180 | si->clk_id, si->clk_frequency, camclk->use_count, on); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1181 | |
| 1182 | if (on) { |
| 1183 | if (camclk->use_count > 0 && |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 1184 | camclk->frequency != si->clk_frequency) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1185 | return -EINVAL; |
| 1186 | |
| 1187 | if (camclk->use_count++ == 0) { |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 1188 | clk_set_rate(camclk->clock, si->clk_frequency); |
| 1189 | camclk->frequency = si->clk_frequency; |
Sylwester Nawrocki | 3e20c34 | 2013-03-21 14:47:17 -0300 | [diff] [blame] | 1190 | ret = pm_runtime_get_sync(fmd->pmf); |
| 1191 | if (ret < 0) |
| 1192 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1193 | ret = clk_enable(camclk->clock); |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 1194 | dbg("Enabled camclk %d: f: %lu", si->clk_id, |
Sylwester Nawrocki | e3fc82e | 2012-05-17 14:22:10 -0300 | [diff] [blame] | 1195 | clk_get_rate(camclk->clock)); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1196 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1197 | return ret; |
| 1198 | } |
| 1199 | |
| 1200 | if (WARN_ON(camclk->use_count == 0)) |
| 1201 | return 0; |
| 1202 | |
| 1203 | if (--camclk->use_count == 0) { |
| 1204 | clk_disable(camclk->clock); |
Sylwester Nawrocki | 3e20c34 | 2013-03-21 14:47:17 -0300 | [diff] [blame] | 1205 | pm_runtime_put(fmd->pmf); |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 1206 | dbg("Disabled camclk %d", si->clk_id); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1207 | } |
| 1208 | return ret; |
| 1209 | } |
| 1210 | |
| 1211 | /** |
| 1212 | * fimc_md_set_camclk - peripheral sensor clock setup |
| 1213 | * @sd: sensor subdev to configure sclk_cam clock for |
| 1214 | * @on: 1 to enable or 0 to disable the clock |
| 1215 | * |
| 1216 | * There are 2 separate clock outputs available in the SoC for external |
| 1217 | * image processors. These clocks are shared between all registered FIMC |
| 1218 | * devices to which sensors can be attached, either directly or through |
| 1219 | * the MIPI CSI receiver. The clock is allowed here to be used by |
| 1220 | * multiple sensors concurrently if they use same frequency. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1221 | * This function should only be called when the graph mutex is held. |
| 1222 | */ |
| 1223 | int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on) |
| 1224 | { |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 1225 | struct fimc_source_info *si = v4l2_get_subdev_hostdata(sd); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1226 | struct fimc_md *fmd = entity_to_fimc_mdev(&sd->entity); |
| 1227 | |
Sylwester Nawrocki | 4c8f062 | 2013-04-09 11:11:58 -0300 | [diff] [blame^] | 1228 | return __fimc_md_set_camclk(fmd, si, on); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | static int fimc_md_link_notify(struct media_pad *source, |
| 1232 | struct media_pad *sink, u32 flags) |
| 1233 | { |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 1234 | struct fimc_lite *fimc_lite = NULL; |
| 1235 | struct fimc_dev *fimc = NULL; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 1236 | struct fimc_pipeline *pipeline; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 1237 | struct v4l2_subdev *sd; |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 1238 | struct mutex *lock; |
Sylwester Nawrocki | 8c6ecdd | 2013-02-05 15:43:08 -0300 | [diff] [blame] | 1239 | int i, ret = 0; |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 1240 | int ref_count; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1241 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 1242 | if (media_entity_type(sink->entity) != MEDIA_ENT_T_V4L2_SUBDEV) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1243 | return 0; |
| 1244 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 1245 | sd = media_entity_to_v4l2_subdev(sink->entity); |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 1246 | |
| 1247 | switch (sd->grp_id) { |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 1248 | case GRP_ID_FLITE: |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 1249 | fimc_lite = v4l2_get_subdevdata(sd); |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 1250 | if (WARN_ON(fimc_lite == NULL)) |
| 1251 | return 0; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 1252 | pipeline = &fimc_lite->pipeline; |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 1253 | lock = &fimc_lite->lock; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 1254 | break; |
Sylwester Nawrocki | 588c87b | 2012-11-27 11:57:42 -0300 | [diff] [blame] | 1255 | case GRP_ID_FIMC: |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 1256 | fimc = v4l2_get_subdevdata(sd); |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 1257 | if (WARN_ON(fimc == NULL)) |
| 1258 | return 0; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 1259 | pipeline = &fimc->pipeline; |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 1260 | lock = &fimc->lock; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 1261 | break; |
| 1262 | default: |
| 1263 | return 0; |
| 1264 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1265 | |
Sylwester Nawrocki | 8c6ecdd | 2013-02-05 15:43:08 -0300 | [diff] [blame] | 1266 | mutex_lock(lock); |
| 1267 | ref_count = fimc ? fimc->vid_cap.refcnt : fimc_lite->ref_count; |
| 1268 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1269 | if (!(flags & MEDIA_LNK_FL_ENABLED)) { |
Sylwester Nawrocki | 8c6ecdd | 2013-02-05 15:43:08 -0300 | [diff] [blame] | 1270 | if (ref_count > 0) { |
| 1271 | ret = __fimc_pipeline_close(pipeline); |
| 1272 | if (!ret && fimc) |
| 1273 | fimc_ctrls_delete(fimc->vid_cap.ctx); |
| 1274 | } |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 1275 | for (i = 0; i < IDX_MAX; i++) |
| 1276 | pipeline->subdevs[i] = NULL; |
Sylwester Nawrocki | 8c6ecdd | 2013-02-05 15:43:08 -0300 | [diff] [blame] | 1277 | } else if (ref_count > 0) { |
| 1278 | /* |
| 1279 | * Link activation. Enable power of pipeline elements only if |
| 1280 | * the pipeline is already in use, i.e. its video node is open. |
| 1281 | * Recreate the controls destroyed during the link deactivation. |
| 1282 | */ |
| 1283 | ret = __fimc_pipeline_open(pipeline, |
| 1284 | source->entity, true); |
| 1285 | if (!ret && fimc) |
| 1286 | ret = fimc_capture_ctrls_create(fimc); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1287 | } |
Sylwester Nawrocki | 740ad92 | 2012-12-06 10:26:19 -0300 | [diff] [blame] | 1288 | |
| 1289 | mutex_unlock(lock); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1290 | return ret ? -EPIPE : ret; |
| 1291 | } |
| 1292 | |
| 1293 | static ssize_t fimc_md_sysfs_show(struct device *dev, |
| 1294 | struct device_attribute *attr, char *buf) |
| 1295 | { |
| 1296 | struct platform_device *pdev = to_platform_device(dev); |
| 1297 | struct fimc_md *fmd = platform_get_drvdata(pdev); |
| 1298 | |
| 1299 | if (fmd->user_subdev_api) |
| 1300 | return strlcpy(buf, "Sub-device API (sub-dev)\n", PAGE_SIZE); |
| 1301 | |
| 1302 | return strlcpy(buf, "V4L2 video node only API (vid-dev)\n", PAGE_SIZE); |
| 1303 | } |
| 1304 | |
| 1305 | static ssize_t fimc_md_sysfs_store(struct device *dev, |
| 1306 | struct device_attribute *attr, |
| 1307 | const char *buf, size_t count) |
| 1308 | { |
| 1309 | struct platform_device *pdev = to_platform_device(dev); |
| 1310 | struct fimc_md *fmd = platform_get_drvdata(pdev); |
| 1311 | bool subdev_api; |
| 1312 | int i; |
| 1313 | |
| 1314 | if (!strcmp(buf, "vid-dev\n")) |
| 1315 | subdev_api = false; |
| 1316 | else if (!strcmp(buf, "sub-dev\n")) |
| 1317 | subdev_api = true; |
| 1318 | else |
| 1319 | return count; |
| 1320 | |
| 1321 | fmd->user_subdev_api = subdev_api; |
| 1322 | for (i = 0; i < FIMC_MAX_DEVS; i++) |
| 1323 | if (fmd->fimc[i]) |
| 1324 | fmd->fimc[i]->vid_cap.user_subdev_api = subdev_api; |
| 1325 | return count; |
| 1326 | } |
| 1327 | /* |
| 1328 | * This device attribute is to select video pipeline configuration method. |
| 1329 | * There are following valid values: |
| 1330 | * vid-dev - for V4L2 video node API only, subdevice will be configured |
| 1331 | * by the host driver. |
| 1332 | * sub-dev - for media controller API, subdevs must be configured in user |
| 1333 | * space before starting streaming. |
| 1334 | */ |
| 1335 | static DEVICE_ATTR(subdev_conf_mode, S_IWUSR | S_IRUGO, |
| 1336 | fimc_md_sysfs_show, fimc_md_sysfs_store); |
| 1337 | |
Sylwester Nawrocki | 4163851 | 2013-03-08 10:41:47 -0300 | [diff] [blame] | 1338 | static int fimc_md_get_pinctrl(struct fimc_md *fmd) |
| 1339 | { |
| 1340 | struct device *dev = &fmd->pdev->dev; |
| 1341 | struct fimc_pinctrl *pctl = &fmd->pinctl; |
| 1342 | |
| 1343 | pctl->pinctrl = devm_pinctrl_get(dev); |
| 1344 | if (IS_ERR(pctl->pinctrl)) |
| 1345 | return PTR_ERR(pctl->pinctrl); |
| 1346 | |
| 1347 | pctl->state_default = pinctrl_lookup_state(pctl->pinctrl, |
| 1348 | PINCTRL_STATE_DEFAULT); |
| 1349 | if (IS_ERR(pctl->state_default)) |
| 1350 | return PTR_ERR(pctl->state_default); |
| 1351 | |
| 1352 | pctl->state_idle = pinctrl_lookup_state(pctl->pinctrl, |
| 1353 | PINCTRL_STATE_IDLE); |
| 1354 | return 0; |
| 1355 | } |
| 1356 | |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 1357 | static int fimc_md_probe(struct platform_device *pdev) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1358 | { |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1359 | struct device *dev = &pdev->dev; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1360 | struct v4l2_device *v4l2_dev; |
| 1361 | struct fimc_md *fmd; |
| 1362 | int ret; |
| 1363 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1364 | fmd = devm_kzalloc(dev, sizeof(*fmd), GFP_KERNEL); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1365 | if (!fmd) |
| 1366 | return -ENOMEM; |
| 1367 | |
| 1368 | spin_lock_init(&fmd->slock); |
| 1369 | fmd->pdev = pdev; |
| 1370 | |
| 1371 | strlcpy(fmd->media_dev.model, "SAMSUNG S5P FIMC", |
| 1372 | sizeof(fmd->media_dev.model)); |
| 1373 | fmd->media_dev.link_notify = fimc_md_link_notify; |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1374 | fmd->media_dev.dev = dev; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1375 | |
| 1376 | v4l2_dev = &fmd->v4l2_dev; |
| 1377 | v4l2_dev->mdev = &fmd->media_dev; |
Sylwester Nawrocki | e1d72f4 | 2011-06-10 15:36:58 -0300 | [diff] [blame] | 1378 | v4l2_dev->notify = fimc_sensor_notify; |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1379 | strlcpy(v4l2_dev->name, "s5p-fimc-md", sizeof(v4l2_dev->name)); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1380 | |
Sylwester Nawrocki | e781bbe3 | 2013-03-21 14:49:16 -0300 | [diff] [blame] | 1381 | fmd->use_isp = fimc_md_is_isp_available(dev->of_node); |
| 1382 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1383 | ret = v4l2_device_register(dev, &fmd->v4l2_dev); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1384 | if (ret < 0) { |
| 1385 | v4l2_err(v4l2_dev, "Failed to register v4l2_device: %d\n", ret); |
Sylwester Nawrocki | 6d91a51 | 2012-01-30 11:37:59 -0300 | [diff] [blame] | 1386 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1387 | } |
| 1388 | ret = media_device_register(&fmd->media_dev); |
| 1389 | if (ret < 0) { |
| 1390 | v4l2_err(v4l2_dev, "Failed to register media device: %d\n", ret); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1391 | goto err_md; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1392 | } |
| 1393 | ret = fimc_md_get_clocks(fmd); |
| 1394 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1395 | goto err_clk; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1396 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1397 | fmd->user_subdev_api = (dev->of_node != NULL); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1398 | |
| 1399 | /* Protect the media graph while we're registering entities */ |
| 1400 | mutex_lock(&fmd->media_dev.graph_mutex); |
| 1401 | |
Sylwester Nawrocki | 4163851 | 2013-03-08 10:41:47 -0300 | [diff] [blame] | 1402 | ret = fimc_md_get_pinctrl(fmd); |
| 1403 | if (ret < 0) { |
| 1404 | if (ret != EPROBE_DEFER) |
| 1405 | dev_err(dev, "Failed to get pinctrl: %d\n", ret); |
| 1406 | goto err_unlock; |
| 1407 | } |
| 1408 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1409 | if (dev->of_node) |
| 1410 | ret = fimc_md_register_of_platform_entities(fmd, dev->of_node); |
| 1411 | else |
| 1412 | ret = bus_for_each_dev(&platform_bus_type, NULL, fmd, |
| 1413 | fimc_md_pdev_match); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1414 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1415 | goto err_unlock; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1416 | |
Sylwester Nawrocki | 2b13f7d | 2013-03-29 14:12:39 -0300 | [diff] [blame] | 1417 | if (dev->platform_data || dev->of_node) { |
Sylwester Nawrocki | 5cbf6f16 | 2011-10-07 07:40:00 -0300 | [diff] [blame] | 1418 | ret = fimc_md_register_sensor_entities(fmd); |
| 1419 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1420 | goto err_unlock; |
Sylwester Nawrocki | 5cbf6f16 | 2011-10-07 07:40:00 -0300 | [diff] [blame] | 1421 | } |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1422 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1423 | ret = fimc_md_create_links(fmd); |
| 1424 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1425 | goto err_unlock; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1426 | ret = v4l2_device_register_subdev_nodes(&fmd->v4l2_dev); |
| 1427 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1428 | goto err_unlock; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1429 | |
| 1430 | ret = device_create_file(&pdev->dev, &dev_attr_subdev_conf_mode); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1431 | if (ret) |
| 1432 | goto err_unlock; |
| 1433 | |
| 1434 | platform_set_drvdata(pdev, fmd); |
| 1435 | mutex_unlock(&fmd->media_dev.graph_mutex); |
| 1436 | return 0; |
| 1437 | |
| 1438 | err_unlock: |
| 1439 | mutex_unlock(&fmd->media_dev.graph_mutex); |
| 1440 | err_clk: |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1441 | media_device_unregister(&fmd->media_dev); |
| 1442 | fimc_md_put_clocks(fmd); |
| 1443 | fimc_md_unregister_entities(fmd); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1444 | err_md: |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1445 | v4l2_device_unregister(&fmd->v4l2_dev); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1446 | return ret; |
| 1447 | } |
| 1448 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1449 | static int fimc_md_remove(struct platform_device *pdev) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1450 | { |
| 1451 | struct fimc_md *fmd = platform_get_drvdata(pdev); |
| 1452 | |
| 1453 | if (!fmd) |
| 1454 | return 0; |
| 1455 | device_remove_file(&pdev->dev, &dev_attr_subdev_conf_mode); |
| 1456 | fimc_md_unregister_entities(fmd); |
| 1457 | media_device_unregister(&fmd->media_dev); |
| 1458 | fimc_md_put_clocks(fmd); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1459 | return 0; |
| 1460 | } |
| 1461 | |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1462 | static struct platform_device_id fimc_driver_ids[] __always_unused = { |
| 1463 | { .name = "s5p-fimc-md" }, |
| 1464 | { }, |
| 1465 | }; |
| 1466 | MODULE_DEVICE_TABLE(platform, fimc_driver_ids); |
| 1467 | |
| 1468 | static const struct of_device_id fimc_md_of_match[] = { |
| 1469 | { .compatible = "samsung,fimc" }, |
| 1470 | { }, |
| 1471 | }; |
| 1472 | MODULE_DEVICE_TABLE(of, fimc_md_of_match); |
| 1473 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1474 | static struct platform_driver fimc_md_driver = { |
| 1475 | .probe = fimc_md_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1476 | .remove = fimc_md_remove, |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1477 | .driver = { |
Sylwester Nawrocki | e2985a2 | 2013-03-08 12:59:33 -0300 | [diff] [blame] | 1478 | .of_match_table = of_match_ptr(fimc_md_of_match), |
| 1479 | .name = "s5p-fimc-md", |
| 1480 | .owner = THIS_MODULE, |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1481 | } |
| 1482 | }; |
| 1483 | |
Sachin Kamat | 7e566be | 2012-05-26 11:11:54 -0300 | [diff] [blame] | 1484 | static int __init fimc_md_init(void) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1485 | { |
| 1486 | int ret; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 1487 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1488 | request_module("s5p-csis"); |
| 1489 | ret = fimc_register_driver(); |
| 1490 | if (ret) |
| 1491 | return ret; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 1492 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1493 | return platform_driver_register(&fimc_md_driver); |
| 1494 | } |
Sachin Kamat | 7e566be | 2012-05-26 11:11:54 -0300 | [diff] [blame] | 1495 | |
| 1496 | static void __exit fimc_md_exit(void) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1497 | { |
| 1498 | platform_driver_unregister(&fimc_md_driver); |
| 1499 | fimc_unregister_driver(); |
| 1500 | } |
| 1501 | |
| 1502 | module_init(fimc_md_init); |
| 1503 | module_exit(fimc_md_exit); |
| 1504 | |
| 1505 | MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>"); |
| 1506 | MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver"); |
| 1507 | MODULE_LICENSE("GPL"); |
| 1508 | MODULE_VERSION("2.0.1"); |