2019-06-04 08:11:33 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2013-01-22 10:26:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
|
|
|
|
* Copyright (C) 2013, Intel Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SPI_PXA2XX_H
|
|
|
|
#define SPI_PXA2XX_H
|
|
|
|
|
2013-01-22 10:26:29 +00:00
|
|
|
#include <linux/atomic.h>
|
|
|
|
#include <linux/dmaengine.h>
|
2013-01-22 10:26:28 +00:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/pxa2xx_ssp.h>
|
2013-01-22 10:26:29 +00:00
|
|
|
#include <linux/scatterlist.h>
|
|
|
|
#include <linux/sizes.h>
|
2013-01-22 10:26:28 +00:00
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
#include <linux/spi/pxa2xx_spi.h>
|
|
|
|
|
|
|
|
struct driver_data {
|
|
|
|
/* Driver model hookup */
|
|
|
|
struct platform_device *pdev;
|
|
|
|
|
|
|
|
/* SSP Info */
|
|
|
|
struct ssp_device *ssp;
|
|
|
|
|
|
|
|
/* SPI framework hookup */
|
|
|
|
enum pxa_ssp_type ssp_type;
|
2019-01-16 15:13:31 +00:00
|
|
|
struct spi_controller *controller;
|
2013-01-22 10:26:28 +00:00
|
|
|
|
|
|
|
/* PXA hookup */
|
2019-01-16 15:13:31 +00:00
|
|
|
struct pxa2xx_spi_controller *controller_info;
|
2013-01-22 10:26:28 +00:00
|
|
|
|
|
|
|
/* SSP register addresses */
|
|
|
|
void __iomem *ioaddr;
|
2018-04-19 16:53:32 +00:00
|
|
|
phys_addr_t ssdr_physical;
|
2013-01-22 10:26:28 +00:00
|
|
|
|
|
|
|
/* SSP masks*/
|
|
|
|
u32 dma_cr1;
|
|
|
|
u32 int_cr1;
|
|
|
|
u32 clear_sr;
|
|
|
|
u32 mask_sr;
|
|
|
|
|
2013-01-22 10:26:29 +00:00
|
|
|
/* DMA engine support */
|
|
|
|
atomic_t dma_running;
|
|
|
|
|
2018-04-17 14:20:02 +00:00
|
|
|
/* Current transfer state info */
|
2013-01-22 10:26:28 +00: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);
|
|
|
|
void (*cs_control)(u32 command);
|
2013-01-22 10:26:32 +00:00
|
|
|
|
|
|
|
void __iomem *lpss_base;
|
2016-09-26 12:19:50 +00:00
|
|
|
|
|
|
|
/* GPIOs for chip selects */
|
|
|
|
struct gpio_desc **cs_gpiods;
|
2018-11-13 10:22:27 +00:00
|
|
|
|
|
|
|
/* Optional slave FIFO ready signal */
|
|
|
|
struct gpio_desc *gpiod_ready;
|
2013-01-22 10:26:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct chip_data {
|
|
|
|
u32 cr1;
|
2014-11-26 10:35:10 +00:00
|
|
|
u32 dds_rate;
|
2013-01-22 10:26:28 +00:00
|
|
|
u32 timeout;
|
|
|
|
u8 n_bytes;
|
|
|
|
u32 dma_burst_size;
|
|
|
|
u32 threshold;
|
|
|
|
u32 dma_threshold;
|
2013-01-22 10:26:32 +00:00
|
|
|
u16 lpss_rx_threshold;
|
|
|
|
u16 lpss_tx_threshold;
|
2013-01-22 10:26:28 +00:00
|
|
|
u8 enable_dma;
|
|
|
|
union {
|
2017-08-03 11:40:32 +00:00
|
|
|
struct gpio_desc *gpiod_cs;
|
2013-01-22 10:26:28 +00:00
|
|
|
unsigned int frm;
|
|
|
|
};
|
|
|
|
int gpio_cs_inverted;
|
|
|
|
int (*write)(struct driver_data *drv_data);
|
|
|
|
int (*read)(struct driver_data *drv_data);
|
|
|
|
void (*cs_control)(u32 command);
|
|
|
|
};
|
|
|
|
|
2014-12-18 13:04:23 +00:00
|
|
|
static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data,
|
|
|
|
unsigned reg)
|
|
|
|
{
|
|
|
|
return __raw_readl(drv_data->ioaddr + reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void pxa2xx_spi_write(const struct driver_data *drv_data,
|
|
|
|
unsigned reg, u32 val)
|
|
|
|
{
|
|
|
|
__raw_writel(val, drv_data->ioaddr + reg);
|
|
|
|
}
|
2013-01-22 10:26:28 +00:00
|
|
|
|
|
|
|
#define DMA_ALIGNMENT 8
|
|
|
|
|
|
|
|
static inline int pxa25x_ssp_comp(struct driver_data *drv_data)
|
|
|
|
{
|
2014-11-26 10:35:10 +00:00
|
|
|
switch (drv_data->ssp_type) {
|
|
|
|
case PXA25x_SSP:
|
|
|
|
case CE4100_SSP:
|
|
|
|
case QUARK_X1000_SSP:
|
2013-01-22 10:26:28 +00:00
|
|
|
return 1;
|
2014-11-26 10:35:10 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2013-01-22 10:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void write_SSSR_CS(struct driver_data *drv_data, u32 val)
|
|
|
|
{
|
2014-11-26 10:35:10 +00:00
|
|
|
if (drv_data->ssp_type == CE4100_SSP ||
|
|
|
|
drv_data->ssp_type == QUARK_X1000_SSP)
|
2014-12-18 13:04:23 +00:00
|
|
|
val |= pxa2xx_spi_read(drv_data, SSSR) & SSSR_ALT_FRM_MASK;
|
2013-01-22 10:26:28 +00:00
|
|
|
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSSR, val);
|
2013-01-22 10:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern int pxa2xx_spi_flush(struct driver_data *drv_data);
|
|
|
|
|
2013-01-22 10:26:29 +00:00
|
|
|
#define MAX_DMA_LEN SZ_64K
|
|
|
|
#define DEFAULT_DMA_CR1 (SSCR1_TSRE | SSCR1_RSRE | SSCR1_TRAIL)
|
|
|
|
|
2013-01-22 10:26:28 +00:00
|
|
|
extern irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data);
|
2018-04-17 14:20:02 +00:00
|
|
|
extern int pxa2xx_spi_dma_prepare(struct driver_data *drv_data,
|
|
|
|
struct spi_transfer *xfer);
|
2013-01-22 10:26:28 +00:00
|
|
|
extern void pxa2xx_spi_dma_start(struct driver_data *drv_data);
|
2018-04-17 14:20:02 +00:00
|
|
|
extern void pxa2xx_spi_dma_stop(struct driver_data *drv_data);
|
2013-01-22 10:26:28 +00: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 */
|