]> git.ipfire.org Git - people/ms/u-boot.git/blame - include/spi_flash.h
sf: ops: Unify read_ops bank configuration
[people/ms/u-boot.git] / include / spi_flash.h
CommitLineData
d25ce7d2 1/*
a5e8199a 2 * Common SPI flash Interface
d25ce7d2
HS
3 *
4 * Copyright (C) 2008 Atmel Corporation
a5e8199a 5 * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc.
d25ce7d2
HS
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
3765b3e7 12 * version 2 as published by the Free Software Foundation.
d25ce7d2 13 */
a5e8199a 14
d25ce7d2
HS
15#ifndef _SPI_FLASH_H_
16#define _SPI_FLASH_H_
17
18#include <spi.h>
e06ab654 19#include <linux/types.h>
32b11273 20#include <linux/compiler.h>
d25ce7d2 21
2ba863fa
JT
22/* sf param flags */
23#define SECT_4K 1 << 1
24#define SECT_32K 1 << 2
25#define E_FSR 1 << 3
3163aaa6
JT
26#define WR_QPP 1 << 4
27
28/* Enum list - Full read commands */
4e09cc1e
JT
29enum spi_read_cmds {
30 ARRAY_SLOW = 1 << 0,
31 DUAL_OUTPUT_FAST = 1 << 1,
32 DUAL_IO_FAST = 1 << 2,
3163aaa6 33 QUAD_OUTPUT_FAST = 1 << 3,
c4ba0d82 34 QUAD_IO_FAST = 1 << 4,
4e09cc1e
JT
35};
36#define RD_EXTN ARRAY_SLOW | DUAL_OUTPUT_FAST | DUAL_IO_FAST
c4ba0d82 37#define RD_FULL RD_EXTN | QUAD_OUTPUT_FAST | QUAD_IO_FAST
4e09cc1e 38
33adfb5f
JT
39/**
40 * struct spi_flash_params - SPI/QSPI flash device params structure
41 *
42 * @name: Device name ([MANUFLETTER][DEVTYPE][DENSITY][EXTRAINFO])
43 * @jedec: Device jedec ID (0x[1byte_manuf_id][2byte_dev_id])
44 * @ext_jedec: Device ext_jedec ID
45 * @sector_size: Sector size of this device
46 * @nr_sectors: No.of sectors on this device
47 * @e_rd_cmd: Enum list for read commands
48 * @flags: Importent param, for flash specific behaviour
49 */
50struct spi_flash_params {
51 const char *name;
52 u32 jedec;
53 u16 ext_jedec;
54 u32 sector_size;
55 u32 nr_sectors;
56 u8 e_rd_cmd;
57 u16 flags;
58};
59
60extern const struct spi_flash_params spi_flash_params_table[];
61
7ab35d92
JT
62/**
63 * struct spi_flash - SPI flash structure
64 *
65 * @spi: SPI slave
66 * @name: Name of SPI flash
67 * @size: Total flash size
68 * @page_size: Write (page) size
69 * @sector_size: Sector size
ce22b922 70 * @erase_size: Erase size
7ab35d92
JT
71 * @bank_read_cmd: Bank read cmd
72 * @bank_write_cmd: Bank write cmd
73 * @bank_curr: Current flash bank
74 * @poll_cmd: Poll cmd - for flash erase/program
75 * @erase_cmd: Erase cmd 4K, 32K, 64K
3163aaa6
JT
76 * @read_cmd: Read cmd - Array Fast, Extn read and quad read.
77 * @write_cmd: Write cmd - page and quad program.
ff063ed4 78 * @dummy_byte: Dummy cycles for read operation.
ce22b922 79 * @memory_map: Address of read-only SPI flash access
7ab35d92
JT
80 * @read: Flash read ops: Read len bytes at offset into buf
81 * Supported cmds: Fast Array Read
82 * @write: Flash write ops: Write len bytes from buf into offeset
83 * Supported cmds: Page Program
84 * @erase: Flash erase ops: Erase len bytes from offset
85 * Supported cmds: Sector erase 4K, 32K, 64K
86 * return 0 - Sucess, 1 - Failure
87 */
d25ce7d2
HS
88struct spi_flash {
89 struct spi_slave *spi;
7ab35d92 90 const char *name;
d25ce7d2 91
7ab35d92
JT
92 u32 size;
93 u32 page_size;
94 u32 sector_size;
95 u32 erase_size;
1dcd6d03 96#ifdef CONFIG_SPI_FLASH_BAR
7ab35d92
JT
97 u8 bank_read_cmd;
98 u8 bank_write_cmd;
99 u8 bank_curr;
1dcd6d03 100#endif
7ab35d92
JT
101 u8 poll_cmd;
102 u8 erase_cmd;
4e09cc1e 103 u8 read_cmd;
3163aaa6 104 u8 write_cmd;
ff063ed4 105 u8 dummy_byte;
615a1561 106
7ab35d92
JT
107 void *memory_map;
108 int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
109 int (*write)(struct spi_flash *flash, u32 offset, size_t len,
110 const void *buf);
111 int (*erase)(struct spi_flash *flash, u32 offset, size_t len);
d25ce7d2
HS
112};
113
114struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
115 unsigned int max_hz, unsigned int spi_mode);
0efc0249
SG
116
117/**
118 * Set up a new SPI flash from an fdt node
119 *
120 * @param blob Device tree blob
121 * @param slave_node Pointer to this SPI slave node in the device tree
122 * @param spi_node Cached pointer to the SPI interface this node belongs
123 * to
124 * @return 0 if ok, -1 on error
125 */
126struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
127 int spi_node);
128
d25ce7d2
HS
129void spi_flash_free(struct spi_flash *flash);
130
131static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
132 size_t len, void *buf)
133{
134 return flash->read(flash, offset, len, buf);
135}
136
137static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
138 size_t len, const void *buf)
139{
140 return flash->write(flash, offset, len, buf);
141}
142
143static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
144 size_t len)
145{
146 return flash->erase(flash, offset, len);
147}
148
32b11273
CR
149void spi_boot(void) __noreturn;
150
d25ce7d2 151#endif /* _SPI_FLASH_H_ */