Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * SPI flash internal definitions |
| 3 | * |
| 4 | * Copyright (C) 2008 Atmel Corporation |
| 5 | */ |
| 6 | |
Edward O'Callaghan | c4561e2 | 2014-06-26 15:02:40 +1000 | [diff] [blame] | 7 | #ifndef SPI_FLASH_INTERNAL_H |
| 8 | #define SPI_FLASH_INTERNAL_H |
| 9 | |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 10 | /* 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 Ehrenberg | a5aac76 | 2015-01-08 10:29:19 -0800 | [diff] [blame] | 29 | #define CMD_BLOCK_ERASE 0xD8 |
| 30 | |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 31 | /* Common status */ |
| 32 | #define STATUS_WIP 0x01 |
| 33 | |
| 34 | /* Send a single-byte command to the device and read the response */ |
| 35 | int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len); |
| 36 | |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 37 | int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset, |
| 38 | size_t len, void *data); |
| 39 | |
| 40 | int 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 | */ |
| 47 | int 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 Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 50 | /* Send a command to the device and wait for some bit to clear itself. */ |
| 51 | int 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 | */ |
| 58 | int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout); |
| 59 | |
| 60 | /* Erase sectors. */ |
Dan Ehrenberg | a5aac76 | 2015-01-08 10:29:19 -0800 | [diff] [blame] | 61 | int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len); |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 62 | |
Duncan Laurie | fb03239 | 2015-01-15 15:28:46 -0800 | [diff] [blame] | 63 | /* Read status register. */ |
| 64 | int spi_flash_cmd_status(struct spi_flash *flash, u8 *reg); |
| 65 | |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 66 | /* Manufacturer-specific probe functions */ |
| 67 | struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode); |
Idwer Vollering | 73a1018 | 2014-02-16 00:32:13 +0000 | [diff] [blame] | 68 | struct spi_flash *spi_flash_probe_amic(struct spi_slave *spi, u8 *idcode); |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 69 | struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode); |
| 70 | struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode); |
| 71 | struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode); |
| 72 | struct spi_flash *spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode); |
| 73 | struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 *idcode); |
| 74 | struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode); |
Martin Roth | bceaf7f | 2012-09-07 15:02:35 -0600 | [diff] [blame] | 75 | struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, |
| 76 | u8 *idcode); |
Chris Douglass | b34739b | 2014-02-14 13:51:26 -0500 | [diff] [blame] | 77 | struct spi_flash *spi_flash_probe_adesto(struct spi_slave *spi, u8 *idcode); |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 78 | struct spi_flash *spi_fram_probe_ramtron(struct spi_slave *spi, u8 *idcode); |
Edward O'Callaghan | c4561e2 | 2014-06-26 15:02:40 +1000 | [diff] [blame] | 79 | |
| 80 | #endif /* SPI_FLASH_INTERNAL_H */ |