Debian Codegraph @

src/driver/spi/spi_flash_internal.h

raw symbols SCIP
1 /*
2 * SPI flash internal definitions
3 *
4 * Copyright (C) 2008 Atmel Corporation
5 */
6
7 /* Common parameters -- kind of high, but they should only occur when there
8 * is a problem (and well your system already is broken), so err on the side
9 * of caution in case we're dealing with slower SPI buses and/or processors.
10 */
11 #ifndef __SPI_FLASH_INTERNAL_H_
12 #define __SPI_FLASH_INTERNAL_H_
13
14 #include <comdef.h>
15
16 #define CONFIG_SYS_HZ 12000000
17 #define SPI_FLASH_PROG_TIMEOUT (2 * CONFIG_SYS_HZ)
18 #define SPI_FLASH_PAGE_ERASE_TIMEOUT (5 * CONFIG_SYS_HZ)
19 #define SPI_FLASH_SECTOR_ERASE_TIMEOUT (10 * CONFIG_SYS_HZ)
20
21 /* Common commands */
22 #define CMD_READ_ARRAY_SLOW 0x03 /* Read Data Bytes */
23 #define CMD_READ_ARRAY_FAST 0x0B
24 #define CMD_READ_ARRAY_DUAL 0x3B
25 #define CMD_READ_ARRAY_QUAD 0X6B
26 #define CMD_READ_ARRAY_LEGACY 0xEB
27
28 #define CMD_WRITE_STATUS 0x01 /* Write Status Register */
29
30 #define CMD_WRITE_STATUS_1 0x01 /* Write Status Register */
31 #define CMD_WRITE_STATUS_2 0x31 /* Write Status Register */
32 #define CMD_WRITE_STATUS_3 0x11 /* Write Status Register */
33 #define CMD_READ_STATUS_1 0x05 /* Read Status Register */
34 #define CMD_READ_STATUS_2 0x35 /* Read Status Register */
35 #define CMD_READ_STATUS_3 0x15 /* Read Status Register */
36
37 #define CMD_PAGE_PROGRAM 0x02 /* Page Program */
38 #define CMD_PAGE_PROGRAM_QUAD 0x32
39 #define CMD_WRITE_DISABLE 0x04 /* Write Disable */
40 #define CMD_READ_STATUS 0x05 /* Read Status Register */
41 #define CMD_READ_STATUS1 0x35
42 #define CMD_WRITE_ENABLE 0x06 /* Write Enable */
43 #define CMD_W25_FAST_READ 0x0b /* Read Data Bytes at Higher Speed */
44 #define CMD_W25_SE 0x20 /* Sector (4K) Erase */
45 #define CMD_W25_BE 0xd8 /* Block (64K) Erase */
46 #define CMD_W25_CE 0xc7 /* Chip Erase */
47 #define CMD_W25_DP 0xb9 /* Deep Power-down */
48 #define CMD_W25_RES 0xab /* Release from DP, and Read Signature */
49 #define CMD_W25_BE_32 0x52 /* Sector (32K) Erase */
50 #define CMD_STATUS_ENABLE 0x50
51
52 /* Common status */
53 #define STATUS_WIP 0x01
54 #define FLASH_ENABLE 0x02
55 #define STATUS_QE (0x01 << 1)
56
57 /* Send a single-byte command to the device and read the response */
58 int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, u32 len);
59
60 /*
61 * Send a multi-byte command to the device and read the response. Used
62 * for flash array reads, etc.
63 */
64 int spi_flash_cmd_read(struct spi_slave *spi, u8 *cmd,u32 cmd_len,
65 void *data, u32 data_len);
66
67 int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
68 u32 len, void *data, u32 mode);
69
70 int spi_flash_read_mode(struct spi_flash *flash, u32 offset,
71 u32 len, void *data, u32 mode);
72
73 /*
74 * Send a multi-byte command to the device followed by (optional)
75 * data. Used for programming the flash array, etc.
76 */
77 int spi_flash_cmd_write(struct spi_slave *spi, u8 *cmd, u32 cmd_len,
78 void *data, u32 data_len);
79
80 /*
81 * Write the requested data out breaking it up into multiple write
82 * commands as needed per the write size.
83 */
84 int spi_flash_cmd_write_mode(struct spi_flash *flash, u32 offset,
85 u32 len, void *buf, u32 mode);
86
87 /*
88 * Enable writing on the SPI flash.
89 */
90 int spi_flash_cmd_write_enable(struct spi_flash *flash);
91
92 /*
93 * Disable writing on the SPI flash.
94 */
95 int spi_flash_cmd_write_disable(struct spi_slave *spi);
96
97 /*
98 * Same as spi_flash_cmd_read() except it also claims/releases the SPI
99 * bus. Used as common part of the ->read() operation.
100 */
101 int spi_flash_read_common(struct spi_flash *flash, u8 *cmd,
102 u32 cmd_len, void *data, u32 data_len);
103
104 /* Send a command to the device and wait for some bit to clear itself. */
105 int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
106 u8 cmd, u8 poll_bit);
107
108 /*
109 * Send the read status command to the device and wait for the wip
110 * (write-in-progress) bit to clear itself.
111 */
112 int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout);
113
114 /* Erase sectors. */
115 int spi_flash_cmd_erase(struct spi_flash *flash, u8 erase_cmd, u32 offset, u32 len);
116 int spi_flash_erase_mode(struct spi_flash *flash, u32 offset, u32 len, u32 mode);
117
118 /* Manufacturer-specific probe functions */
119 struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode);
120 struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode);
121 struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode);
122 struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode);
123 struct spi_flash *spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode);
124 struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 *idcode);
125 struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode);
126 struct spi_flash *spi_fram_probe_ramtron(struct spi_slave *spi, u8 *idcode);
127 struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode);
128 struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
129 unsigned int max_hz, u32 mode, u32 fifo_width);
130
131
132 #endif
133