From 045022f36e4d83396ee3b518d0d3bc5cd9b80ee9 Mon Sep 17 00:00:00 2001 From: Jan Luebbe Date: Tue, 14 Apr 2015 18:43:05 +0200 Subject: [PATCH] sysmobts: add support for the sysmobts v2 --- arch/arm/boards/Makefile | 1 + arch/arm/boards/sysmobts/Makefile | 3 + arch/arm/boards/sysmobts/board.c | 167 ++++++++++++++++ .../defaultenv-sysmobts/bin/prepare-ubi | 13 ++ .../sysmobts/defaultenv-sysmobts/boot/chooser | 3 + .../sysmobts/defaultenv-sysmobts/boot/rescue | 8 + .../defaultenv-sysmobts/boot/rescue-net | 8 + .../sysmobts/defaultenv-sysmobts/boot/system0 | 10 + .../sysmobts/defaultenv-sysmobts/boot/system1 | 10 + .../defaultenv-sysmobts/init/automount-nand | 10 + .../defaultenv-sysmobts/nv/boot.default | 1 + .../nv/linux.bootargs.base | 1 + .../nv/linux.bootargs.console | 1 + arch/arm/boards/sysmobts/lowlevel.c | 37 ++++ arch/arm/dts/Makefile | 1 + arch/arm/dts/dm6442-sysmobts.dts | 178 ++++++++++++++++++ arch/arm/dts/dm644x.dtsi | 47 +++++ arch/arm/mach-davinci/Kconfig | 5 + 18 files changed, 504 insertions(+) create mode 100644 arch/arm/boards/sysmobts/Makefile create mode 100644 arch/arm/boards/sysmobts/board.c create mode 100644 arch/arm/boards/sysmobts/defaultenv-sysmobts/bin/prepare-ubi create mode 100644 arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/chooser create mode 100644 arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/rescue create mode 100644 arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/rescue-net create mode 100644 arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/system0 create mode 100644 arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/system1 create mode 100644 arch/arm/boards/sysmobts/defaultenv-sysmobts/init/automount-nand create mode 100644 arch/arm/boards/sysmobts/defaultenv-sysmobts/nv/boot.default create mode 100644 arch/arm/boards/sysmobts/defaultenv-sysmobts/nv/linux.bootargs.base create mode 100644 arch/arm/boards/sysmobts/defaultenv-sysmobts/nv/linux.bootargs.console create mode 100644 arch/arm/boards/sysmobts/lowlevel.c create mode 100644 arch/arm/dts/dm6442-sysmobts.dts create mode 100644 arch/arm/dts/dm644x.dtsi diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile index 35aa9a2f5..2f5d0e536 100644 --- a/arch/arm/boards/Makefile +++ b/arch/arm/boards/Makefile @@ -107,6 +107,7 @@ obj-$(CONFIG_MACH_SOCFPGA_EBV_SOCRATES) += ebv-socrates/ obj-$(CONFIG_MACH_SOCFPGA_TERASIC_SOCKIT) += terasic-sockit/ obj-$(CONFIG_MACH_SOLIDRUN_CUBOX) += solidrun-cubox/ obj-$(CONFIG_MACH_SOLIDRUN_MICROSOM) += solidrun-microsom/ +obj-$(CONFIG_MACH_SYSMOBTS) += sysmobts/ obj-$(CONFIG_MACH_TNY_A9260) += tny-a926x/ obj-$(CONFIG_MACH_TNY_A9263) += tny-a926x/ obj-$(CONFIG_MACH_TNY_A9G20) += tny-a926x/ diff --git a/arch/arm/boards/sysmobts/Makefile b/arch/arm/boards/sysmobts/Makefile new file mode 100644 index 000000000..3aa2049a5 --- /dev/null +++ b/arch/arm/boards/sysmobts/Makefile @@ -0,0 +1,3 @@ +obj-y += board.o +lwl-y += lowlevel.o +bbenv-y += defaultenv-sysmobts diff --git a/arch/arm/boards/sysmobts/board.c b/arch/arm/boards/sysmobts/board.c new file mode 100644 index 000000000..bf4a1aafe --- /dev/null +++ b/arch/arm/boards/sysmobts/board.c @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2015 Jan Luebbe + * + * This file is part of barebox. + * See file CREDITS for list of people who contributed to this project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define PINMUX0 0x01c40000 +#define PINMUX1 0x01c40004 +#define PINMUX1_I2C BIT(7) + +#define VDD3P3V_PWDN (0x01c40048) + +#include + +#define EMAC_BASE_ADDR 0x01C80000 +#define EMAC_WRAPPER_BASE_ADDR 0x01C81000 +#define EMAC_WRAPPER_RAM_ADDR 0x01C82000 +#define EMAC_MDIO_BASE_ADDR 0x01C84000 + +static struct resource dm644x_emac_resources[] = { + { + .start = EMAC_BASE_ADDR, + .end = EMAC_BASE_ADDR + 0xff, + .flags = IORESOURCE_MEM, + }, { + .start = EMAC_WRAPPER_BASE_ADDR, + .end = EMAC_WRAPPER_BASE_ADDR + 0xfff, + .flags = IORESOURCE_MEM, + }, { + .start = EMAC_MDIO_BASE_ADDR, + .end = EMAC_MDIO_BASE_ADDR + 0xff, + .flags = IORESOURCE_MEM, + }, { + .start = EMAC_WRAPPER_RAM_ADDR, + .end = EMAC_WRAPPER_RAM_ADDR + 0x1fff, /* 8kB */ + .flags = IORESOURCE_MEM, + } +}; + +static struct davinci_emac_platform_data dm644x_emac_pdata = { + .force_link = false, + .interface_rmii = false, + .phy_addr = 1, +}; + +static struct device_d dm644x_emac_device = { + .id = DEVICE_ID_DYNAMIC, + .name = "davinci_emac", + .num_resources = ARRAY_SIZE(dm644x_emac_resources), + .resource = dm644x_emac_resources, + .platform_data = &dm644x_emac_pdata, +}; + +static void sysmobts_board_detect(void) +{ + int board_ver, board_cfg; + char variant[4]; + + board_ver = gpio_get_value(15); + board_ver |= gpio_get_value(16) << 1; + board_ver |= gpio_get_value(17) << 1; + + board_cfg = gpio_get_value(10); + board_cfg |= gpio_get_value(11) << 1; + board_cfg |= gpio_get_value(12) << 3; + board_cfg |= gpio_get_value(13) << 4; + board_cfg |= gpio_get_value(14) << 4; + + variant[0] = 'A' + board_ver; + variant[1] = '.'; + variant[2] = '0' + board_cfg; + variant[3] = '\0'; + + globalvar_add_simple("board.variant", variant); + + printf("detected 'sysmobts_v2 %s'\n", variant); +} + +static int sysmobts_set_ethaddr(void) +{ + char addr[6]; + int fd, ret; + + fd = open("/dev/eeprom0", O_RDONLY); + if (fd < 0) { + ret = fd; + goto err; + } + + ret = read_full(fd, addr, 6); + if (ret < 0) + goto err_open; + + eth_register_ethaddr(0, addr); + + ret = 0; + +err_open: + close(fd); +err: + if (ret) + pr_err("can't read eeprom /dev/eeprom0 (%s)\n", strerror(ret)); + + return ret; +} + +#define MACH_TYPE_SYSMOBTS_V2 3758 + +static void sysmobts_devices_shutdown(void) +{ + writel(readl(PINMUX1) | PINMUX1_I2C, PINMUX1); +} + +static int sysmobts_coredevices_init(void) +{ + board_shutdown = sysmobts_devices_shutdown; + + writel(0, VDD3P3V_PWDN); + + writel(0x8000000f, PINMUX0); + writel(0x00050187, PINMUX1); + + writel(readl(PINMUX1) & ~PINMUX1_I2C, PINMUX1); + + return 0; +} +coredevice_initcall(sysmobts_coredevices_init); + +static int sysmobts_devices_init(void) +{ + sysmobts_board_detect(); + + sysmobts_set_ethaddr(); + platform_device_register(&dm644x_emac_device); + + defaultenv_append_directory(defaultenv_sysmobts); + + armlinux_set_architecture(MACH_TYPE_SYSMOBTS_V2); + + return 0; +} +device_initcall(sysmobts_devices_init); diff --git a/arch/arm/boards/sysmobts/defaultenv-sysmobts/bin/prepare-ubi b/arch/arm/boards/sysmobts/defaultenv-sysmobts/bin/prepare-ubi new file mode 100644 index 000000000..eea2e785a --- /dev/null +++ b/arch/arm/boards/sysmobts/defaultenv-sysmobts/bin/prepare-ubi @@ -0,0 +1,13 @@ +#!/bin/sh + +if test -e /dev/nand0.root.ubi; then + exit 0 +fi + +ubiattach -d 0 /dev/nand0.root +if [ $? != 0 ]; then + echo "failed to run ubiattach" + exit 1 +fi + +exit 0 diff --git a/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/chooser b/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/chooser new file mode 100644 index 000000000..2112d9894 --- /dev/null +++ b/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/chooser @@ -0,0 +1,3 @@ +#!/bin/sh + +bootchooser -d -w 120 diff --git a/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/rescue b/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/rescue new file mode 100644 index 000000000..7b2c59a0d --- /dev/null +++ b/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/rescue @@ -0,0 +1,8 @@ +#!/bin/sh + +global bootm.image=/mnt/rescue/boot/zImage +#global bootm.oftree= +#global bootm.initrd= + +global linux.bootargs.dyn.root="root=ubi0:rescue ubi.mtd=root rootfstype=ubifs ro rauc.slot=rescue" +global linux.bootargs.dyn.mtd="mtdparts=davinci_nand.0:${nand0.partitions}" diff --git a/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/rescue-net b/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/rescue-net new file mode 100644 index 000000000..9097ce303 --- /dev/null +++ b/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/rescue-net @@ -0,0 +1,8 @@ +#!/bin/sh + +global bootm.image=/mnt/tftp/linux/arch/arm/boot/zImage +#global bootm.oftree= +#global bootm.initrd= + +global linux.bootargs.dyn.root="root=ubi0:rescue ubi.mtd=root rootfstype=ubifs ro rauc.slot=rescue" +global linux.bootargs.dyn.mtd="mtdparts=davinci_nand.0:${nand0.partitions}" diff --git a/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/system0 b/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/system0 new file mode 100644 index 000000000..eb5c7f78d --- /dev/null +++ b/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/system0 @@ -0,0 +1,10 @@ +#!/bin/sh + +global bootm.image=/mnt/system0/kernel +if [ -e /mnt/system0/devicetree ]; then + global bootm.oftree=/mnt/system0/devicetree +fi +global bootm.initrd=/mnt/system0/initramfs + +global linux.bootargs.dyn.root="root=ubi0:system0 ubi.mtd=root rootfstype=ubifs ro rauc.slot=system0" +global linux.bootargs.dyn.mtd="mtdparts=davinci_nand.0:${nand0.partitions}" diff --git a/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/system1 b/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/system1 new file mode 100644 index 000000000..4a4c18e7f --- /dev/null +++ b/arch/arm/boards/sysmobts/defaultenv-sysmobts/boot/system1 @@ -0,0 +1,10 @@ +#!/bin/sh + +global bootm.image=/mnt/system1/kernel +if [ -e /mnt/system1/devicetree ]; then + global bootm.oftree=/mnt/system1/devicetree +fi +global bootm.initrd=/mnt/system1/initramfs + +global linux.bootargs.dyn.root="root=ubi0:system1 ubi.mtd=root rootfstype=ubifs ro rauc.slot=system1" +global linux.bootargs.dyn.mtd="mtdparts=davinci_nand.0:${nand0.partitions}" diff --git a/arch/arm/boards/sysmobts/defaultenv-sysmobts/init/automount-nand b/arch/arm/boards/sysmobts/defaultenv-sysmobts/init/automount-nand new file mode 100644 index 000000000..69f3fe3c4 --- /dev/null +++ b/arch/arm/boards/sysmobts/defaultenv-sysmobts/init/automount-nand @@ -0,0 +1,10 @@ +#!/bin/sh + +mkdir /mnt/system0 +automount -d /mnt/system0 'prepare-ubi && mount /dev/nand0.root.ubi.system0 /mnt/system0' + +mkdir /mnt/system1 +automount -d /mnt/system1 'prepare-ubi && mount /dev/nand0.root.ubi.system1 /mnt/system1' + +mkdir /mnt/rescue +automount -d /mnt/rescue 'prepare-ubi && mount /dev/nand0.root.ubi.rescue /mnt/rescue' diff --git a/arch/arm/boards/sysmobts/defaultenv-sysmobts/nv/boot.default b/arch/arm/boards/sysmobts/defaultenv-sysmobts/nv/boot.default new file mode 100644 index 000000000..669ddaf73 --- /dev/null +++ b/arch/arm/boards/sysmobts/defaultenv-sysmobts/nv/boot.default @@ -0,0 +1 @@ +chooser factory diff --git a/arch/arm/boards/sysmobts/defaultenv-sysmobts/nv/linux.bootargs.base b/arch/arm/boards/sysmobts/defaultenv-sysmobts/nv/linux.bootargs.base new file mode 100644 index 000000000..5826c6307 --- /dev/null +++ b/arch/arm/boards/sysmobts/defaultenv-sysmobts/nv/linux.bootargs.base @@ -0,0 +1 @@ +console=ttyS0,115200n8 diff --git a/arch/arm/boards/sysmobts/defaultenv-sysmobts/nv/linux.bootargs.console b/arch/arm/boards/sysmobts/defaultenv-sysmobts/nv/linux.bootargs.console new file mode 100644 index 000000000..df9016a0c --- /dev/null +++ b/arch/arm/boards/sysmobts/defaultenv-sysmobts/nv/linux.bootargs.console @@ -0,0 +1 @@ +quiet panic=30 diff --git a/arch/arm/boards/sysmobts/lowlevel.c b/arch/arm/boards/sysmobts/lowlevel.c new file mode 100644 index 000000000..57eafffad --- /dev/null +++ b/arch/arm/boards/sysmobts/lowlevel.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2015 Jan Luebbe + * + * This file is part of barebox. + * See file CREDITS for list of people who contributed to this project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * 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. + * + */ + +#define __LOWLEVEL_INIT__ + +#include +#include +#include +#include +#include + +extern char __dtb_dm6442_sysmobts_start[]; + +void __naked __bare_init barebox_arm_reset_vector(void) +{ + void *fdt; + + arm_cpu_lowlevel_init(); + + fdt = __dtb_dm6442_sysmobts_start - get_runtime_offset(); + + barebox_arm_entry(0x80000000, SZ_256M, fdt); +} diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile index cc92bdef8..42724611b 100644 --- a/arch/arm/dts/Makefile +++ b/arch/arm/dts/Makefile @@ -46,6 +46,7 @@ pbl-dtb-$(CONFIG_MACH_SOCFPGA_EBV_SOCRATES) += socfpga_cyclone5_socrates.dtb.o pbl-dtb-$(CONFIG_MACH_SOCFPGA_TERASIC_SOCKIT) += socfpga_cyclone5_sockit.dtb.o pbl-dtb-$(CONFIG_MACH_SOLIDRUN_CUBOX) += dove-cubox-bb.dtb.o pbl-dtb-$(CONFIG_MACH_SOLIDRUN_MICROSOM) += imx6dl-hummingboard.dtb.o +pbl-dtb-$(CONFIG_MACH_SYSMOBTS) += dm6442-sysmobts.dtb.o pbl-dtb-$(CONFIG_MACH_TORADEX_COLIBRI_T20) += tegra20-colibri-iris.dtb.o pbl-dtb-$(CONFIG_MACH_TOSHIBA_AC100) += tegra20-paz00.dtb.o pbl-dtb-$(CONFIG_MACH_TQMA53) += imx53-mba53.dtb.o diff --git a/arch/arm/dts/dm6442-sysmobts.dts b/arch/arm/dts/dm6442-sysmobts.dts new file mode 100644 index 000000000..0baf20374 --- /dev/null +++ b/arch/arm/dts/dm6442-sysmobts.dts @@ -0,0 +1,178 @@ +/dts-v1/; + +#include "dm644x.dtsi" + +/ { + model = "sysmobts"; + compatible = "sysmocom,sysmobts"; + + chosen { + stdout-path = &serial0; + environment@0 { + compatible = "barebox,environment"; + device-path = &env; + }; + }; + + memory { + reg = <0x80000000 0x10000000>; + }; + + soc { + serial0: serial@1c20000 { + status = "okay"; + }; + + wdt: wdt@1c21000 { + status = "okay"; + }; + + gpio: gpio@1c67000 { + status = "okay"; + }; + }; + + nand@0x02000000 { + status = "okay"; + + #address-cells = <1>; + #size-cells = <1>; + + env: partition@0 { + label = "env"; + reg = <0x0 0x20000>; + }; + + partition@1 { + label = "ubl"; + reg = <0x20000 0xa0000>; + }; + + partition@2 { + label = "bootloader"; + reg = <0xc0000 0x340000>; + }; + + partition@3 { + label = "root"; + reg = <0x400000 0x0>; + }; + }; + + i2c: i2c { + compatible = "i2c-gpio"; + gpios = < + &gpio 44 0 /* sda */ + &gpio 43 0 /* scl */ + >; + i2c-gpio,sda-open-drain; + i2c-gpio,scl-open-drain; + #address-cells = <1>; + #size-cells = <0>; + status = "okay"; + + eeprom: eeprom@50 { + compatible = "24c02"; + reg = <0x50>; + + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "state"; + reg = <0x25 0x54>; /* _pad1 in struct sysmobts_eeprom */ + }; + }; + }; + + leds { + compatible = "gpio-leds"; + + status { + gpios = <&gpio 29 0>; + linux,default-trigger = "heartbeat"; + default-state = "off"; + }; + }; + + state: state { + compatible = "barebox,state"; + magic = <0xaabe52dc>; + backend-type = "raw"; + backend = &eeprom, "partname:state"; + + bootstate { + system0 { + #address-cells = <1>; + #size-cells = <1>; + + remaining_attempts { + reg = <0x0 0x1>; + type = "uint8"; + }; + priority { + reg = <0x1 0x1>; + type = "uint8"; + }; + ok { + reg = <0x2 0x1>; + type = "uint8"; + }; + }; + + system1 { + #address-cells = <1>; + #size-cells = <1>; + + remaining_attempts { + reg = <0x3 0x1>; + type = "uint8"; + }; + priority { + reg = <0x4 0x1>; + type = "uint8"; + }; + ok { + reg = <0x5 0x1>; + type = "uint8"; + }; + }; + + rescue { + #address-cells = <1>; + #size-cells = <1>; + + remaining_attempts { + reg = <0x6 0x1>; + type = "uint8"; + }; + priority { + reg = <0x7 0x1>; + type = "uint8"; + }; + ok { + reg = <0x8 0x1>; + type = "uint8"; + }; + }; + }; + }; + + bootstate: bootstate { + compatible = "barebox,bootstate"; + backend-type = "state"; + backend = <&state>; + + system0 { + default_attempts = <3>; + }; + + system1 { + default_attempts = <3>; + }; + + rescue { + default_attempts = <3>; + }; + }; +}; diff --git a/arch/arm/dts/dm644x.dtsi b/arch/arm/dts/dm644x.dtsi new file mode 100644 index 000000000..7c3400e40 --- /dev/null +++ b/arch/arm/dts/dm644x.dtsi @@ -0,0 +1,47 @@ +#include "skeleton.dtsi" + +/ { + soc { + compatible = "simple-bus"; + model = "TI TMS320DM644x"; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x01c00000 0x400000>; + + serial0: serial@1c20000 { + compatible = "ns16550a"; + reg = <0x20000 0x400>; + reg-shift = <2>; + status = "disabled"; + }; + + wdt: wdt@1c21000 { + compatible = "ti,davinci-wdt"; + reg = <0x21C00 0x1000>; + status = "disabled"; + }; + + gpio: gpio@1c67000 { + compatible = "ti,dm6441-gpio"; + gpio-controller; + reg = <0x67000 0x800>; + #gpio-cells = <2>; + ti,ngpio = <71>; + status = "disabled"; + }; + }; + + nand@0x02000000 { + compatible = "ti,davinci-nand"; + reg = <0x02000000 0x2000000 + 0x01E00000 0x1000>; + ti,davinci-chipselect = <0>; + ti,davinci-mask-ale = <0>; + ti,davinci-mask-cle = <0>; + ti,davinci-mask-chipsel = <0>; + nand-ecc-mode = "hw"; + ti,davinci-ecc-bits = <1>; + nand-on-flash-bbt; + status = "disabled"; + }; +}; diff --git a/arch/arm/mach-davinci/Kconfig b/arch/arm/mach-davinci/Kconfig index 56182d8e4..fb614e27a 100644 --- a/arch/arm/mach-davinci/Kconfig +++ b/arch/arm/mach-davinci/Kconfig @@ -10,6 +10,11 @@ config ARCH_DAVINCI_DM644x choice prompt "Davinci Board type" +config MACH_SYSMOBTS + bool "Sysmobts" + select ARCH_DAVINCI_DM644x + select HAVE_DEFAULT_ENVIRONMENT_NEW + config MACH_VIRT2REAL bool "Virt2Real" select HAVE_DEFAULT_ENVIRONMENT_NEW