2019-06-04 11:11:33 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2013-01-22 14:26:28 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
|
2021-05-17 17:03:49 +03:00
|
|
|
* Copyright (C) 2013, 2021 Intel Corporation
|
2013-01-22 14:26:28 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SPI_PXA2XX_H
|
|
|
|
#define SPI_PXA2XX_H
|
|
|
|
|
|
|
|
#include <linux/interrupt.h>
|
2021-04-23 21:24:31 +03:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/types.h>
|
2013-01-22 14:26:29 +04:00
|
|
|
#include <linux/sizes.h>
|
2021-04-23 21:24:31 +03:00
|
|
|
|
|
|
|
#include <linux/pxa2xx_ssp.h>
|
|
|
|
|
|
|
|
struct gpio_desc;
|
|
|
|
struct pxa2xx_spi_controller;
|
|
|
|
struct spi_controller;
|
|
|
|
struct spi_device;
|
|
|
|
struct spi_transfer;
|
2013-01-22 14:26:28 +04:00
|
|
|
|
|
|
|
struct driver_data {
|
|
|
|
/* SSP Info */
|
|
|
|
struct ssp_device *ssp;
|
|
|
|
|
|
|
|
/* SPI framework hookup */
|
|
|
|
enum pxa_ssp_type ssp_type;
|
2019-01-16 18:13:31 +03:00
|
|
|
struct spi_controller *controller;
|
2013-01-22 14:26:28 +04:00
|
|
|
|
|
|
|
/* PXA hookup */
|
2019-01-16 18:13:31 +03:00
|
|
|
struct pxa2xx_spi_controller *controller_info;
|
2013-01-22 14:26:28 +04:00
|
|
|
|
|
|
|
/* SSP masks*/
|
|
|
|
u32 dma_cr1;
|
|
|
|
u32 int_cr1;
|
|
|
|
u32 clear_sr;
|
|
|
|
u32 mask_sr;
|
|
|
|
|
2013-01-22 14:26:29 +04:00
|
|
|
/* DMA engine support */
|
|
|
|
atomic_t dma_running;
|
|
|
|
|
2018-04-17 17:20:02 +03:00
|
|
|
/* Current transfer state info */
|
2013-01-22 14:26:28 +04:00
|
|
|
void *tx;
|
|
|
|
void *tx_end;
|
|
|
|
void *rx;
|
|
|
|
void *rx_end;
|
|
|
|
u8 n_bytes;
|
|
|
|
int (*write)(struct driver_data *drv_data);
|
|
|
|
int (*read)(struct driver_data *drv_data);
|
|
|
|
irqreturn_t (*transfer_handler)(struct driver_data *drv_data);
|
2013-01-22 14:26:32 +04:00
|
|
|
|
|
|
|
void __iomem *lpss_base;
|
2016-09-26 15:19:50 +03:00
|
|
|
|
2018-11-13 13:22:27 +03:00
|
|
|
/* Optional slave FIFO ready signal */
|
|
|
|
struct gpio_desc *gpiod_ready;
|
2013-01-22 14:26:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct chip_data {
|
|
|
|
u32 cr1;
|
2014-11-26 13:35:10 +03:00
|
|
|
u32 dds_rate;
|
2013-01-22 14:26:28 +04:00
|
|
|
u32 timeout;
|
2021-05-17 17:03:45 +03:00
|
|
|
u8 enable_dma;
|
2013-01-22 14:26:28 +04:00
|
|
|
u32 dma_burst_size;
|
|
|
|
u32 dma_threshold;
|
2021-05-17 17:03:45 +03:00
|
|
|
u32 threshold;
|
2013-01-22 14:26:32 +04:00
|
|
|
u16 lpss_rx_threshold;
|
|
|
|
u16 lpss_tx_threshold;
|
2013-01-22 14:26:28 +04:00
|
|
|
};
|
|
|
|
|
2021-04-23 21:24:29 +03:00
|
|
|
static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data, u32 reg)
|
2014-12-18 16:04:23 +03:00
|
|
|
{
|
2021-04-23 21:24:29 +03:00
|
|
|
return pxa_ssp_read_reg(drv_data->ssp, reg);
|
2014-12-18 16:04:23 +03:00
|
|
|
}
|
|
|
|
|
2021-04-23 21:24:29 +03:00
|
|
|
static inline void pxa2xx_spi_write(const struct driver_data *drv_data, u32 reg, u32 val)
|
2014-12-18 16:04:23 +03:00
|
|
|
{
|
2021-04-23 21:24:29 +03:00
|
|
|
pxa_ssp_write_reg(drv_data->ssp, reg, val);
|
2014-12-18 16:04:23 +03:00
|
|
|
}
|
2013-01-22 14:26:28 +04:00
|
|
|
|
|
|
|
#define DMA_ALIGNMENT 8
|
|
|
|
|
2021-05-10 15:41:33 +03:00
|
|
|
static inline int pxa25x_ssp_comp(const struct driver_data *drv_data)
|
2013-01-22 14:26:28 +04:00
|
|
|
{
|
2014-11-26 13:35:10 +03:00
|
|
|
switch (drv_data->ssp_type) {
|
|
|
|
case PXA25x_SSP:
|
|
|
|
case CE4100_SSP:
|
|
|
|
case QUARK_X1000_SSP:
|
2013-01-22 14:26:28 +04:00
|
|
|
return 1;
|
2014-11-26 13:35:10 +03:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2013-01-22 14:26:28 +04:00
|
|
|
}
|
|
|
|
|
2021-05-10 15:41:31 +03:00
|
|
|
static inline void clear_SSCR1_bits(const struct driver_data *drv_data, u32 bits)
|
|
|
|
{
|
|
|
|
pxa2xx_spi_write(drv_data, SSCR1, pxa2xx_spi_read(drv_data, SSCR1) & ~bits);
|
|
|
|
}
|
|
|
|
|
2021-05-10 15:41:32 +03:00
|
|
|
static inline u32 read_SSSR_bits(const struct driver_data *drv_data, u32 bits)
|
|
|
|
{
|
|
|
|
return pxa2xx_spi_read(drv_data, SSSR) & bits;
|
|
|
|
}
|
|
|
|
|
2021-05-10 15:41:33 +03:00
|
|
|
static inline void write_SSSR_CS(const struct driver_data *drv_data, u32 val)
|
2013-01-22 14:26:28 +04:00
|
|
|
{
|
2014-11-26 13:35:10 +03:00
|
|
|
if (drv_data->ssp_type == CE4100_SSP ||
|
|
|
|
drv_data->ssp_type == QUARK_X1000_SSP)
|
2021-05-10 15:41:32 +03:00
|
|
|
val |= read_SSSR_bits(drv_data, SSSR_ALT_FRM_MASK);
|
2013-01-22 14:26:28 +04:00
|
|
|
|
2014-12-18 16:04:23 +03:00
|
|
|
pxa2xx_spi_write(drv_data, SSSR, val);
|
2013-01-22 14:26:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern int pxa2xx_spi_flush(struct driver_data *drv_data);
|
|
|
|
|
2013-01-22 14:26:29 +04:00
|
|
|
#define MAX_DMA_LEN SZ_64K
|
|
|
|
#define DEFAULT_DMA_CR1 (SSCR1_TSRE | SSCR1_RSRE | SSCR1_TRAIL)
|
|
|
|
|
2013-01-22 14:26:28 +04:00
|
|
|
extern irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data);
|
2018-04-17 17:20:02 +03:00
|
|
|
extern int pxa2xx_spi_dma_prepare(struct driver_data *drv_data,
|
|
|
|
struct spi_transfer *xfer);
|
2013-01-22 14:26:28 +04:00
|
|
|
extern void pxa2xx_spi_dma_start(struct driver_data *drv_data);
|
2018-04-17 17:20:02 +03:00
|
|
|
extern void pxa2xx_spi_dma_stop(struct driver_data *drv_data);
|
2013-01-22 14:26:28 +04:00
|
|
|
extern int pxa2xx_spi_dma_setup(struct driver_data *drv_data);
|
|
|
|
extern void pxa2xx_spi_dma_release(struct driver_data *drv_data);
|
|
|
|
extern int pxa2xx_spi_set_dma_burst_and_threshold(struct chip_data *chip,
|
|
|
|
struct spi_device *spi,
|
|
|
|
u8 bits_per_word,
|
|
|
|
u32 *burst_code,
|
|
|
|
u32 *threshold);
|
|
|
|
|
|
|
|
#endif /* SPI_PXA2XX_H */
|