2 * S5P/EXYNOS4 SoC series camera host interface media device driver
4 * Copyright (C) 2011 Samsung Electronics Co., Ltd.
5 * Contact: Sylwester Nawrocki, <s.nawrocki@samsung.com>
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.
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>
24 #include <media/v4l2-ctrls.h>
25 #include <media/media-device.h>
27 #include "fimc-core.h"
28 #include "fimc-mdevice.h"
29 #include "mipi-csis.h"
31 static int __fimc_md_set_camclk(struct fimc_md
*fmd
,
32 struct fimc_sensor_info
*s_info
,
35 * fimc_pipeline_prepare - update pipeline information with subdevice pointers
36 * @fimc: fimc device terminating the pipeline
38 * Caller holds the graph mutex.
40 void fimc_pipeline_prepare(struct fimc_dev
*fimc
, struct media_entity
*me
)
42 struct media_entity_graph graph
;
43 struct v4l2_subdev
*sd
;
45 media_entity_graph_walk_start(&graph
, me
);
47 while ((me
= media_entity_graph_walk_next(&graph
))) {
48 if (media_entity_type(me
) != MEDIA_ENT_T_V4L2_SUBDEV
)
50 sd
= media_entity_to_v4l2_subdev(me
);
52 if (sd
->grp_id
== SENSOR_GROUP_ID
)
53 fimc
->pipeline
.sensor
= sd
;
54 else if (sd
->grp_id
== CSIS_GROUP_ID
)
55 fimc
->pipeline
.csis
= sd
;
60 * __subdev_set_power - change power state of a single subdev
61 * @sd: subdevice to change power state for
62 * @on: 1 to enable power or 0 to disable
64 * Return result of s_power subdev operation or -ENXIO if sd argument
65 * is NULL. Return 0 if the subdevice does not implement s_power.
67 static int __subdev_set_power(struct v4l2_subdev
*sd
, int on
)
75 use_count
= &sd
->entity
.use_count
;
76 if (on
&& (*use_count
)++ > 0)
78 else if (!on
&& (*use_count
== 0 || --(*use_count
) > 0))
80 ret
= v4l2_subdev_call(sd
, core
, s_power
, on
);
82 return ret
!= -ENOIOCTLCMD
? ret
: 0;
86 * fimc_pipeline_s_power - change power state of all pipeline subdevs
87 * @fimc: fimc device terminating the pipeline
88 * @state: 1 to enable power or 0 for power down
90 * Need to be called with the graph mutex held.
92 int fimc_pipeline_s_power(struct fimc_dev
*fimc
, int state
)
96 if (fimc
->pipeline
.sensor
== NULL
)
100 ret
= __subdev_set_power(fimc
->pipeline
.csis
, 1);
101 if (ret
&& ret
!= -ENXIO
)
103 return __subdev_set_power(fimc
->pipeline
.sensor
, 1);
106 ret
= __subdev_set_power(fimc
->pipeline
.sensor
, 0);
109 ret
= __subdev_set_power(fimc
->pipeline
.csis
, 0);
111 return ret
== -ENXIO
? 0 : ret
;
115 * __fimc_pipeline_initialize - update the pipeline information, enable power
116 * of all pipeline subdevs and the sensor clock
117 * @me: media entity to start graph walk with
118 * @prep: true to acquire sensor (and csis) subdevs
120 * This function must be called with the graph mutex held.
122 static int __fimc_pipeline_initialize(struct fimc_dev
*fimc
,
123 struct media_entity
*me
, bool prep
)
128 fimc_pipeline_prepare(fimc
, me
);
129 if (fimc
->pipeline
.sensor
== NULL
)
131 ret
= fimc_md_set_camclk(fimc
->pipeline
.sensor
, true);
134 return fimc_pipeline_s_power(fimc
, 1);
137 int fimc_pipeline_initialize(struct fimc_dev
*fimc
, struct media_entity
*me
,
142 mutex_lock(&me
->parent
->graph_mutex
);
143 ret
= __fimc_pipeline_initialize(fimc
, me
, prep
);
144 mutex_unlock(&me
->parent
->graph_mutex
);
150 * __fimc_pipeline_shutdown - disable the sensor clock and pipeline power
151 * @fimc: fimc device terminating the pipeline
153 * Disable power of all subdevs in the pipeline and turn off the external
155 * Called with the graph mutex held.
157 int __fimc_pipeline_shutdown(struct fimc_dev
*fimc
)
161 if (fimc
->pipeline
.sensor
) {
162 ret
= fimc_pipeline_s_power(fimc
, 0);
163 fimc_md_set_camclk(fimc
->pipeline
.sensor
, false);
165 return ret
== -ENXIO
? 0 : ret
;
168 int fimc_pipeline_shutdown(struct fimc_dev
*fimc
)
170 struct media_entity
*me
= &fimc
->vid_cap
.vfd
->entity
;
173 mutex_lock(&me
->parent
->graph_mutex
);
174 ret
= __fimc_pipeline_shutdown(fimc
);
175 mutex_unlock(&me
->parent
->graph_mutex
);
181 * fimc_pipeline_s_stream - invoke s_stream on pipeline subdevs
182 * @fimc: fimc device terminating the pipeline
183 * @on: passed as the s_stream call argument
185 int fimc_pipeline_s_stream(struct fimc_dev
*fimc
, int on
)
187 struct fimc_pipeline
*p
= &fimc
->pipeline
;
190 if (p
->sensor
== NULL
)
193 if ((on
&& p
->csis
) || !on
)
194 ret
= v4l2_subdev_call(on
? p
->csis
: p
->sensor
,
195 video
, s_stream
, on
);
196 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
198 if ((!on
&& p
->csis
) || on
)
199 ret
= v4l2_subdev_call(on
? p
->sensor
: p
->csis
,
200 video
, s_stream
, on
);
201 return ret
== -ENOIOCTLCMD
? 0 : ret
;
205 * Sensor subdevice helper functions
207 static struct v4l2_subdev
*fimc_md_register_sensor(struct fimc_md
*fmd
,
208 struct fimc_sensor_info
*s_info
)
210 struct i2c_adapter
*adapter
;
211 struct v4l2_subdev
*sd
= NULL
;
216 adapter
= i2c_get_adapter(s_info
->pdata
->i2c_bus_num
);
219 sd
= v4l2_i2c_new_subdev_board(&fmd
->v4l2_dev
, adapter
,
220 s_info
->pdata
->board_info
, NULL
);
221 if (IS_ERR_OR_NULL(sd
)) {
222 i2c_put_adapter(adapter
);
223 v4l2_err(&fmd
->v4l2_dev
, "Failed to acquire subdev\n");
226 v4l2_set_subdev_hostdata(sd
, s_info
);
227 sd
->grp_id
= SENSOR_GROUP_ID
;
229 v4l2_info(&fmd
->v4l2_dev
, "Registered sensor subdevice %s\n",
230 s_info
->pdata
->board_info
->type
);
234 static void fimc_md_unregister_sensor(struct v4l2_subdev
*sd
)
236 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
237 struct i2c_adapter
*adapter
;
241 v4l2_device_unregister_subdev(sd
);
242 adapter
= client
->adapter
;
243 i2c_unregister_device(client
);
245 i2c_put_adapter(adapter
);
248 static int fimc_md_register_sensor_entities(struct fimc_md
*fmd
)
250 struct s5p_platform_fimc
*pdata
= fmd
->pdev
->dev
.platform_data
;
251 struct fimc_dev
*fd
= NULL
;
252 int num_clients
, ret
, i
;
255 * Runtime resume one of the FIMC entities to make sure
256 * the sclk_cam clocks are not globally disabled.
258 for (i
= 0; !fd
&& i
< ARRAY_SIZE(fmd
->fimc
); i
++)
263 ret
= pm_runtime_get_sync(&fd
->pdev
->dev
);
267 WARN_ON(pdata
->num_clients
> ARRAY_SIZE(fmd
->sensor
));
268 num_clients
= min_t(u32
, pdata
->num_clients
, ARRAY_SIZE(fmd
->sensor
));
270 fmd
->num_sensors
= num_clients
;
271 for (i
= 0; i
< num_clients
; i
++) {
272 fmd
->sensor
[i
].pdata
= &pdata
->isp_info
[i
];
273 ret
= __fimc_md_set_camclk(fmd
, &fmd
->sensor
[i
], true);
276 fmd
->sensor
[i
].subdev
=
277 fimc_md_register_sensor(fmd
, &fmd
->sensor
[i
]);
278 ret
= __fimc_md_set_camclk(fmd
, &fmd
->sensor
[i
], false);
282 pm_runtime_put(&fd
->pdev
->dev
);
287 * MIPI CSIS and FIMC platform devices registration.
289 static int fimc_register_callback(struct device
*dev
, void *p
)
291 struct fimc_dev
*fimc
= dev_get_drvdata(dev
);
292 struct fimc_md
*fmd
= p
;
295 if (!fimc
|| !fimc
->pdev
)
297 if (fimc
->pdev
->id
< 0 || fimc
->pdev
->id
>= FIMC_MAX_DEVS
)
300 fmd
->fimc
[fimc
->pdev
->id
] = fimc
;
301 ret
= fimc_register_m2m_device(fimc
, &fmd
->v4l2_dev
);
304 ret
= fimc_register_capture_device(fimc
, &fmd
->v4l2_dev
);
306 fimc
->vid_cap
.user_subdev_api
= fmd
->user_subdev_api
;
310 static int csis_register_callback(struct device
*dev
, void *p
)
312 struct v4l2_subdev
*sd
= dev_get_drvdata(dev
);
313 struct platform_device
*pdev
;
314 struct fimc_md
*fmd
= p
;
319 pdev
= v4l2_get_subdevdata(sd
);
320 if (!pdev
|| pdev
->id
< 0 || pdev
->id
>= CSIS_MAX_ENTITIES
)
322 v4l2_info(sd
, "csis%d sd: %s\n", pdev
->id
, sd
->name
);
324 id
= pdev
->id
< 0 ? 0 : pdev
->id
;
325 fmd
->csis
[id
].sd
= sd
;
326 sd
->grp_id
= CSIS_GROUP_ID
;
327 ret
= v4l2_device_register_subdev(&fmd
->v4l2_dev
, sd
);
329 v4l2_err(&fmd
->v4l2_dev
,
330 "Failed to register CSIS subdevice: %d\n", ret
);
335 * fimc_md_register_platform_entities - register FIMC and CSIS media entities
337 static int fimc_md_register_platform_entities(struct fimc_md
*fmd
)
339 struct device_driver
*driver
;
342 driver
= driver_find(FIMC_MODULE_NAME
, &platform_bus_type
);
345 ret
= driver_for_each_device(driver
, NULL
, fmd
,
346 fimc_register_callback
);
351 driver
= driver_find(CSIS_DRIVER_NAME
, &platform_bus_type
);
353 ret
= driver_for_each_device(driver
, NULL
, fmd
,
354 csis_register_callback
);
360 static void fimc_md_unregister_entities(struct fimc_md
*fmd
)
364 for (i
= 0; i
< FIMC_MAX_DEVS
; i
++) {
365 if (fmd
->fimc
[i
] == NULL
)
367 fimc_unregister_m2m_device(fmd
->fimc
[i
]);
368 fimc_unregister_capture_device(fmd
->fimc
[i
]);
371 for (i
= 0; i
< CSIS_MAX_ENTITIES
; i
++) {
372 if (fmd
->csis
[i
].sd
== NULL
)
374 v4l2_device_unregister_subdev(fmd
->csis
[i
].sd
);
375 fmd
->csis
[i
].sd
= NULL
;
377 for (i
= 0; i
< fmd
->num_sensors
; i
++) {
378 if (fmd
->sensor
[i
].subdev
== NULL
)
380 fimc_md_unregister_sensor(fmd
->sensor
[i
].subdev
);
381 fmd
->sensor
[i
].subdev
= NULL
;
385 static int fimc_md_register_video_nodes(struct fimc_md
*fmd
)
387 struct video_device
*vdev
;
390 for (i
= 0; i
< FIMC_MAX_DEVS
&& !ret
; i
++) {
394 vdev
= fmd
->fimc
[i
]->m2m
.vfd
;
396 ret
= video_register_device(vdev
, VFL_TYPE_GRABBER
, -1);
399 v4l2_info(&fmd
->v4l2_dev
, "Registered %s as /dev/%s\n",
400 vdev
->name
, video_device_node_name(vdev
));
403 vdev
= fmd
->fimc
[i
]->vid_cap
.vfd
;
406 ret
= video_register_device(vdev
, VFL_TYPE_GRABBER
, -1);
407 v4l2_info(&fmd
->v4l2_dev
, "Registered %s as /dev/%s\n",
408 vdev
->name
, video_device_node_name(vdev
));
415 * __fimc_md_create_fimc_links - create links to all FIMC entities
416 * @fmd: fimc media device
417 * @source: the source entity to create links to all fimc entities from
418 * @sensor: sensor subdev linked to FIMC[fimc_id] entity, may be null
419 * @pad: the source entity pad index
420 * @fimc_id: index of the fimc device for which link should be enabled
422 static int __fimc_md_create_fimc_links(struct fimc_md
*fmd
,
423 struct media_entity
*source
,
424 struct v4l2_subdev
*sensor
,
425 int pad
, int fimc_id
)
427 struct fimc_sensor_info
*s_info
;
428 struct media_entity
*sink
;
432 for (i
= 0; i
< FIMC_MAX_DEVS
; i
++) {
436 * Some FIMC variants are not fitted with camera capture
437 * interface. Skip creating a link from sensor for those.
439 if (sensor
->grp_id
== SENSOR_GROUP_ID
&&
440 !fmd
->fimc
[i
]->variant
->has_cam_if
)
443 flags
= (i
== fimc_id
) ? MEDIA_LNK_FL_ENABLED
: 0;
444 sink
= &fmd
->fimc
[i
]->vid_cap
.subdev
->entity
;
445 ret
= media_entity_create_link(source
, pad
, sink
,
446 FIMC_SD_PAD_SINK
, flags
);
450 /* Notify FIMC capture subdev entity */
451 ret
= media_entity_call(sink
, link_setup
, &sink
->pads
[0],
452 &source
->pads
[pad
], flags
);
456 v4l2_info(&fmd
->v4l2_dev
, "created link [%s] %c> [%s]",
457 source
->name
, flags
? '=' : '-', sink
->name
);
461 s_info
= v4l2_get_subdev_hostdata(sensor
);
462 if (!WARN_ON(s_info
== NULL
)) {
463 unsigned long irq_flags
;
464 spin_lock_irqsave(&fmd
->slock
, irq_flags
);
465 s_info
->host
= fmd
->fimc
[i
];
466 spin_unlock_irqrestore(&fmd
->slock
, irq_flags
);
473 * fimc_md_create_links - create default links between registered entities
475 * Parallel interface sensor entities are connected directly to FIMC capture
476 * entities. The sensors using MIPI CSIS bus are connected through immutable
477 * link with CSI receiver entity specified by mux_id. Any registered CSIS
478 * entity has a link to each registered FIMC capture entity. Enabled links
479 * are created by default between each subsequent registered sensor and
480 * subsequent FIMC capture entity. The number of default active links is
481 * determined by the number of available sensors or FIMC entities,
484 static int fimc_md_create_links(struct fimc_md
*fmd
)
486 struct v4l2_subdev
*sensor
, *csis
;
487 struct s5p_fimc_isp_info
*pdata
;
488 struct fimc_sensor_info
*s_info
;
489 struct media_entity
*source
, *sink
;
490 int i
, pad
, fimc_id
= 0;
494 for (i
= 0; i
< fmd
->num_sensors
; i
++) {
495 if (fmd
->sensor
[i
].subdev
== NULL
)
498 sensor
= fmd
->sensor
[i
].subdev
;
499 s_info
= v4l2_get_subdev_hostdata(sensor
);
500 if (!s_info
|| !s_info
->pdata
)
504 pdata
= s_info
->pdata
;
506 switch (pdata
->bus_type
) {
508 if (WARN(pdata
->mux_id
>= CSIS_MAX_ENTITIES
,
509 "Wrong CSI channel id: %d\n", pdata
->mux_id
))
512 csis
= fmd
->csis
[pdata
->mux_id
].sd
;
513 if (WARN(csis
== NULL
,
514 "MIPI-CSI interface specified "
515 "but s5p-csis module is not loaded!\n"))
518 ret
= media_entity_create_link(&sensor
->entity
, 0,
519 &csis
->entity
, CSIS_PAD_SINK
,
520 MEDIA_LNK_FL_IMMUTABLE
|
521 MEDIA_LNK_FL_ENABLED
);
525 v4l2_info(&fmd
->v4l2_dev
, "created link [%s] => [%s]",
526 sensor
->entity
.name
, csis
->entity
.name
);
528 source
= &csis
->entity
;
529 pad
= CSIS_PAD_SOURCE
;
532 case FIMC_ITU_601
...FIMC_ITU_656
:
533 source
= &sensor
->entity
;
538 v4l2_err(&fmd
->v4l2_dev
, "Wrong bus_type: %x\n",
545 ret
= __fimc_md_create_fimc_links(fmd
, source
, sensor
, pad
,
548 /* Create immutable links between each FIMC's subdev and video node */
549 flags
= MEDIA_LNK_FL_IMMUTABLE
| MEDIA_LNK_FL_ENABLED
;
550 for (i
= 0; i
< FIMC_MAX_DEVS
; i
++) {
553 source
= &fmd
->fimc
[i
]->vid_cap
.subdev
->entity
;
554 sink
= &fmd
->fimc
[i
]->vid_cap
.vfd
->entity
;
555 ret
= media_entity_create_link(source
, FIMC_SD_PAD_SOURCE
,
565 * The peripheral sensor clock management.
567 static int fimc_md_get_clocks(struct fimc_md
*fmd
)
573 for (i
= 0; i
< FIMC_MAX_CAMCLKS
; i
++) {
574 snprintf(clk_name
, sizeof(clk_name
), "sclk_cam%u", i
);
575 clock
= clk_get(NULL
, clk_name
);
576 if (IS_ERR_OR_NULL(clock
)) {
577 v4l2_err(&fmd
->v4l2_dev
, "Failed to get clock: %s",
581 fmd
->camclk
[i
].clock
= clock
;
586 static void fimc_md_put_clocks(struct fimc_md
*fmd
)
588 int i
= FIMC_MAX_CAMCLKS
;
591 if (IS_ERR_OR_NULL(fmd
->camclk
[i
].clock
))
593 clk_put(fmd
->camclk
[i
].clock
);
594 fmd
->camclk
[i
].clock
= NULL
;
598 static int __fimc_md_set_camclk(struct fimc_md
*fmd
,
599 struct fimc_sensor_info
*s_info
,
602 struct s5p_fimc_isp_info
*pdata
= s_info
->pdata
;
603 struct fimc_camclk_info
*camclk
;
606 if (WARN_ON(pdata
->clk_id
>= FIMC_MAX_CAMCLKS
) || fmd
== NULL
)
609 if (s_info
->clk_on
== on
)
611 camclk
= &fmd
->camclk
[pdata
->clk_id
];
613 dbg("camclk %d, f: %lu, clk: %p, on: %d",
614 pdata
->clk_id
, pdata
->clk_frequency
, camclk
, on
);
617 if (camclk
->use_count
> 0 &&
618 camclk
->frequency
!= pdata
->clk_frequency
)
621 if (camclk
->use_count
++ == 0) {
622 clk_set_rate(camclk
->clock
, pdata
->clk_frequency
);
623 camclk
->frequency
= pdata
->clk_frequency
;
624 ret
= clk_enable(camclk
->clock
);
627 dbg("Enabled camclk %d: f: %lu", pdata
->clk_id
,
628 clk_get_rate(camclk
->clock
));
633 if (WARN_ON(camclk
->use_count
== 0))
636 if (--camclk
->use_count
== 0) {
637 clk_disable(camclk
->clock
);
639 dbg("Disabled camclk %d", pdata
->clk_id
);
645 * fimc_md_set_camclk - peripheral sensor clock setup
646 * @sd: sensor subdev to configure sclk_cam clock for
647 * @on: 1 to enable or 0 to disable the clock
649 * There are 2 separate clock outputs available in the SoC for external
650 * image processors. These clocks are shared between all registered FIMC
651 * devices to which sensors can be attached, either directly or through
652 * the MIPI CSI receiver. The clock is allowed here to be used by
653 * multiple sensors concurrently if they use same frequency.
654 * The per sensor subdev clk_on attribute helps to synchronize accesses
655 * to the sclk_cam clocks from the video and media device nodes.
656 * This function should only be called when the graph mutex is held.
658 int fimc_md_set_camclk(struct v4l2_subdev
*sd
, bool on
)
660 struct fimc_sensor_info
*s_info
= v4l2_get_subdev_hostdata(sd
);
661 struct fimc_md
*fmd
= entity_to_fimc_mdev(&sd
->entity
);
663 return __fimc_md_set_camclk(fmd
, s_info
, on
);
666 static int fimc_md_link_notify(struct media_pad
*source
,
667 struct media_pad
*sink
, u32 flags
)
669 struct v4l2_subdev
*sd
;
670 struct fimc_dev
*fimc
;
673 if (media_entity_type(sink
->entity
) != MEDIA_ENT_T_V4L2_SUBDEV
)
676 sd
= media_entity_to_v4l2_subdev(sink
->entity
);
677 fimc
= v4l2_get_subdevdata(sd
);
679 if (!(flags
& MEDIA_LNK_FL_ENABLED
)) {
680 ret
= __fimc_pipeline_shutdown(fimc
);
681 fimc
->pipeline
.sensor
= NULL
;
682 fimc
->pipeline
.csis
= NULL
;
684 mutex_lock(&fimc
->lock
);
685 fimc_ctrls_delete(fimc
->vid_cap
.ctx
);
686 mutex_unlock(&fimc
->lock
);
690 * Link activation. Enable power of pipeline elements only if the
691 * pipeline is already in use, i.e. its video node is opened.
692 * Recreate the controls destroyed during the link deactivation.
694 mutex_lock(&fimc
->lock
);
695 if (fimc
->vid_cap
.refcnt
> 0) {
696 ret
= __fimc_pipeline_initialize(fimc
, source
->entity
, true);
698 ret
= fimc_capture_ctrls_create(fimc
);
700 mutex_unlock(&fimc
->lock
);
702 return ret
? -EPIPE
: ret
;
705 static ssize_t
fimc_md_sysfs_show(struct device
*dev
,
706 struct device_attribute
*attr
, char *buf
)
708 struct platform_device
*pdev
= to_platform_device(dev
);
709 struct fimc_md
*fmd
= platform_get_drvdata(pdev
);
711 if (fmd
->user_subdev_api
)
712 return strlcpy(buf
, "Sub-device API (sub-dev)\n", PAGE_SIZE
);
714 return strlcpy(buf
, "V4L2 video node only API (vid-dev)\n", PAGE_SIZE
);
717 static ssize_t
fimc_md_sysfs_store(struct device
*dev
,
718 struct device_attribute
*attr
,
719 const char *buf
, size_t count
)
721 struct platform_device
*pdev
= to_platform_device(dev
);
722 struct fimc_md
*fmd
= platform_get_drvdata(pdev
);
726 if (!strcmp(buf
, "vid-dev\n"))
728 else if (!strcmp(buf
, "sub-dev\n"))
733 fmd
->user_subdev_api
= subdev_api
;
734 for (i
= 0; i
< FIMC_MAX_DEVS
; i
++)
736 fmd
->fimc
[i
]->vid_cap
.user_subdev_api
= subdev_api
;
740 * This device attribute is to select video pipeline configuration method.
741 * There are following valid values:
742 * vid-dev - for V4L2 video node API only, subdevice will be configured
743 * by the host driver.
744 * sub-dev - for media controller API, subdevs must be configured in user
745 * space before starting streaming.
747 static DEVICE_ATTR(subdev_conf_mode
, S_IWUSR
| S_IRUGO
,
748 fimc_md_sysfs_show
, fimc_md_sysfs_store
);
750 static int __devinit
fimc_md_probe(struct platform_device
*pdev
)
752 struct v4l2_device
*v4l2_dev
;
756 fmd
= kzalloc(sizeof(struct fimc_md
), GFP_KERNEL
);
760 spin_lock_init(&fmd
->slock
);
763 strlcpy(fmd
->media_dev
.model
, "SAMSUNG S5P FIMC",
764 sizeof(fmd
->media_dev
.model
));
765 fmd
->media_dev
.link_notify
= fimc_md_link_notify
;
766 fmd
->media_dev
.dev
= &pdev
->dev
;
768 v4l2_dev
= &fmd
->v4l2_dev
;
769 v4l2_dev
->mdev
= &fmd
->media_dev
;
770 v4l2_dev
->notify
= fimc_sensor_notify
;
771 snprintf(v4l2_dev
->name
, sizeof(v4l2_dev
->name
), "%s",
772 dev_name(&pdev
->dev
));
774 ret
= v4l2_device_register(&pdev
->dev
, &fmd
->v4l2_dev
);
776 v4l2_err(v4l2_dev
, "Failed to register v4l2_device: %d\n", ret
);
779 ret
= media_device_register(&fmd
->media_dev
);
781 v4l2_err(v4l2_dev
, "Failed to register media device: %d\n", ret
);
784 ret
= fimc_md_get_clocks(fmd
);
788 fmd
->user_subdev_api
= false;
789 ret
= fimc_md_register_platform_entities(fmd
);
793 if (pdev
->dev
.platform_data
) {
794 ret
= fimc_md_register_sensor_entities(fmd
);
798 ret
= fimc_md_create_links(fmd
);
801 ret
= v4l2_device_register_subdev_nodes(&fmd
->v4l2_dev
);
804 ret
= fimc_md_register_video_nodes(fmd
);
808 ret
= device_create_file(&pdev
->dev
, &dev_attr_subdev_conf_mode
);
810 platform_set_drvdata(pdev
, fmd
);
814 media_device_unregister(&fmd
->media_dev
);
815 fimc_md_put_clocks(fmd
);
816 fimc_md_unregister_entities(fmd
);
818 v4l2_device_unregister(&fmd
->v4l2_dev
);
824 static int __devexit
fimc_md_remove(struct platform_device
*pdev
)
826 struct fimc_md
*fmd
= platform_get_drvdata(pdev
);
830 device_remove_file(&pdev
->dev
, &dev_attr_subdev_conf_mode
);
831 fimc_md_unregister_entities(fmd
);
832 media_device_unregister(&fmd
->media_dev
);
833 fimc_md_put_clocks(fmd
);
838 static struct platform_driver fimc_md_driver
= {
839 .probe
= fimc_md_probe
,
840 .remove
= __devexit_p(fimc_md_remove
),
842 .name
= "s5p-fimc-md",
843 .owner
= THIS_MODULE
,
847 int __init
fimc_md_init(void)
850 request_module("s5p-csis");
851 ret
= fimc_register_driver();
854 return platform_driver_register(&fimc_md_driver
);
856 void __exit
fimc_md_exit(void)
858 platform_driver_unregister(&fimc_md_driver
);
859 fimc_unregister_driver();
862 module_init(fimc_md_init
);
863 module_exit(fimc_md_exit
);
865 MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
866 MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver");
867 MODULE_LICENSE("GPL");
868 MODULE_VERSION("2.0.1");