blob: fec3dcc9cf2f8412cccdfdbb64464eb9237b88ea [file] [log] [blame]
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -07001/*
2 * SPI flash internal definitions
3 *
4 * Copyright (C) 2008 Atmel Corporation
5 */
6
Edward O'Callaghanc4561e22014-06-26 15:02:40 +10007#ifndef SPI_FLASH_INTERNAL_H
8#define SPI_FLASH_INTERNAL_H
9
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070010/* Common parameters -- kind of high, but they should only occur when there
11 * is a problem (and well your system already is broken), so err on the side
12 * of caution in case we're dealing with slower SPI buses and/or processors.
13 */
14#define CONFIG_SYS_HZ 100
15#define SPI_FLASH_PROG_TIMEOUT (2 * CONFIG_SYS_HZ)
16#define SPI_FLASH_PAGE_ERASE_TIMEOUT (5 * CONFIG_SYS_HZ)
17#define SPI_FLASH_SECTOR_ERASE_TIMEOUT (10 * CONFIG_SYS_HZ)
18
19/* Common commands */
20#define CMD_READ_ID 0x9f
21
22#define CMD_READ_ARRAY_SLOW 0x03
23#define CMD_READ_ARRAY_FAST 0x0b
24#define CMD_READ_ARRAY_LEGACY 0xe8
25
26#define CMD_READ_STATUS 0x05
27#define CMD_WRITE_ENABLE 0x06
28
Dan Ehrenberga5aac762015-01-08 10:29:19 -080029#define CMD_BLOCK_ERASE 0xD8
30
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070031/* Common status */
32#define STATUS_WIP 0x01
33
34/* Send a single-byte command to the device and read the response */
35int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len);
36
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070037int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
38 size_t len, void *data);
39
40int spi_flash_cmd_read_slow(struct spi_flash *flash, u32 offset,
41 size_t len, void *data);
42
43/*
44 * Send a multi-byte command to the device followed by (optional)
45 * data. Used for programming the flash array, etc.
46 */
47int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len,
48 const void *data, size_t data_len);
49
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070050/* Send a command to the device and wait for some bit to clear itself. */
51int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
52 u8 cmd, u8 poll_bit);
53
54/*
55 * Send the read status command to the device and wait for the wip
56 * (write-in-progress) bit to clear itself.
57 */
58int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout);
59
60/* Erase sectors. */
Dan Ehrenberga5aac762015-01-08 10:29:19 -080061int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len);
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070062
Duncan Lauriefb032392015-01-15 15:28:46 -080063/* Read status register. */
64int spi_flash_cmd_status(struct spi_flash *flash, u8 *reg);
65
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070066/* Manufacturer-specific probe functions */
67struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode);
Idwer Vollering73a10182014-02-16 00:32:13 +000068struct spi_flash *spi_flash_probe_amic(struct spi_slave *spi, u8 *idcode);
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070069struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode);
70struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode);
71struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode);
72struct spi_flash *spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode);
73struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 *idcode);
74struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode);
Martin Rothbceaf7f2012-09-07 15:02:35 -060075struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi,
76 u8 *idcode);
Chris Douglassb34739b2014-02-14 13:51:26 -050077struct spi_flash *spi_flash_probe_adesto(struct spi_slave *spi, u8 *idcode);
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070078struct spi_flash *spi_fram_probe_ramtron(struct spi_slave *spi, u8 *idcode);
Edward O'Callaghanc4561e22014-06-26 15:02:40 +100079
80#endif /* SPI_FLASH_INTERNAL_H */