[U-Boot] [PATCH u-boot-marvell v2 06/12] board: turris_mox: Cosmetic restructurization
Stefan Roese
sr at denx.de
Wed Sep 19 12:22:21 UTC 2018
On 17.08.2018 12:58, Marek BehĂșn wrote:
> Restructure the board initialization source.
> Remove the module_topology environment variable since it won't be
> needed.
>
> Signed-off-by: Marek Behun <marek.behun at nic.cz>
> ---
> board/CZ.NIC/turris_mox/turris_mox.c | 153 ++++++++++++++++++++++++-----------
> 1 file changed, 106 insertions(+), 47 deletions(-)
>
> diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c
> index 42f55b7915..4a3e78c5d6 100644
> --- a/board/CZ.NIC/turris_mox/turris_mox.c
> +++ b/board/CZ.NIC/turris_mox/turris_mox.c
> @@ -33,6 +33,12 @@
>
> #define PCIE_PATH "/soc/pcie at d0070000"
>
> +typedef enum {
> + MOX_UNKNOWN,
> + MOX_EMMC,
> + MOX_SD
> +} mox_version_t;
> +
> DECLARE_GLOBAL_DATA_PTR;
>
> #if defined(CONFIG_OF_BOARD_FIXUP)
> @@ -133,17 +139,15 @@ int board_init(void)
> return 0;
> }
>
> -int last_stage_init(void)
> +static int mox_do_spi(u8 *in, u8 *out, size_t size)
> {
> struct spi_slave *slave;
> struct udevice *dev;
> - u8 din[10], dout[10];
> - int ret, i;
> - size_t len = 0;
> - char module_topology[128];
> + int ret;
>
> - ret = spi_get_bus_and_cs(0, 1, 20000000, SPI_CPHA, "spi_generic_drv",
> - "mox-modules at 1", &dev, &slave);
> + ret = spi_get_bus_and_cs(0, 1, 1000000, SPI_CPHA | SPI_CPOL,
> + "spi_generic_drv", "moxtet at 1", &dev,
> + &slave);
> if (ret)
> goto fail;
>
> @@ -151,57 +155,112 @@ int last_stage_init(void)
> if (ret)
> goto fail_free;
>
> - memset(din, 0, 10);
> - memset(dout, 0, 10);
> + ret = spi_xfer(slave, size * 8, out, in, SPI_XFER_ONCE);
> +
> + spi_release_bus(slave);
> +fail_free:
> + spi_free_slave(slave);
> +fail:
> + return ret;
> +}
>
> - ret = spi_xfer(slave, 80, dout, din, SPI_XFER_ONCE);
> +static int mox_get_topology(const u8 **ptopology, int *psize,
> + mox_version_t *pversion)
> +{
> + static mox_version_t mox_version;
> + static u8 topology[MAX_MOX_MODULES - 1];
> + static int size;
> + u8 din[MAX_MOX_MODULES], dout[MAX_MOX_MODULES];
> + int ret, i;
> +
> + if (size) {
> + if (ptopology)
> + *ptopology = topology;
> + if (psize)
> + *psize = size;
> + if (pversion)
> + *pversion = mox_version;
> + return 0;
> + }
> +
> + memset(din, 0, MAX_MOX_MODULES);
> + memset(dout, 0, MAX_MOX_MODULES);
> +
> + ret = mox_do_spi(din, dout, MAX_MOX_MODULES);
> if (ret)
> - goto fail_release;
> + return ret;
> +
> + switch (din[0]) {
> + case 0x00:
> + mox_version = MOX_EMMC;
> + break;
> + case 0x10:
> + mox_version = MOX_SD;
> + break;
> + case 0xff:
> + mox_version = MOX_UNKNOWN;
> + break;
> + default:
> + return -ENODEV;
> + }
> +
> + for (i = 1; i < MAX_MOX_MODULES && din[i] != 0xff; ++i)
> + topology[i - 1] = din[i] & 0xf;
> + size = i - 1;
> +
> + if (ptopology)
> + *ptopology = topology;
> + if (psize)
> + *psize = size;
> + if (pversion)
> + *pversion = mox_version;
> +
> + return 0;
> +}
>
> - if (din[0] != 0x00 && din[0] != 0xff)
> - goto fail_release;
> +int last_stage_init(void)
> +{
> + int ret, i;
> + const u8 *topology;
> + int module_count;
> + mox_version_t version;
> +
> + ret = mox_get_topology(&topology, &module_count, &version);
> + if (ret) {
> + printf("Cannot read module topology!\n");
> + return 0;
> + }
>
> + printf("Found Turris Mox %s version\n", version == MOX_SD ? "SD" :
> + version == MOX_EMMC ? "eMMC" :
> + "unknown");
> printf("Module Topology:\n");
> - for (i = 1; i < 10 && din[i] != 0xff; ++i) {
> - u8 mid = din[i] & 0xf;
> - size_t mlen;
> - const char *mname = "";
> -
> - switch (mid) {
> - case 0x1:
> - mname = "sfp-";
> - printf("% 4i: SFP Module\n", i);
> + for (i = 0; i < module_count; ++i) {
> + switch (topology[i]) {
> + case MOX_MODULE_SFP:
> + printf("% 4i: SFP Module\n", i + 1);
> + break;
> + case MOX_MODULE_PCI:
> + printf("% 4i: Mini-PCIe Module\n", i + 1);
> + break;
> + case MOX_MODULE_TOPAZ:
> + printf("% 4i: Topaz Switch Module (4-port)\n", i + 1);
> break;
> - case 0x2:
> - mname = "pci-";
> - printf("% 4i: Mini-PCIe Module\n", i);
> + case MOX_MODULE_PERIDOT:
> + printf("% 4i: Peridot Switch Module (8-port)\n", i + 1);
> break;
> - case 0x3:
> - mname = "topaz-";
> - printf("% 4i: Topaz Switch Module\n", i);
> + case MOX_MODULE_USB3:
> + printf("% 4i: USB 3.0 Module (4 ports)\n", i + 1);
> + break;
> + case MOX_MODULE_PASSPCI:
> + printf("% 4i: Passthrough Mini-PCIe Module\n", i + 1);
> break;
> default:
> - printf("% 4i: unknown (ID %i)\n", i, mid);
> - }
> -
> - mlen = strlen(mname);
> - if (len + mlen < sizeof(module_topology)) {
> - strcpy(module_topology + len, mname);
> - len += mlen;
> + printf("% 4i: unknown (ID %i)\n", i + 1, topology[i]);
> }
> }
> - printf("\n");
> -
> - module_topology[len > 0 ? len - 1 : 0] = '\0';
>
> - env_set("module_topology", module_topology);
> + printf("\n");
>
> -fail_release:
> - spi_release_bus(slave);
> -fail_free:
> - spi_free_slave(slave);
> -fail:
> - if (ret)
> - printf("Cannot read module topology!\n");
> - return ret;
> + return 0;
> }
>
This patch does not apply currently. I'm skipping it from this
series for now. I'm currently pushing my Marvell branch upstream
and would like to get the first batch of patches accepted. After
Tom has pulled these patches, please rebase on top of this new
master.
Thanks,
Stefan
More information about the U-Boot
mailing list