Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs |
Andy Shevchenko | 8083d6b | 2021-05-17 17:03:49 +0300 | [diff] [blame] | 4 | * Copyright (C) 2013, 2021 Intel Corporation |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef SPI_PXA2XX_H |
| 8 | #define SPI_PXA2XX_H |
| 9 | |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 10 | #include <linux/interrupt.h> |
Andy Shevchenko | 0e47687 | 2021-04-23 21:24:31 +0300 | [diff] [blame] | 11 | #include <linux/io.h> |
| 12 | #include <linux/types.h> |
Mika Westerberg | 5928808 | 2013-01-22 12:26:29 +0200 | [diff] [blame] | 13 | #include <linux/sizes.h> |
Andy Shevchenko | 0e47687 | 2021-04-23 21:24:31 +0300 | [diff] [blame] | 14 | |
| 15 | #include <linux/pxa2xx_ssp.h> |
| 16 | |
| 17 | struct gpio_desc; |
| 18 | struct pxa2xx_spi_controller; |
| 19 | struct spi_controller; |
| 20 | struct spi_device; |
| 21 | struct spi_transfer; |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 22 | |
| 23 | struct driver_data { |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 24 | /* SSP Info */ |
| 25 | struct ssp_device *ssp; |
| 26 | |
| 27 | /* SPI framework hookup */ |
| 28 | enum pxa_ssp_type ssp_type; |
Lubomir Rintel | 51eea52 | 2019-01-16 16:13:31 +0100 | [diff] [blame] | 29 | struct spi_controller *controller; |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 30 | |
| 31 | /* PXA hookup */ |
Lubomir Rintel | 51eea52 | 2019-01-16 16:13:31 +0100 | [diff] [blame] | 32 | struct pxa2xx_spi_controller *controller_info; |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 33 | |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 34 | /* SSP masks*/ |
| 35 | u32 dma_cr1; |
| 36 | u32 int_cr1; |
| 37 | u32 clear_sr; |
| 38 | u32 mask_sr; |
| 39 | |
Mika Westerberg | 5928808 | 2013-01-22 12:26:29 +0200 | [diff] [blame] | 40 | /* DMA engine support */ |
Mika Westerberg | 5928808 | 2013-01-22 12:26:29 +0200 | [diff] [blame] | 41 | atomic_t dma_running; |
| 42 | |
Jarkko Nikula | d5898e1 | 2018-04-17 17:20:02 +0300 | [diff] [blame] | 43 | /* Current transfer state info */ |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 44 | void *tx; |
| 45 | void *tx_end; |
| 46 | void *rx; |
| 47 | void *rx_end; |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 48 | u8 n_bytes; |
| 49 | int (*write)(struct driver_data *drv_data); |
| 50 | int (*read)(struct driver_data *drv_data); |
| 51 | irqreturn_t (*transfer_handler)(struct driver_data *drv_data); |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 52 | |
| 53 | void __iomem *lpss_base; |
Mika Westerberg | 99f499c | 2016-09-26 15:19:50 +0300 | [diff] [blame] | 54 | |
Lubomir Rintel | 77d3389 | 2018-11-13 11:22:27 +0100 | [diff] [blame] | 55 | /* Optional slave FIFO ready signal */ |
| 56 | struct gpio_desc *gpiod_ready; |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | struct chip_data { |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 60 | u32 cr1; |
Weike Chen | e5262d0 | 2014-11-26 02:35:10 -0800 | [diff] [blame] | 61 | u32 dds_rate; |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 62 | u32 timeout; |
Andy Shevchenko | de6926f | 2021-05-17 17:03:45 +0300 | [diff] [blame] | 63 | u8 enable_dma; |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 64 | u32 dma_burst_size; |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 65 | u32 dma_threshold; |
Andy Shevchenko | de6926f | 2021-05-17 17:03:45 +0300 | [diff] [blame] | 66 | u32 threshold; |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 67 | u16 lpss_rx_threshold; |
| 68 | u16 lpss_tx_threshold; |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
Andy Shevchenko | 9e43c9a8 | 2021-04-23 21:24:29 +0300 | [diff] [blame] | 71 | static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data, u32 reg) |
Jarkko Nikula | c039dd2 | 2014-12-18 15:04:23 +0200 | [diff] [blame] | 72 | { |
Andy Shevchenko | 9e43c9a8 | 2021-04-23 21:24:29 +0300 | [diff] [blame] | 73 | return pxa_ssp_read_reg(drv_data->ssp, reg); |
Jarkko Nikula | c039dd2 | 2014-12-18 15:04:23 +0200 | [diff] [blame] | 74 | } |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 75 | |
Andy Shevchenko | 9e43c9a8 | 2021-04-23 21:24:29 +0300 | [diff] [blame] | 76 | static inline void pxa2xx_spi_write(const struct driver_data *drv_data, u32 reg, u32 val) |
Jarkko Nikula | c039dd2 | 2014-12-18 15:04:23 +0200 | [diff] [blame] | 77 | { |
Andy Shevchenko | 9e43c9a8 | 2021-04-23 21:24:29 +0300 | [diff] [blame] | 78 | pxa_ssp_write_reg(drv_data->ssp, reg, val); |
Jarkko Nikula | c039dd2 | 2014-12-18 15:04:23 +0200 | [diff] [blame] | 79 | } |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 80 | |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 81 | #define DMA_ALIGNMENT 8 |
| 82 | |
Andy Shevchenko | eca32c3 | 2021-05-10 15:41:33 +0300 | [diff] [blame] | 83 | static inline int pxa25x_ssp_comp(const struct driver_data *drv_data) |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 84 | { |
Weike Chen | e5262d0 | 2014-11-26 02:35:10 -0800 | [diff] [blame] | 85 | switch (drv_data->ssp_type) { |
| 86 | case PXA25x_SSP: |
| 87 | case CE4100_SSP: |
| 88 | case QUARK_X1000_SSP: |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 89 | return 1; |
Weike Chen | e5262d0 | 2014-11-26 02:35:10 -0800 | [diff] [blame] | 90 | default: |
| 91 | return 0; |
| 92 | } |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 93 | } |
| 94 | |
Andy Shevchenko | 42c80cd | 2021-05-10 15:41:31 +0300 | [diff] [blame] | 95 | static inline void clear_SSCR1_bits(const struct driver_data *drv_data, u32 bits) |
| 96 | { |
| 97 | pxa2xx_spi_write(drv_data, SSCR1, pxa2xx_spi_read(drv_data, SSCR1) & ~bits); |
| 98 | } |
| 99 | |
Andy Shevchenko | 6d38013 | 2021-05-10 15:41:32 +0300 | [diff] [blame] | 100 | static inline u32 read_SSSR_bits(const struct driver_data *drv_data, u32 bits) |
| 101 | { |
| 102 | return pxa2xx_spi_read(drv_data, SSSR) & bits; |
| 103 | } |
| 104 | |
Andy Shevchenko | eca32c3 | 2021-05-10 15:41:33 +0300 | [diff] [blame] | 105 | static inline void write_SSSR_CS(const struct driver_data *drv_data, u32 val) |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 106 | { |
Weike Chen | e5262d0 | 2014-11-26 02:35:10 -0800 | [diff] [blame] | 107 | if (drv_data->ssp_type == CE4100_SSP || |
| 108 | drv_data->ssp_type == QUARK_X1000_SSP) |
Andy Shevchenko | 6d38013 | 2021-05-10 15:41:32 +0300 | [diff] [blame] | 109 | val |= read_SSSR_bits(drv_data, SSSR_ALT_FRM_MASK); |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 110 | |
Jarkko Nikula | c039dd2 | 2014-12-18 15:04:23 +0200 | [diff] [blame] | 111 | pxa2xx_spi_write(drv_data, SSSR, val); |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | extern int pxa2xx_spi_flush(struct driver_data *drv_data); |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 115 | |
Mika Westerberg | 5928808 | 2013-01-22 12:26:29 +0200 | [diff] [blame] | 116 | #define MAX_DMA_LEN SZ_64K |
| 117 | #define DEFAULT_DMA_CR1 (SSCR1_TSRE | SSCR1_RSRE | SSCR1_TRAIL) |
Mika Westerberg | 5928808 | 2013-01-22 12:26:29 +0200 | [diff] [blame] | 118 | |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 119 | extern irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data); |
Jarkko Nikula | d5898e1 | 2018-04-17 17:20:02 +0300 | [diff] [blame] | 120 | extern int pxa2xx_spi_dma_prepare(struct driver_data *drv_data, |
| 121 | struct spi_transfer *xfer); |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 122 | extern void pxa2xx_spi_dma_start(struct driver_data *drv_data); |
Jarkko Nikula | d5898e1 | 2018-04-17 17:20:02 +0300 | [diff] [blame] | 123 | extern void pxa2xx_spi_dma_stop(struct driver_data *drv_data); |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 124 | extern int pxa2xx_spi_dma_setup(struct driver_data *drv_data); |
| 125 | extern void pxa2xx_spi_dma_release(struct driver_data *drv_data); |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 126 | extern int pxa2xx_spi_set_dma_burst_and_threshold(struct chip_data *chip, |
| 127 | struct spi_device *spi, |
| 128 | u8 bits_per_word, |
| 129 | u32 *burst_code, |
| 130 | u32 *threshold); |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 131 | |
| 132 | #endif /* SPI_PXA2XX_H */ |