spi_flash.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Common SPI flash Interface
  3. *
  4. * Copyright (C) 2008 Atmel Corporation
  5. * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * version 2 as published by the Free Software Foundation.
  13. */
  14. #ifndef _SPI_FLASH_H_
  15. #define _SPI_FLASH_H_
  16. #include <spi.h>
  17. #include <linux/types.h>
  18. #include <linux/compiler.h>
  19. /* No enum list for write commands only QPP */
  20. #define WR_QPP 1 << 4
  21. /* Enum list - Full read commands */
  22. enum spi_read_cmds {
  23. ARRAY_SLOW = 1 << 0,
  24. DUAL_OUTPUT_FAST = 1 << 1,
  25. DUAL_IO_FAST = 1 << 2,
  26. QUAD_OUTPUT_FAST = 1 << 3,
  27. QUAD_IO_FAST = 1 << 4,
  28. };
  29. #define RD_EXTN ARRAY_SLOW | DUAL_OUTPUT_FAST | DUAL_IO_FAST
  30. #define RD_FULL RD_EXTN | QUAD_OUTPUT_FAST | QUAD_IO_FAST
  31. /**
  32. * struct spi_flash_params - SPI/QSPI flash device params structure
  33. *
  34. * @name: Device name ([MANUFLETTER][DEVTYPE][DENSITY][EXTRAINFO])
  35. * @jedec: Device jedec ID (0x[1byte_manuf_id][2byte_dev_id])
  36. * @ext_jedec: Device ext_jedec ID
  37. * @sector_size: Sector size of this device
  38. * @nr_sectors: No.of sectors on this device
  39. * @e_rd_cmd: Enum list for read commands
  40. * @flags: Importent param, for flash specific behaviour
  41. */
  42. struct spi_flash_params {
  43. const char *name;
  44. u32 jedec;
  45. u16 ext_jedec;
  46. u32 sector_size;
  47. u32 nr_sectors;
  48. u8 e_rd_cmd;
  49. u16 flags;
  50. };
  51. extern const struct spi_flash_params spi_flash_params_table[];
  52. /**
  53. * struct spi_flash - SPI flash structure
  54. *
  55. * @spi: SPI slave
  56. * @name: Name of SPI flash
  57. * @size: Total flash size
  58. * @page_size: Write (page) size
  59. * @sector_size: Sector size
  60. * @erase_size: Erase size
  61. * @bank_read_cmd: Bank read cmd
  62. * @bank_write_cmd: Bank write cmd
  63. * @bank_curr: Current flash bank
  64. * @poll_cmd: Poll cmd - for flash erase/program
  65. * @erase_cmd: Erase cmd 4K, 32K, 64K
  66. * @read_cmd: Read cmd - Array Fast, Extn read and quad read.
  67. * @write_cmd: Write cmd - page and quad program.
  68. * @dummy_byte: Dummy cycles for read operation.
  69. * @memory_map: Address of read-only SPI flash access
  70. * @read: Flash read ops: Read len bytes at offset into buf
  71. * Supported cmds: Fast Array Read
  72. * @write: Flash write ops: Write len bytes from buf into offeset
  73. * Supported cmds: Page Program
  74. * @erase: Flash erase ops: Erase len bytes from offset
  75. * Supported cmds: Sector erase 4K, 32K, 64K
  76. * return 0 - Sucess, 1 - Failure
  77. */
  78. struct spi_flash {
  79. struct spi_slave *spi;
  80. const char *name;
  81. u32 size;
  82. u32 page_size;
  83. u32 sector_size;
  84. u32 erase_size;
  85. #ifdef CONFIG_SPI_FLASH_BAR
  86. u8 bank_read_cmd;
  87. u8 bank_write_cmd;
  88. u8 bank_curr;
  89. #endif
  90. u8 poll_cmd;
  91. u8 erase_cmd;
  92. u8 read_cmd;
  93. u8 write_cmd;
  94. u8 dummy_byte;
  95. void *memory_map;
  96. int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
  97. int (*write)(struct spi_flash *flash, u32 offset, size_t len,
  98. const void *buf);
  99. int (*erase)(struct spi_flash *flash, u32 offset, size_t len);
  100. };
  101. struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
  102. unsigned int max_hz, unsigned int spi_mode);
  103. /**
  104. * Set up a new SPI flash from an fdt node
  105. *
  106. * @param blob Device tree blob
  107. * @param slave_node Pointer to this SPI slave node in the device tree
  108. * @param spi_node Cached pointer to the SPI interface this node belongs
  109. * to
  110. * @return 0 if ok, -1 on error
  111. */
  112. struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
  113. int spi_node);
  114. void spi_flash_free(struct spi_flash *flash);
  115. static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
  116. size_t len, void *buf)
  117. {
  118. return flash->read(flash, offset, len, buf);
  119. }
  120. static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
  121. size_t len, const void *buf)
  122. {
  123. return flash->write(flash, offset, len, buf);
  124. }
  125. static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
  126. size_t len)
  127. {
  128. return flash->erase(flash, offset, len);
  129. }
  130. void spi_boot(void) __noreturn;
  131. #endif /* _SPI_FLASH_H_ */