Skip to contentSkip to conversation

Add spi boot support to am335x-icev2

PATCH New Faiz Abbas 2 participants 7 messages Sep 14, 2020 – Sep 15, 2020

Subsystems (4)
lore
Share & tools
lore

Faiz Abbas

author
#0 lore raw

v2 cover Add spi boot support to am335x-icev2

The following patches add spi boot support to TI's am335x-icev2 platform

v2:
1. Changed order of patches to avoid breaking build
2. Changed SPI_OFFSET to SPI0_OFFSET and moved the define arch/arm/mach-omap2/am335x/board.c
3. Updated MAINTAINERS list with the new defconfig.

Faiz Abbas (5):
arm: dts: am335x-icev2: Add spi node
spi: spi-uclass: Block dm_scan_fdt_dev with OF_CONTROL to prevent
build failures
arm: mach-omap2: am33xx: Add device structure for spi
spi: omap3_spi: Read platform data in ofdata_to_platdata()
configs: Add spiboot support for am335x

 arch/arm/dts/am335x-icev2.dts        |  50 +++++++++++++
 arch/arm/mach-omap2/am33xx/board.c   |  18 +++++
 board/ti/am335x/MAINTAINERS          |   1 +
 configs/am335x_evm_spiboot_defconfig |  93 +++++++++++++++++++++++
 drivers/spi/omap3_spi.c              | 107 +++++++--------------------
 drivers/spi/spi-uclass.c             |   2 +-
 include/configs/am335x_evm.h         |   2 -
 include/omap3_spi.h                  |  78 +++++++++++++++++++
 8 files changed, 268 insertions(+), 83 deletions(-)
 create mode 100644 configs/am335x_evm_spiboot_defconfig
 create mode 100644 include/omap3_spi.h
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/5 arm: dts: am335x-icev2: Add spi node

Add spi and spi nor flash nodes for am335x-icev2.

---
 arch/arm/dts/am335x-icev2.dts | 50 +++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
arch/arm/dts/am335x-icev2.dts +50 -0
index 37484cb6f5..2a1b3a53e9 100644
@@ -436,3 +436,53 @@
 		reg = <3>;
 	};
 };
+
+&spi0 {
+	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&spi0_pins_default>;
+
+	sn65hvs882 at 1 {
+		compatible = "pisosr-gpio";
+		gpio-controller;
+		#gpio-cells = <2>;
+
+		load-gpios = <&gpio3 18 GPIO_ACTIVE_LOW>;
+
+		reg = <1>;
+		spi-max-frequency = <1000000>;
+		spi-cpol;
+	};
+
+	spi_nor: flash at 0 {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "winbond,w25q64", "jedec,spi-nor";
+		spi-max-frequency = <80000000>;
+		m25p,fast-read;
+		reg = <0>;
+
+		partition at 0 {
+			label = "u-boot-spl";
+			reg = <0x0 0x80000>;
+			read-only;
+		};
+
+		partition at 1 {
+			label = "u-boot";
+			reg = <0x80000 0x100000>;
+			read-only;
+		};
+
+		partition at 2 {
+			label = "u-boot-env";
+			reg = <0x180000 0x20000>;
+			read-only;
+		};
+
+		partition at 3 {
+			label = "misc";
+			reg = <0x1A0000 0x660000>;
+		};
+	};
+};
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v2 2/5 spi: spi-uclass: Block dm_scan_fdt_dev with OF_CONTROL to prevent build failures

In reply to Faiz Abbas

There are devices which don't use OF_CONTROL or OF_PLATDATA but instead rely on statically defined platdata. Block dm_scan_fdt_dev() with both configs to avoid build failures under this condition.

---
 drivers/spi/spi-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-uclass.c +1 -1
index cffd9cf0b0..55a8eed890 100644
@@ -497,7 +497,7 @@ UCLASS_DRIVER(spi) = {
 	.id		= UCLASS_SPI,
 	.name		= "spi",
 	.flags		= DM_UC_FLAG_SEQ_ALIAS,
-#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 	.post_bind	= dm_scan_fdt_dev,
 #endif
 	.post_probe	= spi_post_probe,
Signature · 1 line
2.17.1
author
#3 lore raw

PATCH v2 3/5 arm: mach-omap2: am33xx: Add device structure for spi

In reply to Faiz Abbas

Add platform data and a device structure for the spi device present on am335x-icev2. This requires moving all omap3_spi platform data structures and symbols to an omap3_spi.h so that the board file can access them.

---
 arch/arm/mach-omap2/am33xx/board.c | 18 +++++++
 drivers/spi/omap3_spi.c            | 70 +--------------------------
 include/configs/am335x_evm.h       |  2 -
 include/omap3_spi.h                | 78 ++++++++++++++++++++++++++++++
 4 files changed, 97 insertions(+), 71 deletions(-)
 create mode 100644 include/omap3_spi.h
arch/arm/mach-omap2/am33xx/board.c +18 -0
index a7b56b6bb3..2888390d24 100644
@@ -14,6 +14,7 @@
 #include <init.h>
 #include <net.h>
 #include <ns16550.h>
+#include <omap3_spi.h>
 #include <spl.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/hardware.h>
@@ -49,6 +50,12 @@
 #define AM43XX_READ_WRITE_LEVELING_CTRL_OFFSET		0xDC
 #define AM43XX_RDWRLVLFULL_START			0x80000000
 
+/* SPI flash. */
+#if CONFIG_IS_ENABLED(DM_SPI) && !CONFIG_IS_ENABLED(OF_CONTROL)
+#define AM33XX_SPI0_BASE	0x48030000
+#define AM33XX_SPI0_OFFSET	(AM33XX_SPI0_BASE + OMAP4_MCSPI_REG_OFFSET)
+#endif
+
 DECLARE_GLOBAL_DATA_PTR;
 
 int dram_init(void)
@@ -142,6 +149,17 @@ U_BOOT_DEVICES(am33xx_gpios) = {
 #endif
 };
 #endif
+#if CONFIG_IS_ENABLED(DM_SPI) && !CONFIG_IS_ENABLED(OF_CONTROL)
+static const struct omap3_spi_plat omap3_spi_pdata = {
+	.regs = (struct mcspi *)AM33XX_SPI0_OFFSET,
+	.pin_dir = MCSPI_PINDIR_D0_IN_D1_OUT,
+};
+
+U_BOOT_DEVICE(am33xx_spi) = {
+	.name = "omap3_spi",
+	.platdata = &omap3_spi_pdata,
+};
+#endif
 #endif
 
 #if !CONFIG_IS_ENABLED(DM_GPIO)
drivers/spi/omap3_spi.c +1 -69

83 lines not on this page · raw message

include/configs/am335x_evm.h +0 -2
index 9c4ef369c5..0767927376 100644
@@ -280,8 +280,6 @@
 #define CONFIG_SYS_ENV_SECT_SIZE	CONFIG_SYS_NAND_BLOCK_SIZE
 #endif
 
-/* SPI flash. */
-
 /* Network. */
 /* Enable Atheros phy driver */
 
include/omap3_spi.h new file +78 -0

78 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#4 lore raw

PATCH v2 4/5 spi: omap3_spi: Read platform data in ofdata_to_platdata()

In reply to Faiz Abbas

Add an ofdata_to_platdata() callback to access dts in U-boot and access all platform data in it. This prepares the driver for supporting both device tree as well as static platform data structures in SPL.

---
 drivers/spi/omap3_spi.c | 37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)
drivers/spi/omap3_spi.c +26 -11
index fb1cf360fc..56cb217486 100644
@@ -414,17 +414,10 @@ static int omap3_spi_set_wordlen(struct udevice *dev, unsigned int wordlen)
 static int omap3_spi_probe(struct udevice *dev)
 {
 	struct omap3_spi_priv *priv = dev_get_priv(dev);
-	const void *blob = gd->fdt_blob;
-	int node = dev_of_offset(dev);
+	struct omap3_spi_plat *plat = dev_get_platdata(dev);
 
-	struct omap2_mcspi_platform_config* data =
-		(struct omap2_mcspi_platform_config*)dev_get_driver_data(dev);
-
-	priv->regs = (struct mcspi *)(dev_read_addr(dev) + data->regs_offset);
-	if (fdtdec_get_bool(blob, node, "ti,pindir-d0-out-d1-in"))
-		priv->pin_dir = MCSPI_PINDIR_D0_OUT_D1_IN;
-	else
-		priv->pin_dir = MCSPI_PINDIR_D0_IN_D1_OUT;
+	priv->regs = plat->regs;
+	priv->pin_dir = plat->pin_dir;
 	priv->wordlen = SPI_DEFAULT_WORDLEN;
 
 	spi_reset(priv->regs);
@@ -476,6 +469,7 @@ static const struct dm_spi_ops omap3_spi_ops = {
 	 */
 };
 
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 static struct omap2_mcspi_platform_config omap2_pdata = {
 	.regs_offset = 0,
 };
@@ -484,16 +478,37 @@ static struct omap2_mcspi_platform_config omap4_pdata = {
 	.regs_offset = OMAP4_MCSPI_REG_OFFSET,
 };
 
+static int omap3_spi_ofdata_to_platdata(struct udevice *dev)
+{
+	struct omap2_mcspi_platform_config *data =
+		(struct omap2_mcspi_platform_config *)dev_get_driver_data(dev);
+	struct omap3_spi_plat *plat = dev_get_platdata(dev);
+
+	plat->regs = (struct mcspi *)(dev_read_addr(dev) + data->regs_offset);
+
+	if (dev_read_bool(dev, "ti,pindir-d0-out-d1-in"))
+		plat->pin_dir = MCSPI_PINDIR_D0_OUT_D1_IN;
+	else
+		plat->pin_dir = MCSPI_PINDIR_D0_IN_D1_OUT;
+
+	return 0;
+}
+
 static const struct udevice_id omap3_spi_ids[] = {
 	{ .compatible = "ti,omap2-mcspi", .data = (ulong)&omap2_pdata },
 	{ .compatible = "ti,omap4-mcspi", .data = (ulong)&omap4_pdata },
 	{ }
 };
-
+#endif
 U_BOOT_DRIVER(omap3_spi) = {
 	.name   = "omap3_spi",
 	.id     = UCLASS_SPI,
+	.flags	= DM_FLAG_PRE_RELOC,
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 	.of_match = omap3_spi_ids,
+	.ofdata_to_platdata = omap3_spi_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct omap3_spi_plat),
+#endif
 	.probe = omap3_spi_probe,
 	.ops    = &omap3_spi_ops,
 	.priv_auto_alloc_size = sizeof(struct omap3_spi_priv),
Signature · 1 line
2.17.1
author
#5 lore raw

PATCH v2 5/5 configs: Add spiboot support for am335x

In reply to Faiz Abbas

am335x internal SRAM is too small to support the addition of SPI bootmode to the default defconfig. Add a separate spiboot_defconfig

---
 board/ti/am335x/MAINTAINERS          |  1 +
 configs/am335x_evm_spiboot_defconfig | 93 ++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+)
 create mode 100644 configs/am335x_evm_spiboot_defconfig
board/ti/am335x/MAINTAINERS +1 -0
index e100adfd68..219c8715bf 100644
@@ -5,3 +5,4 @@ F:	board/ti/am335x/
 F:	include/configs/am335x_evm.h
 F:	configs/am335x_boneblack_vboot_defconfig
 F:	configs/am335x_evm_defconfig
+F:	configs/am335x_evm_spiboot_defconfig
configs/am335x_evm_spiboot_defconfig new file +93 -0

93 lines not on this page · raw message

Signature · 1 line
2.17.1
#6 lore raw

v2 cover Add spi boot support to am335x-icev2

In reply to Faiz Abbas
Quoted 7 lines · Faiz Abbas

The following patches add spi boot support to TI's am335x-icev2 platform

v2:
1. Changed order of patches to avoid breaking build
2. Changed SPI_OFFSET to SPI0_OFFSET and moved the define arch/arm/mach-omap2/am335x/board.c
3. Updated MAINTAINERS list with the new defconfig.

Applied to u-boot-ti next branch.

Thanks and regards,
Lokesh