blob: 5e2ed7d34487215643cd42639567134449ad3bd5 [file] [log] [blame]
Stephen Streete0c99052006-03-07 23:53:24 -08001/*
2 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
Mika Westerberga0d26422013-01-22 12:26:32 +02003 * Copyright (C) 2013, Intel Corporation
Stephen Streete0c99052006-03-07 23:53:24 -08004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Stephen Streete0c99052006-03-07 23:53:24 -080014 */
15
Jarkko Nikula8b136ba2015-10-28 15:13:41 +020016#include <linux/bitops.h>
Stephen Streete0c99052006-03-07 23:53:24 -080017#include <linux/init.h>
18#include <linux/module.h>
19#include <linux/device.h>
20#include <linux/ioport.h>
21#include <linux/errno.h>
Sachin Kamatcbfd6a22013-04-08 15:49:33 +053022#include <linux/err.h>
Stephen Streete0c99052006-03-07 23:53:24 -080023#include <linux/interrupt.h>
Andy Shevchenko9df461e2015-03-25 15:06:16 +020024#include <linux/kernel.h>
Jarkko Nikula34cadd92015-07-30 16:30:07 +030025#include <linux/pci.h>
Stephen Streete0c99052006-03-07 23:53:24 -080026#include <linux/platform_device.h>
Sebastian Andrzej Siewior8348c252010-11-22 17:12:15 -080027#include <linux/spi/pxa2xx_spi.h>
Stephen Streete0c99052006-03-07 23:53:24 -080028#include <linux/spi/spi.h>
Stephen Streete0c99052006-03-07 23:53:24 -080029#include <linux/delay.h>
Eric Miaoa7bb3902009-04-06 19:00:54 -070030#include <linux/gpio.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Mika Westerberg3343b7a2013-01-22 12:26:27 +020032#include <linux/clk.h>
Mika Westerberg7d94a502013-01-22 12:26:30 +020033#include <linux/pm_runtime.h>
Mika Westerberga3496852013-01-22 12:26:33 +020034#include <linux/acpi.h>
Stephen Streete0c99052006-03-07 23:53:24 -080035
Mika Westerbergcd7bed02013-01-22 12:26:28 +020036#include "spi-pxa2xx.h"
Stephen Streete0c99052006-03-07 23:53:24 -080037
38MODULE_AUTHOR("Stephen Street");
Will Newton037cdaf2007-12-10 15:49:25 -080039MODULE_DESCRIPTION("PXA2xx SSP SPI Controller");
Stephen Streete0c99052006-03-07 23:53:24 -080040MODULE_LICENSE("GPL");
Kay Sievers7e38c3c2008-04-10 21:29:20 -070041MODULE_ALIAS("platform:pxa2xx-spi");
Stephen Streete0c99052006-03-07 23:53:24 -080042
Vernon Sauderf1f640a2008-10-15 22:02:43 -070043#define TIMOUT_DFLT 1000
44
Ned Forresterb97c74b2008-02-23 15:23:40 -080045/*
46 * for testing SSCR1 changes that require SSP restart, basically
47 * everything except the service and interrupt enables, the pxa270 developer
48 * manual says only SSCR1_SCFR, SSCR1_SPH, SSCR1_SPO need to be in this
49 * list, but the PXA255 dev man says all bits without really meaning the
50 * service and interrupt enables
51 */
52#define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \
Stephen Street8d94cc52006-12-10 02:18:54 -080053 | SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
Ned Forresterb97c74b2008-02-23 15:23:40 -080054 | SSCR1_SFRMDIR | SSCR1_RWOT | SSCR1_TRAIL \
55 | SSCR1_IFS | SSCR1_STRF | SSCR1_EFWR \
56 | SSCR1_RFT | SSCR1_TFT | SSCR1_MWDS \
57 | SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
Stephen Street8d94cc52006-12-10 02:18:54 -080058
Weike Chene5262d02014-11-26 02:35:10 -080059#define QUARK_X1000_SSCR1_CHANGE_MASK (QUARK_X1000_SSCR1_STRF \
60 | QUARK_X1000_SSCR1_EFWR \
61 | QUARK_X1000_SSCR1_RFT \
62 | QUARK_X1000_SSCR1_TFT \
63 | SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
64
Andy Shevchenko7c7289a2016-09-07 15:43:22 +030065#define CE4100_SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \
66 | SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
67 | SSCR1_SFRMDIR | SSCR1_RWOT | SSCR1_TRAIL \
68 | SSCR1_IFS | SSCR1_STRF | SSCR1_EFWR \
69 | CE4100_SSCR1_RFT | CE4100_SSCR1_TFT | SSCR1_MWDS \
70 | SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
71
Jarkko Nikula624ea722015-10-28 15:13:39 +020072#define LPSS_GENERAL_REG_RXTO_HOLDOFF_DISABLE BIT(24)
73#define LPSS_CS_CONTROL_SW_MODE BIT(0)
74#define LPSS_CS_CONTROL_CS_HIGH BIT(1)
Jarkko Nikula8b136ba2015-10-28 15:13:41 +020075#define LPSS_CAPS_CS_EN_SHIFT 9
76#define LPSS_CAPS_CS_EN_MASK (0xf << LPSS_CAPS_CS_EN_SHIFT)
Mika Westerberga0d26422013-01-22 12:26:32 +020077
Jarkko Nikuladccf7362015-06-04 16:55:11 +030078struct lpss_config {
79 /* LPSS offset from drv_data->ioaddr */
80 unsigned offset;
81 /* Register offsets from drv_data->lpss_base or -1 */
82 int reg_general;
83 int reg_ssp;
84 int reg_cs_ctrl;
Jarkko Nikula8b136ba2015-10-28 15:13:41 +020085 int reg_capabilities;
Jarkko Nikuladccf7362015-06-04 16:55:11 +030086 /* FIFO thresholds */
87 u32 rx_threshold;
88 u32 tx_threshold_lo;
89 u32 tx_threshold_hi;
Mika Westerbergc1e4a532016-02-08 17:14:30 +020090 /* Chip select control */
91 unsigned cs_sel_shift;
92 unsigned cs_sel_mask;
Mika Westerberg30f3a6a2016-02-08 17:14:31 +020093 unsigned cs_num;
Jarkko Nikuladccf7362015-06-04 16:55:11 +030094};
95
96/* Keep these sorted with enum pxa_ssp_type */
97static const struct lpss_config lpss_platforms[] = {
98 { /* LPSS_LPT_SSP */
99 .offset = 0x800,
100 .reg_general = 0x08,
101 .reg_ssp = 0x0c,
102 .reg_cs_ctrl = 0x18,
Jarkko Nikula8b136ba2015-10-28 15:13:41 +0200103 .reg_capabilities = -1,
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300104 .rx_threshold = 64,
105 .tx_threshold_lo = 160,
106 .tx_threshold_hi = 224,
107 },
108 { /* LPSS_BYT_SSP */
109 .offset = 0x400,
110 .reg_general = 0x08,
111 .reg_ssp = 0x0c,
112 .reg_cs_ctrl = 0x18,
Jarkko Nikula8b136ba2015-10-28 15:13:41 +0200113 .reg_capabilities = -1,
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300114 .rx_threshold = 64,
115 .tx_threshold_lo = 160,
116 .tx_threshold_hi = 224,
117 },
Mika Westerberg30f3a6a2016-02-08 17:14:31 +0200118 { /* LPSS_BSW_SSP */
119 .offset = 0x400,
120 .reg_general = 0x08,
121 .reg_ssp = 0x0c,
122 .reg_cs_ctrl = 0x18,
123 .reg_capabilities = -1,
124 .rx_threshold = 64,
125 .tx_threshold_lo = 160,
126 .tx_threshold_hi = 224,
127 .cs_sel_shift = 2,
128 .cs_sel_mask = 1 << 2,
129 .cs_num = 2,
130 },
Jarkko Nikula34cadd92015-07-30 16:30:07 +0300131 { /* LPSS_SPT_SSP */
132 .offset = 0x200,
133 .reg_general = -1,
134 .reg_ssp = 0x20,
135 .reg_cs_ctrl = 0x24,
Jarkko Nikula66ec2462016-04-26 10:08:26 +0300136 .reg_capabilities = -1,
Jarkko Nikula34cadd92015-07-30 16:30:07 +0300137 .rx_threshold = 1,
138 .tx_threshold_lo = 32,
139 .tx_threshold_hi = 56,
140 },
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +0200141 { /* LPSS_BXT_SSP */
142 .offset = 0x200,
143 .reg_general = -1,
144 .reg_ssp = 0x20,
145 .reg_cs_ctrl = 0x24,
146 .reg_capabilities = 0xfc,
147 .rx_threshold = 1,
148 .tx_threshold_lo = 16,
149 .tx_threshold_hi = 48,
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200150 .cs_sel_shift = 8,
151 .cs_sel_mask = 3 << 8,
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +0200152 },
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300153};
154
155static inline const struct lpss_config
156*lpss_get_config(const struct driver_data *drv_data)
157{
158 return &lpss_platforms[drv_data->ssp_type - LPSS_LPT_SSP];
159}
160
Mika Westerberga0d26422013-01-22 12:26:32 +0200161static bool is_lpss_ssp(const struct driver_data *drv_data)
162{
Jarkko Nikula03fbf482015-06-04 16:55:10 +0300163 switch (drv_data->ssp_type) {
164 case LPSS_LPT_SSP:
165 case LPSS_BYT_SSP:
Mika Westerberg30f3a6a2016-02-08 17:14:31 +0200166 case LPSS_BSW_SSP:
Jarkko Nikula34cadd92015-07-30 16:30:07 +0300167 case LPSS_SPT_SSP:
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +0200168 case LPSS_BXT_SSP:
Jarkko Nikula03fbf482015-06-04 16:55:10 +0300169 return true;
170 default:
171 return false;
172 }
Mika Westerberga0d26422013-01-22 12:26:32 +0200173}
174
Weike Chene5262d02014-11-26 02:35:10 -0800175static bool is_quark_x1000_ssp(const struct driver_data *drv_data)
176{
177 return drv_data->ssp_type == QUARK_X1000_SSP;
178}
179
Weike Chen4fdb2422014-10-08 08:50:22 -0700180static u32 pxa2xx_spi_get_ssrc1_change_mask(const struct driver_data *drv_data)
181{
182 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800183 case QUARK_X1000_SSP:
184 return QUARK_X1000_SSCR1_CHANGE_MASK;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300185 case CE4100_SSP:
186 return CE4100_SSCR1_CHANGE_MASK;
Weike Chen4fdb2422014-10-08 08:50:22 -0700187 default:
188 return SSCR1_CHANGE_MASK;
189 }
190}
191
192static u32
193pxa2xx_spi_get_rx_default_thre(const struct driver_data *drv_data)
194{
195 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800196 case QUARK_X1000_SSP:
197 return RX_THRESH_QUARK_X1000_DFLT;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300198 case CE4100_SSP:
199 return RX_THRESH_CE4100_DFLT;
Weike Chen4fdb2422014-10-08 08:50:22 -0700200 default:
201 return RX_THRESH_DFLT;
202 }
203}
204
205static bool pxa2xx_spi_txfifo_full(const struct driver_data *drv_data)
206{
Weike Chen4fdb2422014-10-08 08:50:22 -0700207 u32 mask;
208
209 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800210 case QUARK_X1000_SSP:
211 mask = QUARK_X1000_SSSR_TFL_MASK;
212 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300213 case CE4100_SSP:
214 mask = CE4100_SSSR_TFL_MASK;
215 break;
Weike Chen4fdb2422014-10-08 08:50:22 -0700216 default:
217 mask = SSSR_TFL_MASK;
218 break;
219 }
220
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200221 return (pxa2xx_spi_read(drv_data, SSSR) & mask) == mask;
Weike Chen4fdb2422014-10-08 08:50:22 -0700222}
223
224static void pxa2xx_spi_clear_rx_thre(const struct driver_data *drv_data,
225 u32 *sccr1_reg)
226{
227 u32 mask;
228
229 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800230 case QUARK_X1000_SSP:
231 mask = QUARK_X1000_SSCR1_RFT;
232 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300233 case CE4100_SSP:
234 mask = CE4100_SSCR1_RFT;
235 break;
Weike Chen4fdb2422014-10-08 08:50:22 -0700236 default:
237 mask = SSCR1_RFT;
238 break;
239 }
240 *sccr1_reg &= ~mask;
241}
242
243static void pxa2xx_spi_set_rx_thre(const struct driver_data *drv_data,
244 u32 *sccr1_reg, u32 threshold)
245{
246 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800247 case QUARK_X1000_SSP:
248 *sccr1_reg |= QUARK_X1000_SSCR1_RxTresh(threshold);
249 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300250 case CE4100_SSP:
251 *sccr1_reg |= CE4100_SSCR1_RxTresh(threshold);
252 break;
Weike Chen4fdb2422014-10-08 08:50:22 -0700253 default:
254 *sccr1_reg |= SSCR1_RxTresh(threshold);
255 break;
256 }
257}
258
259static u32 pxa2xx_configure_sscr0(const struct driver_data *drv_data,
260 u32 clk_div, u8 bits)
261{
262 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800263 case QUARK_X1000_SSP:
264 return clk_div
265 | QUARK_X1000_SSCR0_Motorola
266 | QUARK_X1000_SSCR0_DataSize(bits > 32 ? 8 : bits)
267 | SSCR0_SSE;
Weike Chen4fdb2422014-10-08 08:50:22 -0700268 default:
269 return clk_div
270 | SSCR0_Motorola
271 | SSCR0_DataSize(bits > 16 ? bits - 16 : bits)
272 | SSCR0_SSE
273 | (bits > 16 ? SSCR0_EDSS : 0);
274 }
275}
276
Mika Westerberga0d26422013-01-22 12:26:32 +0200277/*
278 * Read and write LPSS SSP private registers. Caller must first check that
279 * is_lpss_ssp() returns true before these can be called.
280 */
281static u32 __lpss_ssp_read_priv(struct driver_data *drv_data, unsigned offset)
282{
283 WARN_ON(!drv_data->lpss_base);
284 return readl(drv_data->lpss_base + offset);
285}
286
287static void __lpss_ssp_write_priv(struct driver_data *drv_data,
288 unsigned offset, u32 value)
289{
290 WARN_ON(!drv_data->lpss_base);
291 writel(value, drv_data->lpss_base + offset);
292}
293
294/*
295 * lpss_ssp_setup - perform LPSS SSP specific setup
296 * @drv_data: pointer to the driver private data
297 *
298 * Perform LPSS SSP specific setup. This function must be called first if
299 * one is going to use LPSS SSP private registers.
300 */
301static void lpss_ssp_setup(struct driver_data *drv_data)
302{
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300303 const struct lpss_config *config;
304 u32 value;
Mika Westerberga0d26422013-01-22 12:26:32 +0200305
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300306 config = lpss_get_config(drv_data);
307 drv_data->lpss_base = drv_data->ioaddr + config->offset;
Mika Westerberga0d26422013-01-22 12:26:32 +0200308
309 /* Enable software chip select control */
Jarkko Nikula0e897212015-10-22 16:44:42 +0300310 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
Jarkko Nikula624ea722015-10-28 15:13:39 +0200311 value &= ~(LPSS_CS_CONTROL_SW_MODE | LPSS_CS_CONTROL_CS_HIGH);
312 value |= LPSS_CS_CONTROL_SW_MODE | LPSS_CS_CONTROL_CS_HIGH;
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300313 __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value);
Mika Westerberg0054e282013-03-05 12:05:17 +0200314
315 /* Enable multiblock DMA transfers */
Mika Westerberg1de70612013-07-03 13:25:06 +0300316 if (drv_data->master_info->enable_dma) {
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300317 __lpss_ssp_write_priv(drv_data, config->reg_ssp, 1);
Mika Westerberg1de70612013-07-03 13:25:06 +0300318
Jarkko Nikula82ba2c22015-06-04 16:55:12 +0300319 if (config->reg_general >= 0) {
320 value = __lpss_ssp_read_priv(drv_data,
321 config->reg_general);
Jarkko Nikula624ea722015-10-28 15:13:39 +0200322 value |= LPSS_GENERAL_REG_RXTO_HOLDOFF_DISABLE;
Jarkko Nikula82ba2c22015-06-04 16:55:12 +0300323 __lpss_ssp_write_priv(drv_data,
324 config->reg_general, value);
325 }
Mika Westerberg1de70612013-07-03 13:25:06 +0300326 }
Mika Westerberga0d26422013-01-22 12:26:32 +0200327}
328
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200329static void lpss_ssp_select_cs(struct driver_data *drv_data,
330 const struct lpss_config *config)
331{
332 u32 value, cs;
333
334 if (!config->cs_sel_mask)
335 return;
336
337 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
338
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300339 cs = drv_data->master->cur_msg->spi->chip_select;
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200340 cs <<= config->cs_sel_shift;
341 if (cs != (value & config->cs_sel_mask)) {
342 /*
343 * When switching another chip select output active the
344 * output must be selected first and wait 2 ssp_clk cycles
345 * before changing state to active. Otherwise a short
346 * glitch will occur on the previous chip select since
347 * output select is latched but state control is not.
348 */
349 value &= ~config->cs_sel_mask;
350 value |= cs;
351 __lpss_ssp_write_priv(drv_data,
352 config->reg_cs_ctrl, value);
353 ndelay(1000000000 /
354 (drv_data->master->max_speed_hz / 2));
355 }
356}
357
Mika Westerberga0d26422013-01-22 12:26:32 +0200358static void lpss_ssp_cs_control(struct driver_data *drv_data, bool enable)
359{
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300360 const struct lpss_config *config;
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200361 u32 value;
Mika Westerberga0d26422013-01-22 12:26:32 +0200362
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300363 config = lpss_get_config(drv_data);
364
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200365 if (enable)
366 lpss_ssp_select_cs(drv_data, config);
367
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300368 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200369 if (enable)
Jarkko Nikula624ea722015-10-28 15:13:39 +0200370 value &= ~LPSS_CS_CONTROL_CS_HIGH;
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200371 else
Jarkko Nikula624ea722015-10-28 15:13:39 +0200372 value |= LPSS_CS_CONTROL_CS_HIGH;
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300373 __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value);
Mika Westerberga0d26422013-01-22 12:26:32 +0200374}
375
Eric Miaoa7bb3902009-04-06 19:00:54 -0700376static void cs_assert(struct driver_data *drv_data)
377{
Jarkko Nikula96579a42016-09-07 17:04:07 +0300378 struct chip_data *chip =
379 spi_get_ctldata(drv_data->master->cur_msg->spi);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700380
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800381 if (drv_data->ssp_type == CE4100_SSP) {
Jarkko Nikula96579a42016-09-07 17:04:07 +0300382 pxa2xx_spi_write(drv_data, SSSR, chip->frm);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800383 return;
384 }
385
Eric Miaoa7bb3902009-04-06 19:00:54 -0700386 if (chip->cs_control) {
387 chip->cs_control(PXA2XX_CS_ASSERT);
388 return;
389 }
390
Mika Westerberga0d26422013-01-22 12:26:32 +0200391 if (gpio_is_valid(chip->gpio_cs)) {
Eric Miaoa7bb3902009-04-06 19:00:54 -0700392 gpio_set_value(chip->gpio_cs, chip->gpio_cs_inverted);
Mika Westerberga0d26422013-01-22 12:26:32 +0200393 return;
394 }
395
Jarkko Nikula7566bcc2014-12-18 15:04:20 +0200396 if (is_lpss_ssp(drv_data))
397 lpss_ssp_cs_control(drv_data, true);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700398}
399
400static void cs_deassert(struct driver_data *drv_data)
401{
Jarkko Nikula96579a42016-09-07 17:04:07 +0300402 struct chip_data *chip =
403 spi_get_ctldata(drv_data->master->cur_msg->spi);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700404
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800405 if (drv_data->ssp_type == CE4100_SSP)
406 return;
407
Eric Miaoa7bb3902009-04-06 19:00:54 -0700408 if (chip->cs_control) {
Daniel Ribeiro2b2562d2009-04-08 22:48:03 -0300409 chip->cs_control(PXA2XX_CS_DEASSERT);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700410 return;
411 }
412
Mika Westerberga0d26422013-01-22 12:26:32 +0200413 if (gpio_is_valid(chip->gpio_cs)) {
Eric Miaoa7bb3902009-04-06 19:00:54 -0700414 gpio_set_value(chip->gpio_cs, !chip->gpio_cs_inverted);
Mika Westerberga0d26422013-01-22 12:26:32 +0200415 return;
416 }
417
Jarkko Nikula7566bcc2014-12-18 15:04:20 +0200418 if (is_lpss_ssp(drv_data))
419 lpss_ssp_cs_control(drv_data, false);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700420}
421
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200422int pxa2xx_spi_flush(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800423{
424 unsigned long limit = loops_per_jiffy << 1;
425
Stephen Streete0c99052006-03-07 23:53:24 -0800426 do {
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200427 while (pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
428 pxa2xx_spi_read(drv_data, SSDR);
429 } while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY) && --limit);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800430 write_SSSR_CS(drv_data, SSSR_ROR);
Stephen Streete0c99052006-03-07 23:53:24 -0800431
432 return limit;
433}
434
Stephen Street8d94cc52006-12-10 02:18:54 -0800435static int null_writer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800436{
Stephen Street9708c122006-03-28 14:05:23 -0800437 u8 n_bytes = drv_data->n_bytes;
Stephen Streete0c99052006-03-07 23:53:24 -0800438
Weike Chen4fdb2422014-10-08 08:50:22 -0700439 if (pxa2xx_spi_txfifo_full(drv_data)
Stephen Street8d94cc52006-12-10 02:18:54 -0800440 || (drv_data->tx == drv_data->tx_end))
441 return 0;
442
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200443 pxa2xx_spi_write(drv_data, SSDR, 0);
Stephen Street8d94cc52006-12-10 02:18:54 -0800444 drv_data->tx += n_bytes;
445
446 return 1;
Stephen Streete0c99052006-03-07 23:53:24 -0800447}
448
Stephen Street8d94cc52006-12-10 02:18:54 -0800449static int null_reader(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800450{
Stephen Street9708c122006-03-28 14:05:23 -0800451 u8 n_bytes = drv_data->n_bytes;
Stephen Streete0c99052006-03-07 23:53:24 -0800452
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200453 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
454 && (drv_data->rx < drv_data->rx_end)) {
455 pxa2xx_spi_read(drv_data, SSDR);
Stephen Streete0c99052006-03-07 23:53:24 -0800456 drv_data->rx += n_bytes;
457 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800458
459 return drv_data->rx == drv_data->rx_end;
Stephen Streete0c99052006-03-07 23:53:24 -0800460}
461
Stephen Street8d94cc52006-12-10 02:18:54 -0800462static int u8_writer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800463{
Weike Chen4fdb2422014-10-08 08:50:22 -0700464 if (pxa2xx_spi_txfifo_full(drv_data)
Stephen Street8d94cc52006-12-10 02:18:54 -0800465 || (drv_data->tx == drv_data->tx_end))
466 return 0;
467
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200468 pxa2xx_spi_write(drv_data, SSDR, *(u8 *)(drv_data->tx));
Stephen Street8d94cc52006-12-10 02:18:54 -0800469 ++drv_data->tx;
470
471 return 1;
Stephen Streete0c99052006-03-07 23:53:24 -0800472}
473
Stephen Street8d94cc52006-12-10 02:18:54 -0800474static int u8_reader(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800475{
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200476 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
477 && (drv_data->rx < drv_data->rx_end)) {
478 *(u8 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
Stephen Streete0c99052006-03-07 23:53:24 -0800479 ++drv_data->rx;
480 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800481
482 return drv_data->rx == drv_data->rx_end;
Stephen Streete0c99052006-03-07 23:53:24 -0800483}
484
Stephen Street8d94cc52006-12-10 02:18:54 -0800485static int u16_writer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800486{
Weike Chen4fdb2422014-10-08 08:50:22 -0700487 if (pxa2xx_spi_txfifo_full(drv_data)
Stephen Street8d94cc52006-12-10 02:18:54 -0800488 || (drv_data->tx == drv_data->tx_end))
489 return 0;
490
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200491 pxa2xx_spi_write(drv_data, SSDR, *(u16 *)(drv_data->tx));
Stephen Street8d94cc52006-12-10 02:18:54 -0800492 drv_data->tx += 2;
493
494 return 1;
Stephen Streete0c99052006-03-07 23:53:24 -0800495}
496
Stephen Street8d94cc52006-12-10 02:18:54 -0800497static int u16_reader(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800498{
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200499 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
500 && (drv_data->rx < drv_data->rx_end)) {
501 *(u16 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
Stephen Streete0c99052006-03-07 23:53:24 -0800502 drv_data->rx += 2;
503 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800504
505 return drv_data->rx == drv_data->rx_end;
Stephen Streete0c99052006-03-07 23:53:24 -0800506}
Stephen Street8d94cc52006-12-10 02:18:54 -0800507
508static int u32_writer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800509{
Weike Chen4fdb2422014-10-08 08:50:22 -0700510 if (pxa2xx_spi_txfifo_full(drv_data)
Stephen Street8d94cc52006-12-10 02:18:54 -0800511 || (drv_data->tx == drv_data->tx_end))
512 return 0;
513
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200514 pxa2xx_spi_write(drv_data, SSDR, *(u32 *)(drv_data->tx));
Stephen Street8d94cc52006-12-10 02:18:54 -0800515 drv_data->tx += 4;
516
517 return 1;
Stephen Streete0c99052006-03-07 23:53:24 -0800518}
519
Stephen Street8d94cc52006-12-10 02:18:54 -0800520static int u32_reader(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800521{
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200522 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
523 && (drv_data->rx < drv_data->rx_end)) {
524 *(u32 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
Stephen Streete0c99052006-03-07 23:53:24 -0800525 drv_data->rx += 4;
526 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800527
528 return drv_data->rx == drv_data->rx_end;
Stephen Streete0c99052006-03-07 23:53:24 -0800529}
530
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200531void *pxa2xx_spi_next_transfer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800532{
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300533 struct spi_message *msg = drv_data->master->cur_msg;
Stephen Streete0c99052006-03-07 23:53:24 -0800534 struct spi_transfer *trans = drv_data->cur_transfer;
535
536 /* Move to next transfer */
537 if (trans->transfer_list.next != &msg->transfers) {
538 drv_data->cur_transfer =
539 list_entry(trans->transfer_list.next,
540 struct spi_transfer,
541 transfer_list);
542 return RUNNING_STATE;
543 } else
544 return DONE_STATE;
545}
546
Stephen Streete0c99052006-03-07 23:53:24 -0800547/* caller already set message->status; dma and pio irqs are blocked */
Stephen Street5daa3ba2006-05-20 15:00:19 -0700548static void giveback(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800549{
550 struct spi_transfer* last_transfer;
Stephen Street5daa3ba2006-05-20 15:00:19 -0700551 struct spi_message *msg;
Jarkko Nikula7a8d44b2016-02-04 12:30:57 +0200552 unsigned long timeout;
Stephen Streete0c99052006-03-07 23:53:24 -0800553
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300554 msg = drv_data->master->cur_msg;
Stephen Street5daa3ba2006-05-20 15:00:19 -0700555 drv_data->cur_transfer = NULL;
Stephen Street5daa3ba2006-05-20 15:00:19 -0700556
Axel Lin23e2c2a2014-02-12 22:13:27 +0800557 last_transfer = list_last_entry(&msg->transfers, struct spi_transfer,
Stephen Streete0c99052006-03-07 23:53:24 -0800558 transfer_list);
559
Ned Forrester84235972008-09-13 02:33:17 -0700560 /* Delay if requested before any change in chip select */
561 if (last_transfer->delay_usecs)
562 udelay(last_transfer->delay_usecs);
563
Jarkko Nikula7a8d44b2016-02-04 12:30:57 +0200564 /* Wait until SSP becomes idle before deasserting the CS */
565 timeout = jiffies + msecs_to_jiffies(10);
566 while (pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY &&
567 !time_after(jiffies, timeout))
568 cpu_relax();
569
Ned Forrester84235972008-09-13 02:33:17 -0700570 /* Drop chip select UNLESS cs_change is true or we are returning
571 * a message with an error, or next message is for another chip
572 */
Stephen Streete0c99052006-03-07 23:53:24 -0800573 if (!last_transfer->cs_change)
Eric Miaoa7bb3902009-04-06 19:00:54 -0700574 cs_deassert(drv_data);
Ned Forrester84235972008-09-13 02:33:17 -0700575 else {
576 struct spi_message *next_msg;
577
578 /* Holding of cs was hinted, but we need to make sure
579 * the next message is for the same chip. Don't waste
580 * time with the following tests unless this was hinted.
581 *
582 * We cannot postpone this until pump_messages, because
583 * after calling msg->complete (below) the driver that
584 * sent the current message could be unloaded, which
585 * could invalidate the cs_control() callback...
586 */
587
588 /* get a pointer to the next message, if any */
Mika Westerberg7f86bde2013-01-22 12:26:26 +0200589 next_msg = spi_get_next_queued_message(drv_data->master);
Ned Forrester84235972008-09-13 02:33:17 -0700590
591 /* see if the next and current messages point
592 * to the same chip
593 */
Christophe Ricarda52db652016-03-20 19:30:17 +0100594 if ((next_msg && next_msg->spi != msg->spi) ||
595 msg->state == ERROR_STATE)
Eric Miaoa7bb3902009-04-06 19:00:54 -0700596 cs_deassert(drv_data);
Ned Forrester84235972008-09-13 02:33:17 -0700597 }
Stephen Streete0c99052006-03-07 23:53:24 -0800598
Mika Westerbergc957e8f2014-12-29 10:33:36 +0200599 spi_finalize_current_message(drv_data->master);
Stephen Streete0c99052006-03-07 23:53:24 -0800600}
601
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800602static void reset_sccr1(struct driver_data *drv_data)
603{
Jarkko Nikula96579a42016-09-07 17:04:07 +0300604 struct chip_data *chip =
605 spi_get_ctldata(drv_data->master->cur_msg->spi);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800606 u32 sccr1_reg;
607
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200608 sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1;
Andy Shevchenko152bc192016-07-06 12:08:11 +0300609 switch (drv_data->ssp_type) {
610 case QUARK_X1000_SSP:
611 sccr1_reg &= ~QUARK_X1000_SSCR1_RFT;
612 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300613 case CE4100_SSP:
614 sccr1_reg &= ~CE4100_SSCR1_RFT;
615 break;
Andy Shevchenko152bc192016-07-06 12:08:11 +0300616 default:
617 sccr1_reg &= ~SSCR1_RFT;
618 break;
619 }
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800620 sccr1_reg |= chip->threshold;
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200621 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800622}
623
Stephen Street8d94cc52006-12-10 02:18:54 -0800624static void int_error_stop(struct driver_data *drv_data, const char* msg)
625{
Stephen Street8d94cc52006-12-10 02:18:54 -0800626 /* Stop and reset SSP */
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800627 write_SSSR_CS(drv_data, drv_data->clear_sr);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800628 reset_sccr1(drv_data);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800629 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200630 pxa2xx_spi_write(drv_data, SSTO, 0);
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200631 pxa2xx_spi_flush(drv_data);
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200632 pxa2xx_spi_write(drv_data, SSCR0,
633 pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
Stephen Street8d94cc52006-12-10 02:18:54 -0800634
635 dev_err(&drv_data->pdev->dev, "%s\n", msg);
636
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300637 drv_data->master->cur_msg->state = ERROR_STATE;
Stephen Street8d94cc52006-12-10 02:18:54 -0800638 tasklet_schedule(&drv_data->pump_transfers);
639}
640
641static void int_transfer_complete(struct driver_data *drv_data)
642{
Jarkko Nikula07550df2016-02-04 12:30:56 +0200643 /* Clear and disable interrupts */
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800644 write_SSSR_CS(drv_data, drv_data->clear_sr);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800645 reset_sccr1(drv_data);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800646 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200647 pxa2xx_spi_write(drv_data, SSTO, 0);
Stephen Street8d94cc52006-12-10 02:18:54 -0800648
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300649 /* Update total byte transferred return count actual bytes read */
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300650 drv_data->master->cur_msg->actual_length += drv_data->len -
Stephen Street8d94cc52006-12-10 02:18:54 -0800651 (drv_data->rx_end - drv_data->rx);
652
Ned Forrester84235972008-09-13 02:33:17 -0700653 /* Transfer delays and chip select release are
654 * handled in pump_transfers or giveback
655 */
Stephen Street8d94cc52006-12-10 02:18:54 -0800656
657 /* Move to next transfer */
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300658 drv_data->master->cur_msg->state = pxa2xx_spi_next_transfer(drv_data);
Stephen Street8d94cc52006-12-10 02:18:54 -0800659
660 /* Schedule transfer tasklet */
661 tasklet_schedule(&drv_data->pump_transfers);
662}
663
Stephen Streete0c99052006-03-07 23:53:24 -0800664static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
665{
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200666 u32 irq_mask = (pxa2xx_spi_read(drv_data, SSCR1) & SSCR1_TIE) ?
667 drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS;
Stephen Street8d94cc52006-12-10 02:18:54 -0800668
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200669 u32 irq_status = pxa2xx_spi_read(drv_data, SSSR) & irq_mask;
Stephen Streete0c99052006-03-07 23:53:24 -0800670
Stephen Street8d94cc52006-12-10 02:18:54 -0800671 if (irq_status & SSSR_ROR) {
672 int_error_stop(drv_data, "interrupt_transfer: fifo overrun");
673 return IRQ_HANDLED;
674 }
Stephen Streete0c99052006-03-07 23:53:24 -0800675
Stephen Street8d94cc52006-12-10 02:18:54 -0800676 if (irq_status & SSSR_TINT) {
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200677 pxa2xx_spi_write(drv_data, SSSR, SSSR_TINT);
Stephen Street8d94cc52006-12-10 02:18:54 -0800678 if (drv_data->read(drv_data)) {
679 int_transfer_complete(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -0800680 return IRQ_HANDLED;
681 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800682 }
Stephen Streete0c99052006-03-07 23:53:24 -0800683
Stephen Street8d94cc52006-12-10 02:18:54 -0800684 /* Drain rx fifo, Fill tx fifo and prevent overruns */
685 do {
686 if (drv_data->read(drv_data)) {
687 int_transfer_complete(drv_data);
688 return IRQ_HANDLED;
Stephen Streete0c99052006-03-07 23:53:24 -0800689 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800690 } while (drv_data->write(drv_data));
Stephen Streete0c99052006-03-07 23:53:24 -0800691
Stephen Street8d94cc52006-12-10 02:18:54 -0800692 if (drv_data->read(drv_data)) {
693 int_transfer_complete(drv_data);
694 return IRQ_HANDLED;
695 }
Stephen Streete0c99052006-03-07 23:53:24 -0800696
Stephen Street8d94cc52006-12-10 02:18:54 -0800697 if (drv_data->tx == drv_data->tx_end) {
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800698 u32 bytes_left;
699 u32 sccr1_reg;
700
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200701 sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800702 sccr1_reg &= ~SSCR1_TIE;
703
704 /*
705 * PXA25x_SSP has no timeout, set up rx threshould for the
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300706 * remaining RX bytes.
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800707 */
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800708 if (pxa25x_ssp_comp(drv_data)) {
Weike Chen4fdb2422014-10-08 08:50:22 -0700709 u32 rx_thre;
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800710
Weike Chen4fdb2422014-10-08 08:50:22 -0700711 pxa2xx_spi_clear_rx_thre(drv_data, &sccr1_reg);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800712
713 bytes_left = drv_data->rx_end - drv_data->rx;
714 switch (drv_data->n_bytes) {
715 case 4:
716 bytes_left >>= 1;
717 case 2:
718 bytes_left >>= 1;
Stephen Street8d94cc52006-12-10 02:18:54 -0800719 }
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800720
Weike Chen4fdb2422014-10-08 08:50:22 -0700721 rx_thre = pxa2xx_spi_get_rx_default_thre(drv_data);
722 if (rx_thre > bytes_left)
723 rx_thre = bytes_left;
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800724
Weike Chen4fdb2422014-10-08 08:50:22 -0700725 pxa2xx_spi_set_rx_thre(drv_data, &sccr1_reg, rx_thre);
Stephen Streete0c99052006-03-07 23:53:24 -0800726 }
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200727 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
Stephen Streete0c99052006-03-07 23:53:24 -0800728 }
729
Stephen Street5daa3ba2006-05-20 15:00:19 -0700730 /* We did something */
731 return IRQ_HANDLED;
Stephen Streete0c99052006-03-07 23:53:24 -0800732}
733
David Howells7d12e782006-10-05 14:55:46 +0100734static irqreturn_t ssp_int(int irq, void *dev_id)
Stephen Streete0c99052006-03-07 23:53:24 -0800735{
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400736 struct driver_data *drv_data = dev_id;
Mika Westerberg7d94a502013-01-22 12:26:30 +0200737 u32 sccr1_reg;
Sebastian Andrzej Siewior49cbb1e2010-11-22 17:12:14 -0800738 u32 mask = drv_data->mask_sr;
739 u32 status;
740
Mika Westerberg7d94a502013-01-22 12:26:30 +0200741 /*
742 * The IRQ might be shared with other peripherals so we must first
743 * check that are we RPM suspended or not. If we are we assume that
744 * the IRQ was not for us (we shouldn't be RPM suspended when the
745 * interrupt is enabled).
746 */
747 if (pm_runtime_suspended(&drv_data->pdev->dev))
748 return IRQ_NONE;
749
Mika Westerberg269e4a42013-09-04 13:37:43 +0300750 /*
751 * If the device is not yet in RPM suspended state and we get an
752 * interrupt that is meant for another device, check if status bits
753 * are all set to one. That means that the device is already
754 * powered off.
755 */
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200756 status = pxa2xx_spi_read(drv_data, SSSR);
Mika Westerberg269e4a42013-09-04 13:37:43 +0300757 if (status == ~0)
758 return IRQ_NONE;
759
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200760 sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
Sebastian Andrzej Siewior49cbb1e2010-11-22 17:12:14 -0800761
762 /* Ignore possible writes if we don't need to write */
763 if (!(sccr1_reg & SSCR1_TIE))
764 mask &= ~SSSR_TFS;
765
Tan, Jui Nee02bc9332015-09-01 10:22:51 +0800766 /* Ignore RX timeout interrupt if it is disabled */
767 if (!(sccr1_reg & SSCR1_TINTE))
768 mask &= ~SSSR_TINT;
769
Sebastian Andrzej Siewior49cbb1e2010-11-22 17:12:14 -0800770 if (!(status & mask))
771 return IRQ_NONE;
Stephen Streete0c99052006-03-07 23:53:24 -0800772
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300773 if (!drv_data->master->cur_msg) {
Stephen Street5daa3ba2006-05-20 15:00:19 -0700774
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200775 pxa2xx_spi_write(drv_data, SSCR0,
776 pxa2xx_spi_read(drv_data, SSCR0)
777 & ~SSCR0_SSE);
778 pxa2xx_spi_write(drv_data, SSCR1,
779 pxa2xx_spi_read(drv_data, SSCR1)
780 & ~drv_data->int_cr1);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800781 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200782 pxa2xx_spi_write(drv_data, SSTO, 0);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800783 write_SSSR_CS(drv_data, drv_data->clear_sr);
Stephen Street5daa3ba2006-05-20 15:00:19 -0700784
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +0300785 dev_err(&drv_data->pdev->dev,
786 "bad message state in interrupt handler\n");
Stephen Street5daa3ba2006-05-20 15:00:19 -0700787
Stephen Streete0c99052006-03-07 23:53:24 -0800788 /* Never fail */
789 return IRQ_HANDLED;
790 }
791
792 return drv_data->transfer_handler(drv_data);
793}
794
Weike Chene5262d02014-11-26 02:35:10 -0800795/*
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200796 * The Quark SPI has an additional 24 bit register (DDS_CLK_RATE) to multiply
797 * input frequency by fractions of 2^24. It also has a divider by 5.
798 *
799 * There are formulas to get baud rate value for given input frequency and
800 * divider parameters, such as DDS_CLK_RATE and SCR:
801 *
802 * Fsys = 200MHz
803 *
804 * Fssp = Fsys * DDS_CLK_RATE / 2^24 (1)
805 * Baud rate = Fsclk = Fssp / (2 * (SCR + 1)) (2)
806 *
807 * DDS_CLK_RATE either 2^n or 2^n / 5.
808 * SCR is in range 0 .. 255
809 *
810 * Divisor = 5^i * 2^j * 2 * k
811 * i = [0, 1] i = 1 iff j = 0 or j > 3
812 * j = [0, 23] j = 0 iff i = 1
813 * k = [1, 256]
814 * Special case: j = 0, i = 1: Divisor = 2 / 5
815 *
816 * Accordingly to the specification the recommended values for DDS_CLK_RATE
817 * are:
818 * Case 1: 2^n, n = [0, 23]
819 * Case 2: 2^24 * 2 / 5 (0x666666)
820 * Case 3: less than or equal to 2^24 / 5 / 16 (0x33333)
821 *
822 * In all cases the lowest possible value is better.
823 *
824 * The function calculates parameters for all cases and chooses the one closest
825 * to the asked baud rate.
Weike Chene5262d02014-11-26 02:35:10 -0800826 */
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200827static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds)
Weike Chene5262d02014-11-26 02:35:10 -0800828{
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200829 unsigned long xtal = 200000000;
830 unsigned long fref = xtal / 2; /* mandatory division by 2,
831 see (2) */
832 /* case 3 */
833 unsigned long fref1 = fref / 2; /* case 1 */
834 unsigned long fref2 = fref * 2 / 5; /* case 2 */
835 unsigned long scale;
836 unsigned long q, q1, q2;
837 long r, r1, r2;
838 u32 mul;
Weike Chene5262d02014-11-26 02:35:10 -0800839
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200840 /* Case 1 */
841
842 /* Set initial value for DDS_CLK_RATE */
843 mul = (1 << 24) >> 1;
844
845 /* Calculate initial quot */
Andy Shevchenko3ad48062015-10-13 17:09:14 +0300846 q1 = DIV_ROUND_UP(fref1, rate);
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200847
848 /* Scale q1 if it's too big */
849 if (q1 > 256) {
850 /* Scale q1 to range [1, 512] */
851 scale = fls_long(q1 - 1);
852 if (scale > 9) {
853 q1 >>= scale - 9;
854 mul >>= scale - 9;
855 }
856
857 /* Round the result if we have a remainder */
858 q1 += q1 & 1;
859 }
860
861 /* Decrease DDS_CLK_RATE as much as we can without loss in precision */
862 scale = __ffs(q1);
863 q1 >>= scale;
864 mul >>= scale;
865
866 /* Get the remainder */
867 r1 = abs(fref1 / (1 << (24 - fls_long(mul))) / q1 - rate);
868
869 /* Case 2 */
870
Andy Shevchenko3ad48062015-10-13 17:09:14 +0300871 q2 = DIV_ROUND_UP(fref2, rate);
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200872 r2 = abs(fref2 / q2 - rate);
873
874 /*
875 * Choose the best between two: less remainder we have the better. We
876 * can't go case 2 if q2 is greater than 256 since SCR register can
877 * hold only values 0 .. 255.
878 */
879 if (r2 >= r1 || q2 > 256) {
880 /* case 1 is better */
881 r = r1;
882 q = q1;
883 } else {
884 /* case 2 is better */
885 r = r2;
886 q = q2;
887 mul = (1 << 24) * 2 / 5;
888 }
889
Andy Shevchenko3ad48062015-10-13 17:09:14 +0300890 /* Check case 3 only if the divisor is big enough */
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200891 if (fref / rate >= 80) {
892 u64 fssp;
893 u32 m;
894
895 /* Calculate initial quot */
Andy Shevchenko3ad48062015-10-13 17:09:14 +0300896 q1 = DIV_ROUND_UP(fref, rate);
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200897 m = (1 << 24) / q1;
898
899 /* Get the remainder */
900 fssp = (u64)fref * m;
901 do_div(fssp, 1 << 24);
902 r1 = abs(fssp - rate);
903
904 /* Choose this one if it suits better */
905 if (r1 < r) {
906 /* case 3 is better */
907 q = 1;
908 mul = m;
Weike Chene5262d02014-11-26 02:35:10 -0800909 }
910 }
911
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200912 *dds = mul;
913 return q - 1;
Weike Chene5262d02014-11-26 02:35:10 -0800914}
915
Mika Westerberg3343b7a2013-01-22 12:26:27 +0200916static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
eric miao2f1a74e2007-11-21 18:50:53 +0800917{
Jarkko Nikula0eca7cf2015-09-25 10:27:17 +0300918 unsigned long ssp_clk = drv_data->master->max_speed_hz;
Mika Westerberg3343b7a2013-01-22 12:26:27 +0200919 const struct ssp_device *ssp = drv_data->ssp;
920
921 rate = min_t(int, ssp_clk, rate);
eric miao2f1a74e2007-11-21 18:50:53 +0800922
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800923 if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200924 return (ssp_clk / (2 * rate) - 1) & 0xff;
eric miao2f1a74e2007-11-21 18:50:53 +0800925 else
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200926 return (ssp_clk / rate - 1) & 0xfff;
eric miao2f1a74e2007-11-21 18:50:53 +0800927}
928
Weike Chene5262d02014-11-26 02:35:10 -0800929static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data,
Andy Shevchenkod2c2f6a2015-10-22 16:44:40 +0300930 int rate)
Weike Chene5262d02014-11-26 02:35:10 -0800931{
Jarkko Nikula96579a42016-09-07 17:04:07 +0300932 struct chip_data *chip =
933 spi_get_ctldata(drv_data->master->cur_msg->spi);
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200934 unsigned int clk_div;
Weike Chene5262d02014-11-26 02:35:10 -0800935
936 switch (drv_data->ssp_type) {
937 case QUARK_X1000_SSP:
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200938 clk_div = quark_x1000_get_clk_div(rate, &chip->dds_rate);
Dan Carpentereecacf72015-03-31 16:49:38 +0300939 break;
Weike Chene5262d02014-11-26 02:35:10 -0800940 default:
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200941 clk_div = ssp_get_clk_div(drv_data, rate);
Dan Carpentereecacf72015-03-31 16:49:38 +0300942 break;
Weike Chene5262d02014-11-26 02:35:10 -0800943 }
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200944 return clk_div << 8;
Weike Chene5262d02014-11-26 02:35:10 -0800945}
946
Jarkko Nikulab6ced292016-06-21 13:21:34 +0300947static bool pxa2xx_spi_can_dma(struct spi_master *master,
948 struct spi_device *spi,
949 struct spi_transfer *xfer)
950{
951 struct chip_data *chip = spi_get_ctldata(spi);
952
953 return chip->enable_dma &&
954 xfer->len <= MAX_DMA_LEN &&
955 xfer->len >= chip->dma_burst_size;
956}
957
Stephen Streete0c99052006-03-07 23:53:24 -0800958static void pump_transfers(unsigned long data)
959{
960 struct driver_data *drv_data = (struct driver_data *)data;
Jarkko Nikula2d7537d2016-06-21 13:21:33 +0300961 struct spi_master *master = drv_data->master;
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300962 struct spi_message *message = master->cur_msg;
Jarkko Nikula96579a42016-09-07 17:04:07 +0300963 struct chip_data *chip = spi_get_ctldata(message->spi);
964 u32 dma_thresh = chip->dma_threshold;
965 u32 dma_burst = chip->dma_burst_size;
966 u32 change_mask = pxa2xx_spi_get_ssrc1_change_mask(drv_data);
Jarkko Nikulabffc9672016-09-07 17:04:05 +0300967 struct spi_transfer *transfer;
968 struct spi_transfer *previous;
Jarkko Nikulabffc9672016-09-07 17:04:05 +0300969 u32 clk_div;
970 u8 bits;
971 u32 speed;
Stephen Street9708c122006-03-28 14:05:23 -0800972 u32 cr0;
Stephen Street8d94cc52006-12-10 02:18:54 -0800973 u32 cr1;
Andy Shevchenko7d1f1bf2016-03-24 15:35:42 +0200974 int err;
Jarkko Nikulab6ced292016-06-21 13:21:34 +0300975 int dma_mapped;
Stephen Streete0c99052006-03-07 23:53:24 -0800976
977 /* Get current state information */
Stephen Streete0c99052006-03-07 23:53:24 -0800978 transfer = drv_data->cur_transfer;
Stephen Streete0c99052006-03-07 23:53:24 -0800979
980 /* Handle for abort */
981 if (message->state == ERROR_STATE) {
982 message->status = -EIO;
Stephen Street5daa3ba2006-05-20 15:00:19 -0700983 giveback(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -0800984 return;
985 }
986
987 /* Handle end of message */
988 if (message->state == DONE_STATE) {
989 message->status = 0;
Stephen Street5daa3ba2006-05-20 15:00:19 -0700990 giveback(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -0800991 return;
992 }
993
Ned Forrester84235972008-09-13 02:33:17 -0700994 /* Delay if requested at end of transfer before CS change */
Stephen Streete0c99052006-03-07 23:53:24 -0800995 if (message->state == RUNNING_STATE) {
996 previous = list_entry(transfer->transfer_list.prev,
997 struct spi_transfer,
998 transfer_list);
999 if (previous->delay_usecs)
1000 udelay(previous->delay_usecs);
Ned Forrester84235972008-09-13 02:33:17 -07001001
1002 /* Drop chip select only if cs_change is requested */
1003 if (previous->cs_change)
Eric Miaoa7bb3902009-04-06 19:00:54 -07001004 cs_deassert(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001005 }
1006
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001007 /* Check if we can DMA this transfer */
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001008 if (transfer->len > MAX_DMA_LEN && chip->enable_dma) {
Ned Forrester7e964452008-09-13 02:33:18 -07001009
1010 /* reject already-mapped transfers; PIO won't always work */
1011 if (message->is_dma_mapped
1012 || transfer->rx_dma || transfer->tx_dma) {
1013 dev_err(&drv_data->pdev->dev,
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +03001014 "pump_transfers: mapped transfer length of "
1015 "%u is greater than %d\n",
Ned Forrester7e964452008-09-13 02:33:18 -07001016 transfer->len, MAX_DMA_LEN);
1017 message->status = -EINVAL;
1018 giveback(drv_data);
1019 return;
1020 }
1021
1022 /* warn ... we force this to PIO mode */
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +03001023 dev_warn_ratelimited(&message->spi->dev,
1024 "pump_transfers: DMA disabled for transfer length %ld "
1025 "greater than %d\n",
1026 (long)drv_data->len, MAX_DMA_LEN);
Stephen Street8d94cc52006-12-10 02:18:54 -08001027 }
1028
Stephen Streete0c99052006-03-07 23:53:24 -08001029 /* Setup the transfer state based on the type of transfer */
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001030 if (pxa2xx_spi_flush(drv_data) == 0) {
Stephen Streete0c99052006-03-07 23:53:24 -08001031 dev_err(&drv_data->pdev->dev, "pump_transfers: flush failed\n");
1032 message->status = -EIO;
Stephen Street5daa3ba2006-05-20 15:00:19 -07001033 giveback(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001034 return;
1035 }
Stephen Street9708c122006-03-28 14:05:23 -08001036 drv_data->n_bytes = chip->n_bytes;
Stephen Streete0c99052006-03-07 23:53:24 -08001037 drv_data->tx = (void *)transfer->tx_buf;
1038 drv_data->tx_end = drv_data->tx + transfer->len;
1039 drv_data->rx = transfer->rx_buf;
1040 drv_data->rx_end = drv_data->rx + transfer->len;
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001041 drv_data->len = transfer->len;
Stephen Streete0c99052006-03-07 23:53:24 -08001042 drv_data->write = drv_data->tx ? chip->write : null_writer;
1043 drv_data->read = drv_data->rx ? chip->read : null_reader;
Stephen Street9708c122006-03-28 14:05:23 -08001044
1045 /* Change speed and bit per word on a per transfer */
Jarkko Nikula196b0e22015-09-15 16:26:27 +03001046 bits = transfer->bits_per_word;
1047 speed = transfer->speed_hz;
Stephen Street9708c122006-03-28 14:05:23 -08001048
Andy Shevchenkod2c2f6a2015-10-22 16:44:40 +03001049 clk_div = pxa2xx_ssp_get_clk_div(drv_data, speed);
Stephen Street9708c122006-03-28 14:05:23 -08001050
Jarkko Nikula196b0e22015-09-15 16:26:27 +03001051 if (bits <= 8) {
1052 drv_data->n_bytes = 1;
1053 drv_data->read = drv_data->read != null_reader ?
1054 u8_reader : null_reader;
1055 drv_data->write = drv_data->write != null_writer ?
1056 u8_writer : null_writer;
1057 } else if (bits <= 16) {
1058 drv_data->n_bytes = 2;
1059 drv_data->read = drv_data->read != null_reader ?
1060 u16_reader : null_reader;
1061 drv_data->write = drv_data->write != null_writer ?
1062 u16_writer : null_writer;
1063 } else if (bits <= 32) {
1064 drv_data->n_bytes = 4;
1065 drv_data->read = drv_data->read != null_reader ?
1066 u32_reader : null_reader;
1067 drv_data->write = drv_data->write != null_writer ?
1068 u32_writer : null_writer;
Stephen Street9708c122006-03-28 14:05:23 -08001069 }
Jarkko Nikula196b0e22015-09-15 16:26:27 +03001070 /*
1071 * if bits/word is changed in dma mode, then must check the
1072 * thresholds and burst also
1073 */
1074 if (chip->enable_dma) {
1075 if (pxa2xx_spi_set_dma_burst_and_threshold(chip,
1076 message->spi,
1077 bits, &dma_burst,
1078 &dma_thresh))
1079 dev_warn_ratelimited(&message->spi->dev,
1080 "pump_transfers: DMA burst size reduced to match bits_per_word\n");
1081 }
1082
Stephen Streete0c99052006-03-07 23:53:24 -08001083 message->state = RUNNING_STATE;
1084
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001085 dma_mapped = master->can_dma &&
1086 master->can_dma(master, message->spi, transfer) &&
1087 master->cur_msg_mapped;
1088 if (dma_mapped) {
Stephen Streete0c99052006-03-07 23:53:24 -08001089
1090 /* Ensure we have the correct interrupt handler */
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001091 drv_data->transfer_handler = pxa2xx_spi_dma_transfer;
Stephen Streete0c99052006-03-07 23:53:24 -08001092
Andy Shevchenko7d1f1bf2016-03-24 15:35:42 +02001093 err = pxa2xx_spi_dma_prepare(drv_data, dma_burst);
1094 if (err) {
1095 message->status = err;
1096 giveback(drv_data);
1097 return;
1098 }
Stephen Streete0c99052006-03-07 23:53:24 -08001099
Stephen Street8d94cc52006-12-10 02:18:54 -08001100 /* Clear status and start DMA engine */
1101 cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1;
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001102 pxa2xx_spi_write(drv_data, SSSR, drv_data->clear_sr);
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001103
1104 pxa2xx_spi_dma_start(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001105 } else {
1106 /* Ensure we have the correct interrupt handler */
1107 drv_data->transfer_handler = interrupt_transfer;
1108
Stephen Street8d94cc52006-12-10 02:18:54 -08001109 /* Clear status */
1110 cr1 = chip->cr1 | chip->threshold | drv_data->int_cr1;
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001111 write_SSSR_CS(drv_data, drv_data->clear_sr);
Stephen Street8d94cc52006-12-10 02:18:54 -08001112 }
1113
Jarkko Nikulaee036722016-01-26 15:33:21 +02001114 /* NOTE: PXA25x_SSP _could_ use external clocking ... */
1115 cr0 = pxa2xx_configure_sscr0(drv_data, clk_div, bits);
1116 if (!pxa25x_ssp_comp(drv_data))
1117 dev_dbg(&message->spi->dev, "%u Hz actual, %s\n",
Jarkko Nikula2d7537d2016-06-21 13:21:33 +03001118 master->max_speed_hz
Jarkko Nikulaee036722016-01-26 15:33:21 +02001119 / (1 + ((cr0 & SSCR0_SCR(0xfff)) >> 8)),
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001120 dma_mapped ? "DMA" : "PIO");
Jarkko Nikulaee036722016-01-26 15:33:21 +02001121 else
1122 dev_dbg(&message->spi->dev, "%u Hz actual, %s\n",
Jarkko Nikula2d7537d2016-06-21 13:21:33 +03001123 master->max_speed_hz / 2
Jarkko Nikulaee036722016-01-26 15:33:21 +02001124 / (1 + ((cr0 & SSCR0_SCR(0x0ff)) >> 8)),
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001125 dma_mapped ? "DMA" : "PIO");
Jarkko Nikulaee036722016-01-26 15:33:21 +02001126
Mika Westerberga0d26422013-01-22 12:26:32 +02001127 if (is_lpss_ssp(drv_data)) {
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001128 if ((pxa2xx_spi_read(drv_data, SSIRF) & 0xff)
1129 != chip->lpss_rx_threshold)
1130 pxa2xx_spi_write(drv_data, SSIRF,
1131 chip->lpss_rx_threshold);
1132 if ((pxa2xx_spi_read(drv_data, SSITF) & 0xffff)
1133 != chip->lpss_tx_threshold)
1134 pxa2xx_spi_write(drv_data, SSITF,
1135 chip->lpss_tx_threshold);
Mika Westerberga0d26422013-01-22 12:26:32 +02001136 }
1137
Weike Chene5262d02014-11-26 02:35:10 -08001138 if (is_quark_x1000_ssp(drv_data) &&
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001139 (pxa2xx_spi_read(drv_data, DDS_RATE) != chip->dds_rate))
1140 pxa2xx_spi_write(drv_data, DDS_RATE, chip->dds_rate);
Weike Chene5262d02014-11-26 02:35:10 -08001141
Stephen Street8d94cc52006-12-10 02:18:54 -08001142 /* see if we need to reload the config registers */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001143 if ((pxa2xx_spi_read(drv_data, SSCR0) != cr0)
1144 || (pxa2xx_spi_read(drv_data, SSCR1) & change_mask)
1145 != (cr1 & change_mask)) {
Ned Forresterb97c74b2008-02-23 15:23:40 -08001146 /* stop the SSP, and update the other bits */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001147 pxa2xx_spi_write(drv_data, SSCR0, cr0 & ~SSCR0_SSE);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001148 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001149 pxa2xx_spi_write(drv_data, SSTO, chip->timeout);
Ned Forresterb97c74b2008-02-23 15:23:40 -08001150 /* first set CR1 without interrupt and service enables */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001151 pxa2xx_spi_write(drv_data, SSCR1, cr1 & change_mask);
Ned Forresterb97c74b2008-02-23 15:23:40 -08001152 /* restart the SSP */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001153 pxa2xx_spi_write(drv_data, SSCR0, cr0);
Ned Forresterb97c74b2008-02-23 15:23:40 -08001154
Stephen Street8d94cc52006-12-10 02:18:54 -08001155 } else {
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001156 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001157 pxa2xx_spi_write(drv_data, SSTO, chip->timeout);
Stephen Streete0c99052006-03-07 23:53:24 -08001158 }
Ned Forresterb97c74b2008-02-23 15:23:40 -08001159
Eric Miaoa7bb3902009-04-06 19:00:54 -07001160 cs_assert(drv_data);
Ned Forresterb97c74b2008-02-23 15:23:40 -08001161
1162 /* after chip select, release the data by enabling service
1163 * requests and interrupts, without changing any mode bits */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001164 pxa2xx_spi_write(drv_data, SSCR1, cr1);
Stephen Streete0c99052006-03-07 23:53:24 -08001165}
1166
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001167static int pxa2xx_spi_transfer_one_message(struct spi_master *master,
1168 struct spi_message *msg)
Stephen Streete0c99052006-03-07 23:53:24 -08001169{
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001170 struct driver_data *drv_data = spi_master_get_devdata(master);
Stephen Streete0c99052006-03-07 23:53:24 -08001171
Stephen Streete0c99052006-03-07 23:53:24 -08001172 /* Initial message state*/
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +03001173 msg->state = START_STATE;
1174 drv_data->cur_transfer = list_entry(msg->transfers.next,
Stephen Streete0c99052006-03-07 23:53:24 -08001175 struct spi_transfer,
1176 transfer_list);
1177
Stephen Streete0c99052006-03-07 23:53:24 -08001178 /* Mark as busy and launch transfers */
1179 tasklet_schedule(&drv_data->pump_transfers);
Stephen Streete0c99052006-03-07 23:53:24 -08001180 return 0;
1181}
1182
Mika Westerberg7d94a502013-01-22 12:26:30 +02001183static int pxa2xx_spi_unprepare_transfer(struct spi_master *master)
1184{
1185 struct driver_data *drv_data = spi_master_get_devdata(master);
1186
1187 /* Disable the SSP now */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001188 pxa2xx_spi_write(drv_data, SSCR0,
1189 pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
Mika Westerberg7d94a502013-01-22 12:26:30 +02001190
Mika Westerberg7d94a502013-01-22 12:26:30 +02001191 return 0;
1192}
1193
Eric Miaoa7bb3902009-04-06 19:00:54 -07001194static int setup_cs(struct spi_device *spi, struct chip_data *chip,
1195 struct pxa2xx_spi_chip *chip_info)
1196{
Mika Westerberg99f499c2016-09-26 15:19:50 +03001197 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
Eric Miaoa7bb3902009-04-06 19:00:54 -07001198 int err = 0;
1199
Mika Westerberg99f499c2016-09-26 15:19:50 +03001200 if (chip == NULL)
1201 return 0;
1202
1203 if (drv_data->cs_gpiods) {
1204 struct gpio_desc *gpiod;
1205
1206 gpiod = drv_data->cs_gpiods[spi->chip_select];
1207 if (gpiod) {
1208 chip->gpio_cs = desc_to_gpio(gpiod);
1209 chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
1210 gpiod_set_value(gpiod, chip->gpio_cs_inverted);
1211 }
1212
1213 return 0;
1214 }
1215
1216 if (chip_info == NULL)
Eric Miaoa7bb3902009-04-06 19:00:54 -07001217 return 0;
1218
1219 /* NOTE: setup() can be called multiple times, possibly with
1220 * different chip_info, release previously requested GPIO
1221 */
1222 if (gpio_is_valid(chip->gpio_cs))
1223 gpio_free(chip->gpio_cs);
1224
1225 /* If (*cs_control) is provided, ignore GPIO chip select */
1226 if (chip_info->cs_control) {
1227 chip->cs_control = chip_info->cs_control;
1228 return 0;
1229 }
1230
1231 if (gpio_is_valid(chip_info->gpio_cs)) {
1232 err = gpio_request(chip_info->gpio_cs, "SPI_CS");
1233 if (err) {
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +03001234 dev_err(&spi->dev, "failed to request chip select GPIO%d\n",
1235 chip_info->gpio_cs);
Eric Miaoa7bb3902009-04-06 19:00:54 -07001236 return err;
1237 }
1238
1239 chip->gpio_cs = chip_info->gpio_cs;
1240 chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
1241
1242 err = gpio_direction_output(chip->gpio_cs,
1243 !chip->gpio_cs_inverted);
1244 }
1245
1246 return err;
1247}
1248
Stephen Streete0c99052006-03-07 23:53:24 -08001249static int setup(struct spi_device *spi)
1250{
Jarkko Nikulabffc9672016-09-07 17:04:05 +03001251 struct pxa2xx_spi_chip *chip_info;
Stephen Streete0c99052006-03-07 23:53:24 -08001252 struct chip_data *chip;
Jarkko Nikuladccf7362015-06-04 16:55:11 +03001253 const struct lpss_config *config;
Stephen Streete0c99052006-03-07 23:53:24 -08001254 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
Mika Westerberga0d26422013-01-22 12:26:32 +02001255 uint tx_thres, tx_hi_thres, rx_thres;
1256
Weike Chene5262d02014-11-26 02:35:10 -08001257 switch (drv_data->ssp_type) {
1258 case QUARK_X1000_SSP:
1259 tx_thres = TX_THRESH_QUARK_X1000_DFLT;
1260 tx_hi_thres = 0;
1261 rx_thres = RX_THRESH_QUARK_X1000_DFLT;
1262 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001263 case CE4100_SSP:
1264 tx_thres = TX_THRESH_CE4100_DFLT;
1265 tx_hi_thres = 0;
1266 rx_thres = RX_THRESH_CE4100_DFLT;
1267 break;
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001268 case LPSS_LPT_SSP:
1269 case LPSS_BYT_SSP:
Mika Westerberg30f3a6a2016-02-08 17:14:31 +02001270 case LPSS_BSW_SSP:
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001271 case LPSS_SPT_SSP:
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +02001272 case LPSS_BXT_SSP:
Jarkko Nikuladccf7362015-06-04 16:55:11 +03001273 config = lpss_get_config(drv_data);
1274 tx_thres = config->tx_threshold_lo;
1275 tx_hi_thres = config->tx_threshold_hi;
1276 rx_thres = config->rx_threshold;
Weike Chene5262d02014-11-26 02:35:10 -08001277 break;
1278 default:
Mika Westerberga0d26422013-01-22 12:26:32 +02001279 tx_thres = TX_THRESH_DFLT;
1280 tx_hi_thres = 0;
1281 rx_thres = RX_THRESH_DFLT;
Weike Chene5262d02014-11-26 02:35:10 -08001282 break;
Mika Westerberga0d26422013-01-22 12:26:32 +02001283 }
Stephen Streete0c99052006-03-07 23:53:24 -08001284
Stephen Street8d94cc52006-12-10 02:18:54 -08001285 /* Only alloc on first setup */
Stephen Streete0c99052006-03-07 23:53:24 -08001286 chip = spi_get_ctldata(spi);
Stephen Street8d94cc52006-12-10 02:18:54 -08001287 if (!chip) {
Stephen Streete0c99052006-03-07 23:53:24 -08001288 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
Jingoo Han9deae452014-04-29 17:19:38 +09001289 if (!chip)
Stephen Streete0c99052006-03-07 23:53:24 -08001290 return -ENOMEM;
1291
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001292 if (drv_data->ssp_type == CE4100_SSP) {
1293 if (spi->chip_select > 4) {
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +03001294 dev_err(&spi->dev,
1295 "failed setup: cs number must not be > 4.\n");
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001296 kfree(chip);
1297 return -EINVAL;
1298 }
1299
1300 chip->frm = spi->chip_select;
1301 } else
1302 chip->gpio_cs = -1;
Dan O'Donovanc64e1262016-05-27 19:57:48 +01001303 chip->enable_dma = drv_data->master_info->enable_dma;
Vernon Sauderf1f640a2008-10-15 22:02:43 -07001304 chip->timeout = TIMOUT_DFLT;
Stephen Streete0c99052006-03-07 23:53:24 -08001305 }
1306
Stephen Street8d94cc52006-12-10 02:18:54 -08001307 /* protocol drivers may change the chip settings, so...
1308 * if chip_info exists, use it */
1309 chip_info = spi->controller_data;
1310
Stephen Streete0c99052006-03-07 23:53:24 -08001311 /* chip_info isn't always needed */
Stephen Street8d94cc52006-12-10 02:18:54 -08001312 chip->cr1 = 0;
Stephen Streete0c99052006-03-07 23:53:24 -08001313 if (chip_info) {
Vernon Sauderf1f640a2008-10-15 22:02:43 -07001314 if (chip_info->timeout)
1315 chip->timeout = chip_info->timeout;
1316 if (chip_info->tx_threshold)
1317 tx_thres = chip_info->tx_threshold;
Mika Westerberga0d26422013-01-22 12:26:32 +02001318 if (chip_info->tx_hi_threshold)
1319 tx_hi_thres = chip_info->tx_hi_threshold;
Vernon Sauderf1f640a2008-10-15 22:02:43 -07001320 if (chip_info->rx_threshold)
1321 rx_thres = chip_info->rx_threshold;
Stephen Streete0c99052006-03-07 23:53:24 -08001322 chip->dma_threshold = 0;
Stephen Streete0c99052006-03-07 23:53:24 -08001323 if (chip_info->enable_loopback)
1324 chip->cr1 = SSCR1_LBM;
1325 }
1326
Mika Westerberga0d26422013-01-22 12:26:32 +02001327 chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres);
1328 chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres)
1329 | SSITF_TxHiThresh(tx_hi_thres);
1330
Stephen Street8d94cc52006-12-10 02:18:54 -08001331 /* set dma burst and threshold outside of chip_info path so that if
1332 * chip_info goes away after setting chip->enable_dma, the
1333 * burst and threshold can still respond to changes in bits_per_word */
1334 if (chip->enable_dma) {
1335 /* set up legal burst and threshold for dma */
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001336 if (pxa2xx_spi_set_dma_burst_and_threshold(chip, spi,
1337 spi->bits_per_word,
Stephen Street8d94cc52006-12-10 02:18:54 -08001338 &chip->dma_burst_size,
1339 &chip->dma_threshold)) {
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +03001340 dev_warn(&spi->dev,
1341 "in setup: DMA burst size reduced to match bits_per_word\n");
Stephen Street8d94cc52006-12-10 02:18:54 -08001342 }
1343 }
1344
Weike Chene5262d02014-11-26 02:35:10 -08001345 switch (drv_data->ssp_type) {
1346 case QUARK_X1000_SSP:
1347 chip->threshold = (QUARK_X1000_SSCR1_RxTresh(rx_thres)
1348 & QUARK_X1000_SSCR1_RFT)
1349 | (QUARK_X1000_SSCR1_TxTresh(tx_thres)
1350 & QUARK_X1000_SSCR1_TFT);
1351 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001352 case CE4100_SSP:
1353 chip->threshold = (CE4100_SSCR1_RxTresh(rx_thres) & CE4100_SSCR1_RFT) |
1354 (CE4100_SSCR1_TxTresh(tx_thres) & CE4100_SSCR1_TFT);
1355 break;
Weike Chene5262d02014-11-26 02:35:10 -08001356 default:
1357 chip->threshold = (SSCR1_RxTresh(rx_thres) & SSCR1_RFT) |
1358 (SSCR1_TxTresh(tx_thres) & SSCR1_TFT);
1359 break;
1360 }
1361
Justin Clacherty7f6ee1a2007-01-26 00:56:44 -08001362 chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
1363 chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)
1364 | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);
Stephen Streete0c99052006-03-07 23:53:24 -08001365
Mika Westerbergb8331722013-01-22 12:26:31 +02001366 if (spi->mode & SPI_LOOP)
1367 chip->cr1 |= SSCR1_LBM;
1368
Stephen Streete0c99052006-03-07 23:53:24 -08001369 if (spi->bits_per_word <= 8) {
1370 chip->n_bytes = 1;
Stephen Streete0c99052006-03-07 23:53:24 -08001371 chip->read = u8_reader;
1372 chip->write = u8_writer;
1373 } else if (spi->bits_per_word <= 16) {
1374 chip->n_bytes = 2;
Stephen Streete0c99052006-03-07 23:53:24 -08001375 chip->read = u16_reader;
1376 chip->write = u16_writer;
1377 } else if (spi->bits_per_word <= 32) {
Stephen Streete0c99052006-03-07 23:53:24 -08001378 chip->n_bytes = 4;
Stephen Streete0c99052006-03-07 23:53:24 -08001379 chip->read = u32_reader;
1380 chip->write = u32_writer;
Stephen Streete0c99052006-03-07 23:53:24 -08001381 }
Stephen Streete0c99052006-03-07 23:53:24 -08001382
1383 spi_set_ctldata(spi, chip);
1384
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001385 if (drv_data->ssp_type == CE4100_SSP)
1386 return 0;
1387
Eric Miaoa7bb3902009-04-06 19:00:54 -07001388 return setup_cs(spi, chip, chip_info);
Stephen Streete0c99052006-03-07 23:53:24 -08001389}
1390
Hans-Peter Nilsson0ffa0282007-02-12 00:52:45 -08001391static void cleanup(struct spi_device *spi)
Stephen Streete0c99052006-03-07 23:53:24 -08001392{
Hans-Peter Nilsson0ffa0282007-02-12 00:52:45 -08001393 struct chip_data *chip = spi_get_ctldata(spi);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001394 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
Stephen Streete0c99052006-03-07 23:53:24 -08001395
Daniel Ribeiro7348d822009-05-12 13:19:36 -07001396 if (!chip)
1397 return;
1398
Mika Westerberg99f499c2016-09-26 15:19:50 +03001399 if (drv_data->ssp_type != CE4100_SSP && !drv_data->cs_gpiods &&
1400 gpio_is_valid(chip->gpio_cs))
Eric Miaoa7bb3902009-04-06 19:00:54 -07001401 gpio_free(chip->gpio_cs);
1402
Stephen Streete0c99052006-03-07 23:53:24 -08001403 kfree(chip);
1404}
1405
Jarkko Nikula0db64212015-10-28 15:13:43 +02001406#ifdef CONFIG_PCI
Mika Westerberga3496852013-01-22 12:26:33 +02001407#ifdef CONFIG_ACPI
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001408
Mathias Krause8422ddf2015-06-13 14:22:14 +02001409static const struct acpi_device_id pxa2xx_spi_acpi_match[] = {
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001410 { "INT33C0", LPSS_LPT_SSP },
1411 { "INT33C1", LPSS_LPT_SSP },
1412 { "INT3430", LPSS_LPT_SSP },
1413 { "INT3431", LPSS_LPT_SSP },
1414 { "80860F0E", LPSS_BYT_SSP },
Mika Westerberg30f3a6a2016-02-08 17:14:31 +02001415 { "8086228E", LPSS_BSW_SSP },
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001416 { },
1417};
1418MODULE_DEVICE_TABLE(acpi, pxa2xx_spi_acpi_match);
1419
Jarkko Nikula0db64212015-10-28 15:13:43 +02001420static int pxa2xx_spi_get_port_id(struct acpi_device *adev)
1421{
1422 unsigned int devid;
1423 int port_id = -1;
1424
1425 if (adev && adev->pnp.unique_id &&
1426 !kstrtouint(adev->pnp.unique_id, 0, &devid))
1427 port_id = devid;
1428 return port_id;
1429}
1430#else /* !CONFIG_ACPI */
1431static int pxa2xx_spi_get_port_id(struct acpi_device *adev)
1432{
1433 return -1;
1434}
1435#endif
1436
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001437/*
1438 * PCI IDs of compound devices that integrate both host controller and private
1439 * integrated DMA engine. Please note these are not used in module
1440 * autoloading and probing in this module but matching the LPSS SSP type.
1441 */
1442static const struct pci_device_id pxa2xx_spi_pci_compound_match[] = {
1443 /* SPT-LP */
1444 { PCI_VDEVICE(INTEL, 0x9d29), LPSS_SPT_SSP },
1445 { PCI_VDEVICE(INTEL, 0x9d2a), LPSS_SPT_SSP },
1446 /* SPT-H */
1447 { PCI_VDEVICE(INTEL, 0xa129), LPSS_SPT_SSP },
1448 { PCI_VDEVICE(INTEL, 0xa12a), LPSS_SPT_SSP },
Mika Westerberg704d2b02016-07-04 13:21:07 +03001449 /* KBL-H */
1450 { PCI_VDEVICE(INTEL, 0xa2a9), LPSS_SPT_SSP },
1451 { PCI_VDEVICE(INTEL, 0xa2aa), LPSS_SPT_SSP },
Jarkko Nikulac1b03f12016-03-02 09:54:14 +02001452 /* BXT A-Step */
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +02001453 { PCI_VDEVICE(INTEL, 0x0ac2), LPSS_BXT_SSP },
1454 { PCI_VDEVICE(INTEL, 0x0ac4), LPSS_BXT_SSP },
1455 { PCI_VDEVICE(INTEL, 0x0ac6), LPSS_BXT_SSP },
Jarkko Nikulac1b03f12016-03-02 09:54:14 +02001456 /* BXT B-Step */
1457 { PCI_VDEVICE(INTEL, 0x1ac2), LPSS_BXT_SSP },
1458 { PCI_VDEVICE(INTEL, 0x1ac4), LPSS_BXT_SSP },
1459 { PCI_VDEVICE(INTEL, 0x1ac6), LPSS_BXT_SSP },
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +02001460 /* APL */
1461 { PCI_VDEVICE(INTEL, 0x5ac2), LPSS_BXT_SSP },
1462 { PCI_VDEVICE(INTEL, 0x5ac4), LPSS_BXT_SSP },
1463 { PCI_VDEVICE(INTEL, 0x5ac6), LPSS_BXT_SSP },
Axel Lin94e5c232015-08-04 13:52:22 +08001464 { },
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001465};
1466
1467static bool pxa2xx_spi_idma_filter(struct dma_chan *chan, void *param)
1468{
1469 struct device *dev = param;
1470
1471 if (dev != chan->device->dev->parent)
1472 return false;
1473
1474 return true;
1475}
1476
Mika Westerberga3496852013-01-22 12:26:33 +02001477static struct pxa2xx_spi_master *
Jarkko Nikula0db64212015-10-28 15:13:43 +02001478pxa2xx_spi_init_pdata(struct platform_device *pdev)
Mika Westerberga3496852013-01-22 12:26:33 +02001479{
1480 struct pxa2xx_spi_master *pdata;
Mika Westerberga3496852013-01-22 12:26:33 +02001481 struct acpi_device *adev;
1482 struct ssp_device *ssp;
1483 struct resource *res;
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001484 const struct acpi_device_id *adev_id = NULL;
1485 const struct pci_device_id *pcidev_id = NULL;
Jarkko Nikula3b8b6d02015-10-22 16:44:41 +03001486 int type;
Mika Westerberga3496852013-01-22 12:26:33 +02001487
Jarkko Nikulab9f69402015-09-25 10:27:18 +03001488 adev = ACPI_COMPANION(&pdev->dev);
Mika Westerberga3496852013-01-22 12:26:33 +02001489
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001490 if (dev_is_pci(pdev->dev.parent))
1491 pcidev_id = pci_match_id(pxa2xx_spi_pci_compound_match,
1492 to_pci_dev(pdev->dev.parent));
Jarkko Nikula0db64212015-10-28 15:13:43 +02001493 else if (adev)
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001494 adev_id = acpi_match_device(pdev->dev.driver->acpi_match_table,
1495 &pdev->dev);
Jarkko Nikula0db64212015-10-28 15:13:43 +02001496 else
1497 return NULL;
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001498
1499 if (adev_id)
1500 type = (int)adev_id->driver_data;
1501 else if (pcidev_id)
1502 type = (int)pcidev_id->driver_data;
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001503 else
1504 return NULL;
1505
Mika Westerbergcc0ee982013-06-20 17:44:22 +03001506 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
Jingoo Han9deae452014-04-29 17:19:38 +09001507 if (!pdata)
Mika Westerberga3496852013-01-22 12:26:33 +02001508 return NULL;
Mika Westerberga3496852013-01-22 12:26:33 +02001509
1510 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1511 if (!res)
1512 return NULL;
1513
1514 ssp = &pdata->ssp;
1515
1516 ssp->phys_base = res->start;
Sachin Kamatcbfd6a22013-04-08 15:49:33 +05301517 ssp->mmio_base = devm_ioremap_resource(&pdev->dev, res);
1518 if (IS_ERR(ssp->mmio_base))
Mika Westerberg6dc81f62013-05-13 13:45:09 +03001519 return NULL;
Mika Westerberga3496852013-01-22 12:26:33 +02001520
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001521 if (pcidev_id) {
1522 pdata->tx_param = pdev->dev.parent;
1523 pdata->rx_param = pdev->dev.parent;
1524 pdata->dma_filter = pxa2xx_spi_idma_filter;
1525 }
1526
Mika Westerberga3496852013-01-22 12:26:33 +02001527 ssp->clk = devm_clk_get(&pdev->dev, NULL);
1528 ssp->irq = platform_get_irq(pdev, 0);
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001529 ssp->type = type;
Mika Westerberga3496852013-01-22 12:26:33 +02001530 ssp->pdev = pdev;
Jarkko Nikula0db64212015-10-28 15:13:43 +02001531 ssp->port_id = pxa2xx_spi_get_port_id(adev);
Mika Westerberga3496852013-01-22 12:26:33 +02001532
1533 pdata->num_chipselect = 1;
Mika Westerbergcddb3392013-05-13 13:45:10 +03001534 pdata->enable_dma = true;
Mika Westerberga3496852013-01-22 12:26:33 +02001535
1536 return pdata;
1537}
1538
Jarkko Nikula0db64212015-10-28 15:13:43 +02001539#else /* !CONFIG_PCI */
Mika Westerberga3496852013-01-22 12:26:33 +02001540static inline struct pxa2xx_spi_master *
Jarkko Nikula0db64212015-10-28 15:13:43 +02001541pxa2xx_spi_init_pdata(struct platform_device *pdev)
Mika Westerberga3496852013-01-22 12:26:33 +02001542{
1543 return NULL;
1544}
1545#endif
1546
Mika Westerberg0c27d9c2016-02-08 17:14:29 +02001547static int pxa2xx_spi_fw_translate_cs(struct spi_master *master, unsigned cs)
1548{
1549 struct driver_data *drv_data = spi_master_get_devdata(master);
1550
1551 if (has_acpi_companion(&drv_data->pdev->dev)) {
1552 switch (drv_data->ssp_type) {
1553 /*
1554 * For Atoms the ACPI DeviceSelection used by the Windows
1555 * driver starts from 1 instead of 0 so translate it here
1556 * to match what Linux expects.
1557 */
1558 case LPSS_BYT_SSP:
Mika Westerberg30f3a6a2016-02-08 17:14:31 +02001559 case LPSS_BSW_SSP:
Mika Westerberg0c27d9c2016-02-08 17:14:29 +02001560 return cs - 1;
1561
1562 default:
1563 break;
1564 }
1565 }
1566
1567 return cs;
1568}
1569
Grant Likelyfd4a3192012-12-07 16:57:14 +00001570static int pxa2xx_spi_probe(struct platform_device *pdev)
Stephen Streete0c99052006-03-07 23:53:24 -08001571{
1572 struct device *dev = &pdev->dev;
1573 struct pxa2xx_spi_master *platform_info;
1574 struct spi_master *master;
Guennadi Liakhovetski65a00a22008-10-15 22:02:42 -07001575 struct driver_data *drv_data;
eric miao2f1a74e2007-11-21 18:50:53 +08001576 struct ssp_device *ssp;
Jarkko Nikula8b136ba2015-10-28 15:13:41 +02001577 const struct lpss_config *config;
Mika Westerberg99f499c2016-09-26 15:19:50 +03001578 int status, count;
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001579 u32 tmp;
Stephen Streete0c99052006-03-07 23:53:24 -08001580
Mika Westerberg851bacf2013-01-07 12:44:33 +02001581 platform_info = dev_get_platdata(dev);
1582 if (!platform_info) {
Jarkko Nikula0db64212015-10-28 15:13:43 +02001583 platform_info = pxa2xx_spi_init_pdata(pdev);
Mika Westerberga3496852013-01-22 12:26:33 +02001584 if (!platform_info) {
1585 dev_err(&pdev->dev, "missing platform data\n");
1586 return -ENODEV;
1587 }
Mika Westerberg851bacf2013-01-07 12:44:33 +02001588 }
Stephen Streete0c99052006-03-07 23:53:24 -08001589
Haojian Zhuangbaffe162010-05-05 10:11:15 -04001590 ssp = pxa_ssp_request(pdev->id, pdev->name);
Mika Westerberg851bacf2013-01-07 12:44:33 +02001591 if (!ssp)
1592 ssp = &platform_info->ssp;
1593
1594 if (!ssp->mmio_base) {
1595 dev_err(&pdev->dev, "failed to get ssp\n");
Stephen Streete0c99052006-03-07 23:53:24 -08001596 return -ENODEV;
1597 }
1598
Jarkko Nikula757fe8d2015-08-05 10:04:05 +03001599 master = spi_alloc_master(dev, sizeof(struct driver_data));
Stephen Streete0c99052006-03-07 23:53:24 -08001600 if (!master) {
Guennadi Liakhovetski65a00a22008-10-15 22:02:42 -07001601 dev_err(&pdev->dev, "cannot alloc spi_master\n");
Haojian Zhuangbaffe162010-05-05 10:11:15 -04001602 pxa_ssp_free(ssp);
Stephen Streete0c99052006-03-07 23:53:24 -08001603 return -ENOMEM;
1604 }
1605 drv_data = spi_master_get_devdata(master);
1606 drv_data->master = master;
1607 drv_data->master_info = platform_info;
1608 drv_data->pdev = pdev;
eric miao2f1a74e2007-11-21 18:50:53 +08001609 drv_data->ssp = ssp;
Stephen Streete0c99052006-03-07 23:53:24 -08001610
Sebastian Andrzej Siewior21486af2010-10-08 18:11:19 +02001611 master->dev.of_node = pdev->dev.of_node;
David Brownelle7db06b2009-06-17 16:26:04 -07001612 /* the spi->mode bits understood by this driver: */
Mika Westerbergb8331722013-01-22 12:26:31 +02001613 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
David Brownelle7db06b2009-06-17 16:26:04 -07001614
Mika Westerberg851bacf2013-01-07 12:44:33 +02001615 master->bus_num = ssp->port_id;
Mike Rapoport7ad0ba92009-04-06 19:00:57 -07001616 master->dma_alignment = DMA_ALIGNMENT;
Stephen Streete0c99052006-03-07 23:53:24 -08001617 master->cleanup = cleanup;
1618 master->setup = setup;
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001619 master->transfer_one_message = pxa2xx_spi_transfer_one_message;
Mika Westerberg7d94a502013-01-22 12:26:30 +02001620 master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer;
Mika Westerberg0c27d9c2016-02-08 17:14:29 +02001621 master->fw_translate_cs = pxa2xx_spi_fw_translate_cs;
Mark Brown7dd62782013-07-28 15:35:21 +01001622 master->auto_runtime_pm = true;
Jarkko Nikula8c3ad482016-03-24 15:35:44 +02001623 master->flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX;
Stephen Streete0c99052006-03-07 23:53:24 -08001624
eric miao2f1a74e2007-11-21 18:50:53 +08001625 drv_data->ssp_type = ssp->type;
Stephen Streete0c99052006-03-07 23:53:24 -08001626
eric miao2f1a74e2007-11-21 18:50:53 +08001627 drv_data->ioaddr = ssp->mmio_base;
1628 drv_data->ssdr_physical = ssp->phys_base + SSDR;
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001629 if (pxa25x_ssp_comp(drv_data)) {
Weike Chene5262d02014-11-26 02:35:10 -08001630 switch (drv_data->ssp_type) {
1631 case QUARK_X1000_SSP:
1632 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
1633 break;
1634 default:
1635 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
1636 break;
1637 }
1638
Stephen Streete0c99052006-03-07 23:53:24 -08001639 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE;
1640 drv_data->dma_cr1 = 0;
1641 drv_data->clear_sr = SSSR_ROR;
1642 drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR;
1643 } else {
Stephen Warren24778be2013-05-21 20:36:35 -06001644 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
Stephen Streete0c99052006-03-07 23:53:24 -08001645 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE;
Mika Westerberg59288082013-01-22 12:26:29 +02001646 drv_data->dma_cr1 = DEFAULT_DMA_CR1;
Stephen Streete0c99052006-03-07 23:53:24 -08001647 drv_data->clear_sr = SSSR_ROR | SSSR_TINT;
1648 drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR;
1649 }
1650
Sebastian Andrzej Siewior49cbb1e2010-11-22 17:12:14 -08001651 status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev),
1652 drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001653 if (status < 0) {
Guennadi Liakhovetski65a00a22008-10-15 22:02:42 -07001654 dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq);
Stephen Streete0c99052006-03-07 23:53:24 -08001655 goto out_error_master_alloc;
1656 }
1657
1658 /* Setup DMA if requested */
Stephen Streete0c99052006-03-07 23:53:24 -08001659 if (platform_info->enable_dma) {
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001660 status = pxa2xx_spi_dma_setup(drv_data);
1661 if (status) {
Mika Westerbergcddb3392013-05-13 13:45:10 +03001662 dev_dbg(dev, "no DMA channels available, using PIO\n");
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001663 platform_info->enable_dma = false;
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001664 } else {
1665 master->can_dma = pxa2xx_spi_can_dma;
Stephen Streete0c99052006-03-07 23:53:24 -08001666 }
Stephen Streete0c99052006-03-07 23:53:24 -08001667 }
1668
1669 /* Enable SOC clock */
Mika Westerberg3343b7a2013-01-22 12:26:27 +02001670 clk_prepare_enable(ssp->clk);
1671
Jarkko Nikula0eca7cf2015-09-25 10:27:17 +03001672 master->max_speed_hz = clk_get_rate(ssp->clk);
Stephen Streete0c99052006-03-07 23:53:24 -08001673
1674 /* Load default SSP configuration */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001675 pxa2xx_spi_write(drv_data, SSCR0, 0);
Weike Chene5262d02014-11-26 02:35:10 -08001676 switch (drv_data->ssp_type) {
1677 case QUARK_X1000_SSP:
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001678 tmp = QUARK_X1000_SSCR1_RxTresh(RX_THRESH_QUARK_X1000_DFLT) |
1679 QUARK_X1000_SSCR1_TxTresh(TX_THRESH_QUARK_X1000_DFLT);
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001680 pxa2xx_spi_write(drv_data, SSCR1, tmp);
Weike Chene5262d02014-11-26 02:35:10 -08001681
1682 /* using the Motorola SPI protocol and use 8 bit frame */
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001683 tmp = QUARK_X1000_SSCR0_Motorola | QUARK_X1000_SSCR0_DataSize(8);
1684 pxa2xx_spi_write(drv_data, SSCR0, tmp);
Weike Chene5262d02014-11-26 02:35:10 -08001685 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001686 case CE4100_SSP:
1687 tmp = CE4100_SSCR1_RxTresh(RX_THRESH_CE4100_DFLT) |
1688 CE4100_SSCR1_TxTresh(TX_THRESH_CE4100_DFLT);
1689 pxa2xx_spi_write(drv_data, SSCR1, tmp);
1690 tmp = SSCR0_SCR(2) | SSCR0_Motorola | SSCR0_DataSize(8);
1691 pxa2xx_spi_write(drv_data, SSCR0, tmp);
Weike Chene5262d02014-11-26 02:35:10 -08001692 default:
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001693 tmp = SSCR1_RxTresh(RX_THRESH_DFLT) |
1694 SSCR1_TxTresh(TX_THRESH_DFLT);
1695 pxa2xx_spi_write(drv_data, SSCR1, tmp);
1696 tmp = SSCR0_SCR(2) | SSCR0_Motorola | SSCR0_DataSize(8);
1697 pxa2xx_spi_write(drv_data, SSCR0, tmp);
Weike Chene5262d02014-11-26 02:35:10 -08001698 break;
1699 }
1700
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001701 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001702 pxa2xx_spi_write(drv_data, SSTO, 0);
Weike Chene5262d02014-11-26 02:35:10 -08001703
1704 if (!is_quark_x1000_ssp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001705 pxa2xx_spi_write(drv_data, SSPSP, 0);
Stephen Streete0c99052006-03-07 23:53:24 -08001706
Jarkko Nikula8b136ba2015-10-28 15:13:41 +02001707 if (is_lpss_ssp(drv_data)) {
1708 lpss_ssp_setup(drv_data);
1709 config = lpss_get_config(drv_data);
1710 if (config->reg_capabilities >= 0) {
1711 tmp = __lpss_ssp_read_priv(drv_data,
1712 config->reg_capabilities);
1713 tmp &= LPSS_CAPS_CS_EN_MASK;
1714 tmp >>= LPSS_CAPS_CS_EN_SHIFT;
1715 platform_info->num_chipselect = ffz(tmp);
Mika Westerberg30f3a6a2016-02-08 17:14:31 +02001716 } else if (config->cs_num) {
1717 platform_info->num_chipselect = config->cs_num;
Jarkko Nikula8b136ba2015-10-28 15:13:41 +02001718 }
1719 }
1720 master->num_chipselect = platform_info->num_chipselect;
1721
Mika Westerberg99f499c2016-09-26 15:19:50 +03001722 count = gpiod_count(&pdev->dev, "cs");
1723 if (count > 0) {
1724 int i;
1725
1726 master->num_chipselect = max_t(int, count,
1727 master->num_chipselect);
1728
1729 drv_data->cs_gpiods = devm_kcalloc(&pdev->dev,
1730 master->num_chipselect, sizeof(struct gpio_desc *),
1731 GFP_KERNEL);
1732 if (!drv_data->cs_gpiods) {
1733 status = -ENOMEM;
1734 goto out_error_clock_enabled;
1735 }
1736
1737 for (i = 0; i < master->num_chipselect; i++) {
1738 struct gpio_desc *gpiod;
1739
1740 gpiod = devm_gpiod_get_index(dev, "cs", i,
1741 GPIOD_OUT_HIGH);
1742 if (IS_ERR(gpiod)) {
1743 /* Means use native chip select */
1744 if (PTR_ERR(gpiod) == -ENOENT)
1745 continue;
1746
1747 status = (int)PTR_ERR(gpiod);
1748 goto out_error_clock_enabled;
1749 } else {
1750 drv_data->cs_gpiods[i] = gpiod;
1751 }
1752 }
1753 }
1754
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001755 tasklet_init(&drv_data->pump_transfers, pump_transfers,
1756 (unsigned long)drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001757
Antonio Ospite836d1a222014-05-30 18:18:09 +02001758 pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
1759 pm_runtime_use_autosuspend(&pdev->dev);
1760 pm_runtime_set_active(&pdev->dev);
1761 pm_runtime_enable(&pdev->dev);
1762
Stephen Streete0c99052006-03-07 23:53:24 -08001763 /* Register with the SPI framework */
1764 platform_set_drvdata(pdev, drv_data);
Jingoo Hana807fcd2013-09-24 13:46:55 +09001765 status = devm_spi_register_master(&pdev->dev, master);
Stephen Streete0c99052006-03-07 23:53:24 -08001766 if (status != 0) {
1767 dev_err(&pdev->dev, "problem registering spi master\n");
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001768 goto out_error_clock_enabled;
Stephen Streete0c99052006-03-07 23:53:24 -08001769 }
1770
1771 return status;
1772
Stephen Streete0c99052006-03-07 23:53:24 -08001773out_error_clock_enabled:
Mika Westerberg3343b7a2013-01-22 12:26:27 +02001774 clk_disable_unprepare(ssp->clk);
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001775 pxa2xx_spi_dma_release(drv_data);
eric miao2f1a74e2007-11-21 18:50:53 +08001776 free_irq(ssp->irq, drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001777
1778out_error_master_alloc:
1779 spi_master_put(master);
Haojian Zhuangbaffe162010-05-05 10:11:15 -04001780 pxa_ssp_free(ssp);
Stephen Streete0c99052006-03-07 23:53:24 -08001781 return status;
1782}
1783
1784static int pxa2xx_spi_remove(struct platform_device *pdev)
1785{
1786 struct driver_data *drv_data = platform_get_drvdata(pdev);
Julia Lawall51e911e2009-01-06 14:41:45 -08001787 struct ssp_device *ssp;
Stephen Streete0c99052006-03-07 23:53:24 -08001788
1789 if (!drv_data)
1790 return 0;
Julia Lawall51e911e2009-01-06 14:41:45 -08001791 ssp = drv_data->ssp;
Stephen Streete0c99052006-03-07 23:53:24 -08001792
Mika Westerberg7d94a502013-01-22 12:26:30 +02001793 pm_runtime_get_sync(&pdev->dev);
1794
Stephen Streete0c99052006-03-07 23:53:24 -08001795 /* Disable the SSP at the peripheral and SOC level */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001796 pxa2xx_spi_write(drv_data, SSCR0, 0);
Mika Westerberg3343b7a2013-01-22 12:26:27 +02001797 clk_disable_unprepare(ssp->clk);
Stephen Streete0c99052006-03-07 23:53:24 -08001798
1799 /* Release DMA */
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001800 if (drv_data->master_info->enable_dma)
1801 pxa2xx_spi_dma_release(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001802
Mika Westerberg7d94a502013-01-22 12:26:30 +02001803 pm_runtime_put_noidle(&pdev->dev);
1804 pm_runtime_disable(&pdev->dev);
1805
Stephen Streete0c99052006-03-07 23:53:24 -08001806 /* Release IRQ */
eric miao2f1a74e2007-11-21 18:50:53 +08001807 free_irq(ssp->irq, drv_data);
1808
1809 /* Release SSP */
Haojian Zhuangbaffe162010-05-05 10:11:15 -04001810 pxa_ssp_free(ssp);
Stephen Streete0c99052006-03-07 23:53:24 -08001811
Stephen Streete0c99052006-03-07 23:53:24 -08001812 return 0;
1813}
1814
1815static void pxa2xx_spi_shutdown(struct platform_device *pdev)
1816{
1817 int status = 0;
1818
1819 if ((status = pxa2xx_spi_remove(pdev)) != 0)
1820 dev_err(&pdev->dev, "shutdown failed with %d\n", status);
1821}
1822
Mika Westerberg382cebb2014-01-16 14:50:55 +02001823#ifdef CONFIG_PM_SLEEP
Mike Rapoport86d25932009-07-21 17:50:16 +03001824static int pxa2xx_spi_suspend(struct device *dev)
Stephen Streete0c99052006-03-07 23:53:24 -08001825{
Mike Rapoport86d25932009-07-21 17:50:16 +03001826 struct driver_data *drv_data = dev_get_drvdata(dev);
eric miao2f1a74e2007-11-21 18:50:53 +08001827 struct ssp_device *ssp = drv_data->ssp;
Jarkko Nikulabffc9672016-09-07 17:04:05 +03001828 int status;
Stephen Streete0c99052006-03-07 23:53:24 -08001829
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001830 status = spi_master_suspend(drv_data->master);
Stephen Streete0c99052006-03-07 23:53:24 -08001831 if (status != 0)
1832 return status;
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001833 pxa2xx_spi_write(drv_data, SSCR0, 0);
Dmitry Eremin-Solenikov2b9375b2014-11-06 14:08:29 +03001834
1835 if (!pm_runtime_suspended(dev))
1836 clk_disable_unprepare(ssp->clk);
Stephen Streete0c99052006-03-07 23:53:24 -08001837
1838 return 0;
1839}
1840
Mike Rapoport86d25932009-07-21 17:50:16 +03001841static int pxa2xx_spi_resume(struct device *dev)
Stephen Streete0c99052006-03-07 23:53:24 -08001842{
Mike Rapoport86d25932009-07-21 17:50:16 +03001843 struct driver_data *drv_data = dev_get_drvdata(dev);
eric miao2f1a74e2007-11-21 18:50:53 +08001844 struct ssp_device *ssp = drv_data->ssp;
Jarkko Nikulabffc9672016-09-07 17:04:05 +03001845 int status;
Stephen Streete0c99052006-03-07 23:53:24 -08001846
1847 /* Enable the SSP clock */
Dmitry Eremin-Solenikov2b9375b2014-11-06 14:08:29 +03001848 if (!pm_runtime_suspended(dev))
1849 clk_prepare_enable(ssp->clk);
Stephen Streete0c99052006-03-07 23:53:24 -08001850
Chew, Chiau Eec50325f2013-11-29 02:13:11 +08001851 /* Restore LPSS private register bits */
Jarkko Nikula48421ad2015-01-28 10:09:42 +02001852 if (is_lpss_ssp(drv_data))
1853 lpss_ssp_setup(drv_data);
Chew, Chiau Eec50325f2013-11-29 02:13:11 +08001854
Stephen Streete0c99052006-03-07 23:53:24 -08001855 /* Start the queue running */
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001856 status = spi_master_resume(drv_data->master);
Stephen Streete0c99052006-03-07 23:53:24 -08001857 if (status != 0) {
Mike Rapoport86d25932009-07-21 17:50:16 +03001858 dev_err(dev, "problem starting queue (%d)\n", status);
Stephen Streete0c99052006-03-07 23:53:24 -08001859 return status;
1860 }
1861
1862 return 0;
1863}
Mika Westerberg7d94a502013-01-22 12:26:30 +02001864#endif
1865
Rafael J. Wysockiec833052014-12-13 00:41:15 +01001866#ifdef CONFIG_PM
Mika Westerberg7d94a502013-01-22 12:26:30 +02001867static int pxa2xx_spi_runtime_suspend(struct device *dev)
1868{
1869 struct driver_data *drv_data = dev_get_drvdata(dev);
1870
1871 clk_disable_unprepare(drv_data->ssp->clk);
1872 return 0;
1873}
1874
1875static int pxa2xx_spi_runtime_resume(struct device *dev)
1876{
1877 struct driver_data *drv_data = dev_get_drvdata(dev);
1878
1879 clk_prepare_enable(drv_data->ssp->clk);
1880 return 0;
1881}
1882#endif
Mike Rapoport86d25932009-07-21 17:50:16 +03001883
Alexey Dobriyan47145212009-12-14 18:00:08 -08001884static const struct dev_pm_ops pxa2xx_spi_pm_ops = {
Mika Westerberg7d94a502013-01-22 12:26:30 +02001885 SET_SYSTEM_SLEEP_PM_OPS(pxa2xx_spi_suspend, pxa2xx_spi_resume)
1886 SET_RUNTIME_PM_OPS(pxa2xx_spi_runtime_suspend,
1887 pxa2xx_spi_runtime_resume, NULL)
Mike Rapoport86d25932009-07-21 17:50:16 +03001888};
Stephen Streete0c99052006-03-07 23:53:24 -08001889
1890static struct platform_driver driver = {
1891 .driver = {
Mike Rapoport86d25932009-07-21 17:50:16 +03001892 .name = "pxa2xx-spi",
Mike Rapoport86d25932009-07-21 17:50:16 +03001893 .pm = &pxa2xx_spi_pm_ops,
Mika Westerberga3496852013-01-22 12:26:33 +02001894 .acpi_match_table = ACPI_PTR(pxa2xx_spi_acpi_match),
Stephen Streete0c99052006-03-07 23:53:24 -08001895 },
Sebastian Andrzej Siewiorfbd29a12010-11-19 09:00:11 -08001896 .probe = pxa2xx_spi_probe,
David Brownelld1e44d92007-10-16 01:27:46 -07001897 .remove = pxa2xx_spi_remove,
Stephen Streete0c99052006-03-07 23:53:24 -08001898 .shutdown = pxa2xx_spi_shutdown,
Stephen Streete0c99052006-03-07 23:53:24 -08001899};
1900
1901static int __init pxa2xx_spi_init(void)
1902{
Sebastian Andrzej Siewiorfbd29a12010-11-19 09:00:11 -08001903 return platform_driver_register(&driver);
Stephen Streete0c99052006-03-07 23:53:24 -08001904}
Antonio Ospite5b61a742009-09-22 16:46:10 -07001905subsys_initcall(pxa2xx_spi_init);
Stephen Streete0c99052006-03-07 23:53:24 -08001906
1907static void __exit pxa2xx_spi_exit(void)
1908{
1909 platform_driver_unregister(&driver);
1910}
1911module_exit(pxa2xx_spi_exit);