spi-pxa2xx.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. phys_addr_t 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. atomic_t dma_running;
  44. /* Current message transfer state info */
  45. struct spi_transfer *cur_transfer;
  46. size_t len;
  47. void *tx;
  48. void *tx_end;
  49. void *rx;
  50. void *rx_end;
  51. u8 n_bytes;
  52. int (*write)(struct driver_data *drv_data);
  53. int (*read)(struct driver_data *drv_data);
  54. irqreturn_t (*transfer_handler)(struct driver_data *drv_data);
  55. void (*cs_control)(u32 command);
  56. void __iomem *lpss_base;
  57. /* GPIOs for chip selects */
  58. struct gpio_desc **cs_gpiods;
  59. };
  60. struct chip_data {
  61. u32 cr1;
  62. u32 dds_rate;
  63. u32 timeout;
  64. u8 n_bytes;
  65. u32 dma_burst_size;
  66. u32 threshold;
  67. u32 dma_threshold;
  68. u16 lpss_rx_threshold;
  69. u16 lpss_tx_threshold;
  70. u8 enable_dma;
  71. union {
  72. int gpio_cs;
  73. unsigned int frm;
  74. };
  75. int gpio_cs_inverted;
  76. int (*write)(struct driver_data *drv_data);
  77. int (*read)(struct driver_data *drv_data);
  78. void (*cs_control)(u32 command);
  79. };
  80. static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data,
  81. unsigned reg)
  82. {
  83. return __raw_readl(drv_data->ioaddr + reg);
  84. }
  85. static inline void pxa2xx_spi_write(const struct driver_data *drv_data,
  86. unsigned reg, u32 val)
  87. {
  88. __raw_writel(val, drv_data->ioaddr + reg);
  89. }
  90. #define START_STATE ((void *)0)
  91. #define RUNNING_STATE ((void *)1)
  92. #define DONE_STATE ((void *)2)
  93. #define ERROR_STATE ((void *)-1)
  94. #define IS_DMA_ALIGNED(x) IS_ALIGNED((unsigned long)(x), DMA_ALIGNMENT)
  95. #define DMA_ALIGNMENT 8
  96. static inline int pxa25x_ssp_comp(struct driver_data *drv_data)
  97. {
  98. switch (drv_data->ssp_type) {
  99. case PXA25x_SSP:
  100. case CE4100_SSP:
  101. case QUARK_X1000_SSP:
  102. return 1;
  103. default:
  104. return 0;
  105. }
  106. }
  107. static inline void write_SSSR_CS(struct driver_data *drv_data, u32 val)
  108. {
  109. if (drv_data->ssp_type == CE4100_SSP ||
  110. drv_data->ssp_type == QUARK_X1000_SSP)
  111. val |= pxa2xx_spi_read(drv_data, SSSR) & SSSR_ALT_FRM_MASK;
  112. pxa2xx_spi_write(drv_data, SSSR, val);
  113. }
  114. extern int pxa2xx_spi_flush(struct driver_data *drv_data);
  115. extern void *pxa2xx_spi_next_transfer(struct driver_data *drv_data);
  116. #define MAX_DMA_LEN SZ_64K
  117. #define DEFAULT_DMA_CR1 (SSCR1_TSRE | SSCR1_RSRE | SSCR1_TRAIL)
  118. extern irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data);
  119. extern int pxa2xx_spi_dma_prepare(struct driver_data *drv_data, u32 dma_burst);
  120. extern void pxa2xx_spi_dma_start(struct driver_data *drv_data);
  121. extern int pxa2xx_spi_dma_setup(struct driver_data *drv_data);
  122. extern void pxa2xx_spi_dma_release(struct driver_data *drv_data);
  123. extern int pxa2xx_spi_set_dma_burst_and_threshold(struct chip_data *chip,
  124. struct spi_device *spi,
  125. u8 bits_per_word,
  126. u32 *burst_code,
  127. u32 *threshold);
  128. #endif /* SPI_PXA2XX_H */