rtl838x-spi.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2009 Realtek Semiconductor Corp.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #ifndef _RTL838X_SPI_H
  17. #define _RTL838X_SPI_H
  18. /*
  19. * Register access macros
  20. */
  21. #define spi_r32(reg) readl(rtl838x_nor->base + reg)
  22. #define spi_w32(val, reg) writel(val, rtl838x_nor->base + reg)
  23. #define spi_w32_mask(clear, set, reg) \
  24. spi_w32((spi_r32(reg) & ~(clear)) | (set), reg)
  25. #define SPI_WAIT_READY do { \
  26. } while (!(spi_r32(SFCSR) & SFCSR_SPI_RDY))
  27. #define spi_w32w(val, reg) do { \
  28. writel(val, rtl838x_nor->base + reg); \
  29. SPI_WAIT_READY; \
  30. } while (0)
  31. #define SFCR (0x00) /*SPI Flash Configuration Register*/
  32. #define SFCR_CLK_DIV(val) ((val)<<29)
  33. #define SFCR_EnableRBO (1<<28)
  34. #define SFCR_EnableWBO (1<<27)
  35. #define SFCR_SPI_TCS(val) ((val)<<23) /*4 bit, 1111 */
  36. #define SFCR2 (0x04) /*For memory mapped I/O */
  37. #define SFCR2_SFCMD(val) ((val)<<24) /*8 bit, 1111_1111 */
  38. #define SFCR2_SIZE(val) ((val)<<21) /*3 bit, 111 */
  39. #define SFCR2_RDOPT (1<<20)
  40. #define SFCR2_CMDIO(val) ((val)<<18) /*2 bit, 11 */
  41. #define SFCR2_ADDRIO(val) ((val)<<16) /*2 bit, 11 */
  42. #define SFCR2_DUMMYCYCLE(val) ((val)<<13) /*3 bit, 111 */
  43. #define SFCR2_DATAIO(val) ((val)<<11) /*2 bit, 11 */
  44. #define SFCR2_HOLD_TILL_SFDR2 (1<<10)
  45. #define SFCR2_GETSIZE(x) (((x)&0x00E00000)>>21)
  46. #define SFCSR (0x08) /*SPI Flash Control&Status Register*/
  47. #define SFCSR_SPI_CSB0 (1<<31)
  48. #define SFCSR_SPI_CSB1 (1<<30)
  49. #define SFCSR_LEN(val) ((val)<<28) /*2 bits*/
  50. #define SFCSR_SPI_RDY (1<<27)
  51. #define SFCSR_IO_WIDTH(val) ((val)<<25) /*2 bits*/
  52. #define SFCSR_CHIP_SEL (1<<24)
  53. #define SFCSR_CMD_BYTE(val) ((val)<<16) /*8 bit, 1111_1111 */
  54. #define SFDR (0x0C) /*SPI Flash Data Register*/
  55. #define SFDR2 (0x10) /*SPI Flash Data Register - for post SPI bootup setting*/
  56. #define SPI_CS_INIT (SFCSR_SPI_CSB0 | SFCSR_SPI_CSB1 | SPI_LEN1)
  57. #define SPI_CS0 SFCSR_SPI_CSB0
  58. #define SPI_CS1 SFCSR_SPI_CSB1
  59. #define SPI_eCS0 ((SFCSR_SPI_CSB1)) /*and SFCSR to active CS0*/
  60. #define SPI_eCS1 ((SFCSR_SPI_CSB0)) /*and SFCSR to active CS1*/
  61. #define SPI_WIP (1) /* Write In Progress */
  62. #define SPI_WEL (1<<1) /* Write Enable Latch*/
  63. #define SPI_SST_QIO_WIP (1<<7) /* SST QIO Flash Write In Progress */
  64. #define SPI_LEN_INIT 0xCFFFFFFF /* and SFCSR to init */
  65. #define SPI_LEN4 0x30000000 /* or SFCSR to set */
  66. #define SPI_LEN3 0x20000000 /* or SFCSR to set */
  67. #define SPI_LEN2 0x10000000 /* or SFCSR to set */
  68. #define SPI_LEN1 0x00000000 /* or SFCSR to set */
  69. #define SPI_SETLEN(val) do { \
  70. SPI_REG(SFCSR) &= 0xCFFFFFFF; \
  71. SPI_REG(SFCSR) |= (val-1)<<28; \
  72. } while (0)
  73. /*
  74. * SPI interface control
  75. */
  76. #define RTL8390_SOC_SPI_MMIO_CONF (0x04)
  77. #define IOSTATUS_CIO_MASK (0x00000038)
  78. /* Chip select: bits 4-7*/
  79. #define CS0 (1<<4)
  80. #define R_MODE 0x04
  81. /* io_status */
  82. #define IO1 (1<<0)
  83. #define IO2 (1<<1)
  84. #define CIO1 (1<<3)
  85. #define CIO2 (1<<4)
  86. #define CMD_IO1 (1<<6)
  87. #define W_ADDR_IO1 ((1)<<12)
  88. #define R_ADDR_IO2 ((2)<<9)
  89. #define R_DATA_IO2 ((2)<<15)
  90. #define W_DATA_IO1 ((1)<<18)
  91. /* Commands */
  92. #define SPI_C_RSTQIO 0xFF
  93. #define SPI_MAX_TRANSFER_SIZE 256
  94. #endif /* _RTL838X_SPI_H */