fimc-mdevice.c 33 KB

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