1 // SPDX-License-Identifier: GPL-2.0
5 * Qualcomm MSM Camera Subsystem - ISPIF (ISP Interface) Module
7 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
8 * Copyright (C) 2015-2018 Linaro Ltd.
10 #include <linux/clk.h>
11 #include <linux/completion.h>
12 #include <linux/interrupt.h>
14 #include <linux/iopoll.h>
15 #include <linux/kernel.h>
16 #include <linux/mutex.h>
17 #include <linux/platform_device.h>
18 #include <linux/pm_runtime.h>
19 #include <media/media-entity.h>
20 #include <media/v4l2-device.h>
21 #include <media/v4l2-subdev.h>
23 #include "camss-ispif.h"
26 #define MSM_ISPIF_NAME "msm_ispif"
28 #define ISPIF_RST_CMD_0 0x008
29 #define ISPIF_RST_CMD_0_STROBED_RST_EN (1 << 0)
30 #define ISPIF_RST_CMD_0_MISC_LOGIC_RST (1 << 1)
31 #define ISPIF_RST_CMD_0_SW_REG_RST (1 << 2)
32 #define ISPIF_RST_CMD_0_PIX_INTF_0_CSID_RST (1 << 3)
33 #define ISPIF_RST_CMD_0_PIX_INTF_0_VFE_RST (1 << 4)
34 #define ISPIF_RST_CMD_0_PIX_INTF_1_CSID_RST (1 << 5)
35 #define ISPIF_RST_CMD_0_PIX_INTF_1_VFE_RST (1 << 6)
36 #define ISPIF_RST_CMD_0_RDI_INTF_0_CSID_RST (1 << 7)
37 #define ISPIF_RST_CMD_0_RDI_INTF_0_VFE_RST (1 << 8)
38 #define ISPIF_RST_CMD_0_RDI_INTF_1_CSID_RST (1 << 9)
39 #define ISPIF_RST_CMD_0_RDI_INTF_1_VFE_RST (1 << 10)
40 #define ISPIF_RST_CMD_0_RDI_INTF_2_CSID_RST (1 << 11)
41 #define ISPIF_RST_CMD_0_RDI_INTF_2_VFE_RST (1 << 12)
42 #define ISPIF_RST_CMD_0_PIX_OUTPUT_0_MISR_RST (1 << 16)
43 #define ISPIF_RST_CMD_0_RDI_OUTPUT_0_MISR_RST (1 << 17)
44 #define ISPIF_RST_CMD_0_RDI_OUTPUT_1_MISR_RST (1 << 18)
45 #define ISPIF_RST_CMD_0_RDI_OUTPUT_2_MISR_RST (1 << 19)
46 #define ISPIF_IRQ_GLOBAL_CLEAR_CMD 0x01c
47 #define ISPIF_VFE_m_CTRL_0(m) (0x200 + 0x200 * (m))
48 #define ISPIF_VFE_m_CTRL_0_PIX0_LINE_BUF_EN (1 << 6)
49 #define ISPIF_VFE_m_IRQ_MASK_0(m) (0x208 + 0x200 * (m))
50 #define ISPIF_VFE_m_IRQ_MASK_0_PIX0_ENABLE 0x00001249
51 #define ISPIF_VFE_m_IRQ_MASK_0_PIX0_MASK 0x00001fff
52 #define ISPIF_VFE_m_IRQ_MASK_0_RDI0_ENABLE 0x02492000
53 #define ISPIF_VFE_m_IRQ_MASK_0_RDI0_MASK 0x03ffe000
54 #define ISPIF_VFE_m_IRQ_MASK_1(m) (0x20c + 0x200 * (m))
55 #define ISPIF_VFE_m_IRQ_MASK_1_PIX1_ENABLE 0x00001249
56 #define ISPIF_VFE_m_IRQ_MASK_1_PIX1_MASK 0x00001fff
57 #define ISPIF_VFE_m_IRQ_MASK_1_RDI1_ENABLE 0x02492000
58 #define ISPIF_VFE_m_IRQ_MASK_1_RDI1_MASK 0x03ffe000
59 #define ISPIF_VFE_m_IRQ_MASK_2(m) (0x210 + 0x200 * (m))
60 #define ISPIF_VFE_m_IRQ_MASK_2_RDI2_ENABLE 0x00001249
61 #define ISPIF_VFE_m_IRQ_MASK_2_RDI2_MASK 0x00001fff
62 #define ISPIF_VFE_m_IRQ_STATUS_0(m) (0x21c + 0x200 * (m))
63 #define ISPIF_VFE_m_IRQ_STATUS_0_PIX0_OVERFLOW (1 << 12)
64 #define ISPIF_VFE_m_IRQ_STATUS_0_RDI0_OVERFLOW (1 << 25)
65 #define ISPIF_VFE_m_IRQ_STATUS_1(m) (0x220 + 0x200 * (m))
66 #define ISPIF_VFE_m_IRQ_STATUS_1_PIX1_OVERFLOW (1 << 12)
67 #define ISPIF_VFE_m_IRQ_STATUS_1_RDI1_OVERFLOW (1 << 25)
68 #define ISPIF_VFE_m_IRQ_STATUS_2(m) (0x224 + 0x200 * (m))
69 #define ISPIF_VFE_m_IRQ_STATUS_2_RDI2_OVERFLOW (1 << 12)
70 #define ISPIF_VFE_m_IRQ_CLEAR_0(m) (0x230 + 0x200 * (m))
71 #define ISPIF_VFE_m_IRQ_CLEAR_1(m) (0x234 + 0x200 * (m))
72 #define ISPIF_VFE_m_IRQ_CLEAR_2(m) (0x238 + 0x200 * (m))
73 #define ISPIF_VFE_m_INTF_INPUT_SEL(m) (0x244 + 0x200 * (m))
74 #define ISPIF_VFE_m_INTF_CMD_0(m) (0x248 + 0x200 * (m))
75 #define ISPIF_VFE_m_INTF_CMD_1(m) (0x24c + 0x200 * (m))
76 #define ISPIF_VFE_m_PIX_INTF_n_CID_MASK(m, n) \
77 (0x254 + 0x200 * (m) + 0x4 * (n))
78 #define ISPIF_VFE_m_RDI_INTF_n_CID_MASK(m, n) \
79 (0x264 + 0x200 * (m) + 0x4 * (n))
80 /* PACK_CFG registers are 8x96 only */
81 #define ISPIF_VFE_m_RDI_INTF_n_PACK_CFG_0(m, n) \
82 (0x270 + 0x200 * (m) + 0x4 * (n))
83 #define ISPIF_VFE_m_RDI_INTF_n_PACK_CFG_1(m, n) \
84 (0x27c + 0x200 * (m) + 0x4 * (n))
85 #define ISPIF_VFE_m_RDI_INTF_n_PACK_CFG_0_CID_c_PLAIN(c) \
86 (1 << ((cid % 8) * 4))
87 #define ISPIF_VFE_m_PIX_INTF_n_STATUS(m, n) \
88 (0x2c0 + 0x200 * (m) + 0x4 * (n))
89 #define ISPIF_VFE_m_RDI_INTF_n_STATUS(m, n) \
90 (0x2d0 + 0x200 * (m) + 0x4 * (n))
92 #define CSI_PIX_CLK_MUX_SEL 0x000
93 #define CSI_RDI_CLK_MUX_SEL 0x008
95 #define ISPIF_TIMEOUT_SLEEP_US 1000
96 #define ISPIF_TIMEOUT_ALL_US 1000000
97 #define ISPIF_RESET_TIMEOUT_MS 500
100 CMD_DISABLE_FRAME_BOUNDARY
= 0x0,
101 CMD_ENABLE_FRAME_BOUNDARY
= 0x1,
102 CMD_DISABLE_IMMEDIATELY
= 0x2,
103 CMD_ALL_DISABLE_IMMEDIATELY
= 0xaaaaaaaa,
104 CMD_ALL_NO_CHANGE
= 0xffffffff,
107 static const u32 ispif_formats_8x16
[] = {
108 MEDIA_BUS_FMT_UYVY8_2X8
,
109 MEDIA_BUS_FMT_VYUY8_2X8
,
110 MEDIA_BUS_FMT_YUYV8_2X8
,
111 MEDIA_BUS_FMT_YVYU8_2X8
,
112 MEDIA_BUS_FMT_SBGGR8_1X8
,
113 MEDIA_BUS_FMT_SGBRG8_1X8
,
114 MEDIA_BUS_FMT_SGRBG8_1X8
,
115 MEDIA_BUS_FMT_SRGGB8_1X8
,
116 MEDIA_BUS_FMT_SBGGR10_1X10
,
117 MEDIA_BUS_FMT_SGBRG10_1X10
,
118 MEDIA_BUS_FMT_SGRBG10_1X10
,
119 MEDIA_BUS_FMT_SRGGB10_1X10
,
120 MEDIA_BUS_FMT_SBGGR12_1X12
,
121 MEDIA_BUS_FMT_SGBRG12_1X12
,
122 MEDIA_BUS_FMT_SGRBG12_1X12
,
123 MEDIA_BUS_FMT_SRGGB12_1X12
,
124 MEDIA_BUS_FMT_Y10_1X10
,
127 static const u32 ispif_formats_8x96
[] = {
128 MEDIA_BUS_FMT_UYVY8_2X8
,
129 MEDIA_BUS_FMT_VYUY8_2X8
,
130 MEDIA_BUS_FMT_YUYV8_2X8
,
131 MEDIA_BUS_FMT_YVYU8_2X8
,
132 MEDIA_BUS_FMT_SBGGR8_1X8
,
133 MEDIA_BUS_FMT_SGBRG8_1X8
,
134 MEDIA_BUS_FMT_SGRBG8_1X8
,
135 MEDIA_BUS_FMT_SRGGB8_1X8
,
136 MEDIA_BUS_FMT_SBGGR10_1X10
,
137 MEDIA_BUS_FMT_SGBRG10_1X10
,
138 MEDIA_BUS_FMT_SGRBG10_1X10
,
139 MEDIA_BUS_FMT_SRGGB10_1X10
,
140 MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE
,
141 MEDIA_BUS_FMT_SBGGR12_1X12
,
142 MEDIA_BUS_FMT_SGBRG12_1X12
,
143 MEDIA_BUS_FMT_SGRBG12_1X12
,
144 MEDIA_BUS_FMT_SRGGB12_1X12
,
145 MEDIA_BUS_FMT_SBGGR14_1X14
,
146 MEDIA_BUS_FMT_SGBRG14_1X14
,
147 MEDIA_BUS_FMT_SGRBG14_1X14
,
148 MEDIA_BUS_FMT_SRGGB14_1X14
,
149 MEDIA_BUS_FMT_Y10_1X10
,
150 MEDIA_BUS_FMT_Y10_2X8_PADHI_LE
,
154 * ispif_isr_8x96 - ISPIF module interrupt handler for 8x96
155 * @irq: Interrupt line
158 * Return IRQ_HANDLED on success
160 static irqreturn_t
ispif_isr_8x96(int irq
, void *dev
)
162 struct ispif_device
*ispif
= dev
;
163 u32 value0
, value1
, value2
, value3
, value4
, value5
;
165 value0
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_STATUS_0(0));
166 value1
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_STATUS_1(0));
167 value2
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_STATUS_2(0));
168 value3
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_STATUS_0(1));
169 value4
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_STATUS_1(1));
170 value5
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_STATUS_2(1));
172 writel_relaxed(value0
, ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_0(0));
173 writel_relaxed(value1
, ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_1(0));
174 writel_relaxed(value2
, ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_2(0));
175 writel_relaxed(value3
, ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_0(1));
176 writel_relaxed(value4
, ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_1(1));
177 writel_relaxed(value5
, ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_2(1));
179 writel(0x1, ispif
->base
+ ISPIF_IRQ_GLOBAL_CLEAR_CMD
);
181 if ((value0
>> 27) & 0x1)
182 complete(&ispif
->reset_complete
);
184 if (unlikely(value0
& ISPIF_VFE_m_IRQ_STATUS_0_PIX0_OVERFLOW
))
185 dev_err_ratelimited(to_device(ispif
), "VFE0 pix0 overflow\n");
187 if (unlikely(value0
& ISPIF_VFE_m_IRQ_STATUS_0_RDI0_OVERFLOW
))
188 dev_err_ratelimited(to_device(ispif
), "VFE0 rdi0 overflow\n");
190 if (unlikely(value1
& ISPIF_VFE_m_IRQ_STATUS_1_PIX1_OVERFLOW
))
191 dev_err_ratelimited(to_device(ispif
), "VFE0 pix1 overflow\n");
193 if (unlikely(value1
& ISPIF_VFE_m_IRQ_STATUS_1_RDI1_OVERFLOW
))
194 dev_err_ratelimited(to_device(ispif
), "VFE0 rdi1 overflow\n");
196 if (unlikely(value2
& ISPIF_VFE_m_IRQ_STATUS_2_RDI2_OVERFLOW
))
197 dev_err_ratelimited(to_device(ispif
), "VFE0 rdi2 overflow\n");
199 if (unlikely(value3
& ISPIF_VFE_m_IRQ_STATUS_0_PIX0_OVERFLOW
))
200 dev_err_ratelimited(to_device(ispif
), "VFE1 pix0 overflow\n");
202 if (unlikely(value3
& ISPIF_VFE_m_IRQ_STATUS_0_RDI0_OVERFLOW
))
203 dev_err_ratelimited(to_device(ispif
), "VFE1 rdi0 overflow\n");
205 if (unlikely(value4
& ISPIF_VFE_m_IRQ_STATUS_1_PIX1_OVERFLOW
))
206 dev_err_ratelimited(to_device(ispif
), "VFE1 pix1 overflow\n");
208 if (unlikely(value4
& ISPIF_VFE_m_IRQ_STATUS_1_RDI1_OVERFLOW
))
209 dev_err_ratelimited(to_device(ispif
), "VFE1 rdi1 overflow\n");
211 if (unlikely(value5
& ISPIF_VFE_m_IRQ_STATUS_2_RDI2_OVERFLOW
))
212 dev_err_ratelimited(to_device(ispif
), "VFE1 rdi2 overflow\n");
218 * ispif_isr_8x16 - ISPIF module interrupt handler for 8x16
219 * @irq: Interrupt line
222 * Return IRQ_HANDLED on success
224 static irqreturn_t
ispif_isr_8x16(int irq
, void *dev
)
226 struct ispif_device
*ispif
= dev
;
227 u32 value0
, value1
, value2
;
229 value0
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_STATUS_0(0));
230 value1
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_STATUS_1(0));
231 value2
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_STATUS_2(0));
233 writel_relaxed(value0
, ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_0(0));
234 writel_relaxed(value1
, ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_1(0));
235 writel_relaxed(value2
, ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_2(0));
237 writel(0x1, ispif
->base
+ ISPIF_IRQ_GLOBAL_CLEAR_CMD
);
239 if ((value0
>> 27) & 0x1)
240 complete(&ispif
->reset_complete
);
242 if (unlikely(value0
& ISPIF_VFE_m_IRQ_STATUS_0_PIX0_OVERFLOW
))
243 dev_err_ratelimited(to_device(ispif
), "VFE0 pix0 overflow\n");
245 if (unlikely(value0
& ISPIF_VFE_m_IRQ_STATUS_0_RDI0_OVERFLOW
))
246 dev_err_ratelimited(to_device(ispif
), "VFE0 rdi0 overflow\n");
248 if (unlikely(value1
& ISPIF_VFE_m_IRQ_STATUS_1_PIX1_OVERFLOW
))
249 dev_err_ratelimited(to_device(ispif
), "VFE0 pix1 overflow\n");
251 if (unlikely(value1
& ISPIF_VFE_m_IRQ_STATUS_1_RDI1_OVERFLOW
))
252 dev_err_ratelimited(to_device(ispif
), "VFE0 rdi1 overflow\n");
254 if (unlikely(value2
& ISPIF_VFE_m_IRQ_STATUS_2_RDI2_OVERFLOW
))
255 dev_err_ratelimited(to_device(ispif
), "VFE0 rdi2 overflow\n");
261 * ispif_reset - Trigger reset on ISPIF module and wait to complete
262 * @ispif: ISPIF device
264 * Return 0 on success or a negative error code otherwise
266 static int ispif_reset(struct ispif_device
*ispif
)
272 ret
= camss_pm_domain_on(to_camss(ispif
), PM_DOMAIN_VFE0
);
276 ret
= camss_pm_domain_on(to_camss(ispif
), PM_DOMAIN_VFE1
);
280 ret
= camss_enable_clocks(ispif
->nclocks_for_reset
,
281 ispif
->clock_for_reset
,
286 reinit_completion(&ispif
->reset_complete
);
288 val
= ISPIF_RST_CMD_0_STROBED_RST_EN
|
289 ISPIF_RST_CMD_0_MISC_LOGIC_RST
|
290 ISPIF_RST_CMD_0_SW_REG_RST
|
291 ISPIF_RST_CMD_0_PIX_INTF_0_CSID_RST
|
292 ISPIF_RST_CMD_0_PIX_INTF_0_VFE_RST
|
293 ISPIF_RST_CMD_0_PIX_INTF_1_CSID_RST
|
294 ISPIF_RST_CMD_0_PIX_INTF_1_VFE_RST
|
295 ISPIF_RST_CMD_0_RDI_INTF_0_CSID_RST
|
296 ISPIF_RST_CMD_0_RDI_INTF_0_VFE_RST
|
297 ISPIF_RST_CMD_0_RDI_INTF_1_CSID_RST
|
298 ISPIF_RST_CMD_0_RDI_INTF_1_VFE_RST
|
299 ISPIF_RST_CMD_0_RDI_INTF_2_CSID_RST
|
300 ISPIF_RST_CMD_0_RDI_INTF_2_VFE_RST
|
301 ISPIF_RST_CMD_0_PIX_OUTPUT_0_MISR_RST
|
302 ISPIF_RST_CMD_0_RDI_OUTPUT_0_MISR_RST
|
303 ISPIF_RST_CMD_0_RDI_OUTPUT_1_MISR_RST
|
304 ISPIF_RST_CMD_0_RDI_OUTPUT_2_MISR_RST
;
306 writel_relaxed(val
, ispif
->base
+ ISPIF_RST_CMD_0
);
308 time
= wait_for_completion_timeout(&ispif
->reset_complete
,
309 msecs_to_jiffies(ISPIF_RESET_TIMEOUT_MS
));
311 dev_err(to_device(ispif
), "ISPIF reset timeout\n");
315 camss_disable_clocks(ispif
->nclocks_for_reset
, ispif
->clock_for_reset
);
317 camss_pm_domain_off(to_camss(ispif
), PM_DOMAIN_VFE0
);
318 camss_pm_domain_off(to_camss(ispif
), PM_DOMAIN_VFE1
);
324 * ispif_set_power - Power on/off ISPIF module
325 * @sd: ISPIF V4L2 subdevice
326 * @on: Requested power state
328 * Return 0 on success or a negative error code otherwise
330 static int ispif_set_power(struct v4l2_subdev
*sd
, int on
)
332 struct ispif_line
*line
= v4l2_get_subdevdata(sd
);
333 struct ispif_device
*ispif
= line
->ispif
;
334 struct device
*dev
= to_device(ispif
);
337 mutex_lock(&ispif
->power_lock
);
340 if (ispif
->power_count
) {
341 /* Power is already on */
342 ispif
->power_count
++;
346 ret
= pm_runtime_get_sync(dev
);
350 ret
= camss_enable_clocks(ispif
->nclocks
, ispif
->clock
, dev
);
352 pm_runtime_put_sync(dev
);
356 ret
= ispif_reset(ispif
);
358 pm_runtime_put_sync(dev
);
359 camss_disable_clocks(ispif
->nclocks
, ispif
->clock
);
363 ispif
->intf_cmd
[line
->vfe_id
].cmd_0
= CMD_ALL_NO_CHANGE
;
364 ispif
->intf_cmd
[line
->vfe_id
].cmd_1
= CMD_ALL_NO_CHANGE
;
366 ispif
->power_count
++;
368 if (ispif
->power_count
== 0) {
369 dev_err(dev
, "ispif power off on power_count == 0\n");
371 } else if (ispif
->power_count
== 1) {
372 camss_disable_clocks(ispif
->nclocks
, ispif
->clock
);
373 pm_runtime_put_sync(dev
);
376 ispif
->power_count
--;
380 mutex_unlock(&ispif
->power_lock
);
386 * ispif_select_clk_mux - Select clock for PIX/RDI interface
387 * @ispif: ISPIF device
388 * @intf: VFE interface
389 * @csid: CSID HW module id
390 * @vfe: VFE HW module id
391 * @enable: enable or disable the selected clock
393 static void ispif_select_clk_mux(struct ispif_device
*ispif
,
394 enum ispif_intf intf
, u8 csid
,
401 val
= readl_relaxed(ispif
->base_clk_mux
+ CSI_PIX_CLK_MUX_SEL
);
402 val
&= ~(0xf << (vfe
* 8));
404 val
|= (csid
<< (vfe
* 8));
405 writel_relaxed(val
, ispif
->base_clk_mux
+ CSI_PIX_CLK_MUX_SEL
);
409 val
= readl_relaxed(ispif
->base_clk_mux
+ CSI_RDI_CLK_MUX_SEL
);
410 val
&= ~(0xf << (vfe
* 12));
412 val
|= (csid
<< (vfe
* 12));
413 writel_relaxed(val
, ispif
->base_clk_mux
+ CSI_RDI_CLK_MUX_SEL
);
417 val
= readl_relaxed(ispif
->base_clk_mux
+ CSI_PIX_CLK_MUX_SEL
);
418 val
&= ~(0xf << (4 + (vfe
* 8)));
420 val
|= (csid
<< (4 + (vfe
* 8)));
421 writel_relaxed(val
, ispif
->base_clk_mux
+ CSI_PIX_CLK_MUX_SEL
);
425 val
= readl_relaxed(ispif
->base_clk_mux
+ CSI_RDI_CLK_MUX_SEL
);
426 val
&= ~(0xf << (4 + (vfe
* 12)));
428 val
|= (csid
<< (4 + (vfe
* 12)));
429 writel_relaxed(val
, ispif
->base_clk_mux
+ CSI_RDI_CLK_MUX_SEL
);
433 val
= readl_relaxed(ispif
->base_clk_mux
+ CSI_RDI_CLK_MUX_SEL
);
434 val
&= ~(0xf << (8 + (vfe
* 12)));
436 val
|= (csid
<< (8 + (vfe
* 12)));
437 writel_relaxed(val
, ispif
->base_clk_mux
+ CSI_RDI_CLK_MUX_SEL
);
445 * ispif_validate_intf_status - Validate current status of PIX/RDI interface
446 * @ispif: ISPIF device
447 * @intf: VFE interface
448 * @vfe: VFE HW module id
450 * Return 0 when interface is idle or -EBUSY otherwise
452 static int ispif_validate_intf_status(struct ispif_device
*ispif
,
453 enum ispif_intf intf
, u8 vfe
)
460 val
= readl_relaxed(ispif
->base
+
461 ISPIF_VFE_m_PIX_INTF_n_STATUS(vfe
, 0));
464 val
= readl_relaxed(ispif
->base
+
465 ISPIF_VFE_m_RDI_INTF_n_STATUS(vfe
, 0));
468 val
= readl_relaxed(ispif
->base
+
469 ISPIF_VFE_m_PIX_INTF_n_STATUS(vfe
, 1));
472 val
= readl_relaxed(ispif
->base
+
473 ISPIF_VFE_m_RDI_INTF_n_STATUS(vfe
, 1));
476 val
= readl_relaxed(ispif
->base
+
477 ISPIF_VFE_m_RDI_INTF_n_STATUS(vfe
, 2));
481 if ((val
& 0xf) != 0xf) {
482 dev_err(to_device(ispif
), "%s: ispif is busy: 0x%x\n",
491 * ispif_wait_for_stop - Wait for PIX/RDI interface to stop
492 * @ispif: ISPIF device
493 * @intf: VFE interface
494 * @vfe: VFE HW module id
496 * Return 0 on success or a negative error code otherwise
498 static int ispif_wait_for_stop(struct ispif_device
*ispif
,
499 enum ispif_intf intf
, u8 vfe
)
507 addr
= ISPIF_VFE_m_PIX_INTF_n_STATUS(vfe
, 0);
510 addr
= ISPIF_VFE_m_RDI_INTF_n_STATUS(vfe
, 0);
513 addr
= ISPIF_VFE_m_PIX_INTF_n_STATUS(vfe
, 1);
516 addr
= ISPIF_VFE_m_RDI_INTF_n_STATUS(vfe
, 1);
519 addr
= ISPIF_VFE_m_RDI_INTF_n_STATUS(vfe
, 2);
523 ret
= readl_poll_timeout(ispif
->base
+ addr
,
525 (stop_flag
& 0xf) == 0xf,
526 ISPIF_TIMEOUT_SLEEP_US
,
527 ISPIF_TIMEOUT_ALL_US
);
529 dev_err(to_device(ispif
), "%s: ispif stop timeout\n",
536 * ispif_select_csid - Select CSID HW module for input from
537 * @ispif: ISPIF device
538 * @intf: VFE interface
539 * @csid: CSID HW module id
540 * @vfe: VFE HW module id
541 * @enable: enable or disable the selected input
543 static void ispif_select_csid(struct ispif_device
*ispif
, enum ispif_intf intf
,
544 u8 csid
, u8 vfe
, u8 enable
)
548 val
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_INTF_INPUT_SEL(vfe
));
551 val
&= ~(BIT(1) | BIT(0));
556 val
&= ~(BIT(5) | BIT(4));
561 val
&= ~(BIT(9) | BIT(8));
566 val
&= ~(BIT(13) | BIT(12));
571 val
&= ~(BIT(21) | BIT(20));
577 writel(val
, ispif
->base
+ ISPIF_VFE_m_INTF_INPUT_SEL(vfe
));
581 * ispif_select_cid - Enable/disable desired CID
582 * @ispif: ISPIF device
583 * @intf: VFE interface
584 * @cid: desired CID to enable/disable
585 * @vfe: VFE HW module id
586 * @enable: enable or disable the desired CID
588 static void ispif_select_cid(struct ispif_device
*ispif
, enum ispif_intf intf
,
589 u8 cid
, u8 vfe
, u8 enable
)
591 u32 cid_mask
= 1 << cid
;
597 addr
= ISPIF_VFE_m_PIX_INTF_n_CID_MASK(vfe
, 0);
600 addr
= ISPIF_VFE_m_RDI_INTF_n_CID_MASK(vfe
, 0);
603 addr
= ISPIF_VFE_m_PIX_INTF_n_CID_MASK(vfe
, 1);
606 addr
= ISPIF_VFE_m_RDI_INTF_n_CID_MASK(vfe
, 1);
609 addr
= ISPIF_VFE_m_RDI_INTF_n_CID_MASK(vfe
, 2);
613 val
= readl_relaxed(ispif
->base
+ addr
);
619 writel(val
, ispif
->base
+ addr
);
623 * ispif_config_irq - Enable/disable interrupts for PIX/RDI interface
624 * @ispif: ISPIF device
625 * @intf: VFE interface
626 * @vfe: VFE HW module id
627 * @enable: enable or disable
629 static void ispif_config_irq(struct ispif_device
*ispif
, enum ispif_intf intf
,
636 val
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_MASK_0(vfe
));
637 val
&= ~ISPIF_VFE_m_IRQ_MASK_0_PIX0_MASK
;
639 val
|= ISPIF_VFE_m_IRQ_MASK_0_PIX0_ENABLE
;
640 writel_relaxed(val
, ispif
->base
+ ISPIF_VFE_m_IRQ_MASK_0(vfe
));
641 writel_relaxed(ISPIF_VFE_m_IRQ_MASK_0_PIX0_ENABLE
,
642 ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_0(vfe
));
645 val
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_MASK_0(vfe
));
646 val
&= ~ISPIF_VFE_m_IRQ_MASK_0_RDI0_MASK
;
648 val
|= ISPIF_VFE_m_IRQ_MASK_0_RDI0_ENABLE
;
649 writel_relaxed(val
, ispif
->base
+ ISPIF_VFE_m_IRQ_MASK_0(vfe
));
650 writel_relaxed(ISPIF_VFE_m_IRQ_MASK_0_RDI0_ENABLE
,
651 ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_0(vfe
));
654 val
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_MASK_1(vfe
));
655 val
&= ~ISPIF_VFE_m_IRQ_MASK_1_PIX1_MASK
;
657 val
|= ISPIF_VFE_m_IRQ_MASK_1_PIX1_ENABLE
;
658 writel_relaxed(val
, ispif
->base
+ ISPIF_VFE_m_IRQ_MASK_1(vfe
));
659 writel_relaxed(ISPIF_VFE_m_IRQ_MASK_1_PIX1_ENABLE
,
660 ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_1(vfe
));
663 val
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_MASK_1(vfe
));
664 val
&= ~ISPIF_VFE_m_IRQ_MASK_1_RDI1_MASK
;
666 val
|= ISPIF_VFE_m_IRQ_MASK_1_RDI1_ENABLE
;
667 writel_relaxed(val
, ispif
->base
+ ISPIF_VFE_m_IRQ_MASK_1(vfe
));
668 writel_relaxed(ISPIF_VFE_m_IRQ_MASK_1_RDI1_ENABLE
,
669 ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_1(vfe
));
672 val
= readl_relaxed(ispif
->base
+ ISPIF_VFE_m_IRQ_MASK_2(vfe
));
673 val
&= ~ISPIF_VFE_m_IRQ_MASK_2_RDI2_MASK
;
675 val
|= ISPIF_VFE_m_IRQ_MASK_2_RDI2_ENABLE
;
676 writel_relaxed(val
, ispif
->base
+ ISPIF_VFE_m_IRQ_MASK_2(vfe
));
677 writel_relaxed(ISPIF_VFE_m_IRQ_MASK_2_RDI2_ENABLE
,
678 ispif
->base
+ ISPIF_VFE_m_IRQ_CLEAR_2(vfe
));
682 writel(0x1, ispif
->base
+ ISPIF_IRQ_GLOBAL_CLEAR_CMD
);
686 * ispif_config_pack - Config packing for PRDI mode
687 * @ispif: ISPIF device
688 * @code: media bus format code
689 * @intf: VFE interface
690 * @cid: desired CID to handle
691 * @vfe: VFE HW module id
692 * @enable: enable or disable
694 static void ispif_config_pack(struct ispif_device
*ispif
, u32 code
,
695 enum ispif_intf intf
, u8 cid
, u8 vfe
, u8 enable
)
699 if (code
!= MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE
&&
700 code
!= MEDIA_BUS_FMT_Y10_2X8_PADHI_LE
)
706 addr
= ISPIF_VFE_m_RDI_INTF_n_PACK_CFG_0(vfe
, 0);
708 addr
= ISPIF_VFE_m_RDI_INTF_n_PACK_CFG_1(vfe
, 0);
712 addr
= ISPIF_VFE_m_RDI_INTF_n_PACK_CFG_0(vfe
, 1);
714 addr
= ISPIF_VFE_m_RDI_INTF_n_PACK_CFG_1(vfe
, 1);
718 addr
= ISPIF_VFE_m_RDI_INTF_n_PACK_CFG_0(vfe
, 2);
720 addr
= ISPIF_VFE_m_RDI_INTF_n_PACK_CFG_1(vfe
, 2);
727 val
= ISPIF_VFE_m_RDI_INTF_n_PACK_CFG_0_CID_c_PLAIN(cid
);
731 writel_relaxed(val
, ispif
->base
+ addr
);
735 * ispif_set_intf_cmd - Set command to enable/disable interface
736 * @ispif: ISPIF device
737 * @cmd: interface command
738 * @intf: VFE interface
739 * @vfe: VFE HW module id
740 * @vc: virtual channel
742 static void ispif_set_intf_cmd(struct ispif_device
*ispif
, u8 cmd
,
743 enum ispif_intf intf
, u8 vfe
, u8 vc
)
748 val
= &ispif
->intf_cmd
[vfe
].cmd_1
;
749 *val
&= ~(0x3 << (vc
* 2 + 8));
750 *val
|= (cmd
<< (vc
* 2 + 8));
752 writel_relaxed(*val
, ispif
->base
+ ISPIF_VFE_m_INTF_CMD_1(vfe
));
755 val
= &ispif
->intf_cmd
[vfe
].cmd_0
;
756 *val
&= ~(0x3 << (vc
* 2 + intf
* 8));
757 *val
|= (cmd
<< (vc
* 2 + intf
* 8));
759 writel_relaxed(*val
, ispif
->base
+ ISPIF_VFE_m_INTF_CMD_0(vfe
));
765 * ispif_set_stream - Enable/disable streaming on ISPIF module
766 * @sd: ISPIF V4L2 subdevice
767 * @enable: Requested streaming state
769 * Main configuration of ISPIF module is also done here.
771 * Return 0 on success or a negative error code otherwise
773 static int ispif_set_stream(struct v4l2_subdev
*sd
, int enable
)
775 struct ispif_line
*line
= v4l2_get_subdevdata(sd
);
776 struct ispif_device
*ispif
= line
->ispif
;
777 enum ispif_intf intf
= line
->interface
;
778 u8 csid
= line
->csid_id
;
779 u8 vfe
= line
->vfe_id
;
780 u8 vc
= 0; /* Virtual Channel 0 */
781 u8 cid
= vc
* 4; /* id of Virtual Channel and Data Type set */
785 if (!media_entity_remote_pad(&line
->pads
[MSM_ISPIF_PAD_SINK
]))
790 mutex_lock(&ispif
->config_lock
);
791 ispif_select_clk_mux(ispif
, intf
, csid
, vfe
, 1);
793 ret
= ispif_validate_intf_status(ispif
, intf
, vfe
);
795 mutex_unlock(&ispif
->config_lock
);
799 ispif_select_csid(ispif
, intf
, csid
, vfe
, 1);
800 ispif_select_cid(ispif
, intf
, cid
, vfe
, 1);
801 ispif_config_irq(ispif
, intf
, vfe
, 1);
802 if (to_camss(ispif
)->version
== CAMSS_8x96
)
803 ispif_config_pack(ispif
,
804 line
->fmt
[MSM_ISPIF_PAD_SINK
].code
,
806 ispif_set_intf_cmd(ispif
, CMD_ENABLE_FRAME_BOUNDARY
,
809 mutex_lock(&ispif
->config_lock
);
810 ispif_set_intf_cmd(ispif
, CMD_DISABLE_FRAME_BOUNDARY
,
812 mutex_unlock(&ispif
->config_lock
);
814 ret
= ispif_wait_for_stop(ispif
, intf
, vfe
);
818 mutex_lock(&ispif
->config_lock
);
819 if (to_camss(ispif
)->version
== CAMSS_8x96
)
820 ispif_config_pack(ispif
,
821 line
->fmt
[MSM_ISPIF_PAD_SINK
].code
,
823 ispif_config_irq(ispif
, intf
, vfe
, 0);
824 ispif_select_cid(ispif
, intf
, cid
, vfe
, 0);
825 ispif_select_csid(ispif
, intf
, csid
, vfe
, 0);
826 ispif_select_clk_mux(ispif
, intf
, csid
, vfe
, 0);
829 mutex_unlock(&ispif
->config_lock
);
835 * __ispif_get_format - Get pointer to format structure
837 * @cfg: V4L2 subdev pad configuration
838 * @pad: pad from which format is requested
839 * @which: TRY or ACTIVE format
841 * Return pointer to TRY or ACTIVE format structure
843 static struct v4l2_mbus_framefmt
*
844 __ispif_get_format(struct ispif_line
*line
,
845 struct v4l2_subdev_pad_config
*cfg
,
847 enum v4l2_subdev_format_whence which
)
849 if (which
== V4L2_SUBDEV_FORMAT_TRY
)
850 return v4l2_subdev_get_try_format(&line
->subdev
, cfg
, pad
);
852 return &line
->fmt
[pad
];
856 * ispif_try_format - Handle try format by pad subdev method
858 * @cfg: V4L2 subdev pad configuration
859 * @pad: pad on which format is requested
860 * @fmt: pointer to v4l2 format structure
861 * @which: wanted subdev format
863 static void ispif_try_format(struct ispif_line
*line
,
864 struct v4l2_subdev_pad_config
*cfg
,
866 struct v4l2_mbus_framefmt
*fmt
,
867 enum v4l2_subdev_format_whence which
)
872 case MSM_ISPIF_PAD_SINK
:
873 /* Set format on sink pad */
875 for (i
= 0; i
< line
->nformats
; i
++)
876 if (fmt
->code
== line
->formats
[i
])
879 /* If not found, use UYVY as default */
880 if (i
>= line
->nformats
)
881 fmt
->code
= MEDIA_BUS_FMT_UYVY8_2X8
;
883 fmt
->width
= clamp_t(u32
, fmt
->width
, 1, 8191);
884 fmt
->height
= clamp_t(u32
, fmt
->height
, 1, 8191);
886 fmt
->field
= V4L2_FIELD_NONE
;
887 fmt
->colorspace
= V4L2_COLORSPACE_SRGB
;
891 case MSM_ISPIF_PAD_SRC
:
892 /* Set and return a format same as sink pad */
894 *fmt
= *__ispif_get_format(line
, cfg
, MSM_ISPIF_PAD_SINK
,
900 fmt
->colorspace
= V4L2_COLORSPACE_SRGB
;
904 * ispif_enum_mbus_code - Handle pixel format enumeration
905 * @sd: ISPIF V4L2 subdevice
906 * @cfg: V4L2 subdev pad configuration
907 * @code: pointer to v4l2_subdev_mbus_code_enum structure
908 * return -EINVAL or zero on success
910 static int ispif_enum_mbus_code(struct v4l2_subdev
*sd
,
911 struct v4l2_subdev_pad_config
*cfg
,
912 struct v4l2_subdev_mbus_code_enum
*code
)
914 struct ispif_line
*line
= v4l2_get_subdevdata(sd
);
915 struct v4l2_mbus_framefmt
*format
;
917 if (code
->pad
== MSM_ISPIF_PAD_SINK
) {
918 if (code
->index
>= line
->nformats
)
921 code
->code
= line
->formats
[code
->index
];
926 format
= __ispif_get_format(line
, cfg
, MSM_ISPIF_PAD_SINK
,
929 code
->code
= format
->code
;
936 * ispif_enum_frame_size - Handle frame size enumeration
937 * @sd: ISPIF V4L2 subdevice
938 * @cfg: V4L2 subdev pad configuration
939 * @fse: pointer to v4l2_subdev_frame_size_enum structure
940 * return -EINVAL or zero on success
942 static int ispif_enum_frame_size(struct v4l2_subdev
*sd
,
943 struct v4l2_subdev_pad_config
*cfg
,
944 struct v4l2_subdev_frame_size_enum
*fse
)
946 struct ispif_line
*line
= v4l2_get_subdevdata(sd
);
947 struct v4l2_mbus_framefmt format
;
952 format
.code
= fse
->code
;
955 ispif_try_format(line
, cfg
, fse
->pad
, &format
, fse
->which
);
956 fse
->min_width
= format
.width
;
957 fse
->min_height
= format
.height
;
959 if (format
.code
!= fse
->code
)
962 format
.code
= fse
->code
;
965 ispif_try_format(line
, cfg
, fse
->pad
, &format
, fse
->which
);
966 fse
->max_width
= format
.width
;
967 fse
->max_height
= format
.height
;
973 * ispif_get_format - Handle get format by pads subdev method
974 * @sd: ISPIF V4L2 subdevice
975 * @cfg: V4L2 subdev pad configuration
976 * @fmt: pointer to v4l2 subdev format structure
978 * Return -EINVAL or zero on success
980 static int ispif_get_format(struct v4l2_subdev
*sd
,
981 struct v4l2_subdev_pad_config
*cfg
,
982 struct v4l2_subdev_format
*fmt
)
984 struct ispif_line
*line
= v4l2_get_subdevdata(sd
);
985 struct v4l2_mbus_framefmt
*format
;
987 format
= __ispif_get_format(line
, cfg
, fmt
->pad
, fmt
->which
);
991 fmt
->format
= *format
;
997 * ispif_set_format - Handle set format by pads subdev method
998 * @sd: ISPIF V4L2 subdevice
999 * @cfg: V4L2 subdev pad configuration
1000 * @fmt: pointer to v4l2 subdev format structure
1002 * Return -EINVAL or zero on success
1004 static int ispif_set_format(struct v4l2_subdev
*sd
,
1005 struct v4l2_subdev_pad_config
*cfg
,
1006 struct v4l2_subdev_format
*fmt
)
1008 struct ispif_line
*line
= v4l2_get_subdevdata(sd
);
1009 struct v4l2_mbus_framefmt
*format
;
1011 format
= __ispif_get_format(line
, cfg
, fmt
->pad
, fmt
->which
);
1015 ispif_try_format(line
, cfg
, fmt
->pad
, &fmt
->format
, fmt
->which
);
1016 *format
= fmt
->format
;
1018 /* Propagate the format from sink to source */
1019 if (fmt
->pad
== MSM_ISPIF_PAD_SINK
) {
1020 format
= __ispif_get_format(line
, cfg
, MSM_ISPIF_PAD_SRC
,
1023 *format
= fmt
->format
;
1024 ispif_try_format(line
, cfg
, MSM_ISPIF_PAD_SRC
, format
,
1032 * ispif_init_formats - Initialize formats on all pads
1033 * @sd: ISPIF V4L2 subdevice
1034 * @fh: V4L2 subdev file handle
1036 * Initialize all pad formats with default values.
1038 * Return 0 on success or a negative error code otherwise
1040 static int ispif_init_formats(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
1042 struct v4l2_subdev_format format
= {
1043 .pad
= MSM_ISPIF_PAD_SINK
,
1044 .which
= fh
? V4L2_SUBDEV_FORMAT_TRY
:
1045 V4L2_SUBDEV_FORMAT_ACTIVE
,
1047 .code
= MEDIA_BUS_FMT_UYVY8_2X8
,
1053 return ispif_set_format(sd
, fh
? fh
->pad
: NULL
, &format
);
1057 * msm_ispif_subdev_init - Initialize ISPIF device structure and resources
1058 * @ispif: ISPIF device
1059 * @res: ISPIF module resources table
1061 * Return 0 on success or a negative error code otherwise
1063 int msm_ispif_subdev_init(struct ispif_device
*ispif
,
1064 const struct resources_ispif
*res
)
1066 struct device
*dev
= to_device(ispif
);
1067 struct platform_device
*pdev
= to_platform_device(dev
);
1072 /* Number of ISPIF lines - same as number of CSID hardware modules */
1073 if (to_camss(ispif
)->version
== CAMSS_8x16
)
1074 ispif
->line_num
= 2;
1075 else if (to_camss(ispif
)->version
== CAMSS_8x96
)
1076 ispif
->line_num
= 4;
1080 ispif
->line
= devm_kcalloc(dev
, ispif
->line_num
, sizeof(*ispif
->line
),
1085 for (i
= 0; i
< ispif
->line_num
; i
++) {
1086 ispif
->line
[i
].ispif
= ispif
;
1087 ispif
->line
[i
].id
= i
;
1089 if (to_camss(ispif
)->version
== CAMSS_8x16
) {
1090 ispif
->line
[i
].formats
= ispif_formats_8x16
;
1091 ispif
->line
[i
].nformats
=
1092 ARRAY_SIZE(ispif_formats_8x16
);
1093 } else if (to_camss(ispif
)->version
== CAMSS_8x96
) {
1094 ispif
->line
[i
].formats
= ispif_formats_8x96
;
1095 ispif
->line
[i
].nformats
=
1096 ARRAY_SIZE(ispif_formats_8x96
);
1104 r
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, res
->reg
[0]);
1105 ispif
->base
= devm_ioremap_resource(dev
, r
);
1106 if (IS_ERR(ispif
->base
)) {
1107 dev_err(dev
, "could not map memory\n");
1108 return PTR_ERR(ispif
->base
);
1111 r
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, res
->reg
[1]);
1112 ispif
->base_clk_mux
= devm_ioremap_resource(dev
, r
);
1113 if (IS_ERR(ispif
->base_clk_mux
)) {
1114 dev_err(dev
, "could not map memory\n");
1115 return PTR_ERR(ispif
->base_clk_mux
);
1120 r
= platform_get_resource_byname(pdev
, IORESOURCE_IRQ
, res
->interrupt
);
1123 dev_err(dev
, "missing IRQ\n");
1127 ispif
->irq
= r
->start
;
1128 snprintf(ispif
->irq_name
, sizeof(ispif
->irq_name
), "%s_%s",
1129 dev_name(dev
), MSM_ISPIF_NAME
);
1130 if (to_camss(ispif
)->version
== CAMSS_8x16
)
1131 ret
= devm_request_irq(dev
, ispif
->irq
, ispif_isr_8x16
,
1132 IRQF_TRIGGER_RISING
, ispif
->irq_name
, ispif
);
1133 else if (to_camss(ispif
)->version
== CAMSS_8x96
)
1134 ret
= devm_request_irq(dev
, ispif
->irq
, ispif_isr_8x96
,
1135 IRQF_TRIGGER_RISING
, ispif
->irq_name
, ispif
);
1139 dev_err(dev
, "request_irq failed: %d\n", ret
);
1146 while (res
->clock
[ispif
->nclocks
])
1149 ispif
->clock
= devm_kcalloc(dev
,
1150 ispif
->nclocks
, sizeof(*ispif
->clock
),
1155 for (i
= 0; i
< ispif
->nclocks
; i
++) {
1156 struct camss_clock
*clock
= &ispif
->clock
[i
];
1158 clock
->clk
= devm_clk_get(dev
, res
->clock
[i
]);
1159 if (IS_ERR(clock
->clk
))
1160 return PTR_ERR(clock
->clk
);
1166 ispif
->nclocks_for_reset
= 0;
1167 while (res
->clock_for_reset
[ispif
->nclocks_for_reset
])
1168 ispif
->nclocks_for_reset
++;
1170 ispif
->clock_for_reset
= devm_kcalloc(dev
,
1171 ispif
->nclocks_for_reset
,
1172 sizeof(*ispif
->clock_for_reset
),
1174 if (!ispif
->clock_for_reset
)
1177 for (i
= 0; i
< ispif
->nclocks_for_reset
; i
++) {
1178 struct camss_clock
*clock
= &ispif
->clock_for_reset
[i
];
1180 clock
->clk
= devm_clk_get(dev
, res
->clock_for_reset
[i
]);
1181 if (IS_ERR(clock
->clk
))
1182 return PTR_ERR(clock
->clk
);
1188 mutex_init(&ispif
->power_lock
);
1189 ispif
->power_count
= 0;
1191 mutex_init(&ispif
->config_lock
);
1193 init_completion(&ispif
->reset_complete
);
1199 * ispif_get_intf - Get ISPIF interface to use by VFE line id
1200 * @line_id: VFE line id that the ISPIF line is connected to
1202 * Return ISPIF interface to use
1204 static enum ispif_intf
ispif_get_intf(enum vfe_line_id line_id
)
1207 case (VFE_LINE_RDI0
):
1209 case (VFE_LINE_RDI1
):
1211 case (VFE_LINE_RDI2
):
1213 case (VFE_LINE_PIX
):
1221 * ispif_link_setup - Setup ISPIF connections
1222 * @entity: Pointer to media entity structure
1223 * @local: Pointer to local pad
1224 * @remote: Pointer to remote pad
1225 * @flags: Link flags
1227 * Return 0 on success
1229 static int ispif_link_setup(struct media_entity
*entity
,
1230 const struct media_pad
*local
,
1231 const struct media_pad
*remote
, u32 flags
)
1233 if (flags
& MEDIA_LNK_FL_ENABLED
) {
1234 if (media_entity_remote_pad(local
))
1237 if (local
->flags
& MEDIA_PAD_FL_SINK
) {
1238 struct v4l2_subdev
*sd
;
1239 struct ispif_line
*line
;
1241 sd
= media_entity_to_v4l2_subdev(entity
);
1242 line
= v4l2_get_subdevdata(sd
);
1244 msm_csid_get_csid_id(remote
->entity
, &line
->csid_id
);
1245 } else { /* MEDIA_PAD_FL_SOURCE */
1246 struct v4l2_subdev
*sd
;
1247 struct ispif_line
*line
;
1248 enum vfe_line_id id
;
1250 sd
= media_entity_to_v4l2_subdev(entity
);
1251 line
= v4l2_get_subdevdata(sd
);
1253 msm_vfe_get_vfe_id(remote
->entity
, &line
->vfe_id
);
1254 msm_vfe_get_vfe_line_id(remote
->entity
, &id
);
1255 line
->interface
= ispif_get_intf(id
);
1262 static const struct v4l2_subdev_core_ops ispif_core_ops
= {
1263 .s_power
= ispif_set_power
,
1266 static const struct v4l2_subdev_video_ops ispif_video_ops
= {
1267 .s_stream
= ispif_set_stream
,
1270 static const struct v4l2_subdev_pad_ops ispif_pad_ops
= {
1271 .enum_mbus_code
= ispif_enum_mbus_code
,
1272 .enum_frame_size
= ispif_enum_frame_size
,
1273 .get_fmt
= ispif_get_format
,
1274 .set_fmt
= ispif_set_format
,
1277 static const struct v4l2_subdev_ops ispif_v4l2_ops
= {
1278 .core
= &ispif_core_ops
,
1279 .video
= &ispif_video_ops
,
1280 .pad
= &ispif_pad_ops
,
1283 static const struct v4l2_subdev_internal_ops ispif_v4l2_internal_ops
= {
1284 .open
= ispif_init_formats
,
1287 static const struct media_entity_operations ispif_media_ops
= {
1288 .link_setup
= ispif_link_setup
,
1289 .link_validate
= v4l2_subdev_link_validate
,
1293 * msm_ispif_register_entities - Register subdev node for ISPIF module
1294 * @ispif: ISPIF device
1295 * @v4l2_dev: V4L2 device
1297 * Return 0 on success or a negative error code otherwise
1299 int msm_ispif_register_entities(struct ispif_device
*ispif
,
1300 struct v4l2_device
*v4l2_dev
)
1302 struct device
*dev
= to_device(ispif
);
1306 for (i
= 0; i
< ispif
->line_num
; i
++) {
1307 struct v4l2_subdev
*sd
= &ispif
->line
[i
].subdev
;
1308 struct media_pad
*pads
= ispif
->line
[i
].pads
;
1310 v4l2_subdev_init(sd
, &ispif_v4l2_ops
);
1311 sd
->internal_ops
= &ispif_v4l2_internal_ops
;
1312 sd
->flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
1313 snprintf(sd
->name
, ARRAY_SIZE(sd
->name
), "%s%d",
1315 v4l2_set_subdevdata(sd
, &ispif
->line
[i
]);
1317 ret
= ispif_init_formats(sd
, NULL
);
1319 dev_err(dev
, "Failed to init format: %d\n", ret
);
1323 pads
[MSM_ISPIF_PAD_SINK
].flags
= MEDIA_PAD_FL_SINK
;
1324 pads
[MSM_ISPIF_PAD_SRC
].flags
= MEDIA_PAD_FL_SOURCE
;
1326 sd
->entity
.function
= MEDIA_ENT_F_IO_V4L
;
1327 sd
->entity
.ops
= &ispif_media_ops
;
1328 ret
= media_entity_pads_init(&sd
->entity
, MSM_ISPIF_PADS_NUM
,
1331 dev_err(dev
, "Failed to init media entity: %d\n", ret
);
1335 ret
= v4l2_device_register_subdev(v4l2_dev
, sd
);
1337 dev_err(dev
, "Failed to register subdev: %d\n", ret
);
1338 media_entity_cleanup(&sd
->entity
);
1346 for (i
--; i
>= 0; i
--) {
1347 struct v4l2_subdev
*sd
= &ispif
->line
[i
].subdev
;
1349 v4l2_device_unregister_subdev(sd
);
1350 media_entity_cleanup(&sd
->entity
);
1357 * msm_ispif_unregister_entities - Unregister ISPIF module subdev node
1358 * @ispif: ISPIF device
1360 void msm_ispif_unregister_entities(struct ispif_device
*ispif
)
1364 mutex_destroy(&ispif
->power_lock
);
1365 mutex_destroy(&ispif
->config_lock
);
1367 for (i
= 0; i
< ispif
->line_num
; i
++) {
1368 struct v4l2_subdev
*sd
= &ispif
->line
[i
].subdev
;
1370 v4l2_device_unregister_subdev(sd
);
1371 media_entity_cleanup(&sd
->entity
);