memory: ti-aemif: Add DM support

The AEMIF's bindings in the Linux tree have a node for the AEMIF
controller and then a node for each AEMIF's chip select. This CS node
doesn't have a compatible property but describes the timing parameters
used by a given chip select.
The U-Boot DM framework expects every node to have a 'compatible'
property. If no 'compatible' is present in a node, its children won't be
parsed by u-boot.

Add DM support to the ti-aemif driver.
Add a new ti-aemif-cs driver to comply with the Linux bindings and the
U-Boot's DM philosophy. This driver handles the timing parameters
of an AEMIF's chip select so move aemif_cs_configure() from ti-aemif.c
to ti-aemif-cs.c.

Signed-off-by: Bastien Curutchet <bastien.curutchet@bootlin.com>
This commit is contained in:
Bastien Curutchet 2024-10-21 17:13:29 +02:00 committed by Tom Rini
parent 4b43602c8b
commit 94e45f7b50
4 changed files with 79 additions and 41 deletions

View file

@ -3,5 +3,5 @@ obj-$(CONFIG_MEMORY) += memory-uclass.o
obj-$(CONFIG_SANDBOX_MEMORY) += memory-sandbox.o obj-$(CONFIG_SANDBOX_MEMORY) += memory-sandbox.o
obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o
obj-$(CONFIG_ATMEL_EBI) += atmel_ebi.o obj-$(CONFIG_ATMEL_EBI) += atmel_ebi.o
obj-$(CONFIG_TI_AEMIF) += ti-aemif.o obj-$(CONFIG_TI_AEMIF) += ti-aemif.o ti-aemif-cs.o
obj-$(CONFIG_TI_GPMC) += ti-gpmc.o obj-$(CONFIG_TI_GPMC) += ti-gpmc.o

View file

@ -0,0 +1,61 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* DaVinci / Keystone2 : AEMIF's chip select configuration
*
*/
#include <asm/io.h>
#include <clk.h>
#include <dm.h>
#include "ti-aemif-cs.h"
#define AEMIF_CONFIG(cs) (0x10 + ((cs) * 4))
#define AEMIF_CFG_SELECT_STROBE(v) ((v) ? 1 << 31 : 0)
#define AEMIF_CFG_EXTEND_WAIT(v) ((v) ? 1 << 30 : 0)
#define AEMIF_CFG_WR_SETUP(v) (((v) & 0x0f) << 26)
#define AEMIF_CFG_WR_STROBE(v) (((v) & 0x3f) << 20)
#define AEMIF_CFG_WR_HOLD(v) (((v) & 0x07) << 17)
#define AEMIF_CFG_RD_SETUP(v) (((v) & 0x0f) << 13)
#define AEMIF_CFG_RD_STROBE(v) (((v) & 0x3f) << 7)
#define AEMIF_CFG_RD_HOLD(v) (((v) & 0x07) << 4)
#define AEMIF_CFG_TURN_AROUND(v) (((v) & 0x03) << 2)
#define AEMIF_CFG_WIDTH(v) (((v) & 0x03) << 0)
#define set_config_field(reg, field, val) \
do { \
if ((val) != -1) { \
(reg) &= ~AEMIF_CFG_##field(0xffffffff); \
(reg) |= AEMIF_CFG_##field((val)); \
} \
} while (0)
void aemif_cs_configure(int cs, struct aemif_config *cfg)
{
unsigned long tmp;
tmp = __raw_readl(cfg->base + AEMIF_CONFIG(cs));
set_config_field(tmp, SELECT_STROBE, cfg->select_strobe);
set_config_field(tmp, EXTEND_WAIT, cfg->extend_wait);
set_config_field(tmp, WR_SETUP, cfg->wr_setup);
set_config_field(tmp, WR_STROBE, cfg->wr_strobe);
set_config_field(tmp, WR_HOLD, cfg->wr_hold);
set_config_field(tmp, RD_SETUP, cfg->rd_setup);
set_config_field(tmp, RD_STROBE, cfg->rd_strobe);
set_config_field(tmp, RD_HOLD, cfg->rd_hold);
set_config_field(tmp, TURN_AROUND, cfg->turn_around);
set_config_field(tmp, WIDTH, cfg->width);
__raw_writel(tmp, cfg->base + AEMIF_CONFIG(cs));
}
static const struct udevice_id aemif_cs_ids[] = {
{ .compatible = "ti,da850-aemif-cs", },
{},
};
U_BOOT_DRIVER(ti_aemif_cs) = {
.name = "ti_aemif_cs",
.id = UCLASS_MEMORY,
.of_match = aemif_cs_ids,
};

View file

@ -0,0 +1,4 @@
/* SPDX-License-Identifier: GPL-2.0+ */
#include <asm/ti-common/ti-aemif.h>
void aemif_cs_configure(int cs, struct aemif_config *cfg);

View file

@ -9,50 +9,12 @@
#include <asm/arch/hardware.h> #include <asm/arch/hardware.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/ti-common/ti-aemif.h> #include <asm/ti-common/ti-aemif.h>
#include <dm.h>
#include "ti-aemif-cs.h"
#define AEMIF_WAITCYCLE_CONFIG (0x4) #define AEMIF_WAITCYCLE_CONFIG (0x4)
#define AEMIF_NAND_CONTROL (0x60) #define AEMIF_NAND_CONTROL (0x60)
#define AEMIF_ONENAND_CONTROL (0x5c) #define AEMIF_ONENAND_CONTROL (0x5c)
#define AEMIF_CONFIG(cs) (0x10 + ((cs) * 4))
#define AEMIF_CFG_SELECT_STROBE(v) ((v) ? 1 << 31 : 0)
#define AEMIF_CFG_EXTEND_WAIT(v) ((v) ? 1 << 30 : 0)
#define AEMIF_CFG_WR_SETUP(v) (((v) & 0x0f) << 26)
#define AEMIF_CFG_WR_STROBE(v) (((v) & 0x3f) << 20)
#define AEMIF_CFG_WR_HOLD(v) (((v) & 0x07) << 17)
#define AEMIF_CFG_RD_SETUP(v) (((v) & 0x0f) << 13)
#define AEMIF_CFG_RD_STROBE(v) (((v) & 0x3f) << 7)
#define AEMIF_CFG_RD_HOLD(v) (((v) & 0x07) << 4)
#define AEMIF_CFG_TURN_AROUND(v) (((v) & 0x03) << 2)
#define AEMIF_CFG_WIDTH(v) (((v) & 0x03) << 0)
#define set_config_field(reg, field, val) \
do { \
if (val != -1) { \
reg &= ~AEMIF_CFG_##field(0xffffffff); \
reg |= AEMIF_CFG_##field(val); \
} \
} while (0)
static void aemif_cs_configure(int cs, struct aemif_config *cfg)
{
unsigned long tmp;
tmp = __raw_readl(cfg->base + AEMIF_CONFIG(cs));
set_config_field(tmp, SELECT_STROBE, cfg->select_strobe);
set_config_field(tmp, EXTEND_WAIT, cfg->extend_wait);
set_config_field(tmp, WR_SETUP, cfg->wr_setup);
set_config_field(tmp, WR_STROBE, cfg->wr_strobe);
set_config_field(tmp, WR_HOLD, cfg->wr_hold);
set_config_field(tmp, RD_SETUP, cfg->rd_setup);
set_config_field(tmp, RD_STROBE, cfg->rd_strobe);
set_config_field(tmp, RD_HOLD, cfg->rd_hold);
set_config_field(tmp, TURN_AROUND, cfg->turn_around);
set_config_field(tmp, WIDTH, cfg->width);
__raw_writel(tmp, cfg->base + AEMIF_CONFIG(cs));
}
static void aemif_configure(int cs, struct aemif_config *cfg) static void aemif_configure(int cs, struct aemif_config *cfg)
{ {
@ -84,3 +46,14 @@ void aemif_init(int num_cs, struct aemif_config *config)
for (cs = 0; cs < num_cs; cs++) for (cs = 0; cs < num_cs; cs++)
aemif_configure(cs, config + cs); aemif_configure(cs, config + cs);
} }
static const struct udevice_id aemif_ids[] = {
{ .compatible = "ti,da850-aemif", },
{},
};
U_BOOT_DRIVER(ti_aemif) = {
.name = "ti_aemif",
.id = UCLASS_MEMORY,
.of_match = aemif_ids,
};