Skip to contentSkip to conversation

spi: davinci: Add platdata support

PATCH New Jagan Teki 2 participants 11 messages Sep 3, 2018 – Oct 10, 2018 SPI

lore
Share & tools
lore

Jagan Teki

author
#0 lore raw

PATCH 1/3 spi: davinci: Add platdata support

Davanci spi driver has DM support already, this patch add support for platdata so-that SPL can use it for low foot-print.

---
 drivers/spi/davinci_spi.c              | 47 +++++++++++++++-----------
 include/dm/platform_data/spi_davinci.h | 15 ++++++++
 2 files changed, 43 insertions(+), 19 deletions(-)
 create mode 100644 include/dm/platform_data/spi_davinci.h
drivers/spi/davinci_spi.c +28 -19
index a822858323..07fa5e3b8a 100644
@@ -14,6 +14,7 @@
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
 #include <dm.h>
+#include <dm/platform_data/spi_davinci.h>
 
 /* SPIGCR0 */
 #define SPIGCR0_SPIENA_MASK	0x1
@@ -529,50 +530,58 @@ static int davinci_spi_xfer(struct udevice *dev, unsigned int bitlen,
 	return __davinci_spi_xfer(ds, bitlen, dout, din, flags);
 }
 
+static const struct dm_spi_ops davinci_spi_ops = {
+	.claim_bus	= davinci_spi_claim_bus,
+	.release_bus	= davinci_spi_release_bus,
+	.xfer		= davinci_spi_xfer,
+	.set_speed	= davinci_spi_set_speed,
+	.set_mode	= davinci_spi_set_mode,
+};
+
 static int davinci_spi_probe(struct udevice *bus)
 {
-	/* Nothing to do */
+	struct davinci_spi_slave *ds = dev_get_priv(bus);
+	struct davinci_spi_platdata *plat = bus->platdata;
+	ds->regs = plat->regs;
+	ds->num_cs = plat->num_cs;
+
 	return 0;
 }
 
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 static int davinci_ofdata_to_platadata(struct udevice *bus)
 {
-	struct davinci_spi_slave *ds = dev_get_priv(bus);
-	const void *blob = gd->fdt_blob;
-	int node = dev_of_offset(bus);
+	struct davinci_spi_platdata *plat = bus->platdata;
+	fdt_addr_t addr;
 
-	ds->regs = devfdt_map_physmem(bus, sizeof(struct davinci_spi_regs));
-	if (!ds->regs) {
-		printf("%s: could not map device address\n", __func__);
+	addr = devfdt_get_addr(bus);
+	if (addr == FDT_ADDR_T_NONE)
 		return -EINVAL;
-	}
-	ds->num_cs = fdtdec_get_int(blob, node, "num-cs", 4);
+
+	plat->regs = (struct davinci_spi_regs *)addr;
+	plat->num_cs = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), "num-cs", 4);
 
 	return 0;
 }
 
-static const struct dm_spi_ops davinci_spi_ops = {
-	.claim_bus	= davinci_spi_claim_bus,
-	.release_bus	= davinci_spi_release_bus,
-	.xfer		= davinci_spi_xfer,
-	.set_speed	= davinci_spi_set_speed,
-	.set_mode	= davinci_spi_set_mode,
-};
-
 static const struct udevice_id davinci_spi_ids[] = {
 	{ .compatible = "ti,keystone-spi" },
 	{ .compatible = "ti,dm6441-spi" },
 	{ .compatible = "ti,da830-spi" },
 	{ }
 };
+#endif
 
 U_BOOT_DRIVER(davinci_spi) = {
 	.name = "davinci_spi",
 	.id = UCLASS_SPI,
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 	.of_match = davinci_spi_ids,
-	.ops = &davinci_spi_ops,
 	.ofdata_to_platdata = davinci_ofdata_to_platadata,
-	.priv_auto_alloc_size = sizeof(struct davinci_spi_slave),
+        .platdata_auto_alloc_size = sizeof(struct davinci_spi_platdata),
+#endif
 	.probe = davinci_spi_probe,
+	.ops = &davinci_spi_ops,
+	.priv_auto_alloc_size = sizeof(struct davinci_spi_slave),
 };
 #endif
include/dm/platform_data/spi_davinci.h new file +15 -0
new file mode 100644
index 0000000000..fbc62c262a
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2018 Jagan Teki <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef __spi_davinci_h
+#define __spi_davinci_h
+
+struct davinci_spi_platdata {
+	struct davinci_spi_regs *regs;
+	u8 num_cs;	   /* total no. of CS available */
+};
+
+#endif /* __spi_davinci_h */
Signature · 1 line
2.18.0.321.gffc6fa0e3
author
#1 lore raw

PATCH 1/3 spi: davinci: Add platdata support

Quoted 7 lines · Jagan Teki

Davanci spi driver has DM support already, this patch add support for platdata so-that SPL can use it for low foot-print.

---

Applied to u-boot-spi/master

author
#2 lore raw

PATCH 2/3 board: da8xxevm: Add SPL DM for serial, spi

In reply to Jagan Teki

This patch add SPL DM support for da8xxevm boards with SPL serial, SPI drivers supported via platdata.

---
 board/davinci/da8xxevm/da850evm.c | 27 +++++++++++++++++++++++++++
 configs/da850_am18xxevm_defconfig |  3 +++
 configs/da850evm_defconfig        |  3 +++
 include/configs/da850evm.h        |  3 ---
 4 files changed, 33 insertions(+), 3 deletions(-)
board/davinci/da8xxevm/da850evm.c +27 -0
index 5583b45792..4cecb53124 100644
@@ -49,6 +49,33 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #define CFG_MAC_ADDR_OFFSET	(flash->size - SZ_64K)
 
+#ifdef CONFIG_SPL_BUILD
+#include <ns16550.h>
+#include <dm/platform_data/spi_davinci.h>
+
+static const struct ns16550_platdata da850evm_serial = {
+	.base = DAVINCI_UART2_BASE,
+	.reg_shift = 2,
+	.clock = 150000000,
+	.fcr = UART_FCR_DEFVAL,
+};
+
+U_BOOT_DEVICE(da850evm_uart) = {
+	.name = "ns16550_serial",
+	.platdata = &da850evm_serial,
+};
+
+static const struct davinci_spi_platdata davinci_spi_data = {
+        .regs = (struct davinci_spi_regs *)0x01f0e000,
+        .num_cs = 4,
+};
+
+U_BOOT_DEVICE(davinci_spi) = {
+        .name = "davinci_spi",
+        .platdata = &davinci_spi_data,
+};
+#endif
+
 #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
 static int get_mac_addr(u8 *addr)
 {
configs/da850_am18xxevm_defconfig +3 -0
index c61d78e2fe..07bfcc15f5 100644
@@ -8,6 +8,7 @@ CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_SPL_SERIAL_SUPPORT=y
 CONFIG_SPL=y
+CONFIG_SPL_DM=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI_SUPPORT=y
 CONFIG_DEFAULT_DEVICE_TREE="da850-evm"
@@ -35,6 +36,8 @@ CONFIG_CRC32_VERIFY=y
 # CONFIG_CMD_FS_GENERIC is not set
 CONFIG_CMD_DIAG=y
 CONFIG_OF_CONTROL=y
+CONFIG_SPL_OF_CONTROL=y
+CONFIG_SPL_OF_PLATDATA=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_DM=y
 CONFIG_DA8XX_GPIO=y
configs/da850evm_defconfig +3 -0
index 0b8bf2ad36..053173f2b1 100644
@@ -7,6 +7,7 @@ CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_SPL_SERIAL_SUPPORT=y
 CONFIG_SPL=y
+CONFIG_SPL_DM=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI_SUPPORT=y
 CONFIG_DEFAULT_DEVICE_TREE="da850-evm"
@@ -37,6 +38,8 @@ CONFIG_MTDIDS_DEFAULT="nor0=spi0.0"
 CONFIG_MTDPARTS_DEFAULT="mtdparts=spi0.0:512k(u-boot.ais),64k(u-boot-env),7552k(kernel-spare),64k(MAC-Address)"
 CONFIG_CMD_DIAG=y
 CONFIG_OF_CONTROL=y
+CONFIG_SPL_OF_CONTROL=y
+CONFIG_SPL_OF_PLATDATA=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_DM=y
 CONFIG_DM_GPIO=y
include/configs/da850evm.h +0 -3
index 7e52fea2a1..ebdadb44a8 100644
@@ -23,8 +23,6 @@
 * DM support in SPL
 */
 #ifdef CONFIG_SPL_BUILD
-#undef CONFIG_DM_SPI
-#undef CONFIG_DM_SPI_FLASH
 #undef CONFIG_DM_I2C
 #undef CONFIG_DM_I2C_COMPAT
 #endif
@@ -117,7 +115,6 @@
 
 #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_DIRECT_NOR_BOOT)
 #define CONFIG_SYS_NS16550_SERIAL
-#define CONFIG_SYS_NS16550_REG_SIZE	-4	/* NS16550 register size */
 #define CONFIG_SYS_NS16550_COM1	DAVINCI_UART2_BASE /* Base address of UART2 */
 #endif
 #define CONFIG_SYS_NS16550_CLK	clk_get(DAVINCI_UART2_CLKID)
Signature · 1 line
2.18.0.321.gffc6fa0e3
#3 lore raw

PATCH 2/3 board: da8xxevm: Add SPL DM for serial, spi

Quoted 5 lines · Jagan Teki

This patch add SPL DM support for da8xxevm boards with SPL serial, SPI drivers supported via platdata.

Cc Adam Ford <[email protected]>

I needed to massage one file a bit to get it to apply to master, but with that,

Quoted 112 lines
---
 board/davinci/da8xxevm/da850evm.c | 27 +++++++++++++++++++++++++++
 configs/da850_am18xxevm_defconfig |  3 +++
 configs/da850evm_defconfig        |  3 +++
 include/configs/da850evm.h        |  3 ---
 4 files changed, 33 insertions(+), 3 deletions(-)
board/davinci/da8xxevm/da850evm.c +27 -0
index 5583b45792..4cecb53124 100644
@@ -49,6 +49,33 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #define CFG_MAC_ADDR_OFFSET    (flash->size - SZ_64K)
 
+#ifdef CONFIG_SPL_BUILD
+#include <ns16550.h>
+#include <dm/platform_data/spi_davinci.h>
+
+static const struct ns16550_platdata da850evm_serial = {
+       .base = DAVINCI_UART2_BASE,
+       .reg_shift = 2,
+       .clock = 150000000,
+       .fcr = UART_FCR_DEFVAL,
+};
+
+U_BOOT_DEVICE(da850evm_uart) = {
+       .name = "ns16550_serial",
+       .platdata = &da850evm_serial,
+};
+
+static const struct davinci_spi_platdata davinci_spi_data = {
+        .regs = (struct davinci_spi_regs *)0x01f0e000,
+        .num_cs = 4,
+};
+
+U_BOOT_DEVICE(davinci_spi) = {
+        .name = "davinci_spi",
+        .platdata = &davinci_spi_data,
+};
+#endif
+
 #ifdef CONFIG_MAC_ADDR_IN_SPIFLASH
 static int get_mac_addr(u8 *addr)
 {
configs/da850_am18xxevm_defconfig +3 -0
index c61d78e2fe..07bfcc15f5 100644
@@ -8,6 +8,7 @@ CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_SPL_SERIAL_SUPPORT=y
 CONFIG_SPL=y
+CONFIG_SPL_DM=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI_SUPPORT=y
 CONFIG_DEFAULT_DEVICE_TREE="da850-evm"
@@ -35,6 +36,8 @@ CONFIG_CRC32_VERIFY=y
 # CONFIG_CMD_FS_GENERIC is not set
 CONFIG_CMD_DIAG=y
 CONFIG_OF_CONTROL=y
+CONFIG_SPL_OF_CONTROL=y
+CONFIG_SPL_OF_PLATDATA=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_DM=y
 CONFIG_DA8XX_GPIO=y
configs/da850evm_defconfig +3 -0
index 0b8bf2ad36..053173f2b1 100644
@@ -7,6 +7,7 @@ CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_SPL_SERIAL_SUPPORT=y
 CONFIG_SPL=y
+CONFIG_SPL_DM=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI_SUPPORT=y
 CONFIG_DEFAULT_DEVICE_TREE="da850-evm"
@@ -37,6 +38,8 @@ CONFIG_MTDIDS_DEFAULT="nor0=spi0.0"
 CONFIG_MTDPARTS_DEFAULT="mtdparts=spi0.0:512k(u-boot.ais),64k(u-boot-env),7552k(kernel-spare),64k(MAC-Address)"
 CONFIG_CMD_DIAG=y
 CONFIG_OF_CONTROL=y
+CONFIG_SPL_OF_CONTROL=y
+CONFIG_SPL_OF_PLATDATA=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_DM=y
 CONFIG_DM_GPIO=y
include/configs/da850evm.h +0 -4
index 7e52fea2a1..ebdadb44a8 100644
@@ -23,8 +23,6 @@
 * DM support in SPL
 */
 #ifdef CONFIG_SPL_BUILD
-#undef CONFIG_DM_SPI
-#undef CONFIG_DM_SPI_FLASH
 #undef CONFIG_DM_I2C
 #undef CONFIG_DM_I2C_COMPAT
 #endif
@@ -117,7 +115,6 @@
 
 #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_DIRECT_NOR_BOOT)
 #define CONFIG_SYS_NS16550_SERIAL
-#define CONFIG_SYS_NS16550_REG_SIZE    -4      /* NS16550 register size */
 #define CONFIG_SYS_NS16550_COM1        DAVINCI_UART2_BASE /* Base address of UART2 */
 #endif
 #define CONFIG_SYS_NS16550_CLK clk_get(DAVINCI_UART2_CLKID)
--

2.18.0.321.gffc6fa0e3

#5 lore raw

PATCH 1/3 spi: davinci: Add platdata support

In reply to Jagan Teki
Quoted 5 lines · Jagan Teki

Davanci spi driver has DM support already, this patch add support for platdata so-that SPL can use it for low foot-print.

In order for this to work, I had to apply a patch [1] that I submitted before. That patch disabled the manual initialization of the UART in da850_lowlevel.c to not conflict with the DM version of initialization.

Assuming that [1] gets applied first then this, you can add me as 'tested-by' on
both patches 1 of 3 and 2 of 3. I don't have the hardware to test 3 of 3.

[1] - https://patchwork.ozlabs.org/patch/957336/

adam

Quoted 121 lines
---
 drivers/spi/davinci_spi.c              | 47 +++++++++++++++-----------
 include/dm/platform_data/spi_davinci.h | 15 ++++++++
 2 files changed, 43 insertions(+), 19 deletions(-)
 create mode 100644 include/dm/platform_data/spi_davinci.h
drivers/spi/davinci_spi.c +28 -19
index a822858323..07fa5e3b8a 100644
@@ -14,6 +14,7 @@
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
 #include <dm.h>
+#include <dm/platform_data/spi_davinci.h>
 
 /* SPIGCR0 */
 #define SPIGCR0_SPIENA_MASK    0x1
@@ -529,50 +530,58 @@ static int davinci_spi_xfer(struct udevice *dev, unsigned int bitlen,
        return __davinci_spi_xfer(ds, bitlen, dout, din, flags);
 }
 
+static const struct dm_spi_ops davinci_spi_ops = {
+       .claim_bus      = davinci_spi_claim_bus,
+       .release_bus    = davinci_spi_release_bus,
+       .xfer           = davinci_spi_xfer,
+       .set_speed      = davinci_spi_set_speed,
+       .set_mode       = davinci_spi_set_mode,
+};
+
 static int davinci_spi_probe(struct udevice *bus)
 {
-       /* Nothing to do */
+       struct davinci_spi_slave *ds = dev_get_priv(bus);
+       struct davinci_spi_platdata *plat = bus->platdata;
+       ds->regs = plat->regs;
+       ds->num_cs = plat->num_cs;
+
        return 0;
 }
 
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 static int davinci_ofdata_to_platadata(struct udevice *bus)
 {
-       struct davinci_spi_slave *ds = dev_get_priv(bus);
-       const void *blob = gd->fdt_blob;
-       int node = dev_of_offset(bus);
+       struct davinci_spi_platdata *plat = bus->platdata;
+       fdt_addr_t addr;
 
-       ds->regs = devfdt_map_physmem(bus, sizeof(struct davinci_spi_regs));
-       if (!ds->regs) {
-               printf("%s: could not map device address\n", __func__);
+       addr = devfdt_get_addr(bus);
+       if (addr == FDT_ADDR_T_NONE)
                return -EINVAL;
-       }
-       ds->num_cs = fdtdec_get_int(blob, node, "num-cs", 4);
+
+       plat->regs = (struct davinci_spi_regs *)addr;
+       plat->num_cs = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), "num-cs", 4);
 
        return 0;
 }
 
-static const struct dm_spi_ops davinci_spi_ops = {
-       .claim_bus      = davinci_spi_claim_bus,
-       .release_bus    = davinci_spi_release_bus,
-       .xfer           = davinci_spi_xfer,
-       .set_speed      = davinci_spi_set_speed,
-       .set_mode       = davinci_spi_set_mode,
-};
-
 static const struct udevice_id davinci_spi_ids[] = {
        { .compatible = "ti,keystone-spi" },
        { .compatible = "ti,dm6441-spi" },
        { .compatible = "ti,da830-spi" },
        { }
 };
+#endif
 
 U_BOOT_DRIVER(davinci_spi) = {
        .name = "davinci_spi",
        .id = UCLASS_SPI,
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
        .of_match = davinci_spi_ids,
-       .ops = &davinci_spi_ops,
        .ofdata_to_platdata = davinci_ofdata_to_platadata,
-       .priv_auto_alloc_size = sizeof(struct davinci_spi_slave),
+        .platdata_auto_alloc_size = sizeof(struct davinci_spi_platdata),
+#endif
        .probe = davinci_spi_probe,
+       .ops = &davinci_spi_ops,
+       .priv_auto_alloc_size = sizeof(struct davinci_spi_slave),
 };
 #endif
include/dm/platform_data/spi_davinci.h new file +15 -1
new file mode 100644
index 0000000000..fbc62c262a
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2018 Jagan Teki <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __spi_davinci_h
+#define __spi_davinci_h
+
+struct davinci_spi_platdata {
+       struct davinci_spi_regs *regs;
+       u8 num_cs;         /* total no. of CS available */
+};
+
+#endif /* __spi_davinci_h */
--

2.18.0.321.gffc6fa0e3

#6 lore raw

PATCH 1/3 spi: davinci: Add platdata support

Quoted 12 lines · Adam Ford
Quoted 5 lines · Jagan Teki

Davanci spi driver has DM support already, this patch add support for platdata so-that SPL can use it for low foot-print.

In order for this to work, I had to apply a patch [1] that I submitted before. That patch disabled the manual initialization of the UART in da850_lowlevel.c to not conflict with the DM version of initialization.

Quoted 8 lines

Assuming that [1] gets applied first then this, you can add me as 'tested-by' on
both patches 1 of 3 and 2 of 3. I don't have the hardware to test 3 of 3.

[1] - https://patchwork.ozlabs.org/patch/957336/

adam

I should have stated, that without the [1] patch, this does does not work.

adam

Quoted 121 lines
Quoted 121 lines
---
 drivers/spi/davinci_spi.c              | 47 +++++++++++++++-----------
 include/dm/platform_data/spi_davinci.h | 15 ++++++++
 2 files changed, 43 insertions(+), 19 deletions(-)
 create mode 100644 include/dm/platform_data/spi_davinci.h
drivers/spi/davinci_spi.c +28 -19
index a822858323..07fa5e3b8a 100644
@@ -14,6 +14,7 @@
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
 #include <dm.h>
+#include <dm/platform_data/spi_davinci.h>
 
 /* SPIGCR0 */
 #define SPIGCR0_SPIENA_MASK    0x1
@@ -529,50 +530,58 @@ static int davinci_spi_xfer(struct udevice *dev, unsigned int bitlen,
        return __davinci_spi_xfer(ds, bitlen, dout, din, flags);
 }
 
+static const struct dm_spi_ops davinci_spi_ops = {
+       .claim_bus      = davinci_spi_claim_bus,
+       .release_bus    = davinci_spi_release_bus,
+       .xfer           = davinci_spi_xfer,
+       .set_speed      = davinci_spi_set_speed,
+       .set_mode       = davinci_spi_set_mode,
+};
+
 static int davinci_spi_probe(struct udevice *bus)
 {
-       /* Nothing to do */
+       struct davinci_spi_slave *ds = dev_get_priv(bus);
+       struct davinci_spi_platdata *plat = bus->platdata;
+       ds->regs = plat->regs;
+       ds->num_cs = plat->num_cs;
+
        return 0;
 }
 
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 static int davinci_ofdata_to_platadata(struct udevice *bus)
 {
-       struct davinci_spi_slave *ds = dev_get_priv(bus);
-       const void *blob = gd->fdt_blob;
-       int node = dev_of_offset(bus);
+       struct davinci_spi_platdata *plat = bus->platdata;
+       fdt_addr_t addr;
 
-       ds->regs = devfdt_map_physmem(bus, sizeof(struct davinci_spi_regs));
-       if (!ds->regs) {
-               printf("%s: could not map device address\n", __func__);
+       addr = devfdt_get_addr(bus);
+       if (addr == FDT_ADDR_T_NONE)
                return -EINVAL;
-       }
-       ds->num_cs = fdtdec_get_int(blob, node, "num-cs", 4);
+
+       plat->regs = (struct davinci_spi_regs *)addr;
+       plat->num_cs = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), "num-cs", 4);
 
        return 0;
 }
 
-static const struct dm_spi_ops davinci_spi_ops = {
-       .claim_bus      = davinci_spi_claim_bus,
-       .release_bus    = davinci_spi_release_bus,
-       .xfer           = davinci_spi_xfer,
-       .set_speed      = davinci_spi_set_speed,
-       .set_mode       = davinci_spi_set_mode,
-};
-
 static const struct udevice_id davinci_spi_ids[] = {
        { .compatible = "ti,keystone-spi" },
        { .compatible = "ti,dm6441-spi" },
        { .compatible = "ti,da830-spi" },
        { }
 };
+#endif
 
 U_BOOT_DRIVER(davinci_spi) = {
        .name = "davinci_spi",
        .id = UCLASS_SPI,
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
        .of_match = davinci_spi_ids,
-       .ops = &davinci_spi_ops,
        .ofdata_to_platdata = davinci_ofdata_to_platadata,
-       .priv_auto_alloc_size = sizeof(struct davinci_spi_slave),
+        .platdata_auto_alloc_size = sizeof(struct davinci_spi_platdata),
+#endif
        .probe = davinci_spi_probe,
+       .ops = &davinci_spi_ops,
+       .priv_auto_alloc_size = sizeof(struct davinci_spi_slave),
 };
 #endif
include/dm/platform_data/spi_davinci.h new file +15 -1
new file mode 100644
index 0000000000..fbc62c262a
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2018 Jagan Teki <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __spi_davinci_h
+#define __spi_davinci_h
+
+struct davinci_spi_platdata {
+       struct davinci_spi_regs *regs;
+       u8 num_cs;         /* total no. of CS available */
+};
+
+#endif /* __spi_davinci_h */
--

2.18.0.321.gffc6fa0e3

#7 lore raw

PATCH 1/3 spi: davinci: Add platdata support

Quoted 18 lines · Adam Ford
Quoted 16 lines · Adam Ford
Quoted 5 lines · Jagan Teki

Davanci spi driver has DM support already, this patch add support for platdata so-that SPL can use it for low foot-print.

In order for this to work, I had to apply a patch [1] that I submitted before. That patch disabled the manual initialization of the UART in da850_lowlevel.c to not conflict with the DM version of initialization.

Assuming that [1] gets applied first then this, you can add me as 'tested-by' on
both patches 1 of 3 and 2 of 3. I don't have the hardware to test 3 of 3.

Quoted 6 lines
Quoted 4 lines

[1] - https://patchwork.ozlabs.org/patch/957336/

adam

I should have stated, that without the [1] patch, this does does not work.

The patch I mentioned is applied. I am back in the US and ready and willing to test/retest anything.
If you want me to just retest this patch as-is, I can do so, if you want to rebase against master and sent out updated patches, I can do that too. If you have a git repo you want me to pull, I can test from there too.

As of 30 September 2018, the master branch booted the da850-evm and the concern I had about DM_SERIAL has been applied, so I am confident for at least the da850-evm your patch series should allow us to enable DM and boot both SPL (with OF_PLATDATA) and U-Boot.

adam

Quoted 123 lines

adam

Quoted 121 lines
Quoted 121 lines
---
 drivers/spi/davinci_spi.c              | 47 +++++++++++++++-----------
 include/dm/platform_data/spi_davinci.h | 15 ++++++++
 2 files changed, 43 insertions(+), 19 deletions(-)
 create mode 100644 include/dm/platform_data/spi_davinci.h
drivers/spi/davinci_spi.c +28 -19
index a822858323..07fa5e3b8a 100644
@@ -14,6 +14,7 @@
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
 #include <dm.h>
+#include <dm/platform_data/spi_davinci.h>
 
 /* SPIGCR0 */
 #define SPIGCR0_SPIENA_MASK    0x1
@@ -529,50 +530,58 @@ static int davinci_spi_xfer(struct udevice *dev, unsigned int bitlen,
        return __davinci_spi_xfer(ds, bitlen, dout, din, flags);
 }
 
+static const struct dm_spi_ops davinci_spi_ops = {
+       .claim_bus      = davinci_spi_claim_bus,
+       .release_bus    = davinci_spi_release_bus,
+       .xfer           = davinci_spi_xfer,
+       .set_speed      = davinci_spi_set_speed,
+       .set_mode       = davinci_spi_set_mode,
+};
+
 static int davinci_spi_probe(struct udevice *bus)
 {
-       /* Nothing to do */
+       struct davinci_spi_slave *ds = dev_get_priv(bus);
+       struct davinci_spi_platdata *plat = bus->platdata;
+       ds->regs = plat->regs;
+       ds->num_cs = plat->num_cs;
+
        return 0;
 }
 
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 static int davinci_ofdata_to_platadata(struct udevice *bus)
 {
-       struct davinci_spi_slave *ds = dev_get_priv(bus);
-       const void *blob = gd->fdt_blob;
-       int node = dev_of_offset(bus);
+       struct davinci_spi_platdata *plat = bus->platdata;
+       fdt_addr_t addr;
 
-       ds->regs = devfdt_map_physmem(bus, sizeof(struct davinci_spi_regs));
-       if (!ds->regs) {
-               printf("%s: could not map device address\n", __func__);
+       addr = devfdt_get_addr(bus);
+       if (addr == FDT_ADDR_T_NONE)
                return -EINVAL;
-       }
-       ds->num_cs = fdtdec_get_int(blob, node, "num-cs", 4);
+
+       plat->regs = (struct davinci_spi_regs *)addr;
+       plat->num_cs = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), "num-cs", 4);
 
        return 0;
 }
 
-static const struct dm_spi_ops davinci_spi_ops = {
-       .claim_bus      = davinci_spi_claim_bus,
-       .release_bus    = davinci_spi_release_bus,
-       .xfer           = davinci_spi_xfer,
-       .set_speed      = davinci_spi_set_speed,
-       .set_mode       = davinci_spi_set_mode,
-};
-
 static const struct udevice_id davinci_spi_ids[] = {
        { .compatible = "ti,keystone-spi" },
        { .compatible = "ti,dm6441-spi" },
        { .compatible = "ti,da830-spi" },
        { }
 };
+#endif
 
 U_BOOT_DRIVER(davinci_spi) = {
        .name = "davinci_spi",
        .id = UCLASS_SPI,
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
        .of_match = davinci_spi_ids,
-       .ops = &davinci_spi_ops,
        .ofdata_to_platdata = davinci_ofdata_to_platadata,
-       .priv_auto_alloc_size = sizeof(struct davinci_spi_slave),
+        .platdata_auto_alloc_size = sizeof(struct davinci_spi_platdata),
+#endif
        .probe = davinci_spi_probe,
+       .ops = &davinci_spi_ops,
+       .priv_auto_alloc_size = sizeof(struct davinci_spi_slave),
 };
 #endif
include/dm/platform_data/spi_davinci.h new file +15 -1
new file mode 100644
index 0000000000..fbc62c262a
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2018 Jagan Teki <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __spi_davinci_h
+#define __spi_davinci_h
+
+struct davinci_spi_platdata {
+       struct davinci_spi_regs *regs;
+       u8 num_cs;         /* total no. of CS available */
+};
+
+#endif /* __spi_davinci_h */
--

2.18.0.321.gffc6fa0e3

#8 lore raw

PATCH 1/3 spi: davinci: Add platdata support

Quoted 34 lines · Adam Ford
Quoted 18 lines · Adam Ford
Quoted 16 lines · Adam Ford
Quoted 5 lines · Jagan Teki

Davanci spi driver has DM support already, this patch add support for platdata so-that SPL can use it for low foot-print.

In order for this to work, I had to apply a patch [1] that I submitted before. That patch disabled the manual initialization of the UART in da850_lowlevel.c to not conflict with the DM version of initialization.

Assuming that [1] gets applied first then this, you can add me as 'tested-by' on
both patches 1 of 3 and 2 of 3. I don't have the hardware to test 3 of 3.

Quoted 6 lines
Quoted 4 lines

[1] - https://patchwork.ozlabs.org/patch/957336/

adam

I should have stated, that without the [1] patch, this does does not work.

The patch I mentioned is applied. I am back in the US and ready and willing to test/retest anything.
If you want me to just retest this patch as-is, I can do so, if you want to rebase against master and sent out updated patches, I can do that too. If you have a git repo you want me to pull, I can test from there too.

Quoted 10 lines

As of 30 September 2018, the master branch booted the da850-evm and the concern I had about DM_SERIAL has been applied, so I am confident for at least the da850-evm your patch series should allow us to enable DM and boot both SPL (with OF_PLATDATA) and U-Boot.

adam

Quoted 3 lines

adam

Quoted 1 line
Quoted 1 line
Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
---
 drivers/spi/davinci_spi.c              | 47 +++++++++++++++-----------
 include/dm/platform_data/spi_davinci.h | 15 ++++++++
 2 files changed, 43 insertions(+), 19 deletions(-)
 create mode 100644 include/dm/platform_data/spi_davinci.h
drivers/spi/davinci_spi.c +28 -19
index a822858323..07fa5e3b8a 100644
@@ -14,6 +14,7 @@
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
 #include <dm.h>
+#include <dm/platform_data/spi_davinci.h>
 
 /* SPIGCR0 */
 #define SPIGCR0_SPIENA_MASK    0x1
@@ -529,50 +530,58 @@ static int davinci_spi_xfer(struct udevice *dev, unsigned int bitlen,
        return __davinci_spi_xfer(ds, bitlen, dout, din, flags);
 }
 
+static const struct dm_spi_ops davinci_spi_ops = {
+       .claim_bus      = davinci_spi_claim_bus,
+       .release_bus    = davinci_spi_release_bus,
+       .xfer           = davinci_spi_xfer,
+       .set_speed      = davinci_spi_set_speed,
+       .set_mode       = davinci_spi_set_mode,
+};
+
 static int davinci_spi_probe(struct udevice *bus)
 {
-       /* Nothing to do */
+       struct davinci_spi_slave *ds = dev_get_priv(bus);
+       struct davinci_spi_platdata *plat = bus->platdata;
+       ds->regs = plat->regs;
+       ds->num_cs = plat->num_cs;
+
        return 0;
 }
 
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 static int davinci_ofdata_to_platadata(struct udevice *bus)
 {
-       struct davinci_spi_slave *ds = dev_get_priv(bus);
-       const void *blob = gd->fdt_blob;
-       int node = dev_of_offset(bus);
+       struct davinci_spi_platdata *plat = bus->platdata;
+       fdt_addr_t addr;
 
-       ds->regs = devfdt_map_physmem(bus, sizeof(struct davinci_spi_regs));
-       if (!ds->regs) {
-               printf("%s: could not map device address\n", __func__);
+       addr = devfdt_get_addr(bus);
+       if (addr == FDT_ADDR_T_NONE)
                return -EINVAL;
-       }
-       ds->num_cs = fdtdec_get_int(blob, node, "num-cs", 4);
+
+       plat->regs = (struct davinci_spi_regs *)addr;
+       plat->num_cs = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), "num-cs", 4);
 
        return 0;
 }
 
-static const struct dm_spi_ops davinci_spi_ops = {
-       .claim_bus      = davinci_spi_claim_bus,
-       .release_bus    = davinci_spi_release_bus,
-       .xfer           = davinci_spi_xfer,
-       .set_speed      = davinci_spi_set_speed,
-       .set_mode       = davinci_spi_set_mode,
-};
-
 static const struct udevice_id davinci_spi_ids[] = {
        { .compatible = "ti,keystone-spi" },
        { .compatible = "ti,dm6441-spi" },
        { .compatible = "ti,da830-spi" },
        { }
 };
+#endif
 
 U_BOOT_DRIVER(davinci_spi) = {
        .name = "davinci_spi",
        .id = UCLASS_SPI,
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
        .of_match = davinci_spi_ids,
-       .ops = &davinci_spi_ops,
        .ofdata_to_platdata = davinci_ofdata_to_platadata,
-       .priv_auto_alloc_size = sizeof(struct davinci_spi_slave),
+        .platdata_auto_alloc_size = sizeof(struct davinci_spi_platdata),
+#endif
        .probe = davinci_spi_probe,
+       .ops = &davinci_spi_ops,
+       .priv_auto_alloc_size = sizeof(struct davinci_spi_slave),
 };
 #endif
include/dm/platform_data/spi_davinci.h new file +15 -1
new file mode 100644
index 0000000000..fbc62c262a
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2018 Jagan Teki <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __spi_davinci_h
+#define __spi_davinci_h
+
+struct davinci_spi_platdata {
+       struct davinci_spi_regs *regs;
+       u8 num_cs;         /* total no. of CS available */
+};
+
+#endif /* __spi_davinci_h */
--

2.18.0.321.gffc6fa0e3

#9 lore raw

PATCH 1/3 spi: davinci: Add platdata support

Quoted 41 lines · Adam Ford
Quoted 39 lines · Adam Ford
Quoted 18 lines · Adam Ford
Quoted 16 lines · Adam Ford
Quoted 5 lines · Jagan Teki

Davanci spi driver has DM support already, this patch add support for platdata so-that SPL can use it for low foot-print.

In order for this to work, I had to apply a patch [1] that I submitted before. That patch disabled the manual initialization of the UART in da850_lowlevel.c to not conflict with the DM version of initialization.

Assuming that [1] gets applied first then this, you can add me as 'tested-by' on
both patches 1 of 3 and 2 of 3. I don't have the hardware to test 3 of 3.

Quoted 6 lines
Quoted 4 lines

[1] - https://patchwork.ozlabs.org/patch/957336/

adam

I should have stated, that without the [1] patch, this does does not work.

The patch I mentioned is applied. I am back in the US and ready and willing to test/retest anything.
If you want me to just retest this patch as-is, I can do so, if you want to rebase against master and sent out updated patches, I can do that too. If you have a git repo you want me to pull, I can test from there too.

As of 30 September 2018, the master branch booted the da850-evm and the concern I had about DM_SERIAL has been applied, so I am confident for at least the da850-evm your patch series should allow us to enable DM and boot both SPL (with OF_PLATDATA) and U-Boot.

Quoted 8 lines
Quoted 5 lines

adam

Quoted 3 lines

adam

Quoted 1 line
Quoted 1 line

Is this patch series going to be acceptable as-is? I'm very happy and excited about it as it helps migrate more and more into DM.

thanks

adam

Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
---
 drivers/spi/davinci_spi.c              | 47 +++++++++++++++-----------
 include/dm/platform_data/spi_davinci.h | 15 ++++++++
 2 files changed, 43 insertions(+), 19 deletions(-)
 create mode 100644 include/dm/platform_data/spi_davinci.h
drivers/spi/davinci_spi.c +28 -19
index a822858323..07fa5e3b8a 100644
@@ -14,6 +14,7 @@
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
 #include <dm.h>
+#include <dm/platform_data/spi_davinci.h>
 
 /* SPIGCR0 */
 #define SPIGCR0_SPIENA_MASK    0x1
@@ -529,50 +530,58 @@ static int davinci_spi_xfer(struct udevice *dev, unsigned int bitlen,
        return __davinci_spi_xfer(ds, bitlen, dout, din, flags);
 }
 
+static const struct dm_spi_ops davinci_spi_ops = {
+       .claim_bus      = davinci_spi_claim_bus,
+       .release_bus    = davinci_spi_release_bus,
+       .xfer           = davinci_spi_xfer,
+       .set_speed      = davinci_spi_set_speed,
+       .set_mode       = davinci_spi_set_mode,
+};
+
 static int davinci_spi_probe(struct udevice *bus)
 {
-       /* Nothing to do */
+       struct davinci_spi_slave *ds = dev_get_priv(bus);
+       struct davinci_spi_platdata *plat = bus->platdata;
+       ds->regs = plat->regs;
+       ds->num_cs = plat->num_cs;
+
        return 0;
 }
 
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 static int davinci_ofdata_to_platadata(struct udevice *bus)
 {
-       struct davinci_spi_slave *ds = dev_get_priv(bus);
-       const void *blob = gd->fdt_blob;
-       int node = dev_of_offset(bus);
+       struct davinci_spi_platdata *plat = bus->platdata;
+       fdt_addr_t addr;
 
-       ds->regs = devfdt_map_physmem(bus, sizeof(struct davinci_spi_regs));
-       if (!ds->regs) {
-               printf("%s: could not map device address\n", __func__);
+       addr = devfdt_get_addr(bus);
+       if (addr == FDT_ADDR_T_NONE)
                return -EINVAL;
-       }
-       ds->num_cs = fdtdec_get_int(blob, node, "num-cs", 4);
+
+       plat->regs = (struct davinci_spi_regs *)addr;
+       plat->num_cs = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), "num-cs", 4);
 
        return 0;
 }
 
-static const struct dm_spi_ops davinci_spi_ops = {
-       .claim_bus      = davinci_spi_claim_bus,
-       .release_bus    = davinci_spi_release_bus,
-       .xfer           = davinci_spi_xfer,
-       .set_speed      = davinci_spi_set_speed,
-       .set_mode       = davinci_spi_set_mode,
-};
-
 static const struct udevice_id davinci_spi_ids[] = {
        { .compatible = "ti,keystone-spi" },
        { .compatible = "ti,dm6441-spi" },
        { .compatible = "ti,da830-spi" },
        { }
 };
+#endif
 
 U_BOOT_DRIVER(davinci_spi) = {
        .name = "davinci_spi",
        .id = UCLASS_SPI,
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
        .of_match = davinci_spi_ids,
-       .ops = &davinci_spi_ops,
        .ofdata_to_platdata = davinci_ofdata_to_platadata,
-       .priv_auto_alloc_size = sizeof(struct davinci_spi_slave),
+        .platdata_auto_alloc_size = sizeof(struct davinci_spi_platdata),
+#endif
        .probe = davinci_spi_probe,
+       .ops = &davinci_spi_ops,
+       .priv_auto_alloc_size = sizeof(struct davinci_spi_slave),
 };
 #endif
include/dm/platform_data/spi_davinci.h new file +15 -1
new file mode 100644
index 0000000000..fbc62c262a
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2018 Jagan Teki <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef __spi_davinci_h
+#define __spi_davinci_h
+
+struct davinci_spi_platdata {
+       struct davinci_spi_regs *regs;
+       u8 num_cs;         /* total no. of CS available */
+};
+
+#endif /* __spi_davinci_h */
--

2.18.0.321.gffc6fa0e3

author
#10 lore raw

PATCH 3/3 configs: omapl138_lcdk: Enable DM_SPI, DM_SPI_FLASH

In reply to Jagan Teki

Enable DM_SPI and DM_SPI_FLASH for omapl138_lcdk board.

---
Note:
This would need spi DT node.

 configs/omapl138_lcdk_defconfig | 2 ++
 1 file changed, 2 insertions(+)
configs/omapl138_lcdk_defconfig +2 -0
index e8c6cf03bc..de92a1af87 100644
@@ -43,6 +43,7 @@ CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
 CONFIG_SYS_NAND_U_BOOT_LOCATIONS=y
 CONFIG_SYS_NAND_U_BOOT_OFFS=0x28000
 CONFIG_SPL_NAND_SIMPLE=y
+CONFIG_DM_SPI_FLASH=y
 CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
@@ -51,4 +52,5 @@ CONFIG_DRIVER_TI_EMAC=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
+CONFIG_DM_SPI=y
 CONFIG_DAVINCI_SPI=y
Signature · 1 line
2.18.0.321.gffc6fa0e3