Skip to content

Commit a0d2642

Browse files
westeribroonie
authored andcommitted
spi/pxa2xx: add support for Intel Low Power Subsystem SPI
Intel LPSS SPI is pretty much the same as the PXA27xx SPI except that it has few additional features over the original: o FIFO depth is 256 entries o RX FIFO has one watermark o TX FIFO has two watermarks, low and high o chip select can be controlled by writing to a register The new FIFO registers follow immediately the PXA27xx registers but then there are some additional LPSS private registers at offset 1k or 2k from the base address. For these private registers we add new accessors that take advantage of drv_data->lpss_base once it is resolved. We add a new type LPSS_SSP that can be used to distinguish the LPSS devices from others. Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> Tested-by: Lu Cao <lucao@marvell.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent b833172 commit a0d2642

4 files changed

Lines changed: 145 additions & 4 deletions

File tree

‎drivers/spi/spi-pxa2xx.c‎

Lines changed: 129 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
3+
* Copyright (C) 2013, Intel Corporation
34
*
45
* This program is free software; you can redistribute it and/or modify
56
* it under the terms of the GNU General Public License as published by
@@ -61,6 +62,98 @@ MODULE_ALIAS("platform:pxa2xx-spi");
6162
| SSCR1_RFT | SSCR1_TFT | SSCR1_MWDS \
6263
| SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
6364

65+
#define LPSS_RX_THRESH_DFLT 64
66+
#define LPSS_TX_LOTHRESH_DFLT 160
67+
#define LPSS_TX_HITHRESH_DFLT 224
68+
69+
/* Offset from drv_data->lpss_base */
70+
#define SPI_CS_CONTROL 0x18
71+
#define SPI_CS_CONTROL_SW_MODE BIT(0)
72+
#define SPI_CS_CONTROL_CS_HIGH BIT(1)
73+
74+
static bool is_lpss_ssp(const struct driver_data *drv_data)
75+
{
76+
return drv_data->ssp_type == LPSS_SSP;
77+
}
78+
79+
/*
80+
* Read and write LPSS SSP private registers. Caller must first check that
81+
* is_lpss_ssp() returns true before these can be called.
82+
*/
83+
static u32 __lpss_ssp_read_priv(struct driver_data *drv_data, unsigned offset)
84+
{
85+
WARN_ON(!drv_data->lpss_base);
86+
return readl(drv_data->lpss_base + offset);
87+
}
88+
89+
static void __lpss_ssp_write_priv(struct driver_data *drv_data,
90+
unsigned offset, u32 value)
91+
{
92+
WARN_ON(!drv_data->lpss_base);
93+
writel(value, drv_data->lpss_base + offset);
94+
}
95+
96+
/*
97+
* lpss_ssp_setup - perform LPSS SSP specific setup
98+
* @drv_data: pointer to the driver private data
99+
*
100+
* Perform LPSS SSP specific setup. This function must be called first if
101+
* one is going to use LPSS SSP private registers.
102+
*/
103+
static void lpss_ssp_setup(struct driver_data *drv_data)
104+
{
105+
unsigned offset = 0x400;
106+
u32 value, orig;
107+
108+
if (!is_lpss_ssp(drv_data))
109+
return;
110+
111+
/*
112+
* Perform auto-detection of the LPSS SSP private registers. They
113+
* can be either at 1k or 2k offset from the base address.
114+
*/
115+
orig = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL);
116+
117+
value = orig | SPI_CS_CONTROL_SW_MODE;
118+
writel(value, drv_data->ioaddr + offset + SPI_CS_CONTROL);
119+
value = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL);
120+
if (value != (orig | SPI_CS_CONTROL_SW_MODE)) {
121+
offset = 0x800;
122+
goto detection_done;
123+
}
124+
125+
value &= ~SPI_CS_CONTROL_SW_MODE;
126+
writel(value, drv_data->ioaddr + offset + SPI_CS_CONTROL);
127+
value = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL);
128+
if (value != orig) {
129+
offset = 0x800;
130+
goto detection_done;
131+
}
132+
133+
detection_done:
134+
/* Now set the LPSS base */
135+
drv_data->lpss_base = drv_data->ioaddr + offset;
136+
137+
/* Enable software chip select control */
138+
value = SPI_CS_CONTROL_SW_MODE | SPI_CS_CONTROL_CS_HIGH;
139+
__lpss_ssp_write_priv(drv_data, SPI_CS_CONTROL, value);
140+
}
141+
142+
static void lpss_ssp_cs_control(struct driver_data *drv_data, bool enable)
143+
{
144+
u32 value;
145+
146+
if (!is_lpss_ssp(drv_data))
147+
return;
148+
149+
value = __lpss_ssp_read_priv(drv_data, SPI_CS_CONTROL);
150+
if (enable)
151+
value &= ~SPI_CS_CONTROL_CS_HIGH;
152+
else
153+
value |= SPI_CS_CONTROL_CS_HIGH;
154+
__lpss_ssp_write_priv(drv_data, SPI_CS_CONTROL, value);
155+
}
156+
64157
static void cs_assert(struct driver_data *drv_data)
65158
{
66159
struct chip_data *chip = drv_data->cur_chip;
@@ -75,8 +168,12 @@ static void cs_assert(struct driver_data *drv_data)
75168
return;
76169
}
77170

78-
if (gpio_is_valid(chip->gpio_cs))
171+
if (gpio_is_valid(chip->gpio_cs)) {
79172
gpio_set_value(chip->gpio_cs, chip->gpio_cs_inverted);
173+
return;
174+
}
175+
176+
lpss_ssp_cs_control(drv_data, true);
80177
}
81178

82179
static void cs_deassert(struct driver_data *drv_data)
@@ -91,8 +188,12 @@ static void cs_deassert(struct driver_data *drv_data)
91188
return;
92189
}
93190

94-
if (gpio_is_valid(chip->gpio_cs))
191+
if (gpio_is_valid(chip->gpio_cs)) {
95192
gpio_set_value(chip->gpio_cs, !chip->gpio_cs_inverted);
193+
return;
194+
}
195+
196+
lpss_ssp_cs_control(drv_data, false);
96197
}
97198

98199
int pxa2xx_spi_flush(struct driver_data *drv_data)
@@ -642,6 +743,13 @@ static void pump_transfers(unsigned long data)
642743
write_SSSR_CS(drv_data, drv_data->clear_sr);
643744
}
644745

746+
if (is_lpss_ssp(drv_data)) {
747+
if ((read_SSIRF(reg) & 0xff) != chip->lpss_rx_threshold)
748+
write_SSIRF(chip->lpss_rx_threshold, reg);
749+
if ((read_SSITF(reg) & 0xffff) != chip->lpss_tx_threshold)
750+
write_SSITF(chip->lpss_tx_threshold, reg);
751+
}
752+
645753
/* see if we need to reload the config registers */
646754
if ((read_SSCR0(reg) != cr0)
647755
|| (read_SSCR1(reg) & SSCR1_CHANGE_MASK) !=
@@ -754,8 +862,17 @@ static int setup(struct spi_device *spi)
754862
struct chip_data *chip;
755863
struct driver_data *drv_data = spi_master_get_devdata(spi->master);
756864
unsigned int clk_div;
757-
uint tx_thres = TX_THRESH_DFLT;
758-
uint rx_thres = RX_THRESH_DFLT;
865+
uint tx_thres, tx_hi_thres, rx_thres;
866+
867+
if (is_lpss_ssp(drv_data)) {
868+
tx_thres = LPSS_TX_LOTHRESH_DFLT;
869+
tx_hi_thres = LPSS_TX_HITHRESH_DFLT;
870+
rx_thres = LPSS_RX_THRESH_DFLT;
871+
} else {
872+
tx_thres = TX_THRESH_DFLT;
873+
tx_hi_thres = 0;
874+
rx_thres = RX_THRESH_DFLT;
875+
}
759876

760877
if (!pxa25x_ssp_comp(drv_data)
761878
&& (spi->bits_per_word < 4 || spi->bits_per_word > 32)) {
@@ -808,6 +925,8 @@ static int setup(struct spi_device *spi)
808925
chip->timeout = chip_info->timeout;
809926
if (chip_info->tx_threshold)
810927
tx_thres = chip_info->tx_threshold;
928+
if (chip_info->tx_hi_threshold)
929+
tx_hi_thres = chip_info->tx_hi_threshold;
811930
if (chip_info->rx_threshold)
812931
rx_thres = chip_info->rx_threshold;
813932
chip->enable_dma = drv_data->master_info->enable_dma;
@@ -819,6 +938,10 @@ static int setup(struct spi_device *spi)
819938
chip->threshold = (SSCR1_RxTresh(rx_thres) & SSCR1_RFT) |
820939
(SSCR1_TxTresh(tx_thres) & SSCR1_TFT);
821940

941+
chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres);
942+
chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres)
943+
| SSITF_TxHiThresh(tx_hi_thres);
944+
822945
/* set dma burst and threshold outside of chip_info path so that if
823946
* chip_info goes away after setting chip->enable_dma, the
824947
* burst and threshold can still respond to changes in bits_per_word */
@@ -1006,6 +1129,8 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
10061129
write_SSTO(0, drv_data->ioaddr);
10071130
write_SSPSP(0, drv_data->ioaddr);
10081131

1132+
lpss_ssp_setup(drv_data);
1133+
10091134
tasklet_init(&drv_data->pump_transfers, pump_transfers,
10101135
(unsigned long)drv_data);
10111136

‎drivers/spi/spi-pxa2xx.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ struct driver_data {
8686
int (*read)(struct driver_data *drv_data);
8787
irqreturn_t (*transfer_handler)(struct driver_data *drv_data);
8888
void (*cs_control)(u32 command);
89+
90+
void __iomem *lpss_base;
8991
};
9092

9193
struct chip_data {
@@ -97,6 +99,8 @@ struct chip_data {
9799
u32 dma_burst_size;
98100
u32 threshold;
99101
u32 dma_threshold;
102+
u16 lpss_rx_threshold;
103+
u16 lpss_tx_threshold;
100104
u8 enable_dma;
101105
u8 bits_per_word;
102106
u32 speed_hz;
@@ -124,6 +128,8 @@ DEFINE_SSP_REG(SSITR, 0x0c)
124128
DEFINE_SSP_REG(SSDR, 0x10)
125129
DEFINE_SSP_REG(SSTO, 0x28)
126130
DEFINE_SSP_REG(SSPSP, 0x2c)
131+
DEFINE_SSP_REG(SSITF, SSITF)
132+
DEFINE_SSP_REG(SSIRF, SSIRF)
127133

128134
#define START_STATE ((void *)0)
129135
#define RUNNING_STATE ((void *)1)

‎include/linux/pxa2xx_ssp.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@
155155
#define SSACD_ACDS(x) ((x) << 0) /* Audio clock divider select */
156156
#define SSACD_SCDX8 (1 << 7) /* SYSCLK division ratio select */
157157

158+
/* LPSS SSP */
159+
#define SSITF 0x44 /* TX FIFO trigger level */
160+
#define SSITF_TxLoThresh(x) (((x) - 1) << 8)
161+
#define SSITF_TxHiThresh(x) ((x) - 1)
162+
163+
#define SSIRF 0x48 /* RX FIFO trigger level */
164+
#define SSIRF_RxThresh(x) ((x) - 1)
165+
158166
enum pxa_ssp_type {
159167
SSP_UNDEFINED = 0,
160168
PXA25x_SSP, /* pxa 210, 250, 255, 26x */
@@ -164,6 +172,7 @@ enum pxa_ssp_type {
164172
PXA168_SSP,
165173
PXA910_SSP,
166174
CE4100_SSP,
175+
LPSS_SSP,
167176
};
168177

169178
struct ssp_device {

‎include/linux/spi/pxa2xx_spi.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct pxa2xx_spi_master {
4444
*/
4545
struct pxa2xx_spi_chip {
4646
u8 tx_threshold;
47+
u8 tx_hi_threshold;
4748
u8 rx_threshold;
4849
u8 dma_burst_size;
4950
u32 timeout;

0 commit comments

Comments
 (0)