Re: [PATCH 1/2] ARM: omap: support for WAGO PFC200v3 750-821x

2019-12-13 Thread Ahmad Fatoum
Hello Roland,

On 12/11/19 9:02 PM, Roland Hieber wrote:
> diff --git a/arch/arm/boards/wago-pfc-am335x/ram-timings.h 
> b/arch/arm/boards/wago-pfc-am335x/ram-timings.h
> new file mode 100644
> index ..cc3d518f0c27
> --- /dev/null
> +++ b/arch/arm/boards/wago-pfc-am335x/ram-timings.h
> @@ -0,0 +1,94 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2015 Wadim Egorov, PHYTEC Messtechnik GmbH
> + *
> + * Copyright (C) 2018 WAGO Kontakttechnik GmbH & Co. KG 
> 
> + * Author: Oleg Karfich 
> + */
> +
> +#ifndef __RAM_TIMINGS_H
> +#define __RAM_TIMINGS_H
> +
> +#define DDR_IOCTRL   0x18B
> +
> +struct am335x_sdram_timings {
> + struct am33xx_emif_regs regs;
> + struct am33xx_ddr_data data;
> + struct am33xx_cmd_control cmd_ctrl;
> +};
> +
> +enum {
> + PFC_DDR3_256MB,
> + PFC_DDR3_512MB,
> +};
> +
> +struct am335x_sdram_timings pfc_timings[] = {

This should be static.

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 1/2] ARM: omap: support for WAGO PFC200v3 750-821x

2019-12-13 Thread Sascha Hauer
On Wed, Dec 11, 2019 at 09:02:43PM +0100, Roland Hieber wrote:
> Based on the downstream patch series in the WAGO PFC firmware SDK [1].
> Downstream has support for other boards too, which we leave out for now
> because no devices are available for testing. The upstream device trees
> have been used as-is except that uart0 was set to "okay" so barebox can
> enable the console on startup.
> 
> [1]: 
> https://github.com/WAGO/pfc-firmware-sdk/tree/V03.02.02-FW14/configs/wago-pfcXXX/patches/barebox-2018.10.0
> 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +static int pfc_coredevice_init(void)
> +{
> + if (!of_machine_is_compatible("wago,am335x-pfc"))
> + return 0;
> +
> + am33xx_register_ethaddr(0, 0);
> +
> + return 0;
> +}
> +coredevice_initcall(pfc_coredevice_init);

You register a MAC for eth0 once here...

> +
> +#define ETH_DEVICE   0
> +#define ETHADDR_EEPROM_OFFSET512
> +#define ETHADDR_EEPROM_LENGTH6
> +static int pfc_set_ethaddr(void)
> +{
> + struct cdev *cdev;
> + u8 mac[6];
> + int ret;
> +
> + cdev = cdev_by_name("eeprom0");
> + if (!cdev)
> + return -ENODEV;
> +
> + ret = cdev_read(cdev, mac, ETHADDR_EEPROM_LENGTH, 
> ETHADDR_EEPROM_OFFSET, 0);
> + if (ret < 0)
> + return ret;
> +
> + eth_register_ethaddr(ETH_DEVICE, mac);

And then here again. Please decide, or implement a fallback if one
source doesn't provide a valid MAC address.

> +
> + return 0;
> +}
> +
> +static int pfc_devices_init(void)
> +{
> + int ret;
> +
> + if (!of_machine_is_compatible("wago,am335x-pfc"))
> + return 0;
> +
> + if (bootsource_get() == BOOTSOURCE_MMC) {
> + if (bootsource_get_instance() == 0) {
> + omap_set_bootmmc_devname("mmc0");
> + } else {
> + omap_set_bootmmc_devname("mmc1");
> + am33xx_bbu_emmc_mlo_register_handler("mlo.emmc",
> + "/dev/mmc1");

Why only register an update handler only when we boot from MMC? This
should always be registered.

> + }
> + }
> +
> + of_device_enable_path("/chosen/environment-sd");

This is done unconditionally. Why isn't this enabled in the device tree
already?

> + defaultenv_append_directory(defaultenv_pfc_am335x);
> +
> + ret = pfc_set_ethaddr();
> + if (ret < 0) {
> + pr_info("no valid ethaddr in eeprom found. Using randomized "
> + "MAC address\n");
> + }
> +
> + if (IS_ENABLED(CONFIG_SHELL_NONE))
> + return am33xx_of_register_bootdevice();
> +
> + return 0;
> +}
> +device_initcall(pfc_devices_init);
> diff --git a/arch/arm/boards/wago-pfc-am335x/defaultenv-pfc-am335x/boot/emmc 
> b/arch/arm/boards/wago-pfc-am335x/defaultenv-pfc-am335x/boot/emmc
> new file mode 100644
> index ..9affcbe2ec18
> --- /dev/null
> +++ b/arch/arm/boards/wago-pfc-am335x/defaultenv-pfc-am335x/boot/emmc
> @@ -0,0 +1,4 @@
> +#!/bin/sh
> +global.bootm.image=/mnt/mmc1.0/linuximage
> +global.bootm.oftree=/mnt/mmc1.0/oftree
> +global.linux.bootargs.dyn.root="root=/dev/mmcblk1p2 rw rootwait"
> diff --git a/arch/arm/boards/wago-pfc-am335x/defaultenv-pfc-am335x/boot/mmc 
> b/arch/arm/boards/wago-pfc-am335x/defaultenv-pfc-am335x/boot/mmc
> new file mode 100644
> index ..1430a0f76614
> --- /dev/null
> +++ b/arch/arm/boards/wago-pfc-am335x/defaultenv-pfc-am335x/boot/mmc
> @@ -0,0 +1,4 @@
> +#!/bin/sh
> +global.bootm.image=/mnt/mmc0.0/linuximage
> +global.bootm.oftree=/mnt/mmc0.0/oftree
> +global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rw rootwait"
> diff --git 
> a/arch/arm/boards/wago-pfc-am335x/defaultenv-pfc-am335x/init/bootsource 
> b/arch/arm/boards/wago-pfc-am335x/defaultenv-pfc-am335x/init/bootsource
> new file mode 100644
> index ..f35c7df46e03
> --- /dev/null
> +++ b/arch/arm/boards/wago-pfc-am335x/defaultenv-pfc-am335x/init/bootsource
> @@ -0,0 +1,12 @@
> +#!/bin/sh
> +if [ -n "$nv.boot.default" ]; then
> + exit
> +fi
> +
> +if [ $bootsource = mmc -a $bootsource_instance = 1 ]; then
> + global.boot.default="emmc mmc net"
> +elif [ $bootsource = mmc -a $bootsource_instance = 0 ]; then
> + global.boot.default="mmc emmc net"
> +elif [ $bootsource = net ]; then
> + global.boot.default="net emmc mmc"
> +fi
> diff --git a/arch/arm/boards/wago-pfc-am335x/lowlevel.c 
> b/arch/arm/boards/wago-pfc-am335x/lowlevel.c
> new file mode 100644
> index ..78112cb03cd6
> --- /dev/null
> +++ b/arch/arm/boards/wago-pfc-am335x/lowlevel.c
> @@ -0,0 +1,98 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2015 Wadim Egorov, PHYTEC Messtechnik GmbH
> + *
> + * Copyright (C) 2018 WAGO Kontakttechnik GmbH & Co. KG 
> 
> + * Author: Oleg Karfich 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#inc

[PATCH 1/2] ARM: omap: support for WAGO PFC200v3 750-821x

2019-12-11 Thread Roland Hieber
Based on the downstream patch series in the WAGO PFC firmware SDK [1].
Downstream has support for other boards too, which we leave out for now
because no devices are available for testing. The upstream device trees
have been used as-is except that uart0 was set to "okay" so barebox can
enable the console on startup.

[1]: 
https://github.com/WAGO/pfc-firmware-sdk/tree/V03.02.02-FW14/configs/wago-pfcXXX/patches/barebox-2018.10.0

Signed-off-by: Roland Hieber 
---
 Documentation/boards/am335x.rst   |   2 +
 Documentation/boards/am335x/wago-pfc.rst  |  90 +++
 arch/arm/boards/Makefile  |   1 +
 arch/arm/boards/wago-pfc-am335x/Makefile  |   3 +
 arch/arm/boards/wago-pfc-am335x/board.c   |  86 +++
 .../defaultenv-pfc-am335x/boot/emmc   |   4 +
 .../defaultenv-pfc-am335x/boot/mmc|   4 +
 .../defaultenv-pfc-am335x/init/bootsource |  12 +
 arch/arm/boards/wago-pfc-am335x/lowlevel.c|  98 
 arch/arm/boards/wago-pfc-am335x/ram-timings.h |  94 
 arch/arm/configs/am335x_mlo_defconfig |   1 +
 arch/arm/configs/omap_defconfig   |   1 +
 arch/arm/dts/Makefile |   2 +
 arch/arm/dts/am335x-pfc-750_821x-mlo.dts  |  31 +++
 arch/arm/dts/am335x-pfc-750_821x.dts  |  66 +
 arch/arm/dts/am335x-pfc-emmc.dtsi |  29 +++
 arch/arm/dts/am335x-pfc-leds.dtsi | 203 
 arch/arm/dts/am335x-pfc-nand.dtsi |  89 +++
 arch/arm/dts/am335x-pfc-rmii12.dtsi   |  62 +
 arch/arm/dts/am335x-pfc-rmii2.dtsi|  40 +++
 arch/arm/dts/am335x-pfc-strip.dtsi|  48 
 arch/arm/dts/am335x-pfc.dtsi  | 228 ++
 arch/arm/mach-omap/Kconfig|   7 +
 images/Makefile.am33xx|   8 +
 24 files changed, 1209 insertions(+)
 create mode 100644 Documentation/boards/am335x/wago-pfc.rst
 create mode 100644 arch/arm/boards/wago-pfc-am335x/Makefile
 create mode 100644 arch/arm/boards/wago-pfc-am335x/board.c
 create mode 100644 
arch/arm/boards/wago-pfc-am335x/defaultenv-pfc-am335x/boot/emmc
 create mode 100644 
arch/arm/boards/wago-pfc-am335x/defaultenv-pfc-am335x/boot/mmc
 create mode 100644 
arch/arm/boards/wago-pfc-am335x/defaultenv-pfc-am335x/init/bootsource
 create mode 100644 arch/arm/boards/wago-pfc-am335x/lowlevel.c
 create mode 100644 arch/arm/boards/wago-pfc-am335x/ram-timings.h
 create mode 100644 arch/arm/dts/am335x-pfc-750_821x-mlo.dts
 create mode 100644 arch/arm/dts/am335x-pfc-750_821x.dts
 create mode 100644 arch/arm/dts/am335x-pfc-emmc.dtsi
 create mode 100644 arch/arm/dts/am335x-pfc-leds.dtsi
 create mode 100644 arch/arm/dts/am335x-pfc-nand.dtsi
 create mode 100644 arch/arm/dts/am335x-pfc-rmii12.dtsi
 create mode 100644 arch/arm/dts/am335x-pfc-rmii2.dtsi
 create mode 100644 arch/arm/dts/am335x-pfc-strip.dtsi
 create mode 100644 arch/arm/dts/am335x-pfc.dtsi

diff --git a/Documentation/boards/am335x.rst b/Documentation/boards/am335x.rst
index f54611428bb3..0da479a1c3f0 100644
--- a/Documentation/boards/am335x.rst
+++ b/Documentation/boards/am335x.rst
@@ -30,6 +30,8 @@ resulting images will be placed under ``images/``:
 
 Some boards come in different variants, make sure to pick the correct one.
 
+.. _am335x_starting_barebox:
+
 Starting and updating barebox
 -
 
diff --git a/Documentation/boards/am335x/wago-pfc.rst 
b/Documentation/boards/am335x/wago-pfc.rst
new file mode 100644
index ..bec2a7c1f05a
--- /dev/null
+++ b/Documentation/boards/am335x/wago-pfc.rst
@@ -0,0 +1,90 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+WAGO PFC200 Fieldbus Controllers (AM335x based)
+
+
+These devices already run a version of Barebox out of the box,
+although the debug console is disabled in the factory settings.
+
+Currently supported devices:
+
+* WAGO PFC200v3 750-8214
+
+Initial Device Preparation
+--
+
+The factory firmware looks for an MLO on the eMMC first.
+If nothing bootable is found there, the ROM code searches for a loader on the
+SD card instead.
+This means we have to erase the internal MLO in order to boot from the SD card.
+
+#. If you haven't set up your device yet,
+   grab a current `firmware `_,
+   write it to an SD card, and boot the device with it.
+   You also need a DHCP server to connect to the device over ethernet.
+
+#. Connect to the web interface and log in with admin privileges.
+   (The default user is ``admin``, password ``wago``).
+
+#. Make sure that SSH is enabled and root login is allowed in
+   *Ports and Services* → *SSH*.
+
+#. Connect to the device over SSH, using user ``root`` and password ``wago``.
+
+#. The eMMC boot partition is */dev/mmcblk1p1*, which contains boot loaders
+   for several PFC variants (probably as a backup?),
+   but only the file named ``mlo`