blob: 540ad8513872b95a32d74aa23496ca75a53c2ad1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vikas Manocha24796092017-04-10 15:02:51 -07002/*
Patrice Chotard789ee0e2017-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 Manocha24796092017-04-10 15:02:51 -07005 */
6
Patrick Delaunaya9b40a12020-11-06 19:01:35 +01007#define LOG_CATEGORY UCLASS_RAM
8
Vikas Manocha24796092017-04-10 15:02:51 -07009#include <common.h>
Vikas Manochaf9c6e6a2017-04-10 15:02:55 -070010#include <clk.h>
Vikas Manochaaa88e1a2017-04-10 15:02:52 -070011#include <dm.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Vikas Manochaaa88e1a2017-04-10 15:02:52 -070014#include <ram.h>
Vikas Manocha24796092017-04-10 15:02:51 -070015#include <asm/io.h>
Simon Glass9bc15642020-02-03 07:36:16 -070016#include <dm/device_compat.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060017#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060018#include <linux/delay.h>
Vikas Manocha24796092017-04-10 15:02:51 -070019
Patrice Chotard63e97282017-12-12 09:49:41 +010020#define MEM_MODE_MASK GENMASK(2, 0)
Radoslaw Pietrzyka88d3142018-05-16 17:27:11 +020021#define SWP_FMC_OFFSET 10
22#define SWP_FMC_MASK GENMASK(SWP_FMC_OFFSET+1, SWP_FMC_OFFSET)
Patrice Chotard63e97282017-12-12 09:49:41 +010023#define NOT_FOUND 0xff
24
Patrice Chotard7e82a692017-07-18 17:37:24 +020025struct stm32_fmc_regs {
Patrice Chotardf2b80002017-07-18 17:37:25 +020026 /* 0x0 */
27 u32 bcr1; /* NOR/PSRAM Chip select control register 1 */
28 u32 btr1; /* SRAM/NOR-Flash Chip select timing register 1 */
29 u32 bcr2; /* NOR/PSRAM Chip select Control register 2 */
30 u32 btr2; /* SRAM/NOR-Flash Chip select timing register 2 */
31 u32 bcr3; /* NOR/PSRAMChip select Control register 3 */
32 u32 btr3; /* SRAM/NOR-Flash Chip select timing register 3 */
33 u32 bcr4; /* NOR/PSRAM Chip select Control register 4 */
34 u32 btr4; /* SRAM/NOR-Flash Chip select timing register 4 */
35 u32 reserved1[24];
36
37 /* 0x80 */
38 u32 pcr; /* NAND Flash control register */
39 u32 sr; /* FIFO status and interrupt register */
40 u32 pmem; /* Common memory space timing register */
41 u32 patt; /* Attribute memory space timing registers */
42 u32 reserved2[1];
43 u32 eccr; /* ECC result registers */
44 u32 reserved3[27];
Patrice Chotard7e82a692017-07-18 17:37:24 +020045
Patrice Chotardf2b80002017-07-18 17:37:25 +020046 /* 0x104 */
47 u32 bwtr1; /* SRAM/NOR-Flash write timing register 1 */
48 u32 reserved4[1];
49 u32 bwtr2; /* SRAM/NOR-Flash write timing register 2 */
50 u32 reserved5[1];
51 u32 bwtr3; /* SRAM/NOR-Flash write timing register 3 */
52 u32 reserved6[1];
53 u32 bwtr4; /* SRAM/NOR-Flash write timing register 4 */
54 u32 reserved7[8];
55
56 /* 0x140 */
57 u32 sdcr1; /* SDRAM Control register 1 */
58 u32 sdcr2; /* SDRAM Control register 2 */
59 u32 sdtr1; /* SDRAM Timing register 1 */
60 u32 sdtr2; /* SDRAM Timing register 2 */
61 u32 sdcmr; /* SDRAM Mode register */
62 u32 sdrtr; /* SDRAM Refresh timing register */
63 u32 sdsr; /* SDRAM Status register */
64};
Patrice Chotard7e82a692017-07-18 17:37:24 +020065
Patrice Chotard7c695ce2017-07-18 17:37:29 +020066/*
67 * NOR/PSRAM Control register BCR1
68 * FMC controller Enable, only availabe for H7
69 */
70#define FMC_BCR1_FMCEN BIT(31)
71
Patrice Chotard7e82a692017-07-18 17:37:24 +020072/* Control register SDCR */
73#define FMC_SDCR_RPIPE_SHIFT 13 /* RPIPE bit shift */
74#define FMC_SDCR_RBURST_SHIFT 12 /* RBURST bit shift */
75#define FMC_SDCR_SDCLK_SHIFT 10 /* SDRAM clock divisor shift */
76#define FMC_SDCR_WP_SHIFT 9 /* Write protection shift */
77#define FMC_SDCR_CAS_SHIFT 7 /* CAS latency shift */
78#define FMC_SDCR_NB_SHIFT 6 /* Number of banks shift */
79#define FMC_SDCR_MWID_SHIFT 4 /* Memory width shift */
80#define FMC_SDCR_NR_SHIFT 2 /* Number of row address bits shift */
81#define FMC_SDCR_NC_SHIFT 0 /* Number of col address bits shift */
82
83/* Timings register SDTR */
84#define FMC_SDTR_TMRD_SHIFT 0 /* Load mode register to active */
85#define FMC_SDTR_TXSR_SHIFT 4 /* Exit self-refresh time */
86#define FMC_SDTR_TRAS_SHIFT 8 /* Self-refresh time */
87#define FMC_SDTR_TRC_SHIFT 12 /* Row cycle delay */
88#define FMC_SDTR_TWR_SHIFT 16 /* Recovery delay */
89#define FMC_SDTR_TRP_SHIFT 20 /* Row precharge delay */
90#define FMC_SDTR_TRCD_SHIFT 24 /* Row-to-column delay */
91
92#define FMC_SDCMR_NRFS_SHIFT 5
93
94#define FMC_SDCMR_MODE_NORMAL 0
95#define FMC_SDCMR_MODE_START_CLOCK 1
96#define FMC_SDCMR_MODE_PRECHARGE 2
97#define FMC_SDCMR_MODE_AUTOREFRESH 3
98#define FMC_SDCMR_MODE_WRITE_MODE 4
99#define FMC_SDCMR_MODE_SELFREFRESH 5
100#define FMC_SDCMR_MODE_POWERDOWN 6
101
102#define FMC_SDCMR_BANK_1 BIT(4)
103#define FMC_SDCMR_BANK_2 BIT(3)
104
105#define FMC_SDCMR_MODE_REGISTER_SHIFT 9
106
107#define FMC_SDSR_BUSY BIT(5)
108
Patrice Chotardf2b80002017-07-18 17:37:25 +0200109#define FMC_BUSY_WAIT(regs) do { \
Patrice Chotard7e82a692017-07-18 17:37:24 +0200110 __asm__ __volatile__ ("dsb" : : : "memory"); \
Patrice Chotardf2b80002017-07-18 17:37:25 +0200111 while (regs->sdsr & FMC_SDSR_BUSY) \
Patrice Chotard7e82a692017-07-18 17:37:24 +0200112 ; \
113 } while (0)
114
Vikas Manocha4515ffe2017-04-10 15:02:56 -0700115struct stm32_sdram_control {
116 u8 no_columns;
117 u8 no_rows;
118 u8 memory_width;
119 u8 no_banks;
120 u8 cas_latency;
Vikas Manocha1c6459d2017-04-10 15:03:03 -0700121 u8 sdclk;
Vikas Manocha4515ffe2017-04-10 15:02:56 -0700122 u8 rd_burst;
123 u8 rd_pipe_delay;
124};
125
126struct stm32_sdram_timing {
127 u8 tmrd;
128 u8 txsr;
129 u8 tras;
130 u8 trc;
131 u8 trp;
Vikas Manocha1c6459d2017-04-10 15:03:03 -0700132 u8 twr;
Vikas Manocha4515ffe2017-04-10 15:02:56 -0700133 u8 trcd;
134};
Patrice Chotard7fb96032017-07-18 17:37:27 +0200135enum stm32_fmc_bank {
136 SDRAM_BANK1,
137 SDRAM_BANK2,
138 MAX_SDRAM_BANK,
139};
140
Patrice Chotard7c695ce2017-07-18 17:37:29 +0200141enum stm32_fmc_family {
142 STM32F7_FMC,
143 STM32H7_FMC,
144};
145
Patrice Chotard7fb96032017-07-18 17:37:27 +0200146struct bank_params {
Patrice Chotard8b379222017-07-18 17:37:26 +0200147 struct stm32_sdram_control *sdram_control;
148 struct stm32_sdram_timing *sdram_timing;
Vikas Manocha1c6459d2017-04-10 15:03:03 -0700149 u32 sdram_ref_count;
Patrice Chotard7fb96032017-07-18 17:37:27 +0200150 enum stm32_fmc_bank target_bank;
Vikas Manocha4515ffe2017-04-10 15:02:56 -0700151};
Vikas Manocha24796092017-04-10 15:02:51 -0700152
Patrice Chotard7fb96032017-07-18 17:37:27 +0200153struct stm32_sdram_params {
154 struct stm32_fmc_regs *base;
155 u8 no_sdram_banks;
156 struct bank_params bank_params[MAX_SDRAM_BANK];
Patrice Chotard7c695ce2017-07-18 17:37:29 +0200157 enum stm32_fmc_family family;
Patrice Chotard7fb96032017-07-18 17:37:27 +0200158};
159
Vikas Manocha24796092017-04-10 15:02:51 -0700160#define SDRAM_MODE_BL_SHIFT 0
161#define SDRAM_MODE_CAS_SHIFT 4
162#define SDRAM_MODE_BL 0
Vikas Manocha4515ffe2017-04-10 15:02:56 -0700163
164int stm32_sdram_init(struct udevice *dev)
Vikas Manocha24796092017-04-10 15:02:51 -0700165{
Simon Glassfa20e932020-12-03 16:55:20 -0700166 struct stm32_sdram_params *params = dev_get_plat(dev);
Patrice Chotard7fb96032017-07-18 17:37:27 +0200167 struct stm32_sdram_control *control;
168 struct stm32_sdram_timing *timing;
Patrice Chotardf2b80002017-07-18 17:37:25 +0200169 struct stm32_fmc_regs *regs = params->base;
Patrice Chotard7fb96032017-07-18 17:37:27 +0200170 enum stm32_fmc_bank target_bank;
171 u32 ctb; /* SDCMR register: Command Target Bank */
172 u32 ref_count;
173 u8 i;
Vikas Manocha24796092017-04-10 15:02:51 -0700174
Patrice Chotard7c695ce2017-07-18 17:37:29 +0200175 /* disable the FMC controller */
176 if (params->family == STM32H7_FMC)
177 clrbits_le32(&regs->bcr1, FMC_BCR1_FMCEN);
178
Patrice Chotard7fb96032017-07-18 17:37:27 +0200179 for (i = 0; i < params->no_sdram_banks; i++) {
180 control = params->bank_params[i].sdram_control;
181 timing = params->bank_params[i].sdram_timing;
182 target_bank = params->bank_params[i].target_bank;
183 ref_count = params->bank_params[i].sdram_ref_count;
Vikas Manocha24796092017-04-10 15:02:51 -0700184
Patrice Chotard7fb96032017-07-18 17:37:27 +0200185 writel(control->sdclk << FMC_SDCR_SDCLK_SHIFT
186 | control->cas_latency << FMC_SDCR_CAS_SHIFT
187 | control->no_banks << FMC_SDCR_NB_SHIFT
188 | control->memory_width << FMC_SDCR_MWID_SHIFT
189 | control->no_rows << FMC_SDCR_NR_SHIFT
190 | control->no_columns << FMC_SDCR_NC_SHIFT
191 | control->rd_pipe_delay << FMC_SDCR_RPIPE_SHIFT
192 | control->rd_burst << FMC_SDCR_RBURST_SHIFT,
193 &regs->sdcr1);
Vikas Manocha24796092017-04-10 15:02:51 -0700194
Patrice Chotard7fb96032017-07-18 17:37:27 +0200195 if (target_bank == SDRAM_BANK2)
196 writel(control->cas_latency << FMC_SDCR_CAS_SHIFT
197 | control->no_banks << FMC_SDCR_NB_SHIFT
198 | control->memory_width << FMC_SDCR_MWID_SHIFT
199 | control->no_rows << FMC_SDCR_NR_SHIFT
200 | control->no_columns << FMC_SDCR_NC_SHIFT,
201 &regs->sdcr2);
Vikas Manocha24796092017-04-10 15:02:51 -0700202
Patrice Chotard7fb96032017-07-18 17:37:27 +0200203 writel(timing->trcd << FMC_SDTR_TRCD_SHIFT
204 | timing->trp << FMC_SDTR_TRP_SHIFT
205 | timing->twr << FMC_SDTR_TWR_SHIFT
206 | timing->trc << FMC_SDTR_TRC_SHIFT
207 | timing->tras << FMC_SDTR_TRAS_SHIFT
208 | timing->txsr << FMC_SDTR_TXSR_SHIFT
209 | timing->tmrd << FMC_SDTR_TMRD_SHIFT,
210 &regs->sdtr1);
Vikas Manocha24796092017-04-10 15:02:51 -0700211
Patrice Chotard7fb96032017-07-18 17:37:27 +0200212 if (target_bank == SDRAM_BANK2)
213 writel(timing->trcd << FMC_SDTR_TRCD_SHIFT
214 | timing->trp << FMC_SDTR_TRP_SHIFT
215 | timing->twr << FMC_SDTR_TWR_SHIFT
216 | timing->trc << FMC_SDTR_TRC_SHIFT
217 | timing->tras << FMC_SDTR_TRAS_SHIFT
218 | timing->txsr << FMC_SDTR_TXSR_SHIFT
219 | timing->tmrd << FMC_SDTR_TMRD_SHIFT,
220 &regs->sdtr2);
Patrice Chotard7c695ce2017-07-18 17:37:29 +0200221
Patrice Chotard7fb96032017-07-18 17:37:27 +0200222 if (target_bank == SDRAM_BANK1)
223 ctb = FMC_SDCMR_BANK_1;
224 else
225 ctb = FMC_SDCMR_BANK_2;
Vikas Manocha24796092017-04-10 15:02:51 -0700226
Patrice Chotard7fb96032017-07-18 17:37:27 +0200227 writel(ctb | FMC_SDCMR_MODE_START_CLOCK, &regs->sdcmr);
228 udelay(200); /* 200 us delay, page 10, "Power-Up" */
229 FMC_BUSY_WAIT(regs);
Vikas Manocha24796092017-04-10 15:02:51 -0700230
Patrice Chotard7fb96032017-07-18 17:37:27 +0200231 writel(ctb | FMC_SDCMR_MODE_PRECHARGE, &regs->sdcmr);
232 udelay(100);
233 FMC_BUSY_WAIT(regs);
Vikas Manocha24796092017-04-10 15:02:51 -0700234
Patrice Chotard7fb96032017-07-18 17:37:27 +0200235 writel((ctb | FMC_SDCMR_MODE_AUTOREFRESH | 7 << FMC_SDCMR_NRFS_SHIFT),
236 &regs->sdcmr);
237 udelay(100);
238 FMC_BUSY_WAIT(regs);
239
240 writel(ctb | (SDRAM_MODE_BL << SDRAM_MODE_BL_SHIFT
241 | control->cas_latency << SDRAM_MODE_CAS_SHIFT)
242 << FMC_SDCMR_MODE_REGISTER_SHIFT | FMC_SDCMR_MODE_WRITE_MODE,
243 &regs->sdcmr);
244 udelay(100);
245 FMC_BUSY_WAIT(regs);
246
247 writel(ctb | FMC_SDCMR_MODE_NORMAL, &regs->sdcmr);
248 FMC_BUSY_WAIT(regs);
249
250 /* Refresh timer */
251 writel(ref_count << 1, &regs->sdrtr);
252 }
Vikas Manocha24796092017-04-10 15:02:51 -0700253
Patrice Chotard7c695ce2017-07-18 17:37:29 +0200254 /* enable the FMC controller */
255 if (params->family == STM32H7_FMC)
256 setbits_le32(&regs->bcr1, FMC_BCR1_FMCEN);
257
Vikas Manocha24796092017-04-10 15:02:51 -0700258 return 0;
259}
Vikas Manochaaa88e1a2017-04-10 15:02:52 -0700260
Simon Glassaad29ae2020-12-03 16:55:21 -0700261static int stm32_fmc_of_to_plat(struct udevice *dev)
Vikas Manocha4515ffe2017-04-10 15:02:56 -0700262{
Simon Glassfa20e932020-12-03 16:55:20 -0700263 struct stm32_sdram_params *params = dev_get_plat(dev);
Patrice Chotard7fb96032017-07-18 17:37:27 +0200264 struct bank_params *bank_params;
Patrice Chotard63e97282017-12-12 09:49:41 +0100265 struct ofnode_phandle_args args;
266 u32 *syscfg_base;
267 u32 mem_remap;
Radoslaw Pietrzyka88d3142018-05-16 17:27:11 +0200268 u32 swp_fmc;
Patrice Chotard7fb96032017-07-18 17:37:27 +0200269 ofnode bank_node;
270 char *bank_name;
271 u8 bank = 0;
Patrice Chotard63e97282017-12-12 09:49:41 +0100272 int ret;
273
Radoslaw Pietrzyka88d3142018-05-16 17:27:11 +0200274 ret = dev_read_phandle_with_args(dev, "st,syscfg", NULL, 0, 0,
Patrice Chotard63e97282017-12-12 09:49:41 +0100275 &args);
Radoslaw Pietrzyka88d3142018-05-16 17:27:11 +0200276 if (ret) {
Patrick Delaunaya9b40a12020-11-06 19:01:35 +0100277 dev_dbg(dev, "can't find syscon device (%d)\n", ret);
Radoslaw Pietrzyka88d3142018-05-16 17:27:11 +0200278 } else {
Patrice Chotard63e97282017-12-12 09:49:41 +0100279 syscfg_base = (u32 *)ofnode_get_addr(args.node);
280
Radoslaw Pietrzyka88d3142018-05-16 17:27:11 +0200281 mem_remap = dev_read_u32_default(dev, "st,mem_remap", NOT_FOUND);
282 if (mem_remap != NOT_FOUND) {
283 /* set memory mapping selection */
284 clrsetbits_le32(syscfg_base, MEM_MODE_MASK, mem_remap);
285 } else {
Patrick Delaunaya9b40a12020-11-06 19:01:35 +0100286 dev_dbg(dev, "cannot find st,mem_remap property\n");
Radoslaw Pietrzyka88d3142018-05-16 17:27:11 +0200287 }
288
289 swp_fmc = dev_read_u32_default(dev, "st,swp_fmc", NOT_FOUND);
290 if (swp_fmc != NOT_FOUND) {
291 /* set fmc swapping selection */
292 clrsetbits_le32(syscfg_base, SWP_FMC_MASK, swp_fmc << SWP_FMC_OFFSET);
293 } else {
Patrick Delaunaya9b40a12020-11-06 19:01:35 +0100294 dev_dbg(dev, "cannot find st,swp_fmc property\n");
Radoslaw Pietrzyka88d3142018-05-16 17:27:11 +0200295 }
296
297 dev_dbg(dev, "syscfg %x = %x\n", (u32)syscfg_base, *syscfg_base);
Patrice Chotard63e97282017-12-12 09:49:41 +0100298 }
Vikas Manocha4515ffe2017-04-10 15:02:56 -0700299
Patrice Chotard8b379222017-07-18 17:37:26 +0200300 dev_for_each_subnode(bank_node, dev) {
Patrice Chotard7fb96032017-07-18 17:37:27 +0200301 /* extract the bank index from DT */
302 bank_name = (char *)ofnode_get_name(bank_node);
303 strsep(&bank_name, "@");
304 if (!bank_name) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900305 pr_err("missing sdram bank index");
Patrice Chotard7fb96032017-07-18 17:37:27 +0200306 return -EINVAL;
307 }
308
309 bank_params = &params->bank_params[bank];
310 strict_strtoul(bank_name, 10,
311 (long unsigned int *)&bank_params->target_bank);
Patrice Chotard8b379222017-07-18 17:37:26 +0200312
Patrice Chotard7fb96032017-07-18 17:37:27 +0200313 if (bank_params->target_bank >= MAX_SDRAM_BANK) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900314 pr_err("Found bank %d , but only bank 0 and 1 are supported",
Patrice Chotard7fb96032017-07-18 17:37:27 +0200315 bank_params->target_bank);
Patrice Chotard8b379222017-07-18 17:37:26 +0200316 return -EINVAL;
317 }
318
Patrice Chotard7fb96032017-07-18 17:37:27 +0200319 debug("Find bank %s %u\n", bank_name, bank_params->target_bank);
Patrice Chotard8b379222017-07-18 17:37:26 +0200320
Patrice Chotard7fb96032017-07-18 17:37:27 +0200321 params->bank_params[bank].sdram_control =
322 (struct stm32_sdram_control *)
323 ofnode_read_u8_array_ptr(bank_node,
324 "st,sdram-control",
325 sizeof(struct stm32_sdram_control));
326
327 if (!params->bank_params[bank].sdram_control) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900328 pr_err("st,sdram-control not found for %s",
Patrice Chotard7fb96032017-07-18 17:37:27 +0200329 ofnode_get_name(bank_node));
Patrice Chotard8b379222017-07-18 17:37:26 +0200330 return -EINVAL;
331 }
Vikas Manocha1c6459d2017-04-10 15:03:03 -0700332
Patrice Chotard7fb96032017-07-18 17:37:27 +0200333
334 params->bank_params[bank].sdram_timing =
335 (struct stm32_sdram_timing *)
336 ofnode_read_u8_array_ptr(bank_node,
337 "st,sdram-timing",
338 sizeof(struct stm32_sdram_timing));
339
340 if (!params->bank_params[bank].sdram_timing) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900341 pr_err("st,sdram-timing not found for %s",
Patrice Chotard7fb96032017-07-18 17:37:27 +0200342 ofnode_get_name(bank_node));
343 return -EINVAL;
344 }
345
346
347 bank_params->sdram_ref_count = ofnode_read_u32_default(bank_node,
Vikas Manocha1c6459d2017-04-10 15:03:03 -0700348 "st,sdram-refcount", 8196);
Patrice Chotard7fb96032017-07-18 17:37:27 +0200349 bank++;
Vikas Manocha4515ffe2017-04-10 15:02:56 -0700350 }
351
Patrice Chotard7fb96032017-07-18 17:37:27 +0200352 params->no_sdram_banks = bank;
Patrick Delaunaya9b40a12020-11-06 19:01:35 +0100353 dev_dbg(dev, "no of banks = %d\n", params->no_sdram_banks);
Patrice Chotard7fb96032017-07-18 17:37:27 +0200354
Vikas Manocha4515ffe2017-04-10 15:02:56 -0700355 return 0;
356}
357
Vikas Manochaaa88e1a2017-04-10 15:02:52 -0700358static int stm32_fmc_probe(struct udevice *dev)
359{
Simon Glassfa20e932020-12-03 16:55:20 -0700360 struct stm32_sdram_params *params = dev_get_plat(dev);
Vikas Manochaf9c6e6a2017-04-10 15:02:55 -0700361 int ret;
Patrice Chotardf2b80002017-07-18 17:37:25 +0200362 fdt_addr_t addr;
363
364 addr = dev_read_addr(dev);
365 if (addr == FDT_ADDR_T_NONE)
366 return -EINVAL;
367
368 params->base = (struct stm32_fmc_regs *)addr;
Patrice Chotard7c695ce2017-07-18 17:37:29 +0200369 params->family = dev_get_driver_data(dev);
Patrice Chotardf2b80002017-07-18 17:37:25 +0200370
Patrice Chotard4fafb722017-05-30 15:06:31 +0200371#ifdef CONFIG_CLK
Vikas Manochaf9c6e6a2017-04-10 15:02:55 -0700372 struct clk clk;
Vikas Manocha4515ffe2017-04-10 15:02:56 -0700373
Vikas Manochaf9c6e6a2017-04-10 15:02:55 -0700374 ret = clk_get_by_index(dev, 0, &clk);
375 if (ret < 0)
376 return ret;
377
378 ret = clk_enable(&clk);
379
380 if (ret) {
381 dev_err(dev, "failed to enable clock\n");
382 return ret;
383 }
384#endif
Vikas Manocha4515ffe2017-04-10 15:02:56 -0700385 ret = stm32_sdram_init(dev);
386 if (ret)
387 return ret;
388
Vikas Manochaaa88e1a2017-04-10 15:02:52 -0700389 return 0;
390}
391
392static int stm32_fmc_get_info(struct udevice *dev, struct ram_info *info)
393{
Vikas Manochaaa88e1a2017-04-10 15:02:52 -0700394 return 0;
395}
396
397static struct ram_ops stm32_fmc_ops = {
398 .get_info = stm32_fmc_get_info,
399};
400
401static const struct udevice_id stm32_fmc_ids[] = {
Patrice Chotard7c695ce2017-07-18 17:37:29 +0200402 { .compatible = "st,stm32-fmc", .data = STM32F7_FMC },
403 { .compatible = "st,stm32h7-fmc", .data = STM32H7_FMC },
Vikas Manochaaa88e1a2017-04-10 15:02:52 -0700404 { }
405};
406
407U_BOOT_DRIVER(stm32_fmc) = {
408 .name = "stm32_fmc",
409 .id = UCLASS_RAM,
410 .of_match = stm32_fmc_ids,
411 .ops = &stm32_fmc_ops,
Simon Glassaad29ae2020-12-03 16:55:21 -0700412 .of_to_plat = stm32_fmc_of_to_plat,
Vikas Manochaaa88e1a2017-04-10 15:02:52 -0700413 .probe = stm32_fmc_probe,
Simon Glass71fa5b42020-12-03 16:55:18 -0700414 .plat_auto = sizeof(struct stm32_sdram_params),
Vikas Manochaaa88e1a2017-04-10 15:02:52 -0700415};