summaryrefslogtreecommitdiffstats
path: root/arch/arm/boards/zii-common
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/boards/zii-common')
-rw-r--r--arch/arm/boards/zii-common/Makefile1
-rw-r--r--arch/arm/boards/zii-common/board.c75
-rw-r--r--arch/arm/boards/zii-common/pn-fixup.c32
-rw-r--r--arch/arm/boards/zii-common/pn-fixup.h93
-rw-r--r--arch/arm/boards/zii-common/switch-cmd.c73
5 files changed, 274 insertions, 0 deletions
diff --git a/arch/arm/boards/zii-common/Makefile b/arch/arm/boards/zii-common/Makefile
new file mode 100644
index 0000000000..fcc5cdf97d
--- /dev/null
+++ b/arch/arm/boards/zii-common/Makefile
@@ -0,0 +1 @@
+obj-y += board.o switch-cmd.o pn-fixup.o
diff --git a/arch/arm/boards/zii-common/board.c b/arch/arm/boards/zii-common/board.c
new file mode 100644
index 0000000000..20ec64d2d4
--- /dev/null
+++ b/arch/arm/boards/zii-common/board.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2019 Zodiac Inflight Innovation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <common.h>
+#include <globalvar.h>
+#include <init.h>
+#include <fs.h>
+
+static int rdu_networkconfig(void)
+{
+ static char *rdu_netconfig;
+ struct device_d *sp_dev;
+
+ if (!of_machine_is_compatible("zii,imx6q-zii-rdu2") &&
+ !of_machine_is_compatible("zii,imx6qp-zii-rdu2") &&
+ !of_machine_is_compatible("zii,imx51-rdu1"))
+ return 0;
+
+ sp_dev = get_device_by_name("sp");
+ if (!sp_dev) {
+ pr_warn("no sp device found, network config not available!\n");
+ return -ENODEV;
+ }
+
+ rdu_netconfig = basprintf("ip=%s:::%s::eth0:",
+ dev_get_param(sp_dev, "ipaddr"),
+ dev_get_param(sp_dev, "netmask"));
+
+ globalvar_add_simple_string("linux.bootargs.rdu_network",
+ &rdu_netconfig);
+
+ return 0;
+}
+late_initcall(rdu_networkconfig);
+
+#define I210_CFGWORD_PCIID_157B 0x157b1a11
+static int rdu_i210_invm(void)
+{
+ int fd;
+ u32 val;
+
+ if (!of_machine_is_compatible("zii,imx6q-zii-rdu2") &&
+ !of_machine_is_compatible("zii,imx6qp-zii-rdu2") &&
+ !of_machine_is_compatible("zii,imx8mq-ultra"))
+ return 0;
+
+ fd = open("/dev/e1000-invm0", O_RDWR);
+ if (fd < 0) {
+ pr_err("could not open e1000 iNVM device!\n");
+ return fd;
+ }
+
+ pread(fd, &val, sizeof(val), 0);
+ if (val == I210_CFGWORD_PCIID_157B) {
+ pr_debug("i210 already programmed correctly\n");
+ return 0;
+ }
+
+ val = I210_CFGWORD_PCIID_157B;
+ pwrite(fd, &val, sizeof(val), 0);
+
+ return 0;
+}
+late_initcall(rdu_i210_invm);
diff --git a/arch/arm/boards/zii-common/pn-fixup.c b/arch/arm/boards/zii-common/pn-fixup.c
new file mode 100644
index 0000000000..a665199917
--- /dev/null
+++ b/arch/arm/boards/zii-common/pn-fixup.c
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2019 Zodiac Inflight Innovation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <common.h>
+#include <init.h>
+#include <linux/nvmem-consumer.h>
+
+#include "pn-fixup.h"
+
+char *zii_read_part_number(const char *cell_name, size_t cell_size)
+{
+ struct device_node *np;
+
+ np = of_find_node_by_name(NULL, "device-info");
+ if (!np) {
+ pr_warn("No device information found\n");
+ return ERR_PTR(-ENOENT);
+ }
+
+ return nvmem_cell_get_and_read(np, cell_name, cell_size);
+}
diff --git a/arch/arm/boards/zii-common/pn-fixup.h b/arch/arm/boards/zii-common/pn-fixup.h
new file mode 100644
index 0000000000..39b848bd00
--- /dev/null
+++ b/arch/arm/boards/zii-common/pn-fixup.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2019 Zodiac Inflight Innovation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __ZII_PN_FIXUP__
+#define __ZII_PN_FIXUP__
+
+struct zii_pn_fixup {
+ const char *pn;
+ void (*callback) (const struct zii_pn_fixup *fixup);
+};
+
+char *zii_read_part_number(const char *, size_t);
+/**
+ * __zii_process_fixups - Process array of ZII part number based fixups
+ *
+ * @__fixups: Array of part number base fixups
+ * @__cell_name: Name of the NVMEM cell containing the part number
+ * @__cell_size: Size of the NVMEM cell containing the part number
+ *
+ * NOTE: Keeping this code as a marcro allows us to avoid restricting
+ * the type of __fixups to an array of struct zii_pn_fixup. This is
+ * really convenient becuase it allows us to do things like
+ *
+ * struct zii_foo_fixup {
+ * struct zii_pn_fixup parent;
+ * type1 custom_field_1
+ * type2 custom_field_2
+ * ...
+ * };
+ *
+ * ...
+ *
+ * const struct zii_foo_fixup foo_fixups[] = {
+ * { fixup1 },
+ * { fixup2 },
+ * { fixup3 },
+ * };
+ *
+ * ...
+ *
+ * __zii_process_fixups(foo_fixups, "blah", BLAH_LENGTH);
+ *
+ * which allows us to have the most compact definition of array of
+ * fixups
+ */
+#define __zii_process_fixups(__fixups, __cell_name, __cell_size) \
+ do { \
+ char *__pn = zii_read_part_number(__cell_name, \
+ __cell_size); \
+ const struct zii_pn_fixup *__fixup; \
+ unsigned int __i; \
+ bool __match_found = false; \
+ \
+ if (WARN_ON(IS_ERR(__pn))) \
+ break; \
+ \
+ for (__i = 0; __i < ARRAY_SIZE(__fixups); __i++) { \
+ __fixup = \
+ (const struct zii_pn_fixup *) &__fixups[__i]; \
+ \
+ if (strstr(__pn, __fixup->pn)) { \
+ pr_debug("%s->%pS\n", __func__, \
+ __fixup->callback); \
+ __match_found = true; \
+ __fixup->callback(__fixup); \
+ } \
+ } \
+ if (!__match_found) \
+ pr_err("No config fixups found for P/N %s!\n", __pn); \
+ free(__pn); \
+ } while (0)
+
+#define DDS_PART_NUMBER_SIZE 15
+#define LRU_PART_NUMBER_SIZE 15
+
+#define zii_process_dds_fixups(_fixups) \
+ __zii_process_fixups(_fixups, "dds-part-number", DDS_PART_NUMBER_SIZE)
+
+#define zii_process_lru_fixups(_fixups) \
+ __zii_process_fixups(_fixups, "lru-part-number", LRU_PART_NUMBER_SIZE)
+
+#endif /* __ZII_PN_FIXUP__ */
diff --git a/arch/arm/boards/zii-common/switch-cmd.c b/arch/arm/boards/zii-common/switch-cmd.c
new file mode 100644
index 0000000000..30438053a1
--- /dev/null
+++ b/arch/arm/boards/zii-common/switch-cmd.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2018 Zodiac Inflight Innovation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+#include <command.h>
+#include <common.h>
+#include <i2c/i2c.h>
+#include <linux/mfd/rave-sp.h>
+
+static int do_rdu2_switch_reset(void)
+{
+ struct i2c_client client;
+ u8 reg;
+
+ client.adapter = i2c_get_adapter(1);
+ if (!client.adapter)
+ return -ENODEV;
+
+ /* address of the switch watchdog microcontroller */
+ client.addr = 0x38;
+ reg = 0x78;
+ /* set switch reset time to 100ms */
+ i2c_write_reg(&client, 0x0a, &reg, 1);
+ /* reset the switch */
+ reg = 0x01;
+ i2c_write_reg(&client, 0x0d, &reg, 1);
+ /* issue dummy command to work around firmware bug */
+ i2c_read_reg(&client, 0x01, &reg, 1);
+
+ return 0;
+}
+
+static int do_rdu1_switch_reset(void)
+{
+ struct device_d *sp_dev = get_device_by_name("sp");
+ struct rave_sp *sp = sp_dev->priv;
+ u8 cmd[] = {
+ [0] = RAVE_SP_CMD_RESET_ETH_SWITCH,
+ [1] = 0
+ };
+
+ if (IS_ENABLED(CONFIG_RAVE_SP_CORE))
+ return rave_sp_exec(sp, cmd, sizeof(cmd), NULL, 0);
+ else
+ return -ENODEV;
+}
+
+static int do_rave_switch_reset(int argc, char *argv[])
+{
+ if (of_machine_is_compatible("zii,imx6q-zii-rdu2") ||
+ of_machine_is_compatible("zii,imx6qp-zii-rdu2"))
+ return do_rdu2_switch_reset();
+
+ if (of_machine_is_compatible("zii,imx51-rdu1"))
+ return do_rdu1_switch_reset();
+
+ return -ENODEV;
+}
+
+BAREBOX_CMD_START(rave_reset_switch)
+ .cmd = do_rave_switch_reset,
+ BAREBOX_CMD_DESC("reset ethernet switch on RDU")
+ BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
+BAREBOX_CMD_END