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