| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | // SPDX-License-Identifier: GPL-2.0+
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (C) 2020 Amarula Solutions(India) | 
					
						
							|  |  |  |  * Author: Jagan Teki <jagan@amarulasolutions.com> | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-19 20:23:24 +05:30
										 |  |  | #include <drm/drm_atomic_helper.h>
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | #include <drm/drm_of.h>
 | 
					
						
							|  |  |  | #include <drm/drm_print.h>
 | 
					
						
							|  |  |  | #include <drm/drm_mipi_dsi.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/delay.h>
 | 
					
						
							|  |  |  | #include <linux/gpio/consumer.h>
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | #include <linux/i2c.h>
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | #include <linux/module.h>
 | 
					
						
							|  |  |  | #include <linux/of_device.h>
 | 
					
						
							|  |  |  | #include <linux/regulator/consumer.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:04:59 +02:00
										 |  |  | #define VENDOR_ID		0x00
 | 
					
						
							|  |  |  | #define DEVICE_ID_H		0x01
 | 
					
						
							|  |  |  | #define DEVICE_ID_L		0x02
 | 
					
						
							|  |  |  | #define VERSION_ID		0x03
 | 
					
						
							|  |  |  | #define FIRMWARE_VERSION	0x08
 | 
					
						
							|  |  |  | #define CONFIG_FINISH		0x09
 | 
					
						
							|  |  |  | #define PD_CTRL(n)		(0x0a + ((n) & 0x3)) /* 0..3 */
 | 
					
						
							|  |  |  | #define RST_CTRL(n)		(0x0e + ((n) & 0x1)) /* 0..1 */
 | 
					
						
							|  |  |  | #define SYS_CTRL(n)		(0x10 + ((n) & 0x7)) /* 0..4 */
 | 
					
						
							|  |  |  | #define RGB_DRV(n)		(0x18 + ((n) & 0x3)) /* 0..3 */
 | 
					
						
							|  |  |  | #define RGB_DLY(n)		(0x1c + ((n) & 0x1)) /* 0..1 */
 | 
					
						
							|  |  |  | #define RGB_TEST_CTRL		0x1e
 | 
					
						
							|  |  |  | #define ATE_PLL_EN		0x1f
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | #define HACTIVE_LI		0x20
 | 
					
						
							|  |  |  | #define VACTIVE_LI		0x21
 | 
					
						
							|  |  |  | #define VACTIVE_HACTIVE_HI	0x22
 | 
					
						
							|  |  |  | #define HFP_LI			0x23
 | 
					
						
							|  |  |  | #define HSYNC_LI		0x24
 | 
					
						
							|  |  |  | #define HBP_LI			0x25
 | 
					
						
							|  |  |  | #define HFP_HSW_HBP_HI		0x26
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:00 +02:00
										 |  |  | #define HFP_HSW_HBP_HI_HFP(n)		(((n) & 0x300) >> 4)
 | 
					
						
							|  |  |  | #define HFP_HSW_HBP_HI_HS(n)		(((n) & 0x300) >> 6)
 | 
					
						
							|  |  |  | #define HFP_HSW_HBP_HI_HBP(n)		(((n) & 0x300) >> 8)
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | #define VFP			0x27
 | 
					
						
							|  |  |  | #define VSYNC			0x28
 | 
					
						
							|  |  |  | #define VBP			0x29
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:04:59 +02:00
										 |  |  | #define BIST_POL		0x2a
 | 
					
						
							|  |  |  | #define BIST_POL_BIST_MODE(n)		(((n) & 0xf) << 4)
 | 
					
						
							|  |  |  | #define BIST_POL_BIST_GEN		BIT(3)
 | 
					
						
							|  |  |  | #define BIST_POL_HSYNC_POL		BIT(2)
 | 
					
						
							|  |  |  | #define BIST_POL_VSYNC_POL		BIT(1)
 | 
					
						
							|  |  |  | #define BIST_POL_DE_POL			BIT(0)
 | 
					
						
							|  |  |  | #define BIST_RED		0x2b
 | 
					
						
							|  |  |  | #define BIST_GREEN		0x2c
 | 
					
						
							|  |  |  | #define BIST_BLUE		0x2d
 | 
					
						
							|  |  |  | #define BIST_CHESS_X		0x2e
 | 
					
						
							|  |  |  | #define BIST_CHESS_Y		0x2f
 | 
					
						
							|  |  |  | #define BIST_CHESS_XY_H		0x30
 | 
					
						
							|  |  |  | #define BIST_FRAME_TIME_L	0x31
 | 
					
						
							|  |  |  | #define BIST_FRAME_TIME_H	0x32
 | 
					
						
							|  |  |  | #define FIFO_MAX_ADDR_LOW	0x33
 | 
					
						
							|  |  |  | #define SYNC_EVENT_DLY		0x34
 | 
					
						
							|  |  |  | #define HSW_MIN			0x35
 | 
					
						
							|  |  |  | #define HFP_MIN			0x36
 | 
					
						
							|  |  |  | #define LOGIC_RST_NUM		0x37
 | 
					
						
							|  |  |  | #define OSC_CTRL(n)		(0x48 + ((n) & 0x7)) /* 0..5 */
 | 
					
						
							|  |  |  | #define BG_CTRL			0x4e
 | 
					
						
							|  |  |  | #define LDO_PLL			0x4f
 | 
					
						
							|  |  |  | #define PLL_CTRL(n)		(0x50 + ((n) & 0xf)) /* 0..15 */
 | 
					
						
							|  |  |  | #define PLL_CTRL_6_EXTERNAL		0x90
 | 
					
						
							|  |  |  | #define PLL_CTRL_6_MIPI_CLK		0x92
 | 
					
						
							|  |  |  | #define PLL_CTRL_6_INTERNAL		0x93
 | 
					
						
							|  |  |  | #define PLL_REM(n)		(0x60 + ((n) & 0x3)) /* 0..2 */
 | 
					
						
							|  |  |  | #define PLL_DIV(n)		(0x63 + ((n) & 0x3)) /* 0..2 */
 | 
					
						
							|  |  |  | #define PLL_FRAC(n)		(0x66 + ((n) & 0x3)) /* 0..2 */
 | 
					
						
							|  |  |  | #define PLL_INT(n)		(0x69 + ((n) & 0x1)) /* 0..1 */
 | 
					
						
							|  |  |  | #define PLL_REF_DIV		0x6b
 | 
					
						
							|  |  |  | #define PLL_REF_DIV_P(n)		((n) & 0xf)
 | 
					
						
							|  |  |  | #define PLL_REF_DIV_Pe			BIT(4)
 | 
					
						
							|  |  |  | #define PLL_REF_DIV_S(n)		(((n) & 0x7) << 5)
 | 
					
						
							|  |  |  | #define PLL_SSC_P(n)		(0x6c + ((n) & 0x3)) /* 0..2 */
 | 
					
						
							|  |  |  | #define PLL_SSC_STEP(n)		(0x6f + ((n) & 0x3)) /* 0..2 */
 | 
					
						
							|  |  |  | #define PLL_SSC_OFFSET(n)	(0x72 + ((n) & 0x3)) /* 0..3 */
 | 
					
						
							|  |  |  | #define GPIO_OEN		0x79
 | 
					
						
							|  |  |  | #define MIPI_CFG_PW		0x7a
 | 
					
						
							|  |  |  | #define MIPI_CFG_PW_CONFIG_DSI		0xc1
 | 
					
						
							|  |  |  | #define MIPI_CFG_PW_CONFIG_I2C		0x3e
 | 
					
						
							|  |  |  | #define GPIO_SEL(n)		(0x7b + ((n) & 0x1)) /* 0..1 */
 | 
					
						
							|  |  |  | #define IRQ_SEL			0x7d
 | 
					
						
							|  |  |  | #define DBG_SEL			0x7e
 | 
					
						
							|  |  |  | #define DBG_SIGNAL		0x7f
 | 
					
						
							|  |  |  | #define MIPI_ERR_VECTOR_L	0x80
 | 
					
						
							|  |  |  | #define MIPI_ERR_VECTOR_H	0x81
 | 
					
						
							|  |  |  | #define MIPI_ERR_VECTOR_EN_L	0x82
 | 
					
						
							|  |  |  | #define MIPI_ERR_VECTOR_EN_H	0x83
 | 
					
						
							|  |  |  | #define MIPI_MAX_SIZE_L		0x84
 | 
					
						
							|  |  |  | #define MIPI_MAX_SIZE_H		0x85
 | 
					
						
							|  |  |  | #define DSI_CTRL		0x86
 | 
					
						
							|  |  |  | #define DSI_CTRL_UNKNOWN		0x28
 | 
					
						
							|  |  |  | #define DSI_CTRL_DSI_LANES(n)		((n) & 0x3)
 | 
					
						
							|  |  |  | #define MIPI_PN_SWAP		0x87
 | 
					
						
							|  |  |  | #define MIPI_PN_SWAP_CLK		BIT(4)
 | 
					
						
							|  |  |  | #define MIPI_PN_SWAP_D(n)		BIT((n) & 0x3)
 | 
					
						
							|  |  |  | #define MIPI_SOT_SYNC_BIT_(n)	(0x88 + ((n) & 0x1)) /* 0..1 */
 | 
					
						
							|  |  |  | #define MIPI_ULPS_CTRL		0x8a
 | 
					
						
							|  |  |  | #define MIPI_CLK_CHK_VAR	0x8e
 | 
					
						
							|  |  |  | #define MIPI_CLK_CHK_INI	0x8f
 | 
					
						
							|  |  |  | #define MIPI_T_TERM_EN		0x90
 | 
					
						
							|  |  |  | #define MIPI_T_HS_SETTLE	0x91
 | 
					
						
							|  |  |  | #define MIPI_T_TA_SURE_PRE	0x92
 | 
					
						
							|  |  |  | #define MIPI_T_LPX_SET		0x94
 | 
					
						
							|  |  |  | #define MIPI_T_CLK_MISS		0x95
 | 
					
						
							|  |  |  | #define MIPI_INIT_TIME_L	0x96
 | 
					
						
							|  |  |  | #define MIPI_INIT_TIME_H	0x97
 | 
					
						
							|  |  |  | #define MIPI_T_CLK_TERM_EN	0x99
 | 
					
						
							|  |  |  | #define MIPI_T_CLK_SETTLE	0x9a
 | 
					
						
							|  |  |  | #define MIPI_TO_HS_RX_L		0x9e
 | 
					
						
							|  |  |  | #define MIPI_TO_HS_RX_H		0x9f
 | 
					
						
							|  |  |  | #define MIPI_PHY_(n)		(0xa0 + ((n) & 0x7)) /* 0..5 */
 | 
					
						
							|  |  |  | #define MIPI_PD_RX		0xb0
 | 
					
						
							|  |  |  | #define MIPI_PD_TERM		0xb1
 | 
					
						
							|  |  |  | #define MIPI_PD_HSRX		0xb2
 | 
					
						
							|  |  |  | #define MIPI_PD_LPTX		0xb3
 | 
					
						
							|  |  |  | #define MIPI_PD_LPRX		0xb4
 | 
					
						
							|  |  |  | #define MIPI_PD_CK_LANE		0xb5
 | 
					
						
							|  |  |  | #define MIPI_FORCE_0		0xb6
 | 
					
						
							|  |  |  | #define MIPI_RST_CTRL		0xb7
 | 
					
						
							|  |  |  | #define MIPI_RST_NUM		0xb8
 | 
					
						
							|  |  |  | #define MIPI_DBG_SET_(n)	(0xc0 + ((n) & 0xf)) /* 0..9 */
 | 
					
						
							|  |  |  | #define MIPI_DBG_SEL		0xe0
 | 
					
						
							|  |  |  | #define MIPI_DBG_DATA		0xe1
 | 
					
						
							|  |  |  | #define MIPI_ATE_TEST_SEL	0xe2
 | 
					
						
							|  |  |  | #define MIPI_ATE_STATUS_(n)	(0xe3 + ((n) & 0x1)) /* 0..1 */
 | 
					
						
							|  |  |  | #define MIPI_ATE_STATUS_1	0xe4
 | 
					
						
							|  |  |  | #define ICN6211_MAX_REGISTER	MIPI_ATE_STATUS(1)
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | struct chipone { | 
					
						
							|  |  |  | 	struct device *dev; | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | 	struct i2c_client *client; | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 	struct drm_bridge bridge; | 
					
						
							| 
									
										
										
										
											2021-11-19 20:23:25 +05:30
										 |  |  | 	struct drm_display_mode mode; | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 	struct drm_bridge *panel_bridge; | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:02 +02:00
										 |  |  | 	struct mipi_dsi_device *dsi; | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 	struct gpio_desc *enable_gpio; | 
					
						
							|  |  |  | 	struct regulator *vdd1; | 
					
						
							|  |  |  | 	struct regulator *vdd2; | 
					
						
							|  |  |  | 	struct regulator *vdd3; | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | 	bool interface_i2c; | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline struct chipone *bridge_to_chipone(struct drm_bridge *bridge) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return container_of(bridge, struct chipone, bridge); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:09 +02:00
										 |  |  | static void chipone_readb(struct chipone *icn, u8 reg, u8 *val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (icn->interface_i2c) | 
					
						
							|  |  |  | 		*val = i2c_smbus_read_byte_data(icn->client, reg); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		mipi_dsi_generic_read(icn->dsi, (u8[]){reg, 1}, 2, val, 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | static int chipone_writeb(struct chipone *icn, u8 reg, u8 val) | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	if (icn->interface_i2c) | 
					
						
							|  |  |  | 		return i2c_smbus_write_byte_data(icn->client, reg, val); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return mipi_dsi_generic_write(icn->dsi, (u8[]){reg, val}, 2); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:02 +02:00
										 |  |  | static void chipone_configure_pll(struct chipone *icn, | 
					
						
							|  |  |  | 				  const struct drm_display_mode *mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned int best_p = 0, best_m = 0, best_s = 0; | 
					
						
							|  |  |  | 	unsigned int delta, min_delta = 0xffffffff; | 
					
						
							|  |  |  | 	unsigned int freq_p, freq_s, freq_out; | 
					
						
							|  |  |  | 	unsigned int p_min, p_max; | 
					
						
							|  |  |  | 	unsigned int p, m, s; | 
					
						
							|  |  |  | 	unsigned int fin; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * DSI clock lane frequency (input into PLL) is calculated as: | 
					
						
							|  |  |  | 	 *  DSI_CLK = mode clock * bpp / dsi_data_lanes / 2 | 
					
						
							|  |  |  | 	 * the 2 is there because the bus is DDR. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * DPI pixel clock frequency (output from PLL) is mode clock. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * The chip contains fractional PLL which works as follows: | 
					
						
							|  |  |  | 	 *  DPI_CLK = ((DSI_CLK / P) * M) / S | 
					
						
							|  |  |  | 	 * P is pre-divider, register PLL_REF_DIV[3:0] is 2^(n+1) divider | 
					
						
							|  |  |  | 	 *                   register PLL_REF_DIV[4] is extra 1:2 divider | 
					
						
							|  |  |  | 	 * M is integer multiplier, register PLL_INT(0) is multiplier | 
					
						
							|  |  |  | 	 * S is post-divider, register PLL_REF_DIV[7:5] is 2^(n+1) divider | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * It seems the PLL input clock after applying P pre-divider have | 
					
						
							|  |  |  | 	 * to be lower than 20 MHz. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	fin = mode->clock * mipi_dsi_pixel_format_to_bpp(icn->dsi->format) / | 
					
						
							|  |  |  | 	      icn->dsi->lanes / 2; /* in kHz */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Minimum value of P predivider for PLL input in 5..20 MHz */ | 
					
						
							|  |  |  | 	p_min = ffs(fin / 20000); | 
					
						
							|  |  |  | 	p_max = (fls(fin / 5000) - 1) & 0x1f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (p = p_min; p < p_max; p++) {	/* PLL_REF_DIV[4,3:0] */ | 
					
						
							|  |  |  | 		freq_p = fin / BIT(p + 1); | 
					
						
							|  |  |  | 		if (freq_p == 0)		/* Divider too high */ | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (s = 0; s < 0x7; s++) {	/* PLL_REF_DIV[7:5] */ | 
					
						
							|  |  |  | 			freq_s = freq_p / BIT(s + 1); | 
					
						
							|  |  |  | 			if (freq_s == 0)	/* Divider too high */ | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			m = mode->clock / freq_s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* Multiplier is 8 bit */ | 
					
						
							|  |  |  | 			if (m > 0xff) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* Limit PLL VCO frequency to 1 GHz */ | 
					
						
							|  |  |  | 			freq_out = (fin * m) / BIT(p + 1); | 
					
						
							|  |  |  | 			if (freq_out > 1000000) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* Apply post-divider */ | 
					
						
							|  |  |  | 			freq_out /= BIT(s + 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			delta = abs(mode->clock - freq_out); | 
					
						
							|  |  |  | 			if (delta < min_delta) { | 
					
						
							|  |  |  | 				best_p = p; | 
					
						
							|  |  |  | 				best_m = m; | 
					
						
							|  |  |  | 				best_s = s; | 
					
						
							|  |  |  | 				min_delta = delta; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dev_dbg(icn->dev, | 
					
						
							|  |  |  | 		"PLL: P[3:0]=2^%d P[4]=2*%d M=%d S[7:5]=2^%d delta=%d => DSI f_in=%d kHz ; DPI f_out=%ld kHz\n", | 
					
						
							|  |  |  | 		best_p, !!best_p, best_m, best_s + 1, min_delta, fin, | 
					
						
							|  |  |  | 		(fin * best_m) / BIT(best_p + best_s + 2)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Clock source selection fixed to MIPI DSI clock lane */ | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	chipone_writeb(icn, PLL_CTRL(6), PLL_CTRL_6_MIPI_CLK); | 
					
						
							|  |  |  | 	chipone_writeb(icn, PLL_REF_DIV, | 
					
						
							|  |  |  | 		       /* Prefer /2 pre-divider */ | 
					
						
							|  |  |  | 		       (best_p ? PLL_REF_DIV_Pe : 0) | | 
					
						
							|  |  |  | 		       PLL_REF_DIV_P(best_p) | PLL_REF_DIV_S(best_s)); | 
					
						
							|  |  |  | 	chipone_writeb(icn, PLL_INT(0), best_m); | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-19 20:23:24 +05:30
										 |  |  | static void chipone_atomic_enable(struct drm_bridge *bridge, | 
					
						
							|  |  |  | 				  struct drm_bridge_state *old_bridge_state) | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | { | 
					
						
							|  |  |  | 	struct chipone *icn = bridge_to_chipone(bridge); | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:01 +02:00
										 |  |  | 	struct drm_atomic_state *state = old_bridge_state->base.state; | 
					
						
							| 
									
										
										
										
											2021-11-19 20:23:25 +05:30
										 |  |  | 	struct drm_display_mode *mode = &icn->mode; | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:01 +02:00
										 |  |  | 	const struct drm_bridge_state *bridge_state; | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:00 +02:00
										 |  |  | 	u16 hfp, hbp, hsync; | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:01 +02:00
										 |  |  | 	u32 bus_flags; | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:09 +02:00
										 |  |  | 	u8 pol, id[4]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	chipone_readb(icn, VENDOR_ID, id); | 
					
						
							|  |  |  | 	chipone_readb(icn, DEVICE_ID_H, id + 1); | 
					
						
							|  |  |  | 	chipone_readb(icn, DEVICE_ID_L, id + 2); | 
					
						
							|  |  |  | 	chipone_readb(icn, VERSION_ID, id + 3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dev_dbg(icn->dev, | 
					
						
							|  |  |  | 		"Chip IDs: Vendor=0x%02x Device=0x%02x:0x%02x Version=0x%02x\n", | 
					
						
							|  |  |  | 		id[0], id[1], id[2], id[3]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (id[0] != 0xc1 || id[1] != 0x62 || id[2] != 0x11) { | 
					
						
							|  |  |  | 		dev_dbg(icn->dev, "Invalid Chip IDs, aborting configuration\n"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Get the DPI flags from the bridge state. */ | 
					
						
							|  |  |  | 	bridge_state = drm_atomic_get_new_bridge_state(state, bridge); | 
					
						
							|  |  |  | 	bus_flags = bridge_state->output_bus_cfg.flags; | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | 	if (icn->interface_i2c) | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 		chipone_writeb(icn, MIPI_CFG_PW, MIPI_CFG_PW_CONFIG_I2C); | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 		chipone_writeb(icn, MIPI_CFG_PW, MIPI_CFG_PW_CONFIG_DSI); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	chipone_writeb(icn, HACTIVE_LI, mode->hdisplay & 0xff); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	chipone_writeb(icn, VACTIVE_LI, mode->vdisplay & 0xff); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:04:59 +02:00
										 |  |  | 	/*
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 	 * lsb nibble: 2nd nibble of hdisplay | 
					
						
							|  |  |  | 	 * msb nibble: 2nd nibble of vdisplay | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	chipone_writeb(icn, VACTIVE_HACTIVE_HI, | 
					
						
							|  |  |  | 		       ((mode->hdisplay >> 8) & 0xf) | | 
					
						
							|  |  |  | 		       (((mode->vdisplay >> 8) & 0xf) << 4)); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:00 +02:00
										 |  |  | 	hfp = mode->hsync_start - mode->hdisplay; | 
					
						
							|  |  |  | 	hsync = mode->hsync_end - mode->hsync_start; | 
					
						
							|  |  |  | 	hbp = mode->htotal - mode->hsync_end; | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	chipone_writeb(icn, HFP_LI, hfp & 0xff); | 
					
						
							|  |  |  | 	chipone_writeb(icn, HSYNC_LI, hsync & 0xff); | 
					
						
							|  |  |  | 	chipone_writeb(icn, HBP_LI, hbp & 0xff); | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:00 +02:00
										 |  |  | 	/* Top two bits of Horizontal Front porch/Sync/Back porch */ | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	chipone_writeb(icn, HFP_HSW_HBP_HI, | 
					
						
							|  |  |  | 		       HFP_HSW_HBP_HI_HFP(hfp) | | 
					
						
							|  |  |  | 		       HFP_HSW_HBP_HI_HS(hsync) | | 
					
						
							|  |  |  | 		       HFP_HSW_HBP_HI_HBP(hbp)); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	chipone_writeb(icn, VFP, mode->vsync_start - mode->vdisplay); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	chipone_writeb(icn, VSYNC, mode->vsync_end - mode->vsync_start); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	chipone_writeb(icn, VBP, mode->vtotal - mode->vsync_end); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* dsi specific sequence */ | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	chipone_writeb(icn, SYNC_EVENT_DLY, 0x80); | 
					
						
							|  |  |  | 	chipone_writeb(icn, HFP_MIN, hfp & 0xff); | 
					
						
							|  |  |  | 	chipone_writeb(icn, MIPI_PD_CK_LANE, 0xa0); | 
					
						
							|  |  |  | 	chipone_writeb(icn, PLL_CTRL(12), 0xff); | 
					
						
							|  |  |  | 	chipone_writeb(icn, MIPI_PN_SWAP, 0x00); | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* DPI HS/VS/DE polarity */ | 
					
						
							|  |  |  | 	pol = ((mode->flags & DRM_MODE_FLAG_PHSYNC) ? BIST_POL_HSYNC_POL : 0) | | 
					
						
							|  |  |  | 	      ((mode->flags & DRM_MODE_FLAG_PVSYNC) ? BIST_POL_VSYNC_POL : 0) | | 
					
						
							|  |  |  | 	      ((bus_flags & DRM_BUS_FLAG_DE_HIGH) ? BIST_POL_DE_POL : 0); | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	chipone_writeb(icn, BIST_POL, pol); | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:02 +02:00
										 |  |  | 	/* Configure PLL settings */ | 
					
						
							|  |  |  | 	chipone_configure_pll(icn, mode); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	chipone_writeb(icn, SYS_CTRL(0), 0x40); | 
					
						
							|  |  |  | 	chipone_writeb(icn, SYS_CTRL(1), 0x88); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* icn6211 specific sequence */ | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:08 +02:00
										 |  |  | 	chipone_writeb(icn, MIPI_FORCE_0, 0x20); | 
					
						
							|  |  |  | 	chipone_writeb(icn, PLL_CTRL(1), 0x20); | 
					
						
							|  |  |  | 	chipone_writeb(icn, CONFIG_FINISH, 0x10); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 	usleep_range(10000, 11000); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-19 20:23:24 +05:30
										 |  |  | static void chipone_atomic_pre_enable(struct drm_bridge *bridge, | 
					
						
							|  |  |  | 				      struct drm_bridge_state *old_bridge_state) | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | { | 
					
						
							|  |  |  | 	struct chipone *icn = bridge_to_chipone(bridge); | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (icn->vdd1) { | 
					
						
							|  |  |  | 		ret = regulator_enable(icn->vdd1); | 
					
						
							|  |  |  | 		if (ret) | 
					
						
							|  |  |  | 			DRM_DEV_ERROR(icn->dev, | 
					
						
							|  |  |  | 				      "failed to enable VDD1 regulator: %d\n", ret); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (icn->vdd2) { | 
					
						
							|  |  |  | 		ret = regulator_enable(icn->vdd2); | 
					
						
							|  |  |  | 		if (ret) | 
					
						
							|  |  |  | 			DRM_DEV_ERROR(icn->dev, | 
					
						
							|  |  |  | 				      "failed to enable VDD2 regulator: %d\n", ret); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (icn->vdd3) { | 
					
						
							|  |  |  | 		ret = regulator_enable(icn->vdd3); | 
					
						
							|  |  |  | 		if (ret) | 
					
						
							|  |  |  | 			DRM_DEV_ERROR(icn->dev, | 
					
						
							|  |  |  | 				      "failed to enable VDD3 regulator: %d\n", ret); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gpiod_set_value(icn->enable_gpio, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	usleep_range(10000, 11000); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-19 20:23:24 +05:30
										 |  |  | static void chipone_atomic_post_disable(struct drm_bridge *bridge, | 
					
						
							|  |  |  | 					struct drm_bridge_state *old_bridge_state) | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | { | 
					
						
							|  |  |  | 	struct chipone *icn = bridge_to_chipone(bridge); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (icn->vdd1) | 
					
						
							|  |  |  | 		regulator_disable(icn->vdd1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (icn->vdd2) | 
					
						
							|  |  |  | 		regulator_disable(icn->vdd2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (icn->vdd3) | 
					
						
							|  |  |  | 		regulator_disable(icn->vdd3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gpiod_set_value(icn->enable_gpio, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-19 20:23:25 +05:30
										 |  |  | static void chipone_mode_set(struct drm_bridge *bridge, | 
					
						
							|  |  |  | 			     const struct drm_display_mode *mode, | 
					
						
							|  |  |  | 			     const struct drm_display_mode *adjusted_mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct chipone *icn = bridge_to_chipone(bridge); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	drm_mode_copy(&icn->mode, adjusted_mode); | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int chipone_dsi_attach(struct chipone *icn) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct mipi_dsi_device *dsi = icn->dsi; | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dsi->lanes = 4; | 
					
						
							|  |  |  | 	dsi->format = MIPI_DSI_FMT_RGB888; | 
					
						
							|  |  |  | 	dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | | 
					
						
							|  |  |  | 			  MIPI_DSI_MODE_LPM | MIPI_DSI_MODE_NO_EOT_PACKET; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = mipi_dsi_attach(dsi); | 
					
						
							|  |  |  | 	if (ret < 0) | 
					
						
							|  |  |  | 		dev_err(icn->dev, "failed to attach dsi\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int chipone_dsi_host_attach(struct chipone *icn) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct device *dev = icn->dev; | 
					
						
							|  |  |  | 	struct device_node *host_node; | 
					
						
							|  |  |  | 	struct device_node *endpoint; | 
					
						
							|  |  |  | 	struct mipi_dsi_device *dsi; | 
					
						
							|  |  |  | 	struct mipi_dsi_host *host; | 
					
						
							|  |  |  | 	int ret = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const struct mipi_dsi_device_info info = { | 
					
						
							|  |  |  | 		.type = "chipone", | 
					
						
							|  |  |  | 		.channel = 0, | 
					
						
							|  |  |  | 		.node = NULL, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0); | 
					
						
							|  |  |  | 	host_node = of_graph_get_remote_port_parent(endpoint); | 
					
						
							|  |  |  | 	of_node_put(endpoint); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!host_node) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	host = of_find_mipi_dsi_host_by_node(host_node); | 
					
						
							|  |  |  | 	of_node_put(host_node); | 
					
						
							|  |  |  | 	if (!host) { | 
					
						
							|  |  |  | 		dev_err(dev, "failed to find dsi host\n"); | 
					
						
							|  |  |  | 		return -EPROBE_DEFER; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dsi = mipi_dsi_device_register_full(host, &info); | 
					
						
							|  |  |  | 	if (IS_ERR(dsi)) { | 
					
						
							|  |  |  | 		return dev_err_probe(dev, PTR_ERR(dsi), | 
					
						
							|  |  |  | 				     "failed to create dsi device\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	icn->dsi = dsi; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = chipone_dsi_attach(icn); | 
					
						
							|  |  |  | 	if (ret < 0) | 
					
						
							|  |  |  | 		mipi_dsi_device_unregister(dsi); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							| 
									
										
										
										
											2021-11-19 20:23:25 +05:30
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | static int chipone_attach(struct drm_bridge *bridge, enum drm_bridge_attach_flags flags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct chipone *icn = bridge_to_chipone(bridge); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return drm_bridge_attach(bridge->encoder, icn->panel_bridge, bridge, flags); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:06 +02:00
										 |  |  | #define MAX_INPUT_SEL_FORMATS	1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static u32 * | 
					
						
							|  |  |  | chipone_atomic_get_input_bus_fmts(struct drm_bridge *bridge, | 
					
						
							|  |  |  | 				  struct drm_bridge_state *bridge_state, | 
					
						
							|  |  |  | 				  struct drm_crtc_state *crtc_state, | 
					
						
							|  |  |  | 				  struct drm_connector_state *conn_state, | 
					
						
							|  |  |  | 				  u32 output_fmt, | 
					
						
							|  |  |  | 				  unsigned int *num_input_fmts) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32 *input_fmts; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	*num_input_fmts = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts), | 
					
						
							|  |  |  | 			     GFP_KERNEL); | 
					
						
							|  |  |  | 	if (!input_fmts) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* This is the DSI-end bus format */ | 
					
						
							|  |  |  | 	input_fmts[0] = MEDIA_BUS_FMT_RGB888_1X24; | 
					
						
							|  |  |  | 	*num_input_fmts = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return input_fmts; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | static const struct drm_bridge_funcs chipone_bridge_funcs = { | 
					
						
							| 
									
										
										
										
											2021-11-19 20:23:24 +05:30
										 |  |  | 	.atomic_duplicate_state	= drm_atomic_helper_bridge_duplicate_state, | 
					
						
							|  |  |  | 	.atomic_destroy_state	= drm_atomic_helper_bridge_destroy_state, | 
					
						
							|  |  |  | 	.atomic_reset		= drm_atomic_helper_bridge_reset, | 
					
						
							|  |  |  | 	.atomic_pre_enable	= chipone_atomic_pre_enable, | 
					
						
							|  |  |  | 	.atomic_enable		= chipone_atomic_enable, | 
					
						
							|  |  |  | 	.atomic_post_disable	= chipone_atomic_post_disable, | 
					
						
							| 
									
										
										
										
											2021-11-19 20:23:25 +05:30
										 |  |  | 	.mode_set		= chipone_mode_set, | 
					
						
							| 
									
										
										
										
											2021-11-19 20:23:24 +05:30
										 |  |  | 	.attach			= chipone_attach, | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:06 +02:00
										 |  |  | 	.atomic_get_input_bus_fmts = chipone_atomic_get_input_bus_fmts, | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int chipone_parse_dt(struct chipone *icn) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct device *dev = icn->dev; | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	icn->vdd1 = devm_regulator_get_optional(dev, "vdd1"); | 
					
						
							|  |  |  | 	if (IS_ERR(icn->vdd1)) { | 
					
						
							|  |  |  | 		ret = PTR_ERR(icn->vdd1); | 
					
						
							|  |  |  | 		if (ret == -EPROBE_DEFER) | 
					
						
							|  |  |  | 			return -EPROBE_DEFER; | 
					
						
							|  |  |  | 		icn->vdd1 = NULL; | 
					
						
							|  |  |  | 		DRM_DEV_DEBUG(dev, "failed to get VDD1 regulator: %d\n", ret); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	icn->vdd2 = devm_regulator_get_optional(dev, "vdd2"); | 
					
						
							|  |  |  | 	if (IS_ERR(icn->vdd2)) { | 
					
						
							|  |  |  | 		ret = PTR_ERR(icn->vdd2); | 
					
						
							|  |  |  | 		if (ret == -EPROBE_DEFER) | 
					
						
							|  |  |  | 			return -EPROBE_DEFER; | 
					
						
							|  |  |  | 		icn->vdd2 = NULL; | 
					
						
							|  |  |  | 		DRM_DEV_DEBUG(dev, "failed to get VDD2 regulator: %d\n", ret); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	icn->vdd3 = devm_regulator_get_optional(dev, "vdd3"); | 
					
						
							|  |  |  | 	if (IS_ERR(icn->vdd3)) { | 
					
						
							|  |  |  | 		ret = PTR_ERR(icn->vdd3); | 
					
						
							|  |  |  | 		if (ret == -EPROBE_DEFER) | 
					
						
							|  |  |  | 			return -EPROBE_DEFER; | 
					
						
							|  |  |  | 		icn->vdd3 = NULL; | 
					
						
							|  |  |  | 		DRM_DEV_DEBUG(dev, "failed to get VDD3 regulator: %d\n", ret); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	icn->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW); | 
					
						
							|  |  |  | 	if (IS_ERR(icn->enable_gpio)) { | 
					
						
							|  |  |  | 		DRM_DEV_ERROR(dev, "failed to get enable GPIO\n"); | 
					
						
							|  |  |  | 		return PTR_ERR(icn->enable_gpio); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-21 08:42:24 +01:00
										 |  |  | 	icn->panel_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 	if (IS_ERR(icn->panel_bridge)) | 
					
						
							|  |  |  | 		return PTR_ERR(icn->panel_bridge); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | static int chipone_common_probe(struct device *dev, struct chipone **icnr) | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | { | 
					
						
							|  |  |  | 	struct chipone *icn; | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	icn = devm_kzalloc(dev, sizeof(struct chipone), GFP_KERNEL); | 
					
						
							|  |  |  | 	if (!icn) | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	icn->dev = dev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = chipone_parse_dt(icn); | 
					
						
							|  |  |  | 	if (ret) | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	icn->bridge.funcs = &chipone_bridge_funcs; | 
					
						
							|  |  |  | 	icn->bridge.type = DRM_MODE_CONNECTOR_DPI; | 
					
						
							|  |  |  | 	icn->bridge.of_node = dev->of_node; | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	*icnr = icn; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int chipone_dsi_probe(struct mipi_dsi_device *dsi) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct device *dev = &dsi->dev; | 
					
						
							|  |  |  | 	struct chipone *icn; | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = chipone_common_probe(dev, &icn); | 
					
						
							|  |  |  | 	if (ret) | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	icn->interface_i2c = false; | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:02 +02:00
										 |  |  | 	icn->dsi = dsi; | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | 	mipi_dsi_set_drvdata(dsi, icn); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | 	drm_bridge_add(&icn->bridge); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | 	ret = chipone_dsi_attach(icn); | 
					
						
							|  |  |  | 	if (ret) | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 		drm_bridge_remove(&icn->bridge); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | static int chipone_i2c_probe(struct i2c_client *client, | 
					
						
							|  |  |  | 			     const struct i2c_device_id *id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct device *dev = &client->dev; | 
					
						
							|  |  |  | 	struct chipone *icn; | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = chipone_common_probe(dev, &icn); | 
					
						
							|  |  |  | 	if (ret) | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	icn->interface_i2c = true; | 
					
						
							|  |  |  | 	icn->client = client; | 
					
						
							|  |  |  | 	dev_set_drvdata(dev, icn); | 
					
						
							|  |  |  | 	i2c_set_clientdata(client, icn); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	drm_bridge_add(&icn->bridge); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return chipone_dsi_host_attach(icn); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int chipone_dsi_remove(struct mipi_dsi_device *dsi) | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | { | 
					
						
							|  |  |  | 	struct chipone *icn = mipi_dsi_get_drvdata(dsi); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mipi_dsi_detach(dsi); | 
					
						
							|  |  |  | 	drm_bridge_remove(&icn->bridge); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const struct of_device_id chipone_of_match[] = { | 
					
						
							|  |  |  | 	{ .compatible = "chipone,icn6211", }, | 
					
						
							|  |  |  | 	{ /* sentinel */ } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | MODULE_DEVICE_TABLE(of, chipone_of_match); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | static struct mipi_dsi_driver chipone_dsi_driver = { | 
					
						
							|  |  |  | 	.probe = chipone_dsi_probe, | 
					
						
							|  |  |  | 	.remove = chipone_dsi_remove, | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 	.driver = { | 
					
						
							|  |  |  | 		.name = "chipone-icn6211", | 
					
						
							|  |  |  | 		.owner = THIS_MODULE, | 
					
						
							|  |  |  | 		.of_match_table = chipone_of_match, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2022-03-31 17:05:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | static struct i2c_device_id chipone_i2c_id[] = { | 
					
						
							|  |  |  | 	{ "chipone,icn6211" }, | 
					
						
							|  |  |  | 	{}, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | MODULE_DEVICE_TABLE(i2c, chipone_i2c_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct i2c_driver chipone_i2c_driver = { | 
					
						
							|  |  |  | 	.probe = chipone_i2c_probe, | 
					
						
							|  |  |  | 	.id_table = chipone_i2c_id, | 
					
						
							|  |  |  | 	.driver = { | 
					
						
							|  |  |  | 		.name = "chipone-icn6211-i2c", | 
					
						
							|  |  |  | 		.owner = THIS_MODULE, | 
					
						
							|  |  |  | 		.of_match_table = chipone_of_match, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int __init chipone_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) | 
					
						
							|  |  |  | 		mipi_dsi_driver_register(&chipone_dsi_driver); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return i2c_add_driver(&chipone_i2c_driver); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module_init(chipone_init); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void __init chipone_exit(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	i2c_del_driver(&chipone_i2c_driver); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) | 
					
						
							|  |  |  | 		mipi_dsi_driver_unregister(&chipone_dsi_driver); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module_exit(chipone_exit); | 
					
						
							| 
									
										
										
										
											2021-03-22 16:03:27 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | MODULE_AUTHOR("Jagan Teki <jagan@amarulasolutions.com>"); | 
					
						
							|  |  |  | MODULE_DESCRIPTION("Chipone ICN6211 MIPI-DSI to RGB Converter Bridge"); | 
					
						
							|  |  |  | MODULE_LICENSE("GPL"); |