spi_flash.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef _SPI_FLASH_H_
  2. #define _SPI_FLASH_H_
  3. #include <comdef.h>
  4. //#define SPI_1LINE
  5. struct spi_flash_params {
  6. const char *name;
  7. u32 id;
  8. /* Log2 of page size in power-of-two mode */
  9. u8 l2_page_size;
  10. u16 pages_per_sector;
  11. u16 sectors_per_block;
  12. u16 nr_blocks;
  13. int flags;
  14. };
  15. struct spi_flash
  16. {
  17. struct spi_slave *spi;
  18. //void *regs;
  19. const char *name;
  20. u32 size; /* Total flash size */
  21. u32 page_size; /* Write (page) size */
  22. u32 sector_size; /* Erase (sector) size */
  23. u32 block_size; /* Erase (sector) size */
  24. int (*read )(struct spi_flash *flash, u32 offset,u32 len, void *data, u32 mode);
  25. int (*write)(struct spi_flash *flash, u32 offset,u32 len, void *data, u32 mode);
  26. int (*erase)(struct spi_flash *flash, u32 offset,u32 len, u32 mode);
  27. };
  28. /*---------------------------------------------------
  29. * spi_flash_probe:
  30. * This function initialize module hardware and some software structures ,
  31. * setup slave and read id codes , search the table and call probe
  32. *
  33. * spi_flash_probe() interface:
  34. * bus: passed to the spi_setup_slave()
  35. * cs: idem
  36. * max_hz: idem
  37. * spi_mode: idem
  38. * bus_width: idem
  39. *
  40. * Returns: return NULL is error , if right return a struct contaims some information
  41. */
  42. struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
  43. unsigned int max_hz, u32 mode, u32 fifo_width);
  44. static /*inline*/ int spi_flash_read(struct spi_flash *flash, u32 offset,
  45. u32 len, void *buf, u32 mode)
  46. {
  47. return flash->read(flash, offset, len, buf, mode);
  48. }
  49. static /*inline*/ int spi_flash_write(struct spi_flash *flash, u32 offset,
  50. u32 len, void *buf, u32 mode)
  51. {
  52. return flash->write(flash, offset, len, buf, mode);
  53. }
  54. static /*inline*/ int spi_flash_erase(struct spi_flash *flash, u32 offset,
  55. u32 len, u32 mode)
  56. {
  57. return flash->erase(flash, offset, len, mode);
  58. }
  59. #endif /* _SPI_FLASH_H_ */