From 4ebdf0876fab87c18a3077878620c1ba65f98d38 Mon Sep 17 00:00:00 2001 From: Rene Straub Date: Sat, 6 Jan 2018 18:33:29 +0100 Subject: [PATCH] nrhw20: preparations for GPIO, I2C --- board/nm/nrhw20/board.c | 222 ++++++++++++++++++++++++++------ include/configs/am335x_nrhw20.h | 15 ++- 2 files changed, 193 insertions(+), 44 deletions(-) diff --git a/board/nm/nrhw20/board.c b/board/nm/nrhw20/board.c index 01b5e1bd1b..59d83d1a18 100644 --- a/board/nm/nrhw20/board.c +++ b/board/nm/nrhw20/board.c @@ -46,6 +46,25 @@ DECLARE_GLOBAL_DATA_PTR; +/* GPIO that controls power to DDR on EVM-SK */ +#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio)) + +#ifdef NRHW20_ON_HW16_MODE + +#define NETBIRD_GPIO_RST_PHY_N GPIO_TO_PIN(0, 16) +#define NETBIRD_GPIO_PWR_GSM GPIO_TO_PIN(1, 21) +#define NETBIRD_GPIO_SUPPLY_GSM GPIO_TO_PIN(0, 31) +#define NETBIRD_GPIO_RST_GSM GPIO_TO_PIN(1, 25) +#define NETBIRD_GPIO_WLAN_EN GPIO_TO_PIN(3, 10) +#define NETBIRD_GPIO_BT_EN GPIO_TO_PIN(3, 4) +#define NETBIRD_GPIO_EN_GPS_ANT GPIO_TO_PIN(2, 24) +#define NETBIRD_GPIO_LED_A GPIO_TO_PIN(1, 14) +#define NETBIRD_GPIO_LED_B GPIO_TO_PIN(1, 15) +#define NETBIRD_GPIO_RESET_BUTTON GPIO_TO_PIN(0, 2) +#define NETBIRD_GPIO_USB_PWR_EN GPIO_TO_PIN(1, 27) +#define NETBIRD_GPIO_USB_PWR_EN_2 GPIO_TO_PIN(2, 4) // On new version this gpio is used + +#else /* * NRHW 20 GPIOs * @@ -76,32 +95,39 @@ DECLARE_GLOBAL_DATA_PTR; * GPIO3_21: RST_HUB~ (USB) */ -/* GPIO that controls power to DDR on EVM-SK */ -#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_PWR_GSM GPIO_TO_PIN(1, 21) -#define NETBIRD_GPIO_SUPPLY_GSM GPIO_TO_PIN(0, 31) -#define NETBIRD_GPIO_RST_GSM GPIO_TO_PIN(1, 25) -#define NETBIRD_GPIO_WLAN_EN GPIO_TO_PIN(3, 10) -#define NETBIRD_GPIO_BT_EN GPIO_TO_PIN(3, 4) -#define NETBIRD_GPIO_EN_GPS_ANT GPIO_TO_PIN(2, 24) -#define NETBIRD_GPIO_LED_A GPIO_TO_PIN(1, 14) -#define NETBIRD_GPIO_LED_B GPIO_TO_PIN(1, 15) -#define NETBIRD_GPIO_RESET_BUTTON GPIO_TO_PIN(0, 2) -#define NETBIRD_GPIO_USB_PWR_EN GPIO_TO_PIN(1, 27) -#define NETBIRD_GPIO_USB_PWR_EN_2 GPIO_TO_PIN(2, 4) // On new version this gpio is used +#define NETBIRD_GPIO_RST_PHY_N GPIO_TO_PIN(0, 16) +#define NETBIRD_GPIO_RST_USB_HUB_N GPIO_TO_PIN(3, 21) -#define DDR3_CLOCK_FREQUENCY (400) +#define NETBIRD_GPIO_RST_GNSS GPIO_TO_PIN(0, 2) +#define NETBIRD_GPIO_RST_PCI GPIO_TO_PIN(3, 10) + +#define NETBIRD_GPIO_RST_GSM GPIO_TO_PIN(1, 25) +#define NETBIRD_GPIO_PWR_GSM GPIO_TO_PIN(1, 21) +#define NETBIRD_GPIO_WAKE_GSM GPIO_TO_PIN(0, 31) +#define NETBIRD_GPIO_SIM_SEL GPIO_TO_PIN(3, 17) + +#define NETBIRD_GPIO_WLAN_EN GPIO_TO_PIN(1, 26) +#define NETBIRD_GPIO_BT_EN GPIO_TO_PIN(1, 20) + +#define NETBIRD_GPIO_DIG_OUT GPIO_TO_PIN(1, 14) +#define NETBIRD_GPIO_DIG_IN GPIO_TO_PIN(1, 15) + +#endif + + + +#define DDR3_CLOCK_FREQUENCY (400) #if defined(CONFIG_SPL_BUILD) || \ (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_DM_ETH)) static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; #endif -#define BD_EEPROM_ADDR (0x50) /* CPU BD EEPROM (8kByte) is at 50 (A0) */ -#define BD_ADDRESS (0x0000) /* Board descriptor at beginning of EEPROM */ -#define PD_ADDRESS (0x0200) /* Product descriptor */ +#define BD_EEPROM_ADDR (0x50) /* CPU BD EEPROM (8kByte) is at 50 (A0) */ +#define BD_ADDRESS (0x0000) /* Board descriptor at beginning of EEPROM */ +#define PD_ADDRESS (0x0200) /* Product descriptor */ #define PARTITION_ADDRESS (0x0600) /* Partition Table */ static BD_Context bdctx[3]; /* The descriptor context */ @@ -275,7 +301,7 @@ void sdram_init(void) #endif /* CONFIG_SKIP_LOWLEVEL_INIT */ -static void request_and_set_gpio(int gpio, char *name, int value) +static void request_and_set_gpio(int gpio, const char *name, int value) { int ret; @@ -285,9 +311,10 @@ static void request_and_set_gpio(int gpio, char *name, int value) return; } + /* TODO: Set value here, remove later call gpio_set_value */ ret = gpio_direction_output(gpio, 0); if (ret < 0) { - printf("%s: Unable to set %s as output\n", __func__, name); + printf("%s: Unable to set %s as output\n", __func__, name); goto err_free_gpio; } @@ -299,12 +326,45 @@ err_free_gpio: gpio_free(gpio); } -#define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1); +#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); -int check_reset_button(void) +#ifndef NRHW20_ON_HW16_MODE + +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 + + +#if !defined(CONFIG_SPL_BUILD) + +/* TODO: Redesign to use PMIC input */ +static int check_reset_button(void) +{ +#ifdef NRHW20_ON_HW16_MODE int counter = 0; int ret; @@ -383,13 +443,18 @@ int check_reset_button(void) return 0; } return 0; +#else + return 0; +#endif } +#endif -/* TODO: Rework to use USB Hub */ static void enable_ext_usb(void) { +#ifdef NRHW20_ON_HW16_MODE REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_USB_PWR_EN); REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_USB_PWR_EN_2); + /* Disable LS2 */ if (tps65218_reg_write(TPS65218_PROT_LEVEL_2, TPS65218_ENABLE2, 0x00, 0x04)) { puts ("tps65218_reg_write failure (LS2 enable)\n"); @@ -421,8 +486,33 @@ static void enable_ext_usb(void) if (tps65218_reg_write(TPS65218_PROT_LEVEL_2, TPS65218_ENABLE2, 0x04, 0x04)) { puts ("tps65218_reg_write failure (LS2 enable)\n"); }; +#else + /* TODO: Rework to use USB Hub */ +#endif } + +/* TODO: I2C Bus Handling */ +/* + * Bus 0: PMIC + * Bus 2: System + */ +void foo(void) +{ + int old_bus; + /* int ret; */ + + old_bus = i2c_get_bus_num(); + i2c_set_bus_num(2); + + i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); + /* ret = i2c_read(0x53, 0, 1, (unsigned char *)spd_params, 256); */ + + i2c_set_bus_num(old_bus); +} + + + /* * Basic board specific setup. Pinmux has been handled already. */ @@ -433,34 +523,79 @@ int board_init(void) #endif gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; + #if defined(CONFIG_NOR) || defined(CONFIG_NAND) gpmc_init(); #endif - /* Remove power, and make sure reset is set once */ +#ifdef NRHW20_ON_HW16_MODE + REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_LED_A); + REQUEST_AND_SET_GPIO(NETBIRD_GPIO_LED_B); +#else + /* TODO: Control via PMIC GPIO10 (Red), 11 (Green) */ +#endif + + /* Keep unused subsystems in reset */ + REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_WLAN_EN); + REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_BT_EN); +#ifndef NRHW20_ON_HW16_MODE + REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_RST_GNSS); + REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_RST_PCI); + REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_DIG_OUT); +#endif + + /* Enable Ethernet and USB subsystem */ +#ifdef NRHW20_ON_HW16_MODE + REQUEST_AND_SET_GPIO(NETBIRD_GPIO_RST_PHY_N); +#else + REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_RST_PHY_N); + mdelay(1); + /* OMAP3 does not feature open drain pins, thus configure as input */ + gpio_direction_input(NETBIRD_GPIO_RST_PHY_N); + /* When thy Ethernet switch senses reset, it drives reset for 8..14ms + * Wait longer than this time to avoid IO congestion later on. + */ + mdelay(20); + + REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_RST_USB_HUB_N); + /* Minimum Reset Pulse = 1us */ + mdelay(1); + gpio_set_value(NETBIRD_GPIO_RST_USB_HUB_N, 1); +#endif + + /* Remove GSM power, and make sure reset is set once */ +#ifdef NRHW20_ON_HW16_MODE REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_SUPPLY_GSM); +#else + /* TODO: Control via PMIC GPIO7 */ +#endif REQUEST_AND_SET_GPIO(NETBIRD_GPIO_RST_GSM); REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_PWR_GSM); mdelay(20); - /* Enable gsm supply */ + + /* Enable GSM supply */ +#ifdef NRHW20_ON_HW16_MODE gpio_set_value(NETBIRD_GPIO_SUPPLY_GSM, 1); +#else + /* TODO: Control via PMIC GPIO7 */ +#endif 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); - REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_LED_A); - REQUEST_AND_SET_GPIO(NETBIRD_GPIO_LED_B); - REQUEST_AND_SET_GPIO(NETBIRD_GPIO_RST_PHY_N); - REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_WLAN_EN); - REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_BT_EN); - /* There are two funcions on the same mux mode for MMC2_DAT7 we want + /* TODO: Move to pinmux? Required??? RMII2 not used! */ + /* There are two functions on the same mux mode for MMC2_DAT7 we want * to use RMII2_CRS_DV so we need to set SMA2 Register to 1 * See SPRS717J site 49 (10)*/ #define SMA2_REGISTER (CTRL_BASE + 0x1320) @@ -468,12 +603,13 @@ int board_init(void) enable_ext_usb(); - printf("OSC: %lu MHz\n", get_osclk()/1000000); + printf("OSC: %lu MHz\n", get_osclk()/1000000); return 0; } /* TODO: Can most likely be removed. */ +#ifdef NRHW20_ON_HW16_MODE /* Enable the ecap2 pwm see siemens/pxm2 */ static int enable_pwm(void) @@ -527,6 +663,8 @@ static void enable_wlan_clock(void) enable_pwm(); } +#endif + #if !defined(CONFIG_SPL_BUILD) void set_console(void) @@ -568,6 +706,7 @@ static void set_devicetree_name(void) /* add hardware versions to environment */ if (bd_get_devicetree(devicetreename, sizeof(devicetreename)) != 0) { printf("Devicetree name not found, use legacy name\n"); + /* TODO: Rename */ strcpy(devicetreename, "am335x-nbhw16-prod2.dtb"); } @@ -578,11 +717,12 @@ static void get_hw_version(void) { int hw_ver, hw_rev; char hw_versions[16]; - char new_env[256]; + char new_env[256]; /* TODO: Check size, have also seen 512 */ /* add hardware versions to environment */ bd_get_hw_version(&hw_ver, &hw_rev); - printf("HW20: V%d.%d\n", hw_ver, hw_rev); + printf("HW20: V%d.%d\n", hw_ver, hw_rev); + snprintf(hw_versions, sizeof(hw_versions), "CP=%d.%d", hw_ver, hw_rev); snprintf(new_env, sizeof(new_env), "setenv bootargs $bootargs %s", hw_versions); setenv("add_version_bootargs", new_env); @@ -590,9 +730,10 @@ static void get_hw_version(void) static void check_fct(void) { - /* TODO: Documentation ! */ - - // EEPROM at 0x51 means FCT test station + /* Check whether an I2C device (EEPROM) is present at address 0xA2/0x51 + * In this case we are connected to the factory test station. + * Clear the bootcmd, so that test system can easily connect. + */ /* If probe fails we are sure no eeprom is connected */ if (i2c_probe(0x51) == 0) { @@ -726,13 +867,14 @@ int board_late_init(void) set_board_info_env(name); #endif +#ifdef NRHW20_ON_HW16_MODE + /* TODO: Remove, Clock should be provided by PMIC */ enable_wlan_clock(); +#endif #if !defined(CONFIG_SPL_BUILD) shield_init(); - check_fct(); - #endif return 0; @@ -800,6 +942,7 @@ static void set_mac_address(int index, uchar mac[6]) } } +/* TODO: Update doc */ /* * This function will: * Read the eFuse for MAC addresses, and set ethaddr/eth1addr/usbnet_devaddr @@ -825,6 +968,7 @@ int board_eth_init(bd_t *bis) bd_get_mac(0, mac_addr0, sizeof(mac_addr0)); set_mac_address(0, mac_addr0); + /* TODO: Check 2x Ethernet? */ writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel); cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RMII; cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_RMII; diff --git a/include/configs/am335x_nrhw20.h b/include/configs/am335x_nrhw20.h index 10aecce1d9..747ba518bb 100644 --- a/include/configs/am335x_nrhw20.h +++ b/include/configs/am335x_nrhw20.h @@ -1,8 +1,8 @@ /* * am335x_nrhw20.h * - * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * Copyright (C) 2018 NetModule AG - http://www.netmodule.com/ + * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -26,7 +26,6 @@ #define NRHW20_ON_HW16_MODE - #include #undef CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC @@ -115,16 +114,20 @@ #define CONFIG_CONS_INDEX 1 /* Use UART1 as standard UART (1 = UART0) */ /* TODO: Check whether CONFIG_CONS_INDEX can be removed --> menuconfig */ + +#define CONFIG_I2C +#define CONFIG_I2C_MULTI_BUS + #define CONFIG_CMD_EEPROM #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50 /* Main EEPROM */ #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2 #define CONFIG_SYS_I2C_SPEED 100000 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 4 -#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 50 +#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS 50 /* TODO: Can this be reduced to 20ms */ #define CONFIG_ENV_IS_IN_EEPROM -#define CONFIG_ENV_OFFSET 0x1000 /* The Environment is located at 4k */ -#define CONFIG_ENV_SIZE 0x800 /* The maximum size is 2k */ +#define CONFIG_ENV_OFFSET 0x1000 /* The Environment is located at 4k */ +#define CONFIG_ENV_SIZE 0x800 /* The maximum size is 2k */ #undef CONFIG_SPL_ENV_SUPPORT #undef CONFIG_SPL_NAND_SUPPORT #undef CONFIG_SPL_ONENAND_SUPPORT @@ -162,6 +165,7 @@ #define CONFIG_ANDROID_BOOT_IMAGE #define CONFIG_FASTBOOT_BUF_ADDR CONFIG_SYS_LOAD_ADDR #define CONFIG_FASTBOOT_BUF_SIZE 0x07000000 +/* TODO: Check */ /* To support eMMC booting */ #define CONFIG_STORAGE_EMMC @@ -199,6 +203,7 @@ /* USB Device Firmware Update support */ #ifndef CONFIG_SPL_BUILD +/* TODO: Check -> Remove */ #define CONFIG_USB_FUNCTION_DFU #define CONFIG_DFU_MMC #define DFU_ALT_INFO_MMC \