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