blob: d6239fa718be9e251f577b9d9dd792a0e5c5ead5 [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>
Mika Westerberg089bd462016-09-29 09:45:20 +030031#include <linux/gpio/consumer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Mika Westerberg3343b7a2013-01-22 12:26:27 +020033#include <linux/clk.h>
Mika Westerberg7d94a502013-01-22 12:26:30 +020034#include <linux/pm_runtime.h>
Mika Westerberga3496852013-01-22 12:26:33 +020035#include <linux/acpi.h>
Stephen Streete0c99052006-03-07 23:53:24 -080036
Mika Westerbergcd7bed02013-01-22 12:26:28 +020037#include "spi-pxa2xx.h"
Stephen Streete0c99052006-03-07 23:53:24 -080038
39MODULE_AUTHOR("Stephen Street");
Will Newton037cdaf2007-12-10 15:49:25 -080040MODULE_DESCRIPTION("PXA2xx SSP SPI Controller");
Stephen Streete0c99052006-03-07 23:53:24 -080041MODULE_LICENSE("GPL");
Kay Sievers7e38c3c2008-04-10 21:29:20 -070042MODULE_ALIAS("platform:pxa2xx-spi");
Stephen Streete0c99052006-03-07 23:53:24 -080043
Vernon Sauderf1f640a2008-10-15 22:02:43 -070044#define TIMOUT_DFLT 1000
45
Ned Forresterb97c74b2008-02-23 15:23:40 -080046/*
47 * for testing SSCR1 changes that require SSP restart, basically
48 * everything except the service and interrupt enables, the pxa270 developer
49 * manual says only SSCR1_SCFR, SSCR1_SPH, SSCR1_SPO need to be in this
50 * list, but the PXA255 dev man says all bits without really meaning the
51 * service and interrupt enables
52 */
53#define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \
Stephen Street8d94cc52006-12-10 02:18:54 -080054 | SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
Ned Forresterb97c74b2008-02-23 15:23:40 -080055 | SSCR1_SFRMDIR | SSCR1_RWOT | SSCR1_TRAIL \
56 | SSCR1_IFS | SSCR1_STRF | SSCR1_EFWR \
57 | SSCR1_RFT | SSCR1_TFT | SSCR1_MWDS \
58 | SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
Stephen Street8d94cc52006-12-10 02:18:54 -080059
Weike Chene5262d02014-11-26 02:35:10 -080060#define QUARK_X1000_SSCR1_CHANGE_MASK (QUARK_X1000_SSCR1_STRF \
61 | QUARK_X1000_SSCR1_EFWR \
62 | QUARK_X1000_SSCR1_RFT \
63 | QUARK_X1000_SSCR1_TFT \
64 | SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
65
Andy Shevchenko7c7289a2016-09-07 15:43:22 +030066#define CE4100_SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \
67 | SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
68 | SSCR1_SFRMDIR | SSCR1_RWOT | SSCR1_TRAIL \
69 | SSCR1_IFS | SSCR1_STRF | SSCR1_EFWR \
70 | CE4100_SSCR1_RFT | CE4100_SSCR1_TFT | SSCR1_MWDS \
71 | SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
72
Jarkko Nikula624ea722015-10-28 15:13:39 +020073#define LPSS_GENERAL_REG_RXTO_HOLDOFF_DISABLE BIT(24)
74#define LPSS_CS_CONTROL_SW_MODE BIT(0)
75#define LPSS_CS_CONTROL_CS_HIGH BIT(1)
Jarkko Nikula8b136ba2015-10-28 15:13:41 +020076#define LPSS_CAPS_CS_EN_SHIFT 9
77#define LPSS_CAPS_CS_EN_MASK (0xf << LPSS_CAPS_CS_EN_SHIFT)
Mika Westerberga0d26422013-01-22 12:26:32 +020078
Jarkko Nikuladccf7362015-06-04 16:55:11 +030079struct lpss_config {
80 /* LPSS offset from drv_data->ioaddr */
81 unsigned offset;
82 /* Register offsets from drv_data->lpss_base or -1 */
83 int reg_general;
84 int reg_ssp;
85 int reg_cs_ctrl;
Jarkko Nikula8b136ba2015-10-28 15:13:41 +020086 int reg_capabilities;
Jarkko Nikuladccf7362015-06-04 16:55:11 +030087 /* FIFO thresholds */
88 u32 rx_threshold;
89 u32 tx_threshold_lo;
90 u32 tx_threshold_hi;
Mika Westerbergc1e4a532016-02-08 17:14:30 +020091 /* Chip select control */
92 unsigned cs_sel_shift;
93 unsigned cs_sel_mask;
Mika Westerberg30f3a6a2016-02-08 17:14:31 +020094 unsigned cs_num;
Jarkko Nikuladccf7362015-06-04 16:55:11 +030095};
96
97/* Keep these sorted with enum pxa_ssp_type */
98static const struct lpss_config lpss_platforms[] = {
99 { /* LPSS_LPT_SSP */
100 .offset = 0x800,
101 .reg_general = 0x08,
102 .reg_ssp = 0x0c,
103 .reg_cs_ctrl = 0x18,
Jarkko Nikula8b136ba2015-10-28 15:13:41 +0200104 .reg_capabilities = -1,
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300105 .rx_threshold = 64,
106 .tx_threshold_lo = 160,
107 .tx_threshold_hi = 224,
108 },
109 { /* LPSS_BYT_SSP */
110 .offset = 0x400,
111 .reg_general = 0x08,
112 .reg_ssp = 0x0c,
113 .reg_cs_ctrl = 0x18,
Jarkko Nikula8b136ba2015-10-28 15:13:41 +0200114 .reg_capabilities = -1,
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300115 .rx_threshold = 64,
116 .tx_threshold_lo = 160,
117 .tx_threshold_hi = 224,
118 },
Mika Westerberg30f3a6a2016-02-08 17:14:31 +0200119 { /* LPSS_BSW_SSP */
120 .offset = 0x400,
121 .reg_general = 0x08,
122 .reg_ssp = 0x0c,
123 .reg_cs_ctrl = 0x18,
124 .reg_capabilities = -1,
125 .rx_threshold = 64,
126 .tx_threshold_lo = 160,
127 .tx_threshold_hi = 224,
128 .cs_sel_shift = 2,
129 .cs_sel_mask = 1 << 2,
130 .cs_num = 2,
131 },
Jarkko Nikula34cadd92015-07-30 16:30:07 +0300132 { /* LPSS_SPT_SSP */
133 .offset = 0x200,
134 .reg_general = -1,
135 .reg_ssp = 0x20,
136 .reg_cs_ctrl = 0x24,
Jarkko Nikula66ec2462016-04-26 10:08:26 +0300137 .reg_capabilities = -1,
Jarkko Nikula34cadd92015-07-30 16:30:07 +0300138 .rx_threshold = 1,
139 .tx_threshold_lo = 32,
140 .tx_threshold_hi = 56,
141 },
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +0200142 { /* LPSS_BXT_SSP */
143 .offset = 0x200,
144 .reg_general = -1,
145 .reg_ssp = 0x20,
146 .reg_cs_ctrl = 0x24,
147 .reg_capabilities = 0xfc,
148 .rx_threshold = 1,
149 .tx_threshold_lo = 16,
150 .tx_threshold_hi = 48,
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200151 .cs_sel_shift = 8,
152 .cs_sel_mask = 3 << 8,
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +0200153 },
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300154};
155
156static inline const struct lpss_config
157*lpss_get_config(const struct driver_data *drv_data)
158{
159 return &lpss_platforms[drv_data->ssp_type - LPSS_LPT_SSP];
160}
161
Mika Westerberga0d26422013-01-22 12:26:32 +0200162static bool is_lpss_ssp(const struct driver_data *drv_data)
163{
Jarkko Nikula03fbf482015-06-04 16:55:10 +0300164 switch (drv_data->ssp_type) {
165 case LPSS_LPT_SSP:
166 case LPSS_BYT_SSP:
Mika Westerberg30f3a6a2016-02-08 17:14:31 +0200167 case LPSS_BSW_SSP:
Jarkko Nikula34cadd92015-07-30 16:30:07 +0300168 case LPSS_SPT_SSP:
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +0200169 case LPSS_BXT_SSP:
Jarkko Nikula03fbf482015-06-04 16:55:10 +0300170 return true;
171 default:
172 return false;
173 }
Mika Westerberga0d26422013-01-22 12:26:32 +0200174}
175
Weike Chene5262d02014-11-26 02:35:10 -0800176static bool is_quark_x1000_ssp(const struct driver_data *drv_data)
177{
178 return drv_data->ssp_type == QUARK_X1000_SSP;
179}
180
Weike Chen4fdb2422014-10-08 08:50:22 -0700181static u32 pxa2xx_spi_get_ssrc1_change_mask(const struct driver_data *drv_data)
182{
183 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800184 case QUARK_X1000_SSP:
185 return QUARK_X1000_SSCR1_CHANGE_MASK;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300186 case CE4100_SSP:
187 return CE4100_SSCR1_CHANGE_MASK;
Weike Chen4fdb2422014-10-08 08:50:22 -0700188 default:
189 return SSCR1_CHANGE_MASK;
190 }
191}
192
193static u32
194pxa2xx_spi_get_rx_default_thre(const struct driver_data *drv_data)
195{
196 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800197 case QUARK_X1000_SSP:
198 return RX_THRESH_QUARK_X1000_DFLT;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300199 case CE4100_SSP:
200 return RX_THRESH_CE4100_DFLT;
Weike Chen4fdb2422014-10-08 08:50:22 -0700201 default:
202 return RX_THRESH_DFLT;
203 }
204}
205
206static bool pxa2xx_spi_txfifo_full(const struct driver_data *drv_data)
207{
Weike Chen4fdb2422014-10-08 08:50:22 -0700208 u32 mask;
209
210 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800211 case QUARK_X1000_SSP:
212 mask = QUARK_X1000_SSSR_TFL_MASK;
213 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300214 case CE4100_SSP:
215 mask = CE4100_SSSR_TFL_MASK;
216 break;
Weike Chen4fdb2422014-10-08 08:50:22 -0700217 default:
218 mask = SSSR_TFL_MASK;
219 break;
220 }
221
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200222 return (pxa2xx_spi_read(drv_data, SSSR) & mask) == mask;
Weike Chen4fdb2422014-10-08 08:50:22 -0700223}
224
225static void pxa2xx_spi_clear_rx_thre(const struct driver_data *drv_data,
226 u32 *sccr1_reg)
227{
228 u32 mask;
229
230 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800231 case QUARK_X1000_SSP:
232 mask = QUARK_X1000_SSCR1_RFT;
233 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300234 case CE4100_SSP:
235 mask = CE4100_SSCR1_RFT;
236 break;
Weike Chen4fdb2422014-10-08 08:50:22 -0700237 default:
238 mask = SSCR1_RFT;
239 break;
240 }
241 *sccr1_reg &= ~mask;
242}
243
244static void pxa2xx_spi_set_rx_thre(const struct driver_data *drv_data,
245 u32 *sccr1_reg, u32 threshold)
246{
247 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800248 case QUARK_X1000_SSP:
249 *sccr1_reg |= QUARK_X1000_SSCR1_RxTresh(threshold);
250 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300251 case CE4100_SSP:
252 *sccr1_reg |= CE4100_SSCR1_RxTresh(threshold);
253 break;
Weike Chen4fdb2422014-10-08 08:50:22 -0700254 default:
255 *sccr1_reg |= SSCR1_RxTresh(threshold);
256 break;
257 }
258}
259
260static u32 pxa2xx_configure_sscr0(const struct driver_data *drv_data,
261 u32 clk_div, u8 bits)
262{
263 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800264 case QUARK_X1000_SSP:
265 return clk_div
266 | QUARK_X1000_SSCR0_Motorola
267 | QUARK_X1000_SSCR0_DataSize(bits > 32 ? 8 : bits)
268 | SSCR0_SSE;
Weike Chen4fdb2422014-10-08 08:50:22 -0700269 default:
270 return clk_div
271 | SSCR0_Motorola
272 | SSCR0_DataSize(bits > 16 ? bits - 16 : bits)
273 | SSCR0_SSE
274 | (bits > 16 ? SSCR0_EDSS : 0);
275 }
276}
277
Mika Westerberga0d26422013-01-22 12:26:32 +0200278/*
279 * Read and write LPSS SSP private registers. Caller must first check that
280 * is_lpss_ssp() returns true before these can be called.
281 */
282static u32 __lpss_ssp_read_priv(struct driver_data *drv_data, unsigned offset)
283{
284 WARN_ON(!drv_data->lpss_base);
285 return readl(drv_data->lpss_base + offset);
286}
287
288static void __lpss_ssp_write_priv(struct driver_data *drv_data,
289 unsigned offset, u32 value)
290{
291 WARN_ON(!drv_data->lpss_base);
292 writel(value, drv_data->lpss_base + offset);
293}
294
295/*
296 * lpss_ssp_setup - perform LPSS SSP specific setup
297 * @drv_data: pointer to the driver private data
298 *
299 * Perform LPSS SSP specific setup. This function must be called first if
300 * one is going to use LPSS SSP private registers.
301 */
302static void lpss_ssp_setup(struct driver_data *drv_data)
303{
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300304 const struct lpss_config *config;
305 u32 value;
Mika Westerberga0d26422013-01-22 12:26:32 +0200306
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300307 config = lpss_get_config(drv_data);
308 drv_data->lpss_base = drv_data->ioaddr + config->offset;
Mika Westerberga0d26422013-01-22 12:26:32 +0200309
310 /* Enable software chip select control */
Jarkko Nikula0e897212015-10-22 16:44:42 +0300311 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
Jarkko Nikula624ea722015-10-28 15:13:39 +0200312 value &= ~(LPSS_CS_CONTROL_SW_MODE | LPSS_CS_CONTROL_CS_HIGH);
313 value |= LPSS_CS_CONTROL_SW_MODE | LPSS_CS_CONTROL_CS_HIGH;
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300314 __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value);
Mika Westerberg0054e282013-03-05 12:05:17 +0200315
316 /* Enable multiblock DMA transfers */
Mika Westerberg1de70612013-07-03 13:25:06 +0300317 if (drv_data->master_info->enable_dma) {
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300318 __lpss_ssp_write_priv(drv_data, config->reg_ssp, 1);
Mika Westerberg1de70612013-07-03 13:25:06 +0300319
Jarkko Nikula82ba2c22015-06-04 16:55:12 +0300320 if (config->reg_general >= 0) {
321 value = __lpss_ssp_read_priv(drv_data,
322 config->reg_general);
Jarkko Nikula624ea722015-10-28 15:13:39 +0200323 value |= LPSS_GENERAL_REG_RXTO_HOLDOFF_DISABLE;
Jarkko Nikula82ba2c22015-06-04 16:55:12 +0300324 __lpss_ssp_write_priv(drv_data,
325 config->reg_general, value);
326 }
Mika Westerberg1de70612013-07-03 13:25:06 +0300327 }
Mika Westerberga0d26422013-01-22 12:26:32 +0200328}
329
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200330static void lpss_ssp_select_cs(struct driver_data *drv_data,
331 const struct lpss_config *config)
332{
333 u32 value, cs;
334
335 if (!config->cs_sel_mask)
336 return;
337
338 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
339
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300340 cs = drv_data->master->cur_msg->spi->chip_select;
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200341 cs <<= config->cs_sel_shift;
342 if (cs != (value & config->cs_sel_mask)) {
343 /*
344 * When switching another chip select output active the
345 * output must be selected first and wait 2 ssp_clk cycles
346 * before changing state to active. Otherwise a short
347 * glitch will occur on the previous chip select since
348 * output select is latched but state control is not.
349 */
350 value &= ~config->cs_sel_mask;
351 value |= cs;
352 __lpss_ssp_write_priv(drv_data,
353 config->reg_cs_ctrl, value);
354 ndelay(1000000000 /
355 (drv_data->master->max_speed_hz / 2));
356 }
357}
358
Mika Westerberga0d26422013-01-22 12:26:32 +0200359static void lpss_ssp_cs_control(struct driver_data *drv_data, bool enable)
360{
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300361 const struct lpss_config *config;
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200362 u32 value;
Mika Westerberga0d26422013-01-22 12:26:32 +0200363
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300364 config = lpss_get_config(drv_data);
365
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200366 if (enable)
367 lpss_ssp_select_cs(drv_data, config);
368
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300369 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200370 if (enable)
Jarkko Nikula624ea722015-10-28 15:13:39 +0200371 value &= ~LPSS_CS_CONTROL_CS_HIGH;
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200372 else
Jarkko Nikula624ea722015-10-28 15:13:39 +0200373 value |= LPSS_CS_CONTROL_CS_HIGH;
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300374 __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value);
Mika Westerberga0d26422013-01-22 12:26:32 +0200375}
376
Eric Miaoa7bb3902009-04-06 19:00:54 -0700377static void cs_assert(struct driver_data *drv_data)
378{
Jarkko Nikula96579a42016-09-07 17:04:07 +0300379 struct chip_data *chip =
380 spi_get_ctldata(drv_data->master->cur_msg->spi);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700381
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800382 if (drv_data->ssp_type == CE4100_SSP) {
Jarkko Nikula96579a42016-09-07 17:04:07 +0300383 pxa2xx_spi_write(drv_data, SSSR, chip->frm);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800384 return;
385 }
386
Eric Miaoa7bb3902009-04-06 19:00:54 -0700387 if (chip->cs_control) {
388 chip->cs_control(PXA2XX_CS_ASSERT);
389 return;
390 }
391
Mika Westerberga0d26422013-01-22 12:26:32 +0200392 if (gpio_is_valid(chip->gpio_cs)) {
Eric Miaoa7bb3902009-04-06 19:00:54 -0700393 gpio_set_value(chip->gpio_cs, chip->gpio_cs_inverted);
Mika Westerberga0d26422013-01-22 12:26:32 +0200394 return;
395 }
396
Jarkko Nikula7566bcc2014-12-18 15:04:20 +0200397 if (is_lpss_ssp(drv_data))
398 lpss_ssp_cs_control(drv_data, true);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700399}
400
401static void cs_deassert(struct driver_data *drv_data)
402{
Jarkko Nikula96579a42016-09-07 17:04:07 +0300403 struct chip_data *chip =
404 spi_get_ctldata(drv_data->master->cur_msg->spi);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700405
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800406 if (drv_data->ssp_type == CE4100_SSP)
407 return;
408
Eric Miaoa7bb3902009-04-06 19:00:54 -0700409 if (chip->cs_control) {
Daniel Ribeiro2b2562d2009-04-08 22:48:03 -0300410 chip->cs_control(PXA2XX_CS_DEASSERT);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700411 return;
412 }
413
Mika Westerberga0d26422013-01-22 12:26:32 +0200414 if (gpio_is_valid(chip->gpio_cs)) {
Eric Miaoa7bb3902009-04-06 19:00:54 -0700415 gpio_set_value(chip->gpio_cs, !chip->gpio_cs_inverted);
Mika Westerberga0d26422013-01-22 12:26:32 +0200416 return;
417 }
418
Jarkko Nikula7566bcc2014-12-18 15:04:20 +0200419 if (is_lpss_ssp(drv_data))
420 lpss_ssp_cs_control(drv_data, false);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700421}
422
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200423int pxa2xx_spi_flush(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800424{
425 unsigned long limit = loops_per_jiffy << 1;
426
Stephen Streete0c99052006-03-07 23:53:24 -0800427 do {
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200428 while (pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
429 pxa2xx_spi_read(drv_data, SSDR);
430 } while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY) && --limit);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800431 write_SSSR_CS(drv_data, SSSR_ROR);
Stephen Streete0c99052006-03-07 23:53:24 -0800432
433 return limit;
434}
435
Stephen Street8d94cc52006-12-10 02:18:54 -0800436static int null_writer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800437{
Stephen Street9708c122006-03-28 14:05:23 -0800438 u8 n_bytes = drv_data->n_bytes;
Stephen Streete0c99052006-03-07 23:53:24 -0800439
Weike Chen4fdb2422014-10-08 08:50:22 -0700440 if (pxa2xx_spi_txfifo_full(drv_data)
Stephen Street8d94cc52006-12-10 02:18:54 -0800441 || (drv_data->tx == drv_data->tx_end))
442 return 0;
443
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200444 pxa2xx_spi_write(drv_data, SSDR, 0);
Stephen Street8d94cc52006-12-10 02:18:54 -0800445 drv_data->tx += n_bytes;
446
447 return 1;
Stephen Streete0c99052006-03-07 23:53:24 -0800448}
449
Stephen Street8d94cc52006-12-10 02:18:54 -0800450static int null_reader(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800451{
Stephen Street9708c122006-03-28 14:05:23 -0800452 u8 n_bytes = drv_data->n_bytes;
Stephen Streete0c99052006-03-07 23:53:24 -0800453
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200454 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
455 && (drv_data->rx < drv_data->rx_end)) {
456 pxa2xx_spi_read(drv_data, SSDR);
Stephen Streete0c99052006-03-07 23:53:24 -0800457 drv_data->rx += n_bytes;
458 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800459
460 return drv_data->rx == drv_data->rx_end;
Stephen Streete0c99052006-03-07 23:53:24 -0800461}
462
Stephen Street8d94cc52006-12-10 02:18:54 -0800463static int u8_writer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800464{
Weike Chen4fdb2422014-10-08 08:50:22 -0700465 if (pxa2xx_spi_txfifo_full(drv_data)
Stephen Street8d94cc52006-12-10 02:18:54 -0800466 || (drv_data->tx == drv_data->tx_end))
467 return 0;
468
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200469 pxa2xx_spi_write(drv_data, SSDR, *(u8 *)(drv_data->tx));
Stephen Street8d94cc52006-12-10 02:18:54 -0800470 ++drv_data->tx;
471
472 return 1;
Stephen Streete0c99052006-03-07 23:53:24 -0800473}
474
Stephen Street8d94cc52006-12-10 02:18:54 -0800475static int u8_reader(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800476{
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200477 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
478 && (drv_data->rx < drv_data->rx_end)) {
479 *(u8 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
Stephen Streete0c99052006-03-07 23:53:24 -0800480 ++drv_data->rx;
481 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800482
483 return drv_data->rx == drv_data->rx_end;
Stephen Streete0c99052006-03-07 23:53:24 -0800484}
485
Stephen Street8d94cc52006-12-10 02:18:54 -0800486static int u16_writer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800487{
Weike Chen4fdb2422014-10-08 08:50:22 -0700488 if (pxa2xx_spi_txfifo_full(drv_data)
Stephen Street8d94cc52006-12-10 02:18:54 -0800489 || (drv_data->tx == drv_data->tx_end))
490 return 0;
491
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200492 pxa2xx_spi_write(drv_data, SSDR, *(u16 *)(drv_data->tx));
Stephen Street8d94cc52006-12-10 02:18:54 -0800493 drv_data->tx += 2;
494
495 return 1;
Stephen Streete0c99052006-03-07 23:53:24 -0800496}
497
Stephen Street8d94cc52006-12-10 02:18:54 -0800498static int u16_reader(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800499{
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200500 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
501 && (drv_data->rx < drv_data->rx_end)) {
502 *(u16 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
Stephen Streete0c99052006-03-07 23:53:24 -0800503 drv_data->rx += 2;
504 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800505
506 return drv_data->rx == drv_data->rx_end;
Stephen Streete0c99052006-03-07 23:53:24 -0800507}
Stephen Street8d94cc52006-12-10 02:18:54 -0800508
509static int u32_writer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800510{
Weike Chen4fdb2422014-10-08 08:50:22 -0700511 if (pxa2xx_spi_txfifo_full(drv_data)
Stephen Street8d94cc52006-12-10 02:18:54 -0800512 || (drv_data->tx == drv_data->tx_end))
513 return 0;
514
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200515 pxa2xx_spi_write(drv_data, SSDR, *(u32 *)(drv_data->tx));
Stephen Street8d94cc52006-12-10 02:18:54 -0800516 drv_data->tx += 4;
517
518 return 1;
Stephen Streete0c99052006-03-07 23:53:24 -0800519}
520
Stephen Street8d94cc52006-12-10 02:18:54 -0800521static int u32_reader(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800522{
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200523 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
524 && (drv_data->rx < drv_data->rx_end)) {
525 *(u32 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
Stephen Streete0c99052006-03-07 23:53:24 -0800526 drv_data->rx += 4;
527 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800528
529 return drv_data->rx == drv_data->rx_end;
Stephen Streete0c99052006-03-07 23:53:24 -0800530}
531
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200532void *pxa2xx_spi_next_transfer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800533{
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300534 struct spi_message *msg = drv_data->master->cur_msg;
Stephen Streete0c99052006-03-07 23:53:24 -0800535 struct spi_transfer *trans = drv_data->cur_transfer;
536
537 /* Move to next transfer */
538 if (trans->transfer_list.next != &msg->transfers) {
539 drv_data->cur_transfer =
540 list_entry(trans->transfer_list.next,
541 struct spi_transfer,
542 transfer_list);
543 return RUNNING_STATE;
544 } else
545 return DONE_STATE;
546}
547
Stephen Streete0c99052006-03-07 23:53:24 -0800548/* caller already set message->status; dma and pio irqs are blocked */
Stephen Street5daa3ba2006-05-20 15:00:19 -0700549static void giveback(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800550{
551 struct spi_transfer* last_transfer;
Stephen Street5daa3ba2006-05-20 15:00:19 -0700552 struct spi_message *msg;
Jarkko Nikula7a8d44b2016-02-04 12:30:57 +0200553 unsigned long timeout;
Stephen Streete0c99052006-03-07 23:53:24 -0800554
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300555 msg = drv_data->master->cur_msg;
Stephen Street5daa3ba2006-05-20 15:00:19 -0700556 drv_data->cur_transfer = NULL;
Stephen Street5daa3ba2006-05-20 15:00:19 -0700557
Axel Lin23e2c2a2014-02-12 22:13:27 +0800558 last_transfer = list_last_entry(&msg->transfers, struct spi_transfer,
Stephen Streete0c99052006-03-07 23:53:24 -0800559 transfer_list);
560
Ned Forrester84235972008-09-13 02:33:17 -0700561 /* Delay if requested before any change in chip select */
562 if (last_transfer->delay_usecs)
563 udelay(last_transfer->delay_usecs);
564
Jarkko Nikula7a8d44b2016-02-04 12:30:57 +0200565 /* Wait until SSP becomes idle before deasserting the CS */
566 timeout = jiffies + msecs_to_jiffies(10);
567 while (pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY &&
568 !time_after(jiffies, timeout))
569 cpu_relax();
570
Ned Forrester84235972008-09-13 02:33:17 -0700571 /* Drop chip select UNLESS cs_change is true or we are returning
572 * a message with an error, or next message is for another chip
573 */
Stephen Streete0c99052006-03-07 23:53:24 -0800574 if (!last_transfer->cs_change)
Eric Miaoa7bb3902009-04-06 19:00:54 -0700575 cs_deassert(drv_data);
Ned Forrester84235972008-09-13 02:33:17 -0700576 else {
577 struct spi_message *next_msg;
578
579 /* Holding of cs was hinted, but we need to make sure
580 * the next message is for the same chip. Don't waste
581 * time with the following tests unless this was hinted.
582 *
583 * We cannot postpone this until pump_messages, because
584 * after calling msg->complete (below) the driver that
585 * sent the current message could be unloaded, which
586 * could invalidate the cs_control() callback...
587 */
588
589 /* get a pointer to the next message, if any */
Mika Westerberg7f86bde2013-01-22 12:26:26 +0200590 next_msg = spi_get_next_queued_message(drv_data->master);
Ned Forrester84235972008-09-13 02:33:17 -0700591
592 /* see if the next and current messages point
593 * to the same chip
594 */
Christophe Ricarda52db652016-03-20 19:30:17 +0100595 if ((next_msg && next_msg->spi != msg->spi) ||
596 msg->state == ERROR_STATE)
Eric Miaoa7bb3902009-04-06 19:00:54 -0700597 cs_deassert(drv_data);
Ned Forrester84235972008-09-13 02:33:17 -0700598 }
Stephen Streete0c99052006-03-07 23:53:24 -0800599
Mika Westerbergc957e8f2014-12-29 10:33:36 +0200600 spi_finalize_current_message(drv_data->master);
Stephen Streete0c99052006-03-07 23:53:24 -0800601}
602
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800603static void reset_sccr1(struct driver_data *drv_data)
604{
Jarkko Nikula96579a42016-09-07 17:04:07 +0300605 struct chip_data *chip =
606 spi_get_ctldata(drv_data->master->cur_msg->spi);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800607 u32 sccr1_reg;
608
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200609 sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1;
Andy Shevchenko152bc192016-07-06 12:08:11 +0300610 switch (drv_data->ssp_type) {
611 case QUARK_X1000_SSP:
612 sccr1_reg &= ~QUARK_X1000_SSCR1_RFT;
613 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300614 case CE4100_SSP:
615 sccr1_reg &= ~CE4100_SSCR1_RFT;
616 break;
Andy Shevchenko152bc192016-07-06 12:08:11 +0300617 default:
618 sccr1_reg &= ~SSCR1_RFT;
619 break;
620 }
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800621 sccr1_reg |= chip->threshold;
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200622 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800623}
624
Stephen Street8d94cc52006-12-10 02:18:54 -0800625static void int_error_stop(struct driver_data *drv_data, const char* msg)
626{
Stephen Street8d94cc52006-12-10 02:18:54 -0800627 /* Stop and reset SSP */
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800628 write_SSSR_CS(drv_data, drv_data->clear_sr);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800629 reset_sccr1(drv_data);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800630 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200631 pxa2xx_spi_write(drv_data, SSTO, 0);
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200632 pxa2xx_spi_flush(drv_data);
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200633 pxa2xx_spi_write(drv_data, SSCR0,
634 pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
Stephen Street8d94cc52006-12-10 02:18:54 -0800635
636 dev_err(&drv_data->pdev->dev, "%s\n", msg);
637
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300638 drv_data->master->cur_msg->state = ERROR_STATE;
Stephen Street8d94cc52006-12-10 02:18:54 -0800639 tasklet_schedule(&drv_data->pump_transfers);
640}
641
642static void int_transfer_complete(struct driver_data *drv_data)
643{
Jarkko Nikula07550df2016-02-04 12:30:56 +0200644 /* Clear and disable interrupts */
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800645 write_SSSR_CS(drv_data, drv_data->clear_sr);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800646 reset_sccr1(drv_data);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800647 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200648 pxa2xx_spi_write(drv_data, SSTO, 0);
Stephen Street8d94cc52006-12-10 02:18:54 -0800649
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300650 /* Update total byte transferred return count actual bytes read */
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300651 drv_data->master->cur_msg->actual_length += drv_data->len -
Stephen Street8d94cc52006-12-10 02:18:54 -0800652 (drv_data->rx_end - drv_data->rx);
653
Ned Forrester84235972008-09-13 02:33:17 -0700654 /* Transfer delays and chip select release are
655 * handled in pump_transfers or giveback
656 */
Stephen Street8d94cc52006-12-10 02:18:54 -0800657
658 /* Move to next transfer */
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300659 drv_data->master->cur_msg->state = pxa2xx_spi_next_transfer(drv_data);
Stephen Street8d94cc52006-12-10 02:18:54 -0800660
661 /* Schedule transfer tasklet */
662 tasklet_schedule(&drv_data->pump_transfers);
663}
664
Stephen Streete0c99052006-03-07 23:53:24 -0800665static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
666{
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200667 u32 irq_mask = (pxa2xx_spi_read(drv_data, SSCR1) & SSCR1_TIE) ?
668 drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS;
Stephen Street8d94cc52006-12-10 02:18:54 -0800669
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200670 u32 irq_status = pxa2xx_spi_read(drv_data, SSSR) & irq_mask;
Stephen Streete0c99052006-03-07 23:53:24 -0800671
Stephen Street8d94cc52006-12-10 02:18:54 -0800672 if (irq_status & SSSR_ROR) {
673 int_error_stop(drv_data, "interrupt_transfer: fifo overrun");
674 return IRQ_HANDLED;
675 }
Stephen Streete0c99052006-03-07 23:53:24 -0800676
Stephen Street8d94cc52006-12-10 02:18:54 -0800677 if (irq_status & SSSR_TINT) {
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200678 pxa2xx_spi_write(drv_data, SSSR, SSSR_TINT);
Stephen Street8d94cc52006-12-10 02:18:54 -0800679 if (drv_data->read(drv_data)) {
680 int_transfer_complete(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -0800681 return IRQ_HANDLED;
682 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800683 }
Stephen Streete0c99052006-03-07 23:53:24 -0800684
Stephen Street8d94cc52006-12-10 02:18:54 -0800685 /* Drain rx fifo, Fill tx fifo and prevent overruns */
686 do {
687 if (drv_data->read(drv_data)) {
688 int_transfer_complete(drv_data);
689 return IRQ_HANDLED;
Stephen Streete0c99052006-03-07 23:53:24 -0800690 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800691 } while (drv_data->write(drv_data));
Stephen Streete0c99052006-03-07 23:53:24 -0800692
Stephen Street8d94cc52006-12-10 02:18:54 -0800693 if (drv_data->read(drv_data)) {
694 int_transfer_complete(drv_data);
695 return IRQ_HANDLED;
696 }
Stephen Streete0c99052006-03-07 23:53:24 -0800697
Stephen Street8d94cc52006-12-10 02:18:54 -0800698 if (drv_data->tx == drv_data->tx_end) {
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800699 u32 bytes_left;
700 u32 sccr1_reg;
701
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200702 sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800703 sccr1_reg &= ~SSCR1_TIE;
704
705 /*
706 * PXA25x_SSP has no timeout, set up rx threshould for the
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300707 * remaining RX bytes.
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800708 */
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800709 if (pxa25x_ssp_comp(drv_data)) {
Weike Chen4fdb2422014-10-08 08:50:22 -0700710 u32 rx_thre;
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800711
Weike Chen4fdb2422014-10-08 08:50:22 -0700712 pxa2xx_spi_clear_rx_thre(drv_data, &sccr1_reg);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800713
714 bytes_left = drv_data->rx_end - drv_data->rx;
715 switch (drv_data->n_bytes) {
716 case 4:
717 bytes_left >>= 1;
718 case 2:
719 bytes_left >>= 1;
Stephen Street8d94cc52006-12-10 02:18:54 -0800720 }
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800721
Weike Chen4fdb2422014-10-08 08:50:22 -0700722 rx_thre = pxa2xx_spi_get_rx_default_thre(drv_data);
723 if (rx_thre > bytes_left)
724 rx_thre = bytes_left;
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800725
Weike Chen4fdb2422014-10-08 08:50:22 -0700726 pxa2xx_spi_set_rx_thre(drv_data, &sccr1_reg, rx_thre);
Stephen Streete0c99052006-03-07 23:53:24 -0800727 }
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200728 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
Stephen Streete0c99052006-03-07 23:53:24 -0800729 }
730
Stephen Street5daa3ba2006-05-20 15:00:19 -0700731 /* We did something */
732 return IRQ_HANDLED;
Stephen Streete0c99052006-03-07 23:53:24 -0800733}
734
David Howells7d12e782006-10-05 14:55:46 +0100735static irqreturn_t ssp_int(int irq, void *dev_id)
Stephen Streete0c99052006-03-07 23:53:24 -0800736{
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400737 struct driver_data *drv_data = dev_id;
Mika Westerberg7d94a502013-01-22 12:26:30 +0200738 u32 sccr1_reg;
Sebastian Andrzej Siewior49cbb1e2010-11-22 17:12:14 -0800739 u32 mask = drv_data->mask_sr;
740 u32 status;
741
Mika Westerberg7d94a502013-01-22 12:26:30 +0200742 /*
743 * The IRQ might be shared with other peripherals so we must first
744 * check that are we RPM suspended or not. If we are we assume that
745 * the IRQ was not for us (we shouldn't be RPM suspended when the
746 * interrupt is enabled).
747 */
748 if (pm_runtime_suspended(&drv_data->pdev->dev))
749 return IRQ_NONE;
750
Mika Westerberg269e4a42013-09-04 13:37:43 +0300751 /*
752 * If the device is not yet in RPM suspended state and we get an
753 * interrupt that is meant for another device, check if status bits
754 * are all set to one. That means that the device is already
755 * powered off.
756 */
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200757 status = pxa2xx_spi_read(drv_data, SSSR);
Mika Westerberg269e4a42013-09-04 13:37:43 +0300758 if (status == ~0)
759 return IRQ_NONE;
760
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200761 sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
Sebastian Andrzej Siewior49cbb1e2010-11-22 17:12:14 -0800762
763 /* Ignore possible writes if we don't need to write */
764 if (!(sccr1_reg & SSCR1_TIE))
765 mask &= ~SSSR_TFS;
766
Tan, Jui Nee02bc9332015-09-01 10:22:51 +0800767 /* Ignore RX timeout interrupt if it is disabled */
768 if (!(sccr1_reg & SSCR1_TINTE))
769 mask &= ~SSSR_TINT;
770
Sebastian Andrzej Siewior49cbb1e2010-11-22 17:12:14 -0800771 if (!(status & mask))
772 return IRQ_NONE;
Stephen Streete0c99052006-03-07 23:53:24 -0800773
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300774 if (!drv_data->master->cur_msg) {
Stephen Street5daa3ba2006-05-20 15:00:19 -0700775
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200776 pxa2xx_spi_write(drv_data, SSCR0,
777 pxa2xx_spi_read(drv_data, SSCR0)
778 & ~SSCR0_SSE);
779 pxa2xx_spi_write(drv_data, SSCR1,
780 pxa2xx_spi_read(drv_data, SSCR1)
781 & ~drv_data->int_cr1);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800782 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200783 pxa2xx_spi_write(drv_data, SSTO, 0);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800784 write_SSSR_CS(drv_data, drv_data->clear_sr);
Stephen Street5daa3ba2006-05-20 15:00:19 -0700785
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +0300786 dev_err(&drv_data->pdev->dev,
787 "bad message state in interrupt handler\n");
Stephen Street5daa3ba2006-05-20 15:00:19 -0700788
Stephen Streete0c99052006-03-07 23:53:24 -0800789 /* Never fail */
790 return IRQ_HANDLED;
791 }
792
793 return drv_data->transfer_handler(drv_data);
794}
795
Weike Chene5262d02014-11-26 02:35:10 -0800796/*
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200797 * The Quark SPI has an additional 24 bit register (DDS_CLK_RATE) to multiply
798 * input frequency by fractions of 2^24. It also has a divider by 5.
799 *
800 * There are formulas to get baud rate value for given input frequency and
801 * divider parameters, such as DDS_CLK_RATE and SCR:
802 *
803 * Fsys = 200MHz
804 *
805 * Fssp = Fsys * DDS_CLK_RATE / 2^24 (1)
806 * Baud rate = Fsclk = Fssp / (2 * (SCR + 1)) (2)
807 *
808 * DDS_CLK_RATE either 2^n or 2^n / 5.
809 * SCR is in range 0 .. 255
810 *
811 * Divisor = 5^i * 2^j * 2 * k
812 * i = [0, 1] i = 1 iff j = 0 or j > 3
813 * j = [0, 23] j = 0 iff i = 1
814 * k = [1, 256]
815 * Special case: j = 0, i = 1: Divisor = 2 / 5
816 *
817 * Accordingly to the specification the recommended values for DDS_CLK_RATE
818 * are:
819 * Case 1: 2^n, n = [0, 23]
820 * Case 2: 2^24 * 2 / 5 (0x666666)
821 * Case 3: less than or equal to 2^24 / 5 / 16 (0x33333)
822 *
823 * In all cases the lowest possible value is better.
824 *
825 * The function calculates parameters for all cases and chooses the one closest
826 * to the asked baud rate.
Weike Chene5262d02014-11-26 02:35:10 -0800827 */
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200828static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds)
Weike Chene5262d02014-11-26 02:35:10 -0800829{
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200830 unsigned long xtal = 200000000;
831 unsigned long fref = xtal / 2; /* mandatory division by 2,
832 see (2) */
833 /* case 3 */
834 unsigned long fref1 = fref / 2; /* case 1 */
835 unsigned long fref2 = fref * 2 / 5; /* case 2 */
836 unsigned long scale;
837 unsigned long q, q1, q2;
838 long r, r1, r2;
839 u32 mul;
Weike Chene5262d02014-11-26 02:35:10 -0800840
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200841 /* Case 1 */
842
843 /* Set initial value for DDS_CLK_RATE */
844 mul = (1 << 24) >> 1;
845
846 /* Calculate initial quot */
Andy Shevchenko3ad48062015-10-13 17:09:14 +0300847 q1 = DIV_ROUND_UP(fref1, rate);
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200848
849 /* Scale q1 if it's too big */
850 if (q1 > 256) {
851 /* Scale q1 to range [1, 512] */
852 scale = fls_long(q1 - 1);
853 if (scale > 9) {
854 q1 >>= scale - 9;
855 mul >>= scale - 9;
856 }
857
858 /* Round the result if we have a remainder */
859 q1 += q1 & 1;
860 }
861
862 /* Decrease DDS_CLK_RATE as much as we can without loss in precision */
863 scale = __ffs(q1);
864 q1 >>= scale;
865 mul >>= scale;
866
867 /* Get the remainder */
868 r1 = abs(fref1 / (1 << (24 - fls_long(mul))) / q1 - rate);
869
870 /* Case 2 */
871
Andy Shevchenko3ad48062015-10-13 17:09:14 +0300872 q2 = DIV_ROUND_UP(fref2, rate);
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200873 r2 = abs(fref2 / q2 - rate);
874
875 /*
876 * Choose the best between two: less remainder we have the better. We
877 * can't go case 2 if q2 is greater than 256 since SCR register can
878 * hold only values 0 .. 255.
879 */
880 if (r2 >= r1 || q2 > 256) {
881 /* case 1 is better */
882 r = r1;
883 q = q1;
884 } else {
885 /* case 2 is better */
886 r = r2;
887 q = q2;
888 mul = (1 << 24) * 2 / 5;
889 }
890
Andy Shevchenko3ad48062015-10-13 17:09:14 +0300891 /* Check case 3 only if the divisor is big enough */
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200892 if (fref / rate >= 80) {
893 u64 fssp;
894 u32 m;
895
896 /* Calculate initial quot */
Andy Shevchenko3ad48062015-10-13 17:09:14 +0300897 q1 = DIV_ROUND_UP(fref, rate);
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200898 m = (1 << 24) / q1;
899
900 /* Get the remainder */
901 fssp = (u64)fref * m;
902 do_div(fssp, 1 << 24);
903 r1 = abs(fssp - rate);
904
905 /* Choose this one if it suits better */
906 if (r1 < r) {
907 /* case 3 is better */
908 q = 1;
909 mul = m;
Weike Chene5262d02014-11-26 02:35:10 -0800910 }
911 }
912
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200913 *dds = mul;
914 return q - 1;
Weike Chene5262d02014-11-26 02:35:10 -0800915}
916
Mika Westerberg3343b7a2013-01-22 12:26:27 +0200917static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
eric miao2f1a74e2007-11-21 18:50:53 +0800918{
Jarkko Nikula0eca7cf2015-09-25 10:27:17 +0300919 unsigned long ssp_clk = drv_data->master->max_speed_hz;
Mika Westerberg3343b7a2013-01-22 12:26:27 +0200920 const struct ssp_device *ssp = drv_data->ssp;
921
922 rate = min_t(int, ssp_clk, rate);
eric miao2f1a74e2007-11-21 18:50:53 +0800923
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800924 if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200925 return (ssp_clk / (2 * rate) - 1) & 0xff;
eric miao2f1a74e2007-11-21 18:50:53 +0800926 else
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200927 return (ssp_clk / rate - 1) & 0xfff;
eric miao2f1a74e2007-11-21 18:50:53 +0800928}
929
Weike Chene5262d02014-11-26 02:35:10 -0800930static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data,
Andy Shevchenkod2c2f6a2015-10-22 16:44:40 +0300931 int rate)
Weike Chene5262d02014-11-26 02:35:10 -0800932{
Jarkko Nikula96579a42016-09-07 17:04:07 +0300933 struct chip_data *chip =
934 spi_get_ctldata(drv_data->master->cur_msg->spi);
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200935 unsigned int clk_div;
Weike Chene5262d02014-11-26 02:35:10 -0800936
937 switch (drv_data->ssp_type) {
938 case QUARK_X1000_SSP:
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200939 clk_div = quark_x1000_get_clk_div(rate, &chip->dds_rate);
Dan Carpentereecacf72015-03-31 16:49:38 +0300940 break;
Weike Chene5262d02014-11-26 02:35:10 -0800941 default:
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200942 clk_div = ssp_get_clk_div(drv_data, rate);
Dan Carpentereecacf72015-03-31 16:49:38 +0300943 break;
Weike Chene5262d02014-11-26 02:35:10 -0800944 }
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200945 return clk_div << 8;
Weike Chene5262d02014-11-26 02:35:10 -0800946}
947
Jarkko Nikulab6ced292016-06-21 13:21:34 +0300948static bool pxa2xx_spi_can_dma(struct spi_master *master,
949 struct spi_device *spi,
950 struct spi_transfer *xfer)
951{
952 struct chip_data *chip = spi_get_ctldata(spi);
953
954 return chip->enable_dma &&
955 xfer->len <= MAX_DMA_LEN &&
956 xfer->len >= chip->dma_burst_size;
957}
958
Stephen Streete0c99052006-03-07 23:53:24 -0800959static void pump_transfers(unsigned long data)
960{
961 struct driver_data *drv_data = (struct driver_data *)data;
Jarkko Nikula2d7537d2016-06-21 13:21:33 +0300962 struct spi_master *master = drv_data->master;
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300963 struct spi_message *message = master->cur_msg;
Jarkko Nikula96579a42016-09-07 17:04:07 +0300964 struct chip_data *chip = spi_get_ctldata(message->spi);
965 u32 dma_thresh = chip->dma_threshold;
966 u32 dma_burst = chip->dma_burst_size;
967 u32 change_mask = pxa2xx_spi_get_ssrc1_change_mask(drv_data);
Jarkko Nikulabffc9672016-09-07 17:04:05 +0300968 struct spi_transfer *transfer;
969 struct spi_transfer *previous;
Jarkko Nikulabffc9672016-09-07 17:04:05 +0300970 u32 clk_div;
971 u8 bits;
972 u32 speed;
Stephen Street9708c122006-03-28 14:05:23 -0800973 u32 cr0;
Stephen Street8d94cc52006-12-10 02:18:54 -0800974 u32 cr1;
Andy Shevchenko7d1f1bf2016-03-24 15:35:42 +0200975 int err;
Jarkko Nikulab6ced292016-06-21 13:21:34 +0300976 int dma_mapped;
Stephen Streete0c99052006-03-07 23:53:24 -0800977
978 /* Get current state information */
Stephen Streete0c99052006-03-07 23:53:24 -0800979 transfer = drv_data->cur_transfer;
Stephen Streete0c99052006-03-07 23:53:24 -0800980
981 /* Handle for abort */
982 if (message->state == ERROR_STATE) {
983 message->status = -EIO;
Stephen Street5daa3ba2006-05-20 15:00:19 -0700984 giveback(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -0800985 return;
986 }
987
988 /* Handle end of message */
989 if (message->state == DONE_STATE) {
990 message->status = 0;
Stephen Street5daa3ba2006-05-20 15:00:19 -0700991 giveback(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -0800992 return;
993 }
994
Ned Forrester84235972008-09-13 02:33:17 -0700995 /* Delay if requested at end of transfer before CS change */
Stephen Streete0c99052006-03-07 23:53:24 -0800996 if (message->state == RUNNING_STATE) {
997 previous = list_entry(transfer->transfer_list.prev,
998 struct spi_transfer,
999 transfer_list);
1000 if (previous->delay_usecs)
1001 udelay(previous->delay_usecs);
Ned Forrester84235972008-09-13 02:33:17 -07001002
1003 /* Drop chip select only if cs_change is requested */
1004 if (previous->cs_change)
Eric Miaoa7bb3902009-04-06 19:00:54 -07001005 cs_deassert(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001006 }
1007
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001008 /* Check if we can DMA this transfer */
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001009 if (transfer->len > MAX_DMA_LEN && chip->enable_dma) {
Ned Forrester7e964452008-09-13 02:33:18 -07001010
1011 /* reject already-mapped transfers; PIO won't always work */
1012 if (message->is_dma_mapped
1013 || transfer->rx_dma || transfer->tx_dma) {
1014 dev_err(&drv_data->pdev->dev,
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +03001015 "pump_transfers: mapped transfer length of "
1016 "%u is greater than %d\n",
Ned Forrester7e964452008-09-13 02:33:18 -07001017 transfer->len, MAX_DMA_LEN);
1018 message->status = -EINVAL;
1019 giveback(drv_data);
1020 return;
1021 }
1022
1023 /* warn ... we force this to PIO mode */
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +03001024 dev_warn_ratelimited(&message->spi->dev,
1025 "pump_transfers: DMA disabled for transfer length %ld "
1026 "greater than %d\n",
1027 (long)drv_data->len, MAX_DMA_LEN);
Stephen Street8d94cc52006-12-10 02:18:54 -08001028 }
1029
Stephen Streete0c99052006-03-07 23:53:24 -08001030 /* Setup the transfer state based on the type of transfer */
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001031 if (pxa2xx_spi_flush(drv_data) == 0) {
Stephen Streete0c99052006-03-07 23:53:24 -08001032 dev_err(&drv_data->pdev->dev, "pump_transfers: flush failed\n");
1033 message->status = -EIO;
Stephen Street5daa3ba2006-05-20 15:00:19 -07001034 giveback(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001035 return;
1036 }
Stephen Street9708c122006-03-28 14:05:23 -08001037 drv_data->n_bytes = chip->n_bytes;
Stephen Streete0c99052006-03-07 23:53:24 -08001038 drv_data->tx = (void *)transfer->tx_buf;
1039 drv_data->tx_end = drv_data->tx + transfer->len;
1040 drv_data->rx = transfer->rx_buf;
1041 drv_data->rx_end = drv_data->rx + transfer->len;
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001042 drv_data->len = transfer->len;
Stephen Streete0c99052006-03-07 23:53:24 -08001043 drv_data->write = drv_data->tx ? chip->write : null_writer;
1044 drv_data->read = drv_data->rx ? chip->read : null_reader;
Stephen Street9708c122006-03-28 14:05:23 -08001045
1046 /* Change speed and bit per word on a per transfer */
Jarkko Nikula196b0e22015-09-15 16:26:27 +03001047 bits = transfer->bits_per_word;
1048 speed = transfer->speed_hz;
Stephen Street9708c122006-03-28 14:05:23 -08001049
Andy Shevchenkod2c2f6a2015-10-22 16:44:40 +03001050 clk_div = pxa2xx_ssp_get_clk_div(drv_data, speed);
Stephen Street9708c122006-03-28 14:05:23 -08001051
Jarkko Nikula196b0e22015-09-15 16:26:27 +03001052 if (bits <= 8) {
1053 drv_data->n_bytes = 1;
1054 drv_data->read = drv_data->read != null_reader ?
1055 u8_reader : null_reader;
1056 drv_data->write = drv_data->write != null_writer ?
1057 u8_writer : null_writer;
1058 } else if (bits <= 16) {
1059 drv_data->n_bytes = 2;
1060 drv_data->read = drv_data->read != null_reader ?
1061 u16_reader : null_reader;
1062 drv_data->write = drv_data->write != null_writer ?
1063 u16_writer : null_writer;
1064 } else if (bits <= 32) {
1065 drv_data->n_bytes = 4;
1066 drv_data->read = drv_data->read != null_reader ?
1067 u32_reader : null_reader;
1068 drv_data->write = drv_data->write != null_writer ?
1069 u32_writer : null_writer;
Stephen Street9708c122006-03-28 14:05:23 -08001070 }
Jarkko Nikula196b0e22015-09-15 16:26:27 +03001071 /*
1072 * if bits/word is changed in dma mode, then must check the
1073 * thresholds and burst also
1074 */
1075 if (chip->enable_dma) {
1076 if (pxa2xx_spi_set_dma_burst_and_threshold(chip,
1077 message->spi,
1078 bits, &dma_burst,
1079 &dma_thresh))
1080 dev_warn_ratelimited(&message->spi->dev,
1081 "pump_transfers: DMA burst size reduced to match bits_per_word\n");
1082 }
1083
Stephen Streete0c99052006-03-07 23:53:24 -08001084 message->state = RUNNING_STATE;
1085
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001086 dma_mapped = master->can_dma &&
1087 master->can_dma(master, message->spi, transfer) &&
1088 master->cur_msg_mapped;
1089 if (dma_mapped) {
Stephen Streete0c99052006-03-07 23:53:24 -08001090
1091 /* Ensure we have the correct interrupt handler */
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001092 drv_data->transfer_handler = pxa2xx_spi_dma_transfer;
Stephen Streete0c99052006-03-07 23:53:24 -08001093
Andy Shevchenko7d1f1bf2016-03-24 15:35:42 +02001094 err = pxa2xx_spi_dma_prepare(drv_data, dma_burst);
1095 if (err) {
1096 message->status = err;
1097 giveback(drv_data);
1098 return;
1099 }
Stephen Streete0c99052006-03-07 23:53:24 -08001100
Stephen Street8d94cc52006-12-10 02:18:54 -08001101 /* Clear status and start DMA engine */
1102 cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1;
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001103 pxa2xx_spi_write(drv_data, SSSR, drv_data->clear_sr);
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001104
1105 pxa2xx_spi_dma_start(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001106 } else {
1107 /* Ensure we have the correct interrupt handler */
1108 drv_data->transfer_handler = interrupt_transfer;
1109
Stephen Street8d94cc52006-12-10 02:18:54 -08001110 /* Clear status */
1111 cr1 = chip->cr1 | chip->threshold | drv_data->int_cr1;
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001112 write_SSSR_CS(drv_data, drv_data->clear_sr);
Stephen Street8d94cc52006-12-10 02:18:54 -08001113 }
1114
Jarkko Nikulaee036722016-01-26 15:33:21 +02001115 /* NOTE: PXA25x_SSP _could_ use external clocking ... */
1116 cr0 = pxa2xx_configure_sscr0(drv_data, clk_div, bits);
1117 if (!pxa25x_ssp_comp(drv_data))
1118 dev_dbg(&message->spi->dev, "%u Hz actual, %s\n",
Jarkko Nikula2d7537d2016-06-21 13:21:33 +03001119 master->max_speed_hz
Jarkko Nikulaee036722016-01-26 15:33:21 +02001120 / (1 + ((cr0 & SSCR0_SCR(0xfff)) >> 8)),
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001121 dma_mapped ? "DMA" : "PIO");
Jarkko Nikulaee036722016-01-26 15:33:21 +02001122 else
1123 dev_dbg(&message->spi->dev, "%u Hz actual, %s\n",
Jarkko Nikula2d7537d2016-06-21 13:21:33 +03001124 master->max_speed_hz / 2
Jarkko Nikulaee036722016-01-26 15:33:21 +02001125 / (1 + ((cr0 & SSCR0_SCR(0x0ff)) >> 8)),
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001126 dma_mapped ? "DMA" : "PIO");
Jarkko Nikulaee036722016-01-26 15:33:21 +02001127
Mika Westerberga0d26422013-01-22 12:26:32 +02001128 if (is_lpss_ssp(drv_data)) {
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001129 if ((pxa2xx_spi_read(drv_data, SSIRF) & 0xff)
1130 != chip->lpss_rx_threshold)
1131 pxa2xx_spi_write(drv_data, SSIRF,
1132 chip->lpss_rx_threshold);
1133 if ((pxa2xx_spi_read(drv_data, SSITF) & 0xffff)
1134 != chip->lpss_tx_threshold)
1135 pxa2xx_spi_write(drv_data, SSITF,
1136 chip->lpss_tx_threshold);
Mika Westerberga0d26422013-01-22 12:26:32 +02001137 }
1138
Weike Chene5262d02014-11-26 02:35:10 -08001139 if (is_quark_x1000_ssp(drv_data) &&
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001140 (pxa2xx_spi_read(drv_data, DDS_RATE) != chip->dds_rate))
1141 pxa2xx_spi_write(drv_data, DDS_RATE, chip->dds_rate);
Weike Chene5262d02014-11-26 02:35:10 -08001142
Stephen Street8d94cc52006-12-10 02:18:54 -08001143 /* see if we need to reload the config registers */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001144 if ((pxa2xx_spi_read(drv_data, SSCR0) != cr0)
1145 || (pxa2xx_spi_read(drv_data, SSCR1) & change_mask)
1146 != (cr1 & change_mask)) {
Ned Forresterb97c74b2008-02-23 15:23:40 -08001147 /* stop the SSP, and update the other bits */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001148 pxa2xx_spi_write(drv_data, SSCR0, cr0 & ~SSCR0_SSE);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001149 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001150 pxa2xx_spi_write(drv_data, SSTO, chip->timeout);
Ned Forresterb97c74b2008-02-23 15:23:40 -08001151 /* first set CR1 without interrupt and service enables */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001152 pxa2xx_spi_write(drv_data, SSCR1, cr1 & change_mask);
Ned Forresterb97c74b2008-02-23 15:23:40 -08001153 /* restart the SSP */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001154 pxa2xx_spi_write(drv_data, SSCR0, cr0);
Ned Forresterb97c74b2008-02-23 15:23:40 -08001155
Stephen Street8d94cc52006-12-10 02:18:54 -08001156 } else {
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001157 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001158 pxa2xx_spi_write(drv_data, SSTO, chip->timeout);
Stephen Streete0c99052006-03-07 23:53:24 -08001159 }
Ned Forresterb97c74b2008-02-23 15:23:40 -08001160
Eric Miaoa7bb3902009-04-06 19:00:54 -07001161 cs_assert(drv_data);
Ned Forresterb97c74b2008-02-23 15:23:40 -08001162
1163 /* after chip select, release the data by enabling service
1164 * requests and interrupts, without changing any mode bits */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001165 pxa2xx_spi_write(drv_data, SSCR1, cr1);
Stephen Streete0c99052006-03-07 23:53:24 -08001166}
1167
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001168static int pxa2xx_spi_transfer_one_message(struct spi_master *master,
1169 struct spi_message *msg)
Stephen Streete0c99052006-03-07 23:53:24 -08001170{
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001171 struct driver_data *drv_data = spi_master_get_devdata(master);
Stephen Streete0c99052006-03-07 23:53:24 -08001172
Stephen Streete0c99052006-03-07 23:53:24 -08001173 /* Initial message state*/
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +03001174 msg->state = START_STATE;
1175 drv_data->cur_transfer = list_entry(msg->transfers.next,
Stephen Streete0c99052006-03-07 23:53:24 -08001176 struct spi_transfer,
1177 transfer_list);
1178
Stephen Streete0c99052006-03-07 23:53:24 -08001179 /* Mark as busy and launch transfers */
1180 tasklet_schedule(&drv_data->pump_transfers);
Stephen Streete0c99052006-03-07 23:53:24 -08001181 return 0;
1182}
1183
Mika Westerberg7d94a502013-01-22 12:26:30 +02001184static int pxa2xx_spi_unprepare_transfer(struct spi_master *master)
1185{
1186 struct driver_data *drv_data = spi_master_get_devdata(master);
1187
1188 /* Disable the SSP now */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001189 pxa2xx_spi_write(drv_data, SSCR0,
1190 pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
Mika Westerberg7d94a502013-01-22 12:26:30 +02001191
Mika Westerberg7d94a502013-01-22 12:26:30 +02001192 return 0;
1193}
1194
Eric Miaoa7bb3902009-04-06 19:00:54 -07001195static int setup_cs(struct spi_device *spi, struct chip_data *chip,
1196 struct pxa2xx_spi_chip *chip_info)
1197{
Mika Westerberg99f499c2016-09-26 15:19:50 +03001198 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
Eric Miaoa7bb3902009-04-06 19:00:54 -07001199 int err = 0;
1200
Mika Westerberg99f499c2016-09-26 15:19:50 +03001201 if (chip == NULL)
1202 return 0;
1203
1204 if (drv_data->cs_gpiods) {
1205 struct gpio_desc *gpiod;
1206
1207 gpiod = drv_data->cs_gpiods[spi->chip_select];
1208 if (gpiod) {
1209 chip->gpio_cs = desc_to_gpio(gpiod);
1210 chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
1211 gpiod_set_value(gpiod, chip->gpio_cs_inverted);
1212 }
1213
1214 return 0;
1215 }
1216
1217 if (chip_info == NULL)
Eric Miaoa7bb3902009-04-06 19:00:54 -07001218 return 0;
1219
1220 /* NOTE: setup() can be called multiple times, possibly with
1221 * different chip_info, release previously requested GPIO
1222 */
1223 if (gpio_is_valid(chip->gpio_cs))
1224 gpio_free(chip->gpio_cs);
1225
1226 /* If (*cs_control) is provided, ignore GPIO chip select */
1227 if (chip_info->cs_control) {
1228 chip->cs_control = chip_info->cs_control;
1229 return 0;
1230 }
1231
1232 if (gpio_is_valid(chip_info->gpio_cs)) {
1233 err = gpio_request(chip_info->gpio_cs, "SPI_CS");
1234 if (err) {
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +03001235 dev_err(&spi->dev, "failed to request chip select GPIO%d\n",
1236 chip_info->gpio_cs);
Eric Miaoa7bb3902009-04-06 19:00:54 -07001237 return err;
1238 }
1239
1240 chip->gpio_cs = chip_info->gpio_cs;
1241 chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
1242
1243 err = gpio_direction_output(chip->gpio_cs,
1244 !chip->gpio_cs_inverted);
1245 }
1246
1247 return err;
1248}
1249
Stephen Streete0c99052006-03-07 23:53:24 -08001250static int setup(struct spi_device *spi)
1251{
Jarkko Nikulabffc9672016-09-07 17:04:05 +03001252 struct pxa2xx_spi_chip *chip_info;
Stephen Streete0c99052006-03-07 23:53:24 -08001253 struct chip_data *chip;
Jarkko Nikuladccf7362015-06-04 16:55:11 +03001254 const struct lpss_config *config;
Stephen Streete0c99052006-03-07 23:53:24 -08001255 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
Mika Westerberga0d26422013-01-22 12:26:32 +02001256 uint tx_thres, tx_hi_thres, rx_thres;
1257
Weike Chene5262d02014-11-26 02:35:10 -08001258 switch (drv_data->ssp_type) {
1259 case QUARK_X1000_SSP:
1260 tx_thres = TX_THRESH_QUARK_X1000_DFLT;
1261 tx_hi_thres = 0;
1262 rx_thres = RX_THRESH_QUARK_X1000_DFLT;
1263 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001264 case CE4100_SSP:
1265 tx_thres = TX_THRESH_CE4100_DFLT;
1266 tx_hi_thres = 0;
1267 rx_thres = RX_THRESH_CE4100_DFLT;
1268 break;
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001269 case LPSS_LPT_SSP:
1270 case LPSS_BYT_SSP:
Mika Westerberg30f3a6a2016-02-08 17:14:31 +02001271 case LPSS_BSW_SSP:
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001272 case LPSS_SPT_SSP:
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +02001273 case LPSS_BXT_SSP:
Jarkko Nikuladccf7362015-06-04 16:55:11 +03001274 config = lpss_get_config(drv_data);
1275 tx_thres = config->tx_threshold_lo;
1276 tx_hi_thres = config->tx_threshold_hi;
1277 rx_thres = config->rx_threshold;
Weike Chene5262d02014-11-26 02:35:10 -08001278 break;
1279 default:
Mika Westerberga0d26422013-01-22 12:26:32 +02001280 tx_thres = TX_THRESH_DFLT;
1281 tx_hi_thres = 0;
1282 rx_thres = RX_THRESH_DFLT;
Weike Chene5262d02014-11-26 02:35:10 -08001283 break;
Mika Westerberga0d26422013-01-22 12:26:32 +02001284 }
Stephen Streete0c99052006-03-07 23:53:24 -08001285
Stephen Street8d94cc52006-12-10 02:18:54 -08001286 /* Only alloc on first setup */
Stephen Streete0c99052006-03-07 23:53:24 -08001287 chip = spi_get_ctldata(spi);
Stephen Street8d94cc52006-12-10 02:18:54 -08001288 if (!chip) {
Stephen Streete0c99052006-03-07 23:53:24 -08001289 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
Jingoo Han9deae452014-04-29 17:19:38 +09001290 if (!chip)
Stephen Streete0c99052006-03-07 23:53:24 -08001291 return -ENOMEM;
1292
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001293 if (drv_data->ssp_type == CE4100_SSP) {
1294 if (spi->chip_select > 4) {
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +03001295 dev_err(&spi->dev,
1296 "failed setup: cs number must not be > 4.\n");
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001297 kfree(chip);
1298 return -EINVAL;
1299 }
1300
1301 chip->frm = spi->chip_select;
1302 } else
1303 chip->gpio_cs = -1;
Dan O'Donovanc64e1262016-05-27 19:57:48 +01001304 chip->enable_dma = drv_data->master_info->enable_dma;
Vernon Sauderf1f640a2008-10-15 22:02:43 -07001305 chip->timeout = TIMOUT_DFLT;
Stephen Streete0c99052006-03-07 23:53:24 -08001306 }
1307
Stephen Street8d94cc52006-12-10 02:18:54 -08001308 /* protocol drivers may change the chip settings, so...
1309 * if chip_info exists, use it */
1310 chip_info = spi->controller_data;
1311
Stephen Streete0c99052006-03-07 23:53:24 -08001312 /* chip_info isn't always needed */
Stephen Street8d94cc52006-12-10 02:18:54 -08001313 chip->cr1 = 0;
Stephen Streete0c99052006-03-07 23:53:24 -08001314 if (chip_info) {
Vernon Sauderf1f640a2008-10-15 22:02:43 -07001315 if (chip_info->timeout)
1316 chip->timeout = chip_info->timeout;
1317 if (chip_info->tx_threshold)
1318 tx_thres = chip_info->tx_threshold;
Mika Westerberga0d26422013-01-22 12:26:32 +02001319 if (chip_info->tx_hi_threshold)
1320 tx_hi_thres = chip_info->tx_hi_threshold;
Vernon Sauderf1f640a2008-10-15 22:02:43 -07001321 if (chip_info->rx_threshold)
1322 rx_thres = chip_info->rx_threshold;
Stephen Streete0c99052006-03-07 23:53:24 -08001323 chip->dma_threshold = 0;
Stephen Streete0c99052006-03-07 23:53:24 -08001324 if (chip_info->enable_loopback)
1325 chip->cr1 = SSCR1_LBM;
1326 }
1327
Mika Westerberga0d26422013-01-22 12:26:32 +02001328 chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres);
1329 chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres)
1330 | SSITF_TxHiThresh(tx_hi_thres);
1331
Stephen Street8d94cc52006-12-10 02:18:54 -08001332 /* set dma burst and threshold outside of chip_info path so that if
1333 * chip_info goes away after setting chip->enable_dma, the
1334 * burst and threshold can still respond to changes in bits_per_word */
1335 if (chip->enable_dma) {
1336 /* set up legal burst and threshold for dma */
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001337 if (pxa2xx_spi_set_dma_burst_and_threshold(chip, spi,
1338 spi->bits_per_word,
Stephen Street8d94cc52006-12-10 02:18:54 -08001339 &chip->dma_burst_size,
1340 &chip->dma_threshold)) {
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +03001341 dev_warn(&spi->dev,
1342 "in setup: DMA burst size reduced to match bits_per_word\n");
Stephen Street8d94cc52006-12-10 02:18:54 -08001343 }
1344 }
1345
Weike Chene5262d02014-11-26 02:35:10 -08001346 switch (drv_data->ssp_type) {
1347 case QUARK_X1000_SSP:
1348 chip->threshold = (QUARK_X1000_SSCR1_RxTresh(rx_thres)
1349 & QUARK_X1000_SSCR1_RFT)
1350 | (QUARK_X1000_SSCR1_TxTresh(tx_thres)
1351 & QUARK_X1000_SSCR1_TFT);
1352 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001353 case CE4100_SSP:
1354 chip->threshold = (CE4100_SSCR1_RxTresh(rx_thres) & CE4100_SSCR1_RFT) |
1355 (CE4100_SSCR1_TxTresh(tx_thres) & CE4100_SSCR1_TFT);
1356 break;
Weike Chene5262d02014-11-26 02:35:10 -08001357 default:
1358 chip->threshold = (SSCR1_RxTresh(rx_thres) & SSCR1_RFT) |
1359 (SSCR1_TxTresh(tx_thres) & SSCR1_TFT);
1360 break;
1361 }
1362
Justin Clacherty7f6ee1a2007-01-26 00:56:44 -08001363 chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
1364 chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)
1365 | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);
Stephen Streete0c99052006-03-07 23:53:24 -08001366
Mika Westerbergb8331722013-01-22 12:26:31 +02001367 if (spi->mode & SPI_LOOP)
1368 chip->cr1 |= SSCR1_LBM;
1369
Stephen Streete0c99052006-03-07 23:53:24 -08001370 if (spi->bits_per_word <= 8) {
1371 chip->n_bytes = 1;
Stephen Streete0c99052006-03-07 23:53:24 -08001372 chip->read = u8_reader;
1373 chip->write = u8_writer;
1374 } else if (spi->bits_per_word <= 16) {
1375 chip->n_bytes = 2;
Stephen Streete0c99052006-03-07 23:53:24 -08001376 chip->read = u16_reader;
1377 chip->write = u16_writer;
1378 } else if (spi->bits_per_word <= 32) {
Stephen Streete0c99052006-03-07 23:53:24 -08001379 chip->n_bytes = 4;
Stephen Streete0c99052006-03-07 23:53:24 -08001380 chip->read = u32_reader;
1381 chip->write = u32_writer;
Stephen Streete0c99052006-03-07 23:53:24 -08001382 }
Stephen Streete0c99052006-03-07 23:53:24 -08001383
1384 spi_set_ctldata(spi, chip);
1385
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001386 if (drv_data->ssp_type == CE4100_SSP)
1387 return 0;
1388
Eric Miaoa7bb3902009-04-06 19:00:54 -07001389 return setup_cs(spi, chip, chip_info);
Stephen Streete0c99052006-03-07 23:53:24 -08001390}
1391
Hans-Peter Nilsson0ffa0282007-02-12 00:52:45 -08001392static void cleanup(struct spi_device *spi)
Stephen Streete0c99052006-03-07 23:53:24 -08001393{
Hans-Peter Nilsson0ffa0282007-02-12 00:52:45 -08001394 struct chip_data *chip = spi_get_ctldata(spi);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001395 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
Stephen Streete0c99052006-03-07 23:53:24 -08001396
Daniel Ribeiro7348d822009-05-12 13:19:36 -07001397 if (!chip)
1398 return;
1399
Mika Westerberg99f499c2016-09-26 15:19:50 +03001400 if (drv_data->ssp_type != CE4100_SSP && !drv_data->cs_gpiods &&
1401 gpio_is_valid(chip->gpio_cs))
Eric Miaoa7bb3902009-04-06 19:00:54 -07001402 gpio_free(chip->gpio_cs);
1403
Stephen Streete0c99052006-03-07 23:53:24 -08001404 kfree(chip);
1405}
1406
Jarkko Nikula0db64212015-10-28 15:13:43 +02001407#ifdef CONFIG_PCI
Mika Westerberga3496852013-01-22 12:26:33 +02001408#ifdef CONFIG_ACPI
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001409
Mathias Krause8422ddf2015-06-13 14:22:14 +02001410static const struct acpi_device_id pxa2xx_spi_acpi_match[] = {
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001411 { "INT33C0", LPSS_LPT_SSP },
1412 { "INT33C1", LPSS_LPT_SSP },
1413 { "INT3430", LPSS_LPT_SSP },
1414 { "INT3431", LPSS_LPT_SSP },
1415 { "80860F0E", LPSS_BYT_SSP },
Mika Westerberg30f3a6a2016-02-08 17:14:31 +02001416 { "8086228E", LPSS_BSW_SSP },
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001417 { },
1418};
1419MODULE_DEVICE_TABLE(acpi, pxa2xx_spi_acpi_match);
1420
Jarkko Nikula0db64212015-10-28 15:13:43 +02001421static int pxa2xx_spi_get_port_id(struct acpi_device *adev)
1422{
1423 unsigned int devid;
1424 int port_id = -1;
1425
1426 if (adev && adev->pnp.unique_id &&
1427 !kstrtouint(adev->pnp.unique_id, 0, &devid))
1428 port_id = devid;
1429 return port_id;
1430}
1431#else /* !CONFIG_ACPI */
1432static int pxa2xx_spi_get_port_id(struct acpi_device *adev)
1433{
1434 return -1;
1435}
1436#endif
1437
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001438/*
1439 * PCI IDs of compound devices that integrate both host controller and private
1440 * integrated DMA engine. Please note these are not used in module
1441 * autoloading and probing in this module but matching the LPSS SSP type.
1442 */
1443static const struct pci_device_id pxa2xx_spi_pci_compound_match[] = {
1444 /* SPT-LP */
1445 { PCI_VDEVICE(INTEL, 0x9d29), LPSS_SPT_SSP },
1446 { PCI_VDEVICE(INTEL, 0x9d2a), LPSS_SPT_SSP },
1447 /* SPT-H */
1448 { PCI_VDEVICE(INTEL, 0xa129), LPSS_SPT_SSP },
1449 { PCI_VDEVICE(INTEL, 0xa12a), LPSS_SPT_SSP },
Mika Westerberg704d2b02016-07-04 13:21:07 +03001450 /* KBL-H */
1451 { PCI_VDEVICE(INTEL, 0xa2a9), LPSS_SPT_SSP },
1452 { PCI_VDEVICE(INTEL, 0xa2aa), LPSS_SPT_SSP },
Jarkko Nikulac1b03f12016-03-02 09:54:14 +02001453 /* BXT A-Step */
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +02001454 { PCI_VDEVICE(INTEL, 0x0ac2), LPSS_BXT_SSP },
1455 { PCI_VDEVICE(INTEL, 0x0ac4), LPSS_BXT_SSP },
1456 { PCI_VDEVICE(INTEL, 0x0ac6), LPSS_BXT_SSP },
Jarkko Nikulac1b03f12016-03-02 09:54:14 +02001457 /* BXT B-Step */
1458 { PCI_VDEVICE(INTEL, 0x1ac2), LPSS_BXT_SSP },
1459 { PCI_VDEVICE(INTEL, 0x1ac4), LPSS_BXT_SSP },
1460 { PCI_VDEVICE(INTEL, 0x1ac6), LPSS_BXT_SSP },
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +02001461 /* APL */
1462 { PCI_VDEVICE(INTEL, 0x5ac2), LPSS_BXT_SSP },
1463 { PCI_VDEVICE(INTEL, 0x5ac4), LPSS_BXT_SSP },
1464 { PCI_VDEVICE(INTEL, 0x5ac6), LPSS_BXT_SSP },
Axel Lin94e5c232015-08-04 13:52:22 +08001465 { },
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001466};
1467
1468static bool pxa2xx_spi_idma_filter(struct dma_chan *chan, void *param)
1469{
1470 struct device *dev = param;
1471
1472 if (dev != chan->device->dev->parent)
1473 return false;
1474
1475 return true;
1476}
1477
Mika Westerberga3496852013-01-22 12:26:33 +02001478static struct pxa2xx_spi_master *
Jarkko Nikula0db64212015-10-28 15:13:43 +02001479pxa2xx_spi_init_pdata(struct platform_device *pdev)
Mika Westerberga3496852013-01-22 12:26:33 +02001480{
1481 struct pxa2xx_spi_master *pdata;
Mika Westerberga3496852013-01-22 12:26:33 +02001482 struct acpi_device *adev;
1483 struct ssp_device *ssp;
1484 struct resource *res;
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001485 const struct acpi_device_id *adev_id = NULL;
1486 const struct pci_device_id *pcidev_id = NULL;
Jarkko Nikula3b8b6d02015-10-22 16:44:41 +03001487 int type;
Mika Westerberga3496852013-01-22 12:26:33 +02001488
Jarkko Nikulab9f69402015-09-25 10:27:18 +03001489 adev = ACPI_COMPANION(&pdev->dev);
Mika Westerberga3496852013-01-22 12:26:33 +02001490
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001491 if (dev_is_pci(pdev->dev.parent))
1492 pcidev_id = pci_match_id(pxa2xx_spi_pci_compound_match,
1493 to_pci_dev(pdev->dev.parent));
Jarkko Nikula0db64212015-10-28 15:13:43 +02001494 else if (adev)
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001495 adev_id = acpi_match_device(pdev->dev.driver->acpi_match_table,
1496 &pdev->dev);
Jarkko Nikula0db64212015-10-28 15:13:43 +02001497 else
1498 return NULL;
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001499
1500 if (adev_id)
1501 type = (int)adev_id->driver_data;
1502 else if (pcidev_id)
1503 type = (int)pcidev_id->driver_data;
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001504 else
1505 return NULL;
1506
Mika Westerbergcc0ee982013-06-20 17:44:22 +03001507 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
Jingoo Han9deae452014-04-29 17:19:38 +09001508 if (!pdata)
Mika Westerberga3496852013-01-22 12:26:33 +02001509 return NULL;
Mika Westerberga3496852013-01-22 12:26:33 +02001510
1511 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1512 if (!res)
1513 return NULL;
1514
1515 ssp = &pdata->ssp;
1516
1517 ssp->phys_base = res->start;
Sachin Kamatcbfd6a22013-04-08 15:49:33 +05301518 ssp->mmio_base = devm_ioremap_resource(&pdev->dev, res);
1519 if (IS_ERR(ssp->mmio_base))
Mika Westerberg6dc81f62013-05-13 13:45:09 +03001520 return NULL;
Mika Westerberga3496852013-01-22 12:26:33 +02001521
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001522 if (pcidev_id) {
1523 pdata->tx_param = pdev->dev.parent;
1524 pdata->rx_param = pdev->dev.parent;
1525 pdata->dma_filter = pxa2xx_spi_idma_filter;
1526 }
1527
Mika Westerberga3496852013-01-22 12:26:33 +02001528 ssp->clk = devm_clk_get(&pdev->dev, NULL);
1529 ssp->irq = platform_get_irq(pdev, 0);
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001530 ssp->type = type;
Mika Westerberga3496852013-01-22 12:26:33 +02001531 ssp->pdev = pdev;
Jarkko Nikula0db64212015-10-28 15:13:43 +02001532 ssp->port_id = pxa2xx_spi_get_port_id(adev);
Mika Westerberga3496852013-01-22 12:26:33 +02001533
1534 pdata->num_chipselect = 1;
Mika Westerbergcddb3392013-05-13 13:45:10 +03001535 pdata->enable_dma = true;
Mika Westerberga3496852013-01-22 12:26:33 +02001536
1537 return pdata;
1538}
1539
Jarkko Nikula0db64212015-10-28 15:13:43 +02001540#else /* !CONFIG_PCI */
Mika Westerberga3496852013-01-22 12:26:33 +02001541static inline struct pxa2xx_spi_master *
Jarkko Nikula0db64212015-10-28 15:13:43 +02001542pxa2xx_spi_init_pdata(struct platform_device *pdev)
Mika Westerberga3496852013-01-22 12:26:33 +02001543{
1544 return NULL;
1545}
1546#endif
1547
Mika Westerberg0c27d9c2016-02-08 17:14:29 +02001548static int pxa2xx_spi_fw_translate_cs(struct spi_master *master, unsigned cs)
1549{
1550 struct driver_data *drv_data = spi_master_get_devdata(master);
1551
1552 if (has_acpi_companion(&drv_data->pdev->dev)) {
1553 switch (drv_data->ssp_type) {
1554 /*
1555 * For Atoms the ACPI DeviceSelection used by the Windows
1556 * driver starts from 1 instead of 0 so translate it here
1557 * to match what Linux expects.
1558 */
1559 case LPSS_BYT_SSP:
Mika Westerberg30f3a6a2016-02-08 17:14:31 +02001560 case LPSS_BSW_SSP:
Mika Westerberg0c27d9c2016-02-08 17:14:29 +02001561 return cs - 1;
1562
1563 default:
1564 break;
1565 }
1566 }
1567
1568 return cs;
1569}
1570
Grant Likelyfd4a3192012-12-07 16:57:14 +00001571static int pxa2xx_spi_probe(struct platform_device *pdev)
Stephen Streete0c99052006-03-07 23:53:24 -08001572{
1573 struct device *dev = &pdev->dev;
1574 struct pxa2xx_spi_master *platform_info;
1575 struct spi_master *master;
Guennadi Liakhovetski65a00a22008-10-15 22:02:42 -07001576 struct driver_data *drv_data;
eric miao2f1a74e2007-11-21 18:50:53 +08001577 struct ssp_device *ssp;
Jarkko Nikula8b136ba2015-10-28 15:13:41 +02001578 const struct lpss_config *config;
Mika Westerberg99f499c2016-09-26 15:19:50 +03001579 int status, count;
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001580 u32 tmp;
Stephen Streete0c99052006-03-07 23:53:24 -08001581
Mika Westerberg851bacf2013-01-07 12:44:33 +02001582 platform_info = dev_get_platdata(dev);
1583 if (!platform_info) {
Jarkko Nikula0db64212015-10-28 15:13:43 +02001584 platform_info = pxa2xx_spi_init_pdata(pdev);
Mika Westerberga3496852013-01-22 12:26:33 +02001585 if (!platform_info) {
1586 dev_err(&pdev->dev, "missing platform data\n");
1587 return -ENODEV;
1588 }
Mika Westerberg851bacf2013-01-07 12:44:33 +02001589 }
Stephen Streete0c99052006-03-07 23:53:24 -08001590
Haojian Zhuangbaffe162010-05-05 10:11:15 -04001591 ssp = pxa_ssp_request(pdev->id, pdev->name);
Mika Westerberg851bacf2013-01-07 12:44:33 +02001592 if (!ssp)
1593 ssp = &platform_info->ssp;
1594
1595 if (!ssp->mmio_base) {
1596 dev_err(&pdev->dev, "failed to get ssp\n");
Stephen Streete0c99052006-03-07 23:53:24 -08001597 return -ENODEV;
1598 }
1599
Jarkko Nikula757fe8d2015-08-05 10:04:05 +03001600 master = spi_alloc_master(dev, sizeof(struct driver_data));
Stephen Streete0c99052006-03-07 23:53:24 -08001601 if (!master) {
Guennadi Liakhovetski65a00a22008-10-15 22:02:42 -07001602 dev_err(&pdev->dev, "cannot alloc spi_master\n");
Haojian Zhuangbaffe162010-05-05 10:11:15 -04001603 pxa_ssp_free(ssp);
Stephen Streete0c99052006-03-07 23:53:24 -08001604 return -ENOMEM;
1605 }
1606 drv_data = spi_master_get_devdata(master);
1607 drv_data->master = master;
1608 drv_data->master_info = platform_info;
1609 drv_data->pdev = pdev;
eric miao2f1a74e2007-11-21 18:50:53 +08001610 drv_data->ssp = ssp;
Stephen Streete0c99052006-03-07 23:53:24 -08001611
Sebastian Andrzej Siewior21486af2010-10-08 18:11:19 +02001612 master->dev.of_node = pdev->dev.of_node;
David Brownelle7db06b2009-06-17 16:26:04 -07001613 /* the spi->mode bits understood by this driver: */
Mika Westerbergb8331722013-01-22 12:26:31 +02001614 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
David Brownelle7db06b2009-06-17 16:26:04 -07001615
Mika Westerberg851bacf2013-01-07 12:44:33 +02001616 master->bus_num = ssp->port_id;
Mike Rapoport7ad0ba92009-04-06 19:00:57 -07001617 master->dma_alignment = DMA_ALIGNMENT;
Stephen Streete0c99052006-03-07 23:53:24 -08001618 master->cleanup = cleanup;
1619 master->setup = setup;
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001620 master->transfer_one_message = pxa2xx_spi_transfer_one_message;
Mika Westerberg7d94a502013-01-22 12:26:30 +02001621 master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer;
Mika Westerberg0c27d9c2016-02-08 17:14:29 +02001622 master->fw_translate_cs = pxa2xx_spi_fw_translate_cs;
Mark Brown7dd62782013-07-28 15:35:21 +01001623 master->auto_runtime_pm = true;
Jarkko Nikula8c3ad482016-03-24 15:35:44 +02001624 master->flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX;
Stephen Streete0c99052006-03-07 23:53:24 -08001625
eric miao2f1a74e2007-11-21 18:50:53 +08001626 drv_data->ssp_type = ssp->type;
Stephen Streete0c99052006-03-07 23:53:24 -08001627
eric miao2f1a74e2007-11-21 18:50:53 +08001628 drv_data->ioaddr = ssp->mmio_base;
1629 drv_data->ssdr_physical = ssp->phys_base + SSDR;
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001630 if (pxa25x_ssp_comp(drv_data)) {
Weike Chene5262d02014-11-26 02:35:10 -08001631 switch (drv_data->ssp_type) {
1632 case QUARK_X1000_SSP:
1633 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
1634 break;
1635 default:
1636 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
1637 break;
1638 }
1639
Stephen Streete0c99052006-03-07 23:53:24 -08001640 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE;
1641 drv_data->dma_cr1 = 0;
1642 drv_data->clear_sr = SSSR_ROR;
1643 drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR;
1644 } else {
Stephen Warren24778be2013-05-21 20:36:35 -06001645 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
Stephen Streete0c99052006-03-07 23:53:24 -08001646 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE;
Mika Westerberg59288082013-01-22 12:26:29 +02001647 drv_data->dma_cr1 = DEFAULT_DMA_CR1;
Stephen Streete0c99052006-03-07 23:53:24 -08001648 drv_data->clear_sr = SSSR_ROR | SSSR_TINT;
1649 drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR;
1650 }
1651
Sebastian Andrzej Siewior49cbb1e2010-11-22 17:12:14 -08001652 status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev),
1653 drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001654 if (status < 0) {
Guennadi Liakhovetski65a00a22008-10-15 22:02:42 -07001655 dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq);
Stephen Streete0c99052006-03-07 23:53:24 -08001656 goto out_error_master_alloc;
1657 }
1658
1659 /* Setup DMA if requested */
Stephen Streete0c99052006-03-07 23:53:24 -08001660 if (platform_info->enable_dma) {
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001661 status = pxa2xx_spi_dma_setup(drv_data);
1662 if (status) {
Mika Westerbergcddb3392013-05-13 13:45:10 +03001663 dev_dbg(dev, "no DMA channels available, using PIO\n");
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001664 platform_info->enable_dma = false;
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001665 } else {
1666 master->can_dma = pxa2xx_spi_can_dma;
Stephen Streete0c99052006-03-07 23:53:24 -08001667 }
Stephen Streete0c99052006-03-07 23:53:24 -08001668 }
1669
1670 /* Enable SOC clock */
Mika Westerberg3343b7a2013-01-22 12:26:27 +02001671 clk_prepare_enable(ssp->clk);
1672
Jarkko Nikula0eca7cf2015-09-25 10:27:17 +03001673 master->max_speed_hz = clk_get_rate(ssp->clk);
Stephen Streete0c99052006-03-07 23:53:24 -08001674
1675 /* Load default SSP configuration */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001676 pxa2xx_spi_write(drv_data, SSCR0, 0);
Weike Chene5262d02014-11-26 02:35:10 -08001677 switch (drv_data->ssp_type) {
1678 case QUARK_X1000_SSP:
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001679 tmp = QUARK_X1000_SSCR1_RxTresh(RX_THRESH_QUARK_X1000_DFLT) |
1680 QUARK_X1000_SSCR1_TxTresh(TX_THRESH_QUARK_X1000_DFLT);
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001681 pxa2xx_spi_write(drv_data, SSCR1, tmp);
Weike Chene5262d02014-11-26 02:35:10 -08001682
1683 /* using the Motorola SPI protocol and use 8 bit frame */
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001684 tmp = QUARK_X1000_SSCR0_Motorola | QUARK_X1000_SSCR0_DataSize(8);
1685 pxa2xx_spi_write(drv_data, SSCR0, tmp);
Weike Chene5262d02014-11-26 02:35:10 -08001686 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001687 case CE4100_SSP:
1688 tmp = CE4100_SSCR1_RxTresh(RX_THRESH_CE4100_DFLT) |
1689 CE4100_SSCR1_TxTresh(TX_THRESH_CE4100_DFLT);
1690 pxa2xx_spi_write(drv_data, SSCR1, tmp);
1691 tmp = SSCR0_SCR(2) | SSCR0_Motorola | SSCR0_DataSize(8);
1692 pxa2xx_spi_write(drv_data, SSCR0, tmp);
Andy Shevchenkoa2dd8af2017-01-02 13:44:28 +02001693 break;
Weike Chene5262d02014-11-26 02:35:10 -08001694 default:
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001695 tmp = SSCR1_RxTresh(RX_THRESH_DFLT) |
1696 SSCR1_TxTresh(TX_THRESH_DFLT);
1697 pxa2xx_spi_write(drv_data, SSCR1, tmp);
1698 tmp = SSCR0_SCR(2) | SSCR0_Motorola | SSCR0_DataSize(8);
1699 pxa2xx_spi_write(drv_data, SSCR0, tmp);
Weike Chene5262d02014-11-26 02:35:10 -08001700 break;
1701 }
1702
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001703 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001704 pxa2xx_spi_write(drv_data, SSTO, 0);
Weike Chene5262d02014-11-26 02:35:10 -08001705
1706 if (!is_quark_x1000_ssp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001707 pxa2xx_spi_write(drv_data, SSPSP, 0);
Stephen Streete0c99052006-03-07 23:53:24 -08001708
Jarkko Nikula8b136ba2015-10-28 15:13:41 +02001709 if (is_lpss_ssp(drv_data)) {
1710 lpss_ssp_setup(drv_data);
1711 config = lpss_get_config(drv_data);
1712 if (config->reg_capabilities >= 0) {
1713 tmp = __lpss_ssp_read_priv(drv_data,
1714 config->reg_capabilities);
1715 tmp &= LPSS_CAPS_CS_EN_MASK;
1716 tmp >>= LPSS_CAPS_CS_EN_SHIFT;
1717 platform_info->num_chipselect = ffz(tmp);
Mika Westerberg30f3a6a2016-02-08 17:14:31 +02001718 } else if (config->cs_num) {
1719 platform_info->num_chipselect = config->cs_num;
Jarkko Nikula8b136ba2015-10-28 15:13:41 +02001720 }
1721 }
1722 master->num_chipselect = platform_info->num_chipselect;
1723
Mika Westerberg99f499c2016-09-26 15:19:50 +03001724 count = gpiod_count(&pdev->dev, "cs");
1725 if (count > 0) {
1726 int i;
1727
1728 master->num_chipselect = max_t(int, count,
1729 master->num_chipselect);
1730
1731 drv_data->cs_gpiods = devm_kcalloc(&pdev->dev,
1732 master->num_chipselect, sizeof(struct gpio_desc *),
1733 GFP_KERNEL);
1734 if (!drv_data->cs_gpiods) {
1735 status = -ENOMEM;
1736 goto out_error_clock_enabled;
1737 }
1738
1739 for (i = 0; i < master->num_chipselect; i++) {
1740 struct gpio_desc *gpiod;
1741
1742 gpiod = devm_gpiod_get_index(dev, "cs", i,
1743 GPIOD_OUT_HIGH);
1744 if (IS_ERR(gpiod)) {
1745 /* Means use native chip select */
1746 if (PTR_ERR(gpiod) == -ENOENT)
1747 continue;
1748
1749 status = (int)PTR_ERR(gpiod);
1750 goto out_error_clock_enabled;
1751 } else {
1752 drv_data->cs_gpiods[i] = gpiod;
1753 }
1754 }
1755 }
1756
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001757 tasklet_init(&drv_data->pump_transfers, pump_transfers,
1758 (unsigned long)drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001759
Antonio Ospite836d1a22014-05-30 18:18:09 +02001760 pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
1761 pm_runtime_use_autosuspend(&pdev->dev);
1762 pm_runtime_set_active(&pdev->dev);
1763 pm_runtime_enable(&pdev->dev);
1764
Stephen Streete0c99052006-03-07 23:53:24 -08001765 /* Register with the SPI framework */
1766 platform_set_drvdata(pdev, drv_data);
Jingoo Hana807fcd2013-09-24 13:46:55 +09001767 status = devm_spi_register_master(&pdev->dev, master);
Stephen Streete0c99052006-03-07 23:53:24 -08001768 if (status != 0) {
1769 dev_err(&pdev->dev, "problem registering spi master\n");
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001770 goto out_error_clock_enabled;
Stephen Streete0c99052006-03-07 23:53:24 -08001771 }
1772
1773 return status;
1774
Stephen Streete0c99052006-03-07 23:53:24 -08001775out_error_clock_enabled:
Mika Westerberg3343b7a2013-01-22 12:26:27 +02001776 clk_disable_unprepare(ssp->clk);
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001777 pxa2xx_spi_dma_release(drv_data);
eric miao2f1a74e2007-11-21 18:50:53 +08001778 free_irq(ssp->irq, drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001779
1780out_error_master_alloc:
1781 spi_master_put(master);
Haojian Zhuangbaffe162010-05-05 10:11:15 -04001782 pxa_ssp_free(ssp);
Stephen Streete0c99052006-03-07 23:53:24 -08001783 return status;
1784}
1785
1786static int pxa2xx_spi_remove(struct platform_device *pdev)
1787{
1788 struct driver_data *drv_data = platform_get_drvdata(pdev);
Julia Lawall51e911e2009-01-06 14:41:45 -08001789 struct ssp_device *ssp;
Stephen Streete0c99052006-03-07 23:53:24 -08001790
1791 if (!drv_data)
1792 return 0;
Julia Lawall51e911e2009-01-06 14:41:45 -08001793 ssp = drv_data->ssp;
Stephen Streete0c99052006-03-07 23:53:24 -08001794
Mika Westerberg7d94a502013-01-22 12:26:30 +02001795 pm_runtime_get_sync(&pdev->dev);
1796
Stephen Streete0c99052006-03-07 23:53:24 -08001797 /* Disable the SSP at the peripheral and SOC level */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001798 pxa2xx_spi_write(drv_data, SSCR0, 0);
Mika Westerberg3343b7a2013-01-22 12:26:27 +02001799 clk_disable_unprepare(ssp->clk);
Stephen Streete0c99052006-03-07 23:53:24 -08001800
1801 /* Release DMA */
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001802 if (drv_data->master_info->enable_dma)
1803 pxa2xx_spi_dma_release(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001804
Mika Westerberg7d94a502013-01-22 12:26:30 +02001805 pm_runtime_put_noidle(&pdev->dev);
1806 pm_runtime_disable(&pdev->dev);
1807
Stephen Streete0c99052006-03-07 23:53:24 -08001808 /* Release IRQ */
eric miao2f1a74e2007-11-21 18:50:53 +08001809 free_irq(ssp->irq, drv_data);
1810
1811 /* Release SSP */
Haojian Zhuangbaffe162010-05-05 10:11:15 -04001812 pxa_ssp_free(ssp);
Stephen Streete0c99052006-03-07 23:53:24 -08001813
Stephen Streete0c99052006-03-07 23:53:24 -08001814 return 0;
1815}
1816
1817static void pxa2xx_spi_shutdown(struct platform_device *pdev)
1818{
1819 int status = 0;
1820
1821 if ((status = pxa2xx_spi_remove(pdev)) != 0)
1822 dev_err(&pdev->dev, "shutdown failed with %d\n", status);
1823}
1824
Mika Westerberg382cebb2014-01-16 14:50:55 +02001825#ifdef CONFIG_PM_SLEEP
Mike Rapoport86d25932009-07-21 17:50:16 +03001826static int pxa2xx_spi_suspend(struct device *dev)
Stephen Streete0c99052006-03-07 23:53:24 -08001827{
Mike Rapoport86d25932009-07-21 17:50:16 +03001828 struct driver_data *drv_data = dev_get_drvdata(dev);
eric miao2f1a74e2007-11-21 18:50:53 +08001829 struct ssp_device *ssp = drv_data->ssp;
Jarkko Nikulabffc9672016-09-07 17:04:05 +03001830 int status;
Stephen Streete0c99052006-03-07 23:53:24 -08001831
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001832 status = spi_master_suspend(drv_data->master);
Stephen Streete0c99052006-03-07 23:53:24 -08001833 if (status != 0)
1834 return status;
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001835 pxa2xx_spi_write(drv_data, SSCR0, 0);
Dmitry Eremin-Solenikov2b9375b2014-11-06 14:08:29 +03001836
1837 if (!pm_runtime_suspended(dev))
1838 clk_disable_unprepare(ssp->clk);
Stephen Streete0c99052006-03-07 23:53:24 -08001839
1840 return 0;
1841}
1842
Mike Rapoport86d25932009-07-21 17:50:16 +03001843static int pxa2xx_spi_resume(struct device *dev)
Stephen Streete0c99052006-03-07 23:53:24 -08001844{
Mike Rapoport86d25932009-07-21 17:50:16 +03001845 struct driver_data *drv_data = dev_get_drvdata(dev);
eric miao2f1a74e2007-11-21 18:50:53 +08001846 struct ssp_device *ssp = drv_data->ssp;
Jarkko Nikulabffc9672016-09-07 17:04:05 +03001847 int status;
Stephen Streete0c99052006-03-07 23:53:24 -08001848
1849 /* Enable the SSP clock */
Dmitry Eremin-Solenikov2b9375b2014-11-06 14:08:29 +03001850 if (!pm_runtime_suspended(dev))
1851 clk_prepare_enable(ssp->clk);
Stephen Streete0c99052006-03-07 23:53:24 -08001852
Chew, Chiau Eec50325f2013-11-29 02:13:11 +08001853 /* Restore LPSS private register bits */
Jarkko Nikula48421ad2015-01-28 10:09:42 +02001854 if (is_lpss_ssp(drv_data))
1855 lpss_ssp_setup(drv_data);
Chew, Chiau Eec50325f2013-11-29 02:13:11 +08001856
Stephen Streete0c99052006-03-07 23:53:24 -08001857 /* Start the queue running */
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001858 status = spi_master_resume(drv_data->master);
Stephen Streete0c99052006-03-07 23:53:24 -08001859 if (status != 0) {
Mike Rapoport86d25932009-07-21 17:50:16 +03001860 dev_err(dev, "problem starting queue (%d)\n", status);
Stephen Streete0c99052006-03-07 23:53:24 -08001861 return status;
1862 }
1863
1864 return 0;
1865}
Mika Westerberg7d94a502013-01-22 12:26:30 +02001866#endif
1867
Rafael J. Wysockiec833052014-12-13 00:41:15 +01001868#ifdef CONFIG_PM
Mika Westerberg7d94a502013-01-22 12:26:30 +02001869static int pxa2xx_spi_runtime_suspend(struct device *dev)
1870{
1871 struct driver_data *drv_data = dev_get_drvdata(dev);
1872
1873 clk_disable_unprepare(drv_data->ssp->clk);
1874 return 0;
1875}
1876
1877static int pxa2xx_spi_runtime_resume(struct device *dev)
1878{
1879 struct driver_data *drv_data = dev_get_drvdata(dev);
1880
1881 clk_prepare_enable(drv_data->ssp->clk);
1882 return 0;
1883}
1884#endif
Mike Rapoport86d25932009-07-21 17:50:16 +03001885
Alexey Dobriyan47145212009-12-14 18:00:08 -08001886static const struct dev_pm_ops pxa2xx_spi_pm_ops = {
Mika Westerberg7d94a502013-01-22 12:26:30 +02001887 SET_SYSTEM_SLEEP_PM_OPS(pxa2xx_spi_suspend, pxa2xx_spi_resume)
1888 SET_RUNTIME_PM_OPS(pxa2xx_spi_runtime_suspend,
1889 pxa2xx_spi_runtime_resume, NULL)
Mike Rapoport86d25932009-07-21 17:50:16 +03001890};
Stephen Streete0c99052006-03-07 23:53:24 -08001891
1892static struct platform_driver driver = {
1893 .driver = {
Mike Rapoport86d25932009-07-21 17:50:16 +03001894 .name = "pxa2xx-spi",
Mike Rapoport86d25932009-07-21 17:50:16 +03001895 .pm = &pxa2xx_spi_pm_ops,
Mika Westerberga3496852013-01-22 12:26:33 +02001896 .acpi_match_table = ACPI_PTR(pxa2xx_spi_acpi_match),
Stephen Streete0c99052006-03-07 23:53:24 -08001897 },
Sebastian Andrzej Siewiorfbd29a12010-11-19 09:00:11 -08001898 .probe = pxa2xx_spi_probe,
David Brownelld1e44d92007-10-16 01:27:46 -07001899 .remove = pxa2xx_spi_remove,
Stephen Streete0c99052006-03-07 23:53:24 -08001900 .shutdown = pxa2xx_spi_shutdown,
Stephen Streete0c99052006-03-07 23:53:24 -08001901};
1902
1903static int __init pxa2xx_spi_init(void)
1904{
Sebastian Andrzej Siewiorfbd29a12010-11-19 09:00:11 -08001905 return platform_driver_register(&driver);
Stephen Streete0c99052006-03-07 23:53:24 -08001906}
Antonio Ospite5b61a742009-09-22 16:46:10 -07001907subsys_initcall(pxa2xx_spi_init);
Stephen Streete0c99052006-03-07 23:53:24 -08001908
1909static void __exit pxa2xx_spi_exit(void)
1910{
1911 platform_driver_unregister(&driver);
1912}
1913module_exit(pxa2xx_spi_exit);