]> git.ipfire.org Git - people/ms/u-boot.git/blame - include/spi_flash.h
spi: Use error return value in sf_ops
[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
e06ab654 18#include <linux/types.h>
d25ce7d2 19
88e34e5f
NK
20#ifndef CONFIG_SF_DEFAULT_SPEED
21# define CONFIG_SF_DEFAULT_SPEED 1000000
22#endif
23#ifndef CONFIG_SF_DEFAULT_MODE
24# define CONFIG_SF_DEFAULT_MODE SPI_MODE_3
25#endif
26#ifndef CONFIG_SF_DEFAULT_CS
27# define CONFIG_SF_DEFAULT_CS 0
28#endif
29#ifndef CONFIG_SF_DEFAULT_BUS
30# define CONFIG_SF_DEFAULT_BUS 0
31#endif
32
ff0960f9 33struct spi_slave;
33adfb5f 34
7ab35d92
JT
35/**
36 * struct spi_flash - SPI flash structure
37 *
38 * @spi: SPI slave
39 * @name: Name of SPI flash
ff0960f9 40 * @dual_flash: Indicates dual flash memories - dual stacked, parallel
056fbc73 41 * @shift: Flash shift useful in dual parallel
7ab35d92
JT
42 * @size: Total flash size
43 * @page_size: Write (page) size
44 * @sector_size: Sector size
ff0960f9 45 * @erase_size: Erase size
7ab35d92
JT
46 * @bank_read_cmd: Bank read cmd
47 * @bank_write_cmd: Bank write cmd
48 * @bank_curr: Current flash bank
49 * @poll_cmd: Poll cmd - for flash erase/program
50 * @erase_cmd: Erase cmd 4K, 32K, 64K
3163aaa6
JT
51 * @read_cmd: Read cmd - Array Fast, Extn read and quad read.
52 * @write_cmd: Write cmd - page and quad program.
ff0960f9
SG
53 * @dummy_byte: Dummy cycles for read operation.
54 * @memory_map: Address of read-only SPI flash access
7ab35d92
JT
55 * @read: Flash read ops: Read len bytes at offset into buf
56 * Supported cmds: Fast Array Read
801cec59 57 * @write: Flash write ops: Write len bytes from buf into offset
7ab35d92
JT
58 * Supported cmds: Page Program
59 * @erase: Flash erase ops: Erase len bytes from offset
60 * Supported cmds: Sector erase 4K, 32K, 64K
801cec59 61 * return 0 - Success, 1 - Failure
7ab35d92 62 */
d25ce7d2
HS
63struct spi_flash {
64 struct spi_slave *spi;
7ab35d92 65 const char *name;
f77f4691 66 u8 dual_flash;
056fbc73 67 u8 shift;
d25ce7d2 68
7ab35d92
JT
69 u32 size;
70 u32 page_size;
71 u32 sector_size;
72 u32 erase_size;
1dcd6d03 73#ifdef CONFIG_SPI_FLASH_BAR
7ab35d92
JT
74 u8 bank_read_cmd;
75 u8 bank_write_cmd;
76 u8 bank_curr;
1dcd6d03 77#endif
7ab35d92
JT
78 u8 poll_cmd;
79 u8 erase_cmd;
4e09cc1e 80 u8 read_cmd;
3163aaa6 81 u8 write_cmd;
ff063ed4 82 u8 dummy_byte;
615a1561 83
7ab35d92
JT
84 void *memory_map;
85 int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
86 int (*write)(struct spi_flash *flash, u32 offset, size_t len,
87 const void *buf);
88 int (*erase)(struct spi_flash *flash, u32 offset, size_t len);
d25ce7d2
HS
89};
90
91struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
92 unsigned int max_hz, unsigned int spi_mode);
0efc0249
SG
93
94/**
95 * Set up a new SPI flash from an fdt node
96 *
97 * @param blob Device tree blob
98 * @param slave_node Pointer to this SPI slave node in the device tree
99 * @param spi_node Cached pointer to the SPI interface this node belongs
100 * to
101 * @return 0 if ok, -1 on error
102 */
103struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
104 int spi_node);
105
d25ce7d2
HS
106void spi_flash_free(struct spi_flash *flash);
107
108static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
109 size_t len, void *buf)
110{
111 return flash->read(flash, offset, len, buf);
112}
113
114static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
115 size_t len, const void *buf)
116{
117 return flash->write(flash, offset, len, buf);
118}
119
120static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
121 size_t len)
122{
123 return flash->erase(flash, offset, len);
124}
125
32b11273 126void spi_boot(void) __noreturn;
1eaa742d 127void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst);
32b11273 128
d25ce7d2 129#endif /* _SPI_FLASH_H_ */