spi_internal.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (c) 2017 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief SPI controller helper for GL5120
  9. */
  10. #ifndef __SPI_H__
  11. #define __SPI_H__
  12. #include <device.h>
  13. #include <soc.h>
  14. #include <arch/common/sys_io.h>
  15. #include "../spi_flash.h"
  16. #ifdef CONFIG_NOR_CODE_IN_RAM
  17. #define _nor_fun __ramfunc
  18. #else
  19. #define _nor_fun
  20. #endif
  21. #define SPI_DELAY_LOOPS 5
  22. /* spinor controller */
  23. #define SSPI_CTL 0x00
  24. #define SSPI_STATUS 0x04
  25. #define SSPI_TXDAT 0x08
  26. #define SSPI_RXDAT 0x0c
  27. #define SSPI_BC 0x10
  28. #define SSPI_SEED 0x14
  29. #define SCACHE_ERR_ADDR 0x18
  30. #define SNO_CACHE_ADDR 0x1C
  31. #define SSPI_CTL_CLK_SEL_MASK ((unsigned int)1 << 31)
  32. #define SSPI_CTL_CLK_SEL_CPU ((unsigned int)0 << 31)
  33. #define SSPI_CTL_CLK_SEL_DMA ((unsigned int)1 << 31)
  34. #define SSPI_CTL_MODE_MASK (1 << 28)
  35. #define SSPI_CTL_MODE_MODE3 (0 << 28)
  36. #define SSPI_CTL_MODE_MODE0 (1 << 28)
  37. #define SSPI_CTL_CRC_EN (1 << 20)
  38. #define SSPI_CTL_DELAYCHAIN_MASK (0xf << 16)
  39. #define SSPI_CTL_DELAYCHAIN_SHIFT (16)
  40. #define SSPI_CTL_RAND_MASK (0xf << 12)
  41. #define SSPI_CTL_RAND_PAUSE (1 << 15)
  42. #define SSPI_CTL_RAND_SEL (1 << 14)
  43. #define SSPI_CTL_RAND_TXEN (1 << 13)
  44. #define SSPI_CTL_RAND_RXEN (1 << 12)
  45. #define SSPI_CTL_IO_MODE_MASK (0x3 << 10)
  46. #define SSPI_CTL_IO_MODE_SHIFT (10)
  47. #define SSPI_CTL_IO_MODE_1X (0x0 << 10)
  48. #define SSPI_CTL_IO_MODE_2X (0x2 << 10)
  49. #define SSPI_CTL_IO_MODE_4X (0x3 << 10)
  50. #define SSPI_CTL_SPI_3WIRE (1 << 9)
  51. #define SSPI_CTL_AHB_REQ (1 << 8)
  52. #define SSPI_CTL_TX_DRQ_EN (1 << 7)
  53. #define SSPI_CTL_RX_DRQ_EN (1 << 6)
  54. #define SSPI_CTL_TX_FIFO_EN (1 << 5)
  55. #define SSPI_CTL_RX_FIFO_EN (1 << 4)
  56. #define SSPI_CTL_SS (1 << 3)
  57. #define SSPI_CTL_WR_MODE_MASK (0x3 << 0)
  58. #define SSPI_CTL_WR_MODE_DISABLE (0x0 << 0)
  59. #define SSPI_CTL_WR_MODE_READ (0x1 << 0)
  60. #define SSPI_CTL_WR_MODE_WRITE (0x2 << 0)
  61. #define SSPI_CTL_WR_MODE_READ_WRITE (0x3 << 0)
  62. #define SSPI_STATUS_BUSY (1 << 6)
  63. #define SSPI_STATUS_TX_FULL (1 << 5)
  64. #define SSPI_STATUS_TX_EMPTY (1 << 4)
  65. #define SSPI_STATUS_RX_FULL (1 << 3)
  66. #define SSPI_STATUS_RX_EMPTY (1 << 2)
  67. #define SSPI0_REGISTER (SPI0_BASE)
  68. #define SSPI1_REGISTER (SPI1_BASE)
  69. #define SSPI2_REGISTER (SPI2_BASE)
  70. /* spi1 registers bits */
  71. #define SSPI1_CTL_MODE_MASK (3 << 28)
  72. #define SSPI1_CTL_MODE_MODE3 (3 << 28)
  73. #define SSPI1_CTL_MODE_MODE0 (0 << 28)
  74. #define SSPI1_CTL_AHB_REQ (1 << 15)
  75. #define SSPI1_STATUS_BUSY (1 << 0)
  76. #define SSPI1_STATUS_TX_FULL (1 << 5)
  77. #define SSPI1_STATUS_TX_EMPTY (1 << 4)
  78. #define SSPI1_STATUS_RX_FULL (1 << 7)
  79. #define SSPI1_STATUS_RX_EMPTY (1 << 6)
  80. #define MRCR0_SPI3RESET (7)
  81. #define MRCR0_SPI2RESET (6)
  82. #define MRCR0_SPI1RESET (5)
  83. #define MRCR0_SPI0RESET (4)
  84. #define CMU_DEVCLKEN0_SPI3CLKEN (7)
  85. #define CMU_DEVCLKEN0_SPI2CLKEN (6)
  86. #define CMU_DEVCLKEN0_SPI1CLKEN (5)
  87. #define CMU_DEVCLKEN0_SPI0CLKEN (4)
  88. extern void spi_delay(void);
  89. static inline unsigned int spi_read(struct spi_info *si, unsigned int reg)
  90. {
  91. return sys_read32(si->base + reg);
  92. }
  93. static inline void spi_write(struct spi_info *si, unsigned int reg,
  94. unsigned int value)
  95. {
  96. sys_write32(value, si->base + reg);
  97. }
  98. #endif /* __SPI_H__ */