spi_flash.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 06/25/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. #ifndef _SPI_FLASH_H_
  22. #define _SPI_FLASH_H_
  23. #include <comdef.h>
  24. //#define SPI_1LINE
  25. struct spi_flash_params {
  26. const char *name;
  27. u32 id;
  28. /* Log2 of page size in power-of-two mode */
  29. u8 l2_page_size;
  30. u16 pages_per_sector;
  31. u16 sectors_per_block;
  32. u16 nr_blocks;
  33. int flags;
  34. };
  35. struct spi_flash
  36. {
  37. struct spi_slave *spi;
  38. //void *regs;
  39. const char *name;
  40. u32 size; /* Total flash size */
  41. u32 page_size; /* Write (page) size */
  42. u32 sector_size; /* Erase (sector) size */
  43. u32 block_size; /* Erase (sector) size */
  44. int (*read )(struct spi_flash *flash, u32 offset,u32 len, void *data, u32 mode);
  45. int (*write)(struct spi_flash *flash, u32 offset,u32 len, void *data, u32 mode);
  46. int (*erase)(struct spi_flash *flash, u32 offset,u32 len, u32 mode);
  47. };
  48. /*---------------------------------------------------
  49. * spi_flash_probe:
  50. * This function initialize module hardware and some software structures ,
  51. * setup slave and read id codes , search the table and call probe
  52. *
  53. * spi_flash_probe() interface:
  54. * bus: passed to the spi_setup_slave()
  55. * cs: idem
  56. * max_hz: idem
  57. * spi_mode: idem
  58. * bus_width: idem
  59. *
  60. * Returns: return NULL is error , if right return a struct contaims some information
  61. */
  62. struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
  63. unsigned int max_hz, u32 mode, u32 fifo_width);
  64. static /*inline*/ int spi_flash_read(struct spi_flash *flash, u32 offset,
  65. u32 len, void *buf, u32 mode)
  66. {
  67. return flash->read(flash, offset, len, buf, mode);
  68. }
  69. static /*inline*/ int spi_flash_write(struct spi_flash *flash, u32 offset,
  70. u32 len, void *buf, u32 mode)
  71. {
  72. return flash->write(flash, offset, len, buf, mode);
  73. }
  74. static /*inline*/ int spi_flash_erase(struct spi_flash *flash, u32 offset,
  75. u32 len, u32 mode)
  76. {
  77. return flash->erase(flash, offset, len, mode);
  78. }
  79. #endif /* _SPI_FLASH_H_ */