blob: 891f4137813ee08383a950ba5d61c3f61bd7be98 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vikas Manochabf1ae442017-04-10 15:02:51 -07002/*
Patrice Chotard3bc599c2017-10-23 09:53:58 +02003 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4 * Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics.
Vikas Manochabf1ae442017-04-10 15:02:51 -07005 */
6
Patrick Delaunay997f7da2020-11-06 19:01:35 +01007#define LOG_CATEGORY UCLASS_RAM
8
Vikas Manochabf1ae442017-04-10 15:02:51 -07009#include <common.h>
Vikas Manochad0b24c12017-04-10 15:02:55 -070010#include <clk.h>
Vikas Manocha910a52e2017-04-10 15:02:52 -070011#include <dm.h>
Simon Glass691d7192020-05-10 11:40:02 -060012#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Vikas Manocha910a52e2017-04-10 15:02:52 -070014#include <ram.h>
Vikas Manochabf1ae442017-04-10 15:02:51 -070015#include <asm/io.h>
Simon Glass336d4612020-02-03 07:36:16 -070016#include <dm/device_compat.h>
Simon Glasscd93d622020-05-10 11:40:13 -060017#include <linux/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060018#include <linux/delay.h>
Simon Glass1e94b462023-09-14 18:21:46 -060019#include <linux/printk.h>
Vikas Manochabf1ae442017-04-10 15:02:51 -070020
Patrice Chotard0b3f7892017-12-12 09:49:41 +010021#define MEM_MODE_MASK GENMASK(2, 0)
Radoslaw Pietrzyk246a5e52018-05-16 17:27:11 +020022#define SWP_FMC_OFFSET 10
23#define SWP_FMC_MASK GENMASK(SWP_FMC_OFFSET+1, SWP_FMC_OFFSET)
Patrice Chotard0b3f7892017-12-12 09:49:41 +010024#define NOT_FOUND 0xff
25
Patrice Chotard9242ece2017-07-18 17:37:24 +020026struct stm32_fmc_regs {
Patrice Chotard1421e0a2017-07-18 17:37:25 +020027 /* 0x0 */
28 u32 bcr1; /* NOR/PSRAM Chip select control register 1 */
29 u32 btr1; /* SRAM/NOR-Flash Chip select timing register 1 */
30 u32 bcr2; /* NOR/PSRAM Chip select Control register 2 */
31 u32 btr2; /* SRAM/NOR-Flash Chip select timing register 2 */
32 u32 bcr3; /* NOR/PSRAMChip select Control register 3 */
33 u32 btr3; /* SRAM/NOR-Flash Chip select timing register 3 */
34 u32 bcr4; /* NOR/PSRAM Chip select Control register 4 */
35 u32 btr4; /* SRAM/NOR-Flash Chip select timing register 4 */
36 u32 reserved1[24];
Patrice Chotard9242ece2017-07-18 17:37:24 +020037
Patrice Chotard1421e0a2017-07-18 17:37:25 +020038 /* 0x80 */
39 u32 pcr; /* NAND Flash control register */
40 u32 sr; /* FIFO status and interrupt register */
41 u32 pmem; /* Common memory space timing register */
42 u32 patt; /* Attribute memory space timing registers */
43 u32 reserved2[1];
44 u32 eccr; /* ECC result registers */
45 u32 reserved3[27];
46
47 /* 0x104 */
48 u32 bwtr1; /* SRAM/NOR-Flash write timing register 1 */
49 u32 reserved4[1];
50 u32 bwtr2; /* SRAM/NOR-Flash write timing register 2 */
51 u32 reserved5[1];
52 u32 bwtr3; /* SRAM/NOR-Flash write timing register 3 */
53 u32 reserved6[1];
54 u32 bwtr4; /* SRAM/NOR-Flash write timing register 4 */
55 u32 reserved7[8];
56
57 /* 0x140 */
58 u32 sdcr1; /* SDRAM Control register 1 */
59 u32 sdcr2; /* SDRAM Control register 2 */
60 u32 sdtr1; /* SDRAM Timing register 1 */
61 u32 sdtr2; /* SDRAM Timing register 2 */
62 u32 sdcmr; /* SDRAM Mode register */
63 u32 sdrtr; /* SDRAM Refresh timing register */
64 u32 sdsr; /* SDRAM Status register */
65};
Patrice Chotard9242ece2017-07-18 17:37:24 +020066
Patrice Chotard70166512017-07-18 17:37:29 +020067/*
68 * NOR/PSRAM Control register BCR1
69 * FMC controller Enable, only availabe for H7
70 */
71#define FMC_BCR1_FMCEN BIT(31)
72
Patrice Chotard9242ece2017-07-18 17:37:24 +020073/* Control register SDCR */
74#define FMC_SDCR_RPIPE_SHIFT 13 /* RPIPE bit shift */
75#define FMC_SDCR_RBURST_SHIFT 12 /* RBURST bit shift */
76#define FMC_SDCR_SDCLK_SHIFT 10 /* SDRAM clock divisor shift */
77#define FMC_SDCR_WP_SHIFT 9 /* Write protection shift */
78#define FMC_SDCR_CAS_SHIFT 7 /* CAS latency shift */
79#define FMC_SDCR_NB_SHIFT 6 /* Number of banks shift */
80#define FMC_SDCR_MWID_SHIFT 4 /* Memory width shift */
81#define FMC_SDCR_NR_SHIFT 2 /* Number of row address bits shift */
82#define FMC_SDCR_NC_SHIFT 0 /* Number of col address bits shift */
83
84/* Timings register SDTR */
85#define FMC_SDTR_TMRD_SHIFT 0 /* Load mode register to active */
86#define FMC_SDTR_TXSR_SHIFT 4 /* Exit self-refresh time */
87#define FMC_SDTR_TRAS_SHIFT 8 /* Self-refresh time */
88#define FMC_SDTR_TRC_SHIFT 12 /* Row cycle delay */
89#define FMC_SDTR_TWR_SHIFT 16 /* Recovery delay */
90#define FMC_SDTR_TRP_SHIFT 20 /* Row precharge delay */
91#define FMC_SDTR_TRCD_SHIFT 24 /* Row-to-column delay */
92
93#define FMC_SDCMR_NRFS_SHIFT 5
94
95#define FMC_SDCMR_MODE_NORMAL 0
96#define FMC_SDCMR_MODE_START_CLOCK 1
97#define FMC_SDCMR_MODE_PRECHARGE 2
98#define FMC_SDCMR_MODE_AUTOREFRESH 3
99#define FMC_SDCMR_MODE_WRITE_MODE 4
100#define FMC_SDCMR_MODE_SELFREFRESH 5
101#define FMC_SDCMR_MODE_POWERDOWN 6
102
103#define FMC_SDCMR_BANK_1 BIT(4)
104#define FMC_SDCMR_BANK_2 BIT(3)
105
106#define FMC_SDCMR_MODE_REGISTER_SHIFT 9
107
108#define FMC_SDSR_BUSY BIT(5)
109
Patrice Chotard1421e0a2017-07-18 17:37:25 +0200110#define FMC_BUSY_WAIT(regs) do { \
Patrice Chotard9242ece2017-07-18 17:37:24 +0200111 __asm__ __volatile__ ("dsb" : : : "memory"); \
Patrice Chotard1421e0a2017-07-18 17:37:25 +0200112 while (regs->sdsr & FMC_SDSR_BUSY) \
Patrice Chotard9242ece2017-07-18 17:37:24 +0200113 ; \
114 } while (0)
115
Vikas Manocha6c9a1002017-04-10 15:02:56 -0700116struct stm32_sdram_control {
117 u8 no_columns;
118 u8 no_rows;
119 u8 memory_width;
120 u8 no_banks;
121 u8 cas_latency;
Vikas Manochabfea69a2017-04-10 15:03:03 -0700122 u8 sdclk;
Vikas Manocha6c9a1002017-04-10 15:02:56 -0700123 u8 rd_burst;
124 u8 rd_pipe_delay;
125};
126
127struct stm32_sdram_timing {
128 u8 tmrd;
129 u8 txsr;
130 u8 tras;
131 u8 trc;
132 u8 trp;
Vikas Manochabfea69a2017-04-10 15:03:03 -0700133 u8 twr;
Vikas Manocha6c9a1002017-04-10 15:02:56 -0700134 u8 trcd;
135};
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200136enum stm32_fmc_bank {
137 SDRAM_BANK1,
138 SDRAM_BANK2,
139 MAX_SDRAM_BANK,
140};
141
Patrice Chotard70166512017-07-18 17:37:29 +0200142enum stm32_fmc_family {
143 STM32F7_FMC,
144 STM32H7_FMC,
145};
146
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200147struct bank_params {
Patrice Chotardf39b90d2017-07-18 17:37:26 +0200148 struct stm32_sdram_control *sdram_control;
149 struct stm32_sdram_timing *sdram_timing;
Vikas Manochabfea69a2017-04-10 15:03:03 -0700150 u32 sdram_ref_count;
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200151 enum stm32_fmc_bank target_bank;
152};
153
154struct stm32_sdram_params {
155 struct stm32_fmc_regs *base;
156 u8 no_sdram_banks;
157 struct bank_params bank_params[MAX_SDRAM_BANK];
Patrice Chotard70166512017-07-18 17:37:29 +0200158 enum stm32_fmc_family family;
Vikas Manocha6c9a1002017-04-10 15:02:56 -0700159};
Vikas Manochabf1ae442017-04-10 15:02:51 -0700160
161#define SDRAM_MODE_BL_SHIFT 0
162#define SDRAM_MODE_CAS_SHIFT 4
163#define SDRAM_MODE_BL 0
Vikas Manocha6c9a1002017-04-10 15:02:56 -0700164
165int stm32_sdram_init(struct udevice *dev)
Vikas Manochabf1ae442017-04-10 15:02:51 -0700166{
Simon Glassc69cda22020-12-03 16:55:20 -0700167 struct stm32_sdram_params *params = dev_get_plat(dev);
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200168 struct stm32_sdram_control *control;
169 struct stm32_sdram_timing *timing;
Patrice Chotard1421e0a2017-07-18 17:37:25 +0200170 struct stm32_fmc_regs *regs = params->base;
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200171 enum stm32_fmc_bank target_bank;
172 u32 ctb; /* SDCMR register: Command Target Bank */
173 u32 ref_count;
174 u8 i;
Vikas Manochabf1ae442017-04-10 15:02:51 -0700175
Patrice Chotard70166512017-07-18 17:37:29 +0200176 /* disable the FMC controller */
177 if (params->family == STM32H7_FMC)
178 clrbits_le32(&regs->bcr1, FMC_BCR1_FMCEN);
179
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200180 for (i = 0; i < params->no_sdram_banks; i++) {
181 control = params->bank_params[i].sdram_control;
182 timing = params->bank_params[i].sdram_timing;
183 target_bank = params->bank_params[i].target_bank;
184 ref_count = params->bank_params[i].sdram_ref_count;
Vikas Manochabf1ae442017-04-10 15:02:51 -0700185
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200186 writel(control->sdclk << FMC_SDCR_SDCLK_SHIFT
187 | control->cas_latency << FMC_SDCR_CAS_SHIFT
188 | control->no_banks << FMC_SDCR_NB_SHIFT
189 | control->memory_width << FMC_SDCR_MWID_SHIFT
190 | control->no_rows << FMC_SDCR_NR_SHIFT
191 | control->no_columns << FMC_SDCR_NC_SHIFT
192 | control->rd_pipe_delay << FMC_SDCR_RPIPE_SHIFT
193 | control->rd_burst << FMC_SDCR_RBURST_SHIFT,
194 &regs->sdcr1);
Vikas Manochabf1ae442017-04-10 15:02:51 -0700195
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200196 if (target_bank == SDRAM_BANK2)
197 writel(control->cas_latency << FMC_SDCR_CAS_SHIFT
198 | control->no_banks << FMC_SDCR_NB_SHIFT
199 | control->memory_width << FMC_SDCR_MWID_SHIFT
200 | control->no_rows << FMC_SDCR_NR_SHIFT
201 | control->no_columns << FMC_SDCR_NC_SHIFT,
202 &regs->sdcr2);
Vikas Manochabf1ae442017-04-10 15:02:51 -0700203
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200204 writel(timing->trcd << FMC_SDTR_TRCD_SHIFT
205 | timing->trp << FMC_SDTR_TRP_SHIFT
206 | timing->twr << FMC_SDTR_TWR_SHIFT
207 | timing->trc << FMC_SDTR_TRC_SHIFT
208 | timing->tras << FMC_SDTR_TRAS_SHIFT
209 | timing->txsr << FMC_SDTR_TXSR_SHIFT
210 | timing->tmrd << FMC_SDTR_TMRD_SHIFT,
211 &regs->sdtr1);
Vikas Manochabf1ae442017-04-10 15:02:51 -0700212
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200213 if (target_bank == SDRAM_BANK2)
214 writel(timing->trcd << FMC_SDTR_TRCD_SHIFT
215 | timing->trp << FMC_SDTR_TRP_SHIFT
216 | timing->twr << FMC_SDTR_TWR_SHIFT
217 | timing->trc << FMC_SDTR_TRC_SHIFT
218 | timing->tras << FMC_SDTR_TRAS_SHIFT
219 | timing->txsr << FMC_SDTR_TXSR_SHIFT
220 | timing->tmrd << FMC_SDTR_TMRD_SHIFT,
221 &regs->sdtr2);
Patrice Chotard70166512017-07-18 17:37:29 +0200222
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200223 if (target_bank == SDRAM_BANK1)
224 ctb = FMC_SDCMR_BANK_1;
225 else
226 ctb = FMC_SDCMR_BANK_2;
Vikas Manochabf1ae442017-04-10 15:02:51 -0700227
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200228 writel(ctb | FMC_SDCMR_MODE_START_CLOCK, &regs->sdcmr);
229 udelay(200); /* 200 us delay, page 10, "Power-Up" */
230 FMC_BUSY_WAIT(regs);
Vikas Manochabf1ae442017-04-10 15:02:51 -0700231
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200232 writel(ctb | FMC_SDCMR_MODE_PRECHARGE, &regs->sdcmr);
233 udelay(100);
234 FMC_BUSY_WAIT(regs);
Vikas Manochabf1ae442017-04-10 15:02:51 -0700235
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200236 writel((ctb | FMC_SDCMR_MODE_AUTOREFRESH | 7 << FMC_SDCMR_NRFS_SHIFT),
237 &regs->sdcmr);
238 udelay(100);
239 FMC_BUSY_WAIT(regs);
240
241 writel(ctb | (SDRAM_MODE_BL << SDRAM_MODE_BL_SHIFT
242 | control->cas_latency << SDRAM_MODE_CAS_SHIFT)
243 << FMC_SDCMR_MODE_REGISTER_SHIFT | FMC_SDCMR_MODE_WRITE_MODE,
244 &regs->sdcmr);
245 udelay(100);
246 FMC_BUSY_WAIT(regs);
247
248 writel(ctb | FMC_SDCMR_MODE_NORMAL, &regs->sdcmr);
249 FMC_BUSY_WAIT(regs);
250
251 /* Refresh timer */
252 writel(ref_count << 1, &regs->sdrtr);
253 }
Vikas Manochabf1ae442017-04-10 15:02:51 -0700254
Patrice Chotard70166512017-07-18 17:37:29 +0200255 /* enable the FMC controller */
256 if (params->family == STM32H7_FMC)
257 setbits_le32(&regs->bcr1, FMC_BCR1_FMCEN);
258
Vikas Manochabf1ae442017-04-10 15:02:51 -0700259 return 0;
260}
Vikas Manocha910a52e2017-04-10 15:02:52 -0700261
Simon Glassd1998a92020-12-03 16:55:21 -0700262static int stm32_fmc_of_to_plat(struct udevice *dev)
Vikas Manocha6c9a1002017-04-10 15:02:56 -0700263{
Simon Glassc69cda22020-12-03 16:55:20 -0700264 struct stm32_sdram_params *params = dev_get_plat(dev);
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200265 struct bank_params *bank_params;
Patrice Chotard0b3f7892017-12-12 09:49:41 +0100266 struct ofnode_phandle_args args;
267 u32 *syscfg_base;
268 u32 mem_remap;
Radoslaw Pietrzyk246a5e52018-05-16 17:27:11 +0200269 u32 swp_fmc;
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200270 ofnode bank_node;
271 char *bank_name;
dillon min1f0305e2021-04-09 15:28:45 +0800272 char _bank_name[128] = {0};
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200273 u8 bank = 0;
Patrice Chotard0b3f7892017-12-12 09:49:41 +0100274 int ret;
275
Radoslaw Pietrzyk246a5e52018-05-16 17:27:11 +0200276 ret = dev_read_phandle_with_args(dev, "st,syscfg", NULL, 0, 0,
Patrice Chotard0b3f7892017-12-12 09:49:41 +0100277 &args);
Radoslaw Pietrzyk246a5e52018-05-16 17:27:11 +0200278 if (ret) {
Patrick Delaunay997f7da2020-11-06 19:01:35 +0100279 dev_dbg(dev, "can't find syscon device (%d)\n", ret);
Radoslaw Pietrzyk246a5e52018-05-16 17:27:11 +0200280 } else {
Patrice Chotard0b3f7892017-12-12 09:49:41 +0100281 syscfg_base = (u32 *)ofnode_get_addr(args.node);
282
Radoslaw Pietrzyk246a5e52018-05-16 17:27:11 +0200283 mem_remap = dev_read_u32_default(dev, "st,mem_remap", NOT_FOUND);
284 if (mem_remap != NOT_FOUND) {
285 /* set memory mapping selection */
286 clrsetbits_le32(syscfg_base, MEM_MODE_MASK, mem_remap);
287 } else {
Patrick Delaunay997f7da2020-11-06 19:01:35 +0100288 dev_dbg(dev, "cannot find st,mem_remap property\n");
Radoslaw Pietrzyk246a5e52018-05-16 17:27:11 +0200289 }
Wolfgang Denk0a50b3c2021-09-27 17:42:38 +0200290
Radoslaw Pietrzyk246a5e52018-05-16 17:27:11 +0200291 swp_fmc = dev_read_u32_default(dev, "st,swp_fmc", NOT_FOUND);
292 if (swp_fmc != NOT_FOUND) {
293 /* set fmc swapping selection */
294 clrsetbits_le32(syscfg_base, SWP_FMC_MASK, swp_fmc << SWP_FMC_OFFSET);
295 } else {
Patrick Delaunay997f7da2020-11-06 19:01:35 +0100296 dev_dbg(dev, "cannot find st,swp_fmc property\n");
Radoslaw Pietrzyk246a5e52018-05-16 17:27:11 +0200297 }
298
299 dev_dbg(dev, "syscfg %x = %x\n", (u32)syscfg_base, *syscfg_base);
Patrice Chotard0b3f7892017-12-12 09:49:41 +0100300 }
Vikas Manocha6c9a1002017-04-10 15:02:56 -0700301
Patrice Chotardf39b90d2017-07-18 17:37:26 +0200302 dev_for_each_subnode(bank_node, dev) {
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200303 /* extract the bank index from DT */
304 bank_name = (char *)ofnode_get_name(bank_node);
dillon min1f0305e2021-04-09 15:28:45 +0800305 strlcpy(_bank_name, bank_name, sizeof(_bank_name));
306 bank_name = (char *)_bank_name;
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200307 strsep(&bank_name, "@");
308 if (!bank_name) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900309 pr_err("missing sdram bank index");
Patrice Chotardf39b90d2017-07-18 17:37:26 +0200310 return -EINVAL;
311 }
312
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200313 bank_params = &params->bank_params[bank];
314 strict_strtoul(bank_name, 10,
315 (long unsigned int *)&bank_params->target_bank);
Patrice Chotardf39b90d2017-07-18 17:37:26 +0200316
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200317 if (bank_params->target_bank >= MAX_SDRAM_BANK) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900318 pr_err("Found bank %d , but only bank 0 and 1 are supported",
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200319 bank_params->target_bank);
Patrice Chotardf39b90d2017-07-18 17:37:26 +0200320 return -EINVAL;
321 }
322
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200323 debug("Find bank %s %u\n", bank_name, bank_params->target_bank);
324
325 params->bank_params[bank].sdram_control =
326 (struct stm32_sdram_control *)
327 ofnode_read_u8_array_ptr(bank_node,
328 "st,sdram-control",
329 sizeof(struct stm32_sdram_control));
330
331 if (!params->bank_params[bank].sdram_control) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900332 pr_err("st,sdram-control not found for %s",
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200333 ofnode_get_name(bank_node));
334 return -EINVAL;
335 }
336
337
338 params->bank_params[bank].sdram_timing =
339 (struct stm32_sdram_timing *)
340 ofnode_read_u8_array_ptr(bank_node,
341 "st,sdram-timing",
342 sizeof(struct stm32_sdram_timing));
343
344 if (!params->bank_params[bank].sdram_timing) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900345 pr_err("st,sdram-timing not found for %s",
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200346 ofnode_get_name(bank_node));
347 return -EINVAL;
348 }
349
350
351 bank_params->sdram_ref_count = ofnode_read_u32_default(bank_node,
Vikas Manochabfea69a2017-04-10 15:03:03 -0700352 "st,sdram-refcount", 8196);
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200353 bank++;
Vikas Manocha6c9a1002017-04-10 15:02:56 -0700354 }
355
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200356 params->no_sdram_banks = bank;
Patrick Delaunay997f7da2020-11-06 19:01:35 +0100357 dev_dbg(dev, "no of banks = %d\n", params->no_sdram_banks);
Patrice Chotardf303aaf2017-07-18 17:37:27 +0200358
Vikas Manocha6c9a1002017-04-10 15:02:56 -0700359 return 0;
360}
361
Vikas Manocha910a52e2017-04-10 15:02:52 -0700362static int stm32_fmc_probe(struct udevice *dev)
363{
Simon Glassc69cda22020-12-03 16:55:20 -0700364 struct stm32_sdram_params *params = dev_get_plat(dev);
Vikas Manochad0b24c12017-04-10 15:02:55 -0700365 int ret;
Patrice Chotard1421e0a2017-07-18 17:37:25 +0200366 fdt_addr_t addr;
367
368 addr = dev_read_addr(dev);
369 if (addr == FDT_ADDR_T_NONE)
370 return -EINVAL;
371
372 params->base = (struct stm32_fmc_regs *)addr;
Patrice Chotard70166512017-07-18 17:37:29 +0200373 params->family = dev_get_driver_data(dev);
Patrice Chotard1421e0a2017-07-18 17:37:25 +0200374
Patrice Chotard14a50e32017-05-30 15:06:31 +0200375#ifdef CONFIG_CLK
Vikas Manochad0b24c12017-04-10 15:02:55 -0700376 struct clk clk;
Vikas Manocha6c9a1002017-04-10 15:02:56 -0700377
Vikas Manochad0b24c12017-04-10 15:02:55 -0700378 ret = clk_get_by_index(dev, 0, &clk);
379 if (ret < 0)
380 return ret;
381
382 ret = clk_enable(&clk);
383
384 if (ret) {
385 dev_err(dev, "failed to enable clock\n");
386 return ret;
387 }
388#endif
Vikas Manocha6c9a1002017-04-10 15:02:56 -0700389 ret = stm32_sdram_init(dev);
390 if (ret)
391 return ret;
392
Vikas Manocha910a52e2017-04-10 15:02:52 -0700393 return 0;
394}
395
396static int stm32_fmc_get_info(struct udevice *dev, struct ram_info *info)
397{
Vikas Manocha910a52e2017-04-10 15:02:52 -0700398 return 0;
399}
400
401static struct ram_ops stm32_fmc_ops = {
402 .get_info = stm32_fmc_get_info,
403};
404
405static const struct udevice_id stm32_fmc_ids[] = {
Patrice Chotard70166512017-07-18 17:37:29 +0200406 { .compatible = "st,stm32-fmc", .data = STM32F7_FMC },
407 { .compatible = "st,stm32h7-fmc", .data = STM32H7_FMC },
Vikas Manocha910a52e2017-04-10 15:02:52 -0700408 { }
409};
410
411U_BOOT_DRIVER(stm32_fmc) = {
412 .name = "stm32_fmc",
413 .id = UCLASS_RAM,
414 .of_match = stm32_fmc_ids,
415 .ops = &stm32_fmc_ops,
Simon Glassd1998a92020-12-03 16:55:21 -0700416 .of_to_plat = stm32_fmc_of_to_plat,
Vikas Manocha910a52e2017-04-10 15:02:52 -0700417 .probe = stm32_fmc_probe,
Simon Glasscaa4daa2020-12-03 16:55:18 -0700418 .plat_auto = sizeof(struct stm32_sdram_params),
Vikas Manocha910a52e2017-04-10 15:02:52 -0700419};