blob: afc3a5809eac7ee4b1f31dda895f02042bc322fa [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 Tekif000ad02013-09-28 18:10:43 +053022/**
23 * struct spi_flash - SPI flash structure
24 *
25 * @spi: SPI slave
26 * @name: Name of SPI flash
27 * @size: Total flash size
28 * @page_size: Write (page) size
29 * @sector_size: Sector size
Jagannadha Sutradharudu Tekif3b2dd82013-10-07 19:34:56 +053030 * @erase_size: Erase size
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053031 * @bank_read_cmd: Bank read cmd
32 * @bank_write_cmd: Bank write cmd
33 * @bank_curr: Current flash bank
34 * @poll_cmd: Poll cmd - for flash erase/program
35 * @erase_cmd: Erase cmd 4K, 32K, 64K
Jagannadha Sutradharudu Tekif3b2dd82013-10-07 19:34:56 +053036 * @memory_map: Address of read-only SPI flash access
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053037 * @read: Flash read ops: Read len bytes at offset into buf
38 * Supported cmds: Fast Array Read
39 * @write: Flash write ops: Write len bytes from buf into offeset
40 * Supported cmds: Page Program
41 * @erase: Flash erase ops: Erase len bytes from offset
42 * Supported cmds: Sector erase 4K, 32K, 64K
43 * return 0 - Sucess, 1 - Failure
44 */
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +020045struct spi_flash {
46 struct spi_slave *spi;
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053047 const char *name;
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +020048
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053049 u32 size;
50 u32 page_size;
51 u32 sector_size;
52 u32 erase_size;
Jagannadha Sutradharudu Tekic6d173d2013-06-19 15:33:58 +053053#ifdef CONFIG_SPI_FLASH_BAR
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053054 u8 bank_read_cmd;
55 u8 bank_write_cmd;
56 u8 bank_curr;
Jagannadha Sutradharudu Tekic6d173d2013-06-19 15:33:58 +053057#endif
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053058 u8 poll_cmd;
59 u8 erase_cmd;
Jagannadha Sutradharudu Teki750f3ac2013-06-21 15:56:30 +053060
Jagannadha Sutradharudu Tekif000ad02013-09-28 18:10:43 +053061 void *memory_map;
62 int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
63 int (*write)(struct spi_flash *flash, u32 offset, size_t len,
64 const void *buf);
65 int (*erase)(struct spi_flash *flash, u32 offset, size_t len);
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +020066};
67
68struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
69 unsigned int max_hz, unsigned int spi_mode);
Simon Glass49e9d2c2013-12-03 16:43:24 -070070
71/**
72 * Set up a new SPI flash from an fdt node
73 *
74 * @param blob Device tree blob
75 * @param slave_node Pointer to this SPI slave node in the device tree
76 * @param spi_node Cached pointer to the SPI interface this node belongs
77 * to
78 * @return 0 if ok, -1 on error
79 */
80struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
81 int spi_node);
82
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +020083void spi_flash_free(struct spi_flash *flash);
84
85static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
86 size_t len, void *buf)
87{
88 return flash->read(flash, offset, len, buf);
89}
90
91static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
92 size_t len, const void *buf)
93{
94 return flash->write(flash, offset, len, buf);
95}
96
97static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
98 size_t len)
99{
100 return flash->erase(flash, offset, len);
101}
102
Christian Riesch23f16a82011-12-09 09:47:35 +0000103void spi_boot(void) __noreturn;
104
Haavard Skinnemoen2f5bfb72008-05-16 11:10:33 +0200105#endif /* _SPI_FLASH_H_ */