Lines Matching +full:fimc +full:- +full:isp

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd.
11 #include <linux/clk-provider.h>
27 #include <media/v4l2-async.h>
28 #include <media/v4l2-ctrls.h>
29 #include <media/v4l2-fwnode.h>
30 #include <media/media-device.h>
31 #include <media/drv-intf/exynos-fimc.h>
33 #include "media-dev.h"
34 #include "fimc-core.h"
35 #include "fimc-is.h"
36 #include "fimc-lite.h"
37 #include "mipi-csis.h"
39 /* Set up image sensor subdev -> FIMC capture node notifications. */
53 spin_lock_irqsave(&fmd->slock, flags); in __setup_sensor_notification()
54 md_si->host = v4l2_get_subdevdata(fimc_sd); in __setup_sensor_notification()
55 spin_unlock_irqrestore(&fmd->slock, flags); in __setup_sensor_notification()
59 * fimc_pipeline_prepare - update pipeline information with subdevice pointers
60 * @p: fimc pipeline
74 p->subdevs[i] = NULL; in fimc_pipeline_prepare()
80 for (i = 0; i < me->num_pads; i++) { in fimc_pipeline_prepare()
81 struct media_pad *spad = &me->pads[i]; in fimc_pipeline_prepare()
82 if (!(spad->flags & MEDIA_PAD_FL_SINK)) in fimc_pipeline_prepare()
89 if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) in fimc_pipeline_prepare()
91 sd = media_entity_to_v4l2_subdev(pad->entity); in fimc_pipeline_prepare()
93 switch (sd->grp_id) { in fimc_pipeline_prepare()
98 p->subdevs[IDX_SENSOR] = sd; in fimc_pipeline_prepare()
101 p->subdevs[IDX_CSIS] = sd; in fimc_pipeline_prepare()
104 p->subdevs[IDX_FLITE] = sd; in fimc_pipeline_prepare()
107 p->subdevs[IDX_FIMC] = sd; in fimc_pipeline_prepare()
110 p->subdevs[IDX_IS_ISP] = sd; in fimc_pipeline_prepare()
115 me = &sd->entity; in fimc_pipeline_prepare()
116 if (me->num_pads == 1) in fimc_pipeline_prepare()
120 if (sensor && p->subdevs[IDX_FIMC]) in fimc_pipeline_prepare()
121 __setup_sensor_notification(fmd, sensor, p->subdevs[IDX_FIMC]); in fimc_pipeline_prepare()
125 * __subdev_set_power - change power state of a single subdev
129 * Return result of s_power subdev operation or -ENXIO if sd argument
138 return -ENXIO; in __subdev_set_power()
140 use_count = &sd->entity.use_count; in __subdev_set_power()
143 else if (!on && (*use_count == 0 || --(*use_count) > 0)) in __subdev_set_power()
147 return ret != -ENOIOCTLCMD ? ret : 0; in __subdev_set_power()
151 * fimc_pipeline_s_power - change power state of all pipeline subdevs
152 * @p: fimc device terminating the pipeline
159 static const u8 seq[2][IDX_MAX - 1] = { in fimc_pipeline_s_power()
165 if (p->subdevs[IDX_SENSOR] == NULL) in fimc_pipeline_s_power()
166 return -ENXIO; in fimc_pipeline_s_power()
168 for (i = 0; i < IDX_MAX - 1; i++) { in fimc_pipeline_s_power()
171 ret = __subdev_set_power(p->subdevs[idx], on); in fimc_pipeline_s_power()
174 if (ret < 0 && ret != -ENXIO) in fimc_pipeline_s_power()
179 for (; i >= 0; i--) { in fimc_pipeline_s_power()
181 __subdev_set_power(p->subdevs[idx], !on); in fimc_pipeline_s_power()
187 * __fimc_pipeline_enable - enable power of all pipeline subdevs
190 * @fmd: fimc media device
200 /* Enable PXLASYNC clock if this pipeline includes FIMC-IS */ in __fimc_pipeline_enable()
201 if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP]) { in __fimc_pipeline_enable()
202 ret = clk_prepare_enable(fmd->wbclk[CLK_IDX_WB_B]); in __fimc_pipeline_enable()
211 if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP]) in __fimc_pipeline_enable()
212 clk_disable_unprepare(fmd->wbclk[CLK_IDX_WB_B]); in __fimc_pipeline_enable()
218 * __fimc_pipeline_open - update the pipeline information, enable power
220 * @ep: fimc device terminating the pipeline
234 return -EINVAL; in __fimc_pipeline_open()
239 sd = p->subdevs[IDX_SENSOR]; in __fimc_pipeline_open()
253 * __fimc_pipeline_close - disable the sensor clock and pipeline power
254 * @ep: fimc device terminating the pipeline
261 struct v4l2_subdev *sd = p ? p->subdevs[IDX_SENSOR] : NULL; in __fimc_pipeline_close()
272 fmd = entity_to_fimc_mdev(&sd->entity); in __fimc_pipeline_close()
274 /* Disable PXLASYNC clock if this pipeline includes FIMC-IS */ in __fimc_pipeline_close()
275 if (!IS_ERR(fmd->wbclk[CLK_IDX_WB_B]) && p->subdevs[IDX_IS_ISP]) in __fimc_pipeline_close()
276 clk_disable_unprepare(fmd->wbclk[CLK_IDX_WB_B]); in __fimc_pipeline_close()
278 return ret == -ENXIO ? 0 : ret; in __fimc_pipeline_close()
282 * __fimc_pipeline_s_stream - call s_stream() on pipeline subdevs
296 if (p->subdevs[IDX_SENSOR] == NULL) { in __fimc_pipeline_s_stream()
298 struct v4l2_subdev *sd = p->subdevs[IDX_CSIS]; in __fimc_pipeline_s_stream()
301 sd = p->subdevs[IDX_FIMC]; in __fimc_pipeline_s_stream()
305 * If neither CSIS nor FIMC was set up, in __fimc_pipeline_s_stream()
308 return -ENODEV; in __fimc_pipeline_s_stream()
311 fmd = entity_to_fimc_mdev(&sd->entity); in __fimc_pipeline_s_stream()
313 if (!fmd->user_subdev_api) { in __fimc_pipeline_s_stream()
318 return -ENODEV; in __fimc_pipeline_s_stream()
322 if (p->subdevs[IDX_FIMC]) in __fimc_pipeline_s_stream()
324 else if (p->subdevs[IDX_IS_ISP]) in __fimc_pipeline_s_stream()
326 else if (p->subdevs[IDX_FLITE]) in __fimc_pipeline_s_stream()
329 return -ENODEV; in __fimc_pipeline_s_stream()
332 * Sensor could have been linked between open and STREAMON - in __fimc_pipeline_s_stream()
335 fimc_pipeline_prepare(p, &p->subdevs[sd_id]->entity); in __fimc_pipeline_s_stream()
337 if (p->subdevs[IDX_SENSOR] == NULL) in __fimc_pipeline_s_stream()
338 return -ENODEV; in __fimc_pipeline_s_stream()
349 ret = v4l2_subdev_call(p->subdevs[idx], video, s_stream, on); in __fimc_pipeline_s_stream()
351 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) in __fimc_pipeline_s_stream()
358 for (; i >= 0; i--) { in __fimc_pipeline_s_stream()
360 v4l2_subdev_call(p->subdevs[idx], video, s_stream, !on); in __fimc_pipeline_s_stream()
365 /* Media pipeline operations for the FIMC/FIMC-LITE video device driver */
381 list_add_tail(&p->list, &fmd->pipelines); in fimc_md_pipeline_create()
383 p->ep.ops = &fimc_pipeline_ops; in fimc_md_pipeline_create()
384 return &p->ep; in fimc_md_pipeline_create()
389 while (!list_empty(&fmd->pipelines)) { in fimc_md_pipelines_free()
392 p = list_entry(fmd->pipelines.next, typeof(*p), list); in fimc_md_pipelines_free()
393 list_del(&p->list); in fimc_md_pipelines_free()
401 int index = fmd->num_sensors; in fimc_md_parse_one_endpoint()
402 struct fimc_source_info *pd = &fmd->sensor[index].pdata; in fimc_md_parse_one_endpoint()
416 return -EINVAL; in fimc_md_parse_one_endpoint()
419 pd->mux_id = (endpoint.base.port - 1) & 0x1; in fimc_md_parse_one_endpoint()
423 v4l2_info(&fmd->v4l2_dev, "Remote device at %pOF not found\n", in fimc_md_parse_one_endpoint()
431 pd->sensor_bus_type = FIMC_BUS_TYPE_ITU_601; in fimc_md_parse_one_endpoint()
433 pd->sensor_bus_type = FIMC_BUS_TYPE_ITU_656; in fimc_md_parse_one_endpoint()
434 pd->flags = endpoint.bus.parallel.flags; in fimc_md_parse_one_endpoint()
437 * MIPI CSI-2: only input mux selection and in fimc_md_parse_one_endpoint()
440 pd->sensor_bus_type = FIMC_BUS_TYPE_MIPI_CSI2; in fimc_md_parse_one_endpoint()
442 v4l2_err(&fmd->v4l2_dev, "Wrong port id (%u) at node %pOF\n", in fimc_md_parse_one_endpoint()
446 * For FIMC-IS handled sensors, that are placed under i2c-isp device in fimc_md_parse_one_endpoint()
447 * node, FIMC is connected to the FIMC-IS through its ISP Writeback in fimc_md_parse_one_endpoint()
448 * input. Sensors are attached to the FIMC-LITE hostdata interface in fimc_md_parse_one_endpoint()
449 * directly or through MIPI-CSIS, depending on the external media bus in fimc_md_parse_one_endpoint()
456 if (of_node_name_eq(np, "i2c-isp")) in fimc_md_parse_one_endpoint()
457 pd->fimc_bus_type = FIMC_BUS_TYPE_ISP_WRITEBACK; in fimc_md_parse_one_endpoint()
459 pd->fimc_bus_type = pd->sensor_bus_type; in fimc_md_parse_one_endpoint()
462 if (WARN_ON(index >= ARRAY_SIZE(fmd->sensor))) { in fimc_md_parse_one_endpoint()
464 return -EINVAL; in fimc_md_parse_one_endpoint()
467 asd = v4l2_async_nf_add_fwnode_remote(&fmd->subdev_notifier, in fimc_md_parse_one_endpoint()
476 fmd->sensor[index].asd = asd; in fimc_md_parse_one_endpoint()
477 fmd->num_sensors++; in fimc_md_parse_one_endpoint()
482 /* Parse port node and register as a sub-device any sensor specified there. */
500 /* Register all SoC external sub-devices */
503 struct device_node *parent = fmd->pdev->dev.of_node; in fimc_md_register_sensor_entities()
509 * Runtime resume one of the FIMC entities to make sure in fimc_md_register_sensor_entities()
512 if (!fmd->pmf) in fimc_md_register_sensor_entities()
513 return -ENXIO; in fimc_md_register_sensor_entities()
515 ret = pm_runtime_resume_and_get(fmd->pmf); in fimc_md_register_sensor_entities()
519 fmd->num_sensors = 0; in fimc_md_register_sensor_entities()
521 /* Attach sensors linked to MIPI CSI-2 receivers */ in fimc_md_register_sensor_entities()
540 /* Attach sensors listed in the parallel-ports node */ in fimc_md_register_sensor_entities()
541 ports = of_get_child_by_name(parent, "parallel-ports"); in fimc_md_register_sensor_entities()
555 pm_runtime_put(fmd->pmf); in fimc_md_register_sensor_entities()
560 v4l2_async_nf_cleanup(&fmd->subdev_notifier); in fimc_md_register_sensor_entities()
561 pm_runtime_put(fmd->pmf); in fimc_md_register_sensor_entities()
571 return -EINVAL; in __of_get_csis_id()
574 return reg - FIMC_INPUT_MIPI_CSI2_0; in __of_get_csis_id()
578 * MIPI-CSIS, FIMC and FIMC-LITE platform devices registration.
587 if (WARN_ON(fimc_lite->index >= FIMC_LITE_MAX_DEVS || in register_fimc_lite_entity()
588 fmd->fimc_lite[fimc_lite->index])) in register_fimc_lite_entity()
589 return -EBUSY; in register_fimc_lite_entity()
591 sd = &fimc_lite->subdev; in register_fimc_lite_entity()
592 sd->grp_id = GRP_ID_FLITE; in register_fimc_lite_entity()
596 return -ENOMEM; in register_fimc_lite_entity()
600 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); in register_fimc_lite_entity()
602 fmd->fimc_lite[fimc_lite->index] = fimc_lite; in register_fimc_lite_entity()
604 v4l2_err(&fmd->v4l2_dev, "Failed to register FIMC.LITE%d\n", in register_fimc_lite_entity()
605 fimc_lite->index); in register_fimc_lite_entity()
609 static int register_fimc_entity(struct fimc_md *fmd, struct fimc_dev *fimc) in register_fimc_entity() argument
615 if (WARN_ON(fimc->id >= FIMC_MAX_DEVS || fmd->fimc[fimc->id])) in register_fimc_entity()
616 return -EBUSY; in register_fimc_entity()
618 sd = &fimc->vid_cap.subdev; in register_fimc_entity()
619 sd->grp_id = GRP_ID_FIMC; in register_fimc_entity()
623 return -ENOMEM; in register_fimc_entity()
627 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); in register_fimc_entity()
629 if (!fmd->pmf && fimc->pdev) in register_fimc_entity()
630 fmd->pmf = &fimc->pdev->dev; in register_fimc_entity()
631 fmd->fimc[fimc->id] = fimc; in register_fimc_entity()
632 fimc->vid_cap.user_subdev_api = fmd->user_subdev_api; in register_fimc_entity()
634 v4l2_err(&fmd->v4l2_dev, "Failed to register FIMC.%d (%d)\n", in register_fimc_entity()
635 fimc->id, ret); in register_fimc_entity()
644 struct device_node *node = pdev->dev.of_node; in register_csis_entity()
647 id = node ? __of_get_csis_id(node) : max(0, pdev->id); in register_csis_entity()
650 return -ENOENT; in register_csis_entity()
652 if (WARN_ON(fmd->csis[id].sd)) in register_csis_entity()
653 return -EBUSY; in register_csis_entity()
655 sd->grp_id = GRP_ID_CSIS; in register_csis_entity()
656 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); in register_csis_entity()
658 fmd->csis[id].sd = sd; in register_csis_entity()
660 v4l2_err(&fmd->v4l2_dev, in register_csis_entity()
661 "Failed to register MIPI-CSIS.%d (%d)\n", id, ret); in register_csis_entity()
667 struct v4l2_subdev *sd = &is->isp.subdev; in register_fimc_is_entity()
671 /* Allocate pipeline object for the ISP capture video node. */ in register_fimc_is_entity()
674 return -ENOMEM; in register_fimc_is_entity()
678 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); in register_fimc_is_entity()
680 v4l2_err(&fmd->v4l2_dev, in register_fimc_is_entity()
681 "Failed to register FIMC-ISP (%d)\n", ret); in register_fimc_is_entity()
685 fmd->fimc_is = is; in register_fimc_is_entity()
693 struct device *dev = &pdev->dev; in fimc_md_register_platform_entity()
694 int ret = -EPROBE_DEFER; in fimc_md_register_platform_entity()
697 /* Lock to ensure dev->driver won't change. */ in fimc_md_register_platform_entity()
700 if (!dev->driver || !try_module_get(dev->driver->owner)) in fimc_md_register_platform_entity()
720 ret = -ENODEV; in fimc_md_register_platform_entity()
724 module_put(dev->driver->owner); in fimc_md_register_platform_entity()
727 if (ret == -EPROBE_DEFER) in fimc_md_register_platform_entity()
728 dev_info(&fmd->pdev->dev, "deferring %s device registration\n", in fimc_md_register_platform_entity()
731 dev_err(&fmd->pdev->dev, "%s device registration failed (%d)\n", in fimc_md_register_platform_entity()
736 /* Register FIMC, FIMC-LITE and CSIS media entities */
745 int plat_entity = -1; in fimc_md_register_platform_entities()
759 !of_property_read_bool(node, "samsung,lcd-wb")) in fimc_md_register_platform_entities()
765 put_device(&pdev->dev); in fimc_md_register_platform_entities()
780 struct fimc_dev *dev = fmd->fimc[i]; in fimc_md_unregister_entities()
783 v4l2_device_unregister_subdev(&dev->vid_cap.subdev); in fimc_md_unregister_entities()
784 dev->vid_cap.ve.pipe = NULL; in fimc_md_unregister_entities()
785 fmd->fimc[i] = NULL; in fimc_md_unregister_entities()
788 struct fimc_lite *dev = fmd->fimc_lite[i]; in fimc_md_unregister_entities()
791 v4l2_device_unregister_subdev(&dev->subdev); in fimc_md_unregister_entities()
792 dev->ve.pipe = NULL; in fimc_md_unregister_entities()
793 fmd->fimc_lite[i] = NULL; in fimc_md_unregister_entities()
796 if (fmd->csis[i].sd == NULL) in fimc_md_unregister_entities()
798 v4l2_device_unregister_subdev(fmd->csis[i].sd); in fimc_md_unregister_entities()
799 fmd->csis[i].sd = NULL; in fimc_md_unregister_entities()
802 if (fmd->fimc_is) in fimc_md_unregister_entities()
803 v4l2_device_unregister_subdev(&fmd->fimc_is->isp.subdev); in fimc_md_unregister_entities()
805 v4l2_info(&fmd->v4l2_dev, "Unregistered all entities\n"); in fimc_md_unregister_entities()
809 * __fimc_md_create_fimc_sink_links - create links to all FIMC entities
810 * @fmd: fimc media device
811 * @source: the source entity to create links to all fimc entities from
812 * @sensor: sensor subdev linked to FIMC[fimc_id] entity, may be null
814 * @link_mask: bitmask of the fimc devices for which link should be enabled
828 /* Skip direct FIMC links in the logical FIMC-IS sensor path */ in __fimc_md_create_fimc_sink_links()
829 if (si && si->fimc_bus_type == FIMC_BUS_TYPE_ISP_WRITEBACK) in __fimc_md_create_fimc_sink_links()
834 if (!fmd->fimc[i]) in __fimc_md_create_fimc_sink_links()
837 * Some FIMC variants are not fitted with camera capture in __fimc_md_create_fimc_sink_links()
840 if (!fmd->fimc[i]->variant->has_cam_if) in __fimc_md_create_fimc_sink_links()
845 sink = &fmd->fimc[i]->vid_cap.subdev.entity; in __fimc_md_create_fimc_sink_links()
851 /* Notify FIMC capture subdev entity */ in __fimc_md_create_fimc_sink_links()
852 ret = media_entity_call(sink, link_setup, &sink->pads[0], in __fimc_md_create_fimc_sink_links()
853 &source->pads[pad], flags); in __fimc_md_create_fimc_sink_links()
857 v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]\n", in __fimc_md_create_fimc_sink_links()
858 source->name, flags ? '=' : '-', sink->name); in __fimc_md_create_fimc_sink_links()
862 if (!fmd->fimc_lite[i]) in __fimc_md_create_fimc_sink_links()
865 sink = &fmd->fimc_lite[i]->subdev.entity; in __fimc_md_create_fimc_sink_links()
871 /* Notify FIMC-LITE subdev entity */ in __fimc_md_create_fimc_sink_links()
872 ret = media_entity_call(sink, link_setup, &sink->pads[0], in __fimc_md_create_fimc_sink_links()
873 &source->pads[pad], 0); in __fimc_md_create_fimc_sink_links()
877 v4l2_info(&fmd->v4l2_dev, "created link [%s] -> [%s]\n", in __fimc_md_create_fimc_sink_links()
878 source->name, sink->name); in __fimc_md_create_fimc_sink_links()
883 /* Create links from FIMC-LITE source pads to other entities */
890 struct fimc_lite *fimc = fmd->fimc_lite[i]; in __fimc_md_create_flite_source_links() local
892 if (fimc == NULL) in __fimc_md_create_flite_source_links()
895 source = &fimc->subdev.entity; in __fimc_md_create_flite_source_links()
896 sink = &fimc->ve.vdev.entity; in __fimc_md_create_flite_source_links()
897 /* FIMC-LITE's subdev and video node */ in __fimc_md_create_flite_source_links()
902 /* Link from FIMC-LITE to IS-ISP subdev */ in __fimc_md_create_flite_source_links()
903 sink = &fmd->fimc_is->isp.subdev.entity; in __fimc_md_create_flite_source_links()
913 /* Create FIMC-IS links */
916 struct fimc_isp *isp = &fmd->fimc_is->isp; in __fimc_md_create_fimc_is_links() local
920 source = &isp->subdev.entity; in __fimc_md_create_fimc_is_links()
923 if (fmd->fimc[i] == NULL) in __fimc_md_create_fimc_is_links()
926 /* Link from FIMC-IS-ISP subdev to FIMC */ in __fimc_md_create_fimc_is_links()
927 sink = &fmd->fimc[i]->vid_cap.subdev.entity; in __fimc_md_create_fimc_is_links()
934 /* Link from FIMC-IS-ISP subdev to fimc-is-isp.capture video node */ in __fimc_md_create_fimc_is_links()
935 sink = &isp->video_capture.ve.vdev.entity; in __fimc_md_create_fimc_is_links()
937 /* Skip this link if the fimc-is-isp video node driver isn't built-in */ in __fimc_md_create_fimc_is_links()
938 if (sink->num_pads == 0) in __fimc_md_create_fimc_is_links()
946 * fimc_md_create_links - create default links between registered entities
947 * @fmd: fimc media device
949 * Parallel interface sensor entities are connected directly to FIMC capture
952 * entity has a link to each registered FIMC capture entity. Enabled links
954 * subsequent FIMC capture entity. The number of default active links is
955 * determined by the number of available sensors or FIMC entities,
967 for (i = 0; i < fmd->num_sensors; i++) { in fimc_md_create_links()
968 if (fmd->sensor[i].subdev == NULL) in fimc_md_create_links()
971 sensor = fmd->sensor[i].subdev; in fimc_md_create_links()
978 switch (pdata->sensor_bus_type) { in fimc_md_create_links()
980 if (WARN(pdata->mux_id >= CSIS_MAX_ENTITIES, in fimc_md_create_links()
981 "Wrong CSI channel id: %d\n", pdata->mux_id)) in fimc_md_create_links()
982 return -EINVAL; in fimc_md_create_links()
984 csis = fmd->csis[pdata->mux_id].sd; in fimc_md_create_links()
986 "MIPI-CSI interface specified but s5p-csis module is not loaded!\n")) in fimc_md_create_links()
987 return -EINVAL; in fimc_md_create_links()
989 pad = sensor->entity.num_pads - 1; in fimc_md_create_links()
990 ret = media_create_pad_link(&sensor->entity, pad, in fimc_md_create_links()
991 &csis->entity, CSIS_PAD_SINK, in fimc_md_create_links()
997 v4l2_info(&fmd->v4l2_dev, "created link [%s] => [%s]\n", in fimc_md_create_links()
998 sensor->entity.name, csis->entity.name); in fimc_md_create_links()
1001 csi_sensors[pdata->mux_id] = sensor; in fimc_md_create_links()
1005 source = &sensor->entity; in fimc_md_create_links()
1010 v4l2_err(&fmd->v4l2_dev, "Wrong bus_type: %x\n", in fimc_md_create_links()
1011 pdata->sensor_bus_type); in fimc_md_create_links()
1012 return -EINVAL; in fimc_md_create_links()
1023 if (fmd->csis[i].sd == NULL) in fimc_md_create_links()
1026 source = &fmd->csis[i].sd->entity; in fimc_md_create_links()
1035 /* Create immutable links between each FIMC's subdev and video node */ in fimc_md_create_links()
1038 if (!fmd->fimc[i]) in fimc_md_create_links()
1041 source = &fmd->fimc[i]->vid_cap.subdev.entity; in fimc_md_create_links()
1042 sink = &fmd->fimc[i]->vid_cap.ve.vdev.entity; in fimc_md_create_links()
1054 if (fmd->use_isp) in fimc_md_create_links()
1067 while (--i >= 0) { in fimc_md_put_clocks()
1068 if (IS_ERR(fmd->camclk[i].clock)) in fimc_md_put_clocks()
1070 clk_put(fmd->camclk[i].clock); in fimc_md_put_clocks()
1071 fmd->camclk[i].clock = ERR_PTR(-EINVAL); in fimc_md_put_clocks()
1076 if (IS_ERR(fmd->wbclk[i])) in fimc_md_put_clocks()
1078 clk_put(fmd->wbclk[i]); in fimc_md_put_clocks()
1079 fmd->wbclk[i] = ERR_PTR(-EINVAL); in fimc_md_put_clocks()
1085 struct device *dev = &fmd->pdev->dev; in fimc_md_get_clocks()
1091 fmd->camclk[i].clock = ERR_PTR(-EINVAL); in fimc_md_get_clocks()
1102 fmd->camclk[i].clock = clock; in fimc_md_get_clocks()
1107 if (!fmd->use_isp) in fimc_md_get_clocks()
1110 * For now get only PIXELASYNCM1 clock (Writeback B/ISP), in fimc_md_get_clocks()
1113 fmd->wbclk[CLK_IDX_WB_A] = ERR_PTR(-EINVAL); in fimc_md_get_clocks()
1119 v4l2_err(&fmd->v4l2_dev, "Failed to get clock: %s\n", in fimc_md_get_clocks()
1124 fmd->wbclk[i] = clock; in fimc_md_get_clocks()
1140 if (vdev->entity.use_count == 0) in __fimc_md_modify_pipeline()
1144 p = to_fimc_pipeline(ve->pipe); in __fimc_md_modify_pipeline()
1147 * has been disconnected and p->subdevs array is cleared now. in __fimc_md_modify_pipeline()
1149 if (!enable && p->subdevs[IDX_SENSOR] == NULL) in __fimc_md_modify_pipeline()
1153 ret = __fimc_pipeline_open(ve->pipe, entity, true); in __fimc_md_modify_pipeline()
1155 ret = __fimc_pipeline_close(ve->pipe); in __fimc_md_modify_pipeline()
1158 memset(p->subdevs, 0, sizeof(p->subdevs)); in __fimc_md_modify_pipeline()
1163 /* Locking: called with entity->graph_obj.mdev->graph_mutex mutex held. */
1210 &container_of(link->graph_obj.mdev, struct fimc_md, in fimc_md_link_notify()
1211 media_dev)->link_setup_graph; in fimc_md_link_notify()
1212 struct media_entity *sink = link->sink->entity; in fimc_md_link_notify()
1218 link->graph_obj.mdev); in fimc_md_link_notify()
1229 if (link->flags & MEDIA_LNK_FL_ENABLED) in fimc_md_link_notify()
1234 return ret ? -EPIPE : 0; in fimc_md_link_notify()
1246 if (fmd->user_subdev_api) in subdev_conf_mode_show()
1247 return strscpy(buf, "Sub-device API (sub-dev)\n", PAGE_SIZE); in subdev_conf_mode_show()
1249 return strscpy(buf, "V4L2 video node only API (vid-dev)\n", PAGE_SIZE); in subdev_conf_mode_show()
1260 if (!strcmp(buf, "vid-dev\n")) in subdev_conf_mode_store()
1262 else if (!strcmp(buf, "sub-dev\n")) in subdev_conf_mode_store()
1267 fmd->user_subdev_api = subdev_api; in subdev_conf_mode_store()
1269 if (fmd->fimc[i]) in subdev_conf_mode_store()
1270 fmd->fimc[i]->vid_cap.user_subdev_api = subdev_api; in subdev_conf_mode_store()
1276 * vid-dev - for V4L2 video node API only, subdevice will be configured
1278 * sub-dev - for media controller API, subdevs must be configured in user
1287 if (camclk->fmd->pmf == NULL) in cam_clk_prepare()
1288 return -ENODEV; in cam_clk_prepare()
1290 return pm_runtime_resume_and_get(camclk->fmd->pmf); in cam_clk_prepare()
1297 if (camclk->fmd->pmf == NULL) in cam_clk_unprepare()
1300 pm_runtime_put_sync(camclk->fmd->pmf); in cam_clk_unprepare()
1310 struct cam_clk_provider *cp = &fmd->clk_provider; in fimc_md_unregister_clk_provider()
1313 if (cp->of_node) in fimc_md_unregister_clk_provider()
1314 of_clk_del_provider(cp->of_node); in fimc_md_unregister_clk_provider()
1316 for (i = 0; i < cp->num_clocks; i++) in fimc_md_unregister_clk_provider()
1317 clk_unregister(cp->clks[i]); in fimc_md_unregister_clk_provider()
1322 struct cam_clk_provider *cp = &fmd->clk_provider; in fimc_md_register_clk_provider()
1323 struct device *dev = &fmd->pdev->dev; in fimc_md_register_clk_provider()
1327 struct cam_clk *camclk = &cp->camclk[i]; in fimc_md_register_clk_provider()
1331 ret = of_property_read_string_index(dev->of_node, in fimc_md_register_clk_provider()
1332 "clock-output-names", i, &init.name); in fimc_md_register_clk_provider()
1336 p_name = __clk_get_name(fmd->camclk[i].clock); in fimc_md_register_clk_provider()
1343 camclk->hw.init = &init; in fimc_md_register_clk_provider()
1344 camclk->fmd = fmd; in fimc_md_register_clk_provider()
1346 cp->clks[i] = clk_register(NULL, &camclk->hw); in fimc_md_register_clk_provider()
1347 if (IS_ERR(cp->clks[i])) { in fimc_md_register_clk_provider()
1349 init.name, PTR_ERR(cp->clks[i])); in fimc_md_register_clk_provider()
1350 ret = PTR_ERR(cp->clks[i]); in fimc_md_register_clk_provider()
1353 cp->num_clocks++; in fimc_md_register_clk_provider()
1356 if (cp->num_clocks == 0) { in fimc_md_register_clk_provider()
1361 cp->clk_data.clks = cp->clks; in fimc_md_register_clk_provider()
1362 cp->clk_data.clk_num = cp->num_clocks; in fimc_md_register_clk_provider()
1363 cp->of_node = dev->of_node; in fimc_md_register_clk_provider()
1364 ret = of_clk_add_provider(dev->of_node, of_clk_src_onecell_get, in fimc_md_register_clk_provider()
1365 &cp->clk_data); in fimc_md_register_clk_provider()
1382 for (i = 0; i < ARRAY_SIZE(fmd->sensor); i++) in subdev_notifier_bound()
1383 if (fmd->sensor[i].asd && in subdev_notifier_bound()
1384 fmd->sensor[i].asd->match.fwnode == in subdev_notifier_bound()
1385 of_fwnode_handle(subdev->dev->of_node)) in subdev_notifier_bound()
1386 si = &fmd->sensor[i]; in subdev_notifier_bound()
1389 return -EINVAL; in subdev_notifier_bound()
1391 v4l2_set_subdev_hostdata(subdev, &si->pdata); in subdev_notifier_bound()
1393 if (si->pdata.fimc_bus_type == FIMC_BUS_TYPE_ISP_WRITEBACK) in subdev_notifier_bound()
1394 subdev->grp_id = GRP_ID_FIMC_IS_SENSOR; in subdev_notifier_bound()
1396 subdev->grp_id = GRP_ID_SENSOR; in subdev_notifier_bound()
1398 si->subdev = subdev; in subdev_notifier_bound()
1400 v4l2_info(&fmd->v4l2_dev, "Registered sensor subdevice: %s (%d)\n", in subdev_notifier_bound()
1401 subdev->name, fmd->num_sensors); in subdev_notifier_bound()
1403 fmd->num_sensors++; in subdev_notifier_bound()
1413 mutex_lock(&fmd->media_dev.graph_mutex); in subdev_notifier_complete()
1419 ret = v4l2_device_register_subdev_nodes(&fmd->v4l2_dev); in subdev_notifier_complete()
1421 mutex_unlock(&fmd->media_dev.graph_mutex); in subdev_notifier_complete()
1425 return media_device_register(&fmd->media_dev); in subdev_notifier_complete()
1435 struct device *dev = &pdev->dev; in fimc_md_probe()
1443 return -ENOMEM; in fimc_md_probe()
1445 spin_lock_init(&fmd->slock); in fimc_md_probe()
1446 INIT_LIST_HEAD(&fmd->pipelines); in fimc_md_probe()
1447 fmd->pdev = pdev; in fimc_md_probe()
1449 strscpy(fmd->media_dev.model, "Samsung S5P FIMC", in fimc_md_probe()
1450 sizeof(fmd->media_dev.model)); in fimc_md_probe()
1451 fmd->media_dev.ops = &fimc_md_ops; in fimc_md_probe()
1452 fmd->media_dev.dev = dev; in fimc_md_probe()
1454 v4l2_dev = &fmd->v4l2_dev; in fimc_md_probe()
1455 v4l2_dev->mdev = &fmd->media_dev; in fimc_md_probe()
1456 v4l2_dev->notify = fimc_sensor_notify; in fimc_md_probe()
1457 strscpy(v4l2_dev->name, "s5p-fimc-md", sizeof(v4l2_dev->name)); in fimc_md_probe()
1459 fmd->use_isp = fimc_md_is_isp_available(dev->of_node); in fimc_md_probe()
1460 fmd->user_subdev_api = true; in fimc_md_probe()
1462 media_device_init(&fmd->media_dev); in fimc_md_probe()
1464 ret = v4l2_device_register(dev, &fmd->v4l2_dev); in fimc_md_probe()
1484 v4l2_async_nf_init(&fmd->subdev_notifier); in fimc_md_probe()
1486 ret = fimc_md_register_platform_entities(fmd, dev->of_node); in fimc_md_probe()
1494 ret = device_create_file(&pdev->dev, &dev_attr_subdev_conf_mode); in fimc_md_probe()
1498 * FIMC platform devices need to be registered before the sclk_cam in fimc_md_probe()
1508 if (fmd->num_sensors > 0) { in fimc_md_probe()
1509 fmd->subdev_notifier.ops = &subdev_notifier_ops; in fimc_md_probe()
1510 fmd->num_sensors = 0; in fimc_md_probe()
1512 ret = v4l2_async_nf_register(&fmd->v4l2_dev, in fimc_md_probe()
1513 &fmd->subdev_notifier); in fimc_md_probe()
1523 device_remove_file(&pdev->dev, &dev_attr_subdev_conf_mode); in fimc_md_probe()
1525 v4l2_async_nf_cleanup(&fmd->subdev_notifier); in fimc_md_probe()
1531 v4l2_device_unregister(&fmd->v4l2_dev); in fimc_md_probe()
1533 media_device_cleanup(&fmd->media_dev); in fimc_md_probe()
1545 v4l2_async_nf_unregister(&fmd->subdev_notifier); in fimc_md_remove()
1546 v4l2_async_nf_cleanup(&fmd->subdev_notifier); in fimc_md_remove()
1548 v4l2_device_unregister(&fmd->v4l2_dev); in fimc_md_remove()
1549 device_remove_file(&pdev->dev, &dev_attr_subdev_conf_mode); in fimc_md_remove()
1552 media_device_unregister(&fmd->media_dev); in fimc_md_remove()
1553 media_device_cleanup(&fmd->media_dev); in fimc_md_remove()
1560 { .name = "s5p-fimc-md" },
1566 { .compatible = "samsung,fimc" },
1576 .name = "s5p-fimc-md",
1584 request_module("s5p-csis"); in fimc_md_init()
1602 MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver");