blob: 99724a0d3ef35640bccde7fe8116d5781944ec3a [file] [log] [blame]
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +02001/*
Jagannadha Sutradharudu Teki25dc86a2013-10-02 19:38:49 +05302 * Common SPI flash Interface
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +02003 *
4 * Copyright (C) 2008 Atmel Corporation
Jagannadha Sutradharudu Teki25dc86a2013-10-02 19:38:49 +05305 * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc.
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +02006 *
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
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +020012 * version 2 as published by the Free Software Foundation.
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +020013 */
Jagannadha Sutradharudu Teki25dc86a2013-10-02 19:38:49 +053014
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +020015#ifndef _SPI_FLASH_H_
16#define _SPI_FLASH_H_
17
18#include <spi.h>
Mike Frysingere4c698b2009-11-03 11:36:39 -050019#include <linux/types.h>
Christian Riesch23f16a82011-12-09 09:47:35 +000020#include <linux/compiler.h>
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +020021
Jagannadha Sutradharudu Tekie0ebabc2014-01-11 15:13:11 +053022/* No enum list for write commands only QPP */
23#define WR_QPP 1 << 4
24
25/* Enum list - Full read commands */
Jagannadha Sutradharudu Teki02eee9a2014-01-11 15:10:28 +053026enum spi_read_cmds {
27 ARRAY_SLOW = 1 << 0,
28 DUAL_OUTPUT_FAST = 1 << 1,
29 DUAL_IO_FAST = 1 << 2,
Jagannadha Sutradharudu Tekie0ebabc2014-01-11 15:13:11 +053030 QUAD_OUTPUT_FAST = 1 << 3,
Jagannadha Sutradharudu Teki45462302013-12-24 15:24:31 +053031 QUAD_IO_FAST = 1 << 4,
Jagannadha Sutradharudu Teki02eee9a2014-01-11 15:10:28 +053032};
33#define RD_EXTN ARRAY_SLOW | DUAL_OUTPUT_FAST | DUAL_IO_FAST
Jagannadha Sutradharudu Teki45462302013-12-24 15:24:31 +053034#define RD_FULL RD_EXTN | QUAD_OUTPUT_FAST | QUAD_IO_FAST
Jagannadha Sutradharudu Teki02eee9a2014-01-11 15:10:28 +053035
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053036/**
Jagannadha Sutradharudu Teki20e45bc2013-12-23 23:34:42 +053037 * struct spi_flash_params - SPI/QSPI flash device params structure
38 *
39 * @name: Device name ([MANUFLETTER][DEVTYPE][DENSITY][EXTRAINFO])
40 * @jedec: Device jedec ID (0x[1byte_manuf_id][2byte_dev_id])
41 * @ext_jedec: Device ext_jedec ID
42 * @sector_size: Sector size of this device
43 * @nr_sectors: No.of sectors on this device
44 * @e_rd_cmd: Enum list for read commands
45 * @flags: Importent param, for flash specific behaviour
46 */
47struct spi_flash_params {
48 const char *name;
49 u32 jedec;
50 u16 ext_jedec;
51 u32 sector_size;
52 u32 nr_sectors;
53 u8 e_rd_cmd;
54 u16 flags;
55};
56
57extern const struct spi_flash_params spi_flash_params_table[];
58
59/**
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053060 * struct spi_flash - SPI flash structure
61 *
62 * @spi: SPI slave
63 * @name: Name of SPI flash
64 * @size: Total flash size
65 * @page_size: Write (page) size
66 * @sector_size: Sector size
Jagannadha Sutradharudu Tekif3b2dd82013-10-07 19:34:56 +053067 * @erase_size: Erase size
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053068 * @bank_read_cmd: Bank read cmd
69 * @bank_write_cmd: Bank write cmd
70 * @bank_curr: Current flash bank
71 * @poll_cmd: Poll cmd - for flash erase/program
72 * @erase_cmd: Erase cmd 4K, 32K, 64K
Jagannadha Sutradharudu Tekie0ebabc2014-01-11 15:13:11 +053073 * @read_cmd: Read cmd - Array Fast, Extn read and quad read.
74 * @write_cmd: Write cmd - page and quad program.
Jagannadha Sutradharudu Tekif3b2dd82013-10-07 19:34:56 +053075 * @memory_map: Address of read-only SPI flash access
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053076 * @read: Flash read ops: Read len bytes at offset into buf
77 * Supported cmds: Fast Array Read
78 * @write: Flash write ops: Write len bytes from buf into offeset
79 * Supported cmds: Page Program
80 * @erase: Flash erase ops: Erase len bytes from offset
81 * Supported cmds: Sector erase 4K, 32K, 64K
82 * return 0 - Sucess, 1 - Failure
83 */
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +020084struct spi_flash {
85 struct spi_slave *spi;
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053086 const char *name;
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +020087
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053088 u32 size;
89 u32 page_size;
90 u32 sector_size;
91 u32 erase_size;
Jagannadha Sutradharudu Tekic6d173d2013-06-19 15:33:58 +053092#ifdef CONFIG_SPI_FLASH_BAR
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053093 u8 bank_read_cmd;
94 u8 bank_write_cmd;
95 u8 bank_curr;
Jagannadha Sutradharudu Tekic6d173d2013-06-19 15:33:58 +053096#endif
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053097 u8 poll_cmd;
98 u8 erase_cmd;
Jagannadha Sutradharudu Teki02eee9a2014-01-11 15:10:28 +053099 u8 read_cmd;
Jagannadha Sutradharudu Tekie0ebabc2014-01-11 15:13:11 +0530100 u8 write_cmd;
Jagannadha Sutradharudu Teki750f3ac2013-06-21 15:56:30 +0530101
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +0530102 void *memory_map;
103 int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
104 int (*write)(struct spi_flash *flash, u32 offset, size_t len,
105 const void *buf);
106 int (*erase)(struct spi_flash *flash, u32 offset, size_t len);
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +0200107};
108
109struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
110 unsigned int max_hz, unsigned int spi_mode);
Simon Glass49e9d2c2013-12-03 16:43:24 -0700111
112/**
113 * Set up a new SPI flash from an fdt node
114 *
115 * @param blob Device tree blob
116 * @param slave_node Pointer to this SPI slave node in the device tree
117 * @param spi_node Cached pointer to the SPI interface this node belongs
118 * to
119 * @return 0 if ok, -1 on error
120 */
121struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
122 int spi_node);
123
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +0200124void spi_flash_free(struct spi_flash *flash);
125
126static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
127 size_t len, void *buf)
128{
129 return flash->read(flash, offset, len, buf);
130}
131
132static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
133 size_t len, const void *buf)
134{
135 return flash->write(flash, offset, len, buf);
136}
137
138static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
139 size_t len)
140{
141 return flash->erase(flash, offset, len);
142}
143
Christian Riesch23f16a82011-12-09 09:47:35 +0000144void spi_boot(void) __noreturn;
145
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +0200146#endif /* _SPI_FLASH_H_ */