Skip to content
Snippets Groups Projects
Commit 4f7e01c9 authored by Hans de Goede's avatar Hans de Goede
Browse files

sunxi: soft-i2c: Fix gpio handling to work with the driver-model


i2c_init_board() gets called before the driver-model (gpio) code is
initialized, so move the setup of the soft-i2c pins out of i2c_init_board()
and into board_init(), at which time the driver-model setup has been done.

Also add proper error checking and properly request the gpios as that is
mandatory with the driver-model.

Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Reviewed-by: default avatarSimon Glass <sjg@chromium.org>
Acked-by: default avatarIan Campbell <ijc@hellion.org.uk>
parent 1572819c
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <asm/arch/gpio.h> #include <asm/arch/gpio.h>
#include <asm/arch/mmc.h> #include <asm/arch/mmc.h>
#include <asm/arch/usbc.h> #include <asm/arch/usbc.h>
#include <asm/gpio.h>
#include <asm/io.h> #include <asm/io.h>
#include <linux/usb/musb.h> #include <linux/usb/musb.h>
#include <net.h> #include <net.h>
...@@ -37,6 +38,41 @@ ...@@ -37,6 +38,41 @@
/* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */ /* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */
int soft_i2c_gpio_sda; int soft_i2c_gpio_sda;
int soft_i2c_gpio_scl; int soft_i2c_gpio_scl;
static int soft_i2c_board_init(void)
{
int ret;
soft_i2c_gpio_sda = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SDA);
if (soft_i2c_gpio_sda < 0) {
printf("Error invalid soft i2c sda pin: '%s', err %d\n",
CONFIG_VIDEO_LCD_PANEL_I2C_SDA, soft_i2c_gpio_sda);
return soft_i2c_gpio_sda;
}
ret = gpio_request(soft_i2c_gpio_sda, "soft-i2c-sda");
if (ret) {
printf("Error requesting soft i2c sda pin: '%s', err %d\n",
CONFIG_VIDEO_LCD_PANEL_I2C_SDA, ret);
return ret;
}
soft_i2c_gpio_scl = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SCL);
if (soft_i2c_gpio_scl < 0) {
printf("Error invalid soft i2c scl pin: '%s', err %d\n",
CONFIG_VIDEO_LCD_PANEL_I2C_SCL, soft_i2c_gpio_scl);
return soft_i2c_gpio_scl;
}
ret = gpio_request(soft_i2c_gpio_scl, "soft-i2c-scl");
if (ret) {
printf("Error requesting soft i2c scl pin: '%s', err %d\n",
CONFIG_VIDEO_LCD_PANEL_I2C_SCL, ret);
return ret;
}
return 0;
}
#else
static int soft_i2c_board_init(void) { return 0; }
#endif #endif
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
...@@ -57,7 +93,8 @@ int board_init(void) ...@@ -57,7 +93,8 @@ int board_init(void)
asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r"(24000000)); asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r"(24000000));
} }
return 0; /* Uses dm gpio code so do this here and not in i2c_init_board() */
return soft_i2c_board_init();
} }
int dram_init(void) int dram_init(void)
...@@ -351,11 +388,6 @@ void i2c_init_board(void) ...@@ -351,11 +388,6 @@ void i2c_init_board(void)
clock_twi_onoff(4, 1); clock_twi_onoff(4, 1);
#endif #endif
#endif #endif
#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 #ifdef CONFIG_SPL_BUILD
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment