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 | */ |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 216 | 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 | |
| 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", |
| 259 | s_info->pdata->i2c_bus_num); |
| 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, |
| 263 | s_info->pdata->board_info, NULL); |
| 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", |
| 268 | s_info->pdata->board_info->type); |
| 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", |
| 275 | s_info->pdata->board_info->type); |
| 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 | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 319 | fmd->sensor[i].pdata = &pdata->isp_info[i]; |
| 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); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 346 | struct v4l2_subdev *sd = &fimc->vid_cap.subdev; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 347 | struct fimc_md *fmd = p; |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 348 | int ret = 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 349 | |
| 350 | if (!fimc || !fimc->pdev) |
| 351 | return 0; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 352 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 353 | if (fimc->pdev->id < 0 || fimc->pdev->id >= FIMC_MAX_DEVS) |
| 354 | return 0; |
| 355 | |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame^] | 356 | fimc->pipeline_ops = &fimc_pipeline_ops; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 357 | fmd->fimc[fimc->pdev->id] = fimc; |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 358 | sd->grp_id = FIMC_GROUP_ID; |
| 359 | |
| 360 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
| 361 | if (ret) { |
| 362 | v4l2_err(&fmd->v4l2_dev, "Failed to register FIMC.%d (%d)\n", |
| 363 | fimc->id, ret); |
| 364 | } |
| 365 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 366 | return ret; |
| 367 | } |
| 368 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 369 | static int fimc_lite_register_callback(struct device *dev, void *p) |
| 370 | { |
| 371 | struct fimc_lite *fimc = dev_get_drvdata(dev); |
| 372 | struct v4l2_subdev *sd = &fimc->subdev; |
| 373 | struct fimc_md *fmd = p; |
| 374 | int ret; |
| 375 | |
| 376 | if (fimc == NULL) |
| 377 | return 0; |
| 378 | |
| 379 | if (fimc->index >= FIMC_LITE_MAX_DEVS) |
| 380 | return 0; |
| 381 | |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame^] | 382 | fimc->pipeline_ops = &fimc_pipeline_ops; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 383 | fmd->fimc_lite[fimc->index] = fimc; |
| 384 | sd->grp_id = FLITE_GROUP_ID; |
| 385 | |
| 386 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
| 387 | if (ret) { |
| 388 | v4l2_err(&fmd->v4l2_dev, |
| 389 | "Failed to register FIMC-LITE.%d (%d)\n", |
| 390 | fimc->index, ret); |
| 391 | } |
| 392 | return ret; |
| 393 | } |
| 394 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 395 | static int csis_register_callback(struct device *dev, void *p) |
| 396 | { |
| 397 | struct v4l2_subdev *sd = dev_get_drvdata(dev); |
| 398 | struct platform_device *pdev; |
| 399 | struct fimc_md *fmd = p; |
| 400 | int id, ret; |
| 401 | |
| 402 | if (!sd) |
| 403 | return 0; |
| 404 | pdev = v4l2_get_subdevdata(sd); |
| 405 | if (!pdev || pdev->id < 0 || pdev->id >= CSIS_MAX_ENTITIES) |
| 406 | return 0; |
| 407 | v4l2_info(sd, "csis%d sd: %s\n", pdev->id, sd->name); |
| 408 | |
| 409 | id = pdev->id < 0 ? 0 : pdev->id; |
| 410 | fmd->csis[id].sd = sd; |
| 411 | sd->grp_id = CSIS_GROUP_ID; |
| 412 | ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); |
| 413 | if (ret) |
| 414 | v4l2_err(&fmd->v4l2_dev, |
| 415 | "Failed to register CSIS subdevice: %d\n", ret); |
| 416 | return ret; |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * fimc_md_register_platform_entities - register FIMC and CSIS media entities |
| 421 | */ |
| 422 | static int fimc_md_register_platform_entities(struct fimc_md *fmd) |
| 423 | { |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 424 | struct s5p_platform_fimc *pdata = fmd->pdev->dev.platform_data; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 425 | struct device_driver *driver; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 426 | int ret, i; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 427 | |
| 428 | driver = driver_find(FIMC_MODULE_NAME, &platform_bus_type); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 429 | if (!driver) { |
| 430 | v4l2_warn(&fmd->v4l2_dev, |
| 431 | "%s driver not found, deffering probe\n", |
| 432 | FIMC_MODULE_NAME); |
| 433 | return -EPROBE_DEFER; |
| 434 | } |
| 435 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 436 | ret = driver_for_each_device(driver, NULL, fmd, |
| 437 | fimc_register_callback); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 438 | if (ret) |
| 439 | return ret; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 440 | |
| 441 | driver = driver_find(FIMC_LITE_DRV_NAME, &platform_bus_type); |
| 442 | if (driver && try_module_get(driver->owner)) { |
| 443 | ret = driver_for_each_device(driver, NULL, fmd, |
| 444 | fimc_lite_register_callback); |
| 445 | if (ret) |
| 446 | return ret; |
| 447 | module_put(driver->owner); |
| 448 | } |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 449 | /* |
| 450 | * Check if there is any sensor on the MIPI-CSI2 bus and |
| 451 | * if not skip the s5p-csis module loading. |
| 452 | */ |
Sylwester Nawrocki | 41df5bf | 2012-04-30 12:10:58 -0300 | [diff] [blame] | 453 | if (pdata == NULL) |
| 454 | return 0; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 455 | for (i = 0; i < pdata->num_clients; i++) { |
| 456 | if (pdata->isp_info[i].bus_type == FIMC_MIPI_CSI2) { |
| 457 | ret = 1; |
| 458 | break; |
| 459 | } |
| 460 | } |
| 461 | if (!ret) |
| 462 | return 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 463 | |
| 464 | driver = driver_find(CSIS_DRIVER_NAME, &platform_bus_type); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 465 | if (!driver || !try_module_get(driver->owner)) { |
| 466 | v4l2_warn(&fmd->v4l2_dev, |
| 467 | "%s driver not found, deffering probe\n", |
| 468 | CSIS_DRIVER_NAME); |
| 469 | return -EPROBE_DEFER; |
| 470 | } |
| 471 | |
| 472 | return driver_for_each_device(driver, NULL, fmd, |
| 473 | csis_register_callback); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static void fimc_md_unregister_entities(struct fimc_md *fmd) |
| 477 | { |
| 478 | int i; |
| 479 | |
| 480 | for (i = 0; i < FIMC_MAX_DEVS; i++) { |
| 481 | if (fmd->fimc[i] == NULL) |
| 482 | continue; |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 483 | v4l2_device_unregister_subdev(&fmd->fimc[i]->vid_cap.subdev); |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame^] | 484 | fmd->fimc[i]->pipeline_ops = NULL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 485 | fmd->fimc[i] = NULL; |
| 486 | } |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 487 | for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { |
| 488 | if (fmd->fimc_lite[i] == NULL) |
| 489 | continue; |
| 490 | v4l2_device_unregister_subdev(&fmd->fimc_lite[i]->subdev); |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame^] | 491 | fmd->fimc[i]->pipeline_ops = NULL; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 492 | fmd->fimc_lite[i] = NULL; |
| 493 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 494 | for (i = 0; i < CSIS_MAX_ENTITIES; i++) { |
| 495 | if (fmd->csis[i].sd == NULL) |
| 496 | continue; |
| 497 | v4l2_device_unregister_subdev(fmd->csis[i].sd); |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 498 | module_put(fmd->csis[i].sd->owner); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 499 | fmd->csis[i].sd = NULL; |
| 500 | } |
| 501 | for (i = 0; i < fmd->num_sensors; i++) { |
| 502 | if (fmd->sensor[i].subdev == NULL) |
| 503 | continue; |
| 504 | fimc_md_unregister_sensor(fmd->sensor[i].subdev); |
| 505 | fmd->sensor[i].subdev = NULL; |
| 506 | } |
| 507 | } |
| 508 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 509 | /** |
| 510 | * __fimc_md_create_fimc_links - create links to all FIMC entities |
| 511 | * @fmd: fimc media device |
| 512 | * @source: the source entity to create links to all fimc entities from |
| 513 | * @sensor: sensor subdev linked to FIMC[fimc_id] entity, may be null |
| 514 | * @pad: the source entity pad index |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 515 | * @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] | 516 | */ |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 517 | static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd, |
| 518 | struct media_entity *source, |
| 519 | struct v4l2_subdev *sensor, |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 520 | int pad, int link_mask) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 521 | { |
| 522 | struct fimc_sensor_info *s_info; |
| 523 | struct media_entity *sink; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 524 | unsigned int flags = 0; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 525 | int ret, i; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 526 | |
| 527 | for (i = 0; i < FIMC_MAX_DEVS; i++) { |
| 528 | if (!fmd->fimc[i]) |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 529 | continue; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 530 | /* |
| 531 | * Some FIMC variants are not fitted with camera capture |
| 532 | * interface. Skip creating a link from sensor for those. |
| 533 | */ |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 534 | if (!fmd->fimc[i]->variant->has_cam_if) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 535 | continue; |
| 536 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 537 | flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 538 | |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 539 | sink = &fmd->fimc[i]->vid_cap.subdev.entity; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 540 | ret = media_entity_create_link(source, pad, sink, |
| 541 | FIMC_SD_PAD_SINK, flags); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 542 | if (ret) |
| 543 | return ret; |
| 544 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 545 | /* Notify FIMC capture subdev entity */ |
| 546 | ret = media_entity_call(sink, link_setup, &sink->pads[0], |
| 547 | &source->pads[pad], flags); |
| 548 | if (ret) |
| 549 | break; |
| 550 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 551 | v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]", |
| 552 | source->name, flags ? '=' : '-', sink->name); |
| 553 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 554 | if (flags == 0 || sensor == NULL) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 555 | continue; |
| 556 | s_info = v4l2_get_subdev_hostdata(sensor); |
| 557 | if (!WARN_ON(s_info == NULL)) { |
| 558 | unsigned long irq_flags; |
| 559 | spin_lock_irqsave(&fmd->slock, irq_flags); |
| 560 | s_info->host = fmd->fimc[i]; |
| 561 | spin_unlock_irqrestore(&fmd->slock, irq_flags); |
| 562 | } |
| 563 | } |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 564 | |
| 565 | for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { |
| 566 | if (!fmd->fimc_lite[i]) |
| 567 | continue; |
| 568 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 569 | if (link_mask & (1 << (i + FIMC_MAX_DEVS))) |
| 570 | flags = MEDIA_LNK_FL_ENABLED; |
| 571 | else |
| 572 | flags = 0; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 573 | |
| 574 | sink = &fmd->fimc_lite[i]->subdev.entity; |
| 575 | ret = media_entity_create_link(source, pad, sink, |
| 576 | FLITE_SD_PAD_SINK, flags); |
| 577 | if (ret) |
| 578 | return ret; |
| 579 | |
| 580 | /* Notify FIMC-LITE subdev entity */ |
| 581 | ret = media_entity_call(sink, link_setup, &sink->pads[0], |
| 582 | &source->pads[pad], flags); |
| 583 | if (ret) |
| 584 | break; |
| 585 | |
| 586 | v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]", |
| 587 | source->name, flags ? '=' : '-', sink->name); |
| 588 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 589 | return 0; |
| 590 | } |
| 591 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 592 | /* Create links from FIMC-LITE source pads to other entities */ |
| 593 | static int __fimc_md_create_flite_source_links(struct fimc_md *fmd) |
| 594 | { |
| 595 | struct media_entity *source, *sink; |
| 596 | unsigned int flags = MEDIA_LNK_FL_ENABLED; |
| 597 | int i, ret; |
| 598 | |
| 599 | for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { |
| 600 | struct fimc_lite *fimc = fmd->fimc_lite[i]; |
| 601 | if (fimc == NULL) |
| 602 | continue; |
| 603 | source = &fimc->subdev.entity; |
Sylwester Nawrocki | 1bcd704 | 2012-07-26 07:13:08 -0300 | [diff] [blame] | 604 | sink = &fimc->vfd.entity; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 605 | /* FIMC-LITE's subdev and video node */ |
| 606 | ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE, |
| 607 | sink, 0, flags); |
| 608 | if (ret) |
| 609 | break; |
| 610 | /* TODO: create links to other entities */ |
| 611 | } |
| 612 | |
| 613 | return ret; |
| 614 | } |
| 615 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 616 | /** |
| 617 | * fimc_md_create_links - create default links between registered entities |
| 618 | * |
| 619 | * Parallel interface sensor entities are connected directly to FIMC capture |
| 620 | * entities. The sensors using MIPI CSIS bus are connected through immutable |
| 621 | * link with CSI receiver entity specified by mux_id. Any registered CSIS |
| 622 | * entity has a link to each registered FIMC capture entity. Enabled links |
| 623 | * are created by default between each subsequent registered sensor and |
| 624 | * subsequent FIMC capture entity. The number of default active links is |
| 625 | * determined by the number of available sensors or FIMC entities, |
| 626 | * whichever is less. |
| 627 | */ |
| 628 | static int fimc_md_create_links(struct fimc_md *fmd) |
| 629 | { |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 630 | struct v4l2_subdev *csi_sensors[2] = { NULL }; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 631 | struct v4l2_subdev *sensor, *csis; |
| 632 | struct s5p_fimc_isp_info *pdata; |
| 633 | struct fimc_sensor_info *s_info; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 634 | struct media_entity *source, *sink; |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 635 | int i, pad, fimc_id = 0, ret = 0; |
| 636 | u32 flags, link_mask = 0; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 637 | |
| 638 | for (i = 0; i < fmd->num_sensors; i++) { |
| 639 | if (fmd->sensor[i].subdev == NULL) |
| 640 | continue; |
| 641 | |
| 642 | sensor = fmd->sensor[i].subdev; |
| 643 | s_info = v4l2_get_subdev_hostdata(sensor); |
| 644 | if (!s_info || !s_info->pdata) |
| 645 | continue; |
| 646 | |
| 647 | source = NULL; |
| 648 | pdata = s_info->pdata; |
| 649 | |
| 650 | switch (pdata->bus_type) { |
| 651 | case FIMC_MIPI_CSI2: |
| 652 | if (WARN(pdata->mux_id >= CSIS_MAX_ENTITIES, |
| 653 | "Wrong CSI channel id: %d\n", pdata->mux_id)) |
| 654 | return -EINVAL; |
| 655 | |
| 656 | csis = fmd->csis[pdata->mux_id].sd; |
| 657 | if (WARN(csis == NULL, |
| 658 | "MIPI-CSI interface specified " |
| 659 | "but s5p-csis module is not loaded!\n")) |
Sylwester Nawrocki | d12392e | 2011-10-20 05:15:59 -0300 | [diff] [blame] | 660 | return -EINVAL; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 661 | |
| 662 | ret = media_entity_create_link(&sensor->entity, 0, |
| 663 | &csis->entity, CSIS_PAD_SINK, |
| 664 | MEDIA_LNK_FL_IMMUTABLE | |
| 665 | MEDIA_LNK_FL_ENABLED); |
| 666 | if (ret) |
| 667 | return ret; |
| 668 | |
| 669 | v4l2_info(&fmd->v4l2_dev, "created link [%s] => [%s]", |
| 670 | sensor->entity.name, csis->entity.name); |
| 671 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 672 | source = NULL; |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 673 | csi_sensors[pdata->mux_id] = sensor; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 674 | break; |
| 675 | |
| 676 | case FIMC_ITU_601...FIMC_ITU_656: |
| 677 | source = &sensor->entity; |
| 678 | pad = 0; |
| 679 | break; |
| 680 | |
| 681 | default: |
| 682 | v4l2_err(&fmd->v4l2_dev, "Wrong bus_type: %x\n", |
| 683 | pdata->bus_type); |
| 684 | return -EINVAL; |
| 685 | } |
| 686 | if (source == NULL) |
| 687 | continue; |
| 688 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 689 | link_mask = 1 << fimc_id++; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 690 | ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor, |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 691 | pad, link_mask); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 692 | } |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 693 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 694 | for (i = 0; i < ARRAY_SIZE(fmd->csis); i++) { |
| 695 | if (fmd->csis[i].sd == NULL) |
| 696 | continue; |
| 697 | source = &fmd->csis[i].sd->entity; |
| 698 | pad = CSIS_PAD_SOURCE; |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 699 | sensor = csi_sensors[i]; |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 700 | |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 701 | link_mask = 1 << fimc_id++; |
Sylwester Nawrocki | 5d33ee9 | 2012-08-16 14:06:41 -0300 | [diff] [blame] | 702 | ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor, |
Sylwester Nawrocki | d0da3c3 | 2012-05-16 13:08:30 -0300 | [diff] [blame] | 703 | pad, link_mask); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 704 | } |
| 705 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 706 | /* Create immutable links between each FIMC's subdev and video node */ |
| 707 | flags = MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED; |
| 708 | for (i = 0; i < FIMC_MAX_DEVS; i++) { |
| 709 | if (!fmd->fimc[i]) |
| 710 | continue; |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 711 | source = &fmd->fimc[i]->vid_cap.subdev.entity; |
Sylwester Nawrocki | 31d34d9 | 2012-07-26 07:15:42 -0300 | [diff] [blame] | 712 | sink = &fmd->fimc[i]->vid_cap.vfd.entity; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 713 | ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE, |
| 714 | sink, 0, flags); |
| 715 | if (ret) |
| 716 | break; |
| 717 | } |
| 718 | |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 719 | return __fimc_md_create_flite_source_links(fmd); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | /* |
| 723 | * The peripheral sensor clock management. |
| 724 | */ |
| 725 | static int fimc_md_get_clocks(struct fimc_md *fmd) |
| 726 | { |
| 727 | char clk_name[32]; |
| 728 | struct clk *clock; |
| 729 | int i; |
| 730 | |
| 731 | for (i = 0; i < FIMC_MAX_CAMCLKS; i++) { |
| 732 | snprintf(clk_name, sizeof(clk_name), "sclk_cam%u", i); |
| 733 | clock = clk_get(NULL, clk_name); |
| 734 | if (IS_ERR_OR_NULL(clock)) { |
| 735 | v4l2_err(&fmd->v4l2_dev, "Failed to get clock: %s", |
| 736 | clk_name); |
| 737 | return -ENXIO; |
| 738 | } |
| 739 | fmd->camclk[i].clock = clock; |
| 740 | } |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | static void fimc_md_put_clocks(struct fimc_md *fmd) |
| 745 | { |
| 746 | int i = FIMC_MAX_CAMCLKS; |
| 747 | |
| 748 | while (--i >= 0) { |
| 749 | if (IS_ERR_OR_NULL(fmd->camclk[i].clock)) |
| 750 | continue; |
| 751 | clk_put(fmd->camclk[i].clock); |
| 752 | fmd->camclk[i].clock = NULL; |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | static int __fimc_md_set_camclk(struct fimc_md *fmd, |
Sylwester Nawrocki | e3fc82e | 2012-05-17 14:22:10 -0300 | [diff] [blame] | 757 | struct fimc_sensor_info *s_info, |
| 758 | bool on) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 759 | { |
| 760 | struct s5p_fimc_isp_info *pdata = s_info->pdata; |
| 761 | struct fimc_camclk_info *camclk; |
| 762 | int ret = 0; |
| 763 | |
| 764 | if (WARN_ON(pdata->clk_id >= FIMC_MAX_CAMCLKS) || fmd == NULL) |
| 765 | return -EINVAL; |
| 766 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 767 | camclk = &fmd->camclk[pdata->clk_id]; |
| 768 | |
Sylwester Nawrocki | e3fc82e | 2012-05-17 14:22:10 -0300 | [diff] [blame] | 769 | dbg("camclk %d, f: %lu, use_count: %d, on: %d", |
| 770 | pdata->clk_id, pdata->clk_frequency, camclk->use_count, on); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 771 | |
| 772 | if (on) { |
| 773 | if (camclk->use_count > 0 && |
| 774 | camclk->frequency != pdata->clk_frequency) |
| 775 | return -EINVAL; |
| 776 | |
| 777 | if (camclk->use_count++ == 0) { |
| 778 | clk_set_rate(camclk->clock, pdata->clk_frequency); |
| 779 | camclk->frequency = pdata->clk_frequency; |
| 780 | ret = clk_enable(camclk->clock); |
Sylwester Nawrocki | e3fc82e | 2012-05-17 14:22:10 -0300 | [diff] [blame] | 781 | dbg("Enabled camclk %d: f: %lu", pdata->clk_id, |
| 782 | clk_get_rate(camclk->clock)); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 783 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 784 | return ret; |
| 785 | } |
| 786 | |
| 787 | if (WARN_ON(camclk->use_count == 0)) |
| 788 | return 0; |
| 789 | |
| 790 | if (--camclk->use_count == 0) { |
| 791 | clk_disable(camclk->clock); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 792 | dbg("Disabled camclk %d", pdata->clk_id); |
| 793 | } |
| 794 | return ret; |
| 795 | } |
| 796 | |
| 797 | /** |
| 798 | * fimc_md_set_camclk - peripheral sensor clock setup |
| 799 | * @sd: sensor subdev to configure sclk_cam clock for |
| 800 | * @on: 1 to enable or 0 to disable the clock |
| 801 | * |
| 802 | * There are 2 separate clock outputs available in the SoC for external |
| 803 | * image processors. These clocks are shared between all registered FIMC |
| 804 | * devices to which sensors can be attached, either directly or through |
| 805 | * the MIPI CSI receiver. The clock is allowed here to be used by |
| 806 | * multiple sensors concurrently if they use same frequency. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 807 | * This function should only be called when the graph mutex is held. |
| 808 | */ |
| 809 | int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on) |
| 810 | { |
| 811 | struct fimc_sensor_info *s_info = v4l2_get_subdev_hostdata(sd); |
| 812 | struct fimc_md *fmd = entity_to_fimc_mdev(&sd->entity); |
| 813 | |
| 814 | return __fimc_md_set_camclk(fmd, s_info, on); |
| 815 | } |
| 816 | |
| 817 | static int fimc_md_link_notify(struct media_pad *source, |
| 818 | struct media_pad *sink, u32 flags) |
| 819 | { |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 820 | struct fimc_lite *fimc_lite = NULL; |
| 821 | struct fimc_dev *fimc = NULL; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 822 | struct fimc_pipeline *pipeline; |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 823 | struct v4l2_subdev *sd; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 824 | int ret = 0; |
| 825 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 826 | if (media_entity_type(sink->entity) != MEDIA_ENT_T_V4L2_SUBDEV) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 827 | return 0; |
| 828 | |
Sylwester Nawrocki | 237e026 | 2011-08-24 20:35:30 -0300 | [diff] [blame] | 829 | sd = media_entity_to_v4l2_subdev(sink->entity); |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 830 | |
| 831 | switch (sd->grp_id) { |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 832 | case FLITE_GROUP_ID: |
| 833 | fimc_lite = v4l2_get_subdevdata(sd); |
| 834 | pipeline = &fimc_lite->pipeline; |
| 835 | break; |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 836 | case FIMC_GROUP_ID: |
| 837 | fimc = v4l2_get_subdevdata(sd); |
| 838 | pipeline = &fimc->pipeline; |
| 839 | break; |
| 840 | default: |
| 841 | return 0; |
| 842 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 843 | |
| 844 | if (!(flags & MEDIA_LNK_FL_ENABLED)) { |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame^] | 845 | ret = __fimc_pipeline_close(pipeline); |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 846 | pipeline->subdevs[IDX_SENSOR] = NULL; |
| 847 | pipeline->subdevs[IDX_CSIS] = NULL; |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 848 | |
Sylwester Nawrocki | 0f735f5 | 2012-04-27 09:33:10 -0300 | [diff] [blame] | 849 | if (fimc) { |
| 850 | mutex_lock(&fimc->lock); |
| 851 | fimc_ctrls_delete(fimc->vid_cap.ctx); |
| 852 | mutex_unlock(&fimc->lock); |
| 853 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 854 | return ret; |
| 855 | } |
| 856 | /* |
| 857 | * Link activation. Enable power of pipeline elements only if the |
| 858 | * pipeline is already in use, i.e. its video node is opened. |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 859 | * Recreate the controls destroyed during the link deactivation. |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 860 | */ |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 861 | if (fimc) { |
| 862 | mutex_lock(&fimc->lock); |
| 863 | if (fimc->vid_cap.refcnt > 0) { |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame^] | 864 | ret = __fimc_pipeline_open(pipeline, |
| 865 | source->entity, true); |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 866 | if (!ret) |
| 867 | ret = fimc_capture_ctrls_create(fimc); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 868 | } |
| 869 | mutex_unlock(&fimc->lock); |
| 870 | } else { |
| 871 | mutex_lock(&fimc_lite->lock); |
| 872 | if (fimc_lite->ref_count > 0) { |
Sylwester Nawrocki | b9ee31e6 | 2012-08-14 10:46:58 -0300 | [diff] [blame^] | 873 | ret = __fimc_pipeline_open(pipeline, |
| 874 | source->entity, true); |
Sylwester Nawrocki | 4af8131 | 2012-04-27 05:29:05 -0300 | [diff] [blame] | 875 | } |
| 876 | mutex_unlock(&fimc_lite->lock); |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 877 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 878 | return ret ? -EPIPE : ret; |
| 879 | } |
| 880 | |
| 881 | static ssize_t fimc_md_sysfs_show(struct device *dev, |
| 882 | struct device_attribute *attr, char *buf) |
| 883 | { |
| 884 | struct platform_device *pdev = to_platform_device(dev); |
| 885 | struct fimc_md *fmd = platform_get_drvdata(pdev); |
| 886 | |
| 887 | if (fmd->user_subdev_api) |
| 888 | return strlcpy(buf, "Sub-device API (sub-dev)\n", PAGE_SIZE); |
| 889 | |
| 890 | return strlcpy(buf, "V4L2 video node only API (vid-dev)\n", PAGE_SIZE); |
| 891 | } |
| 892 | |
| 893 | static ssize_t fimc_md_sysfs_store(struct device *dev, |
| 894 | struct device_attribute *attr, |
| 895 | const char *buf, size_t count) |
| 896 | { |
| 897 | struct platform_device *pdev = to_platform_device(dev); |
| 898 | struct fimc_md *fmd = platform_get_drvdata(pdev); |
| 899 | bool subdev_api; |
| 900 | int i; |
| 901 | |
| 902 | if (!strcmp(buf, "vid-dev\n")) |
| 903 | subdev_api = false; |
| 904 | else if (!strcmp(buf, "sub-dev\n")) |
| 905 | subdev_api = true; |
| 906 | else |
| 907 | return count; |
| 908 | |
| 909 | fmd->user_subdev_api = subdev_api; |
| 910 | for (i = 0; i < FIMC_MAX_DEVS; i++) |
| 911 | if (fmd->fimc[i]) |
| 912 | fmd->fimc[i]->vid_cap.user_subdev_api = subdev_api; |
| 913 | return count; |
| 914 | } |
| 915 | /* |
| 916 | * This device attribute is to select video pipeline configuration method. |
| 917 | * There are following valid values: |
| 918 | * vid-dev - for V4L2 video node API only, subdevice will be configured |
| 919 | * by the host driver. |
| 920 | * sub-dev - for media controller API, subdevs must be configured in user |
| 921 | * space before starting streaming. |
| 922 | */ |
| 923 | static DEVICE_ATTR(subdev_conf_mode, S_IWUSR | S_IRUGO, |
| 924 | fimc_md_sysfs_show, fimc_md_sysfs_store); |
| 925 | |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 926 | static int fimc_md_probe(struct platform_device *pdev) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 927 | { |
| 928 | struct v4l2_device *v4l2_dev; |
| 929 | struct fimc_md *fmd; |
| 930 | int ret; |
| 931 | |
Sylwester Nawrocki | 6d91a51 | 2012-01-30 11:37:59 -0300 | [diff] [blame] | 932 | fmd = devm_kzalloc(&pdev->dev, sizeof(*fmd), GFP_KERNEL); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 933 | if (!fmd) |
| 934 | return -ENOMEM; |
| 935 | |
| 936 | spin_lock_init(&fmd->slock); |
| 937 | fmd->pdev = pdev; |
| 938 | |
| 939 | strlcpy(fmd->media_dev.model, "SAMSUNG S5P FIMC", |
| 940 | sizeof(fmd->media_dev.model)); |
| 941 | fmd->media_dev.link_notify = fimc_md_link_notify; |
| 942 | fmd->media_dev.dev = &pdev->dev; |
| 943 | |
| 944 | v4l2_dev = &fmd->v4l2_dev; |
| 945 | v4l2_dev->mdev = &fmd->media_dev; |
Sylwester Nawrocki | e1d72f4 | 2011-06-10 15:36:58 -0300 | [diff] [blame] | 946 | v4l2_dev->notify = fimc_sensor_notify; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 947 | snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s", |
| 948 | dev_name(&pdev->dev)); |
| 949 | |
| 950 | ret = v4l2_device_register(&pdev->dev, &fmd->v4l2_dev); |
| 951 | if (ret < 0) { |
| 952 | v4l2_err(v4l2_dev, "Failed to register v4l2_device: %d\n", ret); |
Sylwester Nawrocki | 6d91a51 | 2012-01-30 11:37:59 -0300 | [diff] [blame] | 953 | return ret; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 954 | } |
| 955 | ret = media_device_register(&fmd->media_dev); |
| 956 | if (ret < 0) { |
| 957 | v4l2_err(v4l2_dev, "Failed to register media device: %d\n", ret); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 958 | goto err_md; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 959 | } |
| 960 | ret = fimc_md_get_clocks(fmd); |
| 961 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 962 | goto err_clk; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 963 | |
| 964 | fmd->user_subdev_api = false; |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 965 | |
| 966 | /* Protect the media graph while we're registering entities */ |
| 967 | mutex_lock(&fmd->media_dev.graph_mutex); |
| 968 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 969 | ret = fimc_md_register_platform_entities(fmd); |
| 970 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 971 | goto err_unlock; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 972 | |
Sylwester Nawrocki | 5cbf6f16 | 2011-10-07 07:40:00 -0300 | [diff] [blame] | 973 | if (pdev->dev.platform_data) { |
| 974 | ret = fimc_md_register_sensor_entities(fmd); |
| 975 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 976 | goto err_unlock; |
Sylwester Nawrocki | 5cbf6f16 | 2011-10-07 07:40:00 -0300 | [diff] [blame] | 977 | } |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 978 | ret = fimc_md_create_links(fmd); |
| 979 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 980 | goto err_unlock; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 981 | ret = v4l2_device_register_subdev_nodes(&fmd->v4l2_dev); |
| 982 | if (ret) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 983 | goto err_unlock; |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 984 | |
| 985 | ret = device_create_file(&pdev->dev, &dev_attr_subdev_conf_mode); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 986 | if (ret) |
| 987 | goto err_unlock; |
| 988 | |
| 989 | platform_set_drvdata(pdev, fmd); |
| 990 | mutex_unlock(&fmd->media_dev.graph_mutex); |
| 991 | return 0; |
| 992 | |
| 993 | err_unlock: |
| 994 | mutex_unlock(&fmd->media_dev.graph_mutex); |
| 995 | err_clk: |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 996 | media_device_unregister(&fmd->media_dev); |
| 997 | fimc_md_put_clocks(fmd); |
| 998 | fimc_md_unregister_entities(fmd); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 999 | err_md: |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1000 | v4l2_device_unregister(&fmd->v4l2_dev); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1001 | return ret; |
| 1002 | } |
| 1003 | |
| 1004 | static int __devexit fimc_md_remove(struct platform_device *pdev) |
| 1005 | { |
| 1006 | struct fimc_md *fmd = platform_get_drvdata(pdev); |
| 1007 | |
| 1008 | if (!fmd) |
| 1009 | return 0; |
| 1010 | device_remove_file(&pdev->dev, &dev_attr_subdev_conf_mode); |
| 1011 | fimc_md_unregister_entities(fmd); |
| 1012 | media_device_unregister(&fmd->media_dev); |
| 1013 | fimc_md_put_clocks(fmd); |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1014 | return 0; |
| 1015 | } |
| 1016 | |
| 1017 | static struct platform_driver fimc_md_driver = { |
| 1018 | .probe = fimc_md_probe, |
| 1019 | .remove = __devexit_p(fimc_md_remove), |
| 1020 | .driver = { |
| 1021 | .name = "s5p-fimc-md", |
| 1022 | .owner = THIS_MODULE, |
| 1023 | } |
| 1024 | }; |
| 1025 | |
Sachin Kamat | 7e566be | 2012-05-26 11:11:54 -0300 | [diff] [blame] | 1026 | static int __init fimc_md_init(void) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1027 | { |
| 1028 | int ret; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 1029 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1030 | request_module("s5p-csis"); |
| 1031 | ret = fimc_register_driver(); |
| 1032 | if (ret) |
| 1033 | return ret; |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 1034 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1035 | return platform_driver_register(&fimc_md_driver); |
| 1036 | } |
Sachin Kamat | 7e566be | 2012-05-26 11:11:54 -0300 | [diff] [blame] | 1037 | |
| 1038 | static void __exit fimc_md_exit(void) |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1039 | { |
| 1040 | platform_driver_unregister(&fimc_md_driver); |
| 1041 | fimc_unregister_driver(); |
| 1042 | } |
| 1043 | |
| 1044 | module_init(fimc_md_init); |
| 1045 | module_exit(fimc_md_exit); |
| 1046 | |
| 1047 | MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>"); |
| 1048 | MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver"); |
| 1049 | MODULE_LICENSE("GPL"); |
| 1050 | MODULE_VERSION("2.0.1"); |