spi-pxa2xx.h 3.4 KB

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