Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'tags/media-next-rkisp1-20240223' of git://git.kernel.org/pub/scm/linux/kernel/git/pinchartl/linux.git into media_stage

This adds i.MX8MP support to the rkisp1 driver.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Link: https://patchwork.linuxtv.org/project/linux-media/patch/20240223123556.GA26004@pendragon.ideasonboard.com/

+501 -94
+31 -6
Documentation/devicetree/bindings/media/rockchip-isp1.yaml
··· 16 16 properties: 17 17 compatible: 18 18 enum: 19 + - fsl,imx8mp-isp 19 20 - rockchip,px30-cif-isp 20 21 - rockchip,rk3399-cif-isp 21 22 ··· 37 36 minItems: 3 38 37 items: 39 38 # isp0 and isp1 40 - - description: ISP clock 41 - - description: ISP AXI clock 42 - - description: ISP AHB clock 39 + - description: ISP clock (for imx8mp, clk) 40 + - description: ISP AXI clock (for imx8mp, m_hclk) 41 + - description: ISP AHB clock (for imx8mp, hclk) 43 42 # only for isp1 44 43 - description: ISP Pixel clock 45 44 ··· 52 51 - const: hclk 53 52 # only for isp1 54 53 - const: pclk 54 + 55 + fsl,blk-ctrl: 56 + $ref: /schemas/types.yaml#/definitions/phandle-array 57 + maxItems: 1 58 + description: 59 + A phandle to the media block control for the ISP, followed by a cell 60 + containing the index of the gasket. 55 61 56 62 iommus: 57 63 maxItems: 1 ··· 121 113 - interrupts 122 114 - clocks 123 115 - clock-names 124 - - iommus 125 - - phys 126 - - phy-names 127 116 - power-domains 128 117 - ports 129 118 ··· 147 142 then: 148 143 required: 149 144 - interrupt-names 145 + 146 + - if: 147 + properties: 148 + compatible: 149 + contains: 150 + const: fsl,imx8mp-isp 151 + then: 152 + properties: 153 + iommus: false 154 + phys: false 155 + phy-names: false 156 + required: 157 + - fsl,blk-ctrl 158 + else: 159 + properties: 160 + fsl,blk-ctrl: false 161 + required: 162 + - iommus 163 + - phys 164 + - phy-names 150 165 151 166 additionalProperties: false 152 167
+173 -43
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
··· 47 47 * @fourcc: pixel format 48 48 * @fmt_type: helper filed for pixel format 49 49 * @uv_swap: if cb cr swapped, for yuv 50 + * @yc_swap: if y and cb/cr swapped, for yuv 51 + * @byte_swap: if byte pairs are swapped, for raw 50 52 * @write_format: defines how YCbCr self picture data is written to memory 51 - * @output_format: defines sp output format 53 + * @output_format: defines the output format (RKISP1_CIF_MI_INIT_MP_OUTPUT_* for 54 + * the main path and RKISP1_MI_CTRL_SP_OUTPUT_* for the self path) 52 55 * @mbus: the mbus code on the src resizer pad that matches the pixel format 53 56 */ 54 57 struct rkisp1_capture_fmt_cfg { 55 58 u32 fourcc; 56 - u8 uv_swap; 59 + u32 uv_swap : 1; 60 + u32 yc_swap : 1; 61 + u32 byte_swap : 1; 57 62 u32 write_format; 58 63 u32 output_format; 59 64 u32 mbus; ··· 99 94 .fourcc = V4L2_PIX_FMT_YUYV, 100 95 .uv_swap = 0, 101 96 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUVINT, 97 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV422, 98 + .mbus = MEDIA_BUS_FMT_YUYV8_2X8, 99 + }, { 100 + .fourcc = V4L2_PIX_FMT_UYVY, 101 + .uv_swap = 0, 102 + .yc_swap = 1, 103 + .write_format = RKISP1_MI_CTRL_MP_WRITE_YUVINT, 104 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV422, 102 105 .mbus = MEDIA_BUS_FMT_YUYV8_2X8, 103 106 }, { 104 107 .fourcc = V4L2_PIX_FMT_YUV422P, 105 108 .uv_swap = 0, 106 109 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, 110 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV422, 107 111 .mbus = MEDIA_BUS_FMT_YUYV8_2X8, 108 112 }, { 109 113 .fourcc = V4L2_PIX_FMT_NV16, 110 114 .uv_swap = 0, 111 115 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_SPLA, 116 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV422, 112 117 .mbus = MEDIA_BUS_FMT_YUYV8_2X8, 113 118 }, { 114 119 .fourcc = V4L2_PIX_FMT_NV61, 115 120 .uv_swap = 1, 116 121 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_SPLA, 122 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV422, 117 123 .mbus = MEDIA_BUS_FMT_YUYV8_2X8, 118 124 }, { 119 125 .fourcc = V4L2_PIX_FMT_NV16M, 120 126 .uv_swap = 0, 121 127 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_SPLA, 128 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV422, 122 129 .mbus = MEDIA_BUS_FMT_YUYV8_2X8, 123 130 }, { 124 131 .fourcc = V4L2_PIX_FMT_NV61M, 125 132 .uv_swap = 1, 126 133 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_SPLA, 134 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV422, 127 135 .mbus = MEDIA_BUS_FMT_YUYV8_2X8, 128 136 }, { 129 137 .fourcc = V4L2_PIX_FMT_YVU422M, 130 138 .uv_swap = 1, 131 139 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, 140 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV422, 132 141 .mbus = MEDIA_BUS_FMT_YUYV8_2X8, 133 142 }, 134 143 /* yuv400 */ ··· 150 131 .fourcc = V4L2_PIX_FMT_GREY, 151 132 .uv_swap = 0, 152 133 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, 134 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV400, 153 135 .mbus = MEDIA_BUS_FMT_YUYV8_2X8, 154 136 }, 155 137 /* yuv420 */ ··· 158 138 .fourcc = V4L2_PIX_FMT_NV21, 159 139 .uv_swap = 1, 160 140 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_SPLA, 141 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV420, 161 142 .mbus = MEDIA_BUS_FMT_YUYV8_1_5X8, 162 143 }, { 163 144 .fourcc = V4L2_PIX_FMT_NV12, 164 145 .uv_swap = 0, 165 146 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_SPLA, 147 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV420, 166 148 .mbus = MEDIA_BUS_FMT_YUYV8_1_5X8, 167 149 }, { 168 150 .fourcc = V4L2_PIX_FMT_NV21M, 169 151 .uv_swap = 1, 170 152 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_SPLA, 153 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV420, 171 154 .mbus = MEDIA_BUS_FMT_YUYV8_1_5X8, 172 155 }, { 173 156 .fourcc = V4L2_PIX_FMT_NV12M, 174 157 .uv_swap = 0, 175 158 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_SPLA, 159 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV420, 176 160 .mbus = MEDIA_BUS_FMT_YUYV8_1_5X8, 177 161 }, { 178 162 .fourcc = V4L2_PIX_FMT_YUV420, 179 163 .uv_swap = 0, 180 164 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, 165 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV420, 181 166 .mbus = MEDIA_BUS_FMT_YUYV8_1_5X8, 182 167 }, { 183 168 .fourcc = V4L2_PIX_FMT_YVU420, 184 169 .uv_swap = 1, 185 170 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, 171 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV420, 186 172 .mbus = MEDIA_BUS_FMT_YUYV8_1_5X8, 187 173 }, 188 174 /* raw */ 189 175 { 190 176 .fourcc = V4L2_PIX_FMT_SRGGB8, 191 177 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, 178 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW8, 192 179 .mbus = MEDIA_BUS_FMT_SRGGB8_1X8, 193 180 }, { 194 181 .fourcc = V4L2_PIX_FMT_SGRBG8, 195 182 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, 183 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW8, 196 184 .mbus = MEDIA_BUS_FMT_SGRBG8_1X8, 197 185 }, { 198 186 .fourcc = V4L2_PIX_FMT_SGBRG8, 199 187 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, 188 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW8, 200 189 .mbus = MEDIA_BUS_FMT_SGBRG8_1X8, 201 190 }, { 202 191 .fourcc = V4L2_PIX_FMT_SBGGR8, 203 192 .write_format = RKISP1_MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8, 193 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW8, 204 194 .mbus = MEDIA_BUS_FMT_SBGGR8_1X8, 205 195 }, { 206 196 .fourcc = V4L2_PIX_FMT_SRGGB10, 197 + .byte_swap = 1, 207 198 .write_format = RKISP1_MI_CTRL_MP_WRITE_RAW12, 199 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW10, 208 200 .mbus = MEDIA_BUS_FMT_SRGGB10_1X10, 209 201 }, { 210 202 .fourcc = V4L2_PIX_FMT_SGRBG10, 203 + .byte_swap = 1, 211 204 .write_format = RKISP1_MI_CTRL_MP_WRITE_RAW12, 205 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW10, 212 206 .mbus = MEDIA_BUS_FMT_SGRBG10_1X10, 213 207 }, { 214 208 .fourcc = V4L2_PIX_FMT_SGBRG10, 209 + .byte_swap = 1, 215 210 .write_format = RKISP1_MI_CTRL_MP_WRITE_RAW12, 211 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW10, 216 212 .mbus = MEDIA_BUS_FMT_SGBRG10_1X10, 217 213 }, { 218 214 .fourcc = V4L2_PIX_FMT_SBGGR10, 215 + .byte_swap = 1, 219 216 .write_format = RKISP1_MI_CTRL_MP_WRITE_RAW12, 217 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW10, 220 218 .mbus = MEDIA_BUS_FMT_SBGGR10_1X10, 221 219 }, { 222 220 .fourcc = V4L2_PIX_FMT_SRGGB12, 221 + .byte_swap = 1, 223 222 .write_format = RKISP1_MI_CTRL_MP_WRITE_RAW12, 223 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW12, 224 224 .mbus = MEDIA_BUS_FMT_SRGGB12_1X12, 225 225 }, { 226 226 .fourcc = V4L2_PIX_FMT_SGRBG12, 227 + .byte_swap = 1, 227 228 .write_format = RKISP1_MI_CTRL_MP_WRITE_RAW12, 229 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW12, 228 230 .mbus = MEDIA_BUS_FMT_SGRBG12_1X12, 229 231 }, { 230 232 .fourcc = V4L2_PIX_FMT_SGBRG12, 233 + .byte_swap = 1, 231 234 .write_format = RKISP1_MI_CTRL_MP_WRITE_RAW12, 235 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW12, 232 236 .mbus = MEDIA_BUS_FMT_SGBRG12_1X12, 233 237 }, { 234 238 .fourcc = V4L2_PIX_FMT_SBGGR12, 239 + .byte_swap = 1, 235 240 .write_format = RKISP1_MI_CTRL_MP_WRITE_RAW12, 241 + .output_format = RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW12, 236 242 .mbus = MEDIA_BUS_FMT_SBGGR12_1X12, 237 243 }, 238 244 }; ··· 272 226 { 273 227 .fourcc = V4L2_PIX_FMT_YUYV, 274 228 .uv_swap = 0, 229 + .write_format = RKISP1_MI_CTRL_SP_WRITE_INT, 230 + .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV422, 231 + .mbus = MEDIA_BUS_FMT_YUYV8_2X8, 232 + }, { 233 + .fourcc = V4L2_PIX_FMT_UYVY, 234 + .uv_swap = 0, 235 + .yc_swap = 1, 275 236 .write_format = RKISP1_MI_CTRL_SP_WRITE_INT, 276 237 .output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV422, 277 238 .mbus = MEDIA_BUS_FMT_YUYV8_2X8, ··· 495 442 rkisp1_write(rkisp1, cap->config->mi.cr_size_init, 496 443 rkisp1_pixfmt_comp_size(pixm, RKISP1_PLANE_CR)); 497 444 445 + if (rkisp1_has_feature(rkisp1, MAIN_STRIDE)) { 446 + rkisp1_write(rkisp1, RKISP1_CIF_MI_MP_Y_LLENGTH, cap->stride); 447 + rkisp1_write(rkisp1, RKISP1_CIF_MI_MP_Y_PIC_WIDTH, pixm->width); 448 + rkisp1_write(rkisp1, RKISP1_CIF_MI_MP_Y_PIC_HEIGHT, pixm->height); 449 + rkisp1_write(rkisp1, RKISP1_CIF_MI_MP_Y_PIC_SIZE, 450 + cap->stride * pixm->height); 451 + } 452 + 498 453 rkisp1_irq_frame_end_enable(cap); 499 454 500 455 /* set uv swapping for semiplanar formats */ ··· 513 452 else 514 453 reg &= ~RKISP1_CIF_MI_XTD_FMT_CTRL_MP_CB_CR_SWAP; 515 454 rkisp1_write(rkisp1, RKISP1_CIF_MI_XTD_FORMAT_CTRL, reg); 455 + } 456 + 457 + /* 458 + * U/V swapping with the MI_XTD_FORMAT_CTRL register only works for 459 + * NV12/NV21 and NV16/NV61, so instead use byte swap to support UYVY. 460 + * YVYU and VYUY cannot be supported with this method. 461 + */ 462 + if (rkisp1_has_feature(rkisp1, MAIN_STRIDE)) { 463 + reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT); 464 + if (cap->pix.cfg->yc_swap || cap->pix.cfg->byte_swap) 465 + reg |= RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_BYTES; 466 + else 467 + reg &= ~RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_BYTES; 468 + 469 + reg |= RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_LSB_ALIGNMENT; 470 + rkisp1_write(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT, reg); 471 + 472 + rkisp1_write(rkisp1, RKISP1_CIF_MI_INIT, 473 + cap->pix.cfg->output_format); 516 474 } 517 475 518 476 rkisp1_mi_config_ctrl(cap); ··· 559 479 rkisp1_write(rkisp1, cap->config->mi.cr_size_init, 560 480 rkisp1_pixfmt_comp_size(pixm, RKISP1_PLANE_CR)); 561 481 562 - rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_LLENGTH, cap->sp_y_stride); 482 + rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_LLENGTH, cap->stride); 563 483 rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_PIC_WIDTH, pixm->width); 564 484 rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_PIC_HEIGHT, pixm->height); 565 485 rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_PIC_SIZE, 566 - cap->sp_y_stride * pixm->height); 486 + cap->stride * pixm->height); 567 487 568 488 rkisp1_irq_frame_end_enable(cap); 569 489 ··· 575 495 else 576 496 reg &= ~RKISP1_CIF_MI_XTD_FMT_CTRL_SP_CB_CR_SWAP; 577 497 rkisp1_write(rkisp1, RKISP1_CIF_MI_XTD_FORMAT_CTRL, reg); 498 + } 499 + 500 + /* 501 + * U/V swapping with the MI_XTD_FORMAT_CTRL register only works for 502 + * NV12/NV21 and NV16/NV61, so instead use byte swap to support UYVY. 503 + * YVYU and VYUY cannot be supported with this method. 504 + */ 505 + if (rkisp1_has_feature(rkisp1, MAIN_STRIDE)) { 506 + reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT); 507 + if (cap->pix.cfg->yc_swap) 508 + reg |= RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_BYTES; 509 + else 510 + reg &= ~RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_BYTES; 511 + rkisp1_write(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT, reg); 578 512 } 579 513 580 514 rkisp1_mi_config_ctrl(cap); ··· 734 640 735 641 static void rkisp1_set_next_buf(struct rkisp1_capture *cap) 736 642 { 643 + u8 shift = rkisp1_has_feature(cap->rkisp1, DMA_34BIT) ? 2 : 0; 644 + 737 645 cap->buf.curr = cap->buf.next; 738 646 cap->buf.next = NULL; 739 647 740 648 if (!list_empty(&cap->buf.queue)) { 741 - u32 *buff_addr; 649 + dma_addr_t *buff_addr; 742 650 743 651 cap->buf.next = list_first_entry(&cap->buf.queue, struct rkisp1_buffer, queue); 744 652 list_del(&cap->buf.next->queue); ··· 748 652 buff_addr = cap->buf.next->buff_addr; 749 653 750 654 rkisp1_write(cap->rkisp1, cap->config->mi.y_base_ad_init, 751 - buff_addr[RKISP1_PLANE_Y]); 655 + buff_addr[RKISP1_PLANE_Y] >> shift); 752 656 /* 753 657 * In order to support grey format we capture 754 658 * YUV422 planar format from the camera and ··· 757 661 if (cap->pix.cfg->fourcc == V4L2_PIX_FMT_GREY) { 758 662 rkisp1_write(cap->rkisp1, 759 663 cap->config->mi.cb_base_ad_init, 760 - cap->buf.dummy.dma_addr); 664 + cap->buf.dummy.dma_addr >> shift); 761 665 rkisp1_write(cap->rkisp1, 762 666 cap->config->mi.cr_base_ad_init, 763 - cap->buf.dummy.dma_addr); 667 + cap->buf.dummy.dma_addr >> shift); 764 668 } else { 765 669 rkisp1_write(cap->rkisp1, 766 670 cap->config->mi.cb_base_ad_init, 767 - buff_addr[RKISP1_PLANE_CB]); 671 + buff_addr[RKISP1_PLANE_CB] >> shift); 768 672 rkisp1_write(cap->rkisp1, 769 673 cap->config->mi.cr_base_ad_init, 770 - buff_addr[RKISP1_PLANE_CR]); 674 + buff_addr[RKISP1_PLANE_CR] >> shift); 771 675 } 772 676 } else { 773 677 /* ··· 775 679 * throw data if there is no available buffer. 776 680 */ 777 681 rkisp1_write(cap->rkisp1, cap->config->mi.y_base_ad_init, 778 - cap->buf.dummy.dma_addr); 682 + cap->buf.dummy.dma_addr >> shift); 779 683 rkisp1_write(cap->rkisp1, cap->config->mi.cb_base_ad_init, 780 - cap->buf.dummy.dma_addr); 684 + cap->buf.dummy.dma_addr >> shift); 781 685 rkisp1_write(cap->rkisp1, cap->config->mi.cr_base_ad_init, 782 - cap->buf.dummy.dma_addr); 686 + cap->buf.dummy.dma_addr >> shift); 783 687 } 784 688 785 689 /* Set plane offsets */ ··· 818 722 { 819 723 struct device *dev = ctx; 820 724 struct rkisp1_device *rkisp1 = dev_get_drvdata(dev); 725 + unsigned int dev_count = rkisp1_path_count(rkisp1); 821 726 unsigned int i; 822 727 u32 status; 823 728 ··· 828 731 829 732 rkisp1_write(rkisp1, RKISP1_CIF_MI_ICR, status); 830 733 831 - for (i = 0; i < ARRAY_SIZE(rkisp1->capture_devs); ++i) { 734 + for (i = 0; i < dev_count; ++i) { 832 735 struct rkisp1_capture *cap = &rkisp1->capture_devs[i]; 833 736 834 737 if (!(status & RKISP1_CIF_MI_FRAME(cap))) ··· 985 888 { 986 889 struct rkisp1_device *rkisp1 = cap->rkisp1; 987 890 struct rkisp1_capture *other = &rkisp1->capture_devs[cap->id ^ 1]; 891 + bool has_self_path = rkisp1_has_feature(rkisp1, SELF_PATH); 988 892 989 893 cap->ops->set_data_path(cap); 990 894 cap->ops->config(cap); ··· 994 896 spin_lock_irq(&cap->buf.lock); 995 897 rkisp1_set_next_buf(cap); 996 898 cap->ops->enable(cap); 997 - /* It's safe to configure ACTIVE and SHADOW registers for the 998 - * first stream. While when the second is starting, do NOT 999 - * force update because it also updates the first one. 899 + 900 + /* 901 + * It's safe to configure ACTIVE and SHADOW registers for the first 902 + * stream. While when the second is starting, do NOT force update 903 + * because it also updates the first one. 1000 904 * 1001 - * The latter case would drop one more buffer(that is 2) since 1002 - * there's no buffer in a shadow register when the second FE received. 1003 - * This's also required because the second FE maybe corrupt 1004 - * especially when run at 120fps. 905 + * The latter case would drop one more buffer(that is 2) since there's 906 + * no buffer in a shadow register when the second FE received. This's 907 + * also required because the second FE maybe corrupt especially when 908 + * run at 120fps. 1005 909 */ 1006 - if (!other->is_streaming) { 1007 - /* force cfg update */ 1008 - rkisp1_write(rkisp1, RKISP1_CIF_MI_INIT, 1009 - RKISP1_CIF_MI_INIT_SOFT_UPD); 910 + if (!has_self_path || !other->is_streaming) { 911 + u32 reg; 912 + 913 + /* 914 + * Force cfg update. 915 + * 916 + * The ISP8000 (implementing the MAIN_STRIDE feature) as a 917 + * mp_output_format field in the CIF_MI_INIT register that must 918 + * be preserved. It can be read back, but it is not clear what 919 + * other register bits will return. Mask them out. 920 + * 921 + * On Rockchip platforms, the CIF_MI_INIT register is marked as 922 + * write-only and reads as zeros. We can skip reading it. 923 + */ 924 + if (rkisp1_has_feature(rkisp1, MAIN_STRIDE)) 925 + reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_INIT) 926 + & RKISP1_CIF_MI_INIT_MP_OUTPUT_MASK; 927 + else 928 + reg = 0; 929 + 930 + reg |= RKISP1_CIF_MI_INIT_SOFT_UPD; 931 + rkisp1_write(rkisp1, RKISP1_CIF_MI_INIT, reg); 932 + 1010 933 rkisp1_set_next_buf(cap); 1011 934 } 1012 935 spin_unlock_irq(&cap->buf.lock); ··· 1211 1092 */ 1212 1093 1213 1094 static const struct v4l2_format_info * 1214 - rkisp1_fill_pixfmt(struct v4l2_pix_format_mplane *pixm, 1215 - enum rkisp1_stream_id id) 1095 + rkisp1_fill_pixfmt(const struct rkisp1_capture *cap, 1096 + struct v4l2_pix_format_mplane *pixm) 1216 1097 { 1217 1098 struct v4l2_plane_pix_format *plane_y = &pixm->plane_fmt[0]; 1218 1099 const struct v4l2_format_info *info; ··· 1225 1106 1226 1107 /* 1227 1108 * The SP supports custom strides, expressed as a number of pixels for 1228 - * the Y plane. Clamp the stride to a reasonable value to avoid integer 1229 - * overflows when calculating the bytesperline and sizeimage values. 1109 + * the Y plane, and so does the MP in ISP versions that have the 1110 + * MAIN_STRIDE feature. Clamp the stride to a reasonable value to avoid 1111 + * integer overflows when calculating the bytesperline and sizeimage 1112 + * values. 1230 1113 */ 1231 - if (id == RKISP1_SELFPATH) 1114 + if (cap->id == RKISP1_SELFPATH || 1115 + rkisp1_has_feature(cap->rkisp1, MAIN_STRIDE)) 1232 1116 stride = clamp(DIV_ROUND_UP(plane_y->bytesperline, info->bpp[0]), 1233 1117 pixm->width, 65536U); 1234 1118 else ··· 1266 1144 static const struct rkisp1_capture_fmt_cfg * 1267 1145 rkisp1_find_fmt_cfg(const struct rkisp1_capture *cap, const u32 pixelfmt) 1268 1146 { 1147 + bool yc_swap_support = rkisp1_has_feature(cap->rkisp1, MAIN_STRIDE); 1269 1148 unsigned int i; 1270 1149 1271 1150 for (i = 0; i < cap->config->fmt_size; i++) { 1272 - if (cap->config->fmts[i].fourcc == pixelfmt) 1151 + const struct rkisp1_capture_fmt_cfg *fmt = &cap->config->fmts[i]; 1152 + 1153 + if (fmt->fourcc == pixelfmt && 1154 + (!fmt->yc_swap || yc_swap_support)) 1273 1155 return &cap->config->fmts[i]; 1274 1156 } 1275 1157 return NULL; ··· 1310 1184 pixm->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; 1311 1185 pixm->quantization = V4L2_QUANTIZATION_DEFAULT; 1312 1186 1313 - info = rkisp1_fill_pixfmt(pixm, cap->id); 1187 + info = rkisp1_fill_pixfmt(cap, pixm); 1314 1188 1315 1189 if (fmt_cfg) 1316 1190 *fmt_cfg = fmt; ··· 1322 1196 struct v4l2_pix_format_mplane *pixm) 1323 1197 { 1324 1198 rkisp1_try_fmt(cap, pixm, &cap->pix.cfg, &cap->pix.info); 1325 - cap->pix.fmt = *pixm; 1326 1199 1327 - /* SP supports custom stride in number of pixels of the Y plane */ 1328 - if (cap->id == RKISP1_SELFPATH) 1329 - cap->sp_y_stride = pixm->plane_fmt[0].bytesperline / 1330 - cap->pix.info->bpp[0]; 1200 + cap->pix.fmt = *pixm; 1201 + cap->stride = pixm->plane_fmt[0].bytesperline / cap->pix.info->bpp[0]; 1331 1202 } 1332 1203 1333 1204 static int rkisp1_try_fmt_vid_cap_mplane(struct file *file, void *fh, ··· 1342 1219 { 1343 1220 struct rkisp1_capture *cap = video_drvdata(file); 1344 1221 const struct rkisp1_capture_fmt_cfg *fmt = NULL; 1222 + bool yc_swap_support = rkisp1_has_feature(cap->rkisp1, MAIN_STRIDE); 1345 1223 unsigned int i, n = 0; 1346 1224 1347 - if (!f->mbus_code) { 1348 - if (f->index >= cap->config->fmt_size) 1349 - return -EINVAL; 1225 + if (f->index >= cap->config->fmt_size) 1226 + return -EINVAL; 1350 1227 1228 + if (!f->mbus_code && yc_swap_support) { 1351 1229 fmt = &cap->config->fmts[f->index]; 1352 1230 f->pixelformat = fmt->fourcc; 1353 1231 return 0; 1354 1232 } 1355 1233 1356 1234 for (i = 0; i < cap->config->fmt_size; i++) { 1357 - if (cap->config->fmts[i].mbus != f->mbus_code) 1235 + fmt = &cap->config->fmts[i]; 1236 + 1237 + if (f->mbus_code && fmt->mbus != f->mbus_code) 1238 + continue; 1239 + 1240 + if (!yc_swap_support && fmt->yc_swap) 1358 1241 continue; 1359 1242 1360 1243 if (n++ == f->index) { 1361 - f->pixelformat = cap->config->fmts[i].fourcc; 1244 + f->pixelformat = fmt->fourcc; 1362 1245 return 0; 1363 1246 } 1364 1247 } ··· 1627 1498 1628 1499 int rkisp1_capture_devs_register(struct rkisp1_device *rkisp1) 1629 1500 { 1501 + unsigned int dev_count = rkisp1_path_count(rkisp1); 1630 1502 unsigned int i; 1631 1503 int ret; 1632 1504 1633 - for (i = 0; i < ARRAY_SIZE(rkisp1->capture_devs); i++) { 1505 + for (i = 0; i < dev_count; i++) { 1634 1506 struct rkisp1_capture *cap = &rkisp1->capture_devs[i]; 1635 1507 1636 1508 rkisp1_capture_init(rkisp1, i);
+32 -3
drivers/media/platform/rockchip/rkisp1/rkisp1-common.h
··· 24 24 #include "rkisp1-regs.h" 25 25 26 26 struct dentry; 27 + struct regmap; 27 28 28 29 /* 29 30 * flags on the 'direction' field in struct rkisp1_mbus_info' that indicate ··· 111 110 * enum rkisp1_feature - ISP features 112 111 * 113 112 * @RKISP1_FEATURE_MIPI_CSI2: The ISP has an internal MIPI CSI-2 receiver 113 + * @RKISP1_FEATURE_MAIN_STRIDE: The ISP supports configurable stride on the main path 114 + * @RKISP1_FEATURE_SELF_PATH: The ISP has a self path 115 + * @RKISP1_FEATURE_DUAL_CROP: The ISP has the dual crop block at the resizer input 116 + * @RKISP1_FEATURE_DMA_34BIT: The ISP uses 34-bit DMA addresses 114 117 * 115 118 * The ISP features are stored in a bitmask in &rkisp1_info.features and allow 116 119 * the driver to implement support for features present in some ISP versions ··· 122 117 */ 123 118 enum rkisp1_feature { 124 119 RKISP1_FEATURE_MIPI_CSI2 = BIT(0), 120 + RKISP1_FEATURE_MAIN_STRIDE = BIT(1), 121 + RKISP1_FEATURE_SELF_PATH = BIT(2), 122 + RKISP1_FEATURE_DUAL_CROP = BIT(3), 123 + RKISP1_FEATURE_DMA_34BIT = BIT(4), 125 124 }; 125 + 126 + #define rkisp1_has_feature(rkisp1, feature) \ 127 + ((rkisp1)->info->features & RKISP1_FEATURE_##feature) 126 128 127 129 /* 128 130 * struct rkisp1_info - Model-specific ISP Information ··· 241 229 struct rkisp1_buffer { 242 230 struct vb2_v4l2_buffer vb; 243 231 struct list_head queue; 244 - u32 buff_addr[VIDEO_MAX_PLANES]; 232 + dma_addr_t buff_addr[VIDEO_MAX_PLANES]; 245 233 }; 246 234 247 235 /* ··· 275 263 * handler to stop the streaming by waiting on the 'done' wait queue. 276 264 * If the irq handler is not called, the stream is stopped by the callback 277 265 * after timeout. 278 - * @sp_y_stride: the selfpath allows to configure a y stride that is longer than the image width. 266 + * @stride: the line stride for the first plane, in pixel units 279 267 * @buf.lock: lock to protect buf.queue 280 268 * @buf.queue: queued buffer list 281 269 * @buf.dummy: dummy space to store dropped data ··· 296 284 bool is_streaming; 297 285 bool is_stopping; 298 286 wait_queue_head_t done; 299 - unsigned int sp_y_stride; 287 + unsigned int stride; 300 288 struct { 301 289 /* protects queue, curr and next */ 302 290 spinlock_t lock; ··· 447 435 * @dev: a pointer to the struct device 448 436 * @clk_size: number of clocks 449 437 * @clks: array of clocks 438 + * @gasket: the gasket - i.MX8MP only 439 + * @gasket_id: the gasket ID (0 or 1) - i.MX8MP only 450 440 * @v4l2_dev: v4l2_device variable 451 441 * @media_dev: media_device variable 452 442 * @notifier: a notifier to register on the v4l2-async API to be notified on the sensor ··· 470 456 struct device *dev; 471 457 unsigned int clk_size; 472 458 struct clk_bulk_data clks[RKISP1_MAX_BUS_CLK]; 459 + struct regmap *gasket; 460 + unsigned int gasket_id; 473 461 struct v4l2_device v4l2_dev; 474 462 struct media_device media_dev; 475 463 struct v4l2_async_notifier notifier; ··· 539 523 * @index: index of the mbus info to fetch 540 524 */ 541 525 const struct rkisp1_mbus_info *rkisp1_mbus_info_get_by_index(unsigned int index); 526 + 527 + /* 528 + * rkisp1_path_count - Return the number of paths supported by the device 529 + * 530 + * Some devices only have a main path, while other device have both a main path 531 + * and a self path. This function returns the number of paths that this device 532 + * has, based on the feature flags. It should be used insted of checking 533 + * ARRAY_SIZE of capture_devs/resizer_devs. 534 + */ 535 + static inline unsigned int rkisp1_path_count(struct rkisp1_device *rkisp1) 536 + { 537 + return rkisp1_has_feature(rkisp1, SELF_PATH) ? 2 : 1; 538 + } 542 539 543 540 /* 544 541 * rkisp1_sd_adjust_crop_rect - adjust a rectangle to fit into another rectangle.
+62 -9
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c
··· 10 10 11 11 #include <linux/clk.h> 12 12 #include <linux/interrupt.h> 13 + #include <linux/mfd/syscon.h> 13 14 #include <linux/module.h> 14 15 #include <linux/of.h> 15 16 #include <linux/of_graph.h> ··· 208 207 switch (reg) { 209 208 case 0: 210 209 /* MIPI CSI-2 port */ 211 - if (!(rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)) { 210 + if (!rkisp1_has_feature(rkisp1, MIPI_CSI2)) { 212 211 dev_err(rkisp1->dev, 213 212 "internal CSI must be available for port 0\n"); 214 213 ret = -EINVAL; ··· 337 336 338 337 static int rkisp1_create_links(struct rkisp1_device *rkisp1) 339 338 { 339 + unsigned int dev_count = rkisp1_path_count(rkisp1); 340 340 unsigned int i; 341 341 int ret; 342 342 343 - if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) { 343 + if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) { 344 344 /* Link the CSI receiver to the ISP. */ 345 345 ret = media_create_pad_link(&rkisp1->csi.sd.entity, 346 346 RKISP1_CSI_PAD_SRC, ··· 353 351 } 354 352 355 353 /* create ISP->RSZ->CAP links */ 356 - for (i = 0; i < 2; i++) { 354 + for (i = 0; i < dev_count; i++) { 357 355 struct media_entity *resizer = 358 356 &rkisp1->resizer_devs[i].sd.entity; 359 357 struct media_entity *capture = ··· 393 391 394 392 static void rkisp1_entities_unregister(struct rkisp1_device *rkisp1) 395 393 { 396 - if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) 394 + if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) 397 395 rkisp1_csi_unregister(rkisp1); 398 396 rkisp1_params_unregister(rkisp1); 399 397 rkisp1_stats_unregister(rkisp1); ··· 426 424 if (ret) 427 425 goto error; 428 426 429 - if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) { 427 + if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) { 430 428 ret = rkisp1_csi_register(rkisp1); 431 429 if (ret) 432 430 goto error; ··· 485 483 .isrs = px30_isp_isrs, 486 484 .isr_size = ARRAY_SIZE(px30_isp_isrs), 487 485 .isp_ver = RKISP1_V12, 488 - .features = RKISP1_FEATURE_MIPI_CSI2, 486 + .features = RKISP1_FEATURE_MIPI_CSI2 487 + | RKISP1_FEATURE_SELF_PATH 488 + | RKISP1_FEATURE_DUAL_CROP, 489 489 }; 490 490 491 491 static const char * const rk3399_isp_clks[] = { ··· 506 502 .isrs = rk3399_isp_isrs, 507 503 .isr_size = ARRAY_SIZE(rk3399_isp_isrs), 508 504 .isp_ver = RKISP1_V10, 509 - .features = RKISP1_FEATURE_MIPI_CSI2, 505 + .features = RKISP1_FEATURE_MIPI_CSI2 506 + | RKISP1_FEATURE_SELF_PATH 507 + | RKISP1_FEATURE_DUAL_CROP, 508 + }; 509 + 510 + static const char * const imx8mp_isp_clks[] = { 511 + "isp", 512 + "hclk", 513 + "aclk", 514 + }; 515 + 516 + static const struct rkisp1_isr_data imx8mp_isp_isrs[] = { 517 + { NULL, rkisp1_isr, BIT(RKISP1_IRQ_ISP) | BIT(RKISP1_IRQ_MI) }, 518 + }; 519 + 520 + static const struct rkisp1_info imx8mp_isp_info = { 521 + .clks = imx8mp_isp_clks, 522 + .clk_size = ARRAY_SIZE(imx8mp_isp_clks), 523 + .isrs = imx8mp_isp_isrs, 524 + .isr_size = ARRAY_SIZE(imx8mp_isp_isrs), 525 + .isp_ver = RKISP1_V_IMX8MP, 526 + .features = RKISP1_FEATURE_MAIN_STRIDE 527 + | RKISP1_FEATURE_DMA_34BIT, 510 528 }; 511 529 512 530 static const struct of_device_id rkisp1_of_match[] = { ··· 539 513 { 540 514 .compatible = "rockchip,rk3399-cif-isp", 541 515 .data = &rk3399_isp_info, 516 + }, 517 + { 518 + .compatible = "fsl,imx8mp-isp", 519 + .data = &imx8mp_isp_info, 542 520 }, 543 521 {}, 544 522 }; ··· 555 525 struct rkisp1_device *rkisp1; 556 526 struct v4l2_device *v4l2_dev; 557 527 unsigned int i; 528 + u64 dma_mask; 558 529 int ret, irq; 559 530 u32 cif_id; 560 531 ··· 568 537 569 538 dev_set_drvdata(dev, rkisp1); 570 539 rkisp1->dev = dev; 540 + 541 + dma_mask = rkisp1_has_feature(rkisp1, DMA_34BIT) ? DMA_BIT_MASK(34) : 542 + DMA_BIT_MASK(32); 543 + 544 + ret = dma_set_mask_and_coherent(dev, dma_mask); 545 + if (ret) 546 + return ret; 571 547 572 548 mutex_init(&rkisp1->stream_lock); 573 549 ··· 611 573 if (ret) 612 574 return ret; 613 575 rkisp1->clk_size = info->clk_size; 576 + 577 + if (info->isp_ver == RKISP1_V_IMX8MP) { 578 + unsigned int id; 579 + 580 + rkisp1->gasket = syscon_regmap_lookup_by_phandle_args(dev->of_node, 581 + "fsl,blk-ctrl", 582 + 1, &id); 583 + if (IS_ERR(rkisp1->gasket)) { 584 + ret = PTR_ERR(rkisp1->gasket); 585 + dev_err(dev, "failed to get gasket: %d\n", ret); 586 + return ret; 587 + } 588 + 589 + rkisp1->gasket_id = id; 590 + } 614 591 615 592 pm_runtime_enable(&pdev->dev); 616 593 ··· 681 628 err_unreg_entities: 682 629 rkisp1_entities_unregister(rkisp1); 683 630 err_cleanup_csi: 684 - if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) 631 + if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) 685 632 rkisp1_csi_cleanup(rkisp1); 686 633 err_unreg_media_dev: 687 634 media_device_unregister(&rkisp1->media_dev); ··· 702 649 v4l2_async_nf_cleanup(&rkisp1->notifier); 703 650 704 651 rkisp1_entities_unregister(rkisp1); 705 - if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) 652 + if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) 706 653 rkisp1_csi_cleanup(rkisp1); 707 654 rkisp1_debug_cleanup(rkisp1); 708 655
+128 -3
drivers/media/platform/rockchip/rkisp1/rkisp1-isp.c
··· 10 10 11 11 #include <linux/iopoll.h> 12 12 #include <linux/pm_runtime.h> 13 + #include <linux/regmap.h> 13 14 #include <linux/videodev2.h> 14 15 #include <linux/vmalloc.h> 15 16 ··· 53 52 * | +---------------------------------------------------+ | 54 53 * +---------------------------------------------------------+ 55 54 */ 55 + 56 + /* ----------------------------------------------------------------------------- 57 + * Media block control (i.MX8MP only) 58 + */ 59 + 60 + #define ISP_DEWARP_CONTROL 0x0138 61 + 62 + #define ISP_DEWARP_CONTROL_MIPI_CSI2_HS_POLARITY BIT(22) 63 + #define ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_RISING (0 << 20) 64 + #define ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_NEGATIVE (1 << 20) 65 + #define ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_POSITIVE (2 << 20) 66 + #define ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_FALLING (3 << 20) 67 + #define ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_MASK GENMASK(21, 20) 68 + #define ISP_DEWARP_CONTROL_MIPI_ISP2_LEFT_JUST_MODE BIT(19) 69 + #define ISP_DEWARP_CONTROL_MIPI_ISP2_DATA_TYPE(dt) ((dt) << 13) 70 + #define ISP_DEWARP_CONTROL_MIPI_ISP2_DATA_TYPE_MASK GENMASK(18, 13) 71 + 72 + #define ISP_DEWARP_CONTROL_MIPI_CSI1_HS_POLARITY BIT(12) 73 + #define ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_RISING (0 << 10) 74 + #define ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_NEGATIVE (1 << 10) 75 + #define ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_POSITIVE (2 << 10) 76 + #define ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_FALLING (3 << 10) 77 + #define ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_MASK GENMASK(11, 10) 78 + #define ISP_DEWARP_CONTROL_MIPI_ISP1_LEFT_JUST_MODE BIT(9) 79 + #define ISP_DEWARP_CONTROL_MIPI_ISP1_DATA_TYPE(dt) ((dt) << 3) 80 + #define ISP_DEWARP_CONTROL_MIPI_ISP1_DATA_TYPE_MASK GENMASK(8, 3) 81 + 82 + #define ISP_DEWARP_CONTROL_GPR_ISP_1_DISABLE BIT(1) 83 + #define ISP_DEWARP_CONTROL_GPR_ISP_0_DISABLE BIT(0) 84 + 85 + static int rkisp1_gasket_enable(struct rkisp1_device *rkisp1, 86 + struct media_pad *source) 87 + { 88 + struct v4l2_subdev *source_sd; 89 + struct v4l2_mbus_frame_desc fd; 90 + unsigned int dt; 91 + u32 mask; 92 + u32 val; 93 + int ret; 94 + 95 + /* 96 + * Configure and enable the gasket with the CSI-2 data type. Set the 97 + * vsync polarity as active high, as that is what the ISP is configured 98 + * to expect in ISP_ACQ_PROP. Enable left justification, as the i.MX8MP 99 + * ISP has a 16-bit wide input and expects data to be left-aligned. 100 + */ 101 + 102 + source_sd = media_entity_to_v4l2_subdev(source->entity); 103 + ret = v4l2_subdev_call(source_sd, pad, get_frame_desc, 104 + source->index, &fd); 105 + if (ret) { 106 + dev_err(rkisp1->dev, 107 + "failed to get frame descriptor from '%s':%u: %d\n", 108 + source_sd->name, 0, ret); 109 + return ret; 110 + } 111 + 112 + if (fd.num_entries != 1) { 113 + dev_err(rkisp1->dev, "invalid frame descriptor for '%s':%u\n", 114 + source_sd->name, 0); 115 + return -EINVAL; 116 + } 117 + 118 + dt = fd.entry[0].bus.csi2.dt; 119 + 120 + if (rkisp1->gasket_id == 0) { 121 + mask = ISP_DEWARP_CONTROL_MIPI_CSI1_HS_POLARITY 122 + | ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_MASK 123 + | ISP_DEWARP_CONTROL_MIPI_ISP1_LEFT_JUST_MODE 124 + | ISP_DEWARP_CONTROL_MIPI_ISP1_DATA_TYPE_MASK 125 + | ISP_DEWARP_CONTROL_GPR_ISP_0_DISABLE; 126 + val = ISP_DEWARP_CONTROL_MIPI_CSI1_VS_SEL_POSITIVE 127 + | ISP_DEWARP_CONTROL_MIPI_ISP1_LEFT_JUST_MODE 128 + | ISP_DEWARP_CONTROL_MIPI_ISP1_DATA_TYPE(dt); 129 + } else { 130 + mask = ISP_DEWARP_CONTROL_MIPI_CSI2_HS_POLARITY 131 + | ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_MASK 132 + | ISP_DEWARP_CONTROL_MIPI_ISP2_LEFT_JUST_MODE 133 + | ISP_DEWARP_CONTROL_MIPI_ISP2_DATA_TYPE_MASK 134 + | ISP_DEWARP_CONTROL_GPR_ISP_1_DISABLE; 135 + val = ISP_DEWARP_CONTROL_MIPI_CSI2_VS_SEL_POSITIVE 136 + | ISP_DEWARP_CONTROL_MIPI_ISP2_LEFT_JUST_MODE 137 + | ISP_DEWARP_CONTROL_MIPI_ISP2_DATA_TYPE(dt); 138 + } 139 + 140 + regmap_update_bits(rkisp1->gasket, ISP_DEWARP_CONTROL, mask, val); 141 + 142 + return 0; 143 + } 144 + 145 + static void rkisp1_gasket_disable(struct rkisp1_device *rkisp1) 146 + { 147 + u32 mask; 148 + u32 val; 149 + 150 + if (rkisp1->gasket_id == 1) { 151 + mask = ISP_DEWARP_CONTROL_MIPI_ISP2_LEFT_JUST_MODE 152 + | ISP_DEWARP_CONTROL_MIPI_ISP2_DATA_TYPE_MASK 153 + | ISP_DEWARP_CONTROL_GPR_ISP_1_DISABLE; 154 + val = ISP_DEWARP_CONTROL_GPR_ISP_1_DISABLE; 155 + } else { 156 + mask = ISP_DEWARP_CONTROL_MIPI_ISP1_LEFT_JUST_MODE 157 + | ISP_DEWARP_CONTROL_MIPI_ISP1_DATA_TYPE_MASK 158 + | ISP_DEWARP_CONTROL_GPR_ISP_0_DISABLE; 159 + val = ISP_DEWARP_CONTROL_GPR_ISP_0_DISABLE; 160 + } 161 + 162 + regmap_update_bits(rkisp1->gasket, ISP_DEWARP_CONTROL, mask, val); 163 + } 56 164 57 165 /* ---------------------------------------------------------------------------- 58 166 * Camera Interface registers configurations ··· 401 291 RKISP1_CIF_VI_IRCL_MIPI_SW_RST | 402 292 RKISP1_CIF_VI_IRCL_ISP_SW_RST); 403 293 rkisp1_write(rkisp1, RKISP1_CIF_VI_IRCL, 0x0); 294 + 295 + if (rkisp1->info->isp_ver == RKISP1_V_IMX8MP) 296 + rkisp1_gasket_disable(rkisp1); 404 297 } 405 298 406 299 static void rkisp1_config_clk(struct rkisp1_isp *isp) ··· 428 315 } 429 316 } 430 317 431 - static void rkisp1_isp_start(struct rkisp1_isp *isp, 432 - struct v4l2_subdev_state *sd_state) 318 + static int rkisp1_isp_start(struct rkisp1_isp *isp, 319 + struct v4l2_subdev_state *sd_state, 320 + struct media_pad *source) 433 321 { 434 322 struct rkisp1_device *rkisp1 = isp->rkisp1; 435 323 const struct v4l2_mbus_framefmt *src_fmt; 436 324 const struct rkisp1_mbus_info *src_info; 437 325 u32 val; 326 + int ret; 438 327 439 328 rkisp1_config_clk(isp); 329 + 330 + if (rkisp1->info->isp_ver == RKISP1_V_IMX8MP) { 331 + ret = rkisp1_gasket_enable(rkisp1, source); 332 + if (ret) 333 + return ret; 334 + } 440 335 441 336 /* Activate ISP */ 442 337 val = rkisp1_read(rkisp1, RKISP1_CIF_ISP_CTRL); ··· 459 338 460 339 if (src_info->pixel_enc != V4L2_PIXEL_ENC_BAYER) 461 340 rkisp1_params_post_configure(&rkisp1->params); 341 + 342 + return 0; 462 343 } 463 344 464 345 /* ---------------------------------------------------------------------------- ··· 971 848 if (ret) 972 849 goto out_unlock; 973 850 974 - rkisp1_isp_start(isp, sd_state); 851 + ret = rkisp1_isp_start(isp, sd_state, source_pad); 852 + if (ret) 853 + goto out_unlock; 975 854 976 855 ret = v4l2_subdev_call(rkisp1->source, video, s_stream, true); 977 856 if (ret) {
+36
drivers/media/platform/rockchip/rkisp1/rkisp1-regs.h
··· 144 144 /* MI_INIT */ 145 145 #define RKISP1_CIF_MI_INIT_SKIP BIT(2) 146 146 #define RKISP1_CIF_MI_INIT_SOFT_UPD BIT(4) 147 + #define RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV400 (0 << 5) 148 + #define RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV420 (1 << 5) 149 + #define RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV422 (2 << 5) 150 + #define RKISP1_CIF_MI_INIT_MP_OUTPUT_YUV444 (3 << 5) 151 + #define RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW12 (4 << 5) 152 + #define RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW8 (5 << 5) 153 + #define RKISP1_CIF_MI_INIT_MP_OUTPUT_JPEG (6 << 5) 154 + #define RKISP1_CIF_MI_INIT_MP_OUTPUT_RAW10 (7 << 5) 155 + #define RKISP1_CIF_MI_INIT_MP_OUTPUT_MASK (15 << 5) 147 156 148 157 /* MI_CTRL_SHD */ 149 158 #define RKISP1_CIF_MI_CTRL_SHD_MP_IN_ENABLED BIT(0) ··· 215 206 #define RKISP1_CIF_MI_XTD_FMT_CTRL_MP_CB_CR_SWAP BIT(0) 216 207 #define RKISP1_CIF_MI_XTD_FMT_CTRL_SP_CB_CR_SWAP BIT(1) 217 208 #define RKISP1_CIF_MI_XTD_FMT_CTRL_DMA_CB_CR_SWAP BIT(2) 209 + 210 + /* MI_OUTPUT_ALIGN_FORMAT */ 211 + #define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_LSB_ALIGNMENT BIT(0) 212 + #define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_BYTES BIT(1) 213 + #define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_WORDS BIT(2) 214 + #define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_DWORDS BIT(3) 215 + #define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_BYTES BIT(4) 216 + #define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_WORDS BIT(5) 217 + #define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_DWORDS BIT(6) 218 + #define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_DMA_BYTE_SWAP_BYTES BIT(7) 219 + #define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_DMA_BYTE_SWAP_WORDS BIT(8) 220 + #define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_DMA_BYTE_SWAP_DWORDS BIT(9) 221 + 222 + /* MI_MP_OUTPUT_FIFO_SIZE */ 223 + #define RKISP1_CIF_MI_MP_OUTPUT_FIFO_SIZE_OUTPUT_FIFO_DEPTH_FULL (0 << 0) 224 + #define RKISP1_CIF_MI_MP_OUTPUT_FIFO_SIZE_OUTPUT_FIFO_DEPTH_HALF (1 << 0) 225 + #define RKISP1_CIF_MI_MP_OUTPUT_FIFO_SIZE_OUTPUT_FIFO_DEPTH_QUARTER (2 << 0) 226 + #define RKISP1_CIF_MI_MP_OUTPUT_FIFO_SIZE_OUTPUT_FIFO_DEPTH_EIGHT (3 << 0) 218 227 219 228 /* VI_CCL */ 220 229 #define RKISP1_CIF_CCL_CIF_CLK_DIS BIT(2) ··· 1027 1000 #define RKISP1_CIF_MI_SP_CB_BASE_AD_INIT2 (RKISP1_CIF_MI_BASE + 0x00000140) 1028 1001 #define RKISP1_CIF_MI_SP_CR_BASE_AD_INIT2 (RKISP1_CIF_MI_BASE + 0x00000144) 1029 1002 #define RKISP1_CIF_MI_XTD_FORMAT_CTRL (RKISP1_CIF_MI_BASE + 0x00000148) 1003 + #define RKISP1_CIF_MI_MP_HANDSHAKE_0 (RKISP1_CIF_MI_BASE + 0x0000014C) 1004 + #define RKISP1_CIF_MI_MP_Y_LLENGTH (RKISP1_CIF_MI_BASE + 0x00000150) 1005 + #define RKISP1_CIF_MI_MP_Y_SLICE_OFFSET (RKISP1_CIF_MI_BASE + 0x00000154) 1006 + #define RKISP1_CIF_MI_MP_C_SLICE_OFFSET (RKISP1_CIF_MI_BASE + 0x00000158) 1007 + #define RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT (RKISP1_CIF_MI_BASE + 0x0000015C) 1008 + #define RKISP1_CIF_MI_MP_OUTPUT_FIFO_SIZE (RKISP1_CIF_MI_BASE + 0x00000160) 1009 + #define RKISP1_CIF_MI_MP_Y_PIC_WIDTH (RKISP1_CIF_MI_BASE + 0x00000164) 1010 + #define RKISP1_CIF_MI_MP_Y_PIC_HEIGHT (RKISP1_CIF_MI_BASE + 0x00000168) 1011 + #define RKISP1_CIF_MI_MP_Y_PIC_SIZE (RKISP1_CIF_MI_BASE + 0x0000016C) 1030 1012 1031 1013 #define RKISP1_CIF_SMIA_BASE 0x00001a00 1032 1014 #define RKISP1_CIF_SMIA_CTRL (RKISP1_CIF_SMIA_BASE + 0x00000000)
+12 -7
drivers/media/platform/rockchip/rkisp1/rkisp1-resizer.c
··· 444 444 sink_fmt = v4l2_subdev_state_get_format(sd_state, RKISP1_RSZ_PAD_SINK); 445 445 sink_crop = v4l2_subdev_state_get_crop(sd_state, RKISP1_RSZ_PAD_SINK); 446 446 447 - /* Not crop for MP bayer raw data */ 447 + /* Not crop for MP bayer raw data, or for devices lacking dual crop. */ 448 448 mbus_info = rkisp1_mbus_info_get_by_code(sink_fmt->code); 449 449 450 - if (rsz->id == RKISP1_MAINPATH && 451 - mbus_info->pixel_enc == V4L2_PIXEL_ENC_BAYER) { 450 + if ((rsz->id == RKISP1_MAINPATH && 451 + mbus_info->pixel_enc == V4L2_PIXEL_ENC_BAYER) || 452 + !rkisp1_has_feature(rsz->rkisp1, DUAL_CROP)) { 452 453 sink_crop->left = 0; 453 454 sink_crop->top = 0; 454 455 sink_crop->width = sink_fmt->width; ··· 632 631 struct rkisp1_device *rkisp1 = rsz->rkisp1; 633 632 struct rkisp1_capture *other = &rkisp1->capture_devs[rsz->id ^ 1]; 634 633 enum rkisp1_shadow_regs_when when = RKISP1_SHADOW_REGS_SYNC; 634 + bool has_self_path = rkisp1_has_feature(rkisp1, SELF_PATH); 635 635 struct v4l2_subdev_state *sd_state; 636 636 637 637 if (!enable) { 638 - rkisp1_dcrop_disable(rsz, RKISP1_SHADOW_REGS_ASYNC); 638 + if (rkisp1_has_feature(rkisp1, DUAL_CROP)) 639 + rkisp1_dcrop_disable(rsz, RKISP1_SHADOW_REGS_ASYNC); 639 640 rkisp1_rsz_disable(rsz, RKISP1_SHADOW_REGS_ASYNC); 640 641 return 0; 641 642 } 642 643 643 - if (other->is_streaming) 644 + if (has_self_path && other->is_streaming) 644 645 when = RKISP1_SHADOW_REGS_ASYNC; 645 646 646 647 sd_state = v4l2_subdev_lock_and_get_active_state(sd); 647 648 648 649 rkisp1_rsz_config(rsz, sd_state, when); 649 - rkisp1_dcrop_config(rsz, sd_state); 650 + if (rkisp1_has_feature(rkisp1, DUAL_CROP)) 651 + rkisp1_dcrop_config(rsz, sd_state); 650 652 651 653 v4l2_subdev_unlock_state(sd_state); 652 654 ··· 735 731 736 732 int rkisp1_resizer_devs_register(struct rkisp1_device *rkisp1) 737 733 { 734 + unsigned int dev_count = rkisp1_path_count(rkisp1); 738 735 unsigned int i; 739 736 int ret; 740 737 741 - for (i = 0; i < ARRAY_SIZE(rkisp1->resizer_devs); i++) { 738 + for (i = 0; i < dev_count; i++) { 742 739 struct rkisp1_resizer *rsz = &rkisp1->resizer_devs[i]; 743 740 744 741 rsz->rkisp1 = rkisp1;
+27 -23
include/uapi/linux/rkisp1-config.h
··· 175 175 /** 176 176 * enum rkisp1_cif_isp_version - ISP variants 177 177 * 178 - * @RKISP1_V10: used at least in rk3288 and rk3399 179 - * @RKISP1_V11: declared in the original vendor code, but not used 180 - * @RKISP1_V12: used at least in rk3326 and px30 181 - * @RKISP1_V13: used at least in rk1808 178 + * @RKISP1_V10: Used at least in RK3288 and RK3399. 179 + * @RKISP1_V11: Declared in the original vendor code, but not used. Same number 180 + * of entries in grids and histogram as v10. 181 + * @RKISP1_V12: Used at least in RK3326 and PX30. 182 + * @RKISP1_V13: Used at least in RK1808. Same number of entries in grids and 183 + * histogram as v12. 184 + * @RKISP1_V_IMX8MP: Used in at least i.MX8MP. Same number of entries in grids 185 + * and histogram as v10. 182 186 */ 183 187 enum rkisp1_cif_isp_version { 184 188 RKISP1_V10 = 10, 185 189 RKISP1_V11, 186 190 RKISP1_V12, 187 191 RKISP1_V13, 192 + RKISP1_V_IMX8MP, 188 193 }; 189 194 190 195 enum rkisp1_cif_isp_histogram_mode { ··· 589 584 * as is reported by the hw_revision field of the struct media_device_info 590 585 * that is returned by ioctl MEDIA_IOC_DEVICE_INFO. 591 586 * 592 - * Versions <= V11 have RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10 593 - * entries, versions >= V12 have RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12 594 - * entries. RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES is equal to the maximum 595 - * of the two. 587 + * V10 has RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10 entries, V12 has 588 + * RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12 entries. 589 + * RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES is equal to the maximum of the two. 596 590 */ 597 591 struct rkisp1_cif_isp_goc_config { 598 592 __u32 mode; ··· 611 607 * as is reported by the hw_revision field of the struct media_device_info 612 608 * that is returned by ioctl MEDIA_IOC_DEVICE_INFO. 613 609 * 614 - * Versions <= V11 have RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 615 - * entries, versions >= V12 have RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12 616 - * entries. RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE is equal to the maximum 617 - * of the two. 610 + * V10 has RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 entries, V12 has 611 + * RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12 entries. 612 + * RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE is equal to the maximum of the 613 + * two. 618 614 */ 619 615 struct rkisp1_cif_isp_hst_config { 620 616 __u32 mode; ··· 906 902 * as is reported by the hw_revision field of the struct media_device_info 907 903 * that is returned by ioctl MEDIA_IOC_DEVICE_INFO. 908 904 * 909 - * Versions <= V11 have RKISP1_CIF_ISP_AE_MEAN_MAX_V10 entries, 910 - * versions >= V12 have RKISP1_CIF_ISP_AE_MEAN_MAX_V12 entries. 911 - * RKISP1_CIF_ISP_AE_MEAN_MAX is equal to the maximum of the two. 905 + * V10 has RKISP1_CIF_ISP_AE_MEAN_MAX_V10 entries, V12 has 906 + * RKISP1_CIF_ISP_AE_MEAN_MAX_V12 entries. RKISP1_CIF_ISP_AE_MEAN_MAX is equal 907 + * to the maximum of the two. 912 908 * 913 909 * Image is divided into 5x5 blocks on V10 and 9x9 blocks on V12. 914 910 */ ··· 948 944 * integer part. 949 945 * 950 946 * The window of the measurements area is divided to 5x5 sub-windows for 951 - * V10/V11 and to 9x9 sub-windows for V12. The histogram is then computed for 952 - * each sub-window independently and the final result is a weighted average of 953 - * the histogram measurements on all sub-windows. The window of the 954 - * measurements area and the weight of each sub-window are configurable using 947 + * V10 and to 9x9 sub-windows for V12. The histogram is then computed for each 948 + * sub-window independently and the final result is a weighted average of the 949 + * histogram measurements on all sub-windows. The window of the measurements 950 + * area and the weight of each sub-window are configurable using 955 951 * struct @rkisp1_cif_isp_hst_config. 956 952 * 957 - * The histogram contains 16 bins in V10/V11 and 32 bins in V12/V13. 953 + * The histogram contains 16 bins in V10 and 32 bins in V12. 958 954 * 959 955 * The number of entries of @hist_bins depends on the hardware revision 960 956 * as is reported by the hw_revision field of the struct media_device_info 961 957 * that is returned by ioctl MEDIA_IOC_DEVICE_INFO. 962 958 * 963 - * Versions <= V11 have RKISP1_CIF_ISP_HIST_BIN_N_MAX_V10 entries, 964 - * versions >= V12 have RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12 entries. 965 - * RKISP1_CIF_ISP_HIST_BIN_N_MAX is equal to the maximum of the two. 959 + * V10 has RKISP1_CIF_ISP_HIST_BIN_N_MAX_V10 entries, V12 has 960 + * RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12 entries. RKISP1_CIF_ISP_HIST_BIN_N_MAX is 961 + * equal to the maximum of the two. 966 962 */ 967 963 struct rkisp1_cif_isp_hist_stat { 968 964 __u32 hist_bins[RKISP1_CIF_ISP_HIST_BIN_N_MAX];