Re: [PATCH v2 1/2] spi: Port SiFive SPI controller driver

2022-04-29 Thread Sascha Hauer
On Tue, Apr 26, 2022 at 08:46:03AM +0200, Ahmad Fatoum wrote:
> Import the U-Boot v2022.04-rc2 driver to enable access to SPI flash and
> SD over SPI on the HiFive Unleashed. Tested with QEMU.
> 
> Signed-off-by: Ahmad Fatoum 
> ---
> v1 -> v2:
>   - remove unused wait_for_bit (Sascha)
>   - move prep and CS handling out of transfer_one into callers (Sascha)
>   - Use nbytes instead of bitlen as code is bytewise anyway (Sascha)
>   - remove superfluous pos variable (Sascha)
> ---
>  drivers/spi/Kconfig  |   6 +
>  drivers/spi/Makefile |   1 +
>  drivers/spi/spi-sifive.c | 521 +++
>  3 files changed, 528 insertions(+)
>  create mode 100644 drivers/spi/spi-sifive.c

Applied, thanks

Sascha

> 
> diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
> index 7df7561718c2..8935feb97b99 100644
> --- a/drivers/spi/Kconfig
> +++ b/drivers/spi/Kconfig
> @@ -124,6 +124,12 @@ config SPI_NXP_FLEXSPI
> This controller does not support generic SPI messages and only
> supports the high-level SPI memory interface.
>  
> +config SPI_SIFIVE
> + tristate "SiFive SPI controller"
> + depends on SOC_SIFIVE || COMPILE_TEST
> + help
> +   This exposes the SPI controller IP from SiFive.
> +
>  endif
>  
>  endmenu
> diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
> index 64c8e2645a94..3455eea86988 100644
> --- a/drivers/spi/Makefile
> +++ b/drivers/spi/Makefile
> @@ -17,3 +17,4 @@ obj-$(CONFIG_DRIVER_SPI_DSPI) += dspi_spi.o
>  obj-$(CONFIG_SPI_ZYNQ_QSPI) += zynq_qspi.o
>  obj-$(CONFIG_SPI_NXP_FLEXSPI) += spi-nxp-fspi.o
>  obj-$(CONFIG_DRIVER_SPI_STM32) += stm32_spi.o
> +obj-$(CONFIG_SPI_SIFIVE) += spi-sifive.o
> diff --git a/drivers/spi/spi-sifive.c b/drivers/spi/spi-sifive.c
> new file mode 100644
> index ..713bcc0c3bd8
> --- /dev/null
> +++ b/drivers/spi/spi-sifive.c
> @@ -0,0 +1,521 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright 2018 SiFive, Inc.
> + * Copyright 2019 Bhargav Shah 
> + *
> + * SiFive SPI controller driver (master mode only)
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define SIFIVE_SPI_MAX_CS32
> +
> +#define SIFIVE_SPI_DEFAULT_DEPTH 8
> +#define SIFIVE_SPI_DEFAULT_BITS  8
> +
> +/* register offsets */
> +#define SIFIVE_SPI_REG_SCKDIV0x00 /* Serial clock divisor */
> +#define SIFIVE_SPI_REG_SCKMODE   0x04 /* Serial clock mode */
> +#define SIFIVE_SPI_REG_CSID  0x10 /* Chip select ID */
> +#define SIFIVE_SPI_REG_CSDEF 0x14 /* Chip select default */
> +#define SIFIVE_SPI_REG_CSMODE0x18 /* Chip select mode */
> +#define SIFIVE_SPI_REG_DELAY00x28 /* Delay control 0 */
> +#define SIFIVE_SPI_REG_DELAY10x2c /* Delay control 1 */
> +#define SIFIVE_SPI_REG_FMT   0x40 /* Frame format */
> +#define SIFIVE_SPI_REG_TXDATA0x48 /* Tx FIFO data */
> +#define SIFIVE_SPI_REG_RXDATA0x4c /* Rx FIFO data */
> +#define SIFIVE_SPI_REG_TXMARK0x50 /* Tx FIFO watermark */
> +#define SIFIVE_SPI_REG_RXMARK0x54 /* Rx FIFO watermark */
> +#define SIFIVE_SPI_REG_FCTRL 0x60 /* SPI flash interface control 
> */
> +#define SIFIVE_SPI_REG_FFMT  0x64 /* SPI flash instruction 
> format */
> +#define SIFIVE_SPI_REG_IE0x70 /* Interrupt Enable Register */
> +#define SIFIVE_SPI_REG_IP0x74 /* Interrupt Pendings Register 
> */
> +
> +/* sckdiv bits */
> +#define SIFIVE_SPI_SCKDIV_DIV_MASK   0xfffU
> +
> +/* sckmode bits */
> +#define SIFIVE_SPI_SCKMODE_PHA   BIT(0)
> +#define SIFIVE_SPI_SCKMODE_POL   BIT(1)
> +#define SIFIVE_SPI_SCKMODE_MODE_MASK (SIFIVE_SPI_SCKMODE_PHA | \
> +   SIFIVE_SPI_SCKMODE_POL)
> +
> +/* csmode bits */
> +#define SIFIVE_SPI_CSMODE_MODE_AUTO  0U
> +#define SIFIVE_SPI_CSMODE_MODE_HOLD  2U
> +#define SIFIVE_SPI_CSMODE_MODE_OFF   3U
> +
> +/* delay0 bits */
> +#define SIFIVE_SPI_DELAY0_CSSCK(x)   ((u32)(x))
> +#define SIFIVE_SPI_DELAY0_CSSCK_MASK 0xffU
> +#define SIFIVE_SPI_DELAY0_SCKCS(x)   ((u32)(x) << 16)
> +#define SIFIVE_SPI_DELAY0_SCKCS_MASK (0xffU << 16)
> +
> +/* delay1 bits */
> +#define SIFIVE_SPI_DELAY1_INTERCS(x) ((u32)(x))
> +#define SIFIVE_SPI_DELAY1_INTERCS_MASK   0xffU
> +#define SIFIVE_SPI_DELAY1_INTERXFR(x)((u32)(x) << 16)
> +#define SIFIVE_SPI_DELAY1_INTERXFR_MASK  (0xffU << 16)
> +
> +/* fmt bits */
> +#define SIFIVE_SPI_FMT_PROTO_SINGLE  0U
> +#define SIFIVE_SPI_FMT_PROTO_DUAL1U
> +#define SIFIVE_SPI_FMT_PROTO_QUAD2U
> +#define SIFIVE_SPI_FMT_PROTO_MASK3U
> +#define SIFIVE_SPI_FMT_ENDIANBIT(2)
> +#define SIFIVE_SPI_FMT_DIR   BIT(3)
> +#define SIFIVE_SPI_FMT_LEN(x)

Re: [PATCH] gpiolib: remove declaration of now unused variable

2022-04-29 Thread Sascha Hauer
On Tue, Apr 26, 2022 at 08:46:19AM +0200, Ahmad Fatoum wrote:
> Since commit f349b662674e ("gpio: allocate dynamic gpio numbers
> top down"), the variable is now unused and warned about, so remove it.
> 
> Signed-off-by: Ahmad Fatoum 
> ---
>  drivers/gpio/gpiolib.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied to master, thanks

Sascha

> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index c9b33bcd6c2b..10cb7b389555 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -609,7 +609,7 @@ int gpiod_get(struct device_d *dev, const char *_con_id, 
> enum gpiod_flags flags)
>  
>  int gpiochip_add(struct gpio_chip *chip)
>  {
> - int base, i;
> + int i;
>  
>   if (chip->base >= 0) {
>   for (i = 0; i < chip->ngpio; i++) {
> -- 
> 2.34.1
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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] Documentation: remote-control: be explicit about python2 requirement

2022-04-29 Thread Sascha Hauer
On Tue, Apr 26, 2022 at 08:46:58AM +0200, Ahmad Fatoum wrote:
> This should help users a bit when using the tool.
> 
> Signed-off-by: Ahmad Fatoum 
> ---
>  Documentation/user/remote-control.rst | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied to master, thanks

Sascha

> 
> diff --git a/Documentation/user/remote-control.rst 
> b/Documentation/user/remote-control.rst
> index c8b7442f175a..43f1fb3118ea 100644
> --- a/Documentation/user/remote-control.rst
> +++ b/Documentation/user/remote-control.rst
> @@ -54,7 +54,7 @@ account via:
>  
>  .. code-block:: sh
>  
> -  pip install --user crcmod enum enum34
> +  python2 -m pip install --user crcmod enum enum34
>  
>  configuring bbremote
>  
> -- 
> 2.34.1
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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 v3] arm: boards: Add support for MYIR MYD-AM335X Development Board

2022-04-29 Thread Sascha Hauer
On Tue, Apr 26, 2022 at 10:04:40AM +0300, Alexander Shiyan wrote:
> The MYD-AM335X Development Board designed by MYIR is a high-performance
> ARM Evaluation Module (EVM) using the MYC-AM335X CPU module as the core
> controller board. It is based on up to 1GHz Texas Instruments (TI)
> Sitara AM335x family of ARM Cortex-A8 Microprocessors (MPUs) that deliver
> high DMIPs at a low cost while also delivering optional 3D graphics
> acceleration and key peripherals.
> 
> Signed-off-by: Alexander Shiyan 
> ---
>  arch/arm/boards/Makefile  |   1 +
>  arch/arm/boards/myirtech-x335x/Makefile   |   3 +
>  arch/arm/boards/myirtech-x335x/board.c|  44 +++
>  .../defaultenv-myirtech-x335x/boot/nand   |   4 +
>  .../defaultenv-myirtech-x335x/nv/boot.default |   1 +
>  arch/arm/boards/myirtech-x335x/lowlevel.c | 115 ++
>  arch/arm/configs/am335x_mlo_defconfig |   1 +
>  arch/arm/configs/omap_defconfig   |   3 +-
>  arch/arm/dts/Makefile |   1 +
>  arch/arm/dts/am335x-myirtech-myd.dts  |  47 +++
>  arch/arm/mach-omap/Kconfig|   6 +
>  .../arm/mach-omap/include/mach/am33xx-clock.h |   1 +
>  .../mach-omap/include/mach/am33xx-silicon.h   |   2 +
>  images/Makefile.am33xx|   8 ++
>  14 files changed, 236 insertions(+), 1 deletion(-)
>  create mode 100644 arch/arm/boards/myirtech-x335x/Makefile
>  create mode 100644 arch/arm/boards/myirtech-x335x/board.c
>  create mode 100644 
> arch/arm/boards/myirtech-x335x/defaultenv-myirtech-x335x/boot/nand
>  create mode 100644 
> arch/arm/boards/myirtech-x335x/defaultenv-myirtech-x335x/nv/boot.default
>  create mode 100644 arch/arm/boards/myirtech-x335x/lowlevel.c
>  create mode 100644 arch/arm/dts/am335x-myirtech-myd.dts

Applied, thanks

Sascha


-- 
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] ata: disk_ata_drive: clean up code in ata_dump_id()

2022-04-29 Thread Sascha Hauer
On Tue, Apr 26, 2022 at 03:34:34PM +0300, Denis Orlov wrote:
> Add missing macros and fix misspellings.
> 
> Signed-off-by: Denis Orlov 
> ---
>  drivers/ata/disk_ata_drive.c | 23 +--
>  include/ata_drive.h  |  5 +
>  2 files changed, 18 insertions(+), 10 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c
> index f36e06328c..7df0879b19 100644
> --- a/drivers/ata/disk_ata_drive.c
> +++ b/drivers/ata/disk_ata_drive.c
> @@ -80,9 +80,9 @@ static void __maybe_unused ata_dump_id(uint16_t *id)
>   ata_id_c_string(id, product, ATA_ID_PROD, sizeof(product));
>   printf("Product model number: %s\n\r", product);
>  
> - /* Total sectors of device  */
> + /* Total sectors of device */
>   n_sectors = ata_id_n_sectors(id);
> - printf("Capablity: %lld sectors\n\r", n_sectors);
> + printf("Capacity: %lld sectors\n\r", n_sectors);
>  
>   printf ("id[49]: capabilities = 0x%04x\n"
>   "id[53]: field valid = 0x%04x\n"
> @@ -95,12 +95,14 @@ static void __maybe_unused ata_dump_id(uint16_t *id)
>   id[ATA_ID_PIO_MODES],
>   id[ATA_ID_QUEUE_DEPTH]);
>  
> - printf ("id[76]: sata capablity = 0x%04x\n"
> + printf ("id[76]: sata capabilities 1 = 0x%04x\n"
> + "id[77]: sata capabilities 2 = 0x%04x\n"
>   "id[78]: sata features supported = 0x%04x\n"
> - "id[79]: sata features enable = 0x%04x\n",
> - id[76], /* FIXME */
> - id[78], /* FIXME */
> - id[79]); /* FIXME */
> + "id[79]: sata features enabled = 0x%04x\n",
> + id[ATA_ID_SATA_CAPAB_1],
> + id[ATA_ID_SATA_CAPAB_2],
> + id[ATA_ID_SATA_FEAT_SUPP],
> + id[ATA_ID_SATA_FEAT_ENABLE]);
>  
>   printf ("id[80]: major version = 0x%04x\n"
>   "id[81]: minor version = 0x%04x\n"
> @@ -108,12 +110,13 @@ static void __maybe_unused ata_dump_id(uint16_t *id)
>   "id[83]: command set supported 2 = 0x%04x\n"
>   "id[84]: command set extension = 0x%04x\n",
>   id[ATA_ID_MAJOR_VER],
> - id[81], /* FIXME */
> + id[ATA_ID_MINOR_VER],
>   id[ATA_ID_COMMAND_SET_1],
>   id[ATA_ID_COMMAND_SET_2],
>   id[ATA_ID_CFSSE]);
> - printf ("id[85]: command set enable 1 = 0x%04x\n"
> - "id[86]: command set enable 2 = 0x%04x\n"
> +
> + printf ("id[85]: command set enabled 1 = 0x%04x\n"
> + "id[86]: command set enabled 2 = 0x%04x\n"
>   "id[87]: command set default = 0x%04x\n"
>   "id[88]: udma = 0x%04x\n"
>   "id[93]: hardware reset result = 0x%04x\n",
> diff --git a/include/ata_drive.h b/include/ata_drive.h
> index 6b8915c9cb..e11172ba39 100644
> --- a/include/ata_drive.h
> +++ b/include/ata_drive.h
> @@ -67,7 +67,12 @@ enum {
>   ATA_ID_MWDMA_MODES  = 63,
>   ATA_ID_PIO_MODES= 64,
>   ATA_ID_QUEUE_DEPTH  = 75,
> + ATA_ID_SATA_CAPAB_1 = 76,
> + ATA_ID_SATA_CAPAB_2 = 77,
> + ATA_ID_SATA_FEAT_SUPP   = 78,
> + ATA_ID_SATA_FEAT_ENABLE = 79,
>   ATA_ID_MAJOR_VER= 80,
> + ATA_ID_MINOR_VER= 81,
>   ATA_ID_COMMAND_SET_1= 82,
>   ATA_ID_COMMAND_SET_2= 83,
>   ATA_ID_CFSSE= 84,
> -- 
> 2.20.1
> 
> 

-- 
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 master] mci: stm32_sdmmc2: add STM32MP131 AMBA primecell peripheral ID

2022-04-29 Thread Sascha Hauer
On Tue, Apr 26, 2022 at 04:15:04PM +0200, Ahmad Fatoum wrote:
> v5.18-rc1 device tree now features different peripheral ID. As
> peripheral IDs have no fallbacks, this meant broken SD on STM32MP131.
> 
> Add new peripheral ID without special handling as IP is
> backwards-compatible. DT also contains a st,stm32-sdmmc2 compatible,
> which we could match against in future, but for now this isn't
> necessary.
> 
> Fixes: b01786baa849 ("dts: update to v5.18-rc1")
> Signed-off-by: Ahmad Fatoum 
> ---
>  drivers/mci/stm32_sdmmc2.c | 5 +
>  1 file changed, 5 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/drivers/mci/stm32_sdmmc2.c b/drivers/mci/stm32_sdmmc2.c
> index 0c620427ee44..40ffc17908b2 100644
> --- a/drivers/mci/stm32_sdmmc2.c
> +++ b/drivers/mci/stm32_sdmmc2.c
> @@ -643,6 +643,11 @@ static struct amba_id stm32_sdmmc2_ids[] = {
>   .id = 0x00253180,
>   .mask   = 0xf0ff,
>   },
> + /* ST Micro STM32MP13 */
> + {
> + .id = 0x20253180,
> + .mask   = 0xf0ff,
> + },
>   { 0, 0 },
>  };
>  
> -- 
> 2.30.2
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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 v1] net: dsa: wait until PHY aneg is done

2022-04-29 Thread Sascha Hauer
On Wed, Apr 27, 2022 at 09:33:40AM +0200, Oleksij Rempel wrote:
> Some PHYs need a bit longer to complete auto negotiation. So, wait long
> enough until this process is done.
> 
> Signed-off-by: Oleksij Rempel 
> ---
>  drivers/net/dsa.c | 4 
>  1 file changed, 4 insertions(+)

Applied, thanks

Sascha


> 
> diff --git a/drivers/net/dsa.c b/drivers/net/dsa.c
> index f2420d306f..d9e629cefc 100644
> --- a/drivers/net/dsa.c
> +++ b/drivers/net/dsa.c
> @@ -111,6 +111,10 @@ static int dsa_port_start(struct eth_device *edev)
>  
>   dsa_port_set_ethaddr(edev);
>  
> + ret = phy_wait_aneg_done(dp->edev.phydev);
> + if (ret)
> + return ret;
> +
>   if (ops->port_enable) {
>   ret = ops->port_enable(dp, dp->index, dp->edev.phydev);
>   if (ret)
> -- 
> 2.30.2
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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


[PATCH v4 5/5] ARM: boards: protonic-imx6: add HW revision specific machine compatible

2022-04-29 Thread Oleksij Rempel
Currently we use generic/pinned machine compatible for different HW
revisions. With this patch we extend this compatible string with HW
revision specific.

Signed-off-by: Oleksij Rempel 
---
 arch/arm/boards/protonic-imx6/board.c | 22 ++
 arch/arm/mach-imx/Kconfig |  1 +
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boards/protonic-imx6/board.c 
b/arch/arm/boards/protonic-imx6/board.c
index 0fadd148b4..cdbb8debe6 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -126,6 +126,22 @@ static const struct gpio prt_imx6_kvg_gpios[] = {
},
 };
 
+static int prt_of_fixup_hwrev(struct prt_imx6_priv *priv)
+{
+   const char *compat;
+   char *buf;
+
+   compat = of_device_get_match_compatible(priv->dev);
+
+   buf = xasprintf("%s-m%u-r%u", compat, priv->hw_id,
+   priv->hw_rev);
+   barebox_set_of_machine_compatible(buf);
+
+   free(buf);
+
+   return 0;
+}
+
 static int prt_imx6_read_rfid(struct prt_imx6_priv *priv, void *buf,
  size_t size)
 {
@@ -797,7 +813,6 @@ exit_get_dcfg:
 static int prt_imx6_probe(struct device_d *dev)
 {
struct prt_imx6_priv *priv;
-   const char *name, *ptr;
struct param_d *p;
int ret;
 
@@ -806,9 +821,7 @@ static int prt_imx6_probe(struct device_d *dev)
return -ENOMEM;
 
priv->dev = dev;
-   name = of_device_get_match_compatible(priv->dev);
-   ptr = strchr(name, ',');
-   priv->name =  ptr ? ptr + 1 : name;
+   priv->name = of_get_machine_compatible();
 
pr_info("Detected machine type: %s\n", priv->name);
 
@@ -818,6 +831,7 @@ static int prt_imx6_probe(struct device_d *dev)
 
pr_info("  HW type: %d\n", priv->hw_id);
pr_info("  HW revision: %d\n", priv->hw_rev);
+   prt_of_fixup_hwrev(priv);
 
ret = prt_imx6_get_dcfg(priv);
if (ret)
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index ee313a1502..147cd000f9 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -351,6 +351,7 @@ config MACH_PROTONIC_IMX6
select ARCH_IMX6UL
select ARM_USE_COMPRESSED_DTB
select SERIAL_NUMBER_FIXUP
+   select MACHINE_FIXUP
 
 config MACH_PROTONIC_IMX8M
bool "Protonic-Holland i.MX8Mx based boards"
-- 
2.30.2


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


[PATCH v4 3/5] of: add generic of_fixup_machine_compatible()

2022-04-29 Thread Oleksij Rempel
Add generic function to extend/fixup machine compatible.

Signed-off-by: Oleksij Rempel 
---
 common/Kconfig   |  5 +
 common/misc.c| 23 +++
 common/oftree.c  | 41 +
 include/common.h |  3 +++
 include/of.h |  6 ++
 5 files changed, 78 insertions(+)

diff --git a/common/Kconfig b/common/Kconfig
index e77e0c78c5..d602ef3444 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1066,6 +1066,11 @@ config MACHINE_ID
  Note: if no hashable information is available no machine id will be 
passed
  to the kernel.
 
+config MACHINE_FIXUP
+   bool "fix up machine compatible"
+   help
+ fixup machine compatible supplied by board code into device tree
+
 config SERIAL_NUMBER_FIXUP
bool "fix up board serial number"
help
diff --git a/common/misc.c b/common/misc.c
index 3b3bc05bfd..0f6de3e9e5 100644
--- a/common/misc.c
+++ b/common/misc.c
@@ -150,6 +150,7 @@ BAREBOX_MAGICVAR(global.model, "Product name of this 
hardware");
 
 static char *hostname;
 static char *serial_number;
+static char *of_machine_compatible;
 
 /*
  * The hostname is supposed to be the shortname of a board. It should
@@ -195,6 +196,28 @@ const char *barebox_get_serial_number(void)
 
 BAREBOX_MAGICVAR(global.serial_number, "Board serial number");
 
+void barebox_set_of_machine_compatible(const char *__compatible)
+{
+   free(of_machine_compatible);
+   of_machine_compatible = xstrdup(__compatible);
+}
+
+const char *barebox_get_of_machine_compatible(void)
+{
+   return of_machine_compatible;
+}
+
+static int of_kernel_init(void)
+{
+   globalvar_add_simple_string("of.kernel.add_machine_compatible",
+   &of_machine_compatible);
+
+   return 0;
+}
+device_initcall(of_kernel_init);
+
+BAREBOX_MAGICVAR(global.of.kernel.add_machine_compatible, "Additional 
machine/board compatible");
+
 void __noreturn panic(const char *fmt, ...)
 {
va_list args;
diff --git a/common/oftree.c b/common/oftree.c
index c6d75055cc..76239476e0 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -216,6 +216,15 @@ static int of_fixup_bootargs(struct device_node *root, 
void *unused)
 
}
 
+   if (IS_ENABLED(CONFIG_MACHINE_FIXUP)) {
+   const char *compat;
+
+   compat = getenv("global.of.kernel.add_machine_compatible");
+   if (compat)
+   of_fixup_machine_compatible(root, compat);
+
+   }
+
node = of_create_node(root, "/chosen");
if (!node)
return -ENOMEM;
@@ -487,3 +496,35 @@ int of_autoenable_i2c_by_component(char *path)
 
return ret;
 }
+
+int of_fixup_machine_compatible(struct device_node *root, const char *compat)
+{
+   int cclen = 0, clen = strlen(compat) + 1;
+   const char *curcompat;
+   void *buf;
+
+   if (!root) {
+   root = of_get_root_node();
+   if (!root)
+   return -ENODEV;
+   }
+
+   curcompat = of_get_property(root, "compatible", &cclen);
+
+   buf = xzalloc(cclen + clen);
+
+   memcpy(buf, compat, clen);
+
+   if (curcompat)
+   memcpy(buf + clen, curcompat, cclen);
+
+   /*
+* Prepend the compatible from board entry to the machine compatible.
+* Used to match bootspec entries against it.
+*/
+   of_set_property(root, "compatible", buf, cclen + clen, true);
+
+   free(buf);
+
+   return 0;
+}
diff --git a/include/common.h b/include/common.h
index 967502a7ab..bd12035688 100644
--- a/include/common.h
+++ b/include/common.h
@@ -129,4 +129,7 @@ void barebox_set_hostname_no_overwrite(const char *);
 const char *barebox_get_serial_number(void);
 void barebox_set_serial_number(const char *);
 
+void barebox_set_of_machine_compatible(const char *);
+const char *barebox_get_of_machine_compatible(void);
+
 #endif /* __COMMON_H_ */
diff --git a/include/of.h b/include/of.h
index cf9950e9b3..9f514c5ec2 100644
--- a/include/of.h
+++ b/include/of.h
@@ -316,6 +316,7 @@ struct device_node *of_find_node_by_path_or_alias(struct 
device_node *root,
const char *str);
 int of_autoenable_device_by_path(char *path);
 int of_autoenable_i2c_by_component(char *path);
+int of_fixup_machine_compatible(struct device_node *root, const char *compat);
 #else
 static inline bool of_node_name_eq(const struct device_node *np, const char 
*name)
 {
@@ -834,6 +835,11 @@ static inline int of_autoenable_i2c_by_component(char 
*path)
return -ENODEV;
 }
 
+static int of_fixup_machine_compatible(struct device_node *root,
+  const char *compat)
+{
+   return -ENODEV;
+}
 
 #endif
 
-- 
2.30.2


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


[PATCH v4 1/5] common: add $global.serial_number with device tree fixup

2022-04-29 Thread Oleksij Rempel
From: Ahmad Fatoum 

This new variable can be set by boards from C code or from the
environment to change the serial number fixed up into the kernel device
tree.

Signed-off-by: Ahmad Fatoum 
Signed-off-by: Oleksij Rempel 
---
 common/Kconfig   |  5 +
 common/misc.c| 16 
 common/oftree.c  |  9 +
 include/common.h |  3 +++
 4 files changed, 33 insertions(+)

diff --git a/common/Kconfig b/common/Kconfig
index f7a6a96e87..e77e0c78c5 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1066,6 +1066,11 @@ config MACHINE_ID
  Note: if no hashable information is available no machine id will be 
passed
  to the kernel.
 
+config SERIAL_NUMBER_FIXUP
+   bool "fix up board serial number"
+   help
+ fixup serial number supplied by board code into device tree
+
 config SYSTEMD_OF_WATCHDOG
bool "inform devicetree-enabled kernel of used watchdog"
depends on WATCHDOG && OFTREE && FLEXIBLE_BOOTARGS
diff --git a/common/misc.c b/common/misc.c
index 226635f0d4..3b3bc05bfd 100644
--- a/common/misc.c
+++ b/common/misc.c
@@ -149,6 +149,7 @@ EXPORT_SYMBOL(barebox_get_model);
 BAREBOX_MAGICVAR(global.model, "Product name of this hardware");
 
 static char *hostname;
+static char *serial_number;
 
 /*
  * The hostname is supposed to be the shortname of a board. It should
@@ -179,6 +180,21 @@ EXPORT_SYMBOL(barebox_set_hostname_no_overwrite);
 BAREBOX_MAGICVAR(global.hostname,
"shortname of the board. Also used as hostname for DHCP 
requests");
 
+void barebox_set_serial_number(const char *__serial_number)
+{
+   globalvar_add_simple_string("serial_number", &serial_number);
+
+   free(serial_number);
+   serial_number = xstrdup(__serial_number);
+}
+
+const char *barebox_get_serial_number(void)
+{
+   return serial_number;
+}
+
+BAREBOX_MAGICVAR(global.serial_number, "Board serial number");
+
 void __noreturn panic(const char *fmt, ...)
 {
va_list args;
diff --git a/common/oftree.c b/common/oftree.c
index bce0ff09d6..c6d75055cc 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -207,6 +207,15 @@ static int of_fixup_bootargs(struct device_node *root, 
void *unused)
int instance = reset_source_get_instance();
struct device_d *dev;
 
+   if (IS_ENABLED(CONFIG_SERIAL_NUMBER_FIXUP)) {
+   const char *serialno;
+
+   serialno = getenv("global.serial_number");
+   if (serialno)
+   of_property_write_string(root, "serial-number", 
serialno);
+
+   }
+
node = of_create_node(root, "/chosen");
if (!node)
return -ENOMEM;
diff --git a/include/common.h b/include/common.h
index 4167d4676e..967502a7ab 100644
--- a/include/common.h
+++ b/include/common.h
@@ -126,4 +126,7 @@ const char *barebox_get_hostname(void);
 void barebox_set_hostname(const char *);
 void barebox_set_hostname_no_overwrite(const char *);
 
+const char *barebox_get_serial_number(void);
+void barebox_set_serial_number(const char *);
+
 #endif /* __COMMON_H_ */
-- 
2.30.2


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


[PATCH v4 4/5] ARM: boards: skov-imx6: make use of of_fixup_machine_compatible()

2022-04-29 Thread Oleksij Rempel
Replace board specific fixup_machine_compatible() with generic
of_fixup_machine_compatible()

Signed-off-by: Oleksij Rempel 
---
 arch/arm/boards/skov-imx6/board.c | 40 +++
 1 file changed, 3 insertions(+), 37 deletions(-)

diff --git a/arch/arm/boards/skov-imx6/board.c 
b/arch/arm/boards/skov-imx6/board.c
index 2702bc1de9..53c213f33b 100644
--- a/arch/arm/boards/skov-imx6/board.c
+++ b/arch/arm/boards/skov-imx6/board.c
@@ -312,55 +312,21 @@ static int skov_board_no = -1;
 static bool skov_have_switch = true;
 static const char *no_switch_suffix = "-noswitch";
 
-static void fixup_machine_compatible(const char *compat,
-struct device_node *root)
-{
-   int cclen = 0, clen = strlen(compat) + 1;
-   const char *curcompat;
-   void *buf;
-
-   if (!root) {
-   root = of_get_root_node();
-   if (!root)
-   return;
-   }
-
-   curcompat = of_get_property(root, "compatible", &cclen);
-
-   buf = xzalloc(cclen + clen);
-
-   memcpy(buf, compat, clen);
-   memcpy(buf + clen, curcompat, cclen);
-
-   /*
-* Prepend the compatible from board entry to the machine compatible.
-* Used to match bootspec entries against it.
-*/
-   of_set_property(root, "compatible", buf, cclen + clen, true);
-
-   free(buf);
-}
-
 static void fixup_noswitch_machine_compatible(struct device_node *root)
 {
const char *compat = imx6_variants[skov_board_no].dts_compatible;
const char *generic = "skov,imx6";
-   size_t size, size_generic;
char *buf;
 
-   size = strlen(compat) + strlen(no_switch_suffix) + 1;
-   size_generic = strlen(generic) + strlen(no_switch_suffix) + 1;
-   size = max(size, size_generic);
-
/* add generic compatible, so systemd&co can make right decisions */
buf = xasprintf("%s%s", generic, no_switch_suffix);
-   fixup_machine_compatible(buf, root);
+   of_fixup_machine_compatible(root, buf);
 
/* add specific compatible as fallback, in case this board has new
 * challenges.
 */
buf = xasprintf("%s%s", compat, no_switch_suffix);
-   fixup_machine_compatible(buf, root);
+   of_fixup_machine_compatible(root, buf);
 
free(buf);
 }
@@ -648,7 +614,7 @@ static int skov_imx6_probe(struct device_d *dev)
globalvar_add_simple("board.dts", variant->dts_compatible);
globalvar_add_simple("board.display", variant->display ?: NULL);
 
-   fixup_machine_compatible(variant->dts_compatible, NULL);
+   of_fixup_machine_compatible(NULL, variant->dts_compatible);
 
skov_init_board(variant);
 
-- 
2.30.2


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


[PATCH v4 0/5] add different OF board fixups

2022-04-29 Thread Oleksij Rempel
changes v4:
- s/code info device/code into device/

changes v3:
- rename global.of_machine_compatible to global.of.kernel.add_machine_compatible

changes v2:
- protonic: use only allowed chars for generated compatible
- protonic: make use of of_get_machine_compatible() to get board name
- of_fixup_machine_compatible: make curcompat optional
- add $global.of_machine_compatible

Add optional fixups for board serial-number and machine compatible.

Ahmad Fatoum (1):
  common: add $global.serial_number with device tree fixup

Oleksij Rempel (4):
  ARM: boards: protonic-imx6: make use of barebox_set_serial_number()
  of: add generic of_fixup_machine_compatible()
  ARM: boards: skov-imx6: make use of of_fixup_machine_compatible()
  ARM: boards: protonic-imx6: add HW revision specific machine
compatible

 arch/arm/boards/protonic-imx6/board.c | 42 ++
 arch/arm/boards/skov-imx6/board.c | 40 ++---
 arch/arm/mach-imx/Kconfig |  2 ++
 common/Kconfig| 10 ++
 common/misc.c | 39 +
 common/oftree.c   | 50 +++
 include/common.h  |  6 
 include/of.h  |  6 
 8 files changed, 135 insertions(+), 60 deletions(-)

-- 
2.30.2


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


[PATCH v4 2/5] ARM: boards: protonic-imx6: make use of barebox_set_serial_number()

2022-04-29 Thread Oleksij Rempel
Replace board specific serial-number fixup with common
barebox_set_serial_number().

Signed-off-by: Oleksij Rempel 
---
 arch/arm/boards/protonic-imx6/board.c | 20 +---
 arch/arm/mach-imx/Kconfig |  1 +
 2 files changed, 2 insertions(+), 19 deletions(-)

diff --git a/arch/arm/boards/protonic-imx6/board.c 
b/arch/arm/boards/protonic-imx6/board.c
index 52cf39917a..0fadd148b4 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -196,30 +196,12 @@ static int prt_imx6_set_mac(struct prt_imx6_priv *priv,
return 0;
 }
 
-static int prt_of_fixup_serial(struct device_node *dstroot, void *arg)
-{
-   struct device_node *srcroot = arg;
-   const char *ser;
-   int len;
-
-   ser = of_get_property(srcroot, "serial-number", &len);
-   return of_set_property(dstroot, "serial-number", ser, len, 1);
-}
-
-static void prt_oftree_fixup_serial(const char *serial)
-{
-   struct device_node *root = of_get_root_node();
-
-   of_set_property(root, "serial-number", serial, strlen(serial) + 1, 1);
-   of_register_fixup(prt_of_fixup_serial, root);
-}
-
 static int prt_imx6_set_serial(struct prt_imx6_priv *priv,
   struct prti6q_rfid_contents *rfid)
 {
rfid->serial[9] = 0; /* Failsafe */
dev_info(priv->dev, "Serial number: %s\n", rfid->serial);
-   prt_oftree_fixup_serial(rfid->serial);
+   barebox_set_serial_number(rfid->serial);
 
return 0;
 }
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 6b962dcf7e..ee313a1502 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -350,6 +350,7 @@ config MACH_PROTONIC_IMX6
select ARCH_IMX6
select ARCH_IMX6UL
select ARM_USE_COMPRESSED_DTB
+   select SERIAL_NUMBER_FIXUP
 
 config MACH_PROTONIC_IMX8M
bool "Protonic-Holland i.MX8Mx based boards"
-- 
2.30.2


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


Re: [PATCH v3 1/5] common: add $global.serial_number with device tree fixup

2022-04-29 Thread Sascha Hauer
On Wed, Apr 27, 2022 at 02:14:09PM +0200, Oleksij Rempel wrote:
> From: Ahmad Fatoum 
> 
> This new variable can be set by boards from C code or from the
> environment to change the serial number fixed up into the kernel device
> tree.
> 
> Signed-off-by: Ahmad Fatoum 
> Signed-off-by: Oleksij Rempel 
> ---
>  common/Kconfig   |  5 +
>  common/misc.c| 16 
>  common/oftree.c  |  9 +
>  include/common.h |  3 +++
>  4 files changed, 33 insertions(+)
> 
> diff --git a/common/Kconfig b/common/Kconfig
> index f7a6a96e87..d08302a573 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -1066,6 +1066,11 @@ config MACHINE_ID
> Note: if no hashable information is available no machine id will be 
> passed
> to the kernel.
>  
> +config SERIAL_NUMBER_FIXUP
> + bool "fix up board serial number"
> + help
> +   fixup serial number supplied by board code info device tree

I Don't think we need a Kconfig option for this.

Sascha

-- 
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 v3 3/5] of: add generic of_fixup_machine_compatible()

2022-04-29 Thread Sascha Hauer
On Wed, Apr 27, 2022 at 02:14:11PM +0200, Oleksij Rempel wrote:
> Add generic function to extend/fixup machine compatible.
> 
> Signed-off-by: Oleksij Rempel 
> ---
>  common/Kconfig   |  5 +
>  common/misc.c| 23 +++
>  common/oftree.c  | 41 +
>  include/common.h |  3 +++
>  include/of.h |  6 ++
>  5 files changed, 78 insertions(+)
> 
> diff --git a/common/Kconfig b/common/Kconfig
> index d08302a573..9b65b728c0 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -1066,6 +1066,11 @@ config MACHINE_ID
> Note: if no hashable information is available no machine id will be 
> passed
> to the kernel.
>  
> +config MACHINE_FIXUP
> + bool "fix up machine compatible"
> + help
> +   fixup machine compatible supplied by board code info device tree

s/info/into/

> +
>  config SERIAL_NUMBER_FIXUP
>   bool "fix up board serial number"
>   help
> diff --git a/common/misc.c b/common/misc.c
> index 3b3bc05bfd..0f6de3e9e5 100644
> --- a/common/misc.c
> +++ b/common/misc.c
> @@ -150,6 +150,7 @@ BAREBOX_MAGICVAR(global.model, "Product name of this 
> hardware");
>  
>  static char *hostname;
>  static char *serial_number;
> +static char *of_machine_compatible;
>  
>  /*
>   * The hostname is supposed to be the shortname of a board. It should
> @@ -195,6 +196,28 @@ const char *barebox_get_serial_number(void)
>  
>  BAREBOX_MAGICVAR(global.serial_number, "Board serial number");
>  
> +void barebox_set_of_machine_compatible(const char *__compatible)
> +{
> + free(of_machine_compatible);
> + of_machine_compatible = xstrdup(__compatible);
> +}
> +
> +const char *barebox_get_of_machine_compatible(void)
> +{
> + return of_machine_compatible;
> +}
> +
> +static int of_kernel_init(void)
> +{
> + globalvar_add_simple_string("of.kernel.add_machine_compatible",
> + &of_machine_compatible);
> +
> + return 0;
> +}
> +device_initcall(of_kernel_init);
> +
> +BAREBOX_MAGICVAR(global.of.kernel.add_machine_compatible, "Additional 
> machine/board compatible");
> +
>  void __noreturn panic(const char *fmt, ...)
>  {
>   va_list args;
> diff --git a/common/oftree.c b/common/oftree.c
> index c6d75055cc..76239476e0 100644
> --- a/common/oftree.c
> +++ b/common/oftree.c
> @@ -216,6 +216,15 @@ static int of_fixup_bootargs(struct device_node *root, 
> void *unused)
>  
>   }
>  
> + if (IS_ENABLED(CONFIG_MACHINE_FIXUP)) {
> + const char *compat;
> +
> + compat = getenv("global.of.kernel.add_machine_compatible");
> + if (compat)
> + of_fixup_machine_compatible(root, compat);
> +
> + }
> +
>   node = of_create_node(root, "/chosen");
>   if (!node)
>   return -ENOMEM;
> @@ -487,3 +496,35 @@ int of_autoenable_i2c_by_component(char *path)
>  
>   return ret;
>  }
> +
> +int of_fixup_machine_compatible(struct device_node *root, const char *compat)
> +{
> + int cclen = 0, clen = strlen(compat) + 1;
> + const char *curcompat;
> + void *buf;
> +
> + if (!root) {
> + root = of_get_root_node();
> + if (!root)
> + return -ENODEV;
> + }
> +
> + curcompat = of_get_property(root, "compatible", &cclen);
> +
> + buf = xzalloc(cclen + clen);
> +
> + memcpy(buf, compat, clen);
> +
> + if (curcompat)
> + memcpy(buf + clen, curcompat, cclen);
> +
> + /*
> +  * Prepend the compatible from board entry to the machine compatible.
> +  * Used to match bootspec entries against it.
> +  */

This sentence doesn't make sense in the context this function is called
in this patch. In this patch this function is called in a of_fixup which
fixes up the kernel device tree, but the sentence above reads as it
should be called on the barebox internal device tree.

maybe of_prepend_machine_compatible() would be a better name for this
function.

Also, should we check if the passed device tree already is compatible to
@compat before we potentially add the same compatible again?

Sascha

-- 
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