diff options
-rw-r--r-- | board/isee/common/eeprom.c (renamed from board/isee/common/igep_eeprom.c) | 0 | ||||
-rw-r--r-- | board/isee/common/eeprom.h (renamed from board/isee/common/igep_eeprom.h) | 0 | ||||
-rw-r--r-- | board/isee/common/led.c | 89 | ||||
-rw-r--r-- | board/isee/igep0146/Makefile | 3 | ||||
-rw-r--r-- | board/isee/igep0146/igep0146.c | 129 | ||||
-rw-r--r-- | configs/igep0146_imx6ul_512M_defconfig | 43 |
6 files changed, 237 insertions, 27 deletions
diff --git a/board/isee/common/igep_eeprom.c b/board/isee/common/eeprom.c index ff2e4e2..ff2e4e2 100644 --- a/board/isee/common/igep_eeprom.c +++ b/board/isee/common/eeprom.c diff --git a/board/isee/common/igep_eeprom.h b/board/isee/common/eeprom.h index dfbf78c..dfbf78c 100644 --- a/board/isee/common/igep_eeprom.h +++ b/board/isee/common/eeprom.h diff --git a/board/isee/common/led.c b/board/isee/common/led.c new file mode 100644 index 0000000..c9503ee --- /dev/null +++ b/board/isee/common/led.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2018 ISEE 2007 SL + * Manel Caro <mcaro@iseebcn.com> + * + * SPDX-License-Identifier: GPL-2.0+ + */ +#include <common.h> +#include <status_led.h> +#include <asm/io.h> +#include <asm/arch/sys_proto.h> +#include <asm/gpio.h> + +/* GPIO pins for the LEDs */ +/* GPIO Leds */ +#define IGEP0146_LED_RED 8 +#define IGEP0146_LED_GREEN 9 + + +#ifdef CONFIG_LED_STATUS_GREEN +void green_led_off(void) +{ + __led_set(IGEP0146_LED_GREEN, 0); +} + +void green_led_on(void) +{ + __led_set(IGEP0146_LED_GREEN, 1); +} +#endif + +#ifdef CONFIG_LED_STATUS_BLUE +void blue_led_off(void) +{ + __led_set(IGEP0146_LED_RED, 0); +} + +void blue_led_on(void) +{ + __led_set(IGEP0146_LED_RED, 1); +} +#endif + + +static int get_led_gpio(led_id_t mask) +{ +#ifdef CONFIG_LED_STATUS0 + if (CONFIG_LED_STATUS_BIT == mask){ + return IGEP0146_LED_RED; + } +#endif +#ifdef CONFIG_LED_STATUS1 + if (CONFIG_LED_STATUS_BIT1 == mask){ + return IGEP0146_LED_GREEN; + } +#endif + return 0; +} + +void __led_init (led_id_t mask, int state) +{ + int toggle_gpio; + + toggle_gpio = get_led_gpio(mask); + if(toggle_gpio){ + if (!gpio_request(toggle_gpio, "led")) + __led_set(mask, state); + } +} + +void __led_toggle (led_id_t mask) +{ + int state, toggle_gpio; + + toggle_gpio = get_led_gpio(mask); + if(toggle_gpio){ + state = gpio_get_value(toggle_gpio); + gpio_direction_output(toggle_gpio, !state); + } +} + +void __led_set (led_id_t mask, int state) +{ + int toggle_gpio; + + toggle_gpio = get_led_gpio(mask); + if(toggle_gpio){ + gpio_direction_output(toggle_gpio, state); + } +} diff --git a/board/isee/igep0146/Makefile b/board/isee/igep0146/Makefile index f8f19af..ec7df1c 100644 --- a/board/isee/igep0146/Makefile +++ b/board/isee/igep0146/Makefile @@ -6,5 +6,6 @@ # SPDX-License-Identifier: GPL-2.0+ # -obj-y += igep0146_eeprom.o obj-y += igep0146.o +obj-y += ../common/eeprom.o +obj-$(CONFIG_LED_STATUS) += ../common/led.o
\ No newline at end of file diff --git a/board/isee/igep0146/igep0146.c b/board/isee/igep0146/igep0146.c index d508853..936f5a6 100644 --- a/board/isee/igep0146/igep0146.c +++ b/board/isee/igep0146/igep0146.c @@ -9,6 +9,9 @@ */ #include <common.h> +#ifdef CONFIG_LED_STATUS +#include <status_led.h> +#endif #include <asm/arch/clock.h> #include <asm/arch/imx-regs.h> #include <asm/arch/iomux.h> @@ -24,7 +27,6 @@ #include <asm/arch/sys_proto.h> #include <asm/arch-mx6/sys_proto.h> #include <asm/io.h> -#include "../common/igep_common.h" #include <mmc.h> #include <fsl_esdhc.h> @@ -37,7 +39,9 @@ #include <netdev.h> #include <miiphy.h> #include <i2c.h> -#include "igep0146_eeprom.h" + +#include "../common/eeprom.h" +#include "../common/igep_common.h" DECLARE_GLOBAL_DATA_PTR; @@ -88,6 +92,34 @@ DECLARE_GLOBAL_DATA_PTR; /* eMMC reset */ #define USDHC2_PWR_GPIO IMX_GPIO_NR(4, 10) +/* GPIO Leds */ +#define IGEP0146_LED_RED IMX_GPIO_NR(1,8) +#define IGEP0146_LED_GREEN IMX_GPIO_NR(1,9) + + + +/* +There are 4 ranges of Locally Administered Address Ranges that can be used on a local network: + +x2-xx-xx-xx-xx-xx +x6-xx-xx-xx-xx-xx +xA-xx-xx-xx-xx-xx +xE-xx-xx-xx-xx-xx +*/ + +static unsigned int board_rev = 0; +static int igep_eeprom_valid = 0; +#define IGEP_MAGIC_ID 0x78FC110E + +static struct igep_mf_setup igep0146_eeprom_config = { + .magic_id = IGEP_MAGIC_ID, + .crc32 = 0, + .board_uuid = "00000000-0000-0000-0000-000000000000", + .bmac0 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + .bmac1 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, +}; + + int dram_init(void) { gd->ram_size = imx_ddr_size(); @@ -175,11 +207,11 @@ static iomux_v3_cfg_t const init_pads[] = MX6_PAD_CSI_MCLK__GPIO4_IO17 | MUX_PAD_CTRL(NO_PAD_CTRL), }; -const uchar igep_mac0 [6] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0xff }; +// const uchar igep_mac0 [6] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0xff }; //const uchar igep_mac0 [6] = { 0xb0, 0xd5, 0xcc, 0xb2, 0xa5, 0xb9 }; -static int igep_eeprom_valid = 0; -static struct igep_mf_setup igep0046_eeprom_config; +// static int igep_eeprom_valid = 0; +// static struct igep_mf_setup igep0046_eeprom_config; /* i2c */ #ifdef CONFIG_SYS_I2C_MXC @@ -247,11 +279,28 @@ static void setup_iomux_misc(void) } -const uchar* get_mac_address (void) +/*const uchar* get_mac_address (void) { if(igep_eeprom_valid) return igep0046_eeprom_config.bmac0; return igep_mac0; +}*/ + +static int get_mac_address (void) +{ + uchar enetaddr[6]; + + /* Check if the enviroment have ethaddr defined */ + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { + memcpy(enetaddr, igep0146_eeprom_config.bmac0, 6); + } + + if (!is_valid_ethaddr(enetaddr)){ + printf("MAC Address: Error or not set\n"); + return -1; + } + + return eth_setenv_enetaddr("ethaddr", enetaddr); } #ifdef CONFIG_BASE0040 @@ -302,7 +351,8 @@ int board_eth_init(bd_t *bis) { int ret = 0 ; - eth_setenv_enetaddr("ethaddr", get_mac_address()); + get_mac_address(); + /* eth_setenv_enetaddr("ethaddr", ); */ setup_iomux_enet(); mu_reset_phy(); @@ -345,6 +395,7 @@ int board_mmc_getcd(struct mmc *mmc) return ret; } + int board_mmc_init(bd_t *bis) { int i, ret; @@ -394,6 +445,45 @@ int board_early_init_f(void) return 0; } +static void set_boardserial (void) +{ + char *serial_string = getenv("serial#"); + if(!serial_string){ + setenv("serial#", igep0146_eeprom_config.board_uuid); + serial_string = igep0146_eeprom_config.board_uuid; + } + printf("Board uuid: %s\n", serial_string); +} + +static int load_eeprom (void) +{ + int result = -1; + igep_eeprom_valid = 0; + if(check_eeprom() != 0) + printf("eeprom: not found\n"); + else{ + struct igep_mf_setup eeprom_cfg; + /* Read configuration from eeprom */ + if(!eeprom_read_setup(0, (char*) &eeprom_cfg, sizeof(struct igep_mf_setup))){ + /* if(!eeprom_read_setup(0, (char*) &igep00x0_eeprom_config, sizeof(struct igep_mf_setup))){ */ + u32 crc_save_value = 0; + crc_save_value = eeprom_cfg.crc32; + eeprom_cfg.crc32=0; + u32 crc_value = crc32(0, (const unsigned char*) &eeprom_cfg, sizeof(struct igep_mf_setup)); + /* Verify crc32 */ + if((crc_save_value == crc_value) && (eeprom_cfg.magic_id == IGEP_MAGIC_ID)){ + memcpy(&igep0146_eeprom_config, &eeprom_cfg, sizeof(struct igep_mf_setup)); + igep_eeprom_valid = 1; + result = 0; + printf("eeprom: crc32 OK! Loading mac from eeprom\n"); + } + else + printf("eeprom: crc32 Failed, using defaults\n"); + } + } + return result; +} + int board_init(void) { @@ -410,23 +500,13 @@ int board_init(void) mdelay(1); #endif - if(check_eeprom() != 0){ - printf("EEPROM: not found\n"); - }else{ - /* Read configuration from eeprom */ - if(eeprom46_read_setup(0, (char*) &igep0046_eeprom_config, sizeof(struct igep_mf_setup))) - printf("EEPROM: read fail\n"); - /* Verify crc32 */ - crc_save_value = igep0046_eeprom_config.crc32; - igep0046_eeprom_config.crc32 = 0; - crc_value = crc32(0, (const unsigned char*) &igep0046_eeprom_config, sizeof(struct igep_mf_setup)); - if(crc_save_value != crc_value){ - printf("EEPROM: CRC32 failed. Loading default MAC\n"); - }else{ - printf("EEPROM: CRC32 OK! Loading MAC from eeprom\n"); - igep_eeprom_valid = 1; - } - } + load_eeprom(); + + set_boardserial(); + +#if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE) + status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_ON); +#endif #ifdef CONFIG_FEC_MXC setup_phy(); @@ -435,7 +515,6 @@ int board_init(void) return 0; } - int board_late_init(void) { checkboard(); diff --git a/configs/igep0146_imx6ul_512M_defconfig b/configs/igep0146_imx6ul_512M_defconfig index 6b7ef11..9782a6d 100644 --- a/configs/igep0146_imx6ul_512M_defconfig +++ b/configs/igep0146_imx6ul_512M_defconfig @@ -23,4 +23,45 @@ CONFIG_CMD_MEMTEST=y # CONFIG_CMD_IMLS is not set # CONFIG_CMD_FLASH is not set CONFIG_LOCALVERSION="" -# CONFIG_LOCALVERSION_AUTO is not set
\ No newline at end of file + +# LED Support +# +CONFIG_LED=y +CONFIG_CMD_LED=y +# CONFIG_LED_GPIO is not set +CONFIG_LED_STATUS=y +CONFIG_LED_STATUS_OFF=0 +CONFIG_LED_STATUS_BLINKING=1 +CONFIG_LED_STATUS_ON=1 +# CONFIG_LED_STATUS_GPIO is not set +CONFIG_LED_STATUS_BOARD_SPECIFIC=y + +# +# LEDs parameters +# +CONFIG_LED_STATUS0=y +CONFIG_LED_STATUS_BIT=8 +CONFIG_LED_STATUS_STATE=1 +CONFIG_LED_STATUS_FREQ=500 +CONFIG_LED_STATUS1=y +CONFIG_LED_STATUS_BIT1=9 +CONFIG_LED_STATUS_STATE1=0 +CONFIG_LED_STATUS_FREQ1=500 +CONFIG_LED_STATUS2=n +CONFIG_LED_STATUS_BIT2=400 +CONFIG_LED_STATUS_STATE2=0 +CONFIG_LED_STATUS_FREQ2=500 +CONFIG_LED_STATUS3=n +CONFIG_LED_STATUS_BIT3=401 +CONFIG_LED_STATUS_STATE3=0 +CONFIG_LED_STATUS_FREQ3=500 +# CONFIG_LED_STATUS4 is not set +# CONFIG_LED_STATUS5 is not set +# CONFIG_LED_STATUS_BOOT_ENABLE is not set +# CONFIG_LED_STATUS_YELLOW_ENABLE is not set +# CONFIG_LED_STATUS_RED_ENABLE is not set +CONFIG_LED_STATUS_GREEN_ENABLE=y +CONFIG_LED_STATUS_GREEN=0 +CONFIG_LED_STATUS_BLUE_ENABLE=y +CONFIG_LED_STATUS_BLUE=0 +CONFIG_LED_STATUS_CMD=y
\ No newline at end of file |