1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright 2019-2023 NXP 4 */ 5 6 #include <linux/regmap.h> 7 8 #include <media/mipi-csi2.h> 9 10 #include "imx8-isi-core.h" 11 12 /* ----------------------------------------------------------------------------- 13 * i.MX8MN and i.MX8MP gasket 14 */ 15 16 #define GASKET_BASE(n) (0x0060 + (n) * 0x30) 17 18 #define GASKET_CTRL 0x0000 19 #define GASKET_CTRL_DATA_TYPE(dt) ((dt) << 8) 20 #define GASKET_CTRL_DATA_TYPE_MASK (0x3f << 8) 21 #define GASKET_CTRL_DUAL_COMP_ENABLE BIT(1) 22 #define GASKET_CTRL_ENABLE BIT(0) 23 24 #define GASKET_HSIZE 0x0004 25 #define GASKET_VSIZE 0x0008 26 27 static void mxc_imx8_gasket_enable(struct mxc_isi_dev *isi, 28 const struct v4l2_mbus_frame_desc *fd, 29 const struct v4l2_mbus_framefmt *fmt, 30 const unsigned int port) 31 { 32 u32 val; 33 34 regmap_write(isi->gasket, GASKET_BASE(port) + GASKET_HSIZE, fmt->width); 35 regmap_write(isi->gasket, GASKET_BASE(port) + GASKET_VSIZE, fmt->height); 36 37 val = GASKET_CTRL_DATA_TYPE(fd->entry[0].bus.csi2.dt); 38 if (fd->entry[0].bus.csi2.dt == MIPI_CSI2_DT_YUV422_8B) 39 val |= GASKET_CTRL_DUAL_COMP_ENABLE; 40 41 val |= GASKET_CTRL_ENABLE; 42 regmap_write(isi->gasket, GASKET_BASE(port) + GASKET_CTRL, val); 43 } 44 45 static void mxc_imx8_gasket_disable(struct mxc_isi_dev *isi, 46 const unsigned int port) 47 { 48 regmap_write(isi->gasket, GASKET_BASE(port) + GASKET_CTRL, 0); 49 } 50 51 const struct mxc_gasket_ops mxc_imx8_gasket_ops = { 52 .enable = mxc_imx8_gasket_enable, 53 .disable = mxc_imx8_gasket_disable, 54 }; 55 56 /* ----------------------------------------------------------------------------- 57 * i.MX93 gasket 58 */ 59 60 #define DISP_MIX_CAMERA_MUX 0x30 61 #define DISP_MIX_CAMERA_MUX_DATA_TYPE(x) (((x) & 0x3f) << 3) 62 #define DISP_MIX_CAMERA_MUX_GASKET_ENABLE BIT(16) 63 64 static void mxc_imx93_gasket_enable(struct mxc_isi_dev *isi, 65 const struct v4l2_mbus_frame_desc *fd, 66 const struct v4l2_mbus_framefmt *fmt, 67 const unsigned int port) 68 { 69 u32 val; 70 71 val = DISP_MIX_CAMERA_MUX_DATA_TYPE(fd->entry[0].bus.csi2.dt); 72 val |= DISP_MIX_CAMERA_MUX_GASKET_ENABLE; 73 regmap_write(isi->gasket, DISP_MIX_CAMERA_MUX, val); 74 } 75 76 static void mxc_imx93_gasket_disable(struct mxc_isi_dev *isi, 77 unsigned int port) 78 { 79 regmap_write(isi->gasket, DISP_MIX_CAMERA_MUX, 0); 80 } 81 82 const struct mxc_gasket_ops mxc_imx93_gasket_ops = { 83 .enable = mxc_imx93_gasket_enable, 84 .disable = mxc_imx93_gasket_disable, 85 }; 86