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 | * |
| 4 | * Copyright (C) 2011 Samsung Electronics Co., Ltd. |
| 5 | * Contact: Sylwester Nawrocki, <s.nawrocki@samsung.com> |
| 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> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/pm_runtime.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/slab.h> |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 24 | #include <media/v4l2-ctrls.h> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 25 | #include <media/media-device.h> |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 26 | #include <media/s5p_fimc.h> |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 27 | |
| 28 | #include "fimc-core.h" |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 29 | #include "fimc-lite.h" |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 30 | #include "fimc-mdevice.h" |
| 31 | #include "mipi-csis.h" |
| 32 | |
| 33 | static int __fimc_md_set_camclk(struct fimc_md *fmd, |
| 34 | struct fimc_sensor_info *s_info, |
| 35 | bool on); |
| 36 | /** |
| 37 | * fimc_pipeline_prepare - update pipeline information with subdevice pointers |
| 38 | * @fimc: fimc device terminating the pipeline |
| 39 | * |
| 40 | * Caller holds the graph mutex. |
| 41 | */ |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 42 | static void fimc_pipeline_prepare(struct fimc_pipeline *p, |
| 43 | struct media_entity *me) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 44 | { |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 45 | struct media_pad *pad = &me->pads[0]; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 46 | struct v4l2_subdev *sd; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 47 | int i; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 48 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 49 | for (i = 0; i < IDX_MAX; i++) |
| 50 | p->subdevs[i] = NULL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 51 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 52 | while (1) { |
| 53 | if (!(pad->flags & MEDIA_PAD_FL_SINK)) |
| 54 | break; |
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 | /* source pad */ |
| 57 | pad = media_entity_remote_source(pad); |
| 58 | if (pad == NULL || |
| 59 | media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV) |
| 60 | break; |
| 61 | |
| 62 | sd = media_entity_to_v4l2_subdev(pad->entity); |
| 63 | |
| 64 | switch (sd->grp_id) { |
| 65 | case SENSOR_GROUP_ID: |
| 66 | p->subdevs[IDX_SENSOR] = sd; |
| 67 | break; |
| 68 | case CSIS_GROUP_ID: |
| 69 | p->subdevs[IDX_CSIS] = sd; |
| 70 | break; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 71 | case FLITE_GROUP_ID: |
| 72 | p->subdevs[IDX_FLITE] = sd; |
| 73 | break; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 74 | case FIMC_GROUP_ID: |
| 75 | /* No need to control FIMC subdev through subdev ops */ |
| 76 | break; |
| 77 | default: |
| 78 | pr_warn("%s: Unknown subdev grp_id: %#x\n", |
| 79 | __func__, sd->grp_id); |
| 80 | } |
| 81 | /* sink pad */ |
| 82 | pad = &sd->entity.pads[0]; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * __subdev_set_power - change power state of a single subdev |
| 88 | * @sd: subdevice to change power state for |
| 89 | * @on: 1 to enable power or 0 to disable |
| 90 | * |
| 91 | * Return result of s_power subdev operation or -ENXIO if sd argument |
| 92 | * is NULL. Return 0 if the subdevice does not implement s_power. |
| 93 | */ |
| 94 | static int __subdev_set_power(struct v4l2_subdev *sd, int on) |
| 95 | { |
| 96 | int *use_count; |
| 97 | int ret; |
| 98 | |
| 99 | if (sd == NULL) |
| 100 | return -ENXIO; |
| 101 | |
| 102 | use_count = &sd->entity.use_count; |
| 103 | if (on && (*use_count)++ > 0) |
| 104 | return 0; |
| 105 | else if (!on && (*use_count == 0 || --(*use_count) > 0)) |
| 106 | return 0; |
| 107 | ret = v4l2_subdev_call(sd, core, s_power, on); |
| 108 | |
| 109 | return ret != -ENOIOCTLCMD ? ret : 0; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * fimc_pipeline_s_power - change power state of all pipeline subdevs |
| 114 | * @fimc: fimc device terminating the pipeline |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 115 | * @state: true to power on, false to power off |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 116 | * |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 117 | * Needs to be called with the graph mutex held. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 118 | */ |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 119 | static int fimc_pipeline_s_power(struct fimc_pipeline *p, bool state) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 120 | { |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 121 | unsigned int i; |
| 122 | int ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 123 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 124 | if (p->subdevs[IDX_SENSOR] == NULL) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 125 | return -ENXIO; |
| 126 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 127 | for (i = 0; i < IDX_MAX; i++) { |
| 128 | unsigned int idx = state ? (IDX_MAX - 1) - i : i; |
| 129 | |
| 130 | ret = __subdev_set_power(p->subdevs[idx], state); |
| 131 | if (ret < 0 && ret != -ENXIO) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 132 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 133 | } |
| 134 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 135 | return 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /** |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 139 | * __fimc_pipeline_open - update the pipeline information, enable power |
| 140 | * of all pipeline subdevs and the sensor clock |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 141 | * @me: media entity to start graph walk with |
| 142 | * @prep: true to acquire sensor (and csis) subdevs |
| 143 | * |
| 144 | * This function must be called with the graph mutex held. |
| 145 | */ |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 146 | static int __fimc_pipeline_open(struct fimc_pipeline *p, |
| 147 | struct media_entity *me, bool prep) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 148 | { |
| 149 | int ret; |
| 150 | |
| 151 | if (prep) |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 152 | fimc_pipeline_prepare(p, me); |
| 153 | |
| 154 | if (p->subdevs[IDX_SENSOR] == NULL) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 155 | return -EINVAL; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 156 | |
| 157 | ret = fimc_md_set_camclk(p->subdevs[IDX_SENSOR], true); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 158 | if (ret) |
| 159 | return ret; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 160 | |
| 161 | return fimc_pipeline_s_power(p, 1); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 162 | } |
| 163 | |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 164 | static int fimc_pipeline_open(struct fimc_pipeline *p, |
| 165 | struct media_entity *me, bool prep) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 166 | { |
| 167 | int ret; |
| 168 | |
| 169 | mutex_lock(&me->parent->graph_mutex); |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 170 | ret = __fimc_pipeline_open(p, me, prep); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 171 | mutex_unlock(&me->parent->graph_mutex); |
| 172 | |
| 173 | return ret; |
| 174 | } |
| 175 | |
| 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 | * |
| 180 | * Disable power of all subdevs in the pipeline and turn off the external |
| 181 | * sensor clock. |
| 182 | * Called with the graph mutex held. |
| 183 | */ |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 184 | static int __fimc_pipeline_close(struct fimc_pipeline *p) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 185 | { |
| 186 | int ret = 0; |
| 187 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 188 | if (p->subdevs[IDX_SENSOR]) { |
| 189 | ret = fimc_pipeline_s_power(p, 0); |
| 190 | fimc_md_set_camclk(p->subdevs[IDX_SENSOR], false); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 191 | } |
| 192 | return ret == -ENXIO ? 0 : ret; |
| 193 | } |
| 194 | |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 195 | static int fimc_pipeline_close(struct fimc_pipeline *p) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 196 | { |
Sylwester Nawrocki | 90e614bb | 2012-05-16 11:35:04 -0300 | [diff] [blame] | 197 | struct media_entity *me; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 198 | int ret; |
| 199 | |
Sylwester Nawrocki | 90e614bb | 2012-05-16 11:35:04 -0300 | [diff] [blame] | 200 | if (!p || !p->subdevs[IDX_SENSOR]) |
| 201 | return -EINVAL; |
| 202 | |
| 203 | me = &p->subdevs[IDX_SENSOR]->entity; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 204 | mutex_lock(&me->parent->graph_mutex); |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 205 | ret = __fimc_pipeline_close(p); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 206 | mutex_unlock(&me->parent->graph_mutex); |
| 207 | |
| 208 | return ret; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * fimc_pipeline_s_stream - invoke s_stream on pipeline subdevs |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 213 | * @pipeline: video pipeline structure |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 214 | * @on: passed as the s_stream call argument |
| 215 | */ |
Sachin Kamat | 57fcfb6 | 2012-10-17 07:11:51 -0300 | [diff] [blame] | 216 | static int fimc_pipeline_s_stream(struct fimc_pipeline *p, bool on) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 217 | { |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 218 | int i, ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 219 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 220 | if (p->subdevs[IDX_SENSOR] == NULL) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 221 | return -ENODEV; |
| 222 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 223 | for (i = 0; i < IDX_MAX; i++) { |
| 224 | unsigned int idx = on ? (IDX_MAX - 1) - i : i; |
| 225 | |
| 226 | ret = v4l2_subdev_call(p->subdevs[idx], video, s_stream, on); |
| 227 | |
| 228 | if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) |
| 229 | return ret; |
| 230 | } |
| 231 | |
| 232 | return 0; |
| 233 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 234 | } |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 235 | |
| 236 | /* Media pipeline operations for the FIMC/FIMC-LITE video device driver */ |
| 237 | static const struct fimc_pipeline_ops fimc_pipeline_ops = { |
| 238 | .open = fimc_pipeline_open, |
| 239 | .close = fimc_pipeline_close, |
| 240 | .set_stream = fimc_pipeline_s_stream, |
| 241 | }; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 242 | |
| 243 | /* |
| 244 | * Sensor subdevice helper functions |
| 245 | */ |
| 246 | static struct v4l2_subdev *fimc_md_register_sensor(struct fimc_md *fmd, |
| 247 | struct fimc_sensor_info *s_info) |
| 248 | { |
| 249 | struct i2c_adapter *adapter; |
| 250 | struct v4l2_subdev *sd = NULL; |
| 251 | |
| 252 | if (!s_info || !fmd) |
| 253 | return NULL; |
| 254 | |
Sylwester Nawrocki | 6612a08 | 2012-09-17 06:00:48 -0300 | [diff] [blame] | 255 | adapter = i2c_get_adapter(s_info->pdata.i2c_bus_num); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 256 | if (!adapter) { |
| 257 | v4l2_warn(&fmd->v4l2_dev, |
| 258 | "Failed to get I2C adapter %d, deferring probe\n", |
Sylwester Nawrocki | 6612a08 | 2012-09-17 06:00:48 -0300 | [diff] [blame] | 259 | s_info->pdata.i2c_bus_num); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 260 | return ERR_PTR(-EPROBE_DEFER); |
| 261 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 262 | sd = v4l2_i2c_new_subdev_board(&fmd->v4l2_dev, adapter, |
Sylwester Nawrocki | 6612a08 | 2012-09-17 06:00:48 -0300 | [diff] [blame] | 263 | s_info->pdata.board_info, NULL); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 264 | if (IS_ERR_OR_NULL(sd)) { |
Sylwester Nawrocki | 7acde02 | 2011-09-13 14:07:09 -0300 | [diff] [blame] | 265 | i2c_put_adapter(adapter); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 266 | v4l2_warn(&fmd->v4l2_dev, |
| 267 | "Failed to acquire subdev %s, deferring probe\n", |
Sylwester Nawrocki | 6612a08 | 2012-09-17 06:00:48 -0300 | [diff] [blame] | 268 | s_info->pdata.board_info->type); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 269 | return ERR_PTR(-EPROBE_DEFER); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 270 | } |
| 271 | v4l2_set_subdev_hostdata(sd, s_info); |
| 272 | sd->grp_id = SENSOR_GROUP_ID; |
| 273 | |
| 274 | v4l2_info(&fmd->v4l2_dev, "Registered sensor subdevice %s\n", |
Sylwester Nawrocki | 6612a08 | 2012-09-17 06:00:48 -0300 | [diff] [blame] | 275 | s_info->pdata.board_info->type); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 276 | return sd; |
| 277 | } |
| 278 | |
| 279 | static void fimc_md_unregister_sensor(struct v4l2_subdev *sd) |
| 280 | { |
| 281 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Sylwester Nawrocki | 7acde02 | 2011-09-13 14:07:09 -0300 | [diff] [blame] | 282 | struct i2c_adapter *adapter; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 283 | |
| 284 | if (!client) |
| 285 | return; |
| 286 | v4l2_device_unregister_subdev(sd); |
Sylwester Nawrocki | 7acde02 | 2011-09-13 14:07:09 -0300 | [diff] [blame] | 287 | adapter = client->adapter; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 288 | i2c_unregister_device(client); |
Sylwester Nawrocki | 7acde02 | 2011-09-13 14:07:09 -0300 | [diff] [blame] | 289 | if (adapter) |
| 290 | i2c_put_adapter(adapter); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | static int fimc_md_register_sensor_entities(struct fimc_md *fmd) |
| 294 | { |
| 295 | struct s5p_platform_fimc *pdata = fmd->pdev->dev.platform_data; |
| 296 | struct fimc_dev *fd = NULL; |
| 297 | int num_clients, ret, i; |
| 298 | |
| 299 | /* |
| 300 | * Runtime resume one of the FIMC entities to make sure |
| 301 | * the sclk_cam clocks are not globally disabled. |
| 302 | */ |
| 303 | for (i = 0; !fd && i < ARRAY_SIZE(fmd->fimc); i++) |
| 304 | if (fmd->fimc[i]) |
| 305 | fd = fmd->fimc[i]; |
| 306 | if (!fd) |
| 307 | return -ENXIO; |
| 308 | ret = pm_runtime_get_sync(&fd->pdev->dev); |
| 309 | if (ret < 0) |
| 310 | return ret; |
| 311 | |
| 312 | WARN_ON(pdata->num_clients > ARRAY_SIZE(fmd->sensor)); |
| 313 | num_clients = min_t(u32, pdata->num_clients, ARRAY_SIZE(fmd->sensor)); |
| 314 | |
| 315 | fmd->num_sensors = num_clients; |
| 316 | for (i = 0; i < num_clients; i++) { |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 317 | struct v4l2_subdev *sd; |
| 318 | |
Sylwester Nawrocki | 6612a08 | 2012-09-17 06:00:48 -0300 | [diff] [blame] | 319 | fmd->sensor[i].pdata = pdata->isp_info[i]; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 320 | ret = __fimc_md_set_camclk(fmd, &fmd->sensor[i], true); |
| 321 | if (ret) |
| 322 | break; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 323 | sd = fimc_md_register_sensor(fmd, &fmd->sensor[i]); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 324 | ret = __fimc_md_set_camclk(fmd, &fmd->sensor[i], false); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 325 | |
| 326 | if (!IS_ERR(sd)) { |
| 327 | fmd->sensor[i].subdev = sd; |
| 328 | } else { |
| 329 | fmd->sensor[i].subdev = NULL; |
| 330 | ret = PTR_ERR(sd); |
| 331 | break; |
| 332 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 333 | if (ret) |
| 334 | break; |
| 335 | } |
| 336 | pm_runtime_put(&fd->pdev->dev); |
| 337 | return ret; |
| 338 | } |
| 339 | |
| 340 | /* |
| 341 | * MIPI CSIS and FIMC platform devices registration. |
| 342 | */ |
| 343 | static int fimc_register_callback(struct device *dev, void *p) |
| 344 | { |
| 345 | struct fimc_dev *fimc = dev_get_drvdata(dev); |
Sachin Kamat | 8163ec0 | 2012-10-25 10:56:00 -0300 | [diff] [blame] | 346 | struct v4l2_subdev *sd; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 347 | struct fimc_md *fmd = p; |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 348 | int ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 349 | |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 350 | if (fimc == NULL || fimc->id >= FIMC_MAX_DEVS) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 351 | return 0; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 352 | |
Sachin Kamat | 8163ec0 | 2012-10-25 10:56:00 -0300 | [diff] [blame] | 353 | sd = &fimc->vid_cap.subdev; |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 354 | sd->grp_id = FIMC_GROUP_ID; |
Sylwester Nawrocki | 97d66c4 | 2012-11-22 06:17:19 -0300 | [diff] [blame] | 355 | v4l2_set_subdev_hostdata(sd, (void *)&fimc_pipeline_ops); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 356 | |
| 357 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
| 358 | if (ret) { |
| 359 | v4l2_err(&fmd->v4l2_dev, "Failed to register FIMC.%d (%d)\n", |
| 360 | fimc->id, ret); |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 361 | return ret; |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 362 | } |
| 363 | |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 364 | fmd->fimc[fimc->id] = fimc; |
| 365 | return 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 366 | } |
| 367 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 368 | static int fimc_lite_register_callback(struct device *dev, void *p) |
| 369 | { |
| 370 | struct fimc_lite *fimc = dev_get_drvdata(dev); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 371 | struct fimc_md *fmd = p; |
| 372 | int ret; |
| 373 | |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 374 | if (fimc == NULL || fimc->index >= FIMC_LITE_MAX_DEVS) |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 375 | return 0; |
| 376 | |
Sachin Kamat | 8163ec0 | 2012-10-25 10:56:00 -0300 | [diff] [blame] | 377 | fimc->subdev.grp_id = FLITE_GROUP_ID; |
Sylwester Nawrocki | 97d66c4 | 2012-11-22 06:17:19 -0300 | [diff] [blame] | 378 | v4l2_set_subdev_hostdata(&fimc->subdev, (void *)&fimc_pipeline_ops); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 379 | |
Sachin Kamat | 8163ec0 | 2012-10-25 10:56:00 -0300 | [diff] [blame] | 380 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, &fimc->subdev); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 381 | if (ret) { |
| 382 | v4l2_err(&fmd->v4l2_dev, |
| 383 | "Failed to register FIMC-LITE.%d (%d)\n", |
| 384 | fimc->index, ret); |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 385 | return ret; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 386 | } |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 387 | |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 388 | fmd->fimc_lite[fimc->index] = fimc; |
| 389 | return 0; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 390 | } |
| 391 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 392 | static int csis_register_callback(struct device *dev, void *p) |
| 393 | { |
| 394 | struct v4l2_subdev *sd = dev_get_drvdata(dev); |
| 395 | struct platform_device *pdev; |
| 396 | struct fimc_md *fmd = p; |
| 397 | int id, ret; |
| 398 | |
| 399 | if (!sd) |
| 400 | return 0; |
| 401 | pdev = v4l2_get_subdevdata(sd); |
| 402 | if (!pdev || pdev->id < 0 || pdev->id >= CSIS_MAX_ENTITIES) |
| 403 | return 0; |
| 404 | v4l2_info(sd, "csis%d sd: %s\n", pdev->id, sd->name); |
| 405 | |
| 406 | id = pdev->id < 0 ? 0 : pdev->id; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 407 | sd->grp_id = CSIS_GROUP_ID; |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 408 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 409 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
Sylwester Nawrocki | afd7348 | 2012-10-25 10:48:44 -0300 | [diff] [blame] | 410 | if (!ret) |
| 411 | fmd->csis[id].sd = sd; |
| 412 | else |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 413 | v4l2_err(&fmd->v4l2_dev, |
| 414 | "Failed to register CSIS subdevice: %d\n", ret); |
| 415 | return ret; |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * fimc_md_register_platform_entities - register FIMC and CSIS media entities |
| 420 | */ |
| 421 | static int fimc_md_register_platform_entities(struct fimc_md *fmd) |
| 422 | { |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 423 | struct s5p_platform_fimc *pdata = fmd->pdev->dev.platform_data; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 424 | struct device_driver *driver; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 425 | int ret, i; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 426 | |
| 427 | driver = driver_find(FIMC_MODULE_NAME, &platform_bus_type); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 428 | if (!driver) { |
| 429 | v4l2_warn(&fmd->v4l2_dev, |
| 430 | "%s driver not found, deffering probe\n", |
| 431 | FIMC_MODULE_NAME); |
| 432 | return -EPROBE_DEFER; |
| 433 | } |
| 434 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 435 | ret = driver_for_each_device(driver, NULL, fmd, |
| 436 | fimc_register_callback); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 437 | if (ret) |
| 438 | return ret; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 439 | |
| 440 | driver = driver_find(FIMC_LITE_DRV_NAME, &platform_bus_type); |
| 441 | if (driver && try_module_get(driver->owner)) { |
| 442 | ret = driver_for_each_device(driver, NULL, fmd, |
| 443 | fimc_lite_register_callback); |
| 444 | if (ret) |
| 445 | return ret; |
| 446 | module_put(driver->owner); |
| 447 | } |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 448 | /* |
| 449 | * Check if there is any sensor on the MIPI-CSI2 bus and |
| 450 | * if not skip the s5p-csis module loading. |
| 451 | */ |
Sylwester Nawrocki | 41df5bf | 2012-04-30 12:10:58 -0300 | [diff] [blame] | 452 | if (pdata == NULL) |
| 453 | return 0; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 454 | for (i = 0; i < pdata->num_clients; i++) { |
| 455 | if (pdata->isp_info[i].bus_type == FIMC_MIPI_CSI2) { |
| 456 | ret = 1; |
| 457 | break; |
| 458 | } |
| 459 | } |
| 460 | if (!ret) |
| 461 | return 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 462 | |
| 463 | driver = driver_find(CSIS_DRIVER_NAME, &platform_bus_type); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 464 | if (!driver || !try_module_get(driver->owner)) { |
| 465 | v4l2_warn(&fmd->v4l2_dev, |
| 466 | "%s driver not found, deffering probe\n", |
| 467 | CSIS_DRIVER_NAME); |
| 468 | return -EPROBE_DEFER; |
| 469 | } |
| 470 | |
| 471 | return driver_for_each_device(driver, NULL, fmd, |
| 472 | csis_register_callback); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | static void fimc_md_unregister_entities(struct fimc_md *fmd) |
| 476 | { |
| 477 | int i; |
| 478 | |
| 479 | for (i = 0; i < FIMC_MAX_DEVS; i++) { |
| 480 | if (fmd->fimc[i] == NULL) |
| 481 | continue; |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 482 | v4l2_device_unregister_subdev(&fmd->fimc[i]->vid_cap.subdev); |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 483 | fmd->fimc[i]->pipeline_ops = NULL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 484 | fmd->fimc[i] = NULL; |
| 485 | } |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 486 | for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { |
| 487 | if (fmd->fimc_lite[i] == NULL) |
| 488 | continue; |
| 489 | v4l2_device_unregister_subdev(&fmd->fimc_lite[i]->subdev); |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 490 | fmd->fimc[i]->pipeline_ops = NULL; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 491 | fmd->fimc_lite[i] = NULL; |
| 492 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 493 | for (i = 0; i < CSIS_MAX_ENTITIES; i++) { |
| 494 | if (fmd->csis[i].sd == NULL) |
| 495 | continue; |
| 496 | v4l2_device_unregister_subdev(fmd->csis[i].sd); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 497 | module_put(fmd->csis[i].sd->owner); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 498 | fmd->csis[i].sd = NULL; |
| 499 | } |
| 500 | for (i = 0; i < fmd->num_sensors; i++) { |
| 501 | if (fmd->sensor[i].subdev == NULL) |
| 502 | continue; |
| 503 | fimc_md_unregister_sensor(fmd->sensor[i].subdev); |
| 504 | fmd->sensor[i].subdev = NULL; |
| 505 | } |
| 506 | } |
| 507 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 508 | /** |
| 509 | * __fimc_md_create_fimc_links - create links to all FIMC entities |
| 510 | * @fmd: fimc media device |
| 511 | * @source: the source entity to create links to all fimc entities from |
| 512 | * @sensor: sensor subdev linked to FIMC[fimc_id] entity, may be null |
| 513 | * @pad: the source entity pad index |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 514 | * @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] | 515 | */ |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 516 | static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd, |
| 517 | struct media_entity *source, |
| 518 | struct v4l2_subdev *sensor, |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 519 | int pad, int link_mask) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 520 | { |
| 521 | struct fimc_sensor_info *s_info; |
| 522 | struct media_entity *sink; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 523 | unsigned int flags = 0; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 524 | int ret, i; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 525 | |
| 526 | for (i = 0; i < FIMC_MAX_DEVS; i++) { |
| 527 | if (!fmd->fimc[i]) |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 528 | continue; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 529 | /* |
| 530 | * Some FIMC variants are not fitted with camera capture |
| 531 | * interface. Skip creating a link from sensor for those. |
| 532 | */ |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 533 | if (!fmd->fimc[i]->variant->has_cam_if) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 534 | continue; |
| 535 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 536 | flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 537 | |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 538 | sink = &fmd->fimc[i]->vid_cap.subdev.entity; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 539 | ret = media_entity_create_link(source, pad, sink, |
| 540 | FIMC_SD_PAD_SINK, flags); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 541 | if (ret) |
| 542 | return ret; |
| 543 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 544 | /* Notify FIMC capture subdev entity */ |
| 545 | ret = media_entity_call(sink, link_setup, &sink->pads[0], |
| 546 | &source->pads[pad], flags); |
| 547 | if (ret) |
| 548 | break; |
| 549 | |
Sylwester Nawrocki | 542fb08 | 2012-10-25 05:48:19 -0300 | [diff] [blame] | 550 | v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]\n", |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 551 | source->name, flags ? '=' : '-', sink->name); |
| 552 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 553 | if (flags == 0 || sensor == NULL) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 554 | continue; |
| 555 | s_info = v4l2_get_subdev_hostdata(sensor); |
| 556 | if (!WARN_ON(s_info == NULL)) { |
| 557 | unsigned long irq_flags; |
| 558 | spin_lock_irqsave(&fmd->slock, irq_flags); |
| 559 | s_info->host = fmd->fimc[i]; |
| 560 | spin_unlock_irqrestore(&fmd->slock, irq_flags); |
| 561 | } |
| 562 | } |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 563 | |
| 564 | for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { |
| 565 | if (!fmd->fimc_lite[i]) |
| 566 | continue; |
| 567 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 568 | if (link_mask & (1 << (i + FIMC_MAX_DEVS))) |
| 569 | flags = MEDIA_LNK_FL_ENABLED; |
| 570 | else |
| 571 | flags = 0; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 572 | |
| 573 | sink = &fmd->fimc_lite[i]->subdev.entity; |
| 574 | ret = media_entity_create_link(source, pad, sink, |
| 575 | FLITE_SD_PAD_SINK, flags); |
| 576 | if (ret) |
| 577 | return ret; |
| 578 | |
| 579 | /* Notify FIMC-LITE subdev entity */ |
| 580 | ret = media_entity_call(sink, link_setup, &sink->pads[0], |
| 581 | &source->pads[pad], flags); |
| 582 | if (ret) |
| 583 | break; |
| 584 | |
| 585 | v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]", |
| 586 | source->name, flags ? '=' : '-', sink->name); |
| 587 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 588 | return 0; |
| 589 | } |
| 590 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 591 | /* Create links from FIMC-LITE source pads to other entities */ |
| 592 | static int __fimc_md_create_flite_source_links(struct fimc_md *fmd) |
| 593 | { |
| 594 | struct media_entity *source, *sink; |
| 595 | unsigned int flags = MEDIA_LNK_FL_ENABLED; |
| 596 | int i, ret; |
| 597 | |
| 598 | for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { |
| 599 | struct fimc_lite *fimc = fmd->fimc_lite[i]; |
| 600 | if (fimc == NULL) |
| 601 | continue; |
| 602 | source = &fimc->subdev.entity; |
Sylwester Nawrocki | 1bcd704 | 2012-07-26 07:13:08 -0300 | [diff] [blame] | 603 | sink = &fimc->vfd.entity; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 604 | /* FIMC-LITE's subdev and video node */ |
| 605 | ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE, |
| 606 | sink, 0, flags); |
| 607 | if (ret) |
| 608 | break; |
| 609 | /* TODO: create links to other entities */ |
| 610 | } |
| 611 | |
| 612 | return ret; |
| 613 | } |
| 614 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 615 | /** |
| 616 | * fimc_md_create_links - create default links between registered entities |
| 617 | * |
| 618 | * Parallel interface sensor entities are connected directly to FIMC capture |
| 619 | * entities. The sensors using MIPI CSIS bus are connected through immutable |
| 620 | * link with CSI receiver entity specified by mux_id. Any registered CSIS |
| 621 | * entity has a link to each registered FIMC capture entity. Enabled links |
| 622 | * are created by default between each subsequent registered sensor and |
| 623 | * subsequent FIMC capture entity. The number of default active links is |
| 624 | * determined by the number of available sensors or FIMC entities, |
| 625 | * whichever is less. |
| 626 | */ |
| 627 | static int fimc_md_create_links(struct fimc_md *fmd) |
| 628 | { |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 629 | struct v4l2_subdev *csi_sensors[2] = { NULL }; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 630 | struct v4l2_subdev *sensor, *csis; |
| 631 | struct s5p_fimc_isp_info *pdata; |
| 632 | struct fimc_sensor_info *s_info; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 633 | struct media_entity *source, *sink; |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 634 | int i, pad, fimc_id = 0, ret = 0; |
| 635 | u32 flags, link_mask = 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 636 | |
| 637 | for (i = 0; i < fmd->num_sensors; i++) { |
| 638 | if (fmd->sensor[i].subdev == NULL) |
| 639 | continue; |
| 640 | |
| 641 | sensor = fmd->sensor[i].subdev; |
| 642 | s_info = v4l2_get_subdev_hostdata(sensor); |
Sylwester Nawrocki | 6612a08 | 2012-09-17 06:00:48 -0300 | [diff] [blame] | 643 | if (!s_info) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 644 | continue; |
| 645 | |
| 646 | source = NULL; |
Sylwester Nawrocki | 6612a08 | 2012-09-17 06:00:48 -0300 | [diff] [blame] | 647 | pdata = &s_info->pdata; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 648 | |
| 649 | switch (pdata->bus_type) { |
| 650 | case FIMC_MIPI_CSI2: |
| 651 | if (WARN(pdata->mux_id >= CSIS_MAX_ENTITIES, |
| 652 | "Wrong CSI channel id: %d\n", pdata->mux_id)) |
| 653 | return -EINVAL; |
| 654 | |
| 655 | csis = fmd->csis[pdata->mux_id].sd; |
| 656 | if (WARN(csis == NULL, |
| 657 | "MIPI-CSI interface specified " |
| 658 | "but s5p-csis module is not loaded!\n")) |
Sylwester Nawrocki | d12392e | 2011-10-20 05:15:59 -0300 | [diff] [blame] | 659 | return -EINVAL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 660 | |
| 661 | ret = media_entity_create_link(&sensor->entity, 0, |
| 662 | &csis->entity, CSIS_PAD_SINK, |
| 663 | MEDIA_LNK_FL_IMMUTABLE | |
| 664 | MEDIA_LNK_FL_ENABLED); |
| 665 | if (ret) |
| 666 | return ret; |
| 667 | |
| 668 | v4l2_info(&fmd->v4l2_dev, "created link [%s] => [%s]", |
| 669 | sensor->entity.name, csis->entity.name); |
| 670 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 671 | source = NULL; |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 672 | csi_sensors[pdata->mux_id] = sensor; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 673 | break; |
| 674 | |
| 675 | case FIMC_ITU_601...FIMC_ITU_656: |
| 676 | source = &sensor->entity; |
| 677 | pad = 0; |
| 678 | break; |
| 679 | |
| 680 | default: |
| 681 | v4l2_err(&fmd->v4l2_dev, "Wrong bus_type: %x\n", |
| 682 | pdata->bus_type); |
| 683 | return -EINVAL; |
| 684 | } |
| 685 | if (source == NULL) |
| 686 | continue; |
| 687 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 688 | link_mask = 1 << fimc_id++; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 689 | ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor, |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 690 | pad, link_mask); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 691 | } |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 692 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 693 | for (i = 0; i < ARRAY_SIZE(fmd->csis); i++) { |
| 694 | if (fmd->csis[i].sd == NULL) |
| 695 | continue; |
| 696 | source = &fmd->csis[i].sd->entity; |
| 697 | pad = CSIS_PAD_SOURCE; |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 698 | sensor = csi_sensors[i]; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 699 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 700 | link_mask = 1 << fimc_id++; |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 701 | ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor, |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 702 | pad, link_mask); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 703 | } |
| 704 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 705 | /* Create immutable links between each FIMC's subdev and video node */ |
| 706 | flags = MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED; |
| 707 | for (i = 0; i < FIMC_MAX_DEVS; i++) { |
| 708 | if (!fmd->fimc[i]) |
| 709 | continue; |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 710 | source = &fmd->fimc[i]->vid_cap.subdev.entity; |
Sylwester Nawrocki | 31d34d9 | 2012-07-26 07:15:42 -0300 | [diff] [blame] | 711 | sink = &fmd->fimc[i]->vid_cap.vfd.entity; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 712 | ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE, |
| 713 | sink, 0, flags); |
| 714 | if (ret) |
| 715 | break; |
| 716 | } |
| 717 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 718 | return __fimc_md_create_flite_source_links(fmd); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | /* |
| 722 | * The peripheral sensor clock management. |
| 723 | */ |
| 724 | static int fimc_md_get_clocks(struct fimc_md *fmd) |
| 725 | { |
| 726 | char clk_name[32]; |
| 727 | struct clk *clock; |
| 728 | int i; |
| 729 | |
| 730 | for (i = 0; i < FIMC_MAX_CAMCLKS; i++) { |
| 731 | snprintf(clk_name, sizeof(clk_name), "sclk_cam%u", i); |
| 732 | clock = clk_get(NULL, clk_name); |
| 733 | if (IS_ERR_OR_NULL(clock)) { |
| 734 | v4l2_err(&fmd->v4l2_dev, "Failed to get clock: %s", |
| 735 | clk_name); |
| 736 | return -ENXIO; |
| 737 | } |
| 738 | fmd->camclk[i].clock = clock; |
| 739 | } |
| 740 | return 0; |
| 741 | } |
| 742 | |
| 743 | static void fimc_md_put_clocks(struct fimc_md *fmd) |
| 744 | { |
| 745 | int i = FIMC_MAX_CAMCLKS; |
| 746 | |
| 747 | while (--i >= 0) { |
| 748 | if (IS_ERR_OR_NULL(fmd->camclk[i].clock)) |
| 749 | continue; |
| 750 | clk_put(fmd->camclk[i].clock); |
| 751 | fmd->camclk[i].clock = NULL; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | static int __fimc_md_set_camclk(struct fimc_md *fmd, |
Sylwester Nawrocki | e3fc82e | 2012-05-17 14:22:10 -0300 | [diff] [blame] | 756 | struct fimc_sensor_info *s_info, |
| 757 | bool on) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 758 | { |
Sylwester Nawrocki | 6612a08 | 2012-09-17 06:00:48 -0300 | [diff] [blame] | 759 | struct s5p_fimc_isp_info *pdata = &s_info->pdata; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 760 | struct fimc_camclk_info *camclk; |
| 761 | int ret = 0; |
| 762 | |
| 763 | if (WARN_ON(pdata->clk_id >= FIMC_MAX_CAMCLKS) || fmd == NULL) |
| 764 | return -EINVAL; |
| 765 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 766 | camclk = &fmd->camclk[pdata->clk_id]; |
| 767 | |
Sylwester Nawrocki | e3fc82e | 2012-05-17 14:22:10 -0300 | [diff] [blame] | 768 | dbg("camclk %d, f: %lu, use_count: %d, on: %d", |
| 769 | pdata->clk_id, pdata->clk_frequency, camclk->use_count, on); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 770 | |
| 771 | if (on) { |
| 772 | if (camclk->use_count > 0 && |
| 773 | camclk->frequency != pdata->clk_frequency) |
| 774 | return -EINVAL; |
| 775 | |
| 776 | if (camclk->use_count++ == 0) { |
| 777 | clk_set_rate(camclk->clock, pdata->clk_frequency); |
| 778 | camclk->frequency = pdata->clk_frequency; |
| 779 | ret = clk_enable(camclk->clock); |
Sylwester Nawrocki | e3fc82e | 2012-05-17 14:22:10 -0300 | [diff] [blame] | 780 | dbg("Enabled camclk %d: f: %lu", pdata->clk_id, |
| 781 | clk_get_rate(camclk->clock)); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 782 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 783 | return ret; |
| 784 | } |
| 785 | |
| 786 | if (WARN_ON(camclk->use_count == 0)) |
| 787 | return 0; |
| 788 | |
| 789 | if (--camclk->use_count == 0) { |
| 790 | clk_disable(camclk->clock); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 791 | dbg("Disabled camclk %d", pdata->clk_id); |
| 792 | } |
| 793 | return ret; |
| 794 | } |
| 795 | |
| 796 | /** |
| 797 | * fimc_md_set_camclk - peripheral sensor clock setup |
| 798 | * @sd: sensor subdev to configure sclk_cam clock for |
| 799 | * @on: 1 to enable or 0 to disable the clock |
| 800 | * |
| 801 | * There are 2 separate clock outputs available in the SoC for external |
| 802 | * image processors. These clocks are shared between all registered FIMC |
| 803 | * devices to which sensors can be attached, either directly or through |
| 804 | * the MIPI CSI receiver. The clock is allowed here to be used by |
| 805 | * multiple sensors concurrently if they use same frequency. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 806 | * This function should only be called when the graph mutex is held. |
| 807 | */ |
| 808 | int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on) |
| 809 | { |
| 810 | struct fimc_sensor_info *s_info = v4l2_get_subdev_hostdata(sd); |
| 811 | struct fimc_md *fmd = entity_to_fimc_mdev(&sd->entity); |
| 812 | |
| 813 | return __fimc_md_set_camclk(fmd, s_info, on); |
| 814 | } |
| 815 | |
| 816 | static int fimc_md_link_notify(struct media_pad *source, |
| 817 | struct media_pad *sink, u32 flags) |
| 818 | { |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 819 | struct fimc_lite *fimc_lite = NULL; |
| 820 | struct fimc_dev *fimc = NULL; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 821 | struct fimc_pipeline *pipeline; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 822 | struct v4l2_subdev *sd; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 823 | int ret = 0; |
| 824 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 825 | if (media_entity_type(sink->entity) != MEDIA_ENT_T_V4L2_SUBDEV) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 826 | return 0; |
| 827 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 828 | sd = media_entity_to_v4l2_subdev(sink->entity); |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 829 | |
| 830 | switch (sd->grp_id) { |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 831 | case FLITE_GROUP_ID: |
| 832 | fimc_lite = v4l2_get_subdevdata(sd); |
| 833 | pipeline = &fimc_lite->pipeline; |
| 834 | break; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 835 | case FIMC_GROUP_ID: |
| 836 | fimc = v4l2_get_subdevdata(sd); |
| 837 | pipeline = &fimc->pipeline; |
| 838 | break; |
| 839 | default: |
| 840 | return 0; |
| 841 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 842 | |
| 843 | if (!(flags & MEDIA_LNK_FL_ENABLED)) { |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 844 | ret = __fimc_pipeline_close(pipeline); |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 845 | pipeline->subdevs[IDX_SENSOR] = NULL; |
| 846 | pipeline->subdevs[IDX_CSIS] = NULL; |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 847 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 848 | if (fimc) { |
| 849 | mutex_lock(&fimc->lock); |
| 850 | fimc_ctrls_delete(fimc->vid_cap.ctx); |
| 851 | mutex_unlock(&fimc->lock); |
| 852 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 853 | return ret; |
| 854 | } |
| 855 | /* |
| 856 | * Link activation. Enable power of pipeline elements only if the |
| 857 | * pipeline is already in use, i.e. its video node is opened. |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 858 | * Recreate the controls destroyed during the link deactivation. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 859 | */ |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 860 | if (fimc) { |
| 861 | mutex_lock(&fimc->lock); |
| 862 | if (fimc->vid_cap.refcnt > 0) { |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 863 | ret = __fimc_pipeline_open(pipeline, |
| 864 | source->entity, true); |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 865 | if (!ret) |
| 866 | ret = fimc_capture_ctrls_create(fimc); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 867 | } |
| 868 | mutex_unlock(&fimc->lock); |
| 869 | } else { |
| 870 | mutex_lock(&fimc_lite->lock); |
| 871 | if (fimc_lite->ref_count > 0) { |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame] | 872 | ret = __fimc_pipeline_open(pipeline, |
| 873 | source->entity, true); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 874 | } |
| 875 | mutex_unlock(&fimc_lite->lock); |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 876 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 877 | return ret ? -EPIPE : ret; |
| 878 | } |
| 879 | |
| 880 | static ssize_t fimc_md_sysfs_show(struct device *dev, |
| 881 | struct device_attribute *attr, char *buf) |
| 882 | { |
| 883 | struct platform_device *pdev = to_platform_device(dev); |
| 884 | struct fimc_md *fmd = platform_get_drvdata(pdev); |
| 885 | |
| 886 | if (fmd->user_subdev_api) |
| 887 | return strlcpy(buf, "Sub-device API (sub-dev)\n", PAGE_SIZE); |
| 888 | |
| 889 | return strlcpy(buf, "V4L2 video node only API (vid-dev)\n", PAGE_SIZE); |
| 890 | } |
| 891 | |
| 892 | static ssize_t fimc_md_sysfs_store(struct device *dev, |
| 893 | struct device_attribute *attr, |
| 894 | const char *buf, size_t count) |
| 895 | { |
| 896 | struct platform_device *pdev = to_platform_device(dev); |
| 897 | struct fimc_md *fmd = platform_get_drvdata(pdev); |
| 898 | bool subdev_api; |
| 899 | int i; |
| 900 | |
| 901 | if (!strcmp(buf, "vid-dev\n")) |
| 902 | subdev_api = false; |
| 903 | else if (!strcmp(buf, "sub-dev\n")) |
| 904 | subdev_api = true; |
| 905 | else |
| 906 | return count; |
| 907 | |
| 908 | fmd->user_subdev_api = subdev_api; |
| 909 | for (i = 0; i < FIMC_MAX_DEVS; i++) |
| 910 | if (fmd->fimc[i]) |
| 911 | fmd->fimc[i]->vid_cap.user_subdev_api = subdev_api; |
| 912 | return count; |
| 913 | } |
| 914 | /* |
| 915 | * This device attribute is to select video pipeline configuration method. |
| 916 | * There are following valid values: |
| 917 | * vid-dev - for V4L2 video node API only, subdevice will be configured |
| 918 | * by the host driver. |
| 919 | * sub-dev - for media controller API, subdevs must be configured in user |
| 920 | * space before starting streaming. |
| 921 | */ |
| 922 | static DEVICE_ATTR(subdev_conf_mode, S_IWUSR | S_IRUGO, |
| 923 | fimc_md_sysfs_show, fimc_md_sysfs_store); |
| 924 | |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 925 | static int fimc_md_probe(struct platform_device *pdev) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 926 | { |
| 927 | struct v4l2_device *v4l2_dev; |
| 928 | struct fimc_md *fmd; |
| 929 | int ret; |
| 930 | |
Sylwester Nawrocki | 6d91a51 | 2012-01-30 11:37:59 -0300 | [diff] [blame] | 931 | fmd = devm_kzalloc(&pdev->dev, sizeof(*fmd), GFP_KERNEL); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 932 | if (!fmd) |
| 933 | return -ENOMEM; |
| 934 | |
| 935 | spin_lock_init(&fmd->slock); |
| 936 | fmd->pdev = pdev; |
| 937 | |
| 938 | strlcpy(fmd->media_dev.model, "SAMSUNG S5P FIMC", |
| 939 | sizeof(fmd->media_dev.model)); |
| 940 | fmd->media_dev.link_notify = fimc_md_link_notify; |
| 941 | fmd->media_dev.dev = &pdev->dev; |
| 942 | |
| 943 | v4l2_dev = &fmd->v4l2_dev; |
| 944 | v4l2_dev->mdev = &fmd->media_dev; |
Sylwester Nawrocki | e1d72f4 | 2011-06-10 15:36:58 -0300 | [diff] [blame] | 945 | v4l2_dev->notify = fimc_sensor_notify; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 946 | snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s", |
| 947 | dev_name(&pdev->dev)); |
| 948 | |
| 949 | ret = v4l2_device_register(&pdev->dev, &fmd->v4l2_dev); |
| 950 | if (ret < 0) { |
| 951 | v4l2_err(v4l2_dev, "Failed to register v4l2_device: %d\n", ret); |
Sylwester Nawrocki | 6d91a51 | 2012-01-30 11:37:59 -0300 | [diff] [blame] | 952 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 953 | } |
| 954 | ret = media_device_register(&fmd->media_dev); |
| 955 | if (ret < 0) { |
| 956 | v4l2_err(v4l2_dev, "Failed to register media device: %d\n", ret); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 957 | goto err_md; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 958 | } |
| 959 | ret = fimc_md_get_clocks(fmd); |
| 960 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 961 | goto err_clk; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 962 | |
| 963 | fmd->user_subdev_api = false; |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 964 | |
| 965 | /* Protect the media graph while we're registering entities */ |
| 966 | mutex_lock(&fmd->media_dev.graph_mutex); |
| 967 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 968 | ret = fimc_md_register_platform_entities(fmd); |
| 969 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 970 | goto err_unlock; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 971 | |
Sylwester Nawrocki | 5cbf6f16 | 2011-10-07 07:40:00 -0300 | [diff] [blame] | 972 | if (pdev->dev.platform_data) { |
| 973 | ret = fimc_md_register_sensor_entities(fmd); |
| 974 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 975 | goto err_unlock; |
Sylwester Nawrocki | 5cbf6f16 | 2011-10-07 07:40:00 -0300 | [diff] [blame] | 976 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 977 | ret = fimc_md_create_links(fmd); |
| 978 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 979 | goto err_unlock; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 980 | ret = v4l2_device_register_subdev_nodes(&fmd->v4l2_dev); |
| 981 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 982 | goto err_unlock; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 983 | |
| 984 | ret = device_create_file(&pdev->dev, &dev_attr_subdev_conf_mode); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 985 | if (ret) |
| 986 | goto err_unlock; |
| 987 | |
| 988 | platform_set_drvdata(pdev, fmd); |
| 989 | mutex_unlock(&fmd->media_dev.graph_mutex); |
| 990 | return 0; |
| 991 | |
| 992 | err_unlock: |
| 993 | mutex_unlock(&fmd->media_dev.graph_mutex); |
| 994 | err_clk: |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 995 | media_device_unregister(&fmd->media_dev); |
| 996 | fimc_md_put_clocks(fmd); |
| 997 | fimc_md_unregister_entities(fmd); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 998 | err_md: |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 999 | v4l2_device_unregister(&fmd->v4l2_dev); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1000 | return ret; |
| 1001 | } |
| 1002 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame^] | 1003 | static int fimc_md_remove(struct platform_device *pdev) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1004 | { |
| 1005 | struct fimc_md *fmd = platform_get_drvdata(pdev); |
| 1006 | |
| 1007 | if (!fmd) |
| 1008 | return 0; |
| 1009 | device_remove_file(&pdev->dev, &dev_attr_subdev_conf_mode); |
| 1010 | fimc_md_unregister_entities(fmd); |
| 1011 | media_device_unregister(&fmd->media_dev); |
| 1012 | fimc_md_put_clocks(fmd); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | static struct platform_driver fimc_md_driver = { |
| 1017 | .probe = fimc_md_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame^] | 1018 | .remove = fimc_md_remove, |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1019 | .driver = { |
| 1020 | .name = "s5p-fimc-md", |
| 1021 | .owner = THIS_MODULE, |
| 1022 | } |
| 1023 | }; |
| 1024 | |
Sachin Kamat | 7e566be | 2012-05-26 11:11:54 -0300 | [diff] [blame] | 1025 | static int __init fimc_md_init(void) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1026 | { |
| 1027 | int ret; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 1028 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1029 | request_module("s5p-csis"); |
| 1030 | ret = fimc_register_driver(); |
| 1031 | if (ret) |
| 1032 | return ret; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 1033 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1034 | return platform_driver_register(&fimc_md_driver); |
| 1035 | } |
Sachin Kamat | 7e566be | 2012-05-26 11:11:54 -0300 | [diff] [blame] | 1036 | |
| 1037 | static void __exit fimc_md_exit(void) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1038 | { |
| 1039 | platform_driver_unregister(&fimc_md_driver); |
| 1040 | fimc_unregister_driver(); |
| 1041 | } |
| 1042 | |
| 1043 | module_init(fimc_md_init); |
| 1044 | module_exit(fimc_md_exit); |
| 1045 | |
| 1046 | MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>"); |
| 1047 | MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver"); |
| 1048 | MODULE_LICENSE("GPL"); |
| 1049 | MODULE_VERSION("2.0.1"); |