spi_flash.h 2.6 KB

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