Skip to contentSkip to conversation

Introduce MEMORY uclass and TI GPMC driver

PATCH In review Roger Quadros 3 participants 10 messages Oct 20, 2022 – Oct 26, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover Introduce MEMORY uclass and TI GPMC driver

Hi,

This series introduces the MEMORY controller uclass for the drivers that exist in drivers/memory directory.

With that, we add the TI GPMC Memory controller driver as the first user of this uclass.

The GPMC is a unified memory controller dedicated for interfacing with external memory devices like
- Asynchronous SRAM-like memories and ASICs
- Asynchronous, synchronous, and page mode burst NOR flash
- NAND flash
- Pseudo-SRAM devices

The driver is pulled straight from the Linux kernel and adapted for u-boot.

This driver will take care of setting up the GPMC based on the settings specified in the Device tree and then probe its children.

cheers,
-roger

Changelog:
v3:
- Use CONFIG_MEMORY instead of CONFIG_DM_MEMORY
- Introduce CONFIG_SPL_MEMORY and use it to gate inclusion of of drivers/memory for SPL build
- Make TI_GPMC depend on OF_CONTROL and CLK as well

v2:
- Introduce MEMORY uclass

Roger Quadros (4):
dm: memory: Introduce new uclass
scripts: Makefile.spl: Enable memory drivers to be built for SPL dt/bindings: memory: Add bindings for TI GPMC driver
memory: Add TI GPMC driver

 arch/sandbox/dts/test.dts                     |    4 +
 common/spl/Kconfig                            |    7 +
 .../memory/ti,gpmc-child.yaml                 |  252 ++++
 doc/device-tree-bindings/memory/ti,gpmc.yaml  |  190 +++
 drivers/memory/Kconfig                        |   36 +
 drivers/memory/Makefile                       |    3 +
 drivers/memory/memory-sandbox.c               |   18 +
 drivers/memory/memory-uclass.c                |   13 +
 drivers/memory/ti-gpmc.c                      | 1240 +++++++++++++++++
 drivers/memory/ti-gpmc.h                      |  298 ++++
 include/dm/uclass-id.h                        |    1 +
 include/linux/mtd/omap_gpmc.h                 |    3 +
 scripts/Makefile.spl                          |    1 +
 test/dm/Makefile                              |    1 +
 test/dm/memory.c                              |   21 +
 15 files changed, 2088 insertions(+)
 create mode 100644 doc/device-tree-bindings/memory/ti,gpmc-child.yaml
 create mode 100644 doc/device-tree-bindings/memory/ti,gpmc.yaml
 create mode 100644 drivers/memory/memory-sandbox.c
 create mode 100644 drivers/memory/memory-uclass.c
 create mode 100644 drivers/memory/ti-gpmc.c
 create mode 100644 drivers/memory/ti-gpmc.h
 create mode 100644 test/dm/memory.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/4 dm: memory: Introduce new uclass

Introduce UCLASS_MEMORY for future Memory Controller device drivers.

---
 arch/sandbox/dts/test.dts       |  4 ++++
 drivers/memory/Kconfig          | 17 +++++++++++++++++
 drivers/memory/Makefile         |  2 ++
 drivers/memory/memory-sandbox.c | 18 ++++++++++++++++++
 drivers/memory/memory-uclass.c  | 13 +++++++++++++
 include/dm/uclass-id.h          |  1 +
 test/dm/Makefile                |  1 +
 test/dm/memory.c                | 21 +++++++++++++++++++++
 8 files changed, 77 insertions(+)
 create mode 100644 drivers/memory/memory-sandbox.c
 create mode 100644 drivers/memory/memory-uclass.c
 create mode 100644 test/dm/memory.c
arch/sandbox/dts/test.dts +4 -0
index 2761588f0d..d65b2d2dcb 100644
@@ -926,6 +926,10 @@
 		};
 	};
 
+	memory-controller {
+		compatible = "sandbox,memory";
+	};
+
 	misc-test {
 		#address-cells = <1>;
 		#size-cells = <1>;
drivers/memory/Kconfig +17 -0
index 7271892763..c621f5bba3 100644
@@ -4,6 +4,23 @@
 
 menu "Memory Controller drivers"
 
+config MEMORY
+	bool "Enable Driver Model for Memory Controller drivers"
+	depends on DM
+	help
+	  Enable driver model for Memory Controller devices.
+	  These devices provide Memory bus interface to various devices like
+	  SRAM, Ethernet adapters, FPGAs, etc.
+	  For now this uclass has no methods yet.
+
+config SANDBOX_MEMORY
+	bool "Enable Sandbox Memory Controller driver"
+	depends on SANDBOX && MEMORY
+	help
+	  This is a driver model based Memory Controller driver for sandbox.
+	  Currently it is a stub only, as there are no usable uclass methods
+	  yet.
+
 config STM32_FMC2_EBI
 	bool "Support for FMC2 External Bus Interface on STM32MP SoCs"
 	depends on ARCH_STM32MP
drivers/memory/Makefile +2 -0
index fec52efb60..b27f701865 100644
@@ -1,3 +1,5 @@
 
+obj-$(CONFIG_MEMORY) += memory-uclass.o
+obj-$(CONFIG_SANDBOX_MEMORY) += memory-sandbox.o
 obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o
 obj-$(CONFIG_TI_AEMIF) += ti-aemif.o
drivers/memory/memory-sandbox.c new file +18 -0
new file mode 100644
index 0000000000..f2ede50863
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2022
+ *     Texas Instruments Incorporated, <www.ti.com>
+ */
+
+#include <dm.h>
+
+static const struct udevice_id sandbox_memory_match[] = {
+	{ .compatible = "sandbox,memory" },
+	{ /* sentinel */ }
+};
+
+U_BOOT_DRIVER(sandbox_memory) = {
+	.name	= "sandbox_memory",
+	.id	= UCLASS_MEMORY,
+	.of_match = sandbox_memory_match,
+};
drivers/memory/memory-uclass.c new file +13 -0
new file mode 100644
index 0000000000..d6d37fe777
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2022
+ *     Texas Instruments Incorporated, <www.ti.com>
+ */
+
+#include <dm.h>
+
+UCLASS_DRIVER(memory) = {
+	.name = "memory",
+	.id = UCLASS_MEMORY,
+	.post_bind = dm_scan_fdt_dev,
+};
include/dm/uclass-id.h +1 -0
index a432e43871..936a16c5d9 100644
@@ -76,6 +76,7 @@ enum uclass_id {
 	UCLASS_MASS_STORAGE,	/* Mass storage device */
 	UCLASS_MDIO,		/* MDIO bus */
 	UCLASS_MDIO_MUX,	/* MDIO MUX/switch */
+	UCLASS_MEMORY,		/* Memory Controller device */
 	UCLASS_MISC,		/* Miscellaneous device */
 	UCLASS_MMC,		/* SD / MMC card or chip */
 	UCLASS_MOD_EXP,		/* RSA Mod Exp device */
test/dm/Makefile +1 -0
index 7543df8823..1082e65c41 100644
@@ -47,6 +47,7 @@ ifneq ($(CONFIG_EFI_PARTITION),)
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
 endif
 obj-$(CONFIG_FIRMWARE) += firmware.o
+obj-$(CONFIG_MEMORY) += memory.o
 obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o
 obj-$(CONFIG_DM_I2C) += i2c.o
 obj-$(CONFIG_SOUND) += i2s.o
test/dm/memory.c new file +21 -0
new file mode 100644
index 0000000000..7d9500aa91
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2022
+ *     Texas Instruments Incorporated, <www.ti.com>
+ */
+
+#include <dm.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+static int dm_test_memory(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+
+	ut_assertok(uclass_first_device_err(UCLASS_MEMORY, &dev));
+
+	return 0;
+}
+
+DM_TEST(dm_test_memory, UT_TESTF_SCAN_FDT);
Signature · 1 line
2.17.1
#3 lore raw

PATCH v3 2/4 scripts: Makefile.spl: Enable memory drivers to be built for SPL

In reply to Roger Quadros

Introduce CONFIG_SPL_MEMORY to allow Memory drivers to be built for SPL.

---
 common/spl/Kconfig   | 7 +++++++
 scripts/Makefile.spl | 1 +
 2 files changed, 8 insertions(+)
common/spl/Kconfig +7 -0
index 70d97815f0..186131a699 100644
@@ -789,6 +789,13 @@ config SPL_DM_MAILBOX
 	  this option to build the drivers in drivers/mailbox as part of
 	  SPL build.
 
+config SPL_MEMORY
+	bool "Support Memory controller drivers"
+	help
+	  Enable support for Memory Controller drivers within SPL.
+	  These devices provide Memory bus interface to various devices like
+	  SRAM, Ethernet adapters, FPGAs, etc.
+
 config SPL_MMC
 	bool "Support MMC"
 	depends on MMC
scripts/Makefile.spl +1 -0
index 3bafeb4fe9..a1892bff7f 100644
@@ -114,6 +114,7 @@ libs-$(CONFIG_PARTITIONS) += disk/
 endif
 
 libs-y += drivers/
+libs-$(CONFIG_SPL_MEMORY) += drivers/memory/
 libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/dwc3/
 libs-$(CONFIG_SPL_USB_GADGET) += drivers/usb/cdns3/
 libs-y += dts/
Signature · 1 line
2.17.1
#6 lore raw

PATCH v3 3/4 dt/bindings: memory: Add bindings for TI GPMC driver

In reply to Roger Quadros

GPMC stands for General Purpose Memory Controller and it is present on many Texas Instruments SoCs.

It supports a number of Asynchronous and Synchronous interfaces and has various settings to configure the bus interface.

The DT bindings define all the various GPMC settings.

As the GPMC supports multiple devices on the bus, each device is represented as a child and the respective GPMC settings are situated there. (see ti,gpmc-child.yaml)

These binding docs are picked up from the Linux kernel.

---
 .../memory/ti,gpmc-child.yaml                 | 252 ++++++++++++++++++
 doc/device-tree-bindings/memory/ti,gpmc.yaml  | 190 +++++++++++++
 2 files changed, 442 insertions(+)
 create mode 100644 doc/device-tree-bindings/memory/ti,gpmc-child.yaml
 create mode 100644 doc/device-tree-bindings/memory/ti,gpmc.yaml
doc/device-tree-bindings/memory/ti,gpmc-child.yaml new file +252 -0
new file mode 100644
index 0000000000..8e541acdb1
@@ -0,0 +1,252 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/memory-controllers/ti,gpmc-child.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: device tree bindings for children of the Texas Instruments GPMC
+
+maintainers:
+  - Tony Lindgren <[email protected]>
+  - Roger Quadros <[email protected]>
+
+description:
+  This binding is meant for the child nodes of the GPMC node. The node
+  represents any device connected to the GPMC bus. It may be a Flash chip,
+  RAM chip or Ethernet controller, etc. These properties are meant for
+  configuring the GPMC settings/timings and will accompany the bindings
+  supported by the respective device.
+
+properties:
+  reg: true
+
+# GPMC Timing properties for child nodes. All are optional and default to 0.
+  gpmc,sync-clk-ps:
+    description: Minimum clock period for synchronous mode
+    default: 0
+
+# Chip-select signal timings corresponding to GPMC_CONFIG2:
+  gpmc,cs-on-ns:
+    description: Assertion time
+    default: 0
+
+  gpmc,cs-rd-off-ns:
+    description: Read deassertion time
+    default: 0
+
+  gpmc,cs-wr-off-ns:
+    description: Write deassertion time
+    default: 0
+
+# ADV signal timings corresponding to GPMC_CONFIG3:
+  gpmc,adv-on-ns:
+    description: Assertion time
+    default: 0
+
+  gpmc,adv-rd-off-ns:
+    description: Read deassertion time
+    default: 0
+
+  gpmc,adv-wr-off-ns:
+    description: Write deassertion time
+    default: 0
+
+  gpmc,adv-aad-mux-on-ns:
+    description: Assertion time for AAD
+    default: 0
+
+  gpmc,adv-aad-mux-rd-off-ns:
+    description: Read deassertion time for AAD
+    default: 0
+
+  gpmc,adv-aad-mux-wr-off-ns:
+    description: Write deassertion time for AAD
+    default: 0
+
+# WE signals timings corresponding to GPMC_CONFIG4:
+  gpmc,we-on-ns:
+    description: Assertion time
+    default: 0
+
+  gpmc,we-off-ns:
+    description: Deassertion time
+    default: 0
+
+# OE signals timings corresponding to GPMC_CONFIG4:
+  gpmc,oe-on-ns:
+    description: Assertion time
+    default: 0
+
+  gpmc,oe-off-ns:
+    description: Deassertion time
+    default: 0
+
+  gpmc,oe-aad-mux-on-ns:
+    description: Assertion time for AAD
+    default: 0
+
+  gpmc,oe-aad-mux-off-ns:
+    description: Deassertion time for AAD
+    default: 0
+
+# Access time and cycle time timings (in nanoseconds) corresponding to
+# GPMC_CONFIG5:
+  gpmc,page-burst-access-ns:
+    description: Multiple access word delay
+    default: 0
+
+  gpmc,access-ns:
+    description: Start-cycle to first data valid delay
+    default: 0
+
+  gpmc,rd-cycle-ns:
+    description: Total read cycle time
+    default: 0
+
+  gpmc,wr-cycle-ns:
+    description: Total write cycle time
+    default: 0
+
+  gpmc,bus-turnaround-ns:
+    description: Turn-around time between successive accesses
+    default: 0
+
+  gpmc,cycle2cycle-delay-ns:
+    description: Delay between chip-select pulses
+    default: 0
+
+  gpmc,clk-activation-ns:
+    description: GPMC clock activation time
+    default: 0
+
+  gpmc,wait-monitoring-ns:
+    description: Start of wait monitoring with regard to valid data
+    default: 0
+
+# Boolean timing parameters. If property is present, parameter is enabled
+# otherwise disabled.
+  gpmc,adv-extra-delay:
+    description: ADV signal is delayed by half GPMC clock
+    type: boolean
+
+  gpmc,cs-extra-delay:
+    description: CS signal is delayed by half GPMC clock
+    type: boolean
+
+  gpmc,cycle2cycle-diffcsen:
+    description: |
+      Add "cycle2cycle-delay" between successive accesses
+      to a different CS
+    type: boolean
+
+  gpmc,cycle2cycle-samecsen:
+    description: |
+      Add "cycle2cycle-delay" between successive accesses
+      to the same CS
+    type: boolean
+
+  gpmc,oe-extra-delay:
+    description: OE signal is delayed by half GPMC clock
+    type: boolean
+
+  gpmc,we-extra-delay:
+    description: WE signal is delayed by half GPMC clock
+    type: boolean
+
+  gpmc,time-para-granularity:
+    description: Multiply all access times by 2
+    type: boolean
+
+# The following two properties are applicable only to OMAP3+ and AM335x:
+  gpmc,wr-access-ns:
+    description: |
+      In synchronous write mode, for single or
+      burst accesses, defines the number of
+      GPMC_FCLK cycles from start access time
+      to the GPMC_CLK rising edge used by the
+      memory device for the first data capture.
+    default: 0
+
+  gpmc,wr-data-mux-bus-ns:
+    description: |
+      In address-data multiplex mode, specifies
+      the time when the first data is driven on
+      the address-data bus.
+    default: 0
+
+# GPMC chip-select settings properties for child nodes. All are optional.
+  gpmc,burst-length:
+    description: Page/burst length.
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 4, 8, 16]
+    default: 0
+
+  gpmc,burst-wrap:
+    description: Enables wrap bursting
+    type: boolean
+
+  gpmc,burst-read:
+    description: Enables read page/burst mode
+    type: boolean
+
+  gpmc,burst-write:
+    description: Enables write page/burst mode
+    type: boolean
+
+  gpmc,device-width:
+    description: |
+      Total width of device(s) connected to a GPMC
+      chip-select in bytes. The GPMC supports 8-bit
+      and 16-bit devices and so this property must be
+      1 or 2.
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [1, 2]
+    default: 1
+
+  gpmc,mux-add-data:
+    description: |
+      Address and data multiplexing configuration.
+      Valid values are
+      0 for Non multiplexed mode
+      1 for address-address-data multiplexing mode and
+      2 for address-data multiplexing mode.
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 1, 2]
+
+  gpmc,sync-read:
+    description: |
+      Enables synchronous read. Defaults to asynchronous
+      is this is not set.
+    type: boolean
+
+  gpmc,sync-write:
+    description: |
+      Enables synchronous writes. Defaults to asynchronous
+      is this is not set.
+    type: boolean
+
+  gpmc,wait-pin:
+    description: |
+      Wait-pin used by client. Must be less than "gpmc,num-waitpins".
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  gpmc,wait-pin-polarity:
+    description: |
+      Set the desired polarity for the selected wait pin.
+      0 for active low, 1 for active high.
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 1]
+
+  gpmc,wait-on-read:
+    description: Enables wait monitoring on reads.
+    type: boolean
+
+  gpmc,wait-on-write:
+    description: Enables wait monitoring on writes.
+    type: boolean
+
+required:
+  - reg
+
+# the GPMC child will have its own native properties
+additionalProperties: true
doc/device-tree-bindings/memory/ti,gpmc.yaml new file +190 -0

190 lines not on this page · raw message

Signature · 1 line
2.17.1
#8 lore raw

PATCH v3 4/4 memory: Add TI GPMC driver

In reply to Roger Quadros

The GPMC is a unified memory controller dedicated for interfacing with external memory devices like
- Asynchronous SRAM-like memories and ASICs
- Asynchronous, synchronous, and page mode burst NOR flash
- NAND flash
- Pseudo-SRAM devices

This driver will take care of setting up the GPMC based on the settings specified in the Device tree and then probe its children.

---
 drivers/memory/Kconfig        |   19 +
 drivers/memory/Makefile       |    1 +
 drivers/memory/ti-gpmc.c      | 1240 +++++++++++++++++++++++++++++++++
 drivers/memory/ti-gpmc.h      |  298 ++++++++
 include/linux/mtd/omap_gpmc.h |    3 +
 5 files changed, 1561 insertions(+)
 create mode 100644 drivers/memory/ti-gpmc.c
 create mode 100644 drivers/memory/ti-gpmc.h
drivers/memory/Kconfig +19 -0
index c621f5bba3..56b89f17be 100644
@@ -41,4 +41,23 @@ config TI_AEMIF
 	  of 256M bytes of any of these memories can be accessed at a given
 	  time via four chip selects with 64M byte access per chip select.
 
+config TI_GPMC
+	bool "Texas Instruments GPMC driver"
+	depends on ARCH_OMAP2PLUS || ARCH_KEYSTONE || ARCH_K3
+	depends on MEMORY && CLK && OF_CONTROL
+	help
+	  This driver is for the General Purpose Memory Controller (GPMC)
+          present on Texas Instruments SoCs (e.g. OMAP2+). GPMC allows
+          interfacing to a variety of asynchronous as well as synchronous
+          memory drives like NOR, NAND, OneNAND, SRAM.
+
+if TI_GPMC
+config TI_GPMC_DEBUG
+	bool "Debug Texas Instruments GPMC timings"
+	default n
+	help
+	  Enable this to print GPMC timings before and after the GPMC registers
+	  are programmed. This should not be left enabled on production systems.
+endif
+
 endmenu
drivers/memory/Makefile +1 -0
index b27f701865..2b196d78c0 100644
@@ -3,3 +3,4 @@ obj-$(CONFIG_MEMORY) += memory-uclass.o
 obj-$(CONFIG_SANDBOX_MEMORY) += memory-sandbox.o
 obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o
 obj-$(CONFIG_TI_AEMIF) += ti-aemif.o
+obj-$(CONFIG_TI_GPMC) += ti-gpmc.o
drivers/memory/ti-gpmc.c new file +1240 -0

1,240 lines not on this page · raw message

drivers/memory/ti-gpmc.h new file +298 -0

298 lines not on this page · raw message

include/linux/mtd/omap_gpmc.h +3 -0
index 864b05e432..f08e700a1d 100644
@@ -8,6 +8,9 @@
 #ifndef __ASM_OMAP_GPMC_H
 #define __ASM_OMAP_GPMC_H
 
+/* Maximum Number of Chip Selects */
+#define GPMC_CS_NUM	8
+
 #define GPMC_BUF_EMPTY	0
 #define GPMC_BUF_FULL	1
 #define GPMC_MAX_SECTORS	8
Signature · 1 line
2.17.1
#7 lore raw

Re: [u-boot][PATCH v3 3/4] dt/bindings: memory: Add bindings for TI GPMC driver

In reply to Roger Quadros
Quoted 8 lines · Roger Quadros

GPMC stands for General Purpose Memory Controller and it is present on many Texas Instruments SoCs.

It supports a number of Asynchronous and Synchronous interfaces and has various settings to configure the bus interface.

The DT bindings define all the various GPMC settings.

Quoted 7 lines

As the GPMC supports multiple devices on the bus, each device is represented as a child and the respective GPMC settings are situated there. (see ti,gpmc-child.yaml)

These binding docs are picked up from the Linux kernel.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#9 lore raw

Re: [u-boot][PATCH v3 4/4] memory: Add TI GPMC driver

In reply to Roger Quadros
Quoted 7 lines · Roger Quadros

The GPMC is a unified memory controller dedicated for interfacing with external memory devices like
- Asynchronous SRAM-like memories and ASICs
- Asynchronous, synchronous, and page mode burst NOR flash
- NAND flash
- Pseudo-SRAM devices

Quoted 5 lines

This driver will take care of setting up the GPMC based on the settings specified in the Device tree and then probe its children.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom