2 * st_spi_fsm.c - ST Fast Sequence Mode (FSM) Serial Flash Controller
4 * Author: Angus Clark <angus.clark@st.com>
6 * Copyright (C) 2010-2014 STicroelectronics Limited
8 * JEDEC probe based on drivers/mtd/devices/m25p80.c
10 * This code is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/regmap.h>
18 #include <linux/platform_device.h>
19 #include <linux/mfd/syscon.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/sched.h>
22 #include <linux/delay.h>
26 #include "serial_flash_cmds.h"
29 * FSM SPI Controller Registers
31 #define SPI_CLOCKDIV 0x0010
32 #define SPI_MODESELECT 0x0018
33 #define SPI_CONFIGDATA 0x0020
34 #define SPI_STA_MODE_CHANGE 0x0028
35 #define SPI_FAST_SEQ_TRANSFER_SIZE 0x0100
36 #define SPI_FAST_SEQ_ADD1 0x0104
37 #define SPI_FAST_SEQ_ADD2 0x0108
38 #define SPI_FAST_SEQ_ADD_CFG 0x010c
39 #define SPI_FAST_SEQ_OPC1 0x0110
40 #define SPI_FAST_SEQ_OPC2 0x0114
41 #define SPI_FAST_SEQ_OPC3 0x0118
42 #define SPI_FAST_SEQ_OPC4 0x011c
43 #define SPI_FAST_SEQ_OPC5 0x0120
44 #define SPI_MODE_BITS 0x0124
45 #define SPI_DUMMY_BITS 0x0128
46 #define SPI_FAST_SEQ_FLASH_STA_DATA 0x012c
47 #define SPI_FAST_SEQ_1 0x0130
48 #define SPI_FAST_SEQ_2 0x0134
49 #define SPI_FAST_SEQ_3 0x0138
50 #define SPI_FAST_SEQ_4 0x013c
51 #define SPI_FAST_SEQ_CFG 0x0140
52 #define SPI_FAST_SEQ_STA 0x0144
53 #define SPI_QUAD_BOOT_SEQ_INIT_1 0x0148
54 #define SPI_QUAD_BOOT_SEQ_INIT_2 0x014c
55 #define SPI_QUAD_BOOT_READ_SEQ_1 0x0150
56 #define SPI_QUAD_BOOT_READ_SEQ_2 0x0154
57 #define SPI_PROGRAM_ERASE_TIME 0x0158
58 #define SPI_MULT_PAGE_REPEAT_SEQ_1 0x015c
59 #define SPI_MULT_PAGE_REPEAT_SEQ_2 0x0160
60 #define SPI_STATUS_WR_TIME_REG 0x0164
61 #define SPI_FAST_SEQ_DATA_REG 0x0300
64 * Register: SPI_MODESELECT
66 #define SPI_MODESELECT_CONTIG 0x01
67 #define SPI_MODESELECT_FASTREAD 0x02
68 #define SPI_MODESELECT_DUALIO 0x04
69 #define SPI_MODESELECT_FSM 0x08
70 #define SPI_MODESELECT_QUADBOOT 0x10
73 * Register: SPI_CONFIGDATA
75 #define SPI_CFG_DEVICE_ST 0x1
76 #define SPI_CFG_DEVICE_ATMEL 0x4
77 #define SPI_CFG_MIN_CS_HIGH(x) (((x) & 0xfff) << 4)
78 #define SPI_CFG_CS_SETUPHOLD(x) (((x) & 0xff) << 16)
79 #define SPI_CFG_DATA_HOLD(x) (((x) & 0xff) << 24)
81 #define SPI_CFG_DEFAULT_MIN_CS_HIGH SPI_CFG_MIN_CS_HIGH(0x0AA)
82 #define SPI_CFG_DEFAULT_CS_SETUPHOLD SPI_CFG_CS_SETUPHOLD(0xA0)
83 #define SPI_CFG_DEFAULT_DATA_HOLD SPI_CFG_DATA_HOLD(0x00)
86 * Register: SPI_FAST_SEQ_TRANSFER_SIZE
88 #define TRANSFER_SIZE(x) ((x) * 8)
91 * Register: SPI_FAST_SEQ_ADD_CFG
93 #define ADR_CFG_CYCLES_ADD1(x) ((x) << 0)
94 #define ADR_CFG_PADS_1_ADD1 (0x0 << 6)
95 #define ADR_CFG_PADS_2_ADD1 (0x1 << 6)
96 #define ADR_CFG_PADS_4_ADD1 (0x3 << 6)
97 #define ADR_CFG_CSDEASSERT_ADD1 (1 << 8)
98 #define ADR_CFG_CYCLES_ADD2(x) ((x) << (0+16))
99 #define ADR_CFG_PADS_1_ADD2 (0x0 << (6+16))
100 #define ADR_CFG_PADS_2_ADD2 (0x1 << (6+16))
101 #define ADR_CFG_PADS_4_ADD2 (0x3 << (6+16))
102 #define ADR_CFG_CSDEASSERT_ADD2 (1 << (8+16))
105 * Register: SPI_FAST_SEQ_n
107 #define SEQ_OPC_OPCODE(x) ((x) << 0)
108 #define SEQ_OPC_CYCLES(x) ((x) << 8)
109 #define SEQ_OPC_PADS_1 (0x0 << 14)
110 #define SEQ_OPC_PADS_2 (0x1 << 14)
111 #define SEQ_OPC_PADS_4 (0x3 << 14)
112 #define SEQ_OPC_CSDEASSERT (1 << 16)
115 * Register: SPI_FAST_SEQ_CFG
117 #define SEQ_CFG_STARTSEQ (1 << 0)
118 #define SEQ_CFG_SWRESET (1 << 5)
119 #define SEQ_CFG_CSDEASSERT (1 << 6)
120 #define SEQ_CFG_READNOTWRITE (1 << 7)
121 #define SEQ_CFG_ERASE (1 << 8)
122 #define SEQ_CFG_PADS_1 (0x0 << 16)
123 #define SEQ_CFG_PADS_2 (0x1 << 16)
124 #define SEQ_CFG_PADS_4 (0x3 << 16)
127 * Register: SPI_MODE_BITS
129 #define MODE_DATA(x) (x & 0xff)
130 #define MODE_CYCLES(x) ((x & 0x3f) << 16)
131 #define MODE_PADS_1 (0x0 << 22)
132 #define MODE_PADS_2 (0x1 << 22)
133 #define MODE_PADS_4 (0x3 << 22)
134 #define DUMMY_CSDEASSERT (1 << 24)
137 * Register: SPI_DUMMY_BITS
139 #define DUMMY_CYCLES(x) ((x & 0x3f) << 16)
140 #define DUMMY_PADS_1 (0x0 << 22)
141 #define DUMMY_PADS_2 (0x1 << 22)
142 #define DUMMY_PADS_4 (0x3 << 22)
143 #define DUMMY_CSDEASSERT (1 << 24)
146 * Register: SPI_FAST_SEQ_FLASH_STA_DATA
148 #define STA_DATA_BYTE1(x) ((x & 0xff) << 0)
149 #define STA_DATA_BYTE2(x) ((x & 0xff) << 8)
150 #define STA_PADS_1 (0x0 << 16)
151 #define STA_PADS_2 (0x1 << 16)
152 #define STA_PADS_4 (0x3 << 16)
153 #define STA_CSDEASSERT (0x1 << 20)
154 #define STA_RDNOTWR (0x1 << 21)
157 * FSM SPI Instruction Opcodes
159 #define STFSM_OPC_CMD 0x1
160 #define STFSM_OPC_ADD 0x2
161 #define STFSM_OPC_STA 0x3
162 #define STFSM_OPC_MODE 0x4
163 #define STFSM_OPC_DUMMY 0x5
164 #define STFSM_OPC_DATA 0x6
165 #define STFSM_OPC_WAIT 0x7
166 #define STFSM_OPC_JUMP 0x8
167 #define STFSM_OPC_GOTO 0x9
168 #define STFSM_OPC_STOP 0xF
171 * FSM SPI Instructions (== opcode + operand).
173 #define STFSM_INSTR(cmd, op) ((cmd) | ((op) << 4))
175 #define STFSM_INST_CMD1 STFSM_INSTR(STFSM_OPC_CMD, 1)
176 #define STFSM_INST_CMD2 STFSM_INSTR(STFSM_OPC_CMD, 2)
177 #define STFSM_INST_CMD3 STFSM_INSTR(STFSM_OPC_CMD, 3)
178 #define STFSM_INST_CMD4 STFSM_INSTR(STFSM_OPC_CMD, 4)
179 #define STFSM_INST_CMD5 STFSM_INSTR(STFSM_OPC_CMD, 5)
180 #define STFSM_INST_ADD1 STFSM_INSTR(STFSM_OPC_ADD, 1)
181 #define STFSM_INST_ADD2 STFSM_INSTR(STFSM_OPC_ADD, 2)
183 #define STFSM_INST_DATA_WRITE STFSM_INSTR(STFSM_OPC_DATA, 1)
184 #define STFSM_INST_DATA_READ STFSM_INSTR(STFSM_OPC_DATA, 2)
186 #define STFSM_INST_STA_RD1 STFSM_INSTR(STFSM_OPC_STA, 0x1)
187 #define STFSM_INST_STA_WR1 STFSM_INSTR(STFSM_OPC_STA, 0x1)
188 #define STFSM_INST_STA_RD2 STFSM_INSTR(STFSM_OPC_STA, 0x2)
189 #define STFSM_INST_STA_WR1_2 STFSM_INSTR(STFSM_OPC_STA, 0x3)
191 #define STFSM_INST_MODE STFSM_INSTR(STFSM_OPC_MODE, 0)
192 #define STFSM_INST_DUMMY STFSM_INSTR(STFSM_OPC_DUMMY, 0)
193 #define STFSM_INST_WAIT STFSM_INSTR(STFSM_OPC_WAIT, 0)
194 #define STFSM_INST_STOP STFSM_INSTR(STFSM_OPC_STOP, 0)
196 #define STFSM_DEFAULT_EMI_FREQ 100000000UL /* 100 MHz */
197 #define STFSM_DEFAULT_WR_TIME (STFSM_DEFAULT_EMI_FREQ * (15/1000)) /* 15ms */
199 #define STFSM_FLASH_SAFE_FREQ 10000000UL /* 10 MHz */
201 #define STFSM_MAX_WAIT_SEQ_MS 1000 /* FSM execution time */
204 #define FLASH_CMD_WREN 0x06
205 #define FLASH_CMD_WRDI 0x04
206 #define FLASH_CMD_RDID 0x9f
207 #define FLASH_CMD_RDSR 0x05
208 #define FLASH_CMD_RDSR2 0x35
209 #define FLASH_CMD_WRSR 0x01
210 #define FLASH_CMD_SE_4K 0x20
211 #define FLASH_CMD_SE_32K 0x52
212 #define FLASH_CMD_SE 0xd8
213 #define FLASH_CMD_CHIPERASE 0xc7
214 #define FLASH_CMD_WRVCR 0x81
215 #define FLASH_CMD_RDVCR 0x85
217 #define FLASH_CMD_READ 0x03 /* READ */
218 #define FLASH_CMD_READ_FAST 0x0b /* FAST READ */
219 #define FLASH_CMD_READ_1_1_2 0x3b /* DUAL OUTPUT READ */
220 #define FLASH_CMD_READ_1_2_2 0xbb /* DUAL I/O READ */
221 #define FLASH_CMD_READ_1_1_4 0x6b /* QUAD OUTPUT READ */
222 #define FLASH_CMD_READ_1_4_4 0xeb /* QUAD I/O READ */
224 #define FLASH_CMD_WRITE 0x02 /* PAGE PROGRAM */
225 #define FLASH_CMD_WRITE_1_1_2 0xa2 /* DUAL INPUT PROGRAM */
226 #define FLASH_CMD_WRITE_1_2_2 0xd2 /* DUAL INPUT EXT PROGRAM */
227 #define FLASH_CMD_WRITE_1_1_4 0x32 /* QUAD INPUT PROGRAM */
228 #define FLASH_CMD_WRITE_1_4_4 0x12 /* QUAD INPUT EXT PROGRAM */
230 #define FLASH_CMD_EN4B_ADDR 0xb7 /* Enter 4-byte address mode */
231 #define FLASH_CMD_EX4B_ADDR 0xe9 /* Exit 4-byte address mode */
233 /* READ commands with 32-bit addressing (N25Q256 and S25FLxxxS) */
234 #define FLASH_CMD_READ4 0x13
235 #define FLASH_CMD_READ4_FAST 0x0c
236 #define FLASH_CMD_READ4_1_1_2 0x3c
237 #define FLASH_CMD_READ4_1_2_2 0xbc
238 #define FLASH_CMD_READ4_1_1_4 0x6c
239 #define FLASH_CMD_READ4_1_4_4 0xec
241 /* S25FLxxxS commands */
242 #define S25FL_CMD_WRITE4_1_1_4 0x34
243 #define S25FL_CMD_SE4 0xdc
244 #define S25FL_CMD_CLSR 0x30
245 #define S25FL_CMD_DYBWR 0xe1
246 #define S25FL_CMD_DYBRD 0xe0
247 #define S25FL_CMD_WRITE4 0x12 /* Note, opcode clashes with
248 * 'FLASH_CMD_WRITE_1_4_4'
249 * as found on N25Qxxx devices! */
251 /* Status register */
252 #define FLASH_STATUS_BUSY 0x01
253 #define FLASH_STATUS_WEL 0x02
254 #define FLASH_STATUS_BP0 0x04
255 #define FLASH_STATUS_BP1 0x08
256 #define FLASH_STATUS_BP2 0x10
257 #define FLASH_STATUS_SRWP0 0x80
258 #define FLASH_STATUS_TIMEOUT 0xff
259 /* S25FL Error Flags */
260 #define S25FL_STATUS_E_ERR 0x20
261 #define S25FL_STATUS_P_ERR 0x40
263 #define FLASH_PAGESIZE 256 /* In Bytes */
264 #define FLASH_PAGESIZE_32 (FLASH_PAGESIZE / 4) /* In uint32_t */
265 #define FLASH_MAX_BUSY_WAIT (300 * HZ) /* Maximum 'CHIPERASE' time */
268 * Flags to tweak operation of default read/write/erase routines
270 #define CFG_READ_TOGGLE_32BIT_ADDR 0x00000001
271 #define CFG_WRITE_TOGGLE_32BIT_ADDR 0x00000002
272 #define CFG_WRITE_EX_32BIT_ADDR_DELAY 0x00000004
273 #define CFG_ERASESEC_TOGGLE_32BIT_ADDR 0x00000008
274 #define CFG_S25FL_CHECK_ERROR_FLAGS 0x00000010
279 struct resource *region;
282 struct flash_info *info;
284 uint32_t configuration;
285 uint32_t fifo_dir_delay;
286 bool booted_from_spi;
302 } __packed __aligned(4);
304 /* Parameters to configure a READ or WRITE FSM sequence */
305 struct seq_rw_config {
306 uint32_t flags; /* flags to support config */
307 uint8_t cmd; /* FLASH command */
308 int write; /* Write Sequence */
309 uint8_t addr_pads; /* No. of addr pads (MODE & DUMMY) */
310 uint8_t data_pads; /* No. of data pads */
311 uint8_t mode_data; /* MODE data */
312 uint8_t mode_cycles; /* No. of MODE cycles */
313 uint8_t dummy_cycles; /* No. of DUMMY cycles */
316 /* SPI Flash Device Table */
320 * JEDEC id zero means "no ID" (most older chips); otherwise it has
321 * a high byte of zero plus three data bytes: the manufacturer id,
322 * then a two byte device id.
327 * The size listed here is what works with FLASH_CMD_SE, which isn't
328 * necessarily called a "sector" by the vendor.
330 unsigned sector_size;
334 * Note, where FAST_READ is supported, freq_max specifies the
335 * FAST_READ frequency, not the READ frequency.
338 int (*config)(struct stfsm *);
341 static int stfsm_n25q_config(struct stfsm *fsm);
342 static int stfsm_mx25_config(struct stfsm *fsm);
343 static int stfsm_s25fl_config(struct stfsm *fsm);
345 static struct flash_info flash_types[] = {
347 * ST Microelectronics/Numonyx --
348 * (newer production versions may have feature updates
349 * (eg faster operating frequency)
351 #define M25P_FLAG (FLASH_FLAG_READ_WRITE | FLASH_FLAG_READ_FAST)
352 { "m25p40", 0x202013, 0, 64 * 1024, 8, M25P_FLAG, 25, NULL },
353 { "m25p80", 0x202014, 0, 64 * 1024, 16, M25P_FLAG, 25, NULL },
354 { "m25p16", 0x202015, 0, 64 * 1024, 32, M25P_FLAG, 25, NULL },
355 { "m25p32", 0x202016, 0, 64 * 1024, 64, M25P_FLAG, 50, NULL },
356 { "m25p64", 0x202017, 0, 64 * 1024, 128, M25P_FLAG, 50, NULL },
357 { "m25p128", 0x202018, 0, 256 * 1024, 64, M25P_FLAG, 50, NULL },
359 #define M25PX_FLAG (FLASH_FLAG_READ_WRITE | \
360 FLASH_FLAG_READ_FAST | \
361 FLASH_FLAG_READ_1_1_2 | \
362 FLASH_FLAG_WRITE_1_1_2)
363 { "m25px32", 0x207116, 0, 64 * 1024, 64, M25PX_FLAG, 75, NULL },
364 { "m25px64", 0x207117, 0, 64 * 1024, 128, M25PX_FLAG, 75, NULL },
366 #define MX25_FLAG (FLASH_FLAG_READ_WRITE | \
367 FLASH_FLAG_READ_FAST | \
368 FLASH_FLAG_READ_1_1_2 | \
369 FLASH_FLAG_READ_1_2_2 | \
370 FLASH_FLAG_READ_1_1_4 | \
371 FLASH_FLAG_READ_1_4_4 | \
374 { "mx25l25635e", 0xc22019, 0, 64*1024, 512,
375 (MX25_FLAG | FLASH_FLAG_32BIT_ADDR | FLASH_FLAG_RESET), 70,
378 #define N25Q_FLAG (FLASH_FLAG_READ_WRITE | \
379 FLASH_FLAG_READ_FAST | \
380 FLASH_FLAG_READ_1_1_2 | \
381 FLASH_FLAG_READ_1_2_2 | \
382 FLASH_FLAG_READ_1_1_4 | \
383 FLASH_FLAG_READ_1_4_4 | \
384 FLASH_FLAG_WRITE_1_1_2 | \
385 FLASH_FLAG_WRITE_1_2_2 | \
386 FLASH_FLAG_WRITE_1_1_4 | \
387 FLASH_FLAG_WRITE_1_4_4)
388 { "n25q128", 0x20ba18, 0, 64 * 1024, 256, N25Q_FLAG, 108,
390 { "n25q256", 0x20ba19, 0, 64 * 1024, 512,
391 N25Q_FLAG | FLASH_FLAG_32BIT_ADDR, 108, stfsm_n25q_config },
395 * - 256KiB and 64KiB sector variants (identified by ext. JEDEC)
397 #define S25FLXXXP_FLAG (FLASH_FLAG_READ_WRITE | \
398 FLASH_FLAG_READ_1_1_2 | \
399 FLASH_FLAG_READ_1_2_2 | \
400 FLASH_FLAG_READ_1_1_4 | \
401 FLASH_FLAG_READ_1_4_4 | \
402 FLASH_FLAG_WRITE_1_1_4 | \
403 FLASH_FLAG_READ_FAST)
404 { "s25fl129p0", 0x012018, 0x4d00, 256 * 1024, 64, S25FLXXXP_FLAG, 80,
405 stfsm_s25fl_config },
406 { "s25fl129p1", 0x012018, 0x4d01, 64 * 1024, 256, S25FLXXXP_FLAG, 80,
407 stfsm_s25fl_config },
411 * - 256KiB and 64KiB sector variants (identified by ext. JEDEC)
412 * - RESET# signal supported by die but not bristled out on all
413 * package types. The package type is a function of board design,
414 * so this information is captured in the board's flags.
415 * - Supports 'DYB' sector protection. Depending on variant, sectors
416 * may default to locked state on power-on.
418 #define S25FLXXXS_FLAG (S25FLXXXP_FLAG | \
420 FLASH_FLAG_DYB_LOCKING)
421 { "s25fl128s0", 0x012018, 0x0300, 256 * 1024, 64, S25FLXXXS_FLAG, 80,
422 stfsm_s25fl_config },
423 { "s25fl128s1", 0x012018, 0x0301, 64 * 1024, 256, S25FLXXXS_FLAG, 80,
424 stfsm_s25fl_config },
425 { "s25fl256s0", 0x010219, 0x4d00, 256 * 1024, 128,
426 S25FLXXXS_FLAG | FLASH_FLAG_32BIT_ADDR, 80, stfsm_s25fl_config },
427 { "s25fl256s1", 0x010219, 0x4d01, 64 * 1024, 512,
428 S25FLXXXS_FLAG | FLASH_FLAG_32BIT_ADDR, 80, stfsm_s25fl_config },
430 /* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */
431 #define W25X_FLAG (FLASH_FLAG_READ_WRITE | \
432 FLASH_FLAG_READ_FAST | \
433 FLASH_FLAG_READ_1_1_2 | \
434 FLASH_FLAG_WRITE_1_1_2)
435 { "w25x40", 0xef3013, 0, 64 * 1024, 8, W25X_FLAG, 75, NULL },
436 { "w25x80", 0xef3014, 0, 64 * 1024, 16, W25X_FLAG, 75, NULL },
437 { "w25x16", 0xef3015, 0, 64 * 1024, 32, W25X_FLAG, 75, NULL },
438 { "w25x32", 0xef3016, 0, 64 * 1024, 64, W25X_FLAG, 75, NULL },
439 { "w25x64", 0xef3017, 0, 64 * 1024, 128, W25X_FLAG, 75, NULL },
441 /* Winbond -- w25q "blocks" are 64K, "sectors" are 4KiB */
442 #define W25Q_FLAG (FLASH_FLAG_READ_WRITE | \
443 FLASH_FLAG_READ_FAST | \
444 FLASH_FLAG_READ_1_1_2 | \
445 FLASH_FLAG_READ_1_2_2 | \
446 FLASH_FLAG_READ_1_1_4 | \
447 FLASH_FLAG_READ_1_4_4 | \
448 FLASH_FLAG_WRITE_1_1_4)
449 { "w25q80", 0xef4014, 0, 64 * 1024, 16, W25Q_FLAG, 80, NULL },
450 { "w25q16", 0xef4015, 0, 64 * 1024, 32, W25Q_FLAG, 80, NULL },
451 { "w25q32", 0xef4016, 0, 64 * 1024, 64, W25Q_FLAG, 80, NULL },
452 { "w25q64", 0xef4017, 0, 64 * 1024, 128, W25Q_FLAG, 80, NULL },
455 { NULL, 0x000000, 0, 0, 0, 0, 0, NULL },
459 * FSM message sequence configurations:
461 * All configs are presented in order of preference
464 /* Default READ configurations, in order of preference */
465 static struct seq_rw_config default_read_configs[] = {
466 {FLASH_FLAG_READ_1_4_4, FLASH_CMD_READ_1_4_4, 0, 4, 4, 0x00, 2, 4},
467 {FLASH_FLAG_READ_1_1_4, FLASH_CMD_READ_1_1_4, 0, 1, 4, 0x00, 4, 0},
468 {FLASH_FLAG_READ_1_2_2, FLASH_CMD_READ_1_2_2, 0, 2, 2, 0x00, 4, 0},
469 {FLASH_FLAG_READ_1_1_2, FLASH_CMD_READ_1_1_2, 0, 1, 2, 0x00, 0, 8},
470 {FLASH_FLAG_READ_FAST, FLASH_CMD_READ_FAST, 0, 1, 1, 0x00, 0, 8},
471 {FLASH_FLAG_READ_WRITE, FLASH_CMD_READ, 0, 1, 1, 0x00, 0, 0},
472 {0x00, 0, 0, 0, 0, 0x00, 0, 0},
475 /* Default WRITE configurations */
476 static struct seq_rw_config default_write_configs[] = {
477 {FLASH_FLAG_WRITE_1_4_4, FLASH_CMD_WRITE_1_4_4, 1, 4, 4, 0x00, 0, 0},
478 {FLASH_FLAG_WRITE_1_1_4, FLASH_CMD_WRITE_1_1_4, 1, 1, 4, 0x00, 0, 0},
479 {FLASH_FLAG_WRITE_1_2_2, FLASH_CMD_WRITE_1_2_2, 1, 2, 2, 0x00, 0, 0},
480 {FLASH_FLAG_WRITE_1_1_2, FLASH_CMD_WRITE_1_1_2, 1, 1, 2, 0x00, 0, 0},
481 {FLASH_FLAG_READ_WRITE, FLASH_CMD_WRITE, 1, 1, 1, 0x00, 0, 0},
482 {0x00, 0, 0, 0, 0, 0x00, 0, 0},
486 * [N25Qxxx] Configuration
488 #define N25Q_VCR_DUMMY_CYCLES(x) (((x) & 0xf) << 4)
489 #define N25Q_VCR_XIP_DISABLED ((uint8_t)0x1 << 3)
490 #define N25Q_VCR_WRAP_CONT 0x3
492 /* N25Q 3-byte Address READ configurations
493 * - 'FAST' variants configured for 8 dummy cycles.
495 * Note, the number of dummy cycles used for 'FAST' READ operations is
496 * configurable and would normally be tuned according to the READ command and
497 * operating frequency. However, this applies universally to all 'FAST' READ
498 * commands, including those used by the SPIBoot controller, and remains in
499 * force until the device is power-cycled. Since the SPIBoot controller is
500 * hard-wired to use 8 dummy cycles, we must configure the device to also use 8
503 static struct seq_rw_config n25q_read3_configs[] = {
504 {FLASH_FLAG_READ_1_4_4, FLASH_CMD_READ_1_4_4, 0, 4, 4, 0x00, 0, 8},
505 {FLASH_FLAG_READ_1_1_4, FLASH_CMD_READ_1_1_4, 0, 1, 4, 0x00, 0, 8},
506 {FLASH_FLAG_READ_1_2_2, FLASH_CMD_READ_1_2_2, 0, 2, 2, 0x00, 0, 8},
507 {FLASH_FLAG_READ_1_1_2, FLASH_CMD_READ_1_1_2, 0, 1, 2, 0x00, 0, 8},
508 {FLASH_FLAG_READ_FAST, FLASH_CMD_READ_FAST, 0, 1, 1, 0x00, 0, 8},
509 {FLASH_FLAG_READ_WRITE, FLASH_CMD_READ, 0, 1, 1, 0x00, 0, 0},
510 {0x00, 0, 0, 0, 0, 0x00, 0, 0},
513 /* N25Q 4-byte Address READ configurations
514 * - use special 4-byte address READ commands (reduces overheads, and
515 * reduces risk of hitting watchdog reset issues).
516 * - 'FAST' variants configured for 8 dummy cycles (see note above.)
518 static struct seq_rw_config n25q_read4_configs[] = {
519 {FLASH_FLAG_READ_1_4_4, FLASH_CMD_READ4_1_4_4, 0, 4, 4, 0x00, 0, 8},
520 {FLASH_FLAG_READ_1_1_4, FLASH_CMD_READ4_1_1_4, 0, 1, 4, 0x00, 0, 8},
521 {FLASH_FLAG_READ_1_2_2, FLASH_CMD_READ4_1_2_2, 0, 2, 2, 0x00, 0, 8},
522 {FLASH_FLAG_READ_1_1_2, FLASH_CMD_READ4_1_1_2, 0, 1, 2, 0x00, 0, 8},
523 {FLASH_FLAG_READ_FAST, FLASH_CMD_READ4_FAST, 0, 1, 1, 0x00, 0, 8},
524 {FLASH_FLAG_READ_WRITE, FLASH_CMD_READ4, 0, 1, 1, 0x00, 0, 0},
525 {0x00, 0, 0, 0, 0, 0x00, 0, 0},
529 * [MX25xxx] Configuration
531 #define MX25_STATUS_QE (0x1 << 6)
533 static int stfsm_mx25_en_32bit_addr_seq(struct stfsm_seq *seq)
535 seq->seq_opc[0] = (SEQ_OPC_PADS_1 |
537 SEQ_OPC_OPCODE(FLASH_CMD_EN4B_ADDR) |
540 seq->seq[0] = STFSM_INST_CMD1;
541 seq->seq[1] = STFSM_INST_WAIT;
542 seq->seq[2] = STFSM_INST_STOP;
544 seq->seq_cfg = (SEQ_CFG_PADS_1 |
546 SEQ_CFG_READNOTWRITE |
554 * [S25FLxxx] Configuration
556 #define STFSM_S25FL_CONFIG_QE (0x1 << 1)
559 * S25FLxxxS devices provide three ways of supporting 32-bit addressing: Bank
560 * Register, Extended Address Modes, and a 32-bit address command set. The
561 * 32-bit address command set is used here, since it avoids any problems with
562 * entering a state that is incompatible with the SPIBoot Controller.
564 static struct seq_rw_config stfsm_s25fl_read4_configs[] = {
565 {FLASH_FLAG_READ_1_4_4, FLASH_CMD_READ4_1_4_4, 0, 4, 4, 0x00, 2, 4},
566 {FLASH_FLAG_READ_1_1_4, FLASH_CMD_READ4_1_1_4, 0, 1, 4, 0x00, 0, 8},
567 {FLASH_FLAG_READ_1_2_2, FLASH_CMD_READ4_1_2_2, 0, 2, 2, 0x00, 4, 0},
568 {FLASH_FLAG_READ_1_1_2, FLASH_CMD_READ4_1_1_2, 0, 1, 2, 0x00, 0, 8},
569 {FLASH_FLAG_READ_FAST, FLASH_CMD_READ4_FAST, 0, 1, 1, 0x00, 0, 8},
570 {FLASH_FLAG_READ_WRITE, FLASH_CMD_READ4, 0, 1, 1, 0x00, 0, 0},
571 {0x00, 0, 0, 0, 0, 0x00, 0, 0},
574 static struct seq_rw_config stfsm_s25fl_write4_configs[] = {
575 {FLASH_FLAG_WRITE_1_1_4, S25FL_CMD_WRITE4_1_1_4, 1, 1, 4, 0x00, 0, 0},
576 {FLASH_FLAG_READ_WRITE, S25FL_CMD_WRITE4, 1, 1, 1, 0x00, 0, 0},
577 {0x00, 0, 0, 0, 0, 0x00, 0, 0},
580 static struct stfsm_seq stfsm_seq_read; /* Dynamically populated */
581 static struct stfsm_seq stfsm_seq_write; /* Dynamically populated */
582 static struct stfsm_seq stfsm_seq_en_32bit_addr;/* Dynamically populated */
584 static struct stfsm_seq stfsm_seq_read_jedec = {
585 .data_size = TRANSFER_SIZE(8),
586 .seq_opc[0] = (SEQ_OPC_PADS_1 |
588 SEQ_OPC_OPCODE(FLASH_CMD_RDID)),
591 STFSM_INST_DATA_READ,
594 .seq_cfg = (SEQ_CFG_PADS_1 |
595 SEQ_CFG_READNOTWRITE |
600 static struct stfsm_seq stfsm_seq_read_status_fifo = {
601 .data_size = TRANSFER_SIZE(4),
602 .seq_opc[0] = (SEQ_OPC_PADS_1 |
604 SEQ_OPC_OPCODE(FLASH_CMD_RDSR)),
607 STFSM_INST_DATA_READ,
610 .seq_cfg = (SEQ_CFG_PADS_1 |
611 SEQ_CFG_READNOTWRITE |
616 static struct stfsm_seq stfsm_seq_erase_sector = {
617 /* 'addr_cfg' configured during initialisation */
619 (SEQ_OPC_PADS_1 | SEQ_OPC_CYCLES(8) |
620 SEQ_OPC_OPCODE(FLASH_CMD_WREN) | SEQ_OPC_CSDEASSERT),
622 (SEQ_OPC_PADS_1 | SEQ_OPC_CYCLES(8) |
623 SEQ_OPC_OPCODE(FLASH_CMD_SE)),
632 .seq_cfg = (SEQ_CFG_PADS_1 |
633 SEQ_CFG_READNOTWRITE |
638 static struct stfsm_seq stfsm_seq_erase_chip = {
640 (SEQ_OPC_PADS_1 | SEQ_OPC_CYCLES(8) |
641 SEQ_OPC_OPCODE(FLASH_CMD_WREN) | SEQ_OPC_CSDEASSERT),
643 (SEQ_OPC_PADS_1 | SEQ_OPC_CYCLES(8) |
644 SEQ_OPC_OPCODE(FLASH_CMD_CHIPERASE) | SEQ_OPC_CSDEASSERT),
652 .seq_cfg = (SEQ_CFG_PADS_1 |
654 SEQ_CFG_READNOTWRITE |
659 static struct stfsm_seq stfsm_seq_write_status = {
660 .seq_opc[0] = (SEQ_OPC_PADS_1 | SEQ_OPC_CYCLES(8) |
661 SEQ_OPC_OPCODE(FLASH_CMD_WREN) | SEQ_OPC_CSDEASSERT),
662 .seq_opc[1] = (SEQ_OPC_PADS_1 | SEQ_OPC_CYCLES(8) |
663 SEQ_OPC_OPCODE(FLASH_CMD_WRSR)),
670 .seq_cfg = (SEQ_CFG_PADS_1 |
671 SEQ_CFG_READNOTWRITE |
676 static struct stfsm_seq stfsm_seq_wrvcr = {
677 .seq_opc[0] = (SEQ_OPC_PADS_1 | SEQ_OPC_CYCLES(8) |
678 SEQ_OPC_OPCODE(FLASH_CMD_WREN) | SEQ_OPC_CSDEASSERT),
679 .seq_opc[1] = (SEQ_OPC_PADS_1 | SEQ_OPC_CYCLES(8) |
680 SEQ_OPC_OPCODE(FLASH_CMD_WRVCR)),
687 .seq_cfg = (SEQ_CFG_PADS_1 |
688 SEQ_CFG_READNOTWRITE |
693 static int stfsm_n25q_en_32bit_addr_seq(struct stfsm_seq *seq)
695 seq->seq_opc[0] = (SEQ_OPC_PADS_1 | SEQ_OPC_CYCLES(8) |
696 SEQ_OPC_OPCODE(FLASH_CMD_EN4B_ADDR));
697 seq->seq_opc[1] = (SEQ_OPC_PADS_1 | SEQ_OPC_CYCLES(8) |
698 SEQ_OPC_OPCODE(FLASH_CMD_WREN) |
701 seq->seq[0] = STFSM_INST_CMD2;
702 seq->seq[1] = STFSM_INST_CMD1;
703 seq->seq[2] = STFSM_INST_WAIT;
704 seq->seq[3] = STFSM_INST_STOP;
706 seq->seq_cfg = (SEQ_CFG_PADS_1 |
708 SEQ_CFG_READNOTWRITE |
715 static inline int stfsm_is_idle(struct stfsm *fsm)
717 return readl(fsm->base + SPI_FAST_SEQ_STA) & 0x10;
720 static inline uint32_t stfsm_fifo_available(struct stfsm *fsm)
722 return (readl(fsm->base + SPI_FAST_SEQ_STA) >> 5) & 0x7f;
725 static void stfsm_clear_fifo(struct stfsm *fsm)
730 avail = stfsm_fifo_available(fsm);
735 readl(fsm->base + SPI_FAST_SEQ_DATA_REG);
741 static inline void stfsm_load_seq(struct stfsm *fsm,
742 const struct stfsm_seq *seq)
744 void __iomem *dst = fsm->base + SPI_FAST_SEQ_TRANSFER_SIZE;
745 const uint32_t *src = (const uint32_t *)seq;
746 int words = sizeof(*seq) / sizeof(*src);
748 BUG_ON(!stfsm_is_idle(fsm));
757 static void stfsm_wait_seq(struct stfsm *fsm)
759 unsigned long deadline;
762 deadline = jiffies + msecs_to_jiffies(STFSM_MAX_WAIT_SEQ_MS);
765 if (time_after_eq(jiffies, deadline))
768 if (stfsm_is_idle(fsm))
774 dev_err(fsm->dev, "timeout on sequence completion\n");
777 static void stfsm_read_fifo(struct stfsm *fsm, uint32_t *buf,
780 uint32_t remaining = size >> 2;
784 dev_dbg(fsm->dev, "Reading %d bytes from FIFO\n", size);
786 BUG_ON((((uint32_t)buf) & 0x3) || (size & 0x3));
790 avail = stfsm_fifo_available(fsm);
795 words = min(avail, remaining);
798 readsl(fsm->base + SPI_FAST_SEQ_DATA_REG, buf, words);
803 static int stfsm_write_fifo(struct stfsm *fsm,
804 const uint32_t *buf, const uint32_t size)
806 uint32_t words = size >> 2;
808 dev_dbg(fsm->dev, "writing %d bytes to FIFO\n", size);
810 BUG_ON((((uint32_t)buf) & 0x3) || (size & 0x3));
812 writesl(fsm->base + SPI_FAST_SEQ_DATA_REG, buf, words);
817 static int stfsm_enter_32bit_addr(struct stfsm *fsm, int enter)
819 struct stfsm_seq *seq = &stfsm_seq_en_32bit_addr;
820 uint32_t cmd = enter ? FLASH_CMD_EN4B_ADDR : FLASH_CMD_EX4B_ADDR;
822 seq->seq_opc[0] = (SEQ_OPC_PADS_1 |
824 SEQ_OPC_OPCODE(cmd) |
827 stfsm_load_seq(fsm, seq);
834 static uint8_t stfsm_wait_busy(struct stfsm *fsm)
836 struct stfsm_seq *seq = &stfsm_seq_read_status_fifo;
837 unsigned long deadline;
842 seq->seq_opc[0] = (SEQ_OPC_PADS_1 |
844 SEQ_OPC_OPCODE(FLASH_CMD_RDSR));
846 /* Load read_status sequence */
847 stfsm_load_seq(fsm, seq);
850 * Repeat until busy bit is deasserted, or timeout, or error (S25FLxxxS)
852 deadline = jiffies + FLASH_MAX_BUSY_WAIT;
856 if (time_after_eq(jiffies, deadline))
861 stfsm_read_fifo(fsm, &status, 4);
863 if ((status & FLASH_STATUS_BUSY) == 0)
866 if ((fsm->configuration & CFG_S25FL_CHECK_ERROR_FLAGS) &&
867 ((status & S25FL_STATUS_P_ERR) ||
868 (status & S25FL_STATUS_E_ERR)))
869 return (uint8_t)(status & 0xff);
873 writel(seq->seq_cfg, fsm->base + SPI_FAST_SEQ_CFG);
876 dev_err(fsm->dev, "timeout on wait_busy\n");
878 return FLASH_STATUS_TIMEOUT;
881 static int stfsm_read_status(struct stfsm *fsm, uint8_t cmd,
884 struct stfsm_seq *seq = &stfsm_seq_read_status_fifo;
887 dev_dbg(fsm->dev, "reading STA[%s]\n",
888 (cmd == FLASH_CMD_RDSR) ? "1" : "2");
890 seq->seq_opc[0] = (SEQ_OPC_PADS_1 |
892 SEQ_OPC_OPCODE(cmd)),
894 stfsm_load_seq(fsm, seq);
896 stfsm_read_fifo(fsm, &tmp, 4);
898 *status = (uint8_t)(tmp >> 24);
905 static int stfsm_write_status(struct stfsm *fsm, uint16_t status,
908 struct stfsm_seq *seq = &stfsm_seq_write_status;
910 dev_dbg(fsm->dev, "writing STA[%s] 0x%04x\n",
911 (sta_bytes == 1) ? "1" : "1+2", status);
913 seq->status = (uint32_t)status | STA_PADS_1 | STA_CSDEASSERT;
914 seq->seq[2] = (sta_bytes == 1) ?
915 STFSM_INST_STA_WR1 : STFSM_INST_STA_WR1_2;
917 stfsm_load_seq(fsm, seq);
924 static int stfsm_wrvcr(struct stfsm *fsm, uint8_t data)
926 struct stfsm_seq *seq = &stfsm_seq_wrvcr;
928 dev_dbg(fsm->dev, "writing VCR 0x%02x\n", data);
930 seq->status = (STA_DATA_BYTE1(data) | STA_PADS_1 | STA_CSDEASSERT);
932 stfsm_load_seq(fsm, seq);
940 * SoC reset on 'boot-from-spi' systems
942 * Certain modes of operation cause the Flash device to enter a particular state
943 * for a period of time (e.g. 'Erase Sector', 'Quad Enable', and 'Enter 32-bit
944 * Addr' commands). On boot-from-spi systems, it is important to consider what
945 * happens if a warm reset occurs during this period. The SPIBoot controller
946 * assumes that Flash device is in its default reset state, 24-bit address mode,
947 * and ready to accept commands. This can be achieved using some form of
948 * on-board logic/controller to force a device POR in response to a SoC-level
949 * reset or by making use of the device reset signal if available (limited
950 * number of devices only).
952 * Failure to take such precautions can cause problems following a warm reset.
953 * For some operations (e.g. ERASE), there is little that can be done. For
954 * other modes of operation (e.g. 32-bit addressing), options are often
955 * available that can help minimise the window in which a reset could cause a
959 static bool stfsm_can_handle_soc_reset(struct stfsm *fsm)
961 /* Reset signal is available on the board and supported by the device */
962 if (fsm->reset_signal && fsm->info->flags & FLASH_FLAG_RESET)
965 /* Board-level logic forces a power-on-reset */
969 /* Reset is not properly handled and may result in failure to reboot */
973 /* Configure 'addr_cfg' according to addressing mode */
974 static void stfsm_prepare_erasesec_seq(struct stfsm *fsm,
975 struct stfsm_seq *seq)
977 int addr1_cycles = fsm->info->flags & FLASH_FLAG_32BIT_ADDR ? 16 : 8;
979 seq->addr_cfg = (ADR_CFG_CYCLES_ADD1(addr1_cycles) |
980 ADR_CFG_PADS_1_ADD1 |
981 ADR_CFG_CYCLES_ADD2(16) |
982 ADR_CFG_PADS_1_ADD2 |
983 ADR_CFG_CSDEASSERT_ADD2);
986 /* Search for preferred configuration based on available flags */
987 static struct seq_rw_config *
988 stfsm_search_seq_rw_configs(struct stfsm *fsm,
989 struct seq_rw_config cfgs[])
991 struct seq_rw_config *config;
992 int flags = fsm->info->flags;
994 for (config = cfgs; config->cmd != 0; config++)
995 if ((config->flags & flags) == config->flags)
1001 /* Prepare a READ/WRITE sequence according to configuration parameters */
1002 static void stfsm_prepare_rw_seq(struct stfsm *fsm,
1003 struct stfsm_seq *seq,
1004 struct seq_rw_config *cfg)
1006 int addr1_cycles, addr2_cycles;
1009 memset(seq, 0, sizeof(*seq));
1011 /* Add READ/WRITE OPC */
1012 seq->seq_opc[i++] = (SEQ_OPC_PADS_1 |
1014 SEQ_OPC_OPCODE(cfg->cmd));
1016 /* Add WREN OPC for a WRITE sequence */
1018 seq->seq_opc[i++] = (SEQ_OPC_PADS_1 |
1020 SEQ_OPC_OPCODE(FLASH_CMD_WREN) |
1021 SEQ_OPC_CSDEASSERT);
1023 /* Address configuration (24 or 32-bit addresses) */
1024 addr1_cycles = (fsm->info->flags & FLASH_FLAG_32BIT_ADDR) ? 16 : 8;
1025 addr1_cycles /= cfg->addr_pads;
1026 addr2_cycles = 16 / cfg->addr_pads;
1027 seq->addr_cfg = ((addr1_cycles & 0x3f) << 0 | /* ADD1 cycles */
1028 (cfg->addr_pads - 1) << 6 | /* ADD1 pads */
1029 (addr2_cycles & 0x3f) << 16 | /* ADD2 cycles */
1030 ((cfg->addr_pads - 1) << 22)); /* ADD2 pads */
1032 /* Data/Sequence configuration */
1033 seq->seq_cfg = ((cfg->data_pads - 1) << 16 |
1035 SEQ_CFG_CSDEASSERT);
1037 seq->seq_cfg |= SEQ_CFG_READNOTWRITE;
1039 /* Mode configuration (no. of pads taken from addr cfg) */
1040 seq->mode = ((cfg->mode_data & 0xff) << 0 | /* data */
1041 (cfg->mode_cycles & 0x3f) << 16 | /* cycles */
1042 (cfg->addr_pads - 1) << 22); /* pads */
1044 /* Dummy configuration (no. of pads taken from addr cfg) */
1045 seq->dummy = ((cfg->dummy_cycles & 0x3f) << 16 | /* cycles */
1046 (cfg->addr_pads - 1) << 22); /* pads */
1049 /* Instruction sequence */
1052 seq->seq[i++] = STFSM_INST_CMD2;
1054 seq->seq[i++] = STFSM_INST_CMD1;
1056 seq->seq[i++] = STFSM_INST_ADD1;
1057 seq->seq[i++] = STFSM_INST_ADD2;
1059 if (cfg->mode_cycles)
1060 seq->seq[i++] = STFSM_INST_MODE;
1062 if (cfg->dummy_cycles)
1063 seq->seq[i++] = STFSM_INST_DUMMY;
1066 cfg->write ? STFSM_INST_DATA_WRITE : STFSM_INST_DATA_READ;
1067 seq->seq[i++] = STFSM_INST_STOP;
1070 static int stfsm_search_prepare_rw_seq(struct stfsm *fsm,
1071 struct stfsm_seq *seq,
1072 struct seq_rw_config *cfgs)
1074 struct seq_rw_config *config;
1076 config = stfsm_search_seq_rw_configs(fsm, cfgs);
1078 dev_err(fsm->dev, "failed to find suitable config\n");
1082 stfsm_prepare_rw_seq(fsm, seq, config);
1087 /* Prepare a READ/WRITE/ERASE 'default' sequences */
1088 static int stfsm_prepare_rwe_seqs_default(struct stfsm *fsm)
1090 uint32_t flags = fsm->info->flags;
1093 /* Configure 'READ' sequence */
1094 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_read,
1095 default_read_configs);
1098 "failed to prep READ sequence with flags [0x%08x]\n",
1103 /* Configure 'WRITE' sequence */
1104 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_write,
1105 default_write_configs);
1108 "failed to prep WRITE sequence with flags [0x%08x]\n",
1113 /* Configure 'ERASE_SECTOR' sequence */
1114 stfsm_prepare_erasesec_seq(fsm, &stfsm_seq_erase_sector);
1119 static int stfsm_mx25_config(struct stfsm *fsm)
1121 uint32_t flags = fsm->info->flags;
1128 * Use default READ/WRITE sequences
1130 ret = stfsm_prepare_rwe_seqs_default(fsm);
1135 * Configure 32-bit Address Support
1137 if (flags & FLASH_FLAG_32BIT_ADDR) {
1138 /* Configure 'enter_32bitaddr' FSM sequence */
1139 stfsm_mx25_en_32bit_addr_seq(&stfsm_seq_en_32bit_addr);
1141 soc_reset = stfsm_can_handle_soc_reset(fsm);
1142 if (soc_reset || !fsm->booted_from_spi) {
1143 /* If we can handle SoC resets, we enable 32-bit address
1144 * mode pervasively */
1145 stfsm_enter_32bit_addr(fsm, 1);
1148 /* Else, enable/disable 32-bit addressing before/after
1150 fsm->configuration = (CFG_READ_TOGGLE_32BIT_ADDR |
1151 CFG_WRITE_TOGGLE_32BIT_ADDR |
1152 CFG_ERASESEC_TOGGLE_32BIT_ADDR);
1153 /* It seems a small delay is required after exiting
1154 * 32-bit mode following a write operation. The issue
1155 * is under investigation.
1157 fsm->configuration |= CFG_WRITE_EX_32BIT_ADDR_DELAY;
1161 /* For QUAD mode, set 'QE' STATUS bit */
1162 data_pads = ((stfsm_seq_read.seq_cfg >> 16) & 0x3) + 1;
1163 if (data_pads == 4) {
1164 stfsm_read_status(fsm, FLASH_CMD_RDSR, &sta);
1165 sta |= MX25_STATUS_QE;
1166 stfsm_write_status(fsm, sta, 1);
1172 static int stfsm_n25q_config(struct stfsm *fsm)
1174 uint32_t flags = fsm->info->flags;
1179 /* Configure 'READ' sequence */
1180 if (flags & FLASH_FLAG_32BIT_ADDR)
1181 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_read,
1182 n25q_read4_configs);
1184 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_read,
1185 n25q_read3_configs);
1188 "failed to prepare READ sequence with flags [0x%08x]\n",
1193 /* Configure 'WRITE' sequence (default configs) */
1194 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_write,
1195 default_write_configs);
1198 "preparing WRITE sequence using flags [0x%08x] failed\n",
1203 /* * Configure 'ERASE_SECTOR' sequence */
1204 stfsm_prepare_erasesec_seq(fsm, &stfsm_seq_erase_sector);
1206 /* Configure 32-bit address support */
1207 if (flags & FLASH_FLAG_32BIT_ADDR) {
1208 stfsm_n25q_en_32bit_addr_seq(&stfsm_seq_en_32bit_addr);
1210 soc_reset = stfsm_can_handle_soc_reset(fsm);
1211 if (soc_reset || !fsm->booted_from_spi) {
1213 * If we can handle SoC resets, we enable 32-bit
1214 * address mode pervasively
1216 stfsm_enter_32bit_addr(fsm, 1);
1219 * If not, enable/disable for WRITE and ERASE
1220 * operations (READ uses special commands)
1222 fsm->configuration = (CFG_WRITE_TOGGLE_32BIT_ADDR |
1223 CFG_ERASESEC_TOGGLE_32BIT_ADDR);
1228 * Configure device to use 8 dummy cycles
1230 vcr = (N25Q_VCR_DUMMY_CYCLES(8) | N25Q_VCR_XIP_DISABLED |
1231 N25Q_VCR_WRAP_CONT);
1232 stfsm_wrvcr(fsm, vcr);
1237 static void stfsm_s25fl_prepare_erasesec_seq_32(struct stfsm_seq *seq)
1239 seq->seq_opc[1] = (SEQ_OPC_PADS_1 |
1241 SEQ_OPC_OPCODE(S25FL_CMD_SE4));
1243 seq->addr_cfg = (ADR_CFG_CYCLES_ADD1(16) |
1244 ADR_CFG_PADS_1_ADD1 |
1245 ADR_CFG_CYCLES_ADD2(16) |
1246 ADR_CFG_PADS_1_ADD2 |
1247 ADR_CFG_CSDEASSERT_ADD2);
1250 static void stfsm_s25fl_read_dyb(struct stfsm *fsm, uint32_t offs, uint8_t *dby)
1253 struct stfsm_seq seq = {
1254 .data_size = TRANSFER_SIZE(4),
1255 .seq_opc[0] = (SEQ_OPC_PADS_1 |
1257 SEQ_OPC_OPCODE(S25FL_CMD_DYBRD)),
1258 .addr_cfg = (ADR_CFG_CYCLES_ADD1(16) |
1259 ADR_CFG_PADS_1_ADD1 |
1260 ADR_CFG_CYCLES_ADD2(16) |
1261 ADR_CFG_PADS_1_ADD2),
1262 .addr1 = (offs >> 16) & 0xffff,
1263 .addr2 = offs & 0xffff,
1268 STFSM_INST_DATA_READ,
1271 .seq_cfg = (SEQ_CFG_PADS_1 |
1272 SEQ_CFG_READNOTWRITE |
1273 SEQ_CFG_CSDEASSERT |
1277 stfsm_load_seq(fsm, &seq);
1279 stfsm_read_fifo(fsm, &tmp, 4);
1281 *dby = (uint8_t)(tmp >> 24);
1283 stfsm_wait_seq(fsm);
1286 static void stfsm_s25fl_write_dyb(struct stfsm *fsm, uint32_t offs, uint8_t dby)
1288 struct stfsm_seq seq = {
1289 .seq_opc[0] = (SEQ_OPC_PADS_1 | SEQ_OPC_CYCLES(8) |
1290 SEQ_OPC_OPCODE(FLASH_CMD_WREN) |
1291 SEQ_OPC_CSDEASSERT),
1292 .seq_opc[1] = (SEQ_OPC_PADS_1 | SEQ_OPC_CYCLES(8) |
1293 SEQ_OPC_OPCODE(S25FL_CMD_DYBWR)),
1294 .addr_cfg = (ADR_CFG_CYCLES_ADD1(16) |
1295 ADR_CFG_PADS_1_ADD1 |
1296 ADR_CFG_CYCLES_ADD2(16) |
1297 ADR_CFG_PADS_1_ADD2),
1298 .status = (uint32_t)dby | STA_PADS_1 | STA_CSDEASSERT,
1299 .addr1 = (offs >> 16) & 0xffff,
1300 .addr2 = offs & 0xffff,
1309 .seq_cfg = (SEQ_CFG_PADS_1 |
1310 SEQ_CFG_READNOTWRITE |
1311 SEQ_CFG_CSDEASSERT |
1315 stfsm_load_seq(fsm, &seq);
1316 stfsm_wait_seq(fsm);
1318 stfsm_wait_busy(fsm);
1321 static int stfsm_s25fl_clear_status_reg(struct stfsm *fsm)
1323 struct stfsm_seq seq = {
1324 .seq_opc[0] = (SEQ_OPC_PADS_1 |
1326 SEQ_OPC_OPCODE(S25FL_CMD_CLSR) |
1327 SEQ_OPC_CSDEASSERT),
1328 .seq_opc[1] = (SEQ_OPC_PADS_1 |
1330 SEQ_OPC_OPCODE(FLASH_CMD_WRDI) |
1331 SEQ_OPC_CSDEASSERT),
1338 .seq_cfg = (SEQ_CFG_PADS_1 |
1340 SEQ_CFG_READNOTWRITE |
1341 SEQ_CFG_CSDEASSERT |
1345 stfsm_load_seq(fsm, &seq);
1347 stfsm_wait_seq(fsm);
1352 static int stfsm_s25fl_config(struct stfsm *fsm)
1354 struct flash_info *info = fsm->info;
1355 uint32_t flags = info->flags;
1359 uint8_t sr1, cr1, dyb;
1362 if (flags & FLASH_FLAG_32BIT_ADDR) {
1364 * Prepare Read/Write/Erase sequences according to S25FLxxx
1365 * 32-bit address command set
1367 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_read,
1368 stfsm_s25fl_read4_configs);
1372 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_write,
1373 stfsm_s25fl_write4_configs);
1377 stfsm_s25fl_prepare_erasesec_seq_32(&stfsm_seq_erase_sector);
1380 /* Use default configurations for 24-bit addressing */
1381 ret = stfsm_prepare_rwe_seqs_default(fsm);
1387 * For devices that support 'DYB' sector locking, check lock status and
1388 * unlock sectors if necessary (some variants power-on with sectors
1389 * locked by default)
1391 if (flags & FLASH_FLAG_DYB_LOCKING) {
1393 for (offs = 0; offs < info->sector_size * info->n_sectors;) {
1394 stfsm_s25fl_read_dyb(fsm, offs, &dyb);
1396 stfsm_s25fl_write_dyb(fsm, offs, 0xff);
1398 /* Handle bottom/top 4KiB parameter sectors */
1399 if ((offs < info->sector_size * 2) ||
1400 (offs >= (info->sector_size - info->n_sectors * 4)))
1407 /* Check status of 'QE' bit */
1408 data_pads = ((stfsm_seq_read.seq_cfg >> 16) & 0x3) + 1;
1409 stfsm_read_status(fsm, FLASH_CMD_RDSR2, &cr1);
1410 if (data_pads == 4) {
1411 if (!(cr1 & STFSM_S25FL_CONFIG_QE)) {
1413 cr1 |= STFSM_S25FL_CONFIG_QE;
1415 stfsm_read_status(fsm, FLASH_CMD_RDSR, &sr1);
1416 sta_wr = ((uint16_t)cr1 << 8) | sr1;
1418 stfsm_write_status(fsm, sta_wr, 2);
1420 stfsm_wait_busy(fsm);
1423 if ((cr1 & STFSM_S25FL_CONFIG_QE)) {
1425 cr1 &= ~STFSM_S25FL_CONFIG_QE;
1427 stfsm_read_status(fsm, FLASH_CMD_RDSR, &sr1);
1428 sta_wr = ((uint16_t)cr1 << 8) | sr1;
1430 stfsm_write_status(fsm, sta_wr, 2);
1432 stfsm_wait_busy(fsm);
1438 * S25FLxxx devices support Program and Error error flags.
1439 * Configure driver to check flags and clear if necessary.
1441 fsm->configuration |= CFG_S25FL_CHECK_ERROR_FLAGS;
1446 static int stfsm_read(struct stfsm *fsm, uint8_t *buf, uint32_t size,
1449 struct stfsm_seq *seq = &stfsm_seq_read;
1456 uint32_t page_buf[FLASH_PAGESIZE_32];
1459 dev_dbg(fsm->dev, "reading %d bytes from 0x%08x\n", size, offset);
1461 /* Enter 32-bit address mode, if required */
1462 if (fsm->configuration & CFG_READ_TOGGLE_32BIT_ADDR)
1463 stfsm_enter_32bit_addr(fsm, 1);
1465 /* Must read in multiples of 32 cycles (or 32*pads/8 Bytes) */
1466 data_pads = ((seq->seq_cfg >> 16) & 0x3) + 1;
1467 read_mask = (data_pads << 2) - 1;
1469 /* Handle non-aligned buf */
1470 p = ((uint32_t)buf & 0x3) ? (uint8_t *)page_buf : buf;
1472 /* Handle non-aligned size */
1473 size_ub = (size + read_mask) & ~read_mask;
1474 size_lb = size & ~read_mask;
1475 size_mop = size & read_mask;
1477 seq->data_size = TRANSFER_SIZE(size_ub);
1478 seq->addr1 = (offset >> 16) & 0xffff;
1479 seq->addr2 = offset & 0xffff;
1481 stfsm_load_seq(fsm, seq);
1484 stfsm_read_fifo(fsm, (uint32_t *)p, size_lb);
1487 stfsm_read_fifo(fsm, tmp, read_mask + 1);
1488 memcpy(p + size_lb, &tmp, size_mop);
1491 /* Handle non-aligned buf */
1492 if ((uint32_t)buf & 0x3)
1493 memcpy(buf, page_buf, size);
1495 /* Wait for sequence to finish */
1496 stfsm_wait_seq(fsm);
1498 stfsm_clear_fifo(fsm);
1500 /* Exit 32-bit address mode, if required */
1501 if (fsm->configuration & CFG_READ_TOGGLE_32BIT_ADDR)
1502 stfsm_enter_32bit_addr(fsm, 0);
1507 static int stfsm_write(struct stfsm *fsm, const uint8_t *const buf,
1508 const uint32_t size, const uint32_t offset)
1510 struct stfsm_seq *seq = &stfsm_seq_write;
1512 uint32_t write_mask;
1517 uint32_t page_buf[FLASH_PAGESIZE_32];
1518 uint8_t *t = (uint8_t *)&tmp;
1523 dev_dbg(fsm->dev, "writing %d bytes to 0x%08x\n", size, offset);
1525 /* Enter 32-bit address mode, if required */
1526 if (fsm->configuration & CFG_WRITE_TOGGLE_32BIT_ADDR)
1527 stfsm_enter_32bit_addr(fsm, 1);
1529 /* Must write in multiples of 32 cycles (or 32*pads/8 bytes) */
1530 data_pads = ((seq->seq_cfg >> 16) & 0x3) + 1;
1531 write_mask = (data_pads << 2) - 1;
1533 /* Handle non-aligned buf */
1534 if ((uint32_t)buf & 0x3) {
1535 memcpy(page_buf, buf, size);
1536 p = (uint8_t *)page_buf;
1541 /* Handle non-aligned size */
1542 size_ub = (size + write_mask) & ~write_mask;
1543 size_lb = size & ~write_mask;
1544 size_mop = size & write_mask;
1546 seq->data_size = TRANSFER_SIZE(size_ub);
1547 seq->addr1 = (offset >> 16) & 0xffff;
1548 seq->addr2 = offset & 0xffff;
1550 /* Need to set FIFO to write mode, before writing data to FIFO (see
1553 writel(0x00040000, fsm->base + SPI_FAST_SEQ_CFG);
1556 * Before writing data to the FIFO, apply a small delay to allow a
1557 * potential change of FIFO direction to complete.
1559 if (fsm->fifo_dir_delay == 0)
1560 readl(fsm->base + SPI_FAST_SEQ_CFG);
1562 udelay(fsm->fifo_dir_delay);
1565 /* Write data to FIFO, before starting sequence (see GNBvd79593) */
1567 stfsm_write_fifo(fsm, (uint32_t *)p, size_lb);
1571 /* Handle non-aligned size */
1573 memset(t, 0xff, write_mask + 1); /* fill with 0xff's */
1574 for (i = 0; i < size_mop; i++)
1577 stfsm_write_fifo(fsm, tmp, write_mask + 1);
1580 /* Start sequence */
1581 stfsm_load_seq(fsm, seq);
1583 /* Wait for sequence to finish */
1584 stfsm_wait_seq(fsm);
1586 /* Wait for completion */
1587 ret = stfsm_wait_busy(fsm);
1588 if (ret && fsm->configuration & CFG_S25FL_CHECK_ERROR_FLAGS)
1589 stfsm_s25fl_clear_status_reg(fsm);
1591 /* Exit 32-bit address mode, if required */
1592 if (fsm->configuration & CFG_WRITE_TOGGLE_32BIT_ADDR) {
1593 stfsm_enter_32bit_addr(fsm, 0);
1594 if (fsm->configuration & CFG_WRITE_EX_32BIT_ADDR_DELAY)
1602 * Read an address range from the flash chip. The address range
1603 * may be any size provided it is within the physical boundaries.
1605 static int stfsm_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
1606 size_t *retlen, u_char *buf)
1608 struct stfsm *fsm = dev_get_drvdata(mtd->dev.parent);
1611 dev_dbg(fsm->dev, "%s from 0x%08x, len %zd\n",
1612 __func__, (u32)from, len);
1614 mutex_lock(&fsm->lock);
1617 bytes = min_t(size_t, len, FLASH_PAGESIZE);
1619 stfsm_read(fsm, buf, bytes, from);
1628 mutex_unlock(&fsm->lock);
1633 static int stfsm_erase_sector(struct stfsm *fsm, const uint32_t offset)
1635 struct stfsm_seq *seq = &stfsm_seq_erase_sector;
1638 dev_dbg(fsm->dev, "erasing sector at 0x%08x\n", offset);
1640 /* Enter 32-bit address mode, if required */
1641 if (fsm->configuration & CFG_ERASESEC_TOGGLE_32BIT_ADDR)
1642 stfsm_enter_32bit_addr(fsm, 1);
1644 seq->addr1 = (offset >> 16) & 0xffff;
1645 seq->addr2 = offset & 0xffff;
1647 stfsm_load_seq(fsm, seq);
1649 stfsm_wait_seq(fsm);
1651 /* Wait for completion */
1652 ret = stfsm_wait_busy(fsm);
1653 if (ret && fsm->configuration & CFG_S25FL_CHECK_ERROR_FLAGS)
1654 stfsm_s25fl_clear_status_reg(fsm);
1656 /* Exit 32-bit address mode, if required */
1657 if (fsm->configuration & CFG_ERASESEC_TOGGLE_32BIT_ADDR)
1658 stfsm_enter_32bit_addr(fsm, 0);
1663 static int stfsm_erase_chip(struct stfsm *fsm)
1665 const struct stfsm_seq *seq = &stfsm_seq_erase_chip;
1667 dev_dbg(fsm->dev, "erasing chip\n");
1669 stfsm_load_seq(fsm, seq);
1671 stfsm_wait_seq(fsm);
1673 return stfsm_wait_busy(fsm);
1677 * Write an address range to the flash chip. Data must be written in
1678 * FLASH_PAGESIZE chunks. The address range may be any size provided
1679 * it is within the physical boundaries.
1681 static int stfsm_mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
1682 size_t *retlen, const u_char *buf)
1684 struct stfsm *fsm = dev_get_drvdata(mtd->dev.parent);
1688 uint8_t *b = (uint8_t *)buf;
1691 dev_dbg(fsm->dev, "%s to 0x%08x, len %zd\n", __func__, (u32)to, len);
1698 if (to + len > mtd->size)
1701 /* Offset within page */
1702 page_offs = to % FLASH_PAGESIZE;
1704 mutex_lock(&fsm->lock);
1707 /* Write up to page boundary */
1708 bytes = min(FLASH_PAGESIZE - page_offs, len);
1710 ret = stfsm_write(fsm, b, bytes, to);
1718 /* We are now page-aligned */
1726 mutex_unlock(&fsm->lock);
1732 * Erase an address range on the flash chip. The address range may extend
1733 * one or more erase sectors. Return an error is there is a problem erasing.
1735 static int stfsm_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
1737 struct stfsm *fsm = dev_get_drvdata(mtd->dev.parent);
1741 dev_dbg(fsm->dev, "%s at 0x%llx, len %lld\n", __func__,
1742 (long long)instr->addr, (long long)instr->len);
1747 mutex_lock(&fsm->lock);
1749 /* Whole-chip erase? */
1750 if (len == mtd->size) {
1751 ret = stfsm_erase_chip(fsm);
1756 ret = stfsm_erase_sector(fsm, addr);
1760 addr += mtd->erasesize;
1761 len -= mtd->erasesize;
1765 mutex_unlock(&fsm->lock);
1767 instr->state = MTD_ERASE_DONE;
1768 mtd_erase_callback(instr);
1773 instr->state = MTD_ERASE_FAILED;
1774 mutex_unlock(&fsm->lock);
1779 static void stfsm_read_jedec(struct stfsm *fsm, uint8_t *const jedec)
1781 const struct stfsm_seq *seq = &stfsm_seq_read_jedec;
1784 stfsm_load_seq(fsm, seq);
1786 stfsm_read_fifo(fsm, tmp, 8);
1788 memcpy(jedec, tmp, 5);
1790 stfsm_wait_seq(fsm);
1793 static struct flash_info *stfsm_jedec_probe(struct stfsm *fsm)
1795 struct flash_info *info;
1800 stfsm_read_jedec(fsm, id);
1802 jedec = id[0] << 16 | id[1] << 8 | id[2];
1804 * JEDEC also defines an optional "extended device information"
1805 * string for after vendor-specific data, after the three bytes
1806 * we use here. Supporting some chips might require using it.
1808 ext_jedec = id[3] << 8 | id[4];
1810 dev_dbg(fsm->dev, "JEDEC = 0x%08x [%02x %02x %02x %02x %02x]\n",
1811 jedec, id[0], id[1], id[2], id[3], id[4]);
1813 for (info = flash_types; info->name; info++) {
1814 if (info->jedec_id == jedec) {
1815 if (info->ext_id && info->ext_id != ext_jedec)
1820 dev_err(fsm->dev, "Unrecognized JEDEC id %06x\n", jedec);
1825 static int stfsm_set_mode(struct stfsm *fsm, uint32_t mode)
1827 int ret, timeout = 10;
1829 /* Wait for controller to accept mode change */
1831 ret = readl(fsm->base + SPI_STA_MODE_CHANGE);
1840 writel(mode, fsm->base + SPI_MODESELECT);
1845 static void stfsm_set_freq(struct stfsm *fsm, uint32_t spi_freq)
1850 /* TODO: Make this dynamic */
1851 emi_freq = STFSM_DEFAULT_EMI_FREQ;
1854 * Calculate clk_div - values between 2 and 128
1855 * Multiple of 2, rounded up
1857 clk_div = 2 * DIV_ROUND_UP(emi_freq, 2 * spi_freq);
1860 else if (clk_div > 128)
1864 * Determine a suitable delay for the IP to complete a change of
1865 * direction of the FIFO. The required delay is related to the clock
1866 * divider used. The following heuristics are based on empirical tests,
1867 * using a 100MHz EMI clock.
1870 fsm->fifo_dir_delay = 0;
1871 else if (clk_div <= 10)
1872 fsm->fifo_dir_delay = 1;
1874 fsm->fifo_dir_delay = DIV_ROUND_UP(clk_div, 10);
1876 dev_dbg(fsm->dev, "emi_clk = %uHZ, spi_freq = %uHZ, clk_div = %u\n",
1877 emi_freq, spi_freq, clk_div);
1879 writel(clk_div, fsm->base + SPI_CLOCKDIV);
1882 static int stfsm_init(struct stfsm *fsm)
1886 /* Perform a soft reset of the FSM controller */
1887 writel(SEQ_CFG_SWRESET, fsm->base + SPI_FAST_SEQ_CFG);
1889 writel(0, fsm->base + SPI_FAST_SEQ_CFG);
1891 /* Set clock to 'safe' frequency initially */
1892 stfsm_set_freq(fsm, STFSM_FLASH_SAFE_FREQ);
1895 ret = stfsm_set_mode(fsm, SPI_MODESELECT_FSM);
1899 /* Set timing parameters */
1900 writel(SPI_CFG_DEVICE_ST |
1901 SPI_CFG_DEFAULT_MIN_CS_HIGH |
1902 SPI_CFG_DEFAULT_CS_SETUPHOLD |
1903 SPI_CFG_DEFAULT_DATA_HOLD,
1904 fsm->base + SPI_CONFIGDATA);
1905 writel(STFSM_DEFAULT_WR_TIME, fsm->base + SPI_STATUS_WR_TIME_REG);
1907 /* Clear FIFO, just in case */
1908 stfsm_clear_fifo(fsm);
1913 static void stfsm_fetch_platform_configs(struct platform_device *pdev)
1915 struct stfsm *fsm = platform_get_drvdata(pdev);
1916 struct device_node *np = pdev->dev.of_node;
1917 struct regmap *regmap;
1918 uint32_t boot_device_reg;
1919 uint32_t boot_device_spi;
1920 uint32_t boot_device; /* Value we read from *boot_device_reg */
1923 /* Booting from SPI NOR Flash is the default */
1924 fsm->booted_from_spi = true;
1926 regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
1928 goto boot_device_fail;
1930 fsm->reset_signal = of_property_read_bool(np, "st,reset-signal");
1932 fsm->reset_por = of_property_read_bool(np, "st,reset-por");
1934 /* Where in the syscon the boot device information lives */
1935 ret = of_property_read_u32(np, "st,boot-device-reg", &boot_device_reg);
1937 goto boot_device_fail;
1939 /* Boot device value when booted from SPI NOR */
1940 ret = of_property_read_u32(np, "st,boot-device-spi", &boot_device_spi);
1942 goto boot_device_fail;
1944 ret = regmap_read(regmap, boot_device_reg, &boot_device);
1946 goto boot_device_fail;
1948 if (boot_device != boot_device_spi)
1949 fsm->booted_from_spi = false;
1954 dev_warn(&pdev->dev,
1955 "failed to fetch boot device, assuming boot from SPI\n");
1958 static int stfsm_probe(struct platform_device *pdev)
1960 struct device_node *np = pdev->dev.of_node;
1961 struct flash_info *info;
1962 struct resource *res;
1967 dev_err(&pdev->dev, "No DT found\n");
1971 fsm = devm_kzalloc(&pdev->dev, sizeof(*fsm), GFP_KERNEL);
1975 fsm->dev = &pdev->dev;
1977 platform_set_drvdata(pdev, fsm);
1979 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1981 dev_err(&pdev->dev, "Resource not found\n");
1985 fsm->base = devm_ioremap_resource(&pdev->dev, res);
1986 if (IS_ERR(fsm->base)) {
1988 "Failed to reserve memory region %pR\n", res);
1989 return PTR_ERR(fsm->base);
1992 mutex_init(&fsm->lock);
1994 ret = stfsm_init(fsm);
1996 dev_err(&pdev->dev, "Failed to initialise FSM Controller\n");
2000 stfsm_fetch_platform_configs(pdev);
2002 /* Detect SPI FLASH device */
2003 info = stfsm_jedec_probe(fsm);
2008 /* Use device size to determine address width */
2009 if (info->sector_size * info->n_sectors > 0x1000000)
2010 info->flags |= FLASH_FLAG_32BIT_ADDR;
2013 * Configure READ/WRITE/ERASE sequences according to platform and
2017 ret = info->config(fsm);
2021 ret = stfsm_prepare_rwe_seqs_default(fsm);
2026 fsm->mtd.dev.parent = &pdev->dev;
2027 fsm->mtd.type = MTD_NORFLASH;
2028 fsm->mtd.writesize = 4;
2029 fsm->mtd.writebufsize = fsm->mtd.writesize;
2030 fsm->mtd.flags = MTD_CAP_NORFLASH;
2031 fsm->mtd.size = info->sector_size * info->n_sectors;
2032 fsm->mtd.erasesize = info->sector_size;
2034 fsm->mtd._read = stfsm_mtd_read;
2035 fsm->mtd._write = stfsm_mtd_write;
2036 fsm->mtd._erase = stfsm_mtd_erase;
2038 dev_info(&pdev->dev,
2039 "Found serial flash device: %s\n"
2040 " size = %llx (%lldMiB) erasesize = 0x%08x (%uKiB)\n",
2042 (long long)fsm->mtd.size, (long long)(fsm->mtd.size >> 20),
2043 fsm->mtd.erasesize, (fsm->mtd.erasesize >> 10));
2045 return mtd_device_parse_register(&fsm->mtd, NULL, NULL, NULL, 0);
2048 static int stfsm_remove(struct platform_device *pdev)
2050 struct stfsm *fsm = platform_get_drvdata(pdev);
2053 err = mtd_device_unregister(&fsm->mtd);
2060 static struct of_device_id stfsm_match[] = {
2061 { .compatible = "st,spi-fsm", },
2064 MODULE_DEVICE_TABLE(of, stfsm_match);
2066 static struct platform_driver stfsm_driver = {
2067 .probe = stfsm_probe,
2068 .remove = stfsm_remove,
2070 .name = "st-spi-fsm",
2071 .owner = THIS_MODULE,
2072 .of_match_table = stfsm_match,
2075 module_platform_driver(stfsm_driver);
2077 MODULE_AUTHOR("Angus Clark <angus.clark@st.com>");
2078 MODULE_DESCRIPTION("ST SPI FSM driver");
2079 MODULE_LICENSE("GPL");