1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 Intel Corporation
4 #include <linux/device.h>
5 #include <linux/iopoll.h>
6 #include <linux/slab.h>
10 #include "ipu3-css-fw.h"
11 #include "ipu3-css-params.h"
12 #include "ipu3-dmamap.h"
13 #include "ipu3-tables.h"
15 /* IRQ configuration */
16 #define IMGU_IRQCTRL_IRQ_MASK (IMGU_IRQCTRL_IRQ_SP1 | \
17 IMGU_IRQCTRL_IRQ_SP2 | \
18 IMGU_IRQCTRL_IRQ_SW_PIN(0) | \
19 IMGU_IRQCTRL_IRQ_SW_PIN(1))
21 #define IPU3_CSS_FORMAT_BPP_DEN 50 /* Denominator */
23 /* Some sane limits for resolutions */
24 #define IPU3_CSS_MIN_RES 32
25 #define IPU3_CSS_MAX_H 3136
26 #define IPU3_CSS_MAX_W 4224
28 /* minimal envelope size(GDC in - out) should be 4 */
29 #define MIN_ENVELOPE 4
32 * pre-allocated buffer size for CSS ABI, auxiliary frames
33 * after BDS and before GDC. Those values should be tuned
34 * to big enough to avoid buffer re-allocation when
35 * streaming to lower streaming latency.
37 #define CSS_ABI_SIZE 136
38 #define CSS_BDS_SIZE (4480 * 3200 * 3)
39 #define CSS_GDC_SIZE (4224 * 3200 * 12 / 8)
41 #define IPU3_CSS_QUEUE_TO_FLAGS(q) (1 << (q))
42 #define IPU3_CSS_FORMAT_FL_IN \
43 IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_IN)
44 #define IPU3_CSS_FORMAT_FL_OUT \
45 IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_OUT)
46 #define IPU3_CSS_FORMAT_FL_VF \
47 IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_VF)
49 /* Formats supported by IPU3 Camera Sub System */
50 static const struct imgu_css_format imgu_css_formats[] = {
52 .pixelformat = V4L2_PIX_FMT_NV12,
53 .colorspace = V4L2_COLORSPACE_SRGB,
54 .frame_format = IMGU_ABI_FRAME_FORMAT_NV12,
55 .osys_format = IMGU_ABI_OSYS_FORMAT_NV12,
56 .osys_tiling = IMGU_ABI_OSYS_TILING_NONE,
58 .width_align = IPU3_UAPI_ISP_VEC_ELEMS,
59 .flags = IPU3_CSS_FORMAT_FL_OUT | IPU3_CSS_FORMAT_FL_VF,
61 /* Each 32 bytes contains 25 10-bit pixels */
62 .pixelformat = V4L2_PIX_FMT_IPU3_SBGGR10,
63 .colorspace = V4L2_COLORSPACE_RAW,
64 .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
65 .bayer_order = IMGU_ABI_BAYER_ORDER_BGGR,
67 .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
68 .flags = IPU3_CSS_FORMAT_FL_IN,
70 .pixelformat = V4L2_PIX_FMT_IPU3_SGBRG10,
71 .colorspace = V4L2_COLORSPACE_RAW,
72 .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
73 .bayer_order = IMGU_ABI_BAYER_ORDER_GBRG,
75 .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
76 .flags = IPU3_CSS_FORMAT_FL_IN,
78 .pixelformat = V4L2_PIX_FMT_IPU3_SGRBG10,
79 .colorspace = V4L2_COLORSPACE_RAW,
80 .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
81 .bayer_order = IMGU_ABI_BAYER_ORDER_GRBG,
83 .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
84 .flags = IPU3_CSS_FORMAT_FL_IN,
86 .pixelformat = V4L2_PIX_FMT_IPU3_SRGGB10,
87 .colorspace = V4L2_COLORSPACE_RAW,
88 .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
89 .bayer_order = IMGU_ABI_BAYER_ORDER_RGGB,
91 .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
92 .flags = IPU3_CSS_FORMAT_FL_IN,
97 enum imgu_abi_queue_id qid;
99 } imgu_css_queues[IPU3_CSS_QUEUES] = {
100 [IPU3_CSS_QUEUE_IN] = {
102 offsetof(struct imgu_abi_buffer, payload.frame.frame_data)
104 [IPU3_CSS_QUEUE_OUT] = {
106 offsetof(struct imgu_abi_buffer, payload.frame.frame_data)
108 [IPU3_CSS_QUEUE_VF] = {
110 offsetof(struct imgu_abi_buffer, payload.frame.frame_data)
112 [IPU3_CSS_QUEUE_STAT_3A] = {
114 offsetof(struct imgu_abi_buffer, payload.s3a.data_ptr)
118 /* Initialize queue based on given format, adjust format as needed */
119 static int imgu_css_queue_init(struct imgu_css_queue *queue,
120 struct v4l2_pix_format_mplane *fmt, u32 flags)
122 struct v4l2_pix_format_mplane *const f = &queue->fmt.mpix;
126 INIT_LIST_HEAD(&queue->bufs);
128 queue->css_fmt = NULL; /* Disable */
132 for (i = 0; i < ARRAY_SIZE(imgu_css_formats); i++) {
133 if (!(imgu_css_formats[i].flags & flags))
135 queue->css_fmt = &imgu_css_formats[i];
136 if (imgu_css_formats[i].pixelformat == fmt->pixelformat)
140 return -EINVAL; /* Could not find any suitable format */
142 queue->fmt.mpix = *fmt;
144 f->width = ALIGN(clamp_t(u32, f->width,
145 IPU3_CSS_MIN_RES, IPU3_CSS_MAX_W), 2);
146 f->height = ALIGN(clamp_t(u32, f->height,
147 IPU3_CSS_MIN_RES, IPU3_CSS_MAX_H), 2);
148 queue->width_pad = ALIGN(f->width, queue->css_fmt->width_align);
149 f->plane_fmt[0].bytesperline =
150 imgu_bytesperline(f->width, queue->css_fmt->frame_format);
151 sizeimage = f->height * f->plane_fmt[0].bytesperline;
152 if (queue->css_fmt->chroma_decim)
153 sizeimage += 2 * sizeimage / queue->css_fmt->chroma_decim;
155 f->plane_fmt[0].sizeimage = sizeimage;
156 f->field = V4L2_FIELD_NONE;
158 f->colorspace = queue->css_fmt->colorspace;
160 f->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
161 f->quantization = V4L2_QUANTIZATION_DEFAULT;
162 f->xfer_func = V4L2_XFER_FUNC_DEFAULT;
163 memset(f->reserved, 0, sizeof(f->reserved));
168 static bool imgu_css_queue_enabled(struct imgu_css_queue *q)
173 /******************* css hw *******************/
175 /* In the style of writesl() defined in include/asm-generic/io.h */
176 static inline void writes(const void *mem, ssize_t count, void __iomem *addr)
179 const u32 *buf = mem;
183 writel(*buf++, addr);
189 /* Wait until register `reg', masked with `mask', becomes `cmp' */
190 static int imgu_hw_wait(void __iomem *base, int reg, u32 mask, u32 cmp)
194 return readl_poll_timeout(base + reg, val, (val & mask) == cmp,
198 /* Initialize the IPU3 CSS hardware and associated h/w blocks */
200 int imgu_css_set_powerup(struct device *dev, void __iomem *base,
203 u32 pm_ctrl, state, val;
205 dev_dbg(dev, "%s with freq %u\n", __func__, freq);
206 /* Clear the CSS busy signal */
207 readl(base + IMGU_REG_GP_BUSY);
208 writel(0, base + IMGU_REG_GP_BUSY);
210 /* Wait for idle signal */
211 if (imgu_hw_wait(base, IMGU_REG_STATE, IMGU_STATE_IDLE_STS,
212 IMGU_STATE_IDLE_STS)) {
213 dev_err(dev, "failed to set CSS idle\n");
218 writel(readl(base + IMGU_REG_PM_CTRL) | IMGU_PM_CTRL_FORCE_RESET,
219 base + IMGU_REG_PM_CTRL);
221 usleep_range(200, 300);
225 pm_ctrl = readl(base + IMGU_REG_PM_CTRL);
226 state = readl(base + IMGU_REG_STATE);
228 dev_dbg(dev, "CSS pm_ctrl 0x%x state 0x%x (power %s)\n",
229 pm_ctrl, state, state & IMGU_STATE_POWER_DOWN ? "down" : "up");
231 /* Power up CSS using wrapper */
232 if (state & IMGU_STATE_POWER_DOWN) {
233 writel(IMGU_PM_CTRL_RACE_TO_HALT | IMGU_PM_CTRL_START,
234 base + IMGU_REG_PM_CTRL);
235 if (imgu_hw_wait(base, IMGU_REG_PM_CTRL,
236 IMGU_PM_CTRL_START, 0)) {
237 dev_err(dev, "failed to power up CSS\n");
240 usleep_range(2000, 3000);
242 writel(IMGU_PM_CTRL_RACE_TO_HALT, base + IMGU_REG_PM_CTRL);
245 /* Set the busy bit */
246 writel(readl(base + IMGU_REG_GP_BUSY) | 1, base + IMGU_REG_GP_BUSY);
248 /* Set CSS clock frequency */
249 pm_ctrl = readl(base + IMGU_REG_PM_CTRL);
250 val = pm_ctrl & ~(IMGU_PM_CTRL_CSS_PWRDN | IMGU_PM_CTRL_RST_AT_EOF);
251 writel(val, base + IMGU_REG_PM_CTRL);
252 writel(0, base + IMGU_REG_GP_BUSY);
253 if (imgu_hw_wait(base, IMGU_REG_STATE,
254 IMGU_STATE_PWRDNM_FSM_MASK, 0)) {
255 dev_err(dev, "failed to pwrdn CSS\n");
258 val = (freq / IMGU_SYSTEM_REQ_FREQ_DIVIDER) & IMGU_SYSTEM_REQ_FREQ_MASK;
259 writel(val, base + IMGU_REG_SYSTEM_REQ);
260 writel(1, base + IMGU_REG_GP_BUSY);
261 writel(readl(base + IMGU_REG_PM_CTRL) | IMGU_PM_CTRL_FORCE_HALT,
262 base + IMGU_REG_PM_CTRL);
263 if (imgu_hw_wait(base, IMGU_REG_STATE, IMGU_STATE_HALT_STS,
264 IMGU_STATE_HALT_STS)) {
265 dev_err(dev, "failed to halt CSS\n");
269 writel(readl(base + IMGU_REG_PM_CTRL) | IMGU_PM_CTRL_START,
270 base + IMGU_REG_PM_CTRL);
271 if (imgu_hw_wait(base, IMGU_REG_PM_CTRL, IMGU_PM_CTRL_START, 0)) {
272 dev_err(dev, "failed to start CSS\n");
275 writel(readl(base + IMGU_REG_PM_CTRL) | IMGU_PM_CTRL_FORCE_UNHALT,
276 base + IMGU_REG_PM_CTRL);
278 val = readl(base + IMGU_REG_PM_CTRL); /* get pm_ctrl */
279 val &= ~(IMGU_PM_CTRL_CSS_PWRDN | IMGU_PM_CTRL_RST_AT_EOF);
280 val |= pm_ctrl & (IMGU_PM_CTRL_CSS_PWRDN | IMGU_PM_CTRL_RST_AT_EOF);
281 writel(val, base + IMGU_REG_PM_CTRL);
286 imgu_css_set_powerdown(dev, base);
290 void imgu_css_set_powerdown(struct device *dev, void __iomem *base)
292 dev_dbg(dev, "%s\n", __func__);
293 /* wait for cio idle signal */
294 if (imgu_hw_wait(base, IMGU_REG_CIO_GATE_BURST_STATE,
295 IMGU_CIO_GATE_BURST_MASK, 0))
296 dev_warn(dev, "wait cio gate idle timeout");
298 /* wait for css idle signal */
299 if (imgu_hw_wait(base, IMGU_REG_STATE, IMGU_STATE_IDLE_STS,
300 IMGU_STATE_IDLE_STS))
301 dev_warn(dev, "wait css idle timeout\n");
303 /* do halt-halted handshake with css */
304 writel(1, base + IMGU_REG_GP_HALT);
305 if (imgu_hw_wait(base, IMGU_REG_STATE, IMGU_STATE_HALT_STS,
306 IMGU_STATE_HALT_STS))
307 dev_warn(dev, "failed to halt css");
309 /* de-assert the busy bit */
310 writel(0, base + IMGU_REG_GP_BUSY);
313 static void imgu_css_hw_enable_irq(struct imgu_css *css)
315 void __iomem *const base = css->base;
318 /* Set up interrupts */
321 * Enable IRQ on the SP which signals that SP goes to idle
322 * (aka ready state) and set trigger to pulse
324 val = readl(base + IMGU_REG_SP_CTRL(0)) | IMGU_CTRL_IRQ_READY;
325 writel(val, base + IMGU_REG_SP_CTRL(0));
326 writel(val | IMGU_CTRL_IRQ_CLEAR, base + IMGU_REG_SP_CTRL(0));
328 /* Enable IRQs from the IMGU wrapper */
329 writel(IMGU_REG_INT_CSS_IRQ, base + IMGU_REG_INT_ENABLE);
331 writel(IMGU_REG_INT_CSS_IRQ, base + IMGU_REG_INT_STATUS);
333 /* Enable IRQs from main IRQ controller */
334 writel(~0, base + IMGU_REG_IRQCTRL_EDGE_NOT_PULSE(IMGU_IRQCTRL_MAIN));
335 writel(0, base + IMGU_REG_IRQCTRL_MASK(IMGU_IRQCTRL_MAIN));
336 writel(IMGU_IRQCTRL_IRQ_MASK,
337 base + IMGU_REG_IRQCTRL_EDGE(IMGU_IRQCTRL_MAIN));
338 writel(IMGU_IRQCTRL_IRQ_MASK,
339 base + IMGU_REG_IRQCTRL_ENABLE(IMGU_IRQCTRL_MAIN));
340 writel(IMGU_IRQCTRL_IRQ_MASK,
341 base + IMGU_REG_IRQCTRL_CLEAR(IMGU_IRQCTRL_MAIN));
342 writel(IMGU_IRQCTRL_IRQ_MASK,
343 base + IMGU_REG_IRQCTRL_MASK(IMGU_IRQCTRL_MAIN));
344 /* Wait for write complete */
345 readl(base + IMGU_REG_IRQCTRL_ENABLE(IMGU_IRQCTRL_MAIN));
347 /* Enable IRQs from SP0 and SP1 controllers */
348 for (i = IMGU_IRQCTRL_SP0; i <= IMGU_IRQCTRL_SP1; i++) {
349 writel(~0, base + IMGU_REG_IRQCTRL_EDGE_NOT_PULSE(i));
350 writel(0, base + IMGU_REG_IRQCTRL_MASK(i));
351 writel(IMGU_IRQCTRL_IRQ_MASK, base + IMGU_REG_IRQCTRL_EDGE(i));
352 writel(IMGU_IRQCTRL_IRQ_MASK,
353 base + IMGU_REG_IRQCTRL_ENABLE(i));
354 writel(IMGU_IRQCTRL_IRQ_MASK, base + IMGU_REG_IRQCTRL_CLEAR(i));
355 writel(IMGU_IRQCTRL_IRQ_MASK, base + IMGU_REG_IRQCTRL_MASK(i));
356 /* Wait for write complete */
357 readl(base + IMGU_REG_IRQCTRL_ENABLE(i));
361 static int imgu_css_hw_init(struct imgu_css *css)
363 /* For checking that streaming monitor statuses are valid */
364 static const struct {
368 } stream_monitors[] = {
370 IMGU_REG_GP_SP1_STRMON_STAT,
371 IMGU_GP_STRMON_STAT_ISP_PORT_SP12ISP,
374 IMGU_REG_GP_ISP_STRMON_STAT,
375 IMGU_GP_STRMON_STAT_SP1_PORT_ISP2SP1,
378 IMGU_REG_GP_MOD_STRMON_STAT,
379 IMGU_GP_STRMON_STAT_MOD_PORT_ISP2DMA,
382 IMGU_REG_GP_ISP_STRMON_STAT,
383 IMGU_GP_STRMON_STAT_ISP_PORT_DMA2ISP,
386 IMGU_REG_GP_MOD_STRMON_STAT,
387 IMGU_GP_STRMON_STAT_MOD_PORT_CELLS2GDC,
390 IMGU_REG_GP_MOD_STRMON_STAT,
391 IMGU_GP_STRMON_STAT_MOD_PORT_GDC2CELLS,
394 IMGU_REG_GP_MOD_STRMON_STAT,
395 IMGU_GP_STRMON_STAT_MOD_PORT_SP12DMA,
398 IMGU_REG_GP_SP1_STRMON_STAT,
399 IMGU_GP_STRMON_STAT_SP1_PORT_DMA2SP1,
402 IMGU_REG_GP_MOD_STRMON_STAT,
403 IMGU_GP_STRMON_STAT_MOD_PORT_CELLS2GDC,
406 IMGU_REG_GP_MOD_STRMON_STAT,
407 IMGU_GP_STRMON_STAT_MOD_PORT_GDC2CELLS,
412 struct device *dev = css->dev;
413 void __iomem *const base = css->base;
416 /* Set instruction cache address and inv bit for ISP, SP, and SP1 */
417 for (i = 0; i < IMGU_NUM_SP; i++) {
418 struct imgu_fw_info *bi =
419 &css->fwp->binary_header[css->fw_sp[i]];
421 writel(css->binary[css->fw_sp[i]].daddr,
422 base + IMGU_REG_SP_ICACHE_ADDR(bi->type));
423 writel(readl(base + IMGU_REG_SP_CTRL(bi->type)) |
424 IMGU_CTRL_ICACHE_INV,
425 base + IMGU_REG_SP_CTRL(bi->type));
427 writel(css->binary[css->fw_bl].daddr, base + IMGU_REG_ISP_ICACHE_ADDR);
428 writel(readl(base + IMGU_REG_ISP_CTRL) | IMGU_CTRL_ICACHE_INV,
429 base + IMGU_REG_ISP_CTRL);
431 /* Check that IMGU hardware is ready */
433 if (!(readl(base + IMGU_REG_SP_CTRL(0)) & IMGU_CTRL_IDLE)) {
434 dev_err(dev, "SP is not idle\n");
437 if (!(readl(base + IMGU_REG_ISP_CTRL) & IMGU_CTRL_IDLE)) {
438 dev_err(dev, "ISP is not idle\n");
442 for (i = 0; i < ARRAY_SIZE(stream_monitors); i++) {
443 val = readl(base + stream_monitors[i].reg);
444 if (val & stream_monitors[i].mask) {
445 dev_err(dev, "error: Stream monitor %s is valid\n",
446 stream_monitors[i].name);
451 /* Initialize GDC with default values */
453 for (i = 0; i < ARRAY_SIZE(imgu_css_gdc_lut[0]); i++) {
454 u32 val0 = imgu_css_gdc_lut[0][i] & IMGU_GDC_LUT_MASK;
455 u32 val1 = imgu_css_gdc_lut[1][i] & IMGU_GDC_LUT_MASK;
456 u32 val2 = imgu_css_gdc_lut[2][i] & IMGU_GDC_LUT_MASK;
457 u32 val3 = imgu_css_gdc_lut[3][i] & IMGU_GDC_LUT_MASK;
459 writel(val0 | (val1 << 16),
460 base + IMGU_REG_GDC_LUT_BASE + i * 8);
461 writel(val2 | (val3 << 16),
462 base + IMGU_REG_GDC_LUT_BASE + i * 8 + 4);
468 /* Boot the given IPU3 CSS SP */
469 static int imgu_css_hw_start_sp(struct imgu_css *css, int sp)
471 void __iomem *const base = css->base;
472 struct imgu_fw_info *bi = &css->fwp->binary_header[css->fw_sp[sp]];
473 struct imgu_abi_sp_init_dmem_cfg dmem_cfg = {
474 .ddr_data_addr = css->binary[css->fw_sp[sp]].daddr
475 + bi->blob.data_source,
476 .dmem_data_addr = bi->blob.data_target,
477 .dmem_bss_addr = bi->blob.bss_target,
478 .data_size = bi->blob.data_size,
479 .bss_size = bi->blob.bss_size,
483 writes(&dmem_cfg, sizeof(dmem_cfg), base +
484 IMGU_REG_SP_DMEM_BASE(sp) + bi->info.sp.init_dmem_data);
486 writel(bi->info.sp.sp_entry, base + IMGU_REG_SP_START_ADDR(sp));
488 writel(readl(base + IMGU_REG_SP_CTRL(sp))
489 | IMGU_CTRL_START | IMGU_CTRL_RUN, base + IMGU_REG_SP_CTRL(sp));
491 if (imgu_hw_wait(css->base, IMGU_REG_SP_DMEM_BASE(sp)
492 + bi->info.sp.sw_state,
493 ~0, IMGU_ABI_SP_SWSTATE_INITIALIZED))
499 /* Start the IPU3 CSS ImgU (Imaging Unit) and all the SPs */
500 static int imgu_css_hw_start(struct imgu_css *css)
502 static const u32 event_mask =
503 ((1 << IMGU_ABI_EVTTYPE_OUT_FRAME_DONE) |
504 (1 << IMGU_ABI_EVTTYPE_2ND_OUT_FRAME_DONE) |
505 (1 << IMGU_ABI_EVTTYPE_VF_OUT_FRAME_DONE) |
506 (1 << IMGU_ABI_EVTTYPE_2ND_VF_OUT_FRAME_DONE) |
507 (1 << IMGU_ABI_EVTTYPE_3A_STATS_DONE) |
508 (1 << IMGU_ABI_EVTTYPE_DIS_STATS_DONE) |
509 (1 << IMGU_ABI_EVTTYPE_PIPELINE_DONE) |
510 (1 << IMGU_ABI_EVTTYPE_FRAME_TAGGED) |
511 (1 << IMGU_ABI_EVTTYPE_INPUT_FRAME_DONE) |
512 (1 << IMGU_ABI_EVTTYPE_METADATA_DONE) |
513 (1 << IMGU_ABI_EVTTYPE_ACC_STAGE_COMPLETE))
514 << IMGU_ABI_SP_COMM_EVENT_IRQ_MASK_OR_SHIFT;
516 void __iomem *const base = css->base;
517 struct imgu_fw_info *bi, *bl = &css->fwp->binary_header[css->fw_bl];
520 writel(IMGU_TLB_INVALIDATE, base + IMGU_REG_TLB_INVALIDATE);
522 /* Start bootloader */
524 writel(IMGU_ABI_BL_SWSTATE_BUSY,
525 base + IMGU_REG_ISP_DMEM_BASE + bl->info.bl.sw_state);
527 base + IMGU_REG_ISP_DMEM_BASE + bl->info.bl.num_dma_cmds);
529 for (i = 0; i < IMGU_NUM_SP; i++) {
530 int j = IMGU_NUM_SP - i - 1; /* load sp1 first, then sp0 */
531 struct imgu_fw_info *sp =
532 &css->fwp->binary_header[css->fw_sp[j]];
533 struct imgu_abi_bl_dma_cmd_entry dma_cmd = {
534 .src_addr = css->binary[css->fw_sp[j]].daddr
535 + sp->blob.text_source,
536 .size = sp->blob.text_size,
537 .dst_type = IMGU_ABI_BL_DMACMD_TYPE_SP_PMEM,
538 .dst_addr = IMGU_SP_PMEM_BASE(j),
541 writes(&dma_cmd, sizeof(dma_cmd),
542 base + IMGU_REG_ISP_DMEM_BASE + i * sizeof(dma_cmd) +
543 bl->info.bl.dma_cmd_list);
546 writel(bl->info.bl.bl_entry, base + IMGU_REG_ISP_START_ADDR);
548 writel(readl(base + IMGU_REG_ISP_CTRL)
549 | IMGU_CTRL_START | IMGU_CTRL_RUN, base + IMGU_REG_ISP_CTRL);
550 if (imgu_hw_wait(css->base, IMGU_REG_ISP_DMEM_BASE
551 + bl->info.bl.sw_state, ~0,
552 IMGU_ABI_BL_SWSTATE_OK)) {
553 dev_err(css->dev, "failed to start bootloader\n");
559 memset(css->xmem_sp_group_ptrs.vaddr, 0,
560 sizeof(struct imgu_abi_sp_group));
562 bi = &css->fwp->binary_header[css->fw_sp[0]];
564 writel(css->xmem_sp_group_ptrs.daddr,
565 base + IMGU_REG_SP_DMEM_BASE(0) + bi->info.sp.per_frame_data);
567 writel(IMGU_ABI_SP_SWSTATE_TERMINATED,
568 base + IMGU_REG_SP_DMEM_BASE(0) + bi->info.sp.sw_state);
569 writel(1, base + IMGU_REG_SP_DMEM_BASE(0) + bi->info.sp.invalidate_tlb);
571 if (imgu_css_hw_start_sp(css, 0))
574 writel(0, base + IMGU_REG_SP_DMEM_BASE(0) + bi->info.sp.isp_started);
575 writel(0, base + IMGU_REG_SP_DMEM_BASE(0) +
576 bi->info.sp.host_sp_queues_initialized);
577 writel(0, base + IMGU_REG_SP_DMEM_BASE(0) + bi->info.sp.sleep_mode);
578 writel(0, base + IMGU_REG_SP_DMEM_BASE(0) + bi->info.sp.invalidate_tlb);
579 writel(IMGU_ABI_SP_COMM_COMMAND_READY, base + IMGU_REG_SP_DMEM_BASE(0)
580 + bi->info.sp.host_sp_com + IMGU_ABI_SP_COMM_COMMAND);
582 /* Enable all events for all queues */
584 for (i = 0; i < IPU3_CSS_PIPE_ID_NUM; i++)
585 writel(event_mask, base + IMGU_REG_SP_DMEM_BASE(0)
586 + bi->info.sp.host_sp_com
587 + IMGU_ABI_SP_COMM_EVENT_IRQ_MASK(i));
588 writel(1, base + IMGU_REG_SP_DMEM_BASE(0) +
589 bi->info.sp.host_sp_queues_initialized);
593 bi = &css->fwp->binary_header[css->fw_sp[1]];
595 writel(IMGU_ABI_SP_SWSTATE_TERMINATED,
596 base + IMGU_REG_SP_DMEM_BASE(1) + bi->info.sp.sw_state);
598 if (imgu_css_hw_start_sp(css, 1))
601 writel(IMGU_ABI_SP_COMM_COMMAND_READY, base + IMGU_REG_SP_DMEM_BASE(1)
602 + bi->info.sp.host_sp_com + IMGU_ABI_SP_COMM_COMMAND);
607 static void imgu_css_hw_stop(struct imgu_css *css)
609 void __iomem *const base = css->base;
610 struct imgu_fw_info *bi = &css->fwp->binary_header[css->fw_sp[0]];
613 writel(IMGU_ABI_SP_COMM_COMMAND_TERMINATE,
614 base + IMGU_REG_SP_DMEM_BASE(0) +
615 bi->info.sp.host_sp_com + IMGU_ABI_SP_COMM_COMMAND);
616 if (imgu_hw_wait(css->base, IMGU_REG_SP_CTRL(0),
617 IMGU_CTRL_IDLE, IMGU_CTRL_IDLE))
618 dev_err(css->dev, "wait sp0 idle timeout.\n");
619 if (readl(base + IMGU_REG_SP_DMEM_BASE(0) + bi->info.sp.sw_state) !=
620 IMGU_ABI_SP_SWSTATE_TERMINATED)
621 dev_err(css->dev, "sp0 is not terminated.\n");
622 if (imgu_hw_wait(css->base, IMGU_REG_ISP_CTRL,
623 IMGU_CTRL_IDLE, IMGU_CTRL_IDLE))
624 dev_err(css->dev, "wait isp idle timeout\n");
627 static void imgu_css_hw_cleanup(struct imgu_css *css)
629 void __iomem *const base = css->base;
633 /* Clear the CSS busy signal */
634 readl(base + IMGU_REG_GP_BUSY);
635 writel(0, base + IMGU_REG_GP_BUSY);
637 /* Wait for idle signal */
638 if (imgu_hw_wait(css->base, IMGU_REG_STATE, IMGU_STATE_IDLE_STS,
639 IMGU_STATE_IDLE_STS))
640 dev_err(css->dev, "failed to shut down hw cleanly\n");
643 writel(readl(base + IMGU_REG_PM_CTRL) | IMGU_PM_CTRL_FORCE_RESET,
644 base + IMGU_REG_PM_CTRL);
646 usleep_range(200, 300);
649 static void imgu_css_pipeline_cleanup(struct imgu_css *css, unsigned int pipe)
651 struct imgu_device *imgu = dev_get_drvdata(css->dev);
652 struct imgu_css_pipe *css_pipe = &css->pipes[pipe];
655 imgu_css_pool_cleanup(imgu, &css_pipe->pool.parameter_set_info);
656 imgu_css_pool_cleanup(imgu, &css_pipe->pool.acc);
657 imgu_css_pool_cleanup(imgu, &css_pipe->pool.gdc);
658 imgu_css_pool_cleanup(imgu, &css_pipe->pool.obgrid);
660 for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++)
661 imgu_css_pool_cleanup(imgu, &css_pipe->pool.binary_params_p[i]);
665 * This function initializes various stages of the
666 * IPU3 CSS ISP pipeline
668 static int imgu_css_pipeline_init(struct imgu_css *css, unsigned int pipe)
670 static const int BYPC = 2; /* Bytes per component */
671 static const struct imgu_abi_buffer_sp buffer_sp_init = {
672 .buf_src = {.queue_id = IMGU_ABI_QUEUE_EVENT_ID},
673 .buf_type = IMGU_ABI_BUFFER_TYPE_INVALID,
676 struct imgu_abi_isp_iterator_config *cfg_iter;
677 struct imgu_abi_isp_ref_config *cfg_ref;
678 struct imgu_abi_isp_dvs_config *cfg_dvs;
679 struct imgu_abi_isp_tnr3_config *cfg_tnr;
680 struct imgu_abi_isp_ref_dmem_state *cfg_ref_state;
681 struct imgu_abi_isp_tnr3_dmem_state *cfg_tnr_state;
686 struct imgu_css_pipe *css_pipe = &css->pipes[pipe];
687 struct imgu_css_queue *css_queue_in =
688 &css_pipe->queue[IPU3_CSS_QUEUE_IN];
689 struct imgu_css_queue *css_queue_out =
690 &css_pipe->queue[IPU3_CSS_QUEUE_OUT];
691 struct imgu_css_queue *css_queue_vf =
692 &css_pipe->queue[IPU3_CSS_QUEUE_VF];
693 const struct imgu_fw_info *bi =
694 &css->fwp->binary_header[css_pipe->bindex];
695 const unsigned int stripes = bi->info.isp.sp.iterator.num_stripes;
697 struct imgu_fw_config_memory_offsets *cofs = (void *)css->fwp +
698 bi->blob.memory_offsets.offsets[IMGU_ABI_PARAM_CLASS_CONFIG];
699 struct imgu_fw_state_memory_offsets *sofs = (void *)css->fwp +
700 bi->blob.memory_offsets.offsets[IMGU_ABI_PARAM_CLASS_STATE];
702 struct imgu_abi_isp_stage *isp_stage;
703 struct imgu_abi_sp_stage *sp_stage;
704 struct imgu_abi_sp_group *sp_group;
705 struct imgu_abi_frames_sp *frames_sp;
706 struct imgu_abi_frame_sp *frame_sp;
707 struct imgu_abi_frame_sp_info *frame_sp_info;
709 const unsigned int bds_width_pad =
710 ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].width,
711 2 * IPU3_UAPI_ISP_VEC_ELEMS);
713 const enum imgu_abi_memories m0 = IMGU_ABI_MEM_ISP_DMEM0;
714 enum imgu_abi_param_class cfg = IMGU_ABI_PARAM_CLASS_CONFIG;
715 void *vaddr = css_pipe->binary_params_cs[cfg - 1][m0].vaddr;
717 struct imgu_device *imgu = dev_get_drvdata(css->dev);
719 dev_dbg(css->dev, "%s for pipe %d", __func__, pipe);
721 /* Configure iterator */
723 cfg_iter = imgu_css_fw_pipeline_params(css, pipe, cfg, m0,
724 &cofs->dmem.iterator,
725 sizeof(*cfg_iter), vaddr);
729 frame_sp_info = &cfg_iter->input_info;
730 frame_sp_info->res.width = css_queue_in->fmt.mpix.width;
731 frame_sp_info->res.height = css_queue_in->fmt.mpix.height;
732 frame_sp_info->padded_width = css_queue_in->width_pad;
733 frame_sp_info->format = css_queue_in->css_fmt->frame_format;
734 frame_sp_info->raw_bit_depth = css_queue_in->css_fmt->bit_depth;
735 frame_sp_info->raw_bayer_order = css_queue_in->css_fmt->bayer_order;
736 frame_sp_info->raw_type = IMGU_ABI_RAW_TYPE_BAYER;
738 frame_sp_info = &cfg_iter->internal_info;
739 frame_sp_info->res.width = css_pipe->rect[IPU3_CSS_RECT_BDS].width;
740 frame_sp_info->res.height = css_pipe->rect[IPU3_CSS_RECT_BDS].height;
741 frame_sp_info->padded_width = bds_width_pad;
742 frame_sp_info->format = css_queue_out->css_fmt->frame_format;
743 frame_sp_info->raw_bit_depth = css_queue_out->css_fmt->bit_depth;
744 frame_sp_info->raw_bayer_order = css_queue_out->css_fmt->bayer_order;
745 frame_sp_info->raw_type = IMGU_ABI_RAW_TYPE_BAYER;
747 frame_sp_info = &cfg_iter->output_info;
748 frame_sp_info->res.width = css_queue_out->fmt.mpix.width;
749 frame_sp_info->res.height = css_queue_out->fmt.mpix.height;
750 frame_sp_info->padded_width = css_queue_out->width_pad;
751 frame_sp_info->format = css_queue_out->css_fmt->frame_format;
752 frame_sp_info->raw_bit_depth = css_queue_out->css_fmt->bit_depth;
753 frame_sp_info->raw_bayer_order = css_queue_out->css_fmt->bayer_order;
754 frame_sp_info->raw_type = IMGU_ABI_RAW_TYPE_BAYER;
756 frame_sp_info = &cfg_iter->vf_info;
757 frame_sp_info->res.width = css_queue_vf->fmt.mpix.width;
758 frame_sp_info->res.height = css_queue_vf->fmt.mpix.height;
759 frame_sp_info->padded_width = css_queue_vf->width_pad;
760 frame_sp_info->format = css_queue_vf->css_fmt->frame_format;
761 frame_sp_info->raw_bit_depth = css_queue_vf->css_fmt->bit_depth;
762 frame_sp_info->raw_bayer_order = css_queue_vf->css_fmt->bayer_order;
763 frame_sp_info->raw_type = IMGU_ABI_RAW_TYPE_BAYER;
765 cfg_iter->dvs_envelope.width =
766 css_pipe->rect[IPU3_CSS_RECT_ENVELOPE].width;
767 cfg_iter->dvs_envelope.height =
768 css_pipe->rect[IPU3_CSS_RECT_ENVELOPE].height;
770 /* Configure reference (delay) frames */
772 cfg_ref = imgu_css_fw_pipeline_params(css, pipe, cfg, m0,
774 sizeof(*cfg_ref), vaddr);
778 cfg_ref->port_b.crop = 0;
779 cfg_ref->port_b.elems = IMGU_ABI_ISP_DDR_WORD_BYTES / BYPC;
780 cfg_ref->port_b.width =
781 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].width;
782 cfg_ref->port_b.stride =
783 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperline;
784 cfg_ref->width_a_over_b =
785 IPU3_UAPI_ISP_VEC_ELEMS / cfg_ref->port_b.elems;
786 cfg_ref->dvs_frame_delay = IPU3_CSS_AUX_FRAMES - 1;
787 for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++) {
788 cfg_ref->ref_frame_addr_y[i] =
789 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i].daddr;
790 cfg_ref->ref_frame_addr_c[i] =
791 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i].daddr +
792 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperline *
793 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height;
795 for (; i < IMGU_ABI_FRAMES_REF; i++) {
796 cfg_ref->ref_frame_addr_y[i] = 0;
797 cfg_ref->ref_frame_addr_c[i] = 0;
800 /* Configure DVS (digital video stabilization) */
802 cfg_dvs = imgu_css_fw_pipeline_params(css, pipe, cfg, m0,
803 &cofs->dmem.dvs, sizeof(*cfg_dvs),
808 cfg_dvs->num_horizontal_blocks =
809 ALIGN(DIV_ROUND_UP(css_pipe->rect[IPU3_CSS_RECT_GDC].width,
810 IMGU_DVS_BLOCK_W), 2);
811 cfg_dvs->num_vertical_blocks =
812 DIV_ROUND_UP(css_pipe->rect[IPU3_CSS_RECT_GDC].height,
815 /* Configure TNR (temporal noise reduction) */
817 if (css_pipe->pipe_id == IPU3_CSS_PIPE_ID_VIDEO) {
818 cfg_tnr = imgu_css_fw_pipeline_params(css, pipe, cfg, m0,
825 cfg_tnr->port_b.crop = 0;
826 cfg_tnr->port_b.elems = IMGU_ABI_ISP_DDR_WORD_BYTES;
827 cfg_tnr->port_b.width =
828 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].width;
829 cfg_tnr->port_b.stride =
830 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].bytesperline;
831 cfg_tnr->width_a_over_b =
832 IPU3_UAPI_ISP_VEC_ELEMS / cfg_tnr->port_b.elems;
833 cfg_tnr->frame_height =
834 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height;
835 cfg_tnr->delay_frame = IPU3_CSS_AUX_FRAMES - 1;
836 for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++)
837 cfg_tnr->frame_addr[i] =
838 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR]
840 for (; i < IMGU_ABI_FRAMES_TNR; i++)
841 cfg_tnr->frame_addr[i] = 0;
844 /* Configure ref dmem state parameters */
846 cfg = IMGU_ABI_PARAM_CLASS_STATE;
847 vaddr = css_pipe->binary_params_cs[cfg - 1][m0].vaddr;
849 cfg_ref_state = imgu_css_fw_pipeline_params(css, pipe, cfg, m0,
851 sizeof(*cfg_ref_state),
856 cfg_ref_state->ref_in_buf_idx = 0;
857 cfg_ref_state->ref_out_buf_idx = 1;
859 /* Configure tnr dmem state parameters */
860 if (css_pipe->pipe_id == IPU3_CSS_PIPE_ID_VIDEO) {
862 imgu_css_fw_pipeline_params(css, pipe, cfg, m0,
864 sizeof(*cfg_tnr_state),
869 cfg_tnr_state->in_bufidx = 0;
870 cfg_tnr_state->out_bufidx = 1;
871 cfg_tnr_state->bypass_filter = 0;
872 cfg_tnr_state->total_frame_counter = 0;
873 for (i = 0; i < IMGU_ABI_BUF_SETS_TNR; i++)
874 cfg_tnr_state->buffer_frame_counter[i] = 0;
877 /* Configure ISP stage */
879 isp_stage = css_pipe->xmem_isp_stage_ptrs[pipe][stage].vaddr;
880 memset(isp_stage, 0, sizeof(*isp_stage));
881 isp_stage->blob_info = bi->blob;
882 isp_stage->binary_info = bi->info.isp.sp;
883 strscpy(isp_stage->binary_name,
884 (char *)css->fwp + bi->blob.prog_name_offset,
885 sizeof(isp_stage->binary_name));
886 isp_stage->mem_initializers = bi->info.isp.sp.mem_initializers;
887 for (i = IMGU_ABI_PARAM_CLASS_CONFIG; i < IMGU_ABI_PARAM_CLASS_NUM; i++)
888 for (j = 0; j < IMGU_ABI_NUM_MEMORIES; j++)
889 isp_stage->mem_initializers.params[i][j].address =
890 css_pipe->binary_params_cs[i - 1][j].daddr;
892 /* Configure SP stage */
894 sp_stage = css_pipe->xmem_sp_stage_ptrs[pipe][stage].vaddr;
895 memset(sp_stage, 0, sizeof(*sp_stage));
897 frames_sp = &sp_stage->frames;
898 frames_sp->in.buf_attr = buffer_sp_init;
899 for (i = 0; i < IMGU_ABI_BINARY_MAX_OUTPUT_PORTS; i++)
900 frames_sp->out[i].buf_attr = buffer_sp_init;
901 frames_sp->out_vf.buf_attr = buffer_sp_init;
902 frames_sp->s3a_buf = buffer_sp_init;
903 frames_sp->dvs_buf = buffer_sp_init;
905 sp_stage->stage_type = IMGU_ABI_STAGE_TYPE_ISP;
906 sp_stage->num = stage;
907 sp_stage->isp_online = 0;
908 sp_stage->isp_copy_vf = 0;
909 sp_stage->isp_copy_output = 0;
911 sp_stage->enable.vf_output = css_pipe->vf_output_en;
913 frames_sp->effective_in_res.width =
914 css_pipe->rect[IPU3_CSS_RECT_EFFECTIVE].width;
915 frames_sp->effective_in_res.height =
916 css_pipe->rect[IPU3_CSS_RECT_EFFECTIVE].height;
918 frame_sp = &frames_sp->in;
919 frame_sp->info.res.width = css_queue_in->fmt.mpix.width;
920 frame_sp->info.res.height = css_queue_in->fmt.mpix.height;
921 frame_sp->info.padded_width = css_queue_in->width_pad;
922 frame_sp->info.format = css_queue_in->css_fmt->frame_format;
923 frame_sp->info.raw_bit_depth = css_queue_in->css_fmt->bit_depth;
924 frame_sp->info.raw_bayer_order = css_queue_in->css_fmt->bayer_order;
925 frame_sp->info.raw_type = IMGU_ABI_RAW_TYPE_BAYER;
926 frame_sp->buf_attr.buf_src.queue_id = IMGU_ABI_QUEUE_C_ID;
927 frame_sp->buf_attr.buf_type = IMGU_ABI_BUFFER_TYPE_INPUT_FRAME;
929 frame_sp = &frames_sp->out[0];
930 frame_sp->info.res.width = css_queue_out->fmt.mpix.width;
931 frame_sp->info.res.height = css_queue_out->fmt.mpix.height;
932 frame_sp->info.padded_width = css_queue_out->width_pad;
933 frame_sp->info.format = css_queue_out->css_fmt->frame_format;
934 frame_sp->info.raw_bit_depth = css_queue_out->css_fmt->bit_depth;
935 frame_sp->info.raw_bayer_order = css_queue_out->css_fmt->bayer_order;
936 frame_sp->info.raw_type = IMGU_ABI_RAW_TYPE_BAYER;
937 frame_sp->planes.nv.uv.offset = css_queue_out->width_pad *
938 css_queue_out->fmt.mpix.height;
939 frame_sp->buf_attr.buf_src.queue_id = IMGU_ABI_QUEUE_D_ID;
940 frame_sp->buf_attr.buf_type = IMGU_ABI_BUFFER_TYPE_OUTPUT_FRAME;
942 frame_sp = &frames_sp->out[1];
943 frame_sp->buf_attr.buf_src.queue_id = IMGU_ABI_QUEUE_EVENT_ID;
945 frame_sp_info = &frames_sp->internal_frame_info;
946 frame_sp_info->res.width = css_pipe->rect[IPU3_CSS_RECT_BDS].width;
947 frame_sp_info->res.height = css_pipe->rect[IPU3_CSS_RECT_BDS].height;
948 frame_sp_info->padded_width = bds_width_pad;
949 frame_sp_info->format = css_queue_out->css_fmt->frame_format;
950 frame_sp_info->raw_bit_depth = css_queue_out->css_fmt->bit_depth;
951 frame_sp_info->raw_bayer_order = css_queue_out->css_fmt->bayer_order;
952 frame_sp_info->raw_type = IMGU_ABI_RAW_TYPE_BAYER;
954 frame_sp = &frames_sp->out_vf;
955 frame_sp->info.res.width = css_queue_vf->fmt.mpix.width;
956 frame_sp->info.res.height = css_queue_vf->fmt.mpix.height;
957 frame_sp->info.padded_width = css_queue_vf->width_pad;
958 frame_sp->info.format = css_queue_vf->css_fmt->frame_format;
959 frame_sp->info.raw_bit_depth = css_queue_vf->css_fmt->bit_depth;
960 frame_sp->info.raw_bayer_order = css_queue_vf->css_fmt->bayer_order;
961 frame_sp->info.raw_type = IMGU_ABI_RAW_TYPE_BAYER;
962 frame_sp->planes.yuv.u.offset = css_queue_vf->width_pad *
963 css_queue_vf->fmt.mpix.height;
964 frame_sp->planes.yuv.v.offset = css_queue_vf->width_pad *
965 css_queue_vf->fmt.mpix.height * 5 / 4;
966 frame_sp->buf_attr.buf_src.queue_id = IMGU_ABI_QUEUE_E_ID;
967 frame_sp->buf_attr.buf_type = IMGU_ABI_BUFFER_TYPE_VF_OUTPUT_FRAME;
969 frames_sp->s3a_buf.buf_src.queue_id = IMGU_ABI_QUEUE_F_ID;
970 frames_sp->s3a_buf.buf_type = IMGU_ABI_BUFFER_TYPE_3A_STATISTICS;
972 frames_sp->dvs_buf.buf_src.queue_id = IMGU_ABI_QUEUE_G_ID;
973 frames_sp->dvs_buf.buf_type = IMGU_ABI_BUFFER_TYPE_DIS_STATISTICS;
975 sp_stage->dvs_envelope.width =
976 css_pipe->rect[IPU3_CSS_RECT_ENVELOPE].width;
977 sp_stage->dvs_envelope.height =
978 css_pipe->rect[IPU3_CSS_RECT_ENVELOPE].height;
980 sp_stage->isp_pipe_version =
981 bi->info.isp.sp.pipeline.isp_pipe_version;
982 sp_stage->isp_deci_log_factor =
983 clamp(max(fls(css_pipe->rect[IPU3_CSS_RECT_BDS].width /
984 IMGU_MAX_BQ_GRID_WIDTH),
985 fls(css_pipe->rect[IPU3_CSS_RECT_BDS].height /
986 IMGU_MAX_BQ_GRID_HEIGHT)) - 1, 3, 5);
987 sp_stage->isp_vf_downscale_bits = 0;
988 sp_stage->if_config_index = 255;
989 sp_stage->sp_enable_xnr = 0;
990 sp_stage->num_stripes = stripes;
991 sp_stage->enable.s3a = 1;
992 sp_stage->enable.dvs_stats = 0;
994 sp_stage->xmem_bin_addr = css->binary[css_pipe->bindex].daddr;
995 sp_stage->xmem_map_addr = css_pipe->sp_ddr_ptrs.daddr;
996 sp_stage->isp_stage_addr =
997 css_pipe->xmem_isp_stage_ptrs[pipe][stage].daddr;
999 /* Configure SP group */
1001 sp_group = css->xmem_sp_group_ptrs.vaddr;
1002 memset(&sp_group->pipe[pipe], 0, sizeof(struct imgu_abi_sp_pipeline));
1004 sp_group->pipe[pipe].num_stages = 1;
1005 sp_group->pipe[pipe].pipe_id = css_pipe->pipe_id;
1006 sp_group->pipe[pipe].thread_id = pipe;
1007 sp_group->pipe[pipe].pipe_num = pipe;
1008 sp_group->pipe[pipe].num_execs = -1;
1009 sp_group->pipe[pipe].pipe_qos_config = -1;
1010 sp_group->pipe[pipe].required_bds_factor = 0;
1011 sp_group->pipe[pipe].dvs_frame_delay = IPU3_CSS_AUX_FRAMES - 1;
1012 sp_group->pipe[pipe].inout_port_config =
1013 IMGU_ABI_PORT_CONFIG_TYPE_INPUT_HOST |
1014 IMGU_ABI_PORT_CONFIG_TYPE_OUTPUT_HOST;
1015 sp_group->pipe[pipe].scaler_pp_lut = 0;
1016 sp_group->pipe[pipe].shading.internal_frame_origin_x_bqs_on_sctbl = 0;
1017 sp_group->pipe[pipe].shading.internal_frame_origin_y_bqs_on_sctbl = 0;
1018 sp_group->pipe[pipe].sp_stage_addr[stage] =
1019 css_pipe->xmem_sp_stage_ptrs[pipe][stage].daddr;
1020 sp_group->pipe[pipe].pipe_config =
1021 bi->info.isp.sp.enable.params ? (1 << pipe) : 0;
1022 sp_group->pipe[pipe].pipe_config |= IMGU_ABI_PIPE_CONFIG_ACQUIRE_ISP;
1024 /* Initialize parameter pools */
1026 if (imgu_css_pool_init(imgu, &css_pipe->pool.parameter_set_info,
1027 sizeof(struct imgu_abi_parameter_set_info)) ||
1028 imgu_css_pool_init(imgu, &css_pipe->pool.acc,
1029 sizeof(struct imgu_abi_acc_param)) ||
1030 imgu_css_pool_init(imgu, &css_pipe->pool.gdc,
1031 sizeof(struct imgu_abi_gdc_warp_param) *
1032 3 * cfg_dvs->num_horizontal_blocks / 2 *
1033 cfg_dvs->num_vertical_blocks) ||
1034 imgu_css_pool_init(imgu, &css_pipe->pool.obgrid,
1035 imgu_css_fw_obgrid_size(
1036 &css->fwp->binary_header[css_pipe->bindex])))
1039 for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++)
1040 if (imgu_css_pool_init(imgu,
1041 &css_pipe->pool.binary_params_p[i],
1042 bi->info.isp.sp.mem_initializers.params
1043 [IMGU_ABI_PARAM_CLASS_PARAM][i].size))
1049 imgu_css_pipeline_cleanup(css, pipe);
1053 imgu_css_pipeline_cleanup(css, pipe);
1057 static u8 imgu_css_queue_pos(struct imgu_css *css, int queue, int thread)
1059 static const unsigned int sp;
1060 void __iomem *const base = css->base;
1061 struct imgu_fw_info *bi = &css->fwp->binary_header[css->fw_sp[sp]];
1062 struct imgu_abi_queues __iomem *q = base + IMGU_REG_SP_DMEM_BASE(sp) +
1063 bi->info.sp.host_sp_queue;
1065 return queue >= 0 ? readb(&q->host2sp_bufq_info[thread][queue].end) :
1066 readb(&q->host2sp_evtq_info.end);
1069 /* Sent data to sp using given buffer queue, or if queue < 0, event queue. */
1070 static int imgu_css_queue_data(struct imgu_css *css,
1071 int queue, int thread, u32 data)
1073 static const unsigned int sp;
1074 void __iomem *const base = css->base;
1075 struct imgu_fw_info *bi = &css->fwp->binary_header[css->fw_sp[sp]];
1076 struct imgu_abi_queues __iomem *q = base + IMGU_REG_SP_DMEM_BASE(sp) +
1077 bi->info.sp.host_sp_queue;
1078 u8 size, start, end, end2;
1081 size = readb(&q->host2sp_bufq_info[thread][queue].size);
1082 start = readb(&q->host2sp_bufq_info[thread][queue].start);
1083 end = readb(&q->host2sp_bufq_info[thread][queue].end);
1085 size = readb(&q->host2sp_evtq_info.size);
1086 start = readb(&q->host2sp_evtq_info.start);
1087 end = readb(&q->host2sp_evtq_info.end);
1093 end2 = (end + 1) % size;
1095 return -EBUSY; /* Queue full */
1098 writel(data, &q->host2sp_bufq[thread][queue][end]);
1099 writeb(end2, &q->host2sp_bufq_info[thread][queue].end);
1101 writel(data, &q->host2sp_evtq[end]);
1102 writeb(end2, &q->host2sp_evtq_info.end);
1108 /* Receive data using given buffer queue, or if queue < 0, event queue. */
1109 static int imgu_css_dequeue_data(struct imgu_css *css, int queue, u32 *data)
1111 static const unsigned int sp;
1112 void __iomem *const base = css->base;
1113 struct imgu_fw_info *bi = &css->fwp->binary_header[css->fw_sp[sp]];
1114 struct imgu_abi_queues __iomem *q = base + IMGU_REG_SP_DMEM_BASE(sp) +
1115 bi->info.sp.host_sp_queue;
1116 u8 size, start, end, start2;
1119 size = readb(&q->sp2host_bufq_info[queue].size);
1120 start = readb(&q->sp2host_bufq_info[queue].start);
1121 end = readb(&q->sp2host_bufq_info[queue].end);
1123 size = readb(&q->sp2host_evtq_info.size);
1124 start = readb(&q->sp2host_evtq_info.start);
1125 end = readb(&q->sp2host_evtq_info.end);
1132 return -EBUSY; /* Queue empty */
1134 start2 = (start + 1) % size;
1137 *data = readl(&q->sp2host_bufq[queue][start]);
1138 writeb(start2, &q->sp2host_bufq_info[queue].start);
1142 *data = readl(&q->sp2host_evtq[start]);
1143 writeb(start2, &q->sp2host_evtq_info.start);
1145 /* Acknowledge events dequeued from event queue */
1146 r = imgu_css_queue_data(css, queue, 0,
1147 IMGU_ABI_EVENT_EVENT_DEQUEUED);
1155 /* Free binary-specific resources */
1156 static void imgu_css_binary_cleanup(struct imgu_css *css, unsigned int pipe)
1158 struct imgu_device *imgu = dev_get_drvdata(css->dev);
1161 struct imgu_css_pipe *css_pipe = &css->pipes[pipe];
1163 for (j = 0; j < IMGU_ABI_PARAM_CLASS_NUM - 1; j++)
1164 for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++)
1165 imgu_dmamap_free(imgu,
1166 &css_pipe->binary_params_cs[j][i]);
1168 j = IPU3_CSS_AUX_FRAME_REF;
1169 for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++)
1170 imgu_dmamap_free(imgu,
1171 &css_pipe->aux_frames[j].mem[i]);
1173 j = IPU3_CSS_AUX_FRAME_TNR;
1174 for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++)
1175 imgu_dmamap_free(imgu,
1176 &css_pipe->aux_frames[j].mem[i]);
1179 static int imgu_css_binary_preallocate(struct imgu_css *css, unsigned int pipe)
1181 struct imgu_device *imgu = dev_get_drvdata(css->dev);
1184 struct imgu_css_pipe *css_pipe = &css->pipes[pipe];
1186 for (j = IMGU_ABI_PARAM_CLASS_CONFIG;
1187 j < IMGU_ABI_PARAM_CLASS_NUM; j++)
1188 for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++)
1189 if (!imgu_dmamap_alloc(imgu,
1190 &css_pipe->binary_params_cs[j - 1][i],
1194 for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++)
1195 if (!imgu_dmamap_alloc(imgu,
1196 &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].
1197 mem[i], CSS_BDS_SIZE))
1200 for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++)
1201 if (!imgu_dmamap_alloc(imgu,
1202 &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].
1203 mem[i], CSS_GDC_SIZE))
1209 imgu_css_binary_cleanup(css, pipe);
1213 /* allocate binary-specific resources */
1214 static int imgu_css_binary_setup(struct imgu_css *css, unsigned int pipe)
1216 struct imgu_css_pipe *css_pipe = &css->pipes[pipe];
1217 struct imgu_fw_info *bi = &css->fwp->binary_header[css_pipe->bindex];
1218 struct imgu_device *imgu = dev_get_drvdata(css->dev);
1220 static const int BYPC = 2; /* Bytes per component */
1223 /* Allocate parameter memory blocks for this binary */
1225 for (j = IMGU_ABI_PARAM_CLASS_CONFIG; j < IMGU_ABI_PARAM_CLASS_NUM; j++)
1226 for (i = 0; i < IMGU_ABI_NUM_MEMORIES; i++) {
1227 if (imgu_css_dma_buffer_resize(
1229 &css_pipe->binary_params_cs[j - 1][i],
1230 bi->info.isp.sp.mem_initializers.params[j][i].size))
1234 /* Allocate internal frame buffers */
1236 /* Reference frames for DVS, FRAME_FORMAT_YUV420_16 */
1237 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperpixel = BYPC;
1238 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].width =
1239 css_pipe->rect[IPU3_CSS_RECT_BDS].width;
1240 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height =
1241 ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].height,
1242 IMGU_DVS_BLOCK_H) + 2 * IMGU_GDC_BUF_Y;
1243 h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].height;
1244 w = ALIGN(css_pipe->rect[IPU3_CSS_RECT_BDS].width,
1245 2 * IPU3_UAPI_ISP_VEC_ELEMS) + 2 * IMGU_GDC_BUF_X;
1246 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperline =
1247 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].bytesperpixel * w;
1248 size = w * h * BYPC + (w / 2) * (h / 2) * BYPC * 2;
1249 for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++)
1250 if (imgu_css_dma_buffer_resize(
1252 &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_REF].mem[i],
1256 /* TNR frames for temporal noise reduction, FRAME_FORMAT_YUV_LINE */
1257 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].bytesperpixel = 1;
1258 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].width =
1259 roundup(css_pipe->rect[IPU3_CSS_RECT_GDC].width,
1260 bi->info.isp.sp.block.block_width *
1261 IPU3_UAPI_ISP_VEC_ELEMS);
1262 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height =
1263 roundup(css_pipe->rect[IPU3_CSS_RECT_GDC].height,
1264 bi->info.isp.sp.block.output_block_height);
1266 w = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].width;
1267 css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].bytesperline = w;
1268 h = css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].height;
1269 size = w * ALIGN(h * 3 / 2 + 3, 2); /* +3 for vf_pp prefetch */
1270 for (i = 0; i < IPU3_CSS_AUX_FRAMES; i++)
1271 if (imgu_css_dma_buffer_resize(
1273 &css_pipe->aux_frames[IPU3_CSS_AUX_FRAME_TNR].mem[i],
1280 imgu_css_binary_cleanup(css, pipe);
1284 int imgu_css_start_streaming(struct imgu_css *css)
1292 for_each_set_bit(pipe, css->enabled_pipes, IMGU_MAX_PIPE_NUM) {
1293 r = imgu_css_binary_setup(css, pipe);
1298 r = imgu_css_hw_init(css);
1302 r = imgu_css_hw_start(css);
1306 for_each_set_bit(pipe, css->enabled_pipes, IMGU_MAX_PIPE_NUM) {
1307 r = imgu_css_pipeline_init(css, pipe);
1312 css->streaming = true;
1314 imgu_css_hw_enable_irq(css);
1316 /* Initialize parameters to default */
1317 for_each_set_bit(pipe, css->enabled_pipes, IMGU_MAX_PIPE_NUM) {
1318 r = imgu_css_set_parameters(css, pipe, NULL);
1323 while (!(r = imgu_css_dequeue_data(css, IMGU_ABI_QUEUE_A_ID, &data)))
1328 while (!(r = imgu_css_dequeue_data(css, IMGU_ABI_QUEUE_B_ID, &data)))
1333 for_each_set_bit(pipe, css->enabled_pipes, IMGU_MAX_PIPE_NUM) {
1334 r = imgu_css_queue_data(css, IMGU_ABI_QUEUE_EVENT_ID, pipe,
1335 IMGU_ABI_EVENT_START_STREAM |
1344 css->streaming = false;
1345 imgu_css_hw_cleanup(css);
1346 for_each_set_bit(pipe, css->enabled_pipes, IMGU_MAX_PIPE_NUM) {
1347 imgu_css_pipeline_cleanup(css, pipe);
1348 imgu_css_binary_cleanup(css, pipe);
1354 void imgu_css_stop_streaming(struct imgu_css *css)
1356 struct imgu_css_buffer *b, *b0;
1359 for_each_set_bit(pipe, css->enabled_pipes, IMGU_MAX_PIPE_NUM) {
1360 r = imgu_css_queue_data(css, IMGU_ABI_QUEUE_EVENT_ID, pipe,
1361 IMGU_ABI_EVENT_STOP_STREAM);
1363 dev_warn(css->dev, "failed on stop stream event\n");
1366 if (!css->streaming)
1369 imgu_css_hw_stop(css);
1371 imgu_css_hw_cleanup(css);
1373 for_each_set_bit(pipe, css->enabled_pipes, IMGU_MAX_PIPE_NUM) {
1374 struct imgu_css_pipe *css_pipe = &css->pipes[pipe];
1376 imgu_css_pipeline_cleanup(css, pipe);
1378 spin_lock(&css_pipe->qlock);
1379 for (q = 0; q < IPU3_CSS_QUEUES; q++)
1380 list_for_each_entry_safe(b, b0,
1381 &css_pipe->queue[q].bufs,
1383 b->state = IPU3_CSS_BUFFER_FAILED;
1386 spin_unlock(&css_pipe->qlock);
1389 css->streaming = false;
1392 bool imgu_css_pipe_queue_empty(struct imgu_css *css, unsigned int pipe)
1395 struct imgu_css_pipe *css_pipe = &css->pipes[pipe];
1397 spin_lock(&css_pipe->qlock);
1398 for (q = 0; q < IPU3_CSS_QUEUES; q++)
1399 if (!list_empty(&css_pipe->queue[q].bufs))
1401 spin_unlock(&css_pipe->qlock);
1402 return (q == IPU3_CSS_QUEUES);
1405 bool imgu_css_queue_empty(struct imgu_css *css)
1410 for (pipe = 0; pipe < IMGU_MAX_PIPE_NUM; pipe++)
1411 ret &= imgu_css_pipe_queue_empty(css, pipe);
1416 bool imgu_css_is_streaming(struct imgu_css *css)
1418 return css->streaming;
1421 static int imgu_css_map_init(struct imgu_css *css, unsigned int pipe)
1423 struct imgu_device *imgu = dev_get_drvdata(css->dev);
1424 struct imgu_css_pipe *css_pipe = &css->pipes[pipe];
1425 unsigned int p, q, i;
1427 /* Allocate and map common structures with imgu hardware */
1428 for (p = 0; p < IPU3_CSS_PIPE_ID_NUM; p++)
1429 for (i = 0; i < IMGU_ABI_MAX_STAGES; i++) {
1430 if (!imgu_dmamap_alloc(imgu,
1432 xmem_sp_stage_ptrs[p][i],
1433 sizeof(struct imgu_abi_sp_stage)))
1435 if (!imgu_dmamap_alloc(imgu,
1437 xmem_isp_stage_ptrs[p][i],
1438 sizeof(struct imgu_abi_isp_stage)))
1442 if (!imgu_dmamap_alloc(imgu, &css_pipe->sp_ddr_ptrs,
1443 ALIGN(sizeof(struct imgu_abi_ddr_address_map),
1444 IMGU_ABI_ISP_DDR_WORD_BYTES)))
1447 for (q = 0; q < IPU3_CSS_QUEUES; q++) {
1448 unsigned int abi_buf_num = ARRAY_SIZE(css_pipe->abi_buffers[q]);
1450 for (i = 0; i < abi_buf_num; i++)
1451 if (!imgu_dmamap_alloc(imgu,
1452 &css_pipe->abi_buffers[q][i],
1453 sizeof(struct imgu_abi_buffer)))
1457 if (imgu_css_binary_preallocate(css, pipe)) {
1458 imgu_css_binary_cleanup(css, pipe);
1465 static void imgu_css_pipe_cleanup(struct imgu_css *css, unsigned int pipe)
1467 struct imgu_device *imgu = dev_get_drvdata(css->dev);
1468 struct imgu_css_pipe *css_pipe = &css->pipes[pipe];
1469 unsigned int p, q, i, abi_buf_num;
1471 imgu_css_binary_cleanup(css, pipe);
1473 for (q = 0; q < IPU3_CSS_QUEUES; q++) {
1474 abi_buf_num = ARRAY_SIZE(css_pipe->abi_buffers[q]);
1475 for (i = 0; i < abi_buf_num; i++)
1476 imgu_dmamap_free(imgu, &css_pipe->abi_buffers[q][i]);
1479 for (p = 0; p < IPU3_CSS_PIPE_ID_NUM; p++)
1480 for (i = 0; i < IMGU_ABI_MAX_STAGES; i++) {
1481 imgu_dmamap_free(imgu,
1482 &css_pipe->xmem_sp_stage_ptrs[p][i]);
1483 imgu_dmamap_free(imgu,
1484 &css_pipe->xmem_isp_stage_ptrs[p][i]);
1487 imgu_dmamap_free(imgu, &css_pipe->sp_ddr_ptrs);
1490 void imgu_css_cleanup(struct imgu_css *css)
1492 struct imgu_device *imgu = dev_get_drvdata(css->dev);
1495 imgu_css_stop_streaming(css);
1496 for (pipe = 0; pipe < IMGU_MAX_PIPE_NUM; pipe++)
1497 imgu_css_pipe_cleanup(css, pipe);
1498 imgu_dmamap_free(imgu, &css->xmem_sp_group_ptrs);
1499 imgu_css_fw_cleanup(css);
1502 int imgu_css_init(struct device *dev, struct imgu_css *css,
1503 void __iomem *base, int length)
1505 struct imgu_device *imgu = dev_get_drvdata(dev);
1508 /* Initialize main data structure */
1511 css->iomem_length = length;
1513 for (pipe = 0; pipe < IMGU_MAX_PIPE_NUM; pipe++) {
1514 struct imgu_css_pipe *css_pipe = &css->pipes[pipe];
1516 css_pipe->vf_output_en = false;
1517 spin_lock_init(&css_pipe->qlock);
1518 css_pipe->bindex = IPU3_CSS_DEFAULT_BINARY;
1519 css_pipe->pipe_id = IPU3_CSS_PIPE_ID_VIDEO;
1520 for (q = 0; q < IPU3_CSS_QUEUES; q++) {
1521 r = imgu_css_queue_init(&css_pipe->queue[q], NULL, 0);
1525 r = imgu_css_map_init(css, pipe);
1527 imgu_css_cleanup(css);
1531 if (!imgu_dmamap_alloc(imgu, &css->xmem_sp_group_ptrs,
1532 sizeof(struct imgu_abi_sp_group)))
1535 r = imgu_css_fw_init(css);
1542 static u32 imgu_css_adjust(u32 res, u32 align)
1544 u32 val = max_t(u32, IPU3_CSS_MIN_RES, res);
1546 return DIV_ROUND_CLOSEST(val, align) * align;
1549 /* Select a binary matching the required resolutions and formats */
1550 static int imgu_css_find_binary(struct imgu_css *css,
1552 struct imgu_css_queue queue[IPU3_CSS_QUEUES],
1553 struct v4l2_rect rects[IPU3_CSS_RECTS])
1555 const int binary_nr = css->fwp->file_header.binary_nr;
1556 unsigned int binary_mode =
1557 (css->pipes[pipe].pipe_id == IPU3_CSS_PIPE_ID_CAPTURE) ?
1558 IA_CSS_BINARY_MODE_PRIMARY : IA_CSS_BINARY_MODE_VIDEO;
1559 const struct v4l2_pix_format_mplane *in =
1560 &queue[IPU3_CSS_QUEUE_IN].fmt.mpix;
1561 const struct v4l2_pix_format_mplane *out =
1562 &queue[IPU3_CSS_QUEUE_OUT].fmt.mpix;
1563 const struct v4l2_pix_format_mplane *vf =
1564 &queue[IPU3_CSS_QUEUE_VF].fmt.mpix;
1565 u32 stripe_w = 0, stripe_h = 0;
1569 if (!imgu_css_queue_enabled(&queue[IPU3_CSS_QUEUE_IN]))
1572 /* Find out the strip size boundary */
1573 for (i = 0; i < binary_nr; i++) {
1574 struct imgu_fw_info *bi = &css->fwp->binary_header[i];
1576 u32 max_width = bi->info.isp.sp.output.max_width;
1577 u32 max_height = bi->info.isp.sp.output.max_height;
1579 if (bi->info.isp.sp.iterator.num_stripes <= 1) {
1580 stripe_w = stripe_w ?
1581 min(stripe_w, max_width) : max_width;
1582 stripe_h = stripe_h ?
1583 min(stripe_h, max_height) : max_height;
1587 for (i = 0; i < binary_nr; i++) {
1588 struct imgu_fw_info *bi = &css->fwp->binary_header[i];
1589 enum imgu_abi_frame_format q_fmt;
1591 name = (void *)css->fwp + bi->blob.prog_name_offset;
1593 /* Check that binary supports memory-to-memory processing */
1594 if (bi->info.isp.sp.input.source !=
1595 IMGU_ABI_BINARY_INPUT_SOURCE_MEMORY)
1598 /* Check that binary supports raw10 input */
1599 if (!bi->info.isp.sp.enable.input_feeder &&
1600 !bi->info.isp.sp.enable.input_raw)
1603 /* Check binary mode */
1604 if (bi->info.isp.sp.pipeline.mode != binary_mode)
1607 /* Since input is RGGB bayer, need to process colors */
1608 if (bi->info.isp.sp.enable.luma_only)
1611 if (in->width < bi->info.isp.sp.input.min_width ||
1612 in->width > bi->info.isp.sp.input.max_width ||
1613 in->height < bi->info.isp.sp.input.min_height ||
1614 in->height > bi->info.isp.sp.input.max_height)
1617 if (imgu_css_queue_enabled(&queue[IPU3_CSS_QUEUE_OUT])) {
1618 if (bi->info.isp.num_output_pins <= 0)
1621 q_fmt = queue[IPU3_CSS_QUEUE_OUT].css_fmt->frame_format;
1622 for (j = 0; j < bi->info.isp.num_output_formats; j++)
1623 if (bi->info.isp.output_formats[j] == q_fmt)
1625 if (j >= bi->info.isp.num_output_formats)
1628 if (out->width < bi->info.isp.sp.output.min_width ||
1629 out->width > bi->info.isp.sp.output.max_width ||
1630 out->height < bi->info.isp.sp.output.min_height ||
1631 out->height > bi->info.isp.sp.output.max_height)
1634 if (out->width > bi->info.isp.sp.internal.max_width ||
1635 out->height > bi->info.isp.sp.internal.max_height)
1639 if (imgu_css_queue_enabled(&queue[IPU3_CSS_QUEUE_VF])) {
1640 if (bi->info.isp.num_output_pins <= 1)
1643 q_fmt = queue[IPU3_CSS_QUEUE_VF].css_fmt->frame_format;
1644 for (j = 0; j < bi->info.isp.num_output_formats; j++)
1645 if (bi->info.isp.output_formats[j] == q_fmt)
1647 if (j >= bi->info.isp.num_output_formats)
1650 if (vf->width < bi->info.isp.sp.output.min_width ||
1651 vf->width > bi->info.isp.sp.output.max_width ||
1652 vf->height < bi->info.isp.sp.output.min_height ||
1653 vf->height > bi->info.isp.sp.output.max_height)
1657 /* All checks passed, select the binary */
1658 dev_dbg(css->dev, "using binary %s id = %u\n", name,
1659 bi->info.isp.sp.id);
1663 /* Can not find suitable binary for these parameters */
1668 * Check that there is a binary matching requirements. Parameters may be
1669 * NULL indicating disabled input/output. Return negative if given
1670 * parameters can not be supported or on error, zero or positive indicating
1671 * found binary number. May modify the given parameters if not exact match
1674 int imgu_css_fmt_try(struct imgu_css *css,
1675 struct v4l2_pix_format_mplane *fmts[IPU3_CSS_QUEUES],
1676 struct v4l2_rect *rects[IPU3_CSS_RECTS],
1679 static const u32 EFF_ALIGN_W = 2;
1680 static const u32 BDS_ALIGN_W = 4;
1681 static const u32 OUT_ALIGN_W = 8;
1682 static const u32 OUT_ALIGN_H = 4;
1683 static const u32 VF_ALIGN_W = 2;
1684 static const char *qnames[IPU3_CSS_QUEUES] = {
1685 [IPU3_CSS_QUEUE_IN] = "in",
1686 [IPU3_CSS_QUEUE_PARAMS] = "params",
1687 [IPU3_CSS_QUEUE_OUT] = "out",
1688 [IPU3_CSS_QUEUE_VF] = "vf",
1689 [IPU3_CSS_QUEUE_STAT_3A] = "3a",
1691 static const char *rnames[IPU3_CSS_RECTS] = {
1692 [IPU3_CSS_RECT_EFFECTIVE] = "effective resolution",
1693 [IPU3_CSS_RECT_BDS] = "bayer-domain scaled resolution",
1694 [IPU3_CSS_RECT_ENVELOPE] = "DVS envelope size",
1695 [IPU3_CSS_RECT_GDC] = "GDC output res",
1697 struct v4l2_rect r[IPU3_CSS_RECTS] = { };
1698 struct v4l2_rect *const eff = &r[IPU3_CSS_RECT_EFFECTIVE];
1699 struct v4l2_rect *const bds = &r[IPU3_CSS_RECT_BDS];
1700 struct v4l2_rect *const env = &r[IPU3_CSS_RECT_ENVELOPE];
1701 struct v4l2_rect *const gdc = &r[IPU3_CSS_RECT_GDC];
1702 struct imgu_css_queue *q;
1703 struct v4l2_pix_format_mplane *in, *out, *vf;
1706 q = kcalloc(IPU3_CSS_QUEUES, sizeof(struct imgu_css_queue), GFP_KERNEL);
1710 in = &q[IPU3_CSS_QUEUE_IN].fmt.mpix;
1711 out = &q[IPU3_CSS_QUEUE_OUT].fmt.mpix;
1712 vf = &q[IPU3_CSS_QUEUE_VF].fmt.mpix;
1714 /* Adjust all formats, get statistics buffer sizes and formats */
1715 for (i = 0; i < IPU3_CSS_QUEUES; i++) {
1717 dev_dbg(css->dev, "%s %s: (%i,%i) fmt 0x%x\n", __func__,
1718 qnames[i], fmts[i]->width, fmts[i]->height,
1719 fmts[i]->pixelformat);
1721 dev_dbg(css->dev, "%s %s: (not set)\n", __func__,
1723 if (imgu_css_queue_init(&q[i], fmts[i],
1724 IPU3_CSS_QUEUE_TO_FLAGS(i))) {
1725 dev_notice(css->dev, "can not initialize queue %s\n",
1731 for (i = 0; i < IPU3_CSS_RECTS; i++) {
1733 dev_dbg(css->dev, "%s %s: (%i,%i)\n", __func__,
1734 rnames[i], rects[i]->width, rects[i]->height);
1735 r[i].width = rects[i]->width;
1736 r[i].height = rects[i]->height;
1738 dev_dbg(css->dev, "%s %s: (not set)\n", __func__,
1741 /* For now, force known good resolutions */
1746 /* Always require one input and vf only if out is also enabled */
1747 if (!imgu_css_queue_enabled(&q[IPU3_CSS_QUEUE_IN]) ||
1748 !imgu_css_queue_enabled(&q[IPU3_CSS_QUEUE_OUT])) {
1749 dev_warn(css->dev, "required queues are disabled\n");
1754 if (!imgu_css_queue_enabled(&q[IPU3_CSS_QUEUE_OUT])) {
1755 out->width = in->width;
1756 out->height = in->height;
1758 if (eff->width <= 0 || eff->height <= 0) {
1759 eff->width = in->width;
1760 eff->height = in->height;
1762 if (bds->width <= 0 || bds->height <= 0) {
1763 bds->width = out->width;
1764 bds->height = out->height;
1766 if (gdc->width <= 0 || gdc->height <= 0) {
1767 gdc->width = out->width;
1768 gdc->height = out->height;
1771 in->width = imgu_css_adjust(in->width, 1);
1772 in->height = imgu_css_adjust(in->height, 1);
1773 eff->width = imgu_css_adjust(eff->width, EFF_ALIGN_W);
1774 eff->height = imgu_css_adjust(eff->height, 1);
1775 bds->width = imgu_css_adjust(bds->width, BDS_ALIGN_W);
1776 bds->height = imgu_css_adjust(bds->height, 1);
1777 gdc->width = imgu_css_adjust(gdc->width, OUT_ALIGN_W);
1778 gdc->height = imgu_css_adjust(gdc->height, OUT_ALIGN_H);
1779 out->width = imgu_css_adjust(out->width, OUT_ALIGN_W);
1780 out->height = imgu_css_adjust(out->height, OUT_ALIGN_H);
1781 vf->width = imgu_css_adjust(vf->width, VF_ALIGN_W);
1782 vf->height = imgu_css_adjust(vf->height, 1);
1784 s = (bds->width - gdc->width) / 2;
1785 env->width = s < MIN_ENVELOPE ? MIN_ENVELOPE : s;
1786 s = (bds->height - gdc->height) / 2;
1787 env->height = s < MIN_ENVELOPE ? MIN_ENVELOPE : s;
1789 ret = imgu_css_find_binary(css, pipe, q, r);
1791 dev_err(css->dev, "failed to find suitable binary\n");
1795 css->pipes[pipe].bindex = ret;
1797 dev_dbg(css->dev, "Binary index %d for pipe %d found.",
1798 css->pipes[pipe].bindex, pipe);
1800 /* Final adjustment and set back the queried formats */
1801 for (i = 0; i < IPU3_CSS_QUEUES; i++) {
1803 if (imgu_css_queue_init(&q[i], &q[i].fmt.mpix,
1804 IPU3_CSS_QUEUE_TO_FLAGS(i))) {
1806 "final resolution adjustment failed\n");
1810 *fmts[i] = q[i].fmt.mpix;
1814 for (i = 0; i < IPU3_CSS_RECTS; i++)
1819 "in(%u,%u) if(%u,%u) ds(%u,%u) gdc(%u,%u) out(%u,%u) vf(%u,%u)",
1820 in->width, in->height, eff->width, eff->height,
1821 bds->width, bds->height, gdc->width, gdc->height,
1822 out->width, out->height, vf->width, vf->height);
1830 int imgu_css_fmt_set(struct imgu_css *css,
1831 struct v4l2_pix_format_mplane *fmts[IPU3_CSS_QUEUES],
1832 struct v4l2_rect *rects[IPU3_CSS_RECTS],
1835 struct v4l2_rect rect_data[IPU3_CSS_RECTS];
1836 struct v4l2_rect *all_rects[IPU3_CSS_RECTS];
1838 struct imgu_css_pipe *css_pipe = &css->pipes[pipe];
1840 for (i = 0; i < IPU3_CSS_RECTS; i++) {
1842 rect_data[i] = *rects[i];
1844 memset(&rect_data[i], 0, sizeof(rect_data[i]));
1845 all_rects[i] = &rect_data[i];
1847 r = imgu_css_fmt_try(css, fmts, all_rects, pipe);
1851 for (i = 0; i < IPU3_CSS_QUEUES; i++)
1852 if (imgu_css_queue_init(&css_pipe->queue[i], fmts[i],
1853 IPU3_CSS_QUEUE_TO_FLAGS(i)))
1855 for (i = 0; i < IPU3_CSS_RECTS; i++) {
1856 css_pipe->rect[i] = rect_data[i];
1858 *rects[i] = rect_data[i];
1864 int imgu_css_meta_fmt_set(struct v4l2_meta_format *fmt)
1866 switch (fmt->dataformat) {
1867 case V4L2_META_FMT_IPU3_PARAMS:
1868 fmt->buffersize = sizeof(struct ipu3_uapi_params);
1871 * Sanity check for the parameter struct size. This must
1874 BUILD_BUG_ON(sizeof(struct ipu3_uapi_params) != 39328);
1877 case V4L2_META_FMT_IPU3_STAT_3A:
1878 fmt->buffersize = sizeof(struct ipu3_uapi_stats_3a);
1888 * Queue given buffer to CSS. imgu_css_buf_prepare() must have been first
1889 * called for the buffer. May be called from interrupt context.
1890 * Returns 0 on success, -EBUSY if the buffer queue is full, or some other
1891 * code on error conditions.
1893 int imgu_css_buf_queue(struct imgu_css *css, unsigned int pipe,
1894 struct imgu_css_buffer *b)
1896 struct imgu_abi_buffer *abi_buf;
1897 struct imgu_addr_t *buf_addr;
1900 struct imgu_css_pipe *css_pipe = &css->pipes[pipe];
1902 if (!css->streaming)
1903 return -EPROTO; /* CSS or buffer in wrong state */
1905 if (b->queue >= IPU3_CSS_QUEUES || !imgu_css_queues[b->queue].qid)
1908 b->queue_pos = imgu_css_queue_pos(css, imgu_css_queues[b->queue].qid,
1911 if (b->queue_pos >= ARRAY_SIZE(css->pipes[pipe].abi_buffers[b->queue]))
1913 abi_buf = css->pipes[pipe].abi_buffers[b->queue][b->queue_pos].vaddr;
1915 /* Fill struct abi_buffer for firmware */
1916 memset(abi_buf, 0, sizeof(*abi_buf));
1918 buf_addr = (void *)abi_buf + imgu_css_queues[b->queue].ptr_ofs;
1919 *(imgu_addr_t *)buf_addr = b->daddr;
1921 if (b->queue == IPU3_CSS_QUEUE_STAT_3A)
1922 abi_buf->payload.s3a.data.dmem.s3a_tbl = b->daddr;
1924 if (b->queue == IPU3_CSS_QUEUE_OUT)
1925 abi_buf->payload.frame.padded_width =
1926 css_pipe->queue[IPU3_CSS_QUEUE_OUT].width_pad;
1928 if (b->queue == IPU3_CSS_QUEUE_VF)
1929 abi_buf->payload.frame.padded_width =
1930 css_pipe->queue[IPU3_CSS_QUEUE_VF].width_pad;
1932 spin_lock(&css_pipe->qlock);
1933 list_add_tail(&b->list, &css_pipe->queue[b->queue].bufs);
1934 spin_unlock(&css_pipe->qlock);
1935 b->state = IPU3_CSS_BUFFER_QUEUED;
1937 data = css->pipes[pipe].abi_buffers[b->queue][b->queue_pos].daddr;
1938 r = imgu_css_queue_data(css, imgu_css_queues[b->queue].qid,
1941 goto queueing_failed;
1943 data = IMGU_ABI_EVENT_BUFFER_ENQUEUED(pipe,
1944 imgu_css_queues[b->queue].qid);
1945 r = imgu_css_queue_data(css, IMGU_ABI_QUEUE_EVENT_ID, pipe, data);
1947 goto queueing_failed;
1949 dev_dbg(css->dev, "queued buffer %p to css queue %i in pipe %d\n",
1955 b->state = (r == -EBUSY || r == -EAGAIN) ?
1956 IPU3_CSS_BUFFER_NEW : IPU3_CSS_BUFFER_FAILED;
1963 * Get next ready CSS buffer. Returns -EAGAIN in which case the function
1964 * should be called again, or -EBUSY which means that there are no more
1965 * buffers available. May be called from interrupt context.
1967 struct imgu_css_buffer *imgu_css_buf_dequeue(struct imgu_css *css)
1969 static const unsigned char evtype_to_queue[] = {
1970 [IMGU_ABI_EVTTYPE_INPUT_FRAME_DONE] = IPU3_CSS_QUEUE_IN,
1971 [IMGU_ABI_EVTTYPE_OUT_FRAME_DONE] = IPU3_CSS_QUEUE_OUT,
1972 [IMGU_ABI_EVTTYPE_VF_OUT_FRAME_DONE] = IPU3_CSS_QUEUE_VF,
1973 [IMGU_ABI_EVTTYPE_3A_STATS_DONE] = IPU3_CSS_QUEUE_STAT_3A,
1975 struct imgu_css_buffer *b = ERR_PTR(-EAGAIN);
1977 int evtype, pipe, pipeid, queue, qid, r;
1978 struct imgu_css_pipe *css_pipe;
1980 if (!css->streaming)
1981 return ERR_PTR(-EPROTO);
1983 r = imgu_css_dequeue_data(css, IMGU_ABI_QUEUE_EVENT_ID, &event);
1987 evtype = (event & IMGU_ABI_EVTTYPE_EVENT_MASK) >>
1988 IMGU_ABI_EVTTYPE_EVENT_SHIFT;
1991 case IMGU_ABI_EVTTYPE_OUT_FRAME_DONE:
1992 case IMGU_ABI_EVTTYPE_VF_OUT_FRAME_DONE:
1993 case IMGU_ABI_EVTTYPE_3A_STATS_DONE:
1994 case IMGU_ABI_EVTTYPE_INPUT_FRAME_DONE:
1995 pipe = (event & IMGU_ABI_EVTTYPE_PIPE_MASK) >>
1996 IMGU_ABI_EVTTYPE_PIPE_SHIFT;
1997 pipeid = (event & IMGU_ABI_EVTTYPE_PIPEID_MASK) >>
1998 IMGU_ABI_EVTTYPE_PIPEID_SHIFT;
1999 queue = evtype_to_queue[evtype];
2000 qid = imgu_css_queues[queue].qid;
2002 if (pipe >= IMGU_MAX_PIPE_NUM) {
2003 dev_err(css->dev, "Invalid pipe: %i\n", pipe);
2004 return ERR_PTR(-EIO);
2007 if (qid >= IMGU_ABI_QUEUE_NUM) {
2008 dev_err(css->dev, "Invalid qid: %i\n", qid);
2009 return ERR_PTR(-EIO);
2011 css_pipe = &css->pipes[pipe];
2013 "event: buffer done 0x%x queue %i pipe %i pipeid %i\n",
2014 event, queue, pipe, pipeid);
2016 r = imgu_css_dequeue_data(css, qid, &daddr);
2018 dev_err(css->dev, "failed to dequeue buffer\n");
2019 /* Force real error, not -EBUSY */
2020 return ERR_PTR(-EIO);
2023 r = imgu_css_queue_data(css, IMGU_ABI_QUEUE_EVENT_ID, pipe,
2024 IMGU_ABI_EVENT_BUFFER_DEQUEUED(qid));
2026 dev_err(css->dev, "failed to queue event\n");
2027 return ERR_PTR(-EIO);
2030 spin_lock(&css_pipe->qlock);
2031 if (list_empty(&css_pipe->queue[queue].bufs)) {
2032 spin_unlock(&css_pipe->qlock);
2033 dev_err(css->dev, "event on empty queue\n");
2034 return ERR_PTR(-EIO);
2036 b = list_first_entry(&css_pipe->queue[queue].bufs,
2037 struct imgu_css_buffer, list);
2038 if (queue != b->queue ||
2039 daddr != css_pipe->abi_buffers
2040 [b->queue][b->queue_pos].daddr) {
2041 spin_unlock(&css_pipe->qlock);
2042 dev_err(css->dev, "dequeued bad buffer 0x%x\n", daddr);
2043 return ERR_PTR(-EIO);
2046 dev_dbg(css->dev, "buffer 0x%8x done from pipe %d\n", daddr, pipe);
2048 b->state = IPU3_CSS_BUFFER_DONE;
2050 spin_unlock(&css_pipe->qlock);
2052 case IMGU_ABI_EVTTYPE_PIPELINE_DONE:
2053 pipe = (event & IMGU_ABI_EVTTYPE_PIPE_MASK) >>
2054 IMGU_ABI_EVTTYPE_PIPE_SHIFT;
2055 if (pipe >= IMGU_MAX_PIPE_NUM) {
2056 dev_err(css->dev, "Invalid pipe: %i\n", pipe);
2057 return ERR_PTR(-EIO);
2060 css_pipe = &css->pipes[pipe];
2061 dev_dbg(css->dev, "event: pipeline done 0x%8x for pipe %d\n",
2064 case IMGU_ABI_EVTTYPE_TIMER:
2065 r = imgu_css_dequeue_data(css, IMGU_ABI_QUEUE_EVENT_ID, &event);
2069 if ((event & IMGU_ABI_EVTTYPE_EVENT_MASK) >>
2070 IMGU_ABI_EVTTYPE_EVENT_SHIFT == IMGU_ABI_EVTTYPE_TIMER)
2071 dev_dbg(css->dev, "event: timer\n");
2073 dev_warn(css->dev, "half of timer event missing\n");
2075 case IMGU_ABI_EVTTYPE_FW_WARNING:
2076 dev_warn(css->dev, "event: firmware warning 0x%x\n", event);
2078 case IMGU_ABI_EVTTYPE_FW_ASSERT:
2080 "event: firmware assert 0x%x module_id %i line_no %i\n",
2082 (event & IMGU_ABI_EVTTYPE_MODULEID_MASK) >>
2083 IMGU_ABI_EVTTYPE_MODULEID_SHIFT,
2084 swab16((event & IMGU_ABI_EVTTYPE_LINENO_MASK) >>
2085 IMGU_ABI_EVTTYPE_LINENO_SHIFT));
2088 dev_warn(css->dev, "received unknown event 0x%x\n", event);
2095 * Get a new set of parameters from pool and initialize them based on
2096 * the parameters params, gdc, and obgrid. Any of these may be NULL,
2097 * in which case the previously set parameters are used.
2098 * If parameters haven't been set previously, initialize from scratch.
2100 * Return index to css->parameter_set_info which has the newly created
2101 * parameters or negative value on error.
2103 int imgu_css_set_parameters(struct imgu_css *css, unsigned int pipe,
2104 struct ipu3_uapi_params *set_params)
2106 static const unsigned int queue_id = IMGU_ABI_QUEUE_A_ID;
2107 struct imgu_css_pipe *css_pipe = &css->pipes[pipe];
2108 const int stage = 0;
2109 const struct imgu_fw_info *bi;
2111 unsigned int stripes, i;
2112 struct ipu3_uapi_flags *use = set_params ? &set_params->use : NULL;
2114 /* Destination buffers which are filled here */
2115 struct imgu_abi_parameter_set_info *param_set;
2116 struct imgu_abi_acc_param *acc = NULL;
2117 struct imgu_abi_gdc_warp_param *gdc = NULL;
2118 struct ipu3_uapi_obgrid_param *obgrid = NULL;
2119 const struct imgu_css_map *map;
2123 enum imgu_abi_memories m;
2126 if (!css->streaming)
2129 dev_dbg(css->dev, "%s for pipe %d", __func__, pipe);
2131 bi = &css->fwp->binary_header[css_pipe->bindex];
2132 obgrid_size = imgu_css_fw_obgrid_size(bi);
2133 stripes = bi->info.isp.sp.iterator.num_stripes ? : 1;
2135 imgu_css_pool_get(&css_pipe->pool.parameter_set_info);
2136 param_set = imgu_css_pool_last(&css_pipe->pool.parameter_set_info,
2139 /* Get a new acc only if new parameters given, or none yet */
2140 map = imgu_css_pool_last(&css_pipe->pool.acc, 0);
2141 if (set_params || !map->vaddr) {
2142 imgu_css_pool_get(&css_pipe->pool.acc);
2143 map = imgu_css_pool_last(&css_pipe->pool.acc, 0);
2147 /* Get new VMEM0 only if needed, or none yet */
2148 m = IMGU_ABI_MEM_ISP_VMEM0;
2149 map = imgu_css_pool_last(&css_pipe->pool.binary_params_p[m], 0);
2150 if (!map->vaddr || (set_params && (set_params->use.lin_vmem_params ||
2151 set_params->use.tnr3_vmem_params ||
2152 set_params->use.xnr3_vmem_params))) {
2153 imgu_css_pool_get(&css_pipe->pool.binary_params_p[m]);
2154 map = imgu_css_pool_last(&css_pipe->pool.binary_params_p[m], 0);
2158 /* Get new DMEM0 only if needed, or none yet */
2159 m = IMGU_ABI_MEM_ISP_DMEM0;
2160 map = imgu_css_pool_last(&css_pipe->pool.binary_params_p[m], 0);
2161 if (!map->vaddr || (set_params && (set_params->use.tnr3_dmem_params ||
2162 set_params->use.xnr3_dmem_params))) {
2163 imgu_css_pool_get(&css_pipe->pool.binary_params_p[m]);
2164 map = imgu_css_pool_last(&css_pipe->pool.binary_params_p[m], 0);
2168 /* Configure acc parameter cluster */
2171 map = imgu_css_pool_last(&css_pipe->pool.acc, 1);
2173 r = imgu_css_cfg_acc(css, pipe, use, acc, map->vaddr,
2174 set_params ? &set_params->acc_param : NULL);
2179 /* Configure late binding parameters */
2181 m = IMGU_ABI_MEM_ISP_VMEM0;
2182 map = imgu_css_pool_last(&css_pipe->pool.binary_params_p[m], 1);
2183 r = imgu_css_cfg_vmem0(css, pipe, use, vmem0,
2184 map->vaddr, set_params);
2190 m = IMGU_ABI_MEM_ISP_DMEM0;
2191 map = imgu_css_pool_last(&css_pipe->pool.binary_params_p[m], 1);
2192 r = imgu_css_cfg_dmem0(css, pipe, use, dmem0,
2193 map->vaddr, set_params);
2198 /* Get a new gdc only if a new gdc is given, or none yet */
2199 if (bi->info.isp.sp.enable.dvs_6axis) {
2200 unsigned int a = IPU3_CSS_AUX_FRAME_REF;
2201 unsigned int g = IPU3_CSS_RECT_GDC;
2202 unsigned int e = IPU3_CSS_RECT_ENVELOPE;
2204 map = imgu_css_pool_last(&css_pipe->pool.gdc, 0);
2206 imgu_css_pool_get(&css_pipe->pool.gdc);
2207 map = imgu_css_pool_last(&css_pipe->pool.gdc, 0);
2209 imgu_css_cfg_gdc_table(map->vaddr,
2210 css_pipe->aux_frames[a].bytesperline /
2211 css_pipe->aux_frames[a].bytesperpixel,
2212 css_pipe->aux_frames[a].height,
2213 css_pipe->rect[g].width,
2214 css_pipe->rect[g].height,
2215 css_pipe->rect[e].width,
2216 css_pipe->rect[e].height);
2220 /* Get a new obgrid only if a new obgrid is given, or none yet */
2221 map = imgu_css_pool_last(&css_pipe->pool.obgrid, 0);
2222 if (!map->vaddr || (set_params && set_params->use.obgrid_param)) {
2223 imgu_css_pool_get(&css_pipe->pool.obgrid);
2224 map = imgu_css_pool_last(&css_pipe->pool.obgrid, 0);
2225 obgrid = map->vaddr;
2227 /* Configure optical black level grid (obgrid) */
2228 if (set_params && set_params->use.obgrid_param)
2229 for (i = 0; i < obgrid_size / sizeof(*obgrid); i++)
2230 obgrid[i] = set_params->obgrid_param;
2232 memset(obgrid, 0, obgrid_size);
2235 /* Configure parameter set info, queued to `queue_id' */
2237 memset(param_set, 0, sizeof(*param_set));
2238 map = imgu_css_pool_last(&css_pipe->pool.acc, 0);
2239 param_set->mem_map.acc_cluster_params_for_sp = map->daddr;
2241 map = imgu_css_pool_last(&css_pipe->pool.gdc, 0);
2242 param_set->mem_map.dvs_6axis_params_y = map->daddr;
2244 for (i = 0; i < stripes; i++) {
2245 map = imgu_css_pool_last(&css_pipe->pool.obgrid, 0);
2246 param_set->mem_map.obgrid_tbl[i] =
2247 map->daddr + (obgrid_size / stripes) * i;
2250 for (m = 0; m < IMGU_ABI_NUM_MEMORIES; m++) {
2251 map = imgu_css_pool_last(&css_pipe->pool.binary_params_p[m], 0);
2252 param_set->mem_map.isp_mem_param[stage][m] = map->daddr;
2255 /* Then queue the new parameter buffer */
2256 map = imgu_css_pool_last(&css_pipe->pool.parameter_set_info, 0);
2257 r = imgu_css_queue_data(css, queue_id, pipe, map->daddr);
2261 r = imgu_css_queue_data(css, IMGU_ABI_QUEUE_EVENT_ID, pipe,
2262 IMGU_ABI_EVENT_BUFFER_ENQUEUED(pipe,
2267 /* Finally dequeue all old parameter buffers */
2272 r = imgu_css_dequeue_data(css, queue_id, &daddr);
2277 r = imgu_css_queue_data(css, IMGU_ABI_QUEUE_EVENT_ID, pipe,
2278 IMGU_ABI_EVENT_BUFFER_DEQUEUED
2281 dev_err(css->dev, "failed to queue parameter event\n");
2290 * A failure, most likely the parameter queue was full.
2291 * Return error but continue streaming. User can try submitting new
2292 * parameters again later.
2295 imgu_css_pool_put(&css_pipe->pool.parameter_set_info);
2297 imgu_css_pool_put(&css_pipe->pool.acc);
2299 imgu_css_pool_put(&css_pipe->pool.gdc);
2301 imgu_css_pool_put(&css_pipe->pool.obgrid);
2304 &css_pipe->pool.binary_params_p
2305 [IMGU_ABI_MEM_ISP_VMEM0]);
2308 &css_pipe->pool.binary_params_p
2309 [IMGU_ABI_MEM_ISP_DMEM0]);
2315 int imgu_css_irq_ack(struct imgu_css *css)
2317 static const int NUM_SWIRQS = 3;
2318 struct imgu_fw_info *bi = &css->fwp->binary_header[css->fw_sp[0]];
2319 void __iomem *const base = css->base;
2320 u32 irq_status[IMGU_IRQCTRL_NUM];
2323 u32 imgu_status = readl(base + IMGU_REG_INT_STATUS);
2325 writel(imgu_status, base + IMGU_REG_INT_STATUS);
2326 for (i = 0; i < IMGU_IRQCTRL_NUM; i++)
2327 irq_status[i] = readl(base + IMGU_REG_IRQCTRL_STATUS(i));
2329 for (i = 0; i < NUM_SWIRQS; i++) {
2330 if (irq_status[IMGU_IRQCTRL_SP0] & IMGU_IRQCTRL_IRQ_SW_PIN(i)) {
2331 /* SP SW interrupt */
2332 u32 cnt = readl(base + IMGU_REG_SP_DMEM_BASE(0) +
2333 bi->info.sp.output);
2334 u32 val = readl(base + IMGU_REG_SP_DMEM_BASE(0) +
2335 bi->info.sp.output + 4 + 4 * i);
2337 dev_dbg(css->dev, "%s: swirq %i cnt %i val 0x%x\n",
2338 __func__, i, cnt, val);
2342 for (i = IMGU_IRQCTRL_NUM - 1; i >= 0; i--)
2343 if (irq_status[i]) {
2344 writel(irq_status[i], base + IMGU_REG_IRQCTRL_CLEAR(i));
2345 /* Wait for write to complete */
2346 readl(base + IMGU_REG_IRQCTRL_ENABLE(i));
2349 dev_dbg(css->dev, "%s: imgu 0x%x main 0x%x sp0 0x%x sp1 0x%x\n",
2350 __func__, imgu_status, irq_status[IMGU_IRQCTRL_MAIN],
2351 irq_status[IMGU_IRQCTRL_SP0], irq_status[IMGU_IRQCTRL_SP1]);
2353 if (!imgu_status && !irq_status[IMGU_IRQCTRL_MAIN])