nrhw20: board file cleanup

- factor out module init functions from board_init()
This commit is contained in:
Rene Straub 2018-02-28 16:17:28 +01:00
parent 29f4a69460
commit 1f0732af31
1 changed files with 71 additions and 61 deletions

View File

@ -138,12 +138,10 @@ DECLARE_GLOBAL_DATA_PTR;
#define DDR3_CLOCK_FREQUENCY (400)
#if defined(CONFIG_SPL_BUILD) || \
(defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_DM_ETH))
#if !defined(CONFIG_SPL_BUILD)
static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
#endif
#define I2C_BD_EEPROM_BUS (2)
#define BD_EEPROM_ADDR (0x50) /* CPU BD EEPROM (8kByte) is at 50 (A0) */
#define BD_ADDRESS (0x0000) /* Board descriptor at beginning of EEPROM */
@ -173,10 +171,9 @@ static int _bd_init(void)
return -1;
}
/* TODO: Can we get rid of this and use eMMC partitino table solely? */
if (bd_get_context(&bdctx[2], BD_EEPROM_ADDR, PARTITION_ADDRESS) != 0) {
printf("%s() no valid partition table found\n", __func__);
/* TODO: error handling */
return -1;
}
bd_register_context_list(bdctx, ARRAY_SIZE(bdctx));
@ -291,12 +288,7 @@ struct dpll_params dpll_ddr_nrhw20 = {
void am33xx_spl_board_init(void)
{
/* TODO: Remove one of the two opp100 settings */
/* Get the frequency */
dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
/* Set CPU speed to 600 MHZ */
/* Set CPU speed to 600 MHz (fix) */
dpll_mpu_opp100.m = MPUPLL_M_600;
/* Set CORE Frequencies to OPP100 (600MHz) */
@ -308,12 +300,6 @@ void am33xx_spl_board_init(void)
/* Set MPU Frequency to what we detected now that voltages are set */
do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
/* TODO: Should not be needed in SPL */
/*
if (read_eeprom() < 0)
puts("Could not get board ID.\n");
*/
}
const struct dpll_params *get_dpll_ddr_params(void)
@ -595,6 +581,67 @@ static void set_status_led(int red, int green)
}
static void init_ethernet_switch(void)
{
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_RST_PHY_N);
mdelay(1);
/* OMAP3 does not feature open drain pins, thus configure pin as input */
gpio_direction_input(NETBIRD_GPIO_RST_PHY_N);
/* When the Ethernet switch senses reset, it drives reset for 8..14ms
* Wait longer than this time to avoid IO congestion later on.
*/
mdelay(20);
}
static void init_usb_hub(void)
{
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_RST_USB_HUB_N);
/* Minimum Reset Pulse = 1us */
mdelay(2);
gpio_set_value(NETBIRD_GPIO_RST_USB_HUB_N, 1);
}
static void init_pcie_slot(void)
{
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 */
da9063_set_gpio(PMIC_PCIe_SUPPLY_VSEL_IO, 0); /* Set voltage to 3.3V */
mdelay(1);
da9063_set_gpio(PMIC_PCIe_SUPPLY_EN_IO, 1); /* Enable Supply */
mdelay(10); /* PCIe requires at least 1ms delay between power on and reset release */
gpio_set_value(NETBIRD_GPIO_RST_PCI, 0); /* Release reset */
}
static void init_gsm(void)
{
REQUEST_AND_SET_GPIO(NETBIRD_GPIO_RST_GSM); /* Assert reset (active high) */
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_PWR_GSM); /* Keep power switch inactive (released) */
da9063_set_gpio(PMIC_GSM_SUPPLY_EN_IO, 0); /* Switch GSM Supply off */
mdelay(30); /* Give time to discharge supply */
da9063_set_gpio(PMIC_GSM_SUPPLY_EN_IO, 1); /* Enable GSM supply */
mdelay(10);
gpio_set_value(NETBIRD_GPIO_RST_GSM, 0); /* Take modem out of reset. */
mdelay(300); /* Wait 300ms until modem can handle power request */
/*
* Do power up sequence.
* The ME909 has a special power up sequence where we have to pull PWR for > 1s but < 7s (see manual)
*/
gpio_set_value(NETBIRD_GPIO_PWR_GSM, 1);
/* TODO: Defer to late_init, so that we don't block boot */
mdelay(1200);
gpio_set_value(NETBIRD_GPIO_PWR_GSM, 0);
}
/*
* Basic board specific setup. Pinmux has been handled already.
@ -616,64 +663,27 @@ int board_init(void)
i2c_set_bus_num(0);
da9063_init(CONFIG_PMIC_I2C_BUS);
init_indicator_leds();
/* Let user know we're starting */
init_indicator_leds();
set_status_led(1, 1); /* Orange */
set_indicator(0, 0, 1); /* Green */
set_indicator(1, 0, 1); /* Green */
/* Keep unused subsystems in reset */
/* 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_RST_PCI);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_DIG_OUT);
da9063_set_gpio(PMIC_PCIe_SUPPLY_EN_IO, 0); /* PCIe Supply off */
da9063_set_gpio(PMIC_PCIe_SUPPLY_VSEL_IO, 0); /* PCIe voltage = 3.3V */
init_ethernet_switch();
init_usb_hub();
init_pcie_slot();
init_gsm();
/* Enable charging of RTC backup capacitor (1mA, 3.1V) */
(void)da9093_set_reg(PMIC_REG_BBAT_CONT, 0xCF);
/* Enable Ethernet switch */
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_RST_PHY_N);
mdelay(1);
/* OMAP3 does not feature open drain pins, thus configure pin as input */
gpio_direction_input(NETBIRD_GPIO_RST_PHY_N);
/* When the Ethernet switch senses reset, it drives reset for 8..14ms
* Wait longer than this time to avoid IO congestion later on.
*/
mdelay(20);
/* Enable USB hub */
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_RST_USB_HUB_N);
/* Minimum Reset Pulse = 1us */
mdelay(2);
gpio_set_value(NETBIRD_GPIO_RST_USB_HUB_N, 1);
/* Disable GSM supply, and make sure reset is set once */
da9063_set_gpio(PMIC_GSM_SUPPLY_EN_IO, 0);
REQUEST_AND_SET_GPIO(NETBIRD_GPIO_RST_GSM);
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_PWR_GSM);
mdelay(20);
/* Enable GSM supply */
da9063_set_gpio(PMIC_GSM_SUPPLY_EN_IO, 1);
mdelay(20);
/* Take modem out of reset, we have to wait 300ms afterwards */
gpio_set_value(NETBIRD_GPIO_RST_GSM, 0);
mdelay(300);
/* Do power up sequence, this modem has a special power up sequence
* where we have to pull PWR for > 1s but < 7s (see manual)
*/
gpio_set_value(NETBIRD_GPIO_PWR_GSM, 1);
/* TODO: Defer to late_init, so that we don't block boot */
mdelay(1200);
gpio_set_value(NETBIRD_GPIO_PWR_GSM, 0);
printf("OSC: %lu MHz\n", get_osclk()/1000000);
return 0;