1
2
3
4
5
6
7
8
9#ifndef FIMC_MDEVICE_H_
10#define FIMC_MDEVICE_H_
11
12#include <linux/clk.h>
13#include <linux/clk-provider.h>
14#include <linux/platform_device.h>
15#include <linux/mutex.h>
16#include <linux/of.h>
17#include <linux/pinctrl/consumer.h>
18#include <media/media-device.h>
19#include <media/media-entity.h>
20#include <media/v4l2-device.h>
21#include <media/v4l2-subdev.h>
22#include <media/drv-intf/exynos-fimc.h>
23
24#include "fimc-core.h"
25#include "fimc-lite.h"
26#include "mipi-csis.h"
27
28#define FIMC_OF_NODE_NAME "fimc"
29#define FIMC_LITE_OF_NODE_NAME "fimc-lite"
30#define FIMC_IS_OF_NODE_NAME "fimc-is"
31#define CSIS_OF_NODE_NAME "csis"
32
33#define PINCTRL_STATE_IDLE "idle"
34
35#define FIMC_MAX_SENSORS 4
36#define FIMC_MAX_CAMCLKS 2
37#define DEFAULT_SENSOR_CLK_FREQ 24000000U
38
39
40enum {
41 CLK_IDX_WB_A,
42 CLK_IDX_WB_B,
43 FIMC_MAX_WBCLKS
44};
45
46enum fimc_subdev_index {
47 IDX_SENSOR,
48 IDX_CSIS,
49 IDX_FLITE,
50 IDX_IS_ISP,
51 IDX_FIMC,
52 IDX_MAX,
53};
54
55
56
57
58
59
60struct fimc_pipeline {
61 struct exynos_media_pipeline ep;
62 struct list_head list;
63 struct media_entity *vdev_entity;
64 struct v4l2_subdev *subdevs[IDX_MAX];
65};
66
67#define to_fimc_pipeline(_ep) container_of(_ep, struct fimc_pipeline, ep)
68
69struct fimc_csis_info {
70 struct v4l2_subdev *sd;
71 int id;
72};
73
74struct fimc_camclk_info {
75 struct clk *clock;
76 int use_count;
77 unsigned long frequency;
78};
79
80
81
82
83
84
85
86
87
88
89struct fimc_sensor_info {
90 struct fimc_source_info pdata;
91 struct v4l2_async_subdev asd;
92 struct v4l2_subdev *subdev;
93 struct fimc_dev *host;
94};
95
96struct cam_clk {
97 struct clk_hw hw;
98 struct fimc_md *fmd;
99};
100#define to_cam_clk(_hw) container_of(_hw, struct cam_clk, hw)
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122struct fimc_md {
123 struct fimc_csis_info csis[CSIS_MAX_ENTITIES];
124 struct fimc_sensor_info sensor[FIMC_MAX_SENSORS];
125 int num_sensors;
126 struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS];
127 struct clk *wbclk[FIMC_MAX_WBCLKS];
128 struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS];
129 struct fimc_dev *fimc[FIMC_MAX_DEVS];
130 struct fimc_is *fimc_is;
131 bool use_isp;
132 struct device *pmf;
133 struct media_device media_dev;
134 struct v4l2_device v4l2_dev;
135 struct platform_device *pdev;
136
137 struct fimc_pinctrl {
138 struct pinctrl *pinctrl;
139 struct pinctrl_state *state_default;
140 struct pinctrl_state *state_idle;
141 } pinctl;
142
143 struct cam_clk_provider {
144 struct clk *clks[FIMC_MAX_CAMCLKS];
145 struct clk_onecell_data clk_data;
146 struct device_node *of_node;
147 struct cam_clk camclk[FIMC_MAX_CAMCLKS];
148 int num_clocks;
149 } clk_provider;
150
151 struct v4l2_async_notifier subdev_notifier;
152 struct v4l2_async_subdev *async_subdevs[FIMC_MAX_SENSORS];
153
154 bool user_subdev_api;
155 spinlock_t slock;
156 struct list_head pipelines;
157 struct media_entity_graph link_setup_graph;
158};
159
160static inline
161struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si)
162{
163 return container_of(si, struct fimc_sensor_info, pdata);
164}
165
166static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
167{
168 return me->graph_obj.mdev == NULL ? NULL :
169 container_of(me->graph_obj.mdev, struct fimc_md, media_dev);
170}
171
172static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
173{
174 return container_of(n, struct fimc_md, subdev_notifier);
175}
176
177static inline void fimc_md_graph_lock(struct exynos_video_entity *ve)
178{
179 mutex_lock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
180}
181
182static inline void fimc_md_graph_unlock(struct exynos_video_entity *ve)
183{
184 mutex_unlock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
185}
186
187int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
188
189#ifdef CONFIG_OF
190static inline bool fimc_md_is_isp_available(struct device_node *node)
191{
192 node = of_get_child_by_name(node, FIMC_IS_OF_NODE_NAME);
193 return node ? of_device_is_available(node) : false;
194}
195#else
196#define fimc_md_is_isp_available(node) (false)
197#endif
198
199static inline struct v4l2_subdev *__fimc_md_get_subdev(
200 struct exynos_media_pipeline *ep,
201 unsigned int index)
202{
203 struct fimc_pipeline *p = to_fimc_pipeline(ep);
204
205 if (!p || index >= IDX_MAX)
206 return NULL;
207 else
208 return p->subdevs[index];
209}
210
211#endif
212