blob: b26423c457a775cd37ed7060eca646e42920e455 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -04002/*
3 * Keystone2: Asynchronous EMIF Configuration
4 *
5 * (C) Copyright 2012-2014
6 * Texas Instruments Incorporated, <www.ti.com>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -04007 */
8
Andrew Davisab82af62023-11-17 16:38:28 -06009#include <asm/arch/hardware.h>
Bastien Curutchet05460792024-10-21 17:13:27 +020010#include <asm/io.h>
Khoronzhuk, Ivan8062b052014-06-07 05:10:49 +030011#include <asm/ti-common/ti-aemif.h>
Bastien Curutchet9c073232024-10-21 17:13:29 +020012#include <dm.h>
13#include "ti-aemif-cs.h"
Khoronzhuk, Ivan8062b052014-06-07 05:10:49 +030014
Bastien Curutchet9f35e402024-10-21 17:13:26 +020015#define AEMIF_WAITCYCLE_CONFIG (0x4)
16#define AEMIF_NAND_CONTROL (0x60)
17#define AEMIF_ONENAND_CONTROL (0x5c)
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040018
Bastien Curutchet4d1ee402024-10-21 17:13:28 +020019static void aemif_configure(int cs, struct aemif_config *cfg)
20{
21 unsigned long tmp;
22
23 if (cfg->mode == AEMIF_MODE_NAND) {
24 tmp = __raw_readl(cfg->base + AEMIF_NAND_CONTROL);
25 tmp |= (1 << cs);
26 __raw_writel(tmp, cfg->base + AEMIF_NAND_CONTROL);
27
28 } else if (cfg->mode == AEMIF_MODE_ONENAND) {
29 tmp = __raw_readl(cfg->base + AEMIF_ONENAND_CONTROL);
30 tmp |= (1 << cs);
31 __raw_writel(tmp, cfg->base + AEMIF_ONENAND_CONTROL);
32 }
33
34 aemif_cs_configure(cs, cfg);
35}
36
Khoronzhuk, Ivan8062b052014-06-07 05:10:49 +030037void aemif_init(int num_cs, struct aemif_config *config)
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040038{
39 int cs;
40
Khoronzhuk, Ivan8062b052014-06-07 05:10:49 +030041 if (num_cs > AEMIF_NUM_CS) {
42 num_cs = AEMIF_NUM_CS;
43 printf("AEMIF: csnum has to be <= 5");
44 }
45
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040046 for (cs = 0; cs < num_cs; cs++)
Khoronzhuk, Ivan8062b052014-06-07 05:10:49 +030047 aemif_configure(cs, config + cs);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040048}
Bastien Curutchet9c073232024-10-21 17:13:29 +020049
50static const struct udevice_id aemif_ids[] = {
51 { .compatible = "ti,da850-aemif", },
52 {},
53};
54
55U_BOOT_DRIVER(ti_aemif) = {
56 .name = "ti_aemif",
57 .id = UCLASS_MEMORY,
58 .of_match = aemif_ids,
59};