2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-04-10 22:02:51 +00:00
|
|
|
/*
|
2017-10-23 07:53:58 +00:00
|
|
|
* Copyright (C) 2017, STMicroelectronics - All Rights Reserved
|
|
|
|
* Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics.
|
2017-04-10 22:02:51 +00:00
|
|
|
*/
|
|
|
|
|
2020-11-06 18:01:35 +00:00
|
|
|
#define LOG_CATEGORY UCLASS_RAM
|
|
|
|
|
2017-04-10 22:02:51 +00:00
|
|
|
#include <common.h>
|
2017-04-10 22:02:55 +00:00
|
|
|
#include <clk.h>
|
2017-04-10 22:02:52 +00:00
|
|
|
#include <dm.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2017-04-10 22:02:52 +00:00
|
|
|
#include <ram.h>
|
2017-04-10 22:02:51 +00:00
|
|
|
#include <asm/io.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2017-04-10 22:02:51 +00:00
|
|
|
|
2017-12-12 08:49:41 +00:00
|
|
|
#define MEM_MODE_MASK GENMASK(2, 0)
|
2018-05-16 15:27:11 +00:00
|
|
|
#define SWP_FMC_OFFSET 10
|
|
|
|
#define SWP_FMC_MASK GENMASK(SWP_FMC_OFFSET+1, SWP_FMC_OFFSET)
|
2017-12-12 08:49:41 +00:00
|
|
|
#define NOT_FOUND 0xff
|
|
|
|
|
2017-07-18 15:37:24 +00:00
|
|
|
struct stm32_fmc_regs {
|
2017-07-18 15:37:25 +00:00
|
|
|
/* 0x0 */
|
|
|
|
u32 bcr1; /* NOR/PSRAM Chip select control register 1 */
|
|
|
|
u32 btr1; /* SRAM/NOR-Flash Chip select timing register 1 */
|
|
|
|
u32 bcr2; /* NOR/PSRAM Chip select Control register 2 */
|
|
|
|
u32 btr2; /* SRAM/NOR-Flash Chip select timing register 2 */
|
|
|
|
u32 bcr3; /* NOR/PSRAMChip select Control register 3 */
|
|
|
|
u32 btr3; /* SRAM/NOR-Flash Chip select timing register 3 */
|
|
|
|
u32 bcr4; /* NOR/PSRAM Chip select Control register 4 */
|
|
|
|
u32 btr4; /* SRAM/NOR-Flash Chip select timing register 4 */
|
|
|
|
u32 reserved1[24];
|
|
|
|
|
|
|
|
/* 0x80 */
|
|
|
|
u32 pcr; /* NAND Flash control register */
|
|
|
|
u32 sr; /* FIFO status and interrupt register */
|
|
|
|
u32 pmem; /* Common memory space timing register */
|
|
|
|
u32 patt; /* Attribute memory space timing registers */
|
|
|
|
u32 reserved2[1];
|
|
|
|
u32 eccr; /* ECC result registers */
|
|
|
|
u32 reserved3[27];
|
|
|
|
|
|
|
|
/* 0x104 */
|
|
|
|
u32 bwtr1; /* SRAM/NOR-Flash write timing register 1 */
|
|
|
|
u32 reserved4[1];
|
|
|
|
u32 bwtr2; /* SRAM/NOR-Flash write timing register 2 */
|
|
|
|
u32 reserved5[1];
|
|
|
|
u32 bwtr3; /* SRAM/NOR-Flash write timing register 3 */
|
|
|
|
u32 reserved6[1];
|
|
|
|
u32 bwtr4; /* SRAM/NOR-Flash write timing register 4 */
|
|
|
|
u32 reserved7[8];
|
|
|
|
|
|
|
|
/* 0x140 */
|
|
|
|
u32 sdcr1; /* SDRAM Control register 1 */
|
|
|
|
u32 sdcr2; /* SDRAM Control register 2 */
|
|
|
|
u32 sdtr1; /* SDRAM Timing register 1 */
|
|
|
|
u32 sdtr2; /* SDRAM Timing register 2 */
|
|
|
|
u32 sdcmr; /* SDRAM Mode register */
|
|
|
|
u32 sdrtr; /* SDRAM Refresh timing register */
|
|
|
|
u32 sdsr; /* SDRAM Status register */
|
2017-07-18 15:37:24 +00:00
|
|
|
};
|
|
|
|
|
2017-07-18 15:37:29 +00:00
|
|
|
/*
|
|
|
|
* NOR/PSRAM Control register BCR1
|
|
|
|
* FMC controller Enable, only availabe for H7
|
|
|
|
*/
|
|
|
|
#define FMC_BCR1_FMCEN BIT(31)
|
|
|
|
|
2017-07-18 15:37:24 +00:00
|
|
|
/* Control register SDCR */
|
|
|
|
#define FMC_SDCR_RPIPE_SHIFT 13 /* RPIPE bit shift */
|
|
|
|
#define FMC_SDCR_RBURST_SHIFT 12 /* RBURST bit shift */
|
|
|
|
#define FMC_SDCR_SDCLK_SHIFT 10 /* SDRAM clock divisor shift */
|
|
|
|
#define FMC_SDCR_WP_SHIFT 9 /* Write protection shift */
|
|
|
|
#define FMC_SDCR_CAS_SHIFT 7 /* CAS latency shift */
|
|
|
|
#define FMC_SDCR_NB_SHIFT 6 /* Number of banks shift */
|
|
|
|
#define FMC_SDCR_MWID_SHIFT 4 /* Memory width shift */
|
|
|
|
#define FMC_SDCR_NR_SHIFT 2 /* Number of row address bits shift */
|
|
|
|
#define FMC_SDCR_NC_SHIFT 0 /* Number of col address bits shift */
|
|
|
|
|
|
|
|
/* Timings register SDTR */
|
|
|
|
#define FMC_SDTR_TMRD_SHIFT 0 /* Load mode register to active */
|
|
|
|
#define FMC_SDTR_TXSR_SHIFT 4 /* Exit self-refresh time */
|
|
|
|
#define FMC_SDTR_TRAS_SHIFT 8 /* Self-refresh time */
|
|
|
|
#define FMC_SDTR_TRC_SHIFT 12 /* Row cycle delay */
|
|
|
|
#define FMC_SDTR_TWR_SHIFT 16 /* Recovery delay */
|
|
|
|
#define FMC_SDTR_TRP_SHIFT 20 /* Row precharge delay */
|
|
|
|
#define FMC_SDTR_TRCD_SHIFT 24 /* Row-to-column delay */
|
|
|
|
|
|
|
|
#define FMC_SDCMR_NRFS_SHIFT 5
|
|
|
|
|
|
|
|
#define FMC_SDCMR_MODE_NORMAL 0
|
|
|
|
#define FMC_SDCMR_MODE_START_CLOCK 1
|
|
|
|
#define FMC_SDCMR_MODE_PRECHARGE 2
|
|
|
|
#define FMC_SDCMR_MODE_AUTOREFRESH 3
|
|
|
|
#define FMC_SDCMR_MODE_WRITE_MODE 4
|
|
|
|
#define FMC_SDCMR_MODE_SELFREFRESH 5
|
|
|
|
#define FMC_SDCMR_MODE_POWERDOWN 6
|
|
|
|
|
|
|
|
#define FMC_SDCMR_BANK_1 BIT(4)
|
|
|
|
#define FMC_SDCMR_BANK_2 BIT(3)
|
|
|
|
|
|
|
|
#define FMC_SDCMR_MODE_REGISTER_SHIFT 9
|
|
|
|
|
|
|
|
#define FMC_SDSR_BUSY BIT(5)
|
|
|
|
|
2017-07-18 15:37:25 +00:00
|
|
|
#define FMC_BUSY_WAIT(regs) do { \
|
2017-07-18 15:37:24 +00:00
|
|
|
__asm__ __volatile__ ("dsb" : : : "memory"); \
|
2017-07-18 15:37:25 +00:00
|
|
|
while (regs->sdsr & FMC_SDSR_BUSY) \
|
2017-07-18 15:37:24 +00:00
|
|
|
; \
|
|
|
|
} while (0)
|
|
|
|
|
2017-04-10 22:02:56 +00:00
|
|
|
struct stm32_sdram_control {
|
|
|
|
u8 no_columns;
|
|
|
|
u8 no_rows;
|
|
|
|
u8 memory_width;
|
|
|
|
u8 no_banks;
|
|
|
|
u8 cas_latency;
|
2017-04-10 22:03:03 +00:00
|
|
|
u8 sdclk;
|
2017-04-10 22:02:56 +00:00
|
|
|
u8 rd_burst;
|
|
|
|
u8 rd_pipe_delay;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stm32_sdram_timing {
|
|
|
|
u8 tmrd;
|
|
|
|
u8 txsr;
|
|
|
|
u8 tras;
|
|
|
|
u8 trc;
|
|
|
|
u8 trp;
|
2017-04-10 22:03:03 +00:00
|
|
|
u8 twr;
|
2017-04-10 22:02:56 +00:00
|
|
|
u8 trcd;
|
|
|
|
};
|
2017-07-18 15:37:27 +00:00
|
|
|
enum stm32_fmc_bank {
|
|
|
|
SDRAM_BANK1,
|
|
|
|
SDRAM_BANK2,
|
|
|
|
MAX_SDRAM_BANK,
|
|
|
|
};
|
|
|
|
|
2017-07-18 15:37:29 +00:00
|
|
|
enum stm32_fmc_family {
|
|
|
|
STM32F7_FMC,
|
|
|
|
STM32H7_FMC,
|
|
|
|
};
|
|
|
|
|
2017-07-18 15:37:27 +00:00
|
|
|
struct bank_params {
|
2017-07-18 15:37:26 +00:00
|
|
|
struct stm32_sdram_control *sdram_control;
|
|
|
|
struct stm32_sdram_timing *sdram_timing;
|
2017-04-10 22:03:03 +00:00
|
|
|
u32 sdram_ref_count;
|
2017-07-18 15:37:27 +00:00
|
|
|
enum stm32_fmc_bank target_bank;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stm32_sdram_params {
|
|
|
|
struct stm32_fmc_regs *base;
|
|
|
|
u8 no_sdram_banks;
|
|
|
|
struct bank_params bank_params[MAX_SDRAM_BANK];
|
2017-07-18 15:37:29 +00:00
|
|
|
enum stm32_fmc_family family;
|
2017-04-10 22:02:56 +00:00
|
|
|
};
|
2017-04-10 22:02:51 +00:00
|
|
|
|
|
|
|
#define SDRAM_MODE_BL_SHIFT 0
|
|
|
|
#define SDRAM_MODE_CAS_SHIFT 4
|
|
|
|
#define SDRAM_MODE_BL 0
|
|
|
|
|
2017-04-10 22:02:56 +00:00
|
|
|
int stm32_sdram_init(struct udevice *dev)
|
2017-04-10 22:02:51 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct stm32_sdram_params *params = dev_get_plat(dev);
|
2017-07-18 15:37:27 +00:00
|
|
|
struct stm32_sdram_control *control;
|
|
|
|
struct stm32_sdram_timing *timing;
|
2017-07-18 15:37:25 +00:00
|
|
|
struct stm32_fmc_regs *regs = params->base;
|
2017-07-18 15:37:27 +00:00
|
|
|
enum stm32_fmc_bank target_bank;
|
|
|
|
u32 ctb; /* SDCMR register: Command Target Bank */
|
|
|
|
u32 ref_count;
|
|
|
|
u8 i;
|
|
|
|
|
2017-07-18 15:37:29 +00:00
|
|
|
/* disable the FMC controller */
|
|
|
|
if (params->family == STM32H7_FMC)
|
|
|
|
clrbits_le32(®s->bcr1, FMC_BCR1_FMCEN);
|
|
|
|
|
2017-07-18 15:37:27 +00:00
|
|
|
for (i = 0; i < params->no_sdram_banks; i++) {
|
|
|
|
control = params->bank_params[i].sdram_control;
|
|
|
|
timing = params->bank_params[i].sdram_timing;
|
|
|
|
target_bank = params->bank_params[i].target_bank;
|
|
|
|
ref_count = params->bank_params[i].sdram_ref_count;
|
|
|
|
|
|
|
|
writel(control->sdclk << FMC_SDCR_SDCLK_SHIFT
|
|
|
|
| control->cas_latency << FMC_SDCR_CAS_SHIFT
|
|
|
|
| control->no_banks << FMC_SDCR_NB_SHIFT
|
|
|
|
| control->memory_width << FMC_SDCR_MWID_SHIFT
|
|
|
|
| control->no_rows << FMC_SDCR_NR_SHIFT
|
|
|
|
| control->no_columns << FMC_SDCR_NC_SHIFT
|
|
|
|
| control->rd_pipe_delay << FMC_SDCR_RPIPE_SHIFT
|
|
|
|
| control->rd_burst << FMC_SDCR_RBURST_SHIFT,
|
|
|
|
®s->sdcr1);
|
|
|
|
|
|
|
|
if (target_bank == SDRAM_BANK2)
|
|
|
|
writel(control->cas_latency << FMC_SDCR_CAS_SHIFT
|
|
|
|
| control->no_banks << FMC_SDCR_NB_SHIFT
|
|
|
|
| control->memory_width << FMC_SDCR_MWID_SHIFT
|
|
|
|
| control->no_rows << FMC_SDCR_NR_SHIFT
|
|
|
|
| control->no_columns << FMC_SDCR_NC_SHIFT,
|
|
|
|
®s->sdcr2);
|
|
|
|
|
|
|
|
writel(timing->trcd << FMC_SDTR_TRCD_SHIFT
|
|
|
|
| timing->trp << FMC_SDTR_TRP_SHIFT
|
|
|
|
| timing->twr << FMC_SDTR_TWR_SHIFT
|
|
|
|
| timing->trc << FMC_SDTR_TRC_SHIFT
|
|
|
|
| timing->tras << FMC_SDTR_TRAS_SHIFT
|
|
|
|
| timing->txsr << FMC_SDTR_TXSR_SHIFT
|
|
|
|
| timing->tmrd << FMC_SDTR_TMRD_SHIFT,
|
|
|
|
®s->sdtr1);
|
|
|
|
|
|
|
|
if (target_bank == SDRAM_BANK2)
|
|
|
|
writel(timing->trcd << FMC_SDTR_TRCD_SHIFT
|
|
|
|
| timing->trp << FMC_SDTR_TRP_SHIFT
|
|
|
|
| timing->twr << FMC_SDTR_TWR_SHIFT
|
|
|
|
| timing->trc << FMC_SDTR_TRC_SHIFT
|
|
|
|
| timing->tras << FMC_SDTR_TRAS_SHIFT
|
|
|
|
| timing->txsr << FMC_SDTR_TXSR_SHIFT
|
|
|
|
| timing->tmrd << FMC_SDTR_TMRD_SHIFT,
|
|
|
|
®s->sdtr2);
|
2017-07-18 15:37:29 +00:00
|
|
|
|
2017-07-18 15:37:27 +00:00
|
|
|
if (target_bank == SDRAM_BANK1)
|
|
|
|
ctb = FMC_SDCMR_BANK_1;
|
|
|
|
else
|
|
|
|
ctb = FMC_SDCMR_BANK_2;
|
|
|
|
|
|
|
|
writel(ctb | FMC_SDCMR_MODE_START_CLOCK, ®s->sdcmr);
|
|
|
|
udelay(200); /* 200 us delay, page 10, "Power-Up" */
|
|
|
|
FMC_BUSY_WAIT(regs);
|
|
|
|
|
|
|
|
writel(ctb | FMC_SDCMR_MODE_PRECHARGE, ®s->sdcmr);
|
|
|
|
udelay(100);
|
|
|
|
FMC_BUSY_WAIT(regs);
|
|
|
|
|
|
|
|
writel((ctb | FMC_SDCMR_MODE_AUTOREFRESH | 7 << FMC_SDCMR_NRFS_SHIFT),
|
|
|
|
®s->sdcmr);
|
|
|
|
udelay(100);
|
|
|
|
FMC_BUSY_WAIT(regs);
|
|
|
|
|
|
|
|
writel(ctb | (SDRAM_MODE_BL << SDRAM_MODE_BL_SHIFT
|
|
|
|
| control->cas_latency << SDRAM_MODE_CAS_SHIFT)
|
|
|
|
<< FMC_SDCMR_MODE_REGISTER_SHIFT | FMC_SDCMR_MODE_WRITE_MODE,
|
|
|
|
®s->sdcmr);
|
|
|
|
udelay(100);
|
|
|
|
FMC_BUSY_WAIT(regs);
|
|
|
|
|
|
|
|
writel(ctb | FMC_SDCMR_MODE_NORMAL, ®s->sdcmr);
|
|
|
|
FMC_BUSY_WAIT(regs);
|
|
|
|
|
|
|
|
/* Refresh timer */
|
|
|
|
writel(ref_count << 1, ®s->sdrtr);
|
|
|
|
}
|
2017-04-10 22:02:51 +00:00
|
|
|
|
2017-07-18 15:37:29 +00:00
|
|
|
/* enable the FMC controller */
|
|
|
|
if (params->family == STM32H7_FMC)
|
|
|
|
setbits_le32(®s->bcr1, FMC_BCR1_FMCEN);
|
|
|
|
|
2017-04-10 22:02:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-04-10 22:02:52 +00:00
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int stm32_fmc_of_to_plat(struct udevice *dev)
|
2017-04-10 22:02:56 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct stm32_sdram_params *params = dev_get_plat(dev);
|
2017-07-18 15:37:27 +00:00
|
|
|
struct bank_params *bank_params;
|
2017-12-12 08:49:41 +00:00
|
|
|
struct ofnode_phandle_args args;
|
|
|
|
u32 *syscfg_base;
|
|
|
|
u32 mem_remap;
|
2018-05-16 15:27:11 +00:00
|
|
|
u32 swp_fmc;
|
2017-07-18 15:37:27 +00:00
|
|
|
ofnode bank_node;
|
|
|
|
char *bank_name;
|
2021-04-09 07:28:45 +00:00
|
|
|
char _bank_name[128] = {0};
|
2017-07-18 15:37:27 +00:00
|
|
|
u8 bank = 0;
|
2017-12-12 08:49:41 +00:00
|
|
|
int ret;
|
|
|
|
|
2018-05-16 15:27:11 +00:00
|
|
|
ret = dev_read_phandle_with_args(dev, "st,syscfg", NULL, 0, 0,
|
2017-12-12 08:49:41 +00:00
|
|
|
&args);
|
2018-05-16 15:27:11 +00:00
|
|
|
if (ret) {
|
2020-11-06 18:01:35 +00:00
|
|
|
dev_dbg(dev, "can't find syscon device (%d)\n", ret);
|
2018-05-16 15:27:11 +00:00
|
|
|
} else {
|
2017-12-12 08:49:41 +00:00
|
|
|
syscfg_base = (u32 *)ofnode_get_addr(args.node);
|
|
|
|
|
2018-05-16 15:27:11 +00:00
|
|
|
mem_remap = dev_read_u32_default(dev, "st,mem_remap", NOT_FOUND);
|
|
|
|
if (mem_remap != NOT_FOUND) {
|
|
|
|
/* set memory mapping selection */
|
|
|
|
clrsetbits_le32(syscfg_base, MEM_MODE_MASK, mem_remap);
|
|
|
|
} else {
|
2020-11-06 18:01:35 +00:00
|
|
|
dev_dbg(dev, "cannot find st,mem_remap property\n");
|
2018-05-16 15:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
swp_fmc = dev_read_u32_default(dev, "st,swp_fmc", NOT_FOUND);
|
|
|
|
if (swp_fmc != NOT_FOUND) {
|
|
|
|
/* set fmc swapping selection */
|
|
|
|
clrsetbits_le32(syscfg_base, SWP_FMC_MASK, swp_fmc << SWP_FMC_OFFSET);
|
|
|
|
} else {
|
2020-11-06 18:01:35 +00:00
|
|
|
dev_dbg(dev, "cannot find st,swp_fmc property\n");
|
2018-05-16 15:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(dev, "syscfg %x = %x\n", (u32)syscfg_base, *syscfg_base);
|
2017-12-12 08:49:41 +00:00
|
|
|
}
|
2017-04-10 22:02:56 +00:00
|
|
|
|
2017-07-18 15:37:26 +00:00
|
|
|
dev_for_each_subnode(bank_node, dev) {
|
2017-07-18 15:37:27 +00:00
|
|
|
/* extract the bank index from DT */
|
|
|
|
bank_name = (char *)ofnode_get_name(bank_node);
|
2021-04-09 07:28:45 +00:00
|
|
|
strlcpy(_bank_name, bank_name, sizeof(_bank_name));
|
|
|
|
bank_name = (char *)_bank_name;
|
2017-07-18 15:37:27 +00:00
|
|
|
strsep(&bank_name, "@");
|
|
|
|
if (!bank_name) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("missing sdram bank index");
|
2017-07-18 15:37:27 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bank_params = ¶ms->bank_params[bank];
|
|
|
|
strict_strtoul(bank_name, 10,
|
|
|
|
(long unsigned int *)&bank_params->target_bank);
|
|
|
|
|
|
|
|
if (bank_params->target_bank >= MAX_SDRAM_BANK) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("Found bank %d , but only bank 0 and 1 are supported",
|
2017-07-18 15:37:27 +00:00
|
|
|
bank_params->target_bank);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("Find bank %s %u\n", bank_name, bank_params->target_bank);
|
|
|
|
|
|
|
|
params->bank_params[bank].sdram_control =
|
|
|
|
(struct stm32_sdram_control *)
|
|
|
|
ofnode_read_u8_array_ptr(bank_node,
|
|
|
|
"st,sdram-control",
|
|
|
|
sizeof(struct stm32_sdram_control));
|
|
|
|
|
|
|
|
if (!params->bank_params[bank].sdram_control) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("st,sdram-control not found for %s",
|
2017-07-18 15:37:27 +00:00
|
|
|
ofnode_get_name(bank_node));
|
2017-07-18 15:37:26 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-18 15:37:27 +00:00
|
|
|
params->bank_params[bank].sdram_timing =
|
|
|
|
(struct stm32_sdram_timing *)
|
|
|
|
ofnode_read_u8_array_ptr(bank_node,
|
|
|
|
"st,sdram-timing",
|
|
|
|
sizeof(struct stm32_sdram_timing));
|
|
|
|
|
|
|
|
if (!params->bank_params[bank].sdram_timing) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("st,sdram-timing not found for %s",
|
2017-07-18 15:37:27 +00:00
|
|
|
ofnode_get_name(bank_node));
|
2017-07-18 15:37:26 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-07-18 15:37:27 +00:00
|
|
|
|
|
|
|
bank_params->sdram_ref_count = ofnode_read_u32_default(bank_node,
|
2017-04-10 22:03:03 +00:00
|
|
|
"st,sdram-refcount", 8196);
|
2017-07-18 15:37:27 +00:00
|
|
|
bank++;
|
2017-04-10 22:02:56 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 15:37:27 +00:00
|
|
|
params->no_sdram_banks = bank;
|
2020-11-06 18:01:35 +00:00
|
|
|
dev_dbg(dev, "no of banks = %d\n", params->no_sdram_banks);
|
2017-07-18 15:37:27 +00:00
|
|
|
|
2017-04-10 22:02:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-10 22:02:52 +00:00
|
|
|
static int stm32_fmc_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct stm32_sdram_params *params = dev_get_plat(dev);
|
2017-04-10 22:02:55 +00:00
|
|
|
int ret;
|
2017-07-18 15:37:25 +00:00
|
|
|
fdt_addr_t addr;
|
|
|
|
|
|
|
|
addr = dev_read_addr(dev);
|
|
|
|
if (addr == FDT_ADDR_T_NONE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
params->base = (struct stm32_fmc_regs *)addr;
|
2017-07-18 15:37:29 +00:00
|
|
|
params->family = dev_get_driver_data(dev);
|
2017-07-18 15:37:25 +00:00
|
|
|
|
2017-05-30 13:06:31 +00:00
|
|
|
#ifdef CONFIG_CLK
|
2017-04-10 22:02:55 +00:00
|
|
|
struct clk clk;
|
2017-04-10 22:02:56 +00:00
|
|
|
|
2017-04-10 22:02:55 +00:00
|
|
|
ret = clk_get_by_index(dev, 0, &clk);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = clk_enable(&clk);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "failed to enable clock\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
2017-04-10 22:02:56 +00:00
|
|
|
ret = stm32_sdram_init(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2017-04-10 22:02:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stm32_fmc_get_info(struct udevice *dev, struct ram_info *info)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ram_ops stm32_fmc_ops = {
|
|
|
|
.get_info = stm32_fmc_get_info,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id stm32_fmc_ids[] = {
|
2017-07-18 15:37:29 +00:00
|
|
|
{ .compatible = "st,stm32-fmc", .data = STM32F7_FMC },
|
|
|
|
{ .compatible = "st,stm32h7-fmc", .data = STM32H7_FMC },
|
2017-04-10 22:02:52 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(stm32_fmc) = {
|
|
|
|
.name = "stm32_fmc",
|
|
|
|
.id = UCLASS_RAM,
|
|
|
|
.of_match = stm32_fmc_ids,
|
|
|
|
.ops = &stm32_fmc_ops,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = stm32_fmc_of_to_plat,
|
2017-04-10 22:02:52 +00:00
|
|
|
.probe = stm32_fmc_probe,
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct stm32_sdram_params),
|
2017-04-10 22:02:52 +00:00
|
|
|
};
|