spi-pxa2xx.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. /* PXA private DMA setup stuff */
  33. int rx_channel;
  34. int tx_channel;
  35. u32 *null_dma_buf;
  36. /* SSP register addresses */
  37. void __iomem *ioaddr;
  38. u32 ssdr_physical;
  39. /* SSP masks*/
  40. u32 dma_cr1;
  41. u32 int_cr1;
  42. u32 clear_sr;
  43. u32 mask_sr;
  44. /* Maximun clock rate */
  45. unsigned long max_clk_rate;
  46. /* Message Transfer pump */
  47. struct tasklet_struct pump_transfers;
  48. /* DMA engine support */
  49. struct dma_chan *rx_chan;
  50. struct dma_chan *tx_chan;
  51. struct sg_table rx_sgt;
  52. struct sg_table tx_sgt;
  53. int rx_nents;
  54. int tx_nents;
  55. void *dummy;
  56. atomic_t dma_running;
  57. /* Current message transfer state info */
  58. struct spi_message *cur_msg;
  59. struct spi_transfer *cur_transfer;
  60. struct chip_data *cur_chip;
  61. size_t len;
  62. void *tx;
  63. void *tx_end;
  64. void *rx;
  65. void *rx_end;
  66. int dma_mapped;
  67. dma_addr_t rx_dma;
  68. dma_addr_t tx_dma;
  69. size_t rx_map_len;
  70. size_t tx_map_len;
  71. u8 n_bytes;
  72. int (*write)(struct driver_data *drv_data);
  73. int (*read)(struct driver_data *drv_data);
  74. irqreturn_t (*transfer_handler)(struct driver_data *drv_data);
  75. void (*cs_control)(u32 command);
  76. void __iomem *lpss_base;
  77. };
  78. struct chip_data {
  79. u32 cr0;
  80. u32 cr1;
  81. u32 dds_rate;
  82. u32 psp;
  83. u32 timeout;
  84. u8 n_bytes;
  85. u32 dma_burst_size;
  86. u32 threshold;
  87. u32 dma_threshold;
  88. u16 lpss_rx_threshold;
  89. u16 lpss_tx_threshold;
  90. u8 enable_dma;
  91. u8 bits_per_word;
  92. u32 speed_hz;
  93. union {
  94. int gpio_cs;
  95. unsigned int frm;
  96. };
  97. int gpio_cs_inverted;
  98. int (*write)(struct driver_data *drv_data);
  99. int (*read)(struct driver_data *drv_data);
  100. void (*cs_control)(u32 command);
  101. };
  102. static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data,
  103. unsigned reg)
  104. {
  105. return __raw_readl(drv_data->ioaddr + reg);
  106. }
  107. static inline void pxa2xx_spi_write(const struct driver_data *drv_data,
  108. unsigned reg, u32 val)
  109. {
  110. __raw_writel(val, drv_data->ioaddr + reg);
  111. }
  112. #define START_STATE ((void *)0)
  113. #define RUNNING_STATE ((void *)1)
  114. #define DONE_STATE ((void *)2)
  115. #define ERROR_STATE ((void *)-1)
  116. #define IS_DMA_ALIGNED(x) IS_ALIGNED((unsigned long)(x), DMA_ALIGNMENT)
  117. #define DMA_ALIGNMENT 8
  118. static inline int pxa25x_ssp_comp(struct driver_data *drv_data)
  119. {
  120. switch (drv_data->ssp_type) {
  121. case PXA25x_SSP:
  122. case CE4100_SSP:
  123. case QUARK_X1000_SSP:
  124. return 1;
  125. default:
  126. return 0;
  127. }
  128. }
  129. static inline void write_SSSR_CS(struct driver_data *drv_data, u32 val)
  130. {
  131. if (drv_data->ssp_type == CE4100_SSP ||
  132. drv_data->ssp_type == QUARK_X1000_SSP)
  133. val |= pxa2xx_spi_read(drv_data, SSSR) & SSSR_ALT_FRM_MASK;
  134. pxa2xx_spi_write(drv_data, SSSR, val);
  135. }
  136. extern int pxa2xx_spi_flush(struct driver_data *drv_data);
  137. extern void *pxa2xx_spi_next_transfer(struct driver_data *drv_data);
  138. /*
  139. * Select the right DMA implementation.
  140. */
  141. #if defined(CONFIG_SPI_PXA2XX_DMA)
  142. #define SPI_PXA2XX_USE_DMA 1
  143. #define MAX_DMA_LEN SZ_64K
  144. #define DEFAULT_DMA_CR1 (SSCR1_TSRE | SSCR1_RSRE | SSCR1_TRAIL)
  145. #else
  146. #undef SPI_PXA2XX_USE_DMA
  147. #define MAX_DMA_LEN 0
  148. #define DEFAULT_DMA_CR1 0
  149. #endif
  150. #ifdef SPI_PXA2XX_USE_DMA
  151. extern bool pxa2xx_spi_dma_is_possible(size_t len);
  152. extern int pxa2xx_spi_map_dma_buffers(struct driver_data *drv_data);
  153. extern irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data);
  154. extern int pxa2xx_spi_dma_prepare(struct driver_data *drv_data, u32 dma_burst);
  155. extern void pxa2xx_spi_dma_start(struct driver_data *drv_data);
  156. extern int pxa2xx_spi_dma_setup(struct driver_data *drv_data);
  157. extern void pxa2xx_spi_dma_release(struct driver_data *drv_data);
  158. extern void pxa2xx_spi_dma_resume(struct driver_data *drv_data);
  159. extern int pxa2xx_spi_set_dma_burst_and_threshold(struct chip_data *chip,
  160. struct spi_device *spi,
  161. u8 bits_per_word,
  162. u32 *burst_code,
  163. u32 *threshold);
  164. #else
  165. static inline bool pxa2xx_spi_dma_is_possible(size_t len) { return false; }
  166. static inline int pxa2xx_spi_map_dma_buffers(struct driver_data *drv_data)
  167. {
  168. return 0;
  169. }
  170. #define pxa2xx_spi_dma_transfer NULL
  171. static inline void pxa2xx_spi_dma_prepare(struct driver_data *drv_data,
  172. u32 dma_burst) {}
  173. static inline void pxa2xx_spi_dma_start(struct driver_data *drv_data) {}
  174. static inline int pxa2xx_spi_dma_setup(struct driver_data *drv_data)
  175. {
  176. return 0;
  177. }
  178. static inline void pxa2xx_spi_dma_release(struct driver_data *drv_data) {}
  179. static inline void pxa2xx_spi_dma_resume(struct driver_data *drv_data) {}
  180. static inline int pxa2xx_spi_set_dma_burst_and_threshold(struct chip_data *chip,
  181. struct spi_device *spi,
  182. u8 bits_per_word,
  183. u32 *burst_code,
  184. u32 *threshold)
  185. {
  186. return -ENODEV;
  187. }
  188. #endif
  189. #endif /* SPI_PXA2XX_H */