blob: 45cdbbc71c4b441b9be5ea36749ab06b3262ade7 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Mika Westerbergcd7bed02013-01-22 12:26:28 +02002/*
3 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
Andy Shevchenko8083d6b2021-05-17 17:03:49 +03004 * Copyright (C) 2013, 2021 Intel Corporation
Mika Westerbergcd7bed02013-01-22 12:26:28 +02005 */
6
7#ifndef SPI_PXA2XX_H
8#define SPI_PXA2XX_H
9
Mika Westerbergcd7bed02013-01-22 12:26:28 +020010#include <linux/interrupt.h>
Andy Shevchenko0e476872021-04-23 21:24:31 +030011#include <linux/io.h>
12#include <linux/types.h>
Mika Westerberg59288082013-01-22 12:26:29 +020013#include <linux/sizes.h>
Andy Shevchenko0e476872021-04-23 21:24:31 +030014
15#include <linux/pxa2xx_ssp.h>
16
17struct gpio_desc;
18struct pxa2xx_spi_controller;
19struct spi_controller;
20struct spi_device;
21struct spi_transfer;
Mika Westerbergcd7bed02013-01-22 12:26:28 +020022
23struct driver_data {
Mika Westerbergcd7bed02013-01-22 12:26:28 +020024 /* SSP Info */
25 struct ssp_device *ssp;
26
27 /* SPI framework hookup */
28 enum pxa_ssp_type ssp_type;
Lubomir Rintel51eea522019-01-16 16:13:31 +010029 struct spi_controller *controller;
Mika Westerbergcd7bed02013-01-22 12:26:28 +020030
31 /* PXA hookup */
Lubomir Rintel51eea522019-01-16 16:13:31 +010032 struct pxa2xx_spi_controller *controller_info;
Mika Westerbergcd7bed02013-01-22 12:26:28 +020033
Mika Westerbergcd7bed02013-01-22 12:26:28 +020034 /* SSP masks*/
35 u32 dma_cr1;
36 u32 int_cr1;
37 u32 clear_sr;
38 u32 mask_sr;
39
Mika Westerberg59288082013-01-22 12:26:29 +020040 /* DMA engine support */
Mika Westerberg59288082013-01-22 12:26:29 +020041 atomic_t dma_running;
42
Jarkko Nikulad5898e12018-04-17 17:20:02 +030043 /* Current transfer state info */
Mika Westerbergcd7bed02013-01-22 12:26:28 +020044 void *tx;
45 void *tx_end;
46 void *rx;
47 void *rx_end;
Mika Westerbergcd7bed02013-01-22 12:26:28 +020048 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 Westerberga0d26422013-01-22 12:26:32 +020052
53 void __iomem *lpss_base;
Mika Westerberg99f499c2016-09-26 15:19:50 +030054
Lubomir Rintel77d33892018-11-13 11:22:27 +010055 /* Optional slave FIFO ready signal */
56 struct gpio_desc *gpiod_ready;
Mika Westerbergcd7bed02013-01-22 12:26:28 +020057};
58
59struct chip_data {
Mika Westerbergcd7bed02013-01-22 12:26:28 +020060 u32 cr1;
Weike Chene5262d02014-11-26 02:35:10 -080061 u32 dds_rate;
Mika Westerbergcd7bed02013-01-22 12:26:28 +020062 u32 timeout;
Andy Shevchenkode6926f2021-05-17 17:03:45 +030063 u8 enable_dma;
Mika Westerbergcd7bed02013-01-22 12:26:28 +020064 u32 dma_burst_size;
Mika Westerbergcd7bed02013-01-22 12:26:28 +020065 u32 dma_threshold;
Andy Shevchenkode6926f2021-05-17 17:03:45 +030066 u32 threshold;
Mika Westerberga0d26422013-01-22 12:26:32 +020067 u16 lpss_rx_threshold;
68 u16 lpss_tx_threshold;
Mika Westerbergcd7bed02013-01-22 12:26:28 +020069};
70
Andy Shevchenko9e43c9a82021-04-23 21:24:29 +030071static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data, u32 reg)
Jarkko Nikulac039dd22014-12-18 15:04:23 +020072{
Andy Shevchenko9e43c9a82021-04-23 21:24:29 +030073 return pxa_ssp_read_reg(drv_data->ssp, reg);
Jarkko Nikulac039dd22014-12-18 15:04:23 +020074}
Mika Westerbergcd7bed02013-01-22 12:26:28 +020075
Andy Shevchenko9e43c9a82021-04-23 21:24:29 +030076static inline void pxa2xx_spi_write(const struct driver_data *drv_data, u32 reg, u32 val)
Jarkko Nikulac039dd22014-12-18 15:04:23 +020077{
Andy Shevchenko9e43c9a82021-04-23 21:24:29 +030078 pxa_ssp_write_reg(drv_data->ssp, reg, val);
Jarkko Nikulac039dd22014-12-18 15:04:23 +020079}
Mika Westerbergcd7bed02013-01-22 12:26:28 +020080
Mika Westerbergcd7bed02013-01-22 12:26:28 +020081#define DMA_ALIGNMENT 8
82
Andy Shevchenkoeca32c32021-05-10 15:41:33 +030083static inline int pxa25x_ssp_comp(const struct driver_data *drv_data)
Mika Westerbergcd7bed02013-01-22 12:26:28 +020084{
Weike Chene5262d02014-11-26 02:35:10 -080085 switch (drv_data->ssp_type) {
86 case PXA25x_SSP:
87 case CE4100_SSP:
88 case QUARK_X1000_SSP:
Mika Westerbergcd7bed02013-01-22 12:26:28 +020089 return 1;
Weike Chene5262d02014-11-26 02:35:10 -080090 default:
91 return 0;
92 }
Mika Westerbergcd7bed02013-01-22 12:26:28 +020093}
94
Andy Shevchenko42c80cd2021-05-10 15:41:31 +030095static 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 Shevchenko6d380132021-05-10 15:41:32 +0300100static 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 Shevchenkoeca32c32021-05-10 15:41:33 +0300105static inline void write_SSSR_CS(const struct driver_data *drv_data, u32 val)
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200106{
Weike Chene5262d02014-11-26 02:35:10 -0800107 if (drv_data->ssp_type == CE4100_SSP ||
108 drv_data->ssp_type == QUARK_X1000_SSP)
Andy Shevchenko6d380132021-05-10 15:41:32 +0300109 val |= read_SSSR_bits(drv_data, SSSR_ALT_FRM_MASK);
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200110
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200111 pxa2xx_spi_write(drv_data, SSSR, val);
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200112}
113
114extern int pxa2xx_spi_flush(struct driver_data *drv_data);
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200115
Mika Westerberg59288082013-01-22 12:26:29 +0200116#define MAX_DMA_LEN SZ_64K
117#define DEFAULT_DMA_CR1 (SSCR1_TSRE | SSCR1_RSRE | SSCR1_TRAIL)
Mika Westerberg59288082013-01-22 12:26:29 +0200118
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200119extern irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data);
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300120extern int pxa2xx_spi_dma_prepare(struct driver_data *drv_data,
121 struct spi_transfer *xfer);
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200122extern void pxa2xx_spi_dma_start(struct driver_data *drv_data);
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300123extern void pxa2xx_spi_dma_stop(struct driver_data *drv_data);
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200124extern int pxa2xx_spi_dma_setup(struct driver_data *drv_data);
125extern void pxa2xx_spi_dma_release(struct driver_data *drv_data);
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200126extern 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 Westerbergcd7bed02013-01-22 12:26:28 +0200131
132#endif /* SPI_PXA2XX_H */