blob: 6972f52ba43f0170d66b749530f0987c3bd34aa9 [file] [log] [blame]
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001/*
2 * S5P/EXYNOS4 SoC series camera host interface media device driver
3 *
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -03004 * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd.
5 * Sylwester Nawrocki <s.nawrocki@samsung.com>
Sylwester Nawrockid3953222011-09-01 06:01:08 -03006 *
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>
Sylwester Nawrockie2985a22013-03-08 12:59:33 -030020#include <linux/of.h>
21#include <linux/of_platform.h>
22#include <linux/of_device.h>
23#include <linux/of_i2c.h>
Sylwester Nawrockid3953222011-09-01 06:01:08 -030024#include <linux/platform_device.h>
25#include <linux/pm_runtime.h>
26#include <linux/types.h>
27#include <linux/slab.h>
Sylwester Nawrocki131b6c62011-08-24 19:25:10 -030028#include <media/v4l2-ctrls.h>
Sylwester Nawrockie2985a22013-03-08 12:59:33 -030029#include <media/v4l2-of.h>
Sylwester Nawrockid3953222011-09-01 06:01:08 -030030#include <media/media-device.h>
Sylwester Nawrockib9ee31e62012-08-14 10:46:58 -030031#include <media/s5p_fimc.h>
Sylwester Nawrockid3953222011-09-01 06:01:08 -030032
33#include "fimc-core.h"
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -030034#include "fimc-lite.h"
Sylwester Nawrockid3953222011-09-01 06:01:08 -030035#include "fimc-mdevice.h"
36#include "mipi-csis.h"
37
38static int __fimc_md_set_camclk(struct fimc_md *fmd,
39 struct fimc_sensor_info *s_info,
40 bool on);
41/**
42 * fimc_pipeline_prepare - update pipeline information with subdevice pointers
Sylwester Nawrocki39bb6df62013-03-08 08:58:34 -030043 * @me: media entity terminating the pipeline
Sylwester Nawrockid3953222011-09-01 06:01:08 -030044 *
45 * Caller holds the graph mutex.
46 */
Sylwester Nawrockib9ee31e62012-08-14 10:46:58 -030047static void fimc_pipeline_prepare(struct fimc_pipeline *p,
48 struct media_entity *me)
Sylwester Nawrockid3953222011-09-01 06:01:08 -030049{
Sylwester Nawrockid3953222011-09-01 06:01:08 -030050 struct v4l2_subdev *sd;
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -030051 int i;
Sylwester Nawrockid3953222011-09-01 06:01:08 -030052
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -030053 for (i = 0; i < IDX_MAX; i++)
54 p->subdevs[i] = NULL;
Sylwester Nawrockid3953222011-09-01 06:01:08 -030055
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -030056 while (1) {
Sylwester Nawrocki39bb6df62013-03-08 08:58:34 -030057 struct media_pad *pad = NULL;
Sylwester Nawrockid3953222011-09-01 06:01:08 -030058
Sylwester Nawrocki39bb6df62013-03-08 08:58:34 -030059 /* Find remote source pad */
60 for (i = 0; i < me->num_pads; i++) {
61 struct media_pad *spad = &me->pads[i];
62 if (!(spad->flags & MEDIA_PAD_FL_SINK))
63 continue;
64 pad = media_entity_remote_source(spad);
65 if (pad)
66 break;
67 }
68
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -030069 if (pad == NULL ||
70 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
71 break;
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -030072 sd = media_entity_to_v4l2_subdev(pad->entity);
73
74 switch (sd->grp_id) {
Sylwester Nawrocki588c87b2012-11-27 11:57:42 -030075 case GRP_ID_FIMC_IS_SENSOR:
76 case GRP_ID_SENSOR:
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -030077 p->subdevs[IDX_SENSOR] = sd;
78 break;
Sylwester Nawrocki588c87b2012-11-27 11:57:42 -030079 case GRP_ID_CSIS:
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -030080 p->subdevs[IDX_CSIS] = sd;
81 break;
Sylwester Nawrocki588c87b2012-11-27 11:57:42 -030082 case GRP_ID_FLITE:
Sylwester Nawrocki4af81312012-04-27 05:29:05 -030083 p->subdevs[IDX_FLITE] = sd;
84 break;
Sylwester Nawrocki588c87b2012-11-27 11:57:42 -030085 case GRP_ID_FIMC:
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -030086 /* No need to control FIMC subdev through subdev ops */
87 break;
88 default:
89 pr_warn("%s: Unknown subdev grp_id: %#x\n",
90 __func__, sd->grp_id);
91 }
Sylwester Nawrocki39bb6df62013-03-08 08:58:34 -030092 me = &sd->entity;
93 if (me->num_pads == 1)
94 break;
Sylwester Nawrockid3953222011-09-01 06:01:08 -030095 }
96}
97
98/**
99 * __subdev_set_power - change power state of a single subdev
100 * @sd: subdevice to change power state for
101 * @on: 1 to enable power or 0 to disable
102 *
103 * Return result of s_power subdev operation or -ENXIO if sd argument
104 * is NULL. Return 0 if the subdevice does not implement s_power.
105 */
106static int __subdev_set_power(struct v4l2_subdev *sd, int on)
107{
108 int *use_count;
109 int ret;
110
111 if (sd == NULL)
112 return -ENXIO;
113
114 use_count = &sd->entity.use_count;
115 if (on && (*use_count)++ > 0)
116 return 0;
117 else if (!on && (*use_count == 0 || --(*use_count) > 0))
118 return 0;
119 ret = v4l2_subdev_call(sd, core, s_power, on);
120
121 return ret != -ENOIOCTLCMD ? ret : 0;
122}
123
124/**
125 * fimc_pipeline_s_power - change power state of all pipeline subdevs
126 * @fimc: fimc device terminating the pipeline
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300127 * @state: true to power on, false to power off
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300128 *
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300129 * Needs to be called with the graph mutex held.
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300130 */
Sylwester Nawrockib9ee31e62012-08-14 10:46:58 -0300131static int fimc_pipeline_s_power(struct fimc_pipeline *p, bool state)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300132{
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300133 unsigned int i;
134 int ret;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300135
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300136 if (p->subdevs[IDX_SENSOR] == NULL)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300137 return -ENXIO;
138
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300139 for (i = 0; i < IDX_MAX; i++) {
140 unsigned int idx = state ? (IDX_MAX - 1) - i : i;
141
142 ret = __subdev_set_power(p->subdevs[idx], state);
143 if (ret < 0 && ret != -ENXIO)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300144 return ret;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300145 }
146
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300147 return 0;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300148}
149
150/**
Sylwester Nawrockib9ee31e62012-08-14 10:46:58 -0300151 * __fimc_pipeline_open - update the pipeline information, enable power
152 * of all pipeline subdevs and the sensor clock
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300153 * @me: media entity to start graph walk with
154 * @prep: true to acquire sensor (and csis) subdevs
155 *
Sylwester Nawrocki740ad922012-12-06 10:26:19 -0300156 * Called with the graph mutex held.
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300157 */
Sylwester Nawrockib9ee31e62012-08-14 10:46:58 -0300158static int __fimc_pipeline_open(struct fimc_pipeline *p,
159 struct media_entity *me, bool prep)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300160{
161 int ret;
162
163 if (prep)
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300164 fimc_pipeline_prepare(p, me);
165
166 if (p->subdevs[IDX_SENSOR] == NULL)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300167 return -EINVAL;
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300168
169 ret = fimc_md_set_camclk(p->subdevs[IDX_SENSOR], true);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300170 if (ret)
171 return ret;
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300172
173 return fimc_pipeline_s_power(p, 1);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300174}
175
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300176/**
Sylwester Nawrockib9ee31e62012-08-14 10:46:58 -0300177 * __fimc_pipeline_close - disable the sensor clock and pipeline power
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300178 * @fimc: fimc device terminating the pipeline
179 *
Sylwester Nawrocki740ad922012-12-06 10:26:19 -0300180 * Disable power of all subdevs and turn the external sensor clock off.
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300181 */
Sylwester Nawrockib9ee31e62012-08-14 10:46:58 -0300182static int __fimc_pipeline_close(struct fimc_pipeline *p)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300183{
184 int ret = 0;
185
Sylwester Nawrocki740ad922012-12-06 10:26:19 -0300186 if (!p || !p->subdevs[IDX_SENSOR])
187 return -EINVAL;
188
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300189 if (p->subdevs[IDX_SENSOR]) {
190 ret = fimc_pipeline_s_power(p, 0);
191 fimc_md_set_camclk(p->subdevs[IDX_SENSOR], false);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300192 }
193 return ret == -ENXIO ? 0 : ret;
194}
195
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300196/**
Sylwester Nawrocki740ad922012-12-06 10:26:19 -0300197 * __fimc_pipeline_s_stream - invoke s_stream on pipeline subdevs
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300198 * @pipeline: video pipeline structure
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300199 * @on: passed as the s_stream call argument
200 */
Sylwester Nawrocki740ad922012-12-06 10:26:19 -0300201static int __fimc_pipeline_s_stream(struct fimc_pipeline *p, bool on)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300202{
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300203 int i, ret;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300204
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300205 if (p->subdevs[IDX_SENSOR] == NULL)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300206 return -ENODEV;
207
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -0300208 for (i = 0; i < IDX_MAX; i++) {
209 unsigned int idx = on ? (IDX_MAX - 1) - i : i;
210
211 ret = v4l2_subdev_call(p->subdevs[idx], video, s_stream, on);
212
213 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
214 return ret;
215 }
216
217 return 0;
218
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300219}
Sylwester Nawrockib9ee31e62012-08-14 10:46:58 -0300220
221/* Media pipeline operations for the FIMC/FIMC-LITE video device driver */
222static const struct fimc_pipeline_ops fimc_pipeline_ops = {
Sylwester Nawrocki740ad922012-12-06 10:26:19 -0300223 .open = __fimc_pipeline_open,
224 .close = __fimc_pipeline_close,
225 .set_stream = __fimc_pipeline_s_stream,
Sylwester Nawrockib9ee31e62012-08-14 10:46:58 -0300226};
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300227
228/*
229 * Sensor subdevice helper functions
230 */
231static struct v4l2_subdev *fimc_md_register_sensor(struct fimc_md *fmd,
232 struct fimc_sensor_info *s_info)
233{
234 struct i2c_adapter *adapter;
235 struct v4l2_subdev *sd = NULL;
236
237 if (!s_info || !fmd)
238 return NULL;
239
Sylwester Nawrocki6612a082012-09-17 06:00:48 -0300240 adapter = i2c_get_adapter(s_info->pdata.i2c_bus_num);
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -0300241 if (!adapter) {
242 v4l2_warn(&fmd->v4l2_dev,
243 "Failed to get I2C adapter %d, deferring probe\n",
Sylwester Nawrocki6612a082012-09-17 06:00:48 -0300244 s_info->pdata.i2c_bus_num);
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -0300245 return ERR_PTR(-EPROBE_DEFER);
246 }
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300247 sd = v4l2_i2c_new_subdev_board(&fmd->v4l2_dev, adapter,
Sylwester Nawrocki6612a082012-09-17 06:00:48 -0300248 s_info->pdata.board_info, NULL);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300249 if (IS_ERR_OR_NULL(sd)) {
Sylwester Nawrocki7acde022011-09-13 14:07:09 -0300250 i2c_put_adapter(adapter);
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -0300251 v4l2_warn(&fmd->v4l2_dev,
252 "Failed to acquire subdev %s, deferring probe\n",
Sylwester Nawrocki6612a082012-09-17 06:00:48 -0300253 s_info->pdata.board_info->type);
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -0300254 return ERR_PTR(-EPROBE_DEFER);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300255 }
256 v4l2_set_subdev_hostdata(sd, s_info);
Sylwester Nawrocki588c87b2012-11-27 11:57:42 -0300257 sd->grp_id = GRP_ID_SENSOR;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300258
259 v4l2_info(&fmd->v4l2_dev, "Registered sensor subdevice %s\n",
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -0300260 sd->name);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300261 return sd;
262}
263
264static void fimc_md_unregister_sensor(struct v4l2_subdev *sd)
265{
266 struct i2c_client *client = v4l2_get_subdevdata(sd);
Sylwester Nawrocki7acde022011-09-13 14:07:09 -0300267 struct i2c_adapter *adapter;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300268
269 if (!client)
270 return;
271 v4l2_device_unregister_subdev(sd);
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -0300272
273 if (!client->dev.of_node) {
274 adapter = client->adapter;
275 i2c_unregister_device(client);
276 if (adapter)
277 i2c_put_adapter(adapter);
278 }
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300279}
280
Sylwester Nawrockie2985a22013-03-08 12:59:33 -0300281#ifdef CONFIG_OF
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -0300282/* Register I2C client subdev associated with @node. */
283static int fimc_md_of_add_sensor(struct fimc_md *fmd,
284 struct device_node *node, int index)
285{
286 struct fimc_sensor_info *si;
287 struct i2c_client *client;
288 struct v4l2_subdev *sd;
289 int ret;
290
291 if (WARN_ON(index >= ARRAY_SIZE(fmd->sensor)))
292 return -EINVAL;
293 si = &fmd->sensor[index];
294
295 client = of_find_i2c_device_by_node(node);
296 if (!client)
297 return -EPROBE_DEFER;
298
299 device_lock(&client->dev);
300
301 if (!client->driver ||
302 !try_module_get(client->driver->driver.owner)) {
303 ret = -EPROBE_DEFER;
304 v4l2_info(&fmd->v4l2_dev, "No driver found for %s\n",
305 node->full_name);
306 goto dev_put;
307 }
308
309 /* Enable sensor's master clock */
310 ret = __fimc_md_set_camclk(fmd, si, true);
311 if (ret < 0)
312 goto mod_put;
313 sd = i2c_get_clientdata(client);
314
315 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
316 __fimc_md_set_camclk(fmd, si, false);
317 if (ret < 0)
318 goto mod_put;
319
320 v4l2_set_subdev_hostdata(sd, si);
321 sd->grp_id = GRP_ID_SENSOR;
322 si->subdev = sd;
323 v4l2_info(&fmd->v4l2_dev, "Registered sensor subdevice: %s (%d)\n",
324 sd->name, fmd->num_sensors);
325 fmd->num_sensors++;
326
327mod_put:
328 module_put(client->driver->driver.owner);
329dev_put:
330 device_unlock(&client->dev);
331 put_device(&client->dev);
332 return ret;
333}
334
335/* Parse port node and register as a sub-device any sensor specified there. */
336static int fimc_md_parse_port_node(struct fimc_md *fmd,
337 struct device_node *port,
338 unsigned int index)
339{
340 struct device_node *rem, *ep, *np;
341 struct fimc_source_info *pd;
342 struct v4l2_of_endpoint endpoint;
343 int ret;
344 u32 val;
345
346 pd = &fmd->sensor[index].pdata;
347
348 /* Assume here a port node can have only one endpoint node. */
349 ep = of_get_next_child(port, NULL);
350 if (!ep)
351 return 0;
352
353 v4l2_of_parse_endpoint(ep, &endpoint);
354 if (WARN_ON(endpoint.port == 0) || index >= FIMC_MAX_SENSORS)
355 return -EINVAL;
356
357 pd->mux_id = (endpoint.port - 1) & 0x1;
358
359 rem = v4l2_of_get_remote_port_parent(ep);
360 of_node_put(ep);
361 if (rem == NULL) {
362 v4l2_info(&fmd->v4l2_dev, "Remote device at %s not found\n",
363 ep->full_name);
364 return 0;
365 }
366 if (!of_property_read_u32(rem, "samsung,camclk-out", &val))
367 pd->clk_id = val;
368
369 if (!of_property_read_u32(rem, "clock-frequency", &val))
370 pd->clk_frequency = val;
371
372 if (pd->clk_frequency == 0) {
373 v4l2_err(&fmd->v4l2_dev, "Wrong clock frequency at node %s\n",
374 rem->full_name);
375 of_node_put(rem);
376 return -EINVAL;
377 }
378
379 if (fimc_input_is_parallel(endpoint.port)) {
380 if (endpoint.bus_type == V4L2_MBUS_PARALLEL)
381 pd->sensor_bus_type = FIMC_BUS_TYPE_ITU_601;
382 else
383 pd->sensor_bus_type = FIMC_BUS_TYPE_ITU_656;
384 pd->flags = endpoint.bus.parallel.flags;
385 } else if (fimc_input_is_mipi_csi(endpoint.port)) {
386 /*
387 * MIPI CSI-2: only input mux selection and
388 * the sensor's clock frequency is needed.
389 */
390 pd->sensor_bus_type = FIMC_BUS_TYPE_MIPI_CSI2;
391 } else {
392 v4l2_err(&fmd->v4l2_dev, "Wrong port id (%u) at node %s\n",
393 endpoint.port, rem->full_name);
394 }
395 /*
396 * For FIMC-IS handled sensors, that are placed under i2c-isp device
397 * node, FIMC is connected to the FIMC-IS through its ISP Writeback
398 * input. Sensors are attached to the FIMC-LITE hostdata interface
399 * directly or through MIPI-CSIS, depending on the external media bus
400 * used. This needs to be handled in a more reliable way, not by just
401 * checking parent's node name.
402 */
403 np = of_get_parent(rem);
404
405 if (np && !of_node_cmp(np->name, "i2c-isp"))
406 pd->fimc_bus_type = FIMC_BUS_TYPE_ISP_WRITEBACK;
407 else
408 pd->fimc_bus_type = pd->sensor_bus_type;
409
410 ret = fimc_md_of_add_sensor(fmd, rem, index);
411 of_node_put(rem);
412
413 return ret;
414}
415
416/* Register all SoC external sub-devices */
417static int fimc_md_of_sensors_register(struct fimc_md *fmd,
418 struct device_node *np)
419{
420 struct device_node *parent = fmd->pdev->dev.of_node;
421 struct device_node *node, *ports;
422 int index = 0;
423 int ret;
424
425 /* Attach sensors linked to MIPI CSI-2 receivers */
426 for_each_available_child_of_node(parent, node) {
427 struct device_node *port;
428
429 if (of_node_cmp(node->name, "csis"))
430 continue;
431 /* The csis node can have only port subnode. */
432 port = of_get_next_child(node, NULL);
433 if (!port)
434 continue;
435
436 ret = fimc_md_parse_port_node(fmd, port, index);
437 if (ret < 0)
438 return ret;
439 index++;
440 }
441
442 /* Attach sensors listed in the parallel-ports node */
443 ports = of_get_child_by_name(parent, "parallel-ports");
444 if (!ports)
445 return 0;
446
447 for_each_child_of_node(ports, node) {
448 ret = fimc_md_parse_port_node(fmd, node, index);
449 if (ret < 0)
450 break;
451 index++;
452 }
453
454 return 0;
455}
456
Sylwester Nawrockie2985a22013-03-08 12:59:33 -0300457static int __of_get_csis_id(struct device_node *np)
458{
459 u32 reg = 0;
460
461 np = of_get_child_by_name(np, "port");
462 if (!np)
463 return -EINVAL;
464 of_property_read_u32(np, "reg", &reg);
465 return reg - FIMC_INPUT_MIPI_CSI2_0;
466}
467#else
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -0300468#define fimc_md_of_sensors_register(fmd, np) (-ENOSYS)
Sylwester Nawrockie2985a22013-03-08 12:59:33 -0300469#define __of_get_csis_id(np) (-ENOSYS)
470#endif
471
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300472static int fimc_md_register_sensor_entities(struct fimc_md *fmd)
473{
474 struct s5p_platform_fimc *pdata = fmd->pdev->dev.platform_data;
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -0300475 struct device_node *of_node = fmd->pdev->dev.of_node;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300476 struct fimc_dev *fd = NULL;
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -0300477 int num_clients = 0;
478 int ret, i;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300479
480 /*
481 * Runtime resume one of the FIMC entities to make sure
482 * the sclk_cam clocks are not globally disabled.
483 */
484 for (i = 0; !fd && i < ARRAY_SIZE(fmd->fimc); i++)
485 if (fmd->fimc[i])
486 fd = fmd->fimc[i];
487 if (!fd)
488 return -ENXIO;
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -0300489
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300490 ret = pm_runtime_get_sync(&fd->pdev->dev);
491 if (ret < 0)
492 return ret;
493
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -0300494 if (of_node) {
495 fmd->num_sensors = 0;
496 ret = fimc_md_of_sensors_register(fmd, of_node);
497 } else if (pdata) {
498 WARN_ON(pdata->num_clients > ARRAY_SIZE(fmd->sensor));
499 num_clients = min_t(u32, pdata->num_clients,
500 ARRAY_SIZE(fmd->sensor));
501 fmd->num_sensors = num_clients;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300502
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -0300503 for (i = 0; i < num_clients; i++) {
504 struct v4l2_subdev *sd;
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -0300505
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -0300506 fmd->sensor[i].pdata = pdata->source_info[i];
507 ret = __fimc_md_set_camclk(fmd, &fmd->sensor[i], true);
508 if (ret)
509 break;
510 sd = fimc_md_register_sensor(fmd, &fmd->sensor[i]);
511 ret = __fimc_md_set_camclk(fmd, &fmd->sensor[i], false);
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -0300512
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -0300513 if (IS_ERR(sd)) {
514 fmd->sensor[i].subdev = NULL;
515 ret = PTR_ERR(sd);
516 break;
517 }
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -0300518 fmd->sensor[i].subdev = sd;
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -0300519 if (ret)
520 break;
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -0300521 }
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300522 }
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -0300523
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300524 pm_runtime_put(&fd->pdev->dev);
525 return ret;
526}
527
528/*
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300529 * MIPI-CSIS, FIMC and FIMC-LITE platform devices registration.
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300530 */
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300531
532static int register_fimc_lite_entity(struct fimc_md *fmd,
533 struct fimc_lite *fimc_lite)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300534{
Sachin Kamat8163ec02012-10-25 10:56:00 -0300535 struct v4l2_subdev *sd;
Sylwester Nawrockiafd73482012-10-25 10:48:44 -0300536 int ret;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300537
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300538 if (WARN_ON(fimc_lite->index >= FIMC_LITE_MAX_DEVS ||
539 fmd->fimc_lite[fimc_lite->index]))
540 return -EBUSY;
541
542 sd = &fimc_lite->subdev;
543 sd->grp_id = GRP_ID_FLITE;
544 v4l2_set_subdev_hostdata(sd, (void *)&fimc_pipeline_ops);
545
546 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
547 if (!ret)
548 fmd->fimc_lite[fimc_lite->index] = fimc_lite;
549 else
550 v4l2_err(&fmd->v4l2_dev, "Failed to register FIMC.LITE%d\n",
551 fimc_lite->index);
552 return ret;
553}
554
555static int register_fimc_entity(struct fimc_md *fmd, struct fimc_dev *fimc)
556{
557 struct v4l2_subdev *sd;
558 int ret;
559
560 if (WARN_ON(fimc->id >= FIMC_MAX_DEVS || fmd->fimc[fimc->id]))
561 return -EBUSY;
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300562
Sachin Kamat8163ec02012-10-25 10:56:00 -0300563 sd = &fimc->vid_cap.subdev;
Sylwester Nawrocki588c87b2012-11-27 11:57:42 -0300564 sd->grp_id = GRP_ID_FIMC;
Sylwester Nawrocki97d66c42012-11-22 06:17:19 -0300565 v4l2_set_subdev_hostdata(sd, (void *)&fimc_pipeline_ops);
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -0300566
567 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300568 if (!ret) {
569 fmd->fimc[fimc->id] = fimc;
570 fimc->vid_cap.user_subdev_api = fmd->user_subdev_api;
571 } else {
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -0300572 v4l2_err(&fmd->v4l2_dev, "Failed to register FIMC.%d (%d)\n",
573 fimc->id, ret);
574 }
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300575 return ret;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300576}
577
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300578static int register_csis_entity(struct fimc_md *fmd,
579 struct platform_device *pdev,
580 struct v4l2_subdev *sd)
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300581{
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300582 struct device_node *node = pdev->dev.of_node;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300583 int id, ret;
584
Sylwester Nawrockie2985a22013-03-08 12:59:33 -0300585 id = node ? __of_get_csis_id(node) : max(0, pdev->id);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300586
Sylwester Nawrockie2985a22013-03-08 12:59:33 -0300587 if (WARN_ON(id < 0 || id >= CSIS_MAX_ENTITIES))
588 return -ENOENT;
589
590 if (WARN_ON(fmd->csis[id].sd))
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300591 return -EBUSY;
592
Sylwester Nawrocki588c87b2012-11-27 11:57:42 -0300593 sd->grp_id = GRP_ID_CSIS;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300594 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
Sylwester Nawrockiafd73482012-10-25 10:48:44 -0300595 if (!ret)
596 fmd->csis[id].sd = sd;
597 else
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300598 v4l2_err(&fmd->v4l2_dev,
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300599 "Failed to register MIPI-CSIS.%d (%d)\n", id, ret);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300600 return ret;
601}
602
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300603static int fimc_md_register_platform_entity(struct fimc_md *fmd,
604 struct platform_device *pdev,
605 int plat_entity)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300606{
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300607 struct device *dev = &pdev->dev;
608 int ret = -EPROBE_DEFER;
609 void *drvdata;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300610
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300611 /* Lock to ensure dev->driver won't change. */
612 device_lock(dev);
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -0300613
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300614 if (!dev->driver || !try_module_get(dev->driver->owner))
615 goto dev_unlock;
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300616
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300617 drvdata = dev_get_drvdata(dev);
618 /* Some subdev didn't probe succesfully id drvdata is NULL */
619 if (drvdata) {
620 switch (plat_entity) {
621 case IDX_FIMC:
622 ret = register_fimc_entity(fmd, drvdata);
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -0300623 break;
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300624 case IDX_FLITE:
625 ret = register_fimc_lite_entity(fmd, drvdata);
626 break;
627 case IDX_CSIS:
628 ret = register_csis_entity(fmd, pdev, drvdata);
629 break;
630 default:
631 ret = -ENODEV;
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -0300632 }
633 }
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300634
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300635 module_put(dev->driver->owner);
636dev_unlock:
637 device_unlock(dev);
638 if (ret == -EPROBE_DEFER)
639 dev_info(&fmd->pdev->dev, "deferring %s device registration\n",
640 dev_name(dev));
641 else if (ret < 0)
642 dev_err(&fmd->pdev->dev, "%s device registration failed (%d)\n",
643 dev_name(dev), ret);
644 return ret;
645}
646
647static int fimc_md_pdev_match(struct device *dev, void *data)
648{
649 struct platform_device *pdev = to_platform_device(dev);
650 int plat_entity = -1;
651 int ret;
652 char *p;
653
654 if (!get_device(dev))
655 return -ENODEV;
656
657 if (!strcmp(pdev->name, CSIS_DRIVER_NAME)) {
658 plat_entity = IDX_CSIS;
659 } else if (!strcmp(pdev->name, FIMC_LITE_DRV_NAME)) {
660 plat_entity = IDX_FLITE;
661 } else {
662 p = strstr(pdev->name, "fimc");
663 if (p && *(p + 4) == 0)
664 plat_entity = IDX_FIMC;
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -0300665 }
666
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300667 if (plat_entity >= 0)
668 ret = fimc_md_register_platform_entity(data, pdev,
669 plat_entity);
670 put_device(dev);
671 return 0;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300672}
673
Sylwester Nawrockie2985a22013-03-08 12:59:33 -0300674/* Register FIMC, FIMC-LITE and CSIS media entities */
675#ifdef CONFIG_OF
676static int fimc_md_register_of_platform_entities(struct fimc_md *fmd,
677 struct device_node *parent)
678{
679 struct device_node *node;
680 int ret = 0;
681
682 for_each_available_child_of_node(parent, node) {
683 struct platform_device *pdev;
684 int plat_entity = -1;
685
686 pdev = of_find_device_by_node(node);
687 if (!pdev)
688 continue;
689
690 /* If driver of any entity isn't ready try all again later. */
691 if (!strcmp(node->name, CSIS_OF_NODE_NAME))
692 plat_entity = IDX_CSIS;
693 else if (!strcmp(node->name, FIMC_LITE_OF_NODE_NAME))
694 plat_entity = IDX_FLITE;
695 else if (!strcmp(node->name, FIMC_OF_NODE_NAME) &&
696 !of_property_read_bool(node, "samsung,lcd-wb"))
697 plat_entity = IDX_FIMC;
698
699 if (plat_entity >= 0)
700 ret = fimc_md_register_platform_entity(fmd, pdev,
701 plat_entity);
702 put_device(&pdev->dev);
703 if (ret < 0)
704 break;
705 }
706
707 return ret;
708}
709#else
710#define fimc_md_register_of_platform_entities(fmd, node) (-ENOSYS)
711#endif
712
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300713static void fimc_md_unregister_entities(struct fimc_md *fmd)
714{
715 int i;
716
717 for (i = 0; i < FIMC_MAX_DEVS; i++) {
718 if (fmd->fimc[i] == NULL)
719 continue;
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -0300720 v4l2_device_unregister_subdev(&fmd->fimc[i]->vid_cap.subdev);
Sylwester Nawrockib9ee31e62012-08-14 10:46:58 -0300721 fmd->fimc[i]->pipeline_ops = NULL;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300722 fmd->fimc[i] = NULL;
723 }
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300724 for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) {
725 if (fmd->fimc_lite[i] == NULL)
726 continue;
727 v4l2_device_unregister_subdev(&fmd->fimc_lite[i]->subdev);
Sylwester Nawrocki248ac362013-01-11 07:06:28 -0300728 fmd->fimc_lite[i]->pipeline_ops = NULL;
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300729 fmd->fimc_lite[i] = NULL;
730 }
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300731 for (i = 0; i < CSIS_MAX_ENTITIES; i++) {
732 if (fmd->csis[i].sd == NULL)
733 continue;
734 v4l2_device_unregister_subdev(fmd->csis[i].sd);
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -0300735 module_put(fmd->csis[i].sd->owner);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300736 fmd->csis[i].sd = NULL;
737 }
738 for (i = 0; i < fmd->num_sensors; i++) {
739 if (fmd->sensor[i].subdev == NULL)
740 continue;
741 fimc_md_unregister_sensor(fmd->sensor[i].subdev);
742 fmd->sensor[i].subdev = NULL;
743 }
Sylwester Nawrocki7b43a6f2012-12-12 08:16:05 -0300744 v4l2_info(&fmd->v4l2_dev, "Unregistered all entities\n");
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300745}
746
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300747/**
748 * __fimc_md_create_fimc_links - create links to all FIMC entities
749 * @fmd: fimc media device
750 * @source: the source entity to create links to all fimc entities from
751 * @sensor: sensor subdev linked to FIMC[fimc_id] entity, may be null
752 * @pad: the source entity pad index
Sylwester Nawrockid0da3c32012-05-16 13:08:30 -0300753 * @link_mask: bitmask of the fimc devices for which link should be enabled
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300754 */
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300755static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
756 struct media_entity *source,
757 struct v4l2_subdev *sensor,
Sylwester Nawrockid0da3c32012-05-16 13:08:30 -0300758 int pad, int link_mask)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300759{
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300760 struct fimc_sensor_info *s_info = NULL;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300761 struct media_entity *sink;
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300762 unsigned int flags = 0;
Sylwester Nawrocki237e0262011-08-24 20:35:30 -0300763 int ret, i;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300764
765 for (i = 0; i < FIMC_MAX_DEVS; i++) {
766 if (!fmd->fimc[i])
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300767 continue;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300768 /*
769 * Some FIMC variants are not fitted with camera capture
770 * interface. Skip creating a link from sensor for those.
771 */
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300772 if (!fmd->fimc[i]->variant->has_cam_if)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300773 continue;
774
Sylwester Nawrockid0da3c32012-05-16 13:08:30 -0300775 flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0;
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300776
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -0300777 sink = &fmd->fimc[i]->vid_cap.subdev.entity;
Sylwester Nawrocki237e0262011-08-24 20:35:30 -0300778 ret = media_entity_create_link(source, pad, sink,
779 FIMC_SD_PAD_SINK, flags);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300780 if (ret)
781 return ret;
782
Sylwester Nawrocki237e0262011-08-24 20:35:30 -0300783 /* Notify FIMC capture subdev entity */
784 ret = media_entity_call(sink, link_setup, &sink->pads[0],
785 &source->pads[pad], flags);
786 if (ret)
787 break;
788
Sylwester Nawrocki542fb082012-10-25 05:48:19 -0300789 v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]\n",
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300790 source->name, flags ? '=' : '-', sink->name);
791
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300792 if (flags == 0 || sensor == NULL)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300793 continue;
794 s_info = v4l2_get_subdev_hostdata(sensor);
795 if (!WARN_ON(s_info == NULL)) {
796 unsigned long irq_flags;
797 spin_lock_irqsave(&fmd->slock, irq_flags);
798 s_info->host = fmd->fimc[i];
799 spin_unlock_irqrestore(&fmd->slock, irq_flags);
800 }
801 }
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300802
803 for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) {
804 if (!fmd->fimc_lite[i])
805 continue;
806
Sylwester Nawrockid0da3c32012-05-16 13:08:30 -0300807 if (link_mask & (1 << (i + FIMC_MAX_DEVS)))
808 flags = MEDIA_LNK_FL_ENABLED;
809 else
810 flags = 0;
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300811
812 sink = &fmd->fimc_lite[i]->subdev.entity;
813 ret = media_entity_create_link(source, pad, sink,
814 FLITE_SD_PAD_SINK, flags);
815 if (ret)
816 return ret;
817
818 /* Notify FIMC-LITE subdev entity */
819 ret = media_entity_call(sink, link_setup, &sink->pads[0],
820 &source->pads[pad], flags);
821 if (ret)
822 break;
823
Sylwester Nawrocki969e8772012-12-07 16:40:08 -0300824 v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]\n",
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300825 source->name, flags ? '=' : '-', sink->name);
826 }
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300827 return 0;
828}
829
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300830/* Create links from FIMC-LITE source pads to other entities */
831static int __fimc_md_create_flite_source_links(struct fimc_md *fmd)
832{
833 struct media_entity *source, *sink;
834 unsigned int flags = MEDIA_LNK_FL_ENABLED;
Sylwester Nawrockia26860b2012-12-05 13:43:05 -0300835 int i, ret = 0;
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300836
837 for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) {
838 struct fimc_lite *fimc = fmd->fimc_lite[i];
839 if (fimc == NULL)
840 continue;
841 source = &fimc->subdev.entity;
Sylwester Nawrocki1bcd7042012-07-26 07:13:08 -0300842 sink = &fimc->vfd.entity;
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300843 /* FIMC-LITE's subdev and video node */
Sylwester Nawrocki6319d6a2012-11-28 15:41:01 -0300844 ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA,
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300845 sink, 0, flags);
846 if (ret)
847 break;
848 /* TODO: create links to other entities */
849 }
850
851 return ret;
852}
853
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300854/**
855 * fimc_md_create_links - create default links between registered entities
856 *
857 * Parallel interface sensor entities are connected directly to FIMC capture
858 * entities. The sensors using MIPI CSIS bus are connected through immutable
859 * link with CSI receiver entity specified by mux_id. Any registered CSIS
860 * entity has a link to each registered FIMC capture entity. Enabled links
861 * are created by default between each subsequent registered sensor and
862 * subsequent FIMC capture entity. The number of default active links is
863 * determined by the number of available sensors or FIMC entities,
864 * whichever is less.
865 */
866static int fimc_md_create_links(struct fimc_md *fmd)
867{
Sylwester Nawrockia8697ec2012-12-05 13:40:04 -0300868 struct v4l2_subdev *csi_sensors[CSIS_MAX_ENTITIES] = { NULL };
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300869 struct v4l2_subdev *sensor, *csis;
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300870 struct fimc_source_info *pdata;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300871 struct fimc_sensor_info *s_info;
Sylwester Nawrocki237e0262011-08-24 20:35:30 -0300872 struct media_entity *source, *sink;
Sylwester Nawrockid0da3c32012-05-16 13:08:30 -0300873 int i, pad, fimc_id = 0, ret = 0;
874 u32 flags, link_mask = 0;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300875
876 for (i = 0; i < fmd->num_sensors; i++) {
877 if (fmd->sensor[i].subdev == NULL)
878 continue;
879
880 sensor = fmd->sensor[i].subdev;
881 s_info = v4l2_get_subdev_hostdata(sensor);
Sylwester Nawrocki6612a082012-09-17 06:00:48 -0300882 if (!s_info)
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300883 continue;
884
885 source = NULL;
Sylwester Nawrocki6612a082012-09-17 06:00:48 -0300886 pdata = &s_info->pdata;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300887
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300888 switch (pdata->sensor_bus_type) {
889 case FIMC_BUS_TYPE_MIPI_CSI2:
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300890 if (WARN(pdata->mux_id >= CSIS_MAX_ENTITIES,
891 "Wrong CSI channel id: %d\n", pdata->mux_id))
892 return -EINVAL;
893
894 csis = fmd->csis[pdata->mux_id].sd;
895 if (WARN(csis == NULL,
896 "MIPI-CSI interface specified "
897 "but s5p-csis module is not loaded!\n"))
Sylwester Nawrockid12392e2011-10-20 05:15:59 -0300898 return -EINVAL;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300899
Andrzej Hajda1c9f5bd2012-11-22 12:13:27 -0300900 pad = sensor->entity.num_pads - 1;
901 ret = media_entity_create_link(&sensor->entity, pad,
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300902 &csis->entity, CSIS_PAD_SINK,
903 MEDIA_LNK_FL_IMMUTABLE |
904 MEDIA_LNK_FL_ENABLED);
905 if (ret)
906 return ret;
907
Sylwester Nawrocki969e8772012-12-07 16:40:08 -0300908 v4l2_info(&fmd->v4l2_dev, "created link [%s] => [%s]\n",
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300909 sensor->entity.name, csis->entity.name);
910
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300911 source = NULL;
Sylwester Nawrocki5d33ee92012-08-16 14:06:41 -0300912 csi_sensors[pdata->mux_id] = sensor;
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300913 break;
914
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300915 case FIMC_BUS_TYPE_ITU_601...FIMC_BUS_TYPE_ITU_656:
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300916 source = &sensor->entity;
917 pad = 0;
918 break;
919
920 default:
921 v4l2_err(&fmd->v4l2_dev, "Wrong bus_type: %x\n",
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -0300922 pdata->sensor_bus_type);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300923 return -EINVAL;
924 }
925 if (source == NULL)
926 continue;
927
Sylwester Nawrockid0da3c32012-05-16 13:08:30 -0300928 link_mask = 1 << fimc_id++;
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300929 ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor,
Sylwester Nawrockid0da3c32012-05-16 13:08:30 -0300930 pad, link_mask);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300931 }
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300932
Sylwester Nawrockia8697ec2012-12-05 13:40:04 -0300933 for (i = 0; i < CSIS_MAX_ENTITIES; i++) {
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300934 if (fmd->csis[i].sd == NULL)
935 continue;
936 source = &fmd->csis[i].sd->entity;
937 pad = CSIS_PAD_SOURCE;
Sylwester Nawrocki5d33ee92012-08-16 14:06:41 -0300938 sensor = csi_sensors[i];
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300939
Sylwester Nawrockid0da3c32012-05-16 13:08:30 -0300940 link_mask = 1 << fimc_id++;
Sylwester Nawrocki5d33ee92012-08-16 14:06:41 -0300941 ret = __fimc_md_create_fimc_sink_links(fmd, source, sensor,
Sylwester Nawrockid0da3c32012-05-16 13:08:30 -0300942 pad, link_mask);
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300943 }
944
Sylwester Nawrocki237e0262011-08-24 20:35:30 -0300945 /* Create immutable links between each FIMC's subdev and video node */
946 flags = MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED;
947 for (i = 0; i < FIMC_MAX_DEVS; i++) {
948 if (!fmd->fimc[i])
949 continue;
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -0300950 source = &fmd->fimc[i]->vid_cap.subdev.entity;
Sylwester Nawrocki31d34d92012-07-26 07:15:42 -0300951 sink = &fmd->fimc[i]->vid_cap.vfd.entity;
Sylwester Nawrocki237e0262011-08-24 20:35:30 -0300952 ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE,
953 sink, 0, flags);
954 if (ret)
955 break;
956 }
957
Sylwester Nawrocki4af81312012-04-27 05:29:05 -0300958 return __fimc_md_create_flite_source_links(fmd);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300959}
960
961/*
962 * The peripheral sensor clock management.
963 */
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300964static void fimc_md_put_clocks(struct fimc_md *fmd)
965{
966 int i = FIMC_MAX_CAMCLKS;
967
968 while (--i >= 0) {
Sylwester Nawrocki0e23cbb2013-01-18 15:34:37 -0300969 if (IS_ERR(fmd->camclk[i].clock))
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300970 continue;
Sylwester Nawrocki0e23cbb2013-01-18 15:34:37 -0300971 clk_unprepare(fmd->camclk[i].clock);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300972 clk_put(fmd->camclk[i].clock);
Sylwester Nawrocki0e23cbb2013-01-18 15:34:37 -0300973 fmd->camclk[i].clock = ERR_PTR(-EINVAL);
Sylwester Nawrockid3953222011-09-01 06:01:08 -0300974 }
975}
976
Sylwester Nawrocki0e23cbb2013-01-18 15:34:37 -0300977static int fimc_md_get_clocks(struct fimc_md *fmd)
978{
979 struct device *dev = NULL;
980 char clk_name[32];
981 struct clk *clock;
982 int ret, i;
983
984 for (i = 0; i < FIMC_MAX_CAMCLKS; i++)
985 fmd->camclk[i].clock = ERR_PTR(-EINVAL);
986
987 if (fmd->pdev->dev.of_node)
988 dev = &fmd->pdev->dev;
989
990 for (i = 0; i < FIMC_MAX_CAMCLKS; i++) {
991 snprintf(clk_name, sizeof(clk_name), "sclk_cam%u", i);
992 clock = clk_get(dev, clk_name);
993
994 if (IS_ERR(clock)) {
995 dev_err(&fmd->pdev->dev, "Failed to get clock: %s\n",
996 clk_name);
997 ret = PTR_ERR(clock);
998 break;
999 }
1000 ret = clk_prepare(clock);
1001 if (ret < 0) {
1002 clk_put(clock);
1003 fmd->camclk[i].clock = ERR_PTR(-EINVAL);
1004 break;
1005 }
1006 fmd->camclk[i].clock = clock;
1007 }
1008 if (ret)
1009 fimc_md_put_clocks(fmd);
1010
1011 return ret;
1012}
1013
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001014static int __fimc_md_set_camclk(struct fimc_md *fmd,
Sylwester Nawrockie3fc82e2012-05-17 14:22:10 -03001015 struct fimc_sensor_info *s_info,
1016 bool on)
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001017{
Sylwester Nawrocki56bc9112013-02-01 15:00:40 -03001018 struct fimc_source_info *pdata = &s_info->pdata;
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001019 struct fimc_camclk_info *camclk;
1020 int ret = 0;
1021
1022 if (WARN_ON(pdata->clk_id >= FIMC_MAX_CAMCLKS) || fmd == NULL)
1023 return -EINVAL;
1024
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001025 camclk = &fmd->camclk[pdata->clk_id];
1026
Sylwester Nawrockie3fc82e2012-05-17 14:22:10 -03001027 dbg("camclk %d, f: %lu, use_count: %d, on: %d",
1028 pdata->clk_id, pdata->clk_frequency, camclk->use_count, on);
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001029
1030 if (on) {
1031 if (camclk->use_count > 0 &&
1032 camclk->frequency != pdata->clk_frequency)
1033 return -EINVAL;
1034
1035 if (camclk->use_count++ == 0) {
1036 clk_set_rate(camclk->clock, pdata->clk_frequency);
1037 camclk->frequency = pdata->clk_frequency;
1038 ret = clk_enable(camclk->clock);
Sylwester Nawrockie3fc82e2012-05-17 14:22:10 -03001039 dbg("Enabled camclk %d: f: %lu", pdata->clk_id,
1040 clk_get_rate(camclk->clock));
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001041 }
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001042 return ret;
1043 }
1044
1045 if (WARN_ON(camclk->use_count == 0))
1046 return 0;
1047
1048 if (--camclk->use_count == 0) {
1049 clk_disable(camclk->clock);
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001050 dbg("Disabled camclk %d", pdata->clk_id);
1051 }
1052 return ret;
1053}
1054
1055/**
1056 * fimc_md_set_camclk - peripheral sensor clock setup
1057 * @sd: sensor subdev to configure sclk_cam clock for
1058 * @on: 1 to enable or 0 to disable the clock
1059 *
1060 * There are 2 separate clock outputs available in the SoC for external
1061 * image processors. These clocks are shared between all registered FIMC
1062 * devices to which sensors can be attached, either directly or through
1063 * the MIPI CSI receiver. The clock is allowed here to be used by
1064 * multiple sensors concurrently if they use same frequency.
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001065 * This function should only be called when the graph mutex is held.
1066 */
1067int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on)
1068{
1069 struct fimc_sensor_info *s_info = v4l2_get_subdev_hostdata(sd);
1070 struct fimc_md *fmd = entity_to_fimc_mdev(&sd->entity);
1071
1072 return __fimc_md_set_camclk(fmd, s_info, on);
1073}
1074
1075static int fimc_md_link_notify(struct media_pad *source,
1076 struct media_pad *sink, u32 flags)
1077{
Sylwester Nawrocki4af81312012-04-27 05:29:05 -03001078 struct fimc_lite *fimc_lite = NULL;
1079 struct fimc_dev *fimc = NULL;
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -03001080 struct fimc_pipeline *pipeline;
Sylwester Nawrocki237e0262011-08-24 20:35:30 -03001081 struct v4l2_subdev *sd;
Sylwester Nawrocki740ad922012-12-06 10:26:19 -03001082 struct mutex *lock;
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001083 int ret = 0;
Sylwester Nawrocki740ad922012-12-06 10:26:19 -03001084 int ref_count;
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001085
Sylwester Nawrocki237e0262011-08-24 20:35:30 -03001086 if (media_entity_type(sink->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001087 return 0;
1088
Sylwester Nawrocki237e0262011-08-24 20:35:30 -03001089 sd = media_entity_to_v4l2_subdev(sink->entity);
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -03001090
1091 switch (sd->grp_id) {
Sylwester Nawrocki588c87b2012-11-27 11:57:42 -03001092 case GRP_ID_FLITE:
Sylwester Nawrocki4af81312012-04-27 05:29:05 -03001093 fimc_lite = v4l2_get_subdevdata(sd);
Sylwester Nawrocki740ad922012-12-06 10:26:19 -03001094 if (WARN_ON(fimc_lite == NULL))
1095 return 0;
Sylwester Nawrocki4af81312012-04-27 05:29:05 -03001096 pipeline = &fimc_lite->pipeline;
Sylwester Nawrocki740ad922012-12-06 10:26:19 -03001097 lock = &fimc_lite->lock;
Sylwester Nawrocki4af81312012-04-27 05:29:05 -03001098 break;
Sylwester Nawrocki588c87b2012-11-27 11:57:42 -03001099 case GRP_ID_FIMC:
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -03001100 fimc = v4l2_get_subdevdata(sd);
Sylwester Nawrocki740ad922012-12-06 10:26:19 -03001101 if (WARN_ON(fimc == NULL))
1102 return 0;
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -03001103 pipeline = &fimc->pipeline;
Sylwester Nawrocki740ad922012-12-06 10:26:19 -03001104 lock = &fimc->lock;
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -03001105 break;
1106 default:
1107 return 0;
1108 }
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001109
1110 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
Sylwester Nawrocki740ad922012-12-06 10:26:19 -03001111 int i;
1112 mutex_lock(lock);
Sylwester Nawrockib9ee31e62012-08-14 10:46:58 -03001113 ret = __fimc_pipeline_close(pipeline);
Sylwester Nawrocki740ad922012-12-06 10:26:19 -03001114 for (i = 0; i < IDX_MAX; i++)
1115 pipeline->subdevs[i] = NULL;
1116 if (fimc)
Sylwester Nawrocki0f735f52012-04-27 09:33:10 -03001117 fimc_ctrls_delete(fimc->vid_cap.ctx);
Sylwester Nawrocki740ad922012-12-06 10:26:19 -03001118 mutex_unlock(lock);
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001119 return ret;
1120 }
1121 /*
1122 * Link activation. Enable power of pipeline elements only if the
1123 * pipeline is already in use, i.e. its video node is opened.
Sylwester Nawrocki131b6c62011-08-24 19:25:10 -03001124 * Recreate the controls destroyed during the link deactivation.
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001125 */
Sylwester Nawrocki740ad922012-12-06 10:26:19 -03001126 mutex_lock(lock);
1127
1128 ref_count = fimc ? fimc->vid_cap.refcnt : fimc_lite->ref_count;
1129 if (ref_count > 0)
1130 ret = __fimc_pipeline_open(pipeline, source->entity, true);
1131 if (!ret && fimc)
1132 ret = fimc_capture_ctrls_create(fimc);
1133
1134 mutex_unlock(lock);
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001135 return ret ? -EPIPE : ret;
1136}
1137
1138static ssize_t fimc_md_sysfs_show(struct device *dev,
1139 struct device_attribute *attr, char *buf)
1140{
1141 struct platform_device *pdev = to_platform_device(dev);
1142 struct fimc_md *fmd = platform_get_drvdata(pdev);
1143
1144 if (fmd->user_subdev_api)
1145 return strlcpy(buf, "Sub-device API (sub-dev)\n", PAGE_SIZE);
1146
1147 return strlcpy(buf, "V4L2 video node only API (vid-dev)\n", PAGE_SIZE);
1148}
1149
1150static ssize_t fimc_md_sysfs_store(struct device *dev,
1151 struct device_attribute *attr,
1152 const char *buf, size_t count)
1153{
1154 struct platform_device *pdev = to_platform_device(dev);
1155 struct fimc_md *fmd = platform_get_drvdata(pdev);
1156 bool subdev_api;
1157 int i;
1158
1159 if (!strcmp(buf, "vid-dev\n"))
1160 subdev_api = false;
1161 else if (!strcmp(buf, "sub-dev\n"))
1162 subdev_api = true;
1163 else
1164 return count;
1165
1166 fmd->user_subdev_api = subdev_api;
1167 for (i = 0; i < FIMC_MAX_DEVS; i++)
1168 if (fmd->fimc[i])
1169 fmd->fimc[i]->vid_cap.user_subdev_api = subdev_api;
1170 return count;
1171}
1172/*
1173 * This device attribute is to select video pipeline configuration method.
1174 * There are following valid values:
1175 * vid-dev - for V4L2 video node API only, subdevice will be configured
1176 * by the host driver.
1177 * sub-dev - for media controller API, subdevs must be configured in user
1178 * space before starting streaming.
1179 */
1180static DEVICE_ATTR(subdev_conf_mode, S_IWUSR | S_IRUGO,
1181 fimc_md_sysfs_show, fimc_md_sysfs_store);
1182
Sylwester Nawrocki41638512013-03-08 10:41:47 -03001183static int fimc_md_get_pinctrl(struct fimc_md *fmd)
1184{
1185 struct device *dev = &fmd->pdev->dev;
1186 struct fimc_pinctrl *pctl = &fmd->pinctl;
1187
1188 pctl->pinctrl = devm_pinctrl_get(dev);
1189 if (IS_ERR(pctl->pinctrl))
1190 return PTR_ERR(pctl->pinctrl);
1191
1192 pctl->state_default = pinctrl_lookup_state(pctl->pinctrl,
1193 PINCTRL_STATE_DEFAULT);
1194 if (IS_ERR(pctl->state_default))
1195 return PTR_ERR(pctl->state_default);
1196
1197 pctl->state_idle = pinctrl_lookup_state(pctl->pinctrl,
1198 PINCTRL_STATE_IDLE);
1199 return 0;
1200}
1201
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -03001202static int fimc_md_probe(struct platform_device *pdev)
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001203{
Sylwester Nawrockie2985a22013-03-08 12:59:33 -03001204 struct device *dev = &pdev->dev;
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001205 struct v4l2_device *v4l2_dev;
1206 struct fimc_md *fmd;
1207 int ret;
1208
Sylwester Nawrockie2985a22013-03-08 12:59:33 -03001209 fmd = devm_kzalloc(dev, sizeof(*fmd), GFP_KERNEL);
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001210 if (!fmd)
1211 return -ENOMEM;
1212
1213 spin_lock_init(&fmd->slock);
1214 fmd->pdev = pdev;
1215
1216 strlcpy(fmd->media_dev.model, "SAMSUNG S5P FIMC",
1217 sizeof(fmd->media_dev.model));
1218 fmd->media_dev.link_notify = fimc_md_link_notify;
Sylwester Nawrockie2985a22013-03-08 12:59:33 -03001219 fmd->media_dev.dev = dev;
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001220
1221 v4l2_dev = &fmd->v4l2_dev;
1222 v4l2_dev->mdev = &fmd->media_dev;
Sylwester Nawrockie1d72f42011-06-10 15:36:58 -03001223 v4l2_dev->notify = fimc_sensor_notify;
Sylwester Nawrockie2985a22013-03-08 12:59:33 -03001224 strlcpy(v4l2_dev->name, "s5p-fimc-md", sizeof(v4l2_dev->name));
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001225
Sylwester Nawrockie2985a22013-03-08 12:59:33 -03001226 ret = v4l2_device_register(dev, &fmd->v4l2_dev);
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001227 if (ret < 0) {
1228 v4l2_err(v4l2_dev, "Failed to register v4l2_device: %d\n", ret);
Sylwester Nawrocki6d91a512012-01-30 11:37:59 -03001229 return ret;
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001230 }
1231 ret = media_device_register(&fmd->media_dev);
1232 if (ret < 0) {
1233 v4l2_err(v4l2_dev, "Failed to register media device: %d\n", ret);
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -03001234 goto err_md;
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001235 }
1236 ret = fimc_md_get_clocks(fmd);
1237 if (ret)
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -03001238 goto err_clk;
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001239
Sylwester Nawrockie2985a22013-03-08 12:59:33 -03001240 fmd->user_subdev_api = (dev->of_node != NULL);
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -03001241
1242 /* Protect the media graph while we're registering entities */
1243 mutex_lock(&fmd->media_dev.graph_mutex);
1244
Sylwester Nawrocki41638512013-03-08 10:41:47 -03001245 ret = fimc_md_get_pinctrl(fmd);
1246 if (ret < 0) {
1247 if (ret != EPROBE_DEFER)
1248 dev_err(dev, "Failed to get pinctrl: %d\n", ret);
1249 goto err_unlock;
1250 }
1251
Sylwester Nawrockie2985a22013-03-08 12:59:33 -03001252 if (dev->of_node)
1253 ret = fimc_md_register_of_platform_entities(fmd, dev->of_node);
1254 else
1255 ret = bus_for_each_dev(&platform_bus_type, NULL, fmd,
1256 fimc_md_pdev_match);
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001257 if (ret)
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -03001258 goto err_unlock;
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001259
Sylwester Nawrocki2b13f7d2013-03-29 14:12:39 -03001260 if (dev->platform_data || dev->of_node) {
Sylwester Nawrocki5cbf6f162011-10-07 07:40:00 -03001261 ret = fimc_md_register_sensor_entities(fmd);
1262 if (ret)
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -03001263 goto err_unlock;
Sylwester Nawrocki5cbf6f162011-10-07 07:40:00 -03001264 }
Sylwester Nawrockie2985a22013-03-08 12:59:33 -03001265
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001266 ret = fimc_md_create_links(fmd);
1267 if (ret)
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -03001268 goto err_unlock;
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001269 ret = v4l2_device_register_subdev_nodes(&fmd->v4l2_dev);
1270 if (ret)
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -03001271 goto err_unlock;
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001272
1273 ret = device_create_file(&pdev->dev, &dev_attr_subdev_conf_mode);
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -03001274 if (ret)
1275 goto err_unlock;
1276
1277 platform_set_drvdata(pdev, fmd);
1278 mutex_unlock(&fmd->media_dev.graph_mutex);
1279 return 0;
1280
1281err_unlock:
1282 mutex_unlock(&fmd->media_dev.graph_mutex);
1283err_clk:
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001284 media_device_unregister(&fmd->media_dev);
1285 fimc_md_put_clocks(fmd);
1286 fimc_md_unregister_entities(fmd);
Sylwester Nawrocki693f5c42012-04-20 18:57:25 -03001287err_md:
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001288 v4l2_device_unregister(&fmd->v4l2_dev);
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001289 return ret;
1290}
1291
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001292static int fimc_md_remove(struct platform_device *pdev)
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001293{
1294 struct fimc_md *fmd = platform_get_drvdata(pdev);
1295
1296 if (!fmd)
1297 return 0;
1298 device_remove_file(&pdev->dev, &dev_attr_subdev_conf_mode);
1299 fimc_md_unregister_entities(fmd);
1300 media_device_unregister(&fmd->media_dev);
1301 fimc_md_put_clocks(fmd);
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001302 return 0;
1303}
1304
Sylwester Nawrockie2985a22013-03-08 12:59:33 -03001305static struct platform_device_id fimc_driver_ids[] __always_unused = {
1306 { .name = "s5p-fimc-md" },
1307 { },
1308};
1309MODULE_DEVICE_TABLE(platform, fimc_driver_ids);
1310
1311static const struct of_device_id fimc_md_of_match[] = {
1312 { .compatible = "samsung,fimc" },
1313 { },
1314};
1315MODULE_DEVICE_TABLE(of, fimc_md_of_match);
1316
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001317static struct platform_driver fimc_md_driver = {
1318 .probe = fimc_md_probe,
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001319 .remove = fimc_md_remove,
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001320 .driver = {
Sylwester Nawrockie2985a22013-03-08 12:59:33 -03001321 .of_match_table = of_match_ptr(fimc_md_of_match),
1322 .name = "s5p-fimc-md",
1323 .owner = THIS_MODULE,
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001324 }
1325};
1326
Sachin Kamat7e566be2012-05-26 11:11:54 -03001327static int __init fimc_md_init(void)
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001328{
1329 int ret;
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -03001330
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001331 request_module("s5p-csis");
1332 ret = fimc_register_driver();
1333 if (ret)
1334 return ret;
Sylwester Nawrockiecd9acb2012-03-21 09:58:09 -03001335
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001336 return platform_driver_register(&fimc_md_driver);
1337}
Sachin Kamat7e566be2012-05-26 11:11:54 -03001338
1339static void __exit fimc_md_exit(void)
Sylwester Nawrockid3953222011-09-01 06:01:08 -03001340{
1341 platform_driver_unregister(&fimc_md_driver);
1342 fimc_unregister_driver();
1343}
1344
1345module_init(fimc_md_init);
1346module_exit(fimc_md_exit);
1347
1348MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
1349MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver");
1350MODULE_LICENSE("GPL");
1351MODULE_VERSION("2.0.1");