Skip to contentSkip to conversation

sunxi: video: Add support for LCD reset pin

PATCH New Hans de Goede 2 participants 7 messages Feb 16, 2015 – Feb 18, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 sunxi: video: Add support for LCD reset pin

On some boards there is a gpio to reset the LCD panel, add support for this.

---
 board/sunxi/Kconfig           |  8 ++++++++
 drivers/video/sunxi_display.c | 11 ++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
board/sunxi/Kconfig +8 -0
index 0226d28..70e6f4d 100644
@@ -317,6 +317,14 @@ config VIDEO_LCD_POWER
 	Set the power enable pin for the LCD panel. This takes a string in the
 	format understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
 
+config VIDEO_LCD_RESET
+	string "LCD panel reset pin"
+	depends on VIDEO
+	default ""
+	---help---
+	Set the reset pin for the LCD panel. This takes a string in the format
+	understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
+
 config VIDEO_LCD_BL_EN
 	string "LCD panel backlight enable pin"
 	depends on VIDEO
drivers/video/sunxi_display.c +10 -1
index dbda97e..7f01401 100644
@@ -592,7 +592,7 @@ static void sunxi_lcdc_enable(void)
 
 static void sunxi_lcdc_panel_enable(void)
 {
-	int pin;
+	int pin, reset_pin;
 
 	/*
 	 * Start with backlight disabled to avoid the screen flashing to
@@ -610,6 +610,12 @@ static void sunxi_lcdc_panel_enable(void)
 		gpio_direction_output(pin, PWM_OFF);
 	}
 
+	reset_pin = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_RESET);
+	if (reset_pin != -1) {
+		gpio_request(reset_pin, "lcd_reset");
+		gpio_direction_output(reset_pin, 0); /* Assert reset */
+	}
+
 	/* Give the backlight some time to turn off and power up the panel. */
 	mdelay(40);
 	pin = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_POWER);
@@ -617,6 +623,9 @@ static void sunxi_lcdc_panel_enable(void)
 		gpio_request(pin, "lcd_power");
 		gpio_direction_output(pin, 1);
 	}
+
+	if (reset_pin != -1)
+		gpio_direction_output(reset_pin, 1); /* De-assert reset */
 }
 
 static void sunxi_lcdc_backlight_enable(void)
Signature · 1 line
2.1.0
#1 lore raw

PATCH 2/4 sunxi: video: Add support for LCD panels which need to be configured via i2c

This commits adds support for configuring a a bitbang i2c controller, which is used on some boards to configure the LCD panel (via i2c).

---
 board/sunxi/Kconfig            | 24 ++++++++++++++++++++++++
 board/sunxi/board.c            | 10 ++++++++++
 include/configs/sunxi-common.h | 16 ++++++++++++++++
 3 files changed, 50 insertions(+)
board/sunxi/Kconfig +24 -0
index 70e6f4d..ef59e21 100644
@@ -349,6 +349,30 @@ config VIDEO_LCD_BL_PWM_ACTIVE_LOW
 	---help---
 	Set this if the backlight pwm output is active low.
 
+config VIDEO_LCD_PANEL_I2C
+	bool "LCD panel needs to be configured via i2c"
+	depends on VIDEO
+	default m
+	---help---
+	Say y here if the LCD panel needs to be configured via i2c. This
+	will add a bitbang i2c controller using gpios to talk to the LCD.
+
+config VIDEO_LCD_PANEL_I2C_SDA
+	string "LCD panel i2c interface SDA pin"
+	depends on VIDEO_LCD_PANEL_I2C
+	default "PG12"
+	---help---
+	Set the SDA pin for the LCD i2c interface. This takes a string in the
+	format understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
+
+config VIDEO_LCD_PANEL_I2C_SCL
+	string "LCD panel i2c interface SCL pin"
+	depends on VIDEO_LCD_PANEL_I2C
+	default "PG10"
+	---help---
+	Set the SCL pin for the LCD i2c interface. This takes a string in the
+	format understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
+
 
 # Note only one of these may be selected at a time! But hidden choices are
 # not supported by Kconfig
board/sunxi/board.c +10 -0
index b70e00c..e1891d1 100644
@@ -33,6 +33,12 @@
 #include <linux/usb/musb.h>
 #include <net.h>
 
+#if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
+/* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */
+int soft_i2c_gpio_sda;
+int soft_i2c_gpio_scl;
+#endif
+
 DECLARE_GLOBAL_DATA_PTR;
 
 /* add board specific code here */
@@ -152,6 +158,10 @@ void i2c_init_board(void)
 	sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUNXI_GPB0_TWI0);
 	sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUNXI_GPB0_TWI0);
 	clock_twi_onoff(0, 1);
+#if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
+	soft_i2c_gpio_sda = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SDA);
+	soft_i2c_gpio_scl = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SCL);
+#endif
 }
 
 #ifdef CONFIG_SPL_BUILD
include/configs/sunxi-common.h +16 -0
index fa9ac29..dc9a8a8 100644
@@ -243,6 +243,22 @@
 #define CONFIG_SYS_I2C_MVTWSI
 #define CONFIG_SYS_I2C_SPEED		400000
 #define CONFIG_SYS_I2C_SLAVE		0x7f
+
+#if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
+#define CONFIG_SYS_I2C_SOFT
+#define CONFIG_SYS_I2C_SOFT_SPEED	50000
+#define CONFIG_SYS_I2C_SOFT_SLAVE	0x00
+#define CONFIG_VIDEO_LCD_I2C_BUS	0 /* The lcd panel soft i2c is bus 0 */
+#define CONFIG_SYS_SPD_BUS_NUM		1 /* And the axp209 i2c bus is bus 1 */
+/* We use pin names in Kconfig and sunxi_name_to_gpio() */
+#define CONFIG_SOFT_I2C_GPIO_SDA	soft_i2c_gpio_sda
+#define CONFIG_SOFT_I2C_GPIO_SCL	soft_i2c_gpio_scl
+#ifndef __ASSEMBLY__
+extern int soft_i2c_gpio_sda;
+extern int soft_i2c_gpio_scl;
+#endif
+#endif
+
 #define CONFIG_CMD_I2C
 
 /* PMU */
Signature · 1 line
2.1.0
#2 lore raw

PATCH 3/4 sunxi: video: Add support for tl059wv5c0 lcd panels

In reply to Hans de Goede

Add support for the 6" 480x800 tl059wv5c0 panel used on e.g. Utoo P66 and Aigo M60/M608/M606 tablets.

---
 board/sunxi/Kconfig           | 8 ++++++++
 drivers/video/sunxi_display.c | 7 +++++++
 2 files changed, 15 insertions(+)
board/sunxi/Kconfig +8 -0
index ef59e21..19e7286 100644
@@ -411,6 +411,14 @@ config VIDEO_LCD_PANEL_HITACHI_TX18D42VM
 	---help---
 	7.85" 1024x768 Hitachi tx18d42vm LCD panel support
 
+config VIDEO_LCD_TL059WV5C0
+	bool "tl059wv5c0 LCD panel"
+	select VIDEO_LCD_PANEL_I2C
+	select VIDEO_LCD_IF_PARALLEL
+	---help---
+	Say Y here to add support for the 6" 480x800 tl059wv5c0 panel used
+	on e.g. Utoo P66 and Aigo M60/M608/M606 tablets.
+
 endchoice
 
 
drivers/video/sunxi_display.c +7 -0
index 7f01401..4e12150 100644
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <fdtdec.h>
 #include <fdt_support.h>
+#include <i2c.h>
 #include <video_fb.h>
 #include "videomodes.h"
 #include "hitachi_tx18d42vm_lcd.h"
@@ -1030,6 +1031,12 @@ static void sunxi_mode_set(const struct ctfb_res_modes *mode,
 			mdelay(50); /* Wait for lcd controller power on */
 			hitachi_tx18d42vm_init();
 		}
+		if (IS_ENABLED(CONFIG_VIDEO_LCD_TL059WV5C0)) {
+			unsigned int orig_i2c_bus = i2c_get_bus_num();
+			i2c_set_bus_num(CONFIG_VIDEO_LCD_I2C_BUS);
+			i2c_reg_write(0x5c, 0x04, 0x42); /* Turn on the LCD */
+			i2c_set_bus_num(orig_i2c_bus);
+		}
 		sunxi_composer_mode_set(mode, address);
 		sunxi_lcdc_tcon0_mode_set(mode, false);
 		sunxi_composer_enable();
Signature · 1 line
2.1.0
#3 lore raw

PATCH 3/4 sunxi: video: Add support for tl059wv5c0 lcd panels

Quoted 4 lines · Hans de Goede

Add support for the 6" 480x800 tl059wv5c0 panel used on e.g. Utoo P66 and Aigo M60/M608/M606 tablets.

All 4 patches: Acked-by: Ian Campbell <[email protected]>

I a couple of small comments on this one, which you can either ignore or fixup as you commit:

Quoted 10 lines
---
 board/sunxi/Kconfig           | 8 ++++++++
 drivers/video/sunxi_display.c | 7 +++++++
 2 files changed, 15 insertions(+)
board/sunxi/Kconfig +0 -0
index ef59e21..19e7286 100644

board/sunxi/Kconfig config VIDEO_LCD_PANEL_HITACHI_TX18D42VM · line 420

Quoted 10 lines
board/sunxi/Kconfig +7 -0
@@ -411,6 +411,14 @@ config VIDEO_LCD_PANEL_HITACHI_TX18D42VM
 	---help---
 	7.85" 1024x768 Hitachi tx18d42vm LCD panel support
 
+config VIDEO_LCD_TL059WV5C0
+	bool "tl059wv5c0 LCD panel"
+	select VIDEO_LCD_PANEL_I2C
+	select VIDEO_LCD_IF_PARALLEL
+	---help---
+	Say Y here to add support for the 6" 480x800 tl059wv5c0 panel used
+	on e.g. Utoo P66 and Aigo M60/M608/M606 tablets.

"Say Y" doesn't really make sense within a choice option. Better to follow the lead of the Hitachi panel above and '6" 480x800 tl059wv5c0 panel'. I'm not sure a non-exhaustive list of boards/tablets is useful either -- presumably if we know to list them here we also know to enable the option in the defconfig.

board/sunxi/Kconfig static void sunxi_mode_set(const struct ctfb_res_modes *mode, · line 1036

Quoted 7 lines
board/sunxi/Kconfig +3 -0
@@ -1030,6 +1031,12 @@ static void sunxi_mode_set(const struct ctfb_res_modes *mode,
 			mdelay(50); /* Wait for lcd controller power on */
 			hitachi_tx18d42vm_init();
 		}
+		if (IS_ENABLED(CONFIG_VIDEO_LCD_TL059WV5C0)) {
+			unsigned int orig_i2c_bus = i2c_get_bus_num();
+			i2c_set_bus_num(CONFIG_VIDEO_LCD_I2C_BUS);

I see that you save and restore the value but it might be nice for the relevant axp drivers to also call this using CONFIG_SYS_SPD_BUS_NUM? (I'm assuming it is set initially to this via i2c_init_all()?)

Ian.

#4 lore raw

PATCH 3/4 sunxi: video: Add support for tl059wv5c0 lcd panels

Hi,

Quoted 7 lines · Ian Campbell
Quoted 4 lines · Hans de Goede

Add support for the 6" 480x800 tl059wv5c0 panel used on e.g. Utoo P66 and Aigo M60/M608/M606 tablets.

All 4 patches: Acked-by: Ian Campbell <[email protected]>

Thanks for the review.

Quoted 15 lines

I a couple of small comments on this one, which you can either ignore or fixup as you commit:

Quoted 13 lines
---
  board/sunxi/Kconfig           | 8 ++++++++
  drivers/video/sunxi_display.c | 7 +++++++
  2 files changed, 15 insertions(+)
board/sunxi/Kconfig +0 -0
index ef59e21..19e7286 100644
@@ -411,6 +411,14 @@ config VIDEO_LCD_PANEL_HITACHI_TX18D42VM
  	---help---
  	7.85" 1024x768 Hitachi tx18d42vm LCD panel support
 
Quoted 12 lines

board/sunxi/Kconfig config VIDEO_LCD_PANEL_HITACHI_TX18D42VM · line 420

Quoted 7 lines
board/sunxi/Kconfig +7 -0
+config VIDEO_LCD_TL059WV5C0
+	bool "tl059wv5c0 LCD panel"
+	select VIDEO_LCD_PANEL_I2C
+	select VIDEO_LCD_IF_PARALLEL
+	---help---
+	Say Y here to add support for the 6" 480x800 tl059wv5c0 panel used
+	on e.g. Utoo P66 and Aigo M60/M608/M606 tablets.

"Say Y" doesn't really make sense within a choice option. Better to follow the lead of the Hitachi panel above and '6" 480x800 tl059wv5c0 panel'.

I agree, fixed.

Quoted 3 lines

I'm not sure a non-exhaustive list of boards/tablets is useful either -- presumably if we know to list them here we also know to enable the option in the defconfig.

Although the patch in the end is small, figuring out that this LCD needs bit banging i2c + a magic write took me a lot of time, during which I also found out that it is at least used with these tablets (I've an UTOO P66 myself, I'm preparing a patch for adding support for that), so I would like to keep this around so that if anyone ever shows up with one of the involved Aigo tablets we know what to do to get the LCD to work.

Quoted 10 lines

board/sunxi/Kconfig static void sunxi_mode_set(const struct ctfb_res_modes *mode, · line 1036

Quoted 7 lines
board/sunxi/Kconfig +3 -0
@@ -1030,6 +1031,12 @@ static void sunxi_mode_set(const struct ctfb_res_modes *mode,
  			mdelay(50); /* Wait for lcd controller power on */
  			hitachi_tx18d42vm_init();
  		}
+		if (IS_ENABLED(CONFIG_VIDEO_LCD_TL059WV5C0)) {
+			unsigned int orig_i2c_bus = i2c_get_bus_num();
+			i2c_set_bus_num(CONFIG_VIDEO_LCD_I2C_BUS);

I see that you save and restore the value but it might be nice for the relevant axp drivers to also call this using CONFIG_SYS_SPD_BUS_NUM?

I would rather not "pollute" the axp209 driver with this, eventually this should all move to the device model and the set_bus calls should go away.

Quoted 1 line

(I'm assuming it is set initially to this via i2c_init_all()?)

Correct.

Regards,

Hans

#6 lore raw

PATCH 4/4 sunxi: musb: Check Vbus-det before enabling otg port power

In reply to Hans de Goede

Sending out 5V when there is a charger connected to the otg port is not a good idea, so check for this and error out.

Note this commit currently breaks otg support on the q8h tablets, as we need to do some magic with the pmic there to get vbus info, this is deliberate (better safe then sorry), fixing this is on my TODO list.

---
 board/sunxi/Kconfig               |  8 ++++++++
 configs/Ampe_A76_defconfig        |  1 +
 configs/Chuwi_V7_CW0825_defconfig |  1 +
 configs/Hyundai_A7HD_defconfig    |  1 +
 configs/Inet_86VS_defconfig       |  1 +
 configs/TZX-Q8-713B7_defconfig    |  1 +
 drivers/usb/musb-new/sunxi.c      | 25 +++++++++++++++++++++++++
 7 files changed, 38 insertions(+)
board/sunxi/Kconfig +8 -0
index 19e7286..febcc8e 100644
@@ -228,6 +228,14 @@ config USB0_VBUS_PIN
 	Set the Vbus enable pin for usb0 (otg). This takes a string in the
 	format understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
 
+config USB0_VBUS_DET
+	string "Vbus detect pin for usb0 (otg)"
+	depends on USB_MUSB_SUNXI
+	default ""
+	---help---
+	Set the Vbus detect pin for usb0 (otg). This takes a string in the
+	format understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
+
 config USB1_VBUS_PIN
 	string "Vbus enable pin for usb1 (ehci0)"
 	default "PH6" if MACH_SUN4I || MACH_SUN7I
configs/Ampe_A76_defconfig +1 -0
index 2054fc3..f8ceb6c 100644
@@ -3,6 +3,7 @@ CONFIG_SYS_EXTRA_OPTIONS="CONS_INDEX=2,AXP209_POWER"
 CONFIG_FDTFILE="sun5i-a13-ampe-a76.dtb"
 CONFIG_USB_MUSB_SUNXI=y
 CONFIG_USB0_VBUS_PIN="PG12"
+CONFIG_USB0_VBUS_DET="PG01"
 CONFIG_VIDEO_LCD_MODE="x:800,y:480,depth:18,pclk_khz:33000,le:45,ri:82,up:22,lo:22,hs:1,vs:1,sync:3,vmode:0"
 CONFIG_VIDEO_LCD_POWER="AXP0-0"
 CONFIG_VIDEO_LCD_BL_EN="AXP0-1"
configs/Chuwi_V7_CW0825_defconfig +1 -0
index 680b631..1ef23e4 100644
@@ -3,6 +3,7 @@ CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER"
 CONFIG_FDTFILE="sun4i-a10-chuwi-v7-cw0825.dtb"
 CONFIG_USB_MUSB_SUNXI=y
 CONFIG_USB0_VBUS_PIN="PB9"
+CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_VIDEO_LCD_MODE="x:1024,y:768,depth:24,pclk_khz:51000,le:19,ri:300,up:6,lo:31,hs:1,vs:1,sync:3,vmode:0"
 CONFIG_VIDEO_LCD_POWER="PH8"
 CONFIG_VIDEO_LCD_BL_EN="PH7"
configs/Hyundai_A7HD_defconfig +1 -0
index 204640e..6b784e2 100644
@@ -6,6 +6,7 @@ CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER"
 CONFIG_FDTFILE="sun4i-a10-hyundai-a7hd.dtb"
 CONFIG_USB_MUSB_SUNXI=y
 CONFIG_USB0_VBUS_PIN="PB09"
+CONFIG_USB0_VBUS_DET="PH5"
 CONFIG_USB1_VBUS_PIN=""
 CONFIG_USB2_VBUS_PIN="PH6"
 CONFIG_VIDEO_LCD_MODE="x:1024,y:600,depth:18,pclk_khz:51000,le:45,ri:274,up:22,lo:12,hs:1,vs:1,sync:3,vmode:0"
configs/Inet_86VS_defconfig +1 -0
index ce9985a..50c073a 100644
@@ -3,6 +3,7 @@ CONFIG_SYS_EXTRA_OPTIONS="AXP209_POWER"
 CONFIG_FDTFILE="sun5i-a13-inet-86vs.dtb"
 CONFIG_USB_MUSB_SUNXI=y
 CONFIG_USB0_VBUS_PIN="PG12"
+CONFIG_USB0_VBUS_DET="PG1"
 CONFIG_VIDEO_LCD_MODE="x:800,y:480,depth:18,pclk_khz:33000,le:45,ri:209,up:22,lo:22,hs:1,vs:1,sync:3,vmode:0"
 CONFIG_VIDEO_LCD_POWER="AXP0-0"
 CONFIG_VIDEO_LCD_BL_EN="AXP0-1"
configs/TZX-Q8-713B7_defconfig +1 -0
index 7b7b9dd..c22286a 100644
@@ -3,6 +3,7 @@ CONFIG_SYS_EXTRA_OPTIONS="CONS_INDEX=2,AXP209_POWER"
 CONFIG_FDTFILE="sun5i-a13-tzx-q8-713b7.dtb"
 CONFIG_USB_MUSB_SUNXI=y
 CONFIG_USB0_VBUS_PIN="PG12"
+CONFIG_USB0_VBUS_DET="PG1"
 CONFIG_VIDEO_LCD_MODE="x:800,y:480,depth:18,pclk_khz:33000,le:87,ri:40,up:31,lo:13,hs:1,vs:1,sync:3,vmode:0"
 CONFIG_VIDEO_LCD_POWER="AXP0-0"
 CONFIG_VIDEO_LCD_BL_EN="AXP0-1"
drivers/usb/musb-new/sunxi.c +25 -0
index 4646a3d..b77e938 100644
@@ -22,7 +22,9 @@
  */
 #include <common.h>
 #include <asm/arch/cpu.h>
+#include <asm/arch/gpio.h>
 #include <asm/arch/usbc.h>
+#include <asm-generic/gpio.h>
 #include "linux-compat.h"
 #include "musb_core.h"
 
@@ -224,6 +226,29 @@ static int sunxi_musb_init(struct musb *musb)
 
 	pr_debug("%s():\n", __func__);
 
+	if (is_host_enabled(musb)) {
+		int vbus_det = sunxi_name_to_gpio(CONFIG_USB0_VBUS_DET);
+		if (vbus_det == -1) {
+			eprintf("Error invalid Vusb-det pin\n");
+			return -EINVAL;
+		}
+
+		err = gpio_request(vbus_det, "vbus0_det");
+		if (err)
+			return err;
+		err = gpio_direction_input(vbus_det);
+		if (err)
+			return err;
+
+		err = gpio_get_value(vbus_det);
+		if (err) {
+			eprintf("Error: A charger is plugged into the OTG\n");
+			return -EIO;
+		}
+
+		gpio_free(vbus_det);
+	}
+
 	err = sunxi_usbc_request_resources(0);
 	if (err)
 		return err;
Signature · 1 line
2.1.0