spiflash.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef __SPIFLASH_H__
  2. #define __SPIFLASH_H__
  3. #include "typedef.h"
  4. #include "generic/list.h"
  5. #include "generic/ioctl.h"
  6. #include "device/device.h"
  7. #include "system/task.h"
  8. struct spi_device;
  9. enum spiflash_bit_mode {
  10. SPI_2WIRE_MODE,
  11. SPI_ODD_MODE,
  12. SPI_DUAL_MODE,
  13. SPI_QUAD_MODE,
  14. };
  15. enum spiflash_read_mode {
  16. FAST_READ_OUTPUT_MODE,
  17. FAST_READ_IO_MODE,
  18. FAST_READ_IO_CONTINUOUS_READ_MODE,
  19. };
  20. enum sfc_run_mode {
  21. //1bit mode
  22. SFC_READ_DATA_MODE = (1 << 0),
  23. SFC_FAST_READ_MODE = (1 << 1),
  24. //2bit mode
  25. SFC_FAST_READ_DUAL_IO_NORMAL_READ_MODE = (1 << 2),
  26. SFC_FAST_READ_DUAL_IO_CONTINUOUS_READ_MODE = (1 << 3),
  27. SFC_FAST_READ_DUAL_OUTPUT_MODE = (1 << 4),
  28. //4bit mode
  29. SFC_FAST_READ_QUAD_IO_NORMAL_READ_MODE = (1 << 5),
  30. SFC_FAST_READ_QUAD_IO_CONTINUOUS_READ_MODE = (1 << 6),
  31. SFC_FAST_READ_QUAD_OUTPUT_MODE = (1 << 7),
  32. };
  33. struct spi_ops {
  34. int (*set_cs)(int);
  35. int (*init)(void *);
  36. u8(*read_byte)(int *err);
  37. int (*read)(u8 *, u32 len, u8 mode);
  38. int (*write_byte)(u8 cmd);
  39. int (*write_cmd)(u8 *cmd, u32 len);
  40. int (*write)(u8 *, u32 len);
  41. u8(*get_bit_mode)();
  42. };
  43. struct sf_info {
  44. u32 id;
  45. u16 page_size; //byte
  46. u16 block_size; //KByte
  47. u32 chip_size; //KByte
  48. };
  49. enum sf_erase_type {
  50. SF_SECTOR_ERASE,
  51. SF_BLOCK_ERASE,
  52. SF_CHIP_ERASE,
  53. };
  54. //struct sf_erase {
  55. //enum sf_erase_type type;
  56. //u32 addr;
  57. //};
  58. //struct sf_wp {
  59. //u8 enable;
  60. //u8 cmd;
  61. //};
  62. struct spi_device {
  63. const char *name;
  64. const struct spi_ops *ops;
  65. };
  66. struct spiflash_platform_data {
  67. const char *name;
  68. enum spiflash_read_mode mode;
  69. enum sfc_run_mode sfc_run_mode;
  70. void *private_data;
  71. };
  72. struct spiflash {
  73. struct list_head entry;
  74. void *device;
  75. struct device dev;
  76. struct sf_info info;
  77. const struct spiflash_platform_data *pd;
  78. const char *name;
  79. OS_MUTEX mutext;
  80. u8 inited;
  81. u8 read_mode;
  82. u8 read_cmd_mode;
  83. u8 write_cmd_mode;
  84. u8 continuous_read_mode;
  85. };
  86. #define REGISTER_SPIFLASH_DEVICE(dev) \
  87. static const struct spi_device dev sec(.spi_device)
  88. extern struct spi_device spi_device_begin[];
  89. extern struct spi_device spi_device_end[];
  90. extern struct spiflash *__get_spiflash(const char *name);
  91. #endif