summaryrefslogtreecommitdiff
path: root/board/compulab/imx8mm-cl-iot-gate
diff options
context:
space:
mode:
Diffstat (limited to 'board/compulab/imx8mm-cl-iot-gate')
-rw-r--r--board/compulab/imx8mm-cl-iot-gate/Makefile2
-rw-r--r--board/compulab/imx8mm-cl-iot-gate/ddr/ddr.c24
-rw-r--r--board/compulab/imx8mm-cl-iot-gate/ddr/ddr.h5
-rw-r--r--board/compulab/imx8mm-cl-iot-gate/eeprom_spl.c130
-rw-r--r--board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c101
5 files changed, 258 insertions, 4 deletions
diff --git a/board/compulab/imx8mm-cl-iot-gate/Makefile b/board/compulab/imx8mm-cl-iot-gate/Makefile
index 3a2bfc4dc4b..3800b21a6fd 100644
--- a/board/compulab/imx8mm-cl-iot-gate/Makefile
+++ b/board/compulab/imx8mm-cl-iot-gate/Makefile
@@ -8,6 +8,6 @@
obj-y += imx8mm-cl-iot-gate.o
ifdef CONFIG_SPL_BUILD
-obj-y += spl.o
+obj-y += spl.o eeprom_spl.o
obj-y += ddr/
endif
diff --git a/board/compulab/imx8mm-cl-iot-gate/ddr/ddr.c b/board/compulab/imx8mm-cl-iot-gate/ddr/ddr.c
index 42dd0dbf18f..5b93491923e 100644
--- a/board/compulab/imx8mm-cl-iot-gate/ddr/ddr.c
+++ b/board/compulab/imx8mm-cl-iot-gate/ddr/ddr.c
@@ -22,6 +22,8 @@
#include <asm/mach-imx/gpio.h>
#include "ddr.h"
+#include <linux/delay.h>
+
static unsigned int lpddr4_mr_read(unsigned int mr_rank, unsigned int mr_addr)
{
unsigned int tmp;
@@ -137,10 +139,11 @@ void spl_dram_init_compulab(void)
(struct lpddr4_tcm_desc *)SPL_TCM_DATA;
if (lpddr4_tcm_desc->sign != DEFAULT) {
- /* if not in tcm scan mode */
+ /* get ddr type from the eeprom if not in tcm scan mode */
+ ddr_info = cl_eeprom_get_ddrinfo();
for (i = 0; i < ARRAY_SIZE(lpddr4_array); i++) {
if (lpddr4_array[i].id == ddr_info &&
- lpddr4_array[i].subind == 0xff) {
+ lpddr4_array[i].subind == cl_eeprom_get_subind()) {
ddr_found = 1;
break;
}
@@ -198,10 +201,25 @@ void spl_dram_init_compulab(void)
SPL_TCM_FINI;
+ if (ddr_found == 0) {
+ /* Update eeprom */
+ cl_eeprom_set_ddrinfo(ddr_info_mrr);
+ mdelay(10);
+ ddr_info = cl_eeprom_get_ddrinfo();
+ mdelay(10);
+ cl_eeprom_set_subind(lpddr4_array[i].subind);
+ /* make sure that the ddr_info has reached the eeprom */
+ printf("DDRINFO(E): mr5-8 [ 0x%x ], read back\n", ddr_info);
+ if (ddr_info_mrr != ddr_info || cl_eeprom_get_subind() != lpddr4_array[i].subind) {
+ printf("DDRINFO(EEPROM): make sure that the eeprom is accessible\n");
+ printf("DDRINFO(EEPROM): i2c dev 1; i2c md 0x51 0x40 0x50\n");
+ }
+ }
+
/* Pass the dram size to th U-Boot through the tcm memory */
{ /* To figure out what to store into the TCM buffer */
/* For debug purpouse only. To override the real memsize */
- unsigned int ddr_tcm_size = 0;
+ unsigned int ddr_tcm_size = cl_eeprom_get_osize();
if (ddr_tcm_size == 0 || ddr_tcm_size == -1)
ddr_tcm_size = lpddr4_array[i].size;
diff --git a/board/compulab/imx8mm-cl-iot-gate/ddr/ddr.h b/board/compulab/imx8mm-cl-iot-gate/ddr/ddr.h
index 59c18911592..f7d4fdc1016 100644
--- a/board/compulab/imx8mm-cl-iot-gate/ddr/ddr.h
+++ b/board/compulab/imx8mm-cl-iot-gate/ddr/ddr.h
@@ -23,4 +23,9 @@ struct lpddr4_tcm_desc {
unsigned int count;
};
+u32 cl_eeprom_get_ddrinfo(void);
+u32 cl_eeprom_set_ddrinfo(u32 ddrinfo);
+u32 cl_eeprom_get_subind(void);
+u32 cl_eeprom_set_subind(u32 subind);
+u32 cl_eeprom_get_osize(void);
#endif
diff --git a/board/compulab/imx8mm-cl-iot-gate/eeprom_spl.c b/board/compulab/imx8mm-cl-iot-gate/eeprom_spl.c
new file mode 100644
index 00000000000..ee6d2bb0016
--- /dev/null
+++ b/board/compulab/imx8mm-cl-iot-gate/eeprom_spl.c
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* (C) Copyright 2019 CompuLab, Ltd. <www.compulab.co.il> */
+
+#include <common.h>
+#include <i2c.h>
+#include <linux/kernel.h>
+#include <asm/arch/imx8mq_pins.h>
+#include <asm/mach-imx/gpio.h>
+#include <asm-generic/gpio.h>
+#include <asm/setup.h>
+#include <linux/delay.h>
+
+#ifdef CONFIG_SPL_BUILD
+
+#define CONFIG_SYS_I2C_EEPROM_ADDR_P1 0x51
+#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1
+
+static iomux_v3_cfg_t const eeprom_pads[] = {
+ IMX8MQ_PAD_GPIO1_IO13__GPIO1_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL),
+};
+
+#define EEPROM_WP_GPIO IMX_GPIO_NR(1, 13)
+
+static void cl_eeprom_we(int enable)
+{
+ static int done;
+
+ if (done) {
+ gpio_direction_output(EEPROM_WP_GPIO, enable);
+ return;
+ }
+
+ imx_iomux_v3_setup_multiple_pads(eeprom_pads, ARRAY_SIZE(eeprom_pads));
+ gpio_request(EEPROM_WP_GPIO, "eeprom_wp");
+ gpio_direction_output(EEPROM_WP_GPIO, enable);
+ done = 1;
+}
+
+static int cl_eeprom_read(uint offset, uchar *buf, int len)
+{
+ struct udevice *dev;
+ int ret;
+
+ ret = i2c_get_chip_for_busnum(1, CONFIG_SYS_I2C_EEPROM_ADDR_P1,
+ CONFIG_SYS_I2C_EEPROM_ADDR_LEN, &dev);
+ if (ret) {
+ printf("%s: Cannot find EEPROM: %d\n", __func__, ret);
+ return ret;
+ }
+
+ return dm_i2c_read(dev, offset, buf, len);
+}
+
+static int cl_eeprom_write(uint offset, uchar *buf, int len)
+{
+ struct udevice *dev;
+ int ret;
+
+ cl_eeprom_we(1);
+
+ ret = i2c_get_chip_for_busnum(1, CONFIG_SYS_I2C_EEPROM_ADDR_P1,
+ CONFIG_SYS_I2C_EEPROM_ADDR_LEN, &dev);
+ if (ret) {
+ printf("%s: Cannot find EEPROM: %d\n", __func__, ret);
+ return ret;
+ }
+
+ return dm_i2c_write(dev, offset, buf, len);
+}
+
+/* Reserved for fututre use area */
+#define BOARD_DDRINFO_OFFSET 0x40
+#define BOARD_DDR_SIZE 4
+static u32 board_ddrinfo = 0xdeadbeef;
+
+#define BOARD_DDRSUBIND_OFFSET 0x44
+#define BOARD_DDRSUBIND_SIZE 1
+static u8 board_ddrsubind = 0xff;
+
+#define BOARD_OSIZE_OFFSET 0x80
+#define BOARD_OSIZE_SIZE 4
+static u32 board_osize = 0xdeadbeef;
+
+#define BOARD_DDRINFO_VALID(A) ((A) != 0xdeadbeef)
+
+u32 cl_eeprom_get_ddrinfo(void)
+{
+ if (!BOARD_DDRINFO_VALID(board_ddrinfo)) {
+ if (cl_eeprom_read(BOARD_DDRINFO_OFFSET, (uchar *)&board_ddrinfo, BOARD_DDR_SIZE))
+ return 0;
+ }
+ return board_ddrinfo;
+};
+
+u32 cl_eeprom_set_ddrinfo(u32 ddrinfo)
+{
+ if (cl_eeprom_write(BOARD_DDRINFO_OFFSET, (uchar *)&ddrinfo, BOARD_DDR_SIZE))
+ return 0;
+
+ board_ddrinfo = ddrinfo;
+
+ return board_ddrinfo;
+};
+
+u8 cl_eeprom_get_subind(void)
+{
+ if (cl_eeprom_read(BOARD_DDRSUBIND_OFFSET, (uchar *)&board_ddrsubind, BOARD_DDRSUBIND_SIZE))
+ return 0xff;
+
+ return board_ddrsubind;
+};
+
+u8 cl_eeprom_set_subind(u8 ddrsubind)
+{
+ if (cl_eeprom_write(BOARD_DDRSUBIND_OFFSET, (uchar *)&ddrsubind, BOARD_DDRSUBIND_SIZE))
+ return 0xff;
+ board_ddrsubind = ddrsubind;
+
+ return board_ddrsubind;
+};
+
+/* override-size ifaces */
+u32 cl_eeprom_get_osize(void)
+{
+ if (cl_eeprom_read(BOARD_OSIZE_OFFSET, (uchar *)&board_osize, BOARD_OSIZE_SIZE))
+ return 0;
+
+ return board_osize;
+};
+#endif
diff --git a/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c b/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c
index 7e2d88f449c..27200f728ef 100644
--- a/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c
+++ b/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c
@@ -12,6 +12,8 @@
#include <init.h>
#include <miiphy.h>
#include <netdev.h>
+#include <i2c_eeprom.h>
+#include <i2c.h>
#include <asm/arch/clock.h>
#include <asm/arch/imx8mm_pins.h>
@@ -418,12 +420,111 @@ int extension_board_scan(struct list_head *extension_list)
return ret;
}
+static int setup_mac_address(void)
+{
+ unsigned char enetaddr[6];
+ struct udevice *dev;
+ int ret, off;
+
+ ret = eth_env_get_enetaddr("ethaddr", enetaddr);
+ if (ret)
+ return 0;
+
+ off = fdt_path_offset(gd->fdt_blob, "eeprom1");
+ if (off < 0) {
+ printf("No eeprom0 path offset found in DT\n");
+ return off;
+ }
+
+ ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
+ if (ret) {
+ printf("%s: Could not find EEPROM\n", __func__);
+ return ret;
+ }
+
+ ret = i2c_set_chip_offset_len(dev, 1);
+ if (ret)
+ return ret;
+
+ ret = i2c_eeprom_read(dev, 4, enetaddr, sizeof(enetaddr));
+ if (ret) {
+ printf("%s: Could not read EEPROM\n", __func__);
+ return ret;
+ }
+
+ ret = is_valid_ethaddr(enetaddr);
+ if (!ret)
+ return -EINVAL;
+
+ ret = eth_env_set_enetaddr("ethaddr", enetaddr);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static int read_serial_number(void)
+{
+ unsigned char serialnumber[6];
+ unsigned char reversed[6];
+ char serial_string[12];
+ struct udevice *dev;
+ int ret, off, i;
+
+ off = fdt_path_offset(gd->fdt_blob, "eeprom0");
+ if (off < 0) {
+ printf("No eeprom0 path offset found in DT\n");
+ return off;
+ }
+
+ ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
+ if (ret) {
+ printf("%s: Could not find EEPROM\n", __func__);
+ return ret;
+ }
+
+ ret = i2c_set_chip_offset_len(dev, 1);
+ if (ret)
+ return ret;
+
+ ret = i2c_eeprom_read(dev, 0x14, serialnumber, sizeof(serialnumber));
+ if (ret) {
+ printf("%s: Could not read EEPROM\n", __func__);
+ return ret;
+ }
+
+ for (i = sizeof(serialnumber) - 1; i >= 0; i--)
+ reversed[i] = serialnumber[sizeof(serialnumber) - 1 - i];
+
+ for (i = 0; i < sizeof(reversed); i++) {
+ serial_string[i * 2] = (reversed[i] >> 4) & 0xf;
+ serial_string[i * 2 + 1] = reversed[i] & 0xf;
+ }
+
+ for (i = 0; i < sizeof(serial_string); i++)
+ serial_string[i] += '0';
+
+ env_set("serial#", serial_string);
+
+ return 0;
+}
+
int board_late_init(void)
{
+ int ret;
+
if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)) {
env_set("board_name", "IOT-GATE-IMX8");
env_set("board_rev", "SBC-IOTMX8");
}
+ ret = setup_mac_address();
+ if (ret < 0)
+ printf("Cannot set MAC address from EEPROM\n");
+
+ ret = read_serial_number();
+ if (ret < 0)
+ printf("Cannot read serial number from EEPROM\n");
+
return 0;
}