spi_flash.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /**
  20. * struct spi_flash - SPI flash structure
  21. *
  22. * @spi: SPI slave
  23. * @name: Name of SPI flash
  24. * @size: Total flash size
  25. * @page_size: Write (page) size
  26. * @sector_size: Sector size
  27. * @erase_size: Erase size
  28. * @bank_read_cmd: Bank read cmd
  29. * @bank_write_cmd: Bank write cmd
  30. * @bank_curr: Current flash bank
  31. * @poll_cmd: Poll cmd - for flash erase/program
  32. * @erase_cmd: Erase cmd 4K, 32K, 64K
  33. * @memory_map: Address of read-only SPI flash access
  34. * @read: Flash read ops: Read len bytes at offset into buf
  35. * Supported cmds: Fast Array Read
  36. * @write: Flash write ops: Write len bytes from buf into offeset
  37. * Supported cmds: Page Program
  38. * @erase: Flash erase ops: Erase len bytes from offset
  39. * Supported cmds: Sector erase 4K, 32K, 64K
  40. * return 0 - Sucess, 1 - Failure
  41. */
  42. struct spi_flash {
  43. struct spi_slave *spi;
  44. const char *name;
  45. u32 size;
  46. u32 page_size;
  47. u32 sector_size;
  48. u32 erase_size;
  49. #ifdef CONFIG_SPI_FLASH_BAR
  50. u8 bank_read_cmd;
  51. u8 bank_write_cmd;
  52. u8 bank_curr;
  53. #endif
  54. u8 poll_cmd;
  55. u8 erase_cmd;
  56. void *memory_map;
  57. int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
  58. int (*write)(struct spi_flash *flash, u32 offset, size_t len,
  59. const void *buf);
  60. int (*erase)(struct spi_flash *flash, u32 offset, size_t len);
  61. };
  62. struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
  63. unsigned int max_hz, unsigned int spi_mode);
  64. void spi_flash_free(struct spi_flash *flash);
  65. static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
  66. size_t len, void *buf)
  67. {
  68. return flash->read(flash, offset, len, buf);
  69. }
  70. static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
  71. size_t len, const void *buf)
  72. {
  73. return flash->write(flash, offset, len, buf);
  74. }
  75. static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
  76. size_t len)
  77. {
  78. return flash->erase(flash, offset, len);
  79. }
  80. void spi_boot(void) __noreturn;
  81. #endif /* _SPI_FLASH_H_ */