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 <linux/version.h>
25 #include <media/v4l2-ctrls.h>
26 #include <media/media-device.h>
28 #include "fimc-core.h"
29 #include "fimc-mdevice.h"
30 #include "mipi-csis.h"
32 static int __fimc_md_set_camclk(struct fimc_md
*fmd
,
33 struct fimc_sensor_info
*s_info
,
36 * fimc_pipeline_prepare - update pipeline information with subdevice pointers
37 * @fimc: fimc device terminating the pipeline
39 * Caller holds the graph mutex.
41 void fimc_pipeline_prepare(struct fimc_dev
*fimc
, struct media_entity
*me
)
43 struct media_entity_graph graph
;
44 struct v4l2_subdev
*sd
;
46 media_entity_graph_walk_start(&graph
, me
);
48 while ((me
= media_entity_graph_walk_next(&graph
))) {
49 if (media_entity_type(me
) != MEDIA_ENT_T_V4L2_SUBDEV
)
51 sd
= media_entity_to_v4l2_subdev(me
);
53 if (sd
->grp_id
== SENSOR_GROUP_ID
)
54 fimc
->pipeline
.sensor
= sd
;
55 else if (sd
->grp_id
== CSIS_GROUP_ID
)
56 fimc
->pipeline
.csis
= sd
;
61 * __subdev_set_power - change power state of a single subdev
62 * @sd: subdevice to change power state for
63 * @on: 1 to enable power or 0 to disable
65 * Return result of s_power subdev operation or -ENXIO if sd argument
66 * is NULL. Return 0 if the subdevice does not implement s_power.
68 static int __subdev_set_power(struct v4l2_subdev
*sd
, int on
)
76 use_count
= &sd
->entity
.use_count
;
77 if (on
&& (*use_count
)++ > 0)
79 else if (!on
&& (*use_count
== 0 || --(*use_count
) > 0))
81 ret
= v4l2_subdev_call(sd
, core
, s_power
, on
);
83 return ret
!= -ENOIOCTLCMD
? ret
: 0;
87 * fimc_pipeline_s_power - change power state of all pipeline subdevs
88 * @fimc: fimc device terminating the pipeline
89 * @state: 1 to enable power or 0 for power down
91 * Need to be called with the graph mutex held.
93 int fimc_pipeline_s_power(struct fimc_dev
*fimc
, int state
)
97 if (fimc
->pipeline
.sensor
== NULL
)
101 ret
= __subdev_set_power(fimc
->pipeline
.csis
, 1);
102 if (ret
&& ret
!= -ENXIO
)
104 return __subdev_set_power(fimc
->pipeline
.sensor
, 1);
107 ret
= __subdev_set_power(fimc
->pipeline
.sensor
, 0);
110 ret
= __subdev_set_power(fimc
->pipeline
.csis
, 0);
112 return ret
== -ENXIO
? 0 : ret
;
116 * __fimc_pipeline_initialize - update the pipeline information, enable power
117 * of all pipeline subdevs and the sensor clock
118 * @me: media entity to start graph walk with
119 * @prep: true to acquire sensor (and csis) subdevs
121 * This function must be called with the graph mutex held.
123 static int __fimc_pipeline_initialize(struct fimc_dev
*fimc
,
124 struct media_entity
*me
, bool prep
)
129 fimc_pipeline_prepare(fimc
, me
);
130 if (fimc
->pipeline
.sensor
== NULL
)
132 ret
= fimc_md_set_camclk(fimc
->pipeline
.sensor
, true);
135 return fimc_pipeline_s_power(fimc
, 1);
138 int fimc_pipeline_initialize(struct fimc_dev
*fimc
, struct media_entity
*me
,
143 mutex_lock(&me
->parent
->graph_mutex
);
144 ret
= __fimc_pipeline_initialize(fimc
, me
, prep
);
145 mutex_unlock(&me
->parent
->graph_mutex
);
151 * __fimc_pipeline_shutdown - disable the sensor clock and pipeline power
152 * @fimc: fimc device terminating the pipeline
154 * Disable power of all subdevs in the pipeline and turn off the external
156 * Called with the graph mutex held.
158 int __fimc_pipeline_shutdown(struct fimc_dev
*fimc
)
162 if (fimc
->pipeline
.sensor
) {
163 ret
= fimc_pipeline_s_power(fimc
, 0);
164 fimc_md_set_camclk(fimc
->pipeline
.sensor
, false);
166 return ret
== -ENXIO
? 0 : ret
;
169 int fimc_pipeline_shutdown(struct fimc_dev
*fimc
)
171 struct media_entity
*me
= &fimc
->vid_cap
.vfd
->entity
;
174 mutex_lock(&me
->parent
->graph_mutex
);
175 ret
= __fimc_pipeline_shutdown(fimc
);
176 mutex_unlock(&me
->parent
->graph_mutex
);
182 * fimc_pipeline_s_stream - invoke s_stream on pipeline subdevs
183 * @fimc: fimc device terminating the pipeline
184 * @on: passed as the s_stream call argument
186 int fimc_pipeline_s_stream(struct fimc_dev
*fimc
, int on
)
188 struct fimc_pipeline
*p
= &fimc
->pipeline
;
191 if (p
->sensor
== NULL
)
194 if ((on
&& p
->csis
) || !on
)
195 ret
= v4l2_subdev_call(on
? p
->csis
: p
->sensor
,
196 video
, s_stream
, on
);
197 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
199 if ((!on
&& p
->csis
) || on
)
200 ret
= v4l2_subdev_call(on
? p
->sensor
: p
->csis
,
201 video
, s_stream
, on
);
202 return ret
== -ENOIOCTLCMD
? 0 : ret
;
206 * Sensor subdevice helper functions
208 static struct v4l2_subdev
*fimc_md_register_sensor(struct fimc_md
*fmd
,
209 struct fimc_sensor_info
*s_info
)
211 struct i2c_adapter
*adapter
;
212 struct v4l2_subdev
*sd
= NULL
;
217 adapter
= i2c_get_adapter(s_info
->pdata
->i2c_bus_num
);
220 sd
= v4l2_i2c_new_subdev_board(&fmd
->v4l2_dev
, adapter
,
221 s_info
->pdata
->board_info
, NULL
);
222 if (IS_ERR_OR_NULL(sd
)) {
223 i2c_put_adapter(adapter
);
224 v4l2_err(&fmd
->v4l2_dev
, "Failed to acquire subdev\n");
227 v4l2_set_subdev_hostdata(sd
, s_info
);
228 sd
->grp_id
= SENSOR_GROUP_ID
;
230 v4l2_info(&fmd
->v4l2_dev
, "Registered sensor subdevice %s\n",
231 s_info
->pdata
->board_info
->type
);
235 static void fimc_md_unregister_sensor(struct v4l2_subdev
*sd
)
237 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
238 struct i2c_adapter
*adapter
;
242 v4l2_device_unregister_subdev(sd
);
243 adapter
= client
->adapter
;
244 i2c_unregister_device(client
);
246 i2c_put_adapter(adapter
);
249 static int fimc_md_register_sensor_entities(struct fimc_md
*fmd
)
251 struct s5p_platform_fimc
*pdata
= fmd
->pdev
->dev
.platform_data
;
252 struct fimc_dev
*fd
= NULL
;
253 int num_clients
, ret
, i
;
256 * Runtime resume one of the FIMC entities to make sure
257 * the sclk_cam clocks are not globally disabled.
259 for (i
= 0; !fd
&& i
< ARRAY_SIZE(fmd
->fimc
); i
++)
264 ret
= pm_runtime_get_sync(&fd
->pdev
->dev
);
268 WARN_ON(pdata
->num_clients
> ARRAY_SIZE(fmd
->sensor
));
269 num_clients
= min_t(u32
, pdata
->num_clients
, ARRAY_SIZE(fmd
->sensor
));
271 fmd
->num_sensors
= num_clients
;
272 for (i
= 0; i
< num_clients
; i
++) {
273 fmd
->sensor
[i
].pdata
= &pdata
->isp_info
[i
];
274 ret
= __fimc_md_set_camclk(fmd
, &fmd
->sensor
[i
], true);
277 fmd
->sensor
[i
].subdev
=
278 fimc_md_register_sensor(fmd
, &fmd
->sensor
[i
]);
279 ret
= __fimc_md_set_camclk(fmd
, &fmd
->sensor
[i
], false);
283 pm_runtime_put(&fd
->pdev
->dev
);
288 * MIPI CSIS and FIMC platform devices registration.
290 static int fimc_register_callback(struct device
*dev
, void *p
)
292 struct fimc_dev
*fimc
= dev_get_drvdata(dev
);
293 struct fimc_md
*fmd
= p
;
296 if (!fimc
|| !fimc
->pdev
)
298 if (fimc
->pdev
->id
< 0 || fimc
->pdev
->id
>= FIMC_MAX_DEVS
)
301 fmd
->fimc
[fimc
->pdev
->id
] = fimc
;
302 ret
= fimc_register_m2m_device(fimc
, &fmd
->v4l2_dev
);
305 ret
= fimc_register_capture_device(fimc
, &fmd
->v4l2_dev
);
307 fimc
->vid_cap
.user_subdev_api
= fmd
->user_subdev_api
;
311 static int csis_register_callback(struct device
*dev
, void *p
)
313 struct v4l2_subdev
*sd
= dev_get_drvdata(dev
);
314 struct platform_device
*pdev
;
315 struct fimc_md
*fmd
= p
;
320 pdev
= v4l2_get_subdevdata(sd
);
321 if (!pdev
|| pdev
->id
< 0 || pdev
->id
>= CSIS_MAX_ENTITIES
)
323 v4l2_info(sd
, "csis%d sd: %s\n", pdev
->id
, sd
->name
);
325 id
= pdev
->id
< 0 ? 0 : pdev
->id
;
326 fmd
->csis
[id
].sd
= sd
;
327 sd
->grp_id
= CSIS_GROUP_ID
;
328 ret
= v4l2_device_register_subdev(&fmd
->v4l2_dev
, sd
);
330 v4l2_err(&fmd
->v4l2_dev
,
331 "Failed to register CSIS subdevice: %d\n", ret
);
336 * fimc_md_register_platform_entities - register FIMC and CSIS media entities
338 static int fimc_md_register_platform_entities(struct fimc_md
*fmd
)
340 struct device_driver
*driver
;
343 driver
= driver_find(FIMC_MODULE_NAME
, &platform_bus_type
);
346 ret
= driver_for_each_device(driver
, NULL
, fmd
,
347 fimc_register_callback
);
352 driver
= driver_find(CSIS_DRIVER_NAME
, &platform_bus_type
);
354 ret
= driver_for_each_device(driver
, NULL
, fmd
,
355 csis_register_callback
);
361 static void fimc_md_unregister_entities(struct fimc_md
*fmd
)
365 for (i
= 0; i
< FIMC_MAX_DEVS
; i
++) {
366 if (fmd
->fimc
[i
] == NULL
)
368 fimc_unregister_m2m_device(fmd
->fimc
[i
]);
369 fimc_unregister_capture_device(fmd
->fimc
[i
]);
372 for (i
= 0; i
< CSIS_MAX_ENTITIES
; i
++) {
373 if (fmd
->csis
[i
].sd
== NULL
)
375 v4l2_device_unregister_subdev(fmd
->csis
[i
].sd
);
376 fmd
->csis
[i
].sd
= NULL
;
378 for (i
= 0; i
< fmd
->num_sensors
; i
++) {
379 if (fmd
->sensor
[i
].subdev
== NULL
)
381 fimc_md_unregister_sensor(fmd
->sensor
[i
].subdev
);
382 fmd
->sensor
[i
].subdev
= NULL
;
386 static int fimc_md_register_video_nodes(struct fimc_md
*fmd
)
388 struct video_device
*vdev
;
391 for (i
= 0; i
< FIMC_MAX_DEVS
&& !ret
; i
++) {
395 vdev
= fmd
->fimc
[i
]->m2m
.vfd
;
397 ret
= video_register_device(vdev
, VFL_TYPE_GRABBER
, -1);
400 v4l2_info(&fmd
->v4l2_dev
, "Registered %s as /dev/%s\n",
401 vdev
->name
, video_device_node_name(vdev
));
404 vdev
= fmd
->fimc
[i
]->vid_cap
.vfd
;
407 ret
= video_register_device(vdev
, VFL_TYPE_GRABBER
, -1);
408 v4l2_info(&fmd
->v4l2_dev
, "Registered %s as /dev/%s\n",
409 vdev
->name
, video_device_node_name(vdev
));
416 * __fimc_md_create_fimc_links - create links to all FIMC entities
417 * @fmd: fimc media device
418 * @source: the source entity to create links to all fimc entities from
419 * @sensor: sensor subdev linked to FIMC[fimc_id] entity, may be null
420 * @pad: the source entity pad index
421 * @fimc_id: index of the fimc device for which link should be enabled
423 static int __fimc_md_create_fimc_links(struct fimc_md
*fmd
,
424 struct media_entity
*source
,
425 struct v4l2_subdev
*sensor
,
426 int pad
, int fimc_id
)
428 struct fimc_sensor_info
*s_info
;
429 struct media_entity
*sink
;
433 for (i
= 0; i
< FIMC_MAX_DEVS
; i
++) {
437 * Some FIMC variants are not fitted with camera capture
438 * interface. Skip creating a link from sensor for those.
440 if (sensor
->grp_id
== SENSOR_GROUP_ID
&&
441 !fmd
->fimc
[i
]->variant
->has_cam_if
)
444 flags
= (i
== fimc_id
) ? MEDIA_LNK_FL_ENABLED
: 0;
445 sink
= &fmd
->fimc
[i
]->vid_cap
.subdev
->entity
;
446 ret
= media_entity_create_link(source
, pad
, sink
,
447 FIMC_SD_PAD_SINK
, flags
);
451 /* Notify FIMC capture subdev entity */
452 ret
= media_entity_call(sink
, link_setup
, &sink
->pads
[0],
453 &source
->pads
[pad
], flags
);
457 v4l2_info(&fmd
->v4l2_dev
, "created link [%s] %c> [%s]",
458 source
->name
, flags
? '=' : '-', sink
->name
);
462 s_info
= v4l2_get_subdev_hostdata(sensor
);
463 if (!WARN_ON(s_info
== NULL
)) {
464 unsigned long irq_flags
;
465 spin_lock_irqsave(&fmd
->slock
, irq_flags
);
466 s_info
->host
= fmd
->fimc
[i
];
467 spin_unlock_irqrestore(&fmd
->slock
, irq_flags
);
474 * fimc_md_create_links - create default links between registered entities
476 * Parallel interface sensor entities are connected directly to FIMC capture
477 * entities. The sensors using MIPI CSIS bus are connected through immutable
478 * link with CSI receiver entity specified by mux_id. Any registered CSIS
479 * entity has a link to each registered FIMC capture entity. Enabled links
480 * are created by default between each subsequent registered sensor and
481 * subsequent FIMC capture entity. The number of default active links is
482 * determined by the number of available sensors or FIMC entities,
485 static int fimc_md_create_links(struct fimc_md
*fmd
)
487 struct v4l2_subdev
*sensor
, *csis
;
488 struct s5p_fimc_isp_info
*pdata
;
489 struct fimc_sensor_info
*s_info
;
490 struct media_entity
*source
, *sink
;
491 int i
, pad
, fimc_id
= 0;
495 for (i
= 0; i
< fmd
->num_sensors
; i
++) {
496 if (fmd
->sensor
[i
].subdev
== NULL
)
499 sensor
= fmd
->sensor
[i
].subdev
;
500 s_info
= v4l2_get_subdev_hostdata(sensor
);
501 if (!s_info
|| !s_info
->pdata
)
505 pdata
= s_info
->pdata
;
507 switch (pdata
->bus_type
) {
509 if (WARN(pdata
->mux_id
>= CSIS_MAX_ENTITIES
,
510 "Wrong CSI channel id: %d\n", pdata
->mux_id
))
513 csis
= fmd
->csis
[pdata
->mux_id
].sd
;
514 if (WARN(csis
== NULL
,
515 "MIPI-CSI interface specified "
516 "but s5p-csis module is not loaded!\n"))
519 ret
= media_entity_create_link(&sensor
->entity
, 0,
520 &csis
->entity
, CSIS_PAD_SINK
,
521 MEDIA_LNK_FL_IMMUTABLE
|
522 MEDIA_LNK_FL_ENABLED
);
526 v4l2_info(&fmd
->v4l2_dev
, "created link [%s] => [%s]",
527 sensor
->entity
.name
, csis
->entity
.name
);
529 source
= &csis
->entity
;
530 pad
= CSIS_PAD_SOURCE
;
533 case FIMC_ITU_601
...FIMC_ITU_656
:
534 source
= &sensor
->entity
;
539 v4l2_err(&fmd
->v4l2_dev
, "Wrong bus_type: %x\n",
546 ret
= __fimc_md_create_fimc_links(fmd
, source
, sensor
, pad
,
549 /* Create immutable links between each FIMC's subdev and video node */
550 flags
= MEDIA_LNK_FL_IMMUTABLE
| MEDIA_LNK_FL_ENABLED
;
551 for (i
= 0; i
< FIMC_MAX_DEVS
; i
++) {
554 source
= &fmd
->fimc
[i
]->vid_cap
.subdev
->entity
;
555 sink
= &fmd
->fimc
[i
]->vid_cap
.vfd
->entity
;
556 ret
= media_entity_create_link(source
, FIMC_SD_PAD_SOURCE
,
566 * The peripheral sensor clock management.
568 static int fimc_md_get_clocks(struct fimc_md
*fmd
)
574 for (i
= 0; i
< FIMC_MAX_CAMCLKS
; i
++) {
575 snprintf(clk_name
, sizeof(clk_name
), "sclk_cam%u", i
);
576 clock
= clk_get(NULL
, clk_name
);
577 if (IS_ERR_OR_NULL(clock
)) {
578 v4l2_err(&fmd
->v4l2_dev
, "Failed to get clock: %s",
582 fmd
->camclk
[i
].clock
= clock
;
587 static void fimc_md_put_clocks(struct fimc_md
*fmd
)
589 int i
= FIMC_MAX_CAMCLKS
;
592 if (IS_ERR_OR_NULL(fmd
->camclk
[i
].clock
))
594 clk_put(fmd
->camclk
[i
].clock
);
595 fmd
->camclk
[i
].clock
= NULL
;
599 static int __fimc_md_set_camclk(struct fimc_md
*fmd
,
600 struct fimc_sensor_info
*s_info
,
603 struct s5p_fimc_isp_info
*pdata
= s_info
->pdata
;
604 struct fimc_camclk_info
*camclk
;
607 if (WARN_ON(pdata
->clk_id
>= FIMC_MAX_CAMCLKS
) || fmd
== NULL
)
610 if (s_info
->clk_on
== on
)
612 camclk
= &fmd
->camclk
[pdata
->clk_id
];
614 dbg("camclk %d, f: %lu, clk: %p, on: %d",
615 pdata
->clk_id
, pdata
->clk_frequency
, camclk
, on
);
618 if (camclk
->use_count
> 0 &&
619 camclk
->frequency
!= pdata
->clk_frequency
)
622 if (camclk
->use_count
++ == 0) {
623 clk_set_rate(camclk
->clock
, pdata
->clk_frequency
);
624 camclk
->frequency
= pdata
->clk_frequency
;
625 ret
= clk_enable(camclk
->clock
);
628 dbg("Enabled camclk %d: f: %lu", pdata
->clk_id
,
629 clk_get_rate(camclk
->clock
));
634 if (WARN_ON(camclk
->use_count
== 0))
637 if (--camclk
->use_count
== 0) {
638 clk_disable(camclk
->clock
);
640 dbg("Disabled camclk %d", pdata
->clk_id
);
646 * fimc_md_set_camclk - peripheral sensor clock setup
647 * @sd: sensor subdev to configure sclk_cam clock for
648 * @on: 1 to enable or 0 to disable the clock
650 * There are 2 separate clock outputs available in the SoC for external
651 * image processors. These clocks are shared between all registered FIMC
652 * devices to which sensors can be attached, either directly or through
653 * the MIPI CSI receiver. The clock is allowed here to be used by
654 * multiple sensors concurrently if they use same frequency.
655 * The per sensor subdev clk_on attribute helps to synchronize accesses
656 * to the sclk_cam clocks from the video and media device nodes.
657 * This function should only be called when the graph mutex is held.
659 int fimc_md_set_camclk(struct v4l2_subdev
*sd
, bool on
)
661 struct fimc_sensor_info
*s_info
= v4l2_get_subdev_hostdata(sd
);
662 struct fimc_md
*fmd
= entity_to_fimc_mdev(&sd
->entity
);
664 return __fimc_md_set_camclk(fmd
, s_info
, on
);
667 static int fimc_md_link_notify(struct media_pad
*source
,
668 struct media_pad
*sink
, u32 flags
)
670 struct v4l2_subdev
*sd
;
671 struct fimc_dev
*fimc
;
674 if (media_entity_type(sink
->entity
) != MEDIA_ENT_T_V4L2_SUBDEV
)
677 sd
= media_entity_to_v4l2_subdev(sink
->entity
);
678 fimc
= v4l2_get_subdevdata(sd
);
680 if (!(flags
& MEDIA_LNK_FL_ENABLED
)) {
681 ret
= __fimc_pipeline_shutdown(fimc
);
682 fimc
->pipeline
.sensor
= NULL
;
683 fimc
->pipeline
.csis
= NULL
;
685 mutex_lock(&fimc
->lock
);
686 fimc_ctrls_delete(fimc
->vid_cap
.ctx
);
687 mutex_unlock(&fimc
->lock
);
691 * Link activation. Enable power of pipeline elements only if the
692 * pipeline is already in use, i.e. its video node is opened.
693 * Recreate the controls destroyed during the link deactivation.
695 mutex_lock(&fimc
->lock
);
696 if (fimc
->vid_cap
.refcnt
> 0) {
697 ret
= __fimc_pipeline_initialize(fimc
, source
->entity
, true);
699 ret
= fimc_capture_ctrls_create(fimc
);
701 mutex_unlock(&fimc
->lock
);
703 return ret
? -EPIPE
: ret
;
706 static ssize_t
fimc_md_sysfs_show(struct device
*dev
,
707 struct device_attribute
*attr
, char *buf
)
709 struct platform_device
*pdev
= to_platform_device(dev
);
710 struct fimc_md
*fmd
= platform_get_drvdata(pdev
);
712 if (fmd
->user_subdev_api
)
713 return strlcpy(buf
, "Sub-device API (sub-dev)\n", PAGE_SIZE
);
715 return strlcpy(buf
, "V4L2 video node only API (vid-dev)\n", PAGE_SIZE
);
718 static ssize_t
fimc_md_sysfs_store(struct device
*dev
,
719 struct device_attribute
*attr
,
720 const char *buf
, size_t count
)
722 struct platform_device
*pdev
= to_platform_device(dev
);
723 struct fimc_md
*fmd
= platform_get_drvdata(pdev
);
727 if (!strcmp(buf
, "vid-dev\n"))
729 else if (!strcmp(buf
, "sub-dev\n"))
734 fmd
->user_subdev_api
= subdev_api
;
735 for (i
= 0; i
< FIMC_MAX_DEVS
; i
++)
737 fmd
->fimc
[i
]->vid_cap
.user_subdev_api
= subdev_api
;
741 * This device attribute is to select video pipeline configuration method.
742 * There are following valid values:
743 * vid-dev - for V4L2 video node API only, subdevice will be configured
744 * by the host driver.
745 * sub-dev - for media controller API, subdevs must be configured in user
746 * space before starting streaming.
748 static DEVICE_ATTR(subdev_conf_mode
, S_IWUSR
| S_IRUGO
,
749 fimc_md_sysfs_show
, fimc_md_sysfs_store
);
751 static int __devinit
fimc_md_probe(struct platform_device
*pdev
)
753 struct v4l2_device
*v4l2_dev
;
757 fmd
= kzalloc(sizeof(struct fimc_md
), GFP_KERNEL
);
761 spin_lock_init(&fmd
->slock
);
764 strlcpy(fmd
->media_dev
.model
, "SAMSUNG S5P FIMC",
765 sizeof(fmd
->media_dev
.model
));
766 fmd
->media_dev
.link_notify
= fimc_md_link_notify
;
767 fmd
->media_dev
.dev
= &pdev
->dev
;
769 v4l2_dev
= &fmd
->v4l2_dev
;
770 v4l2_dev
->mdev
= &fmd
->media_dev
;
771 v4l2_dev
->notify
= fimc_sensor_notify
;
772 snprintf(v4l2_dev
->name
, sizeof(v4l2_dev
->name
), "%s",
773 dev_name(&pdev
->dev
));
775 ret
= v4l2_device_register(&pdev
->dev
, &fmd
->v4l2_dev
);
777 v4l2_err(v4l2_dev
, "Failed to register v4l2_device: %d\n", ret
);
780 ret
= media_device_register(&fmd
->media_dev
);
782 v4l2_err(v4l2_dev
, "Failed to register media device: %d\n", ret
);
785 ret
= fimc_md_get_clocks(fmd
);
789 fmd
->user_subdev_api
= false;
790 ret
= fimc_md_register_platform_entities(fmd
);
794 if (pdev
->dev
.platform_data
) {
795 ret
= fimc_md_register_sensor_entities(fmd
);
799 ret
= fimc_md_create_links(fmd
);
802 ret
= v4l2_device_register_subdev_nodes(&fmd
->v4l2_dev
);
805 ret
= fimc_md_register_video_nodes(fmd
);
809 ret
= device_create_file(&pdev
->dev
, &dev_attr_subdev_conf_mode
);
811 platform_set_drvdata(pdev
, fmd
);
815 media_device_unregister(&fmd
->media_dev
);
816 fimc_md_put_clocks(fmd
);
817 fimc_md_unregister_entities(fmd
);
819 v4l2_device_unregister(&fmd
->v4l2_dev
);
825 static int __devexit
fimc_md_remove(struct platform_device
*pdev
)
827 struct fimc_md
*fmd
= platform_get_drvdata(pdev
);
831 device_remove_file(&pdev
->dev
, &dev_attr_subdev_conf_mode
);
832 fimc_md_unregister_entities(fmd
);
833 media_device_unregister(&fmd
->media_dev
);
834 fimc_md_put_clocks(fmd
);
839 static struct platform_driver fimc_md_driver
= {
840 .probe
= fimc_md_probe
,
841 .remove
= __devexit_p(fimc_md_remove
),
843 .name
= "s5p-fimc-md",
844 .owner
= THIS_MODULE
,
848 int __init
fimc_md_init(void)
851 request_module("s5p-csis");
852 ret
= fimc_register_driver();
855 return platform_driver_register(&fimc_md_driver
);
857 void __exit
fimc_md_exit(void)
859 platform_driver_unregister(&fimc_md_driver
);
860 fimc_unregister_driver();
863 module_init(fimc_md_init
);
864 module_exit(fimc_md_exit
);
866 MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
867 MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver");
868 MODULE_LICENSE("GPL");
869 MODULE_VERSION("2.0.1");