Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Keystone2: Asynchronous EMIF Configuration |
| 4 | * |
| 5 | * (C) Copyright 2012-2014 |
| 6 | * Texas Instruments Incorporated, <www.ti.com> |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
Andrew Davis | ab82af6 | 2023-11-17 16:38:28 -0600 | [diff] [blame] | 9 | #include <asm/arch/hardware.h> |
Bastien Curutchet | 0546079 | 2024-10-21 17:13:27 +0200 | [diff] [blame] | 10 | #include <asm/io.h> |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 11 | #include <asm/ti-common/ti-aemif.h> |
Bastien Curutchet | 9c07323 | 2024-10-21 17:13:29 +0200 | [diff] [blame] | 12 | #include <dm.h> |
| 13 | #include "ti-aemif-cs.h" |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 14 | |
Bastien Curutchet | 9f35e40 | 2024-10-21 17:13:26 +0200 | [diff] [blame] | 15 | #define AEMIF_WAITCYCLE_CONFIG (0x4) |
| 16 | #define AEMIF_NAND_CONTROL (0x60) |
| 17 | #define AEMIF_ONENAND_CONTROL (0x5c) |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 18 | |
Bastien Curutchet | 4d1ee40 | 2024-10-21 17:13:28 +0200 | [diff] [blame] | 19 | static 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, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 37 | void aemif_init(int num_cs, struct aemif_config *config) |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 38 | { |
| 39 | int cs; |
| 40 | |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 41 | if (num_cs > AEMIF_NUM_CS) { |
| 42 | num_cs = AEMIF_NUM_CS; |
| 43 | printf("AEMIF: csnum has to be <= 5"); |
| 44 | } |
| 45 | |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 46 | for (cs = 0; cs < num_cs; cs++) |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 47 | aemif_configure(cs, config + cs); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 48 | } |
Bastien Curutchet | 9c07323 | 2024-10-21 17:13:29 +0200 | [diff] [blame] | 49 | |
| 50 | static const struct udevice_id aemif_ids[] = { |
| 51 | { .compatible = "ti,da850-aemif", }, |
| 52 | {}, |
| 53 | }; |
| 54 | |
| 55 | U_BOOT_DRIVER(ti_aemif) = { |
| 56 | .name = "ti_aemif", |
| 57 | .id = UCLASS_MEMORY, |
| 58 | .of_match = aemif_ids, |
| 59 | }; |