Debian Codegraph @

src/driver/spi/spi_flash.h

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /**
3 ******************************************************************************
4 * @file spi_flash.h
5 * @author StarFive Technology
6 * @version V1.0
7 * @date 07/24/2020
8 * @brief
9 ******************************************************************************
10 * @copy
11 *
12 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 * TIME. AS A RESULT, STARFIVE SHALL NOT BE HELD LIABLE FOR ANY
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 * FROM THE CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 *
19 * COPYRIGHT 2020 Shanghai StarFive Technology Co., Ltd.
20 */
21
22 #ifndef _SPI_FLASH_H_
23 #define _SPI_FLASH_H_
24
25 #include <comdef.h>
26
27
28 //#define SPI_1LINE
29
30 struct spi_flash_params {
31 const char *name;
32 u32 id;
33 /* Log2 of page size in power-of-two mode */
34 u8 l2_page_size;
35 u16 pages_per_sector;
36 u16 sectors_per_block;
37 u16 nr_blocks;
38 int flags;
39 };
40
41 struct spi_flash
42 {
43 struct spi_slave *spi;
44 //void *regs;
45 const char *name;
46 u32 size; /* Total flash size */
47 u32 page_size; /* Write (page) size */
48 u32 sector_size; /* Erase (sector) size */
49 u32 block_size; /* Erase (sector) size */
50 int (*read )(struct spi_flash *flash, u32 offset,u32 len, void *data, u32 mode);
51 int (*write)(struct spi_flash *flash, u32 offset,u32 len, void *data, u32 mode);
52 int (*erase)(struct spi_flash *flash, u32 offset,u32 len, u32 mode);
53 };
54
55 /*---------------------------------------------------
56 * spi_flash_probe:
57 * This function initialize module hardware and some software structures ,
58 * setup slave and read id codes , search the table and call probe
59 *
60 * spi_flash_probe() interface:
61 * bus: passed to the spi_setup_slave()
62 * cs: idem
63 * max_hz: idem
64 * spi_mode: idem
65 * bus_width: idem
66 *
67 * Returns: return NULL is error , if right return a struct contaims some information
68 */
69 struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
70 unsigned int max_hz, u32 mode, u32 fifo_width);
71
72
73 static /*inline*/ int spi_flash_read(struct spi_flash *flash, u32 offset,
74 u32 len, void *buf, u32 mode)
75 {
76 return flash->read(flash, offset, len, buf, mode);
77 }
78
79 static /*inline*/ int spi_flash_write(struct spi_flash *flash, u32 offset,
80 u32 len, void *buf, u32 mode)
81 {
82 return flash->write(flash, offset, len, buf, mode);
83 }
84
85 static /*inline*/ int spi_flash_erase(struct spi_flash *flash, u32 offset,
86 u32 len, u32 mode)
87 {
88 return flash->erase(flash, offset, len, mode);
89 }
90
91
92 #endif /* _SPI_FLASH_H_ */