spi-pxa2xx.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
  3. * Copyright (C) 2013, Intel Corporation
  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 version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #ifndef SPI_PXA2XX_H
  10. #define SPI_PXA2XX_H
  11. #include <linux/atomic.h>
  12. #include <linux/dmaengine.h>
  13. #include <linux/errno.h>
  14. #include <linux/io.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/pxa2xx_ssp.h>
  18. #include <linux/scatterlist.h>
  19. #include <linux/sizes.h>
  20. #include <linux/spi/spi.h>
  21. #include <linux/spi/pxa2xx_spi.h>
  22. struct driver_data {
  23. /* Driver model hookup */
  24. struct platform_device *pdev;
  25. /* SSP Info */
  26. struct ssp_device *ssp;
  27. /* SPI framework hookup */
  28. enum pxa_ssp_type ssp_type;
  29. struct spi_master *master;
  30. /* PXA hookup */
  31. struct pxa2xx_spi_master *master_info;
  32. /* SSP register addresses */
  33. void __iomem *ioaddr;
  34. u32 ssdr_physical;
  35. /* SSP masks*/
  36. u32 dma_cr1;
  37. u32 int_cr1;
  38. u32 clear_sr;
  39. u32 mask_sr;
  40. /* Message Transfer pump */
  41. struct tasklet_struct pump_transfers;
  42. /* DMA engine support */
  43. struct dma_chan *rx_chan;
  44. struct dma_chan *tx_chan;
  45. struct sg_table rx_sgt;
  46. struct sg_table tx_sgt;
  47. int rx_nents;
  48. int tx_nents;
  49. void *dummy;
  50. atomic_t dma_running;
  51. /* Current message transfer state info */
  52. struct spi_message *cur_msg;
  53. struct spi_transfer *cur_transfer;
  54. struct chip_data *cur_chip;
  55. size_t len;
  56. void *tx;
  57. void *tx_end;
  58. void *rx;
  59. void *rx_end;
  60. int dma_mapped;
  61. dma_addr_t rx_dma;
  62. dma_addr_t tx_dma;
  63. size_t rx_map_len;
  64. size_t tx_map_len;
  65. u8 n_bytes;
  66. int (*write)(struct driver_data *drv_data);
  67. int (*read)(struct driver_data *drv_data);
  68. irqreturn_t (*transfer_handler)(struct driver_data *drv_data);
  69. void (*cs_control)(u32 command);
  70. void __iomem *lpss_base;
  71. };
  72. struct chip_data {
  73. u32 cr1;
  74. u32 dds_rate;
  75. u32 timeout;
  76. u8 n_bytes;
  77. u32 dma_burst_size;
  78. u32 threshold;
  79. u32 dma_threshold;
  80. u16 lpss_rx_threshold;
  81. u16 lpss_tx_threshold;
  82. u8 enable_dma;
  83. union {
  84. int gpio_cs;
  85. unsigned int frm;
  86. };
  87. int gpio_cs_inverted;
  88. int (*write)(struct driver_data *drv_data);
  89. int (*read)(struct driver_data *drv_data);
  90. void (*cs_control)(u32 command);
  91. };
  92. static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data,
  93. unsigned reg)
  94. {
  95. return __raw_readl(drv_data->ioaddr + reg);
  96. }
  97. static inline void pxa2xx_spi_write(const struct driver_data *drv_data,
  98. unsigned reg, u32 val)
  99. {
  100. __raw_writel(val, drv_data->ioaddr + reg);
  101. }
  102. #define START_STATE ((void *)0)
  103. #define RUNNING_STATE ((void *)1)
  104. #define DONE_STATE ((void *)2)
  105. #define ERROR_STATE ((void *)-1)
  106. #define IS_DMA_ALIGNED(x) IS_ALIGNED((unsigned long)(x), DMA_ALIGNMENT)
  107. #define DMA_ALIGNMENT 8
  108. static inline int pxa25x_ssp_comp(struct driver_data *drv_data)
  109. {
  110. switch (drv_data->ssp_type) {
  111. case PXA25x_SSP:
  112. case CE4100_SSP:
  113. case QUARK_X1000_SSP:
  114. return 1;
  115. default:
  116. return 0;
  117. }
  118. }
  119. static inline void write_SSSR_CS(struct driver_data *drv_data, u32 val)
  120. {
  121. if (drv_data->ssp_type == CE4100_SSP ||
  122. drv_data->ssp_type == QUARK_X1000_SSP)
  123. val |= pxa2xx_spi_read(drv_data, SSSR) & SSSR_ALT_FRM_MASK;
  124. pxa2xx_spi_write(drv_data, SSSR, val);
  125. }
  126. extern int pxa2xx_spi_flush(struct driver_data *drv_data);
  127. extern void *pxa2xx_spi_next_transfer(struct driver_data *drv_data);
  128. /*
  129. * Select the right DMA implementation.
  130. */
  131. #if defined(CONFIG_SPI_PXA2XX_DMA)
  132. #define SPI_PXA2XX_USE_DMA 1
  133. #define MAX_DMA_LEN SZ_64K
  134. #define DEFAULT_DMA_CR1 (SSCR1_TSRE | SSCR1_RSRE | SSCR1_TRAIL)
  135. #else
  136. #undef SPI_PXA2XX_USE_DMA
  137. #define MAX_DMA_LEN 0
  138. #define DEFAULT_DMA_CR1 0
  139. #endif
  140. #ifdef SPI_PXA2XX_USE_DMA
  141. extern bool pxa2xx_spi_dma_is_possible(size_t len);
  142. extern int pxa2xx_spi_map_dma_buffers(struct driver_data *drv_data);
  143. extern irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data);
  144. extern int pxa2xx_spi_dma_prepare(struct driver_data *drv_data, u32 dma_burst);
  145. extern void pxa2xx_spi_dma_start(struct driver_data *drv_data);
  146. extern int pxa2xx_spi_dma_setup(struct driver_data *drv_data);
  147. extern void pxa2xx_spi_dma_release(struct driver_data *drv_data);
  148. extern int pxa2xx_spi_set_dma_burst_and_threshold(struct chip_data *chip,
  149. struct spi_device *spi,
  150. u8 bits_per_word,
  151. u32 *burst_code,
  152. u32 *threshold);
  153. #else
  154. static inline bool pxa2xx_spi_dma_is_possible(size_t len) { return false; }
  155. static inline int pxa2xx_spi_map_dma_buffers(struct driver_data *drv_data)
  156. {
  157. return 0;
  158. }
  159. #define pxa2xx_spi_dma_transfer NULL
  160. static inline void pxa2xx_spi_dma_prepare(struct driver_data *drv_data,
  161. u32 dma_burst) {}
  162. static inline void pxa2xx_spi_dma_start(struct driver_data *drv_data) {}
  163. static inline int pxa2xx_spi_dma_setup(struct driver_data *drv_data)
  164. {
  165. return 0;
  166. }
  167. static inline void pxa2xx_spi_dma_release(struct driver_data *drv_data) {}
  168. static inline int pxa2xx_spi_set_dma_burst_and_threshold(struct chip_data *chip,
  169. struct spi_device *spi,
  170. u8 bits_per_word,
  171. u32 *burst_code,
  172. u32 *threshold)
  173. {
  174. return -ENODEV;
  175. }
  176. #endif
  177. #endif /* SPI_PXA2XX_H */