nrhw20: hardware initialization update

- moved most hardware init functions to board_late_init
- enable wireless transmission for PCIe slot
- general cleanup
This commit is contained in:
Rene Straub 2018-05-25 17:09:58 +02:00
parent 9c31a29136
commit e21b076da4
1 changed files with 65 additions and 72 deletions

View File

@ -77,8 +77,6 @@ DECLARE_GLOBAL_DATA_PTR;
#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
#define NETBIRD_GPIO_RESET_BUTTON GPIO_TO_PIN(3, 0) /* TODO: From PMIC */
#define NETBIRD_GPIO_RST_PHY_N GPIO_TO_PIN(0, 16)
#define NETBIRD_GPIO_RST_USB_HUB_N GPIO_TO_PIN(3, 21)
@ -96,6 +94,9 @@ DECLARE_GLOBAL_DATA_PTR;
#define NETBIRD_GPIO_DIG_OUT GPIO_TO_PIN(1, 14)
#define NETBIRD_GPIO_DIG_IN GPIO_TO_PIN(1, 15)
#define NETBIRD_GPIO_PCI_WDIS GPIO_TO_PIN(3, 9)
/*
* PMIC GPIOs
*
@ -231,7 +232,6 @@ static void set_indicator(unsigned led, int red, int green)
i2c_set_bus_num(old_bus);
}
/*
* Read header information from EEPROM into global structure.
*/
@ -250,8 +250,6 @@ struct serial_device *default_serial_console(void)
return &eserial1_device;
}
else {
/* TODO: Check */
/* return &eserial1_device; */
enable_uart1_pin_mux();
return &eserial2_device;
}
@ -337,7 +335,7 @@ void set_uart_mux_conf(void)
{
enable_uart0_pin_mux();
enable_uart1_pin_mux();
/* TODO: ?? */
/* TODO: Who calls this method when ? */
/* disable_uart0_pin_mux(); */
/* enable_uart1_pin_mux(); */
}
@ -367,6 +365,8 @@ void sdram_init(void)
#endif /* CONFIG_SKIP_LOWLEVEL_INIT */
#if !defined(CONFIG_SPL_BUILD)
static void request_and_set_gpio(int gpio, const char *name, int value)
{
int ret;
@ -395,33 +395,10 @@ err_free_gpio:
#define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
#define REQUEST_AND_CLEAR_GPIO(N) request_and_set_gpio(N, #N, 0);
#if 0 /* TODO: Remove if not required */
static void request_input_gpio(int gpio, const char *name, int value)
{
int ret;
ret = gpio_request(gpio, name);
if (ret < 0) {
printf("%s: Unable to request %s\n", __func__, name);
return;
}
ret = gpio_direction_input(gpio);
if (ret < 0) {
printf("%s: Unable to set %s as input\n", __func__, name);
goto err_free_gpio;
}
return;
err_free_gpio:
gpio_free(gpio);
}
#define REQUEST_INPUT_GPIO(N) request_input_gpio(N, #N, 0);
#endif
static void set_status_led(int red, int green)
{
/* LED outputs are active low, invert state */
@ -429,6 +406,7 @@ static void set_status_led(int red, int green)
da9063_set_gpio(PMIC_LED0_GREEN, !green);
}
#if !defined(CONFIG_SPL_BUILD)
static void init_ethernet_switch(void)
{
@ -454,7 +432,10 @@ static void init_usb_hub(void)
static void init_pcie_slot(void)
{
puts("PCIe: ");
REQUEST_AND_SET_GPIO(NETBIRD_GPIO_RST_PCI); /* Assert reset (active high) */
da9063_set_gpio(PMIC_PCIe_SUPPLY_EN_IO, 0); /* Switch PCIe Supply off */
mdelay(30); /* Give time to discharge output */
@ -465,8 +446,9 @@ static void init_pcie_slot(void)
mdelay(10); /* PCIe requires at least 1ms delay between power on and reset release */
gpio_set_value(NETBIRD_GPIO_RST_PCI, 0); /* Release reset */
/* TODO: Define state of W_DISABLE */
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_PCI_WDIS); /* Allow wireless operation */
puts("ready\n");
}
static void init_gsm(void)
@ -483,6 +465,8 @@ static void init_gsm(void)
* 3.4.2 Power-on/off Pin, Figure 3.7
*/
puts("GSM: ");
/* TODO: Keep Power-On and use GSM Modem Reset Signal to restart */
REQUEST_AND_SET_GPIO(NETBIRD_GPIO_RST_GSM); /* Assert reset (active high) */
@ -498,12 +482,14 @@ static void init_gsm(void)
gpio_set_value(NETBIRD_GPIO_RST_GSM, 0); /* Take modem out of reset */
mdelay(300); /* Wait for power to stabilizy, #3.4.2 */
/* TODO: Defer to late_init, so that we don't block boot */
gpio_set_value(NETBIRD_GPIO_PWR_GSM, 1); /* Generate power on event, #3.4.2 */
mdelay(1200);
gpio_set_value(NETBIRD_GPIO_PWR_GSM, 0);
puts("ready\n");
}
#endif /* !defined(CONFIG_SPL_BUILD) */
/*
@ -526,21 +512,6 @@ int board_init(void)
/* Let user know we're starting */
init_indicator_leds();
set_status_led(1, 1); /* Orange */
/* set_indicator(0, 0, 1); *//* Green */
/* Initialize pins */
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_WLAN_EN);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_BT_EN);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_RST_GNSS);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_DIG_OUT);
init_ethernet_switch();
init_usb_hub();
init_pcie_slot();
init_gsm();
/* Enable charging of RTC backup capacitor (1mA, 3.1V) */
(void)da9063_set_reg(PMIC_REG_BBAT_CONT, 0xCF);
printf("OSC: %lu MHz\n", get_osclk()/1000000);
@ -549,17 +520,24 @@ int board_init(void)
#if !defined(CONFIG_SPL_BUILD)
// TODO: Check tty logic with NRSW team
// UART1: Fixed to mains connector, always present
// UART0: Mapped to shield slot
// Can only be used when shield is installed
void set_console(void)
{
char buf[8];
const char *defaultconsole = getenv("defaultconsole");
#if 0
int shield_id = bd_get_shield(0);
char buf[8];
#endif
const char *defaultconsole = getenv("defaultconsole");
if (defaultconsole == 0) {
/* Use the default console */
setenv("defaultconsole", "ttyS1");
}
#if 0
/* Don't allow changing to ttyS0 because ttyS0 is not available in the
* kernel if no comio shield is available */
if (shield_id != SHIELD_COM_IO) {
@ -569,7 +547,7 @@ void set_console(void)
/* With comio shield the defaultconsole should be ttyS0 and not ttyS1 */
setenv("defaultconsole", "ttyS0");
/* If consoldev is set take this as productive console instead of default console */
/* If consoledev is set, take this as productive console instead of default console */
if (read_file("/root/boot/consoledev", buf, 5) != 5) {
puts("Invalid file consoledev\n");
return;
@ -579,6 +557,7 @@ void set_console(void)
buf[5] = 0;
setenv("defaultconsole", buf);
}
#endif
}
static void set_devicetree_name(void)
@ -594,6 +573,20 @@ static void set_devicetree_name(void)
setenv("fdt_image", devicetreename);
}
static void set_root_partition(void)
{
int boot_partition;
/* add active root partition to environment */
boot_partition = bd_get_boot_partition();
if (boot_partition > 1) {
boot_partition = 0;
}
/* mmcblk0p1 => root0, mmcblk0p2 => root1 so +1 */
setenv_ulong("root_part", boot_partition + 1);
}
static void get_hw_version(void)
{
int hw_ver, hw_rev;
@ -722,10 +715,6 @@ static void shield_init(void)
{
shield_config();
}
#endif
#if !defined(CONFIG_SPL_BUILD)
static bool get_button_state(void)
{
@ -801,37 +790,40 @@ static void check_reset_button(void)
/* setenv("consoledev", "ttyS1"); */
}
}
#endif
#endif /* !defined(CONFIG_SPL_BUILD) */
int board_late_init(void)
{
#if !defined(CONFIG_SPL_BUILD)
int boot_partition;
if (read_eeprom() < 0)
puts("Could not get board ID.\n");
/* add active root partition to environment */
boot_partition = bd_get_boot_partition();
if (boot_partition > 1) {
boot_partition = 0;
}
get_hw_version();
set_root_partition();
set_devicetree_name();
/* mmcblk0p1 => root0, mmcblk0p2 => root1 so +1 */
setenv_ulong("root_part", boot_partition + 1);
/* Initialize pins */
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_WLAN_EN);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_BT_EN);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_RST_GNSS);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_DIG_OUT);
init_ethernet_switch();
init_usb_hub();
init_pcie_slot();
init_gsm();
/* Enable charging of RTC backup capacitor (1mA, 3.1V) */
(void)da9063_set_reg(PMIC_REG_BBAT_CONT, 0xCF);
check_reset_button();
get_hw_version();
set_devicetree_name();
/* TODO: Later */
/* set_console(); */
set_console();
shield_init();
set_status_led(0, 1); /* Green */
shield_init();
set_indicator(0, 0, 1); /* Green */
check_fct();
#endif
@ -839,6 +831,7 @@ int board_late_init(void)
return 0;
}
#ifndef CONFIG_DM_ETH
#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \