Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / media / platform / exynos4-is / media-dev.h
blob9447fafe23c6e8028aa7467077239a95f0a0c424
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd.
4 */
6 #ifndef FIMC_MDEVICE_H_
7 #define FIMC_MDEVICE_H_
9 #include <linux/clk.h>
10 #include <linux/clk-provider.h>
11 #include <linux/platform_device.h>
12 #include <linux/mutex.h>
13 #include <linux/of.h>
14 #include <linux/pinctrl/consumer.h>
15 #include <media/media-device.h>
16 #include <media/media-entity.h>
17 #include <media/v4l2-device.h>
18 #include <media/v4l2-subdev.h>
19 #include <media/drv-intf/exynos-fimc.h>
21 #include "fimc-core.h"
22 #include "fimc-lite.h"
23 #include "mipi-csis.h"
25 #define FIMC_OF_NODE_NAME "fimc"
26 #define FIMC_LITE_OF_NODE_NAME "fimc-lite"
27 #define FIMC_IS_OF_NODE_NAME "fimc-is"
28 #define CSIS_OF_NODE_NAME "csis"
30 #define FIMC_MAX_SENSORS 4
31 #define FIMC_MAX_CAMCLKS 2
32 #define DEFAULT_SENSOR_CLK_FREQ 24000000U
34 /* LCD/ISP Writeback clocks (PIXELASYNCMx) */
35 enum {
36 CLK_IDX_WB_A,
37 CLK_IDX_WB_B,
38 FIMC_MAX_WBCLKS
41 enum fimc_subdev_index {
42 IDX_SENSOR,
43 IDX_CSIS,
44 IDX_FLITE,
45 IDX_IS_ISP,
46 IDX_FIMC,
47 IDX_MAX,
51 * This structure represents a chain of media entities, including a data
52 * source entity (e.g. an image sensor subdevice), a data capture entity
53 * - a video capture device node and any remaining entities.
55 struct fimc_pipeline {
56 struct exynos_media_pipeline ep;
57 struct list_head list;
58 struct media_entity *vdev_entity;
59 struct v4l2_subdev *subdevs[IDX_MAX];
62 #define to_fimc_pipeline(_ep) container_of(_ep, struct fimc_pipeline, ep)
64 struct fimc_csis_info {
65 struct v4l2_subdev *sd;
66 int id;
69 struct fimc_camclk_info {
70 struct clk *clock;
71 int use_count;
72 unsigned long frequency;
75 /**
76 * struct fimc_sensor_info - image data source subdev information
77 * @pdata: sensor's attributes passed as media device's platform data
78 * @asd: asynchronous subdev registration data structure
79 * @subdev: image sensor v4l2 subdev
80 * @host: fimc device the sensor is currently linked to
82 * This data structure applies to image sensor and the writeback subdevs.
84 struct fimc_sensor_info {
85 struct fimc_source_info pdata;
86 struct v4l2_async_subdev asd;
87 struct v4l2_subdev *subdev;
88 struct fimc_dev *host;
91 struct cam_clk {
92 struct clk_hw hw;
93 struct fimc_md *fmd;
95 #define to_cam_clk(_hw) container_of(_hw, struct cam_clk, hw)
97 /**
98 * struct fimc_md - fimc media device information
99 * @csis: MIPI CSIS subdevs data
100 * @sensor: array of registered sensor subdevs
101 * @num_sensors: actual number of registered sensors
102 * @camclk: external sensor clock information
103 * @fimc: array of registered fimc devices
104 * @fimc_is: fimc-is data structure
105 * @use_isp: set to true when FIMC-IS subsystem is used
106 * @pmf: handle to the CAMCLK clock control FIMC helper device
107 * @media_dev: top level media device
108 * @v4l2_dev: top level v4l2_device holding up the subdevs
109 * @pdev: platform device this media device is hooked up into
110 * @cam_clk_provider: CAMCLK clock provider structure
111 * @user_subdev_api: true if subdevs are not configured by the host driver
112 * @slock: spinlock protecting @sensor array
114 struct fimc_md {
115 struct fimc_csis_info csis[CSIS_MAX_ENTITIES];
116 struct fimc_sensor_info sensor[FIMC_MAX_SENSORS];
117 int num_sensors;
118 struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS];
119 struct clk *wbclk[FIMC_MAX_WBCLKS];
120 struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS];
121 struct fimc_dev *fimc[FIMC_MAX_DEVS];
122 struct fimc_is *fimc_is;
123 bool use_isp;
124 struct device *pmf;
125 struct media_device media_dev;
126 struct v4l2_device v4l2_dev;
127 struct platform_device *pdev;
129 struct cam_clk_provider {
130 struct clk *clks[FIMC_MAX_CAMCLKS];
131 struct clk_onecell_data clk_data;
132 struct device_node *of_node;
133 struct cam_clk camclk[FIMC_MAX_CAMCLKS];
134 int num_clocks;
135 } clk_provider;
137 struct v4l2_async_notifier subdev_notifier;
139 bool user_subdev_api;
140 spinlock_t slock;
141 struct list_head pipelines;
142 struct media_graph link_setup_graph;
145 static inline
146 struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si)
148 return container_of(si, struct fimc_sensor_info, pdata);
151 static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
153 return me->graph_obj.mdev == NULL ? NULL :
154 container_of(me->graph_obj.mdev, struct fimc_md, media_dev);
157 static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
159 return container_of(n, struct fimc_md, subdev_notifier);
162 static inline void fimc_md_graph_lock(struct exynos_video_entity *ve)
164 mutex_lock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
167 static inline void fimc_md_graph_unlock(struct exynos_video_entity *ve)
169 mutex_unlock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
172 int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
174 #ifdef CONFIG_OF
175 static inline bool fimc_md_is_isp_available(struct device_node *node)
177 node = of_get_child_by_name(node, FIMC_IS_OF_NODE_NAME);
178 return node ? of_device_is_available(node) : false;
180 #else
181 #define fimc_md_is_isp_available(node) (false)
182 #endif /* CONFIG_OF */
184 static inline struct v4l2_subdev *__fimc_md_get_subdev(
185 struct exynos_media_pipeline *ep,
186 unsigned int index)
188 struct fimc_pipeline *p = to_fimc_pipeline(ep);
190 if (!p || index >= IDX_MAX)
191 return NULL;
192 else
193 return p->subdevs[index];
196 #endif