blob: d68f511a9ef1526483ec6bd4271f4581609e2a7a [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 Nikulafc0b2ac2017-05-30 17:31:21 +0300154 { /* LPSS_CNL_SSP */
155 .offset = 0x200,
156 .reg_general = -1,
157 .reg_ssp = 0x20,
158 .reg_cs_ctrl = 0x24,
159 .reg_capabilities = 0xfc,
160 .rx_threshold = 1,
161 .tx_threshold_lo = 32,
162 .tx_threshold_hi = 56,
163 .cs_sel_shift = 8,
164 .cs_sel_mask = 3 << 8,
165 },
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300166};
167
168static inline const struct lpss_config
169*lpss_get_config(const struct driver_data *drv_data)
170{
171 return &lpss_platforms[drv_data->ssp_type - LPSS_LPT_SSP];
172}
173
Mika Westerberga0d26422013-01-22 12:26:32 +0200174static bool is_lpss_ssp(const struct driver_data *drv_data)
175{
Jarkko Nikula03fbf482015-06-04 16:55:10 +0300176 switch (drv_data->ssp_type) {
177 case LPSS_LPT_SSP:
178 case LPSS_BYT_SSP:
Mika Westerberg30f3a6a2016-02-08 17:14:31 +0200179 case LPSS_BSW_SSP:
Jarkko Nikula34cadd92015-07-30 16:30:07 +0300180 case LPSS_SPT_SSP:
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +0200181 case LPSS_BXT_SSP:
Jarkko Nikulafc0b2ac2017-05-30 17:31:21 +0300182 case LPSS_CNL_SSP:
Jarkko Nikula03fbf482015-06-04 16:55:10 +0300183 return true;
184 default:
185 return false;
186 }
Mika Westerberga0d26422013-01-22 12:26:32 +0200187}
188
Weike Chene5262d02014-11-26 02:35:10 -0800189static bool is_quark_x1000_ssp(const struct driver_data *drv_data)
190{
191 return drv_data->ssp_type == QUARK_X1000_SSP;
192}
193
Weike Chen4fdb2422014-10-08 08:50:22 -0700194static u32 pxa2xx_spi_get_ssrc1_change_mask(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 QUARK_X1000_SSCR1_CHANGE_MASK;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300199 case CE4100_SSP:
200 return CE4100_SSCR1_CHANGE_MASK;
Weike Chen4fdb2422014-10-08 08:50:22 -0700201 default:
202 return SSCR1_CHANGE_MASK;
203 }
204}
205
206static u32
207pxa2xx_spi_get_rx_default_thre(const struct driver_data *drv_data)
208{
209 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800210 case QUARK_X1000_SSP:
211 return RX_THRESH_QUARK_X1000_DFLT;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300212 case CE4100_SSP:
213 return RX_THRESH_CE4100_DFLT;
Weike Chen4fdb2422014-10-08 08:50:22 -0700214 default:
215 return RX_THRESH_DFLT;
216 }
217}
218
219static bool pxa2xx_spi_txfifo_full(const struct driver_data *drv_data)
220{
Weike Chen4fdb2422014-10-08 08:50:22 -0700221 u32 mask;
222
223 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800224 case QUARK_X1000_SSP:
225 mask = QUARK_X1000_SSSR_TFL_MASK;
226 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300227 case CE4100_SSP:
228 mask = CE4100_SSSR_TFL_MASK;
229 break;
Weike Chen4fdb2422014-10-08 08:50:22 -0700230 default:
231 mask = SSSR_TFL_MASK;
232 break;
233 }
234
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200235 return (pxa2xx_spi_read(drv_data, SSSR) & mask) == mask;
Weike Chen4fdb2422014-10-08 08:50:22 -0700236}
237
238static void pxa2xx_spi_clear_rx_thre(const struct driver_data *drv_data,
239 u32 *sccr1_reg)
240{
241 u32 mask;
242
243 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800244 case QUARK_X1000_SSP:
245 mask = QUARK_X1000_SSCR1_RFT;
246 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300247 case CE4100_SSP:
248 mask = CE4100_SSCR1_RFT;
249 break;
Weike Chen4fdb2422014-10-08 08:50:22 -0700250 default:
251 mask = SSCR1_RFT;
252 break;
253 }
254 *sccr1_reg &= ~mask;
255}
256
257static void pxa2xx_spi_set_rx_thre(const struct driver_data *drv_data,
258 u32 *sccr1_reg, u32 threshold)
259{
260 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800261 case QUARK_X1000_SSP:
262 *sccr1_reg |= QUARK_X1000_SSCR1_RxTresh(threshold);
263 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300264 case CE4100_SSP:
265 *sccr1_reg |= CE4100_SSCR1_RxTresh(threshold);
266 break;
Weike Chen4fdb2422014-10-08 08:50:22 -0700267 default:
268 *sccr1_reg |= SSCR1_RxTresh(threshold);
269 break;
270 }
271}
272
273static u32 pxa2xx_configure_sscr0(const struct driver_data *drv_data,
274 u32 clk_div, u8 bits)
275{
276 switch (drv_data->ssp_type) {
Weike Chene5262d02014-11-26 02:35:10 -0800277 case QUARK_X1000_SSP:
278 return clk_div
279 | QUARK_X1000_SSCR0_Motorola
280 | QUARK_X1000_SSCR0_DataSize(bits > 32 ? 8 : bits)
281 | SSCR0_SSE;
Weike Chen4fdb2422014-10-08 08:50:22 -0700282 default:
283 return clk_div
284 | SSCR0_Motorola
285 | SSCR0_DataSize(bits > 16 ? bits - 16 : bits)
286 | SSCR0_SSE
287 | (bits > 16 ? SSCR0_EDSS : 0);
288 }
289}
290
Mika Westerberga0d26422013-01-22 12:26:32 +0200291/*
292 * Read and write LPSS SSP private registers. Caller must first check that
293 * is_lpss_ssp() returns true before these can be called.
294 */
295static u32 __lpss_ssp_read_priv(struct driver_data *drv_data, unsigned offset)
296{
297 WARN_ON(!drv_data->lpss_base);
298 return readl(drv_data->lpss_base + offset);
299}
300
301static void __lpss_ssp_write_priv(struct driver_data *drv_data,
302 unsigned offset, u32 value)
303{
304 WARN_ON(!drv_data->lpss_base);
305 writel(value, drv_data->lpss_base + offset);
306}
307
308/*
309 * lpss_ssp_setup - perform LPSS SSP specific setup
310 * @drv_data: pointer to the driver private data
311 *
312 * Perform LPSS SSP specific setup. This function must be called first if
313 * one is going to use LPSS SSP private registers.
314 */
315static void lpss_ssp_setup(struct driver_data *drv_data)
316{
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300317 const struct lpss_config *config;
318 u32 value;
Mika Westerberga0d26422013-01-22 12:26:32 +0200319
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300320 config = lpss_get_config(drv_data);
321 drv_data->lpss_base = drv_data->ioaddr + config->offset;
Mika Westerberga0d26422013-01-22 12:26:32 +0200322
323 /* Enable software chip select control */
Jarkko Nikula0e897212015-10-22 16:44:42 +0300324 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
Jarkko Nikula624ea722015-10-28 15:13:39 +0200325 value &= ~(LPSS_CS_CONTROL_SW_MODE | LPSS_CS_CONTROL_CS_HIGH);
326 value |= LPSS_CS_CONTROL_SW_MODE | LPSS_CS_CONTROL_CS_HIGH;
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300327 __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value);
Mika Westerberg0054e282013-03-05 12:05:17 +0200328
329 /* Enable multiblock DMA transfers */
Mika Westerberg1de70612013-07-03 13:25:06 +0300330 if (drv_data->master_info->enable_dma) {
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300331 __lpss_ssp_write_priv(drv_data, config->reg_ssp, 1);
Mika Westerberg1de70612013-07-03 13:25:06 +0300332
Jarkko Nikula82ba2c22015-06-04 16:55:12 +0300333 if (config->reg_general >= 0) {
334 value = __lpss_ssp_read_priv(drv_data,
335 config->reg_general);
Jarkko Nikula624ea722015-10-28 15:13:39 +0200336 value |= LPSS_GENERAL_REG_RXTO_HOLDOFF_DISABLE;
Jarkko Nikula82ba2c22015-06-04 16:55:12 +0300337 __lpss_ssp_write_priv(drv_data,
338 config->reg_general, value);
339 }
Mika Westerberg1de70612013-07-03 13:25:06 +0300340 }
Mika Westerberga0d26422013-01-22 12:26:32 +0200341}
342
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300343static void lpss_ssp_select_cs(struct spi_device *spi,
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200344 const struct lpss_config *config)
345{
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300346 struct driver_data *drv_data =
347 spi_controller_get_devdata(spi->controller);
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200348 u32 value, cs;
349
350 if (!config->cs_sel_mask)
351 return;
352
353 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
354
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300355 cs = spi->chip_select;
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200356 cs <<= config->cs_sel_shift;
357 if (cs != (value & config->cs_sel_mask)) {
358 /*
359 * When switching another chip select output active the
360 * output must be selected first and wait 2 ssp_clk cycles
361 * before changing state to active. Otherwise a short
362 * glitch will occur on the previous chip select since
363 * output select is latched but state control is not.
364 */
365 value &= ~config->cs_sel_mask;
366 value |= cs;
367 __lpss_ssp_write_priv(drv_data,
368 config->reg_cs_ctrl, value);
369 ndelay(1000000000 /
370 (drv_data->master->max_speed_hz / 2));
371 }
372}
373
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300374static void lpss_ssp_cs_control(struct spi_device *spi, bool enable)
Mika Westerberga0d26422013-01-22 12:26:32 +0200375{
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300376 struct driver_data *drv_data =
377 spi_controller_get_devdata(spi->controller);
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300378 const struct lpss_config *config;
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200379 u32 value;
Mika Westerberga0d26422013-01-22 12:26:32 +0200380
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300381 config = lpss_get_config(drv_data);
382
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200383 if (enable)
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300384 lpss_ssp_select_cs(spi, config);
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200385
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300386 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200387 if (enable)
Jarkko Nikula624ea722015-10-28 15:13:39 +0200388 value &= ~LPSS_CS_CONTROL_CS_HIGH;
Mika Westerbergc1e4a532016-02-08 17:14:30 +0200389 else
Jarkko Nikula624ea722015-10-28 15:13:39 +0200390 value |= LPSS_CS_CONTROL_CS_HIGH;
Jarkko Nikuladccf7362015-06-04 16:55:11 +0300391 __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value);
Mika Westerberga0d26422013-01-22 12:26:32 +0200392}
393
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300394static void cs_assert(struct spi_device *spi)
Eric Miaoa7bb3902009-04-06 19:00:54 -0700395{
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300396 struct chip_data *chip = spi_get_ctldata(spi);
397 struct driver_data *drv_data =
398 spi_controller_get_devdata(spi->controller);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700399
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800400 if (drv_data->ssp_type == CE4100_SSP) {
Jarkko Nikula96579a42016-09-07 17:04:07 +0300401 pxa2xx_spi_write(drv_data, SSSR, chip->frm);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800402 return;
403 }
404
Eric Miaoa7bb3902009-04-06 19:00:54 -0700405 if (chip->cs_control) {
406 chip->cs_control(PXA2XX_CS_ASSERT);
407 return;
408 }
409
Jan Kiszkac18d9252017-08-03 13:40:32 +0200410 if (chip->gpiod_cs) {
411 gpiod_set_value(chip->gpiod_cs, chip->gpio_cs_inverted);
Mika Westerberga0d26422013-01-22 12:26:32 +0200412 return;
413 }
414
Jarkko Nikula7566bcc2014-12-18 15:04:20 +0200415 if (is_lpss_ssp(drv_data))
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300416 lpss_ssp_cs_control(spi, true);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700417}
418
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300419static void cs_deassert(struct spi_device *spi)
Eric Miaoa7bb3902009-04-06 19:00:54 -0700420{
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300421 struct chip_data *chip = spi_get_ctldata(spi);
422 struct driver_data *drv_data =
423 spi_controller_get_devdata(spi->controller);
Jarkko Nikula104e51a2018-02-09 16:31:07 +0200424 unsigned long timeout;
Eric Miaoa7bb3902009-04-06 19:00:54 -0700425
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800426 if (drv_data->ssp_type == CE4100_SSP)
427 return;
428
Jarkko Nikula104e51a2018-02-09 16:31:07 +0200429 /* Wait until SSP becomes idle before deasserting the CS */
430 timeout = jiffies + msecs_to_jiffies(10);
431 while (pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY &&
432 !time_after(jiffies, timeout))
433 cpu_relax();
434
Eric Miaoa7bb3902009-04-06 19:00:54 -0700435 if (chip->cs_control) {
Daniel Ribeiro2b2562d2009-04-08 22:48:03 -0300436 chip->cs_control(PXA2XX_CS_DEASSERT);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700437 return;
438 }
439
Jan Kiszkac18d9252017-08-03 13:40:32 +0200440 if (chip->gpiod_cs) {
441 gpiod_set_value(chip->gpiod_cs, !chip->gpio_cs_inverted);
Mika Westerberga0d26422013-01-22 12:26:32 +0200442 return;
443 }
444
Jarkko Nikula7566bcc2014-12-18 15:04:20 +0200445 if (is_lpss_ssp(drv_data))
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300446 lpss_ssp_cs_control(spi, false);
447}
448
449static void pxa2xx_spi_set_cs(struct spi_device *spi, bool level)
450{
451 if (level)
452 cs_deassert(spi);
453 else
454 cs_assert(spi);
Eric Miaoa7bb3902009-04-06 19:00:54 -0700455}
456
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200457int pxa2xx_spi_flush(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800458{
459 unsigned long limit = loops_per_jiffy << 1;
460
Stephen Streete0c99052006-03-07 23:53:24 -0800461 do {
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200462 while (pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
463 pxa2xx_spi_read(drv_data, SSDR);
464 } while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY) && --limit);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800465 write_SSSR_CS(drv_data, SSSR_ROR);
Stephen Streete0c99052006-03-07 23:53:24 -0800466
467 return limit;
468}
469
Stephen Street8d94cc52006-12-10 02:18:54 -0800470static int null_writer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800471{
Stephen Street9708c122006-03-28 14:05:23 -0800472 u8 n_bytes = drv_data->n_bytes;
Stephen Streete0c99052006-03-07 23:53:24 -0800473
Weike Chen4fdb2422014-10-08 08:50:22 -0700474 if (pxa2xx_spi_txfifo_full(drv_data)
Stephen Street8d94cc52006-12-10 02:18:54 -0800475 || (drv_data->tx == drv_data->tx_end))
476 return 0;
477
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200478 pxa2xx_spi_write(drv_data, SSDR, 0);
Stephen Street8d94cc52006-12-10 02:18:54 -0800479 drv_data->tx += n_bytes;
480
481 return 1;
Stephen Streete0c99052006-03-07 23:53:24 -0800482}
483
Stephen Street8d94cc52006-12-10 02:18:54 -0800484static int null_reader(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800485{
Stephen Street9708c122006-03-28 14:05:23 -0800486 u8 n_bytes = drv_data->n_bytes;
Stephen Streete0c99052006-03-07 23:53:24 -0800487
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200488 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
489 && (drv_data->rx < drv_data->rx_end)) {
490 pxa2xx_spi_read(drv_data, SSDR);
Stephen Streete0c99052006-03-07 23:53:24 -0800491 drv_data->rx += n_bytes;
492 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800493
494 return drv_data->rx == drv_data->rx_end;
Stephen Streete0c99052006-03-07 23:53:24 -0800495}
496
Stephen Street8d94cc52006-12-10 02:18:54 -0800497static int u8_writer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800498{
Weike Chen4fdb2422014-10-08 08:50:22 -0700499 if (pxa2xx_spi_txfifo_full(drv_data)
Stephen Street8d94cc52006-12-10 02:18:54 -0800500 || (drv_data->tx == drv_data->tx_end))
501 return 0;
502
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200503 pxa2xx_spi_write(drv_data, SSDR, *(u8 *)(drv_data->tx));
Stephen Street8d94cc52006-12-10 02:18:54 -0800504 ++drv_data->tx;
505
506 return 1;
Stephen Streete0c99052006-03-07 23:53:24 -0800507}
508
Stephen Street8d94cc52006-12-10 02:18:54 -0800509static int u8_reader(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800510{
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200511 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
512 && (drv_data->rx < drv_data->rx_end)) {
513 *(u8 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
Stephen Streete0c99052006-03-07 23:53:24 -0800514 ++drv_data->rx;
515 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800516
517 return drv_data->rx == drv_data->rx_end;
Stephen Streete0c99052006-03-07 23:53:24 -0800518}
519
Stephen Street8d94cc52006-12-10 02:18:54 -0800520static int u16_writer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800521{
Weike Chen4fdb2422014-10-08 08:50:22 -0700522 if (pxa2xx_spi_txfifo_full(drv_data)
Stephen Street8d94cc52006-12-10 02:18:54 -0800523 || (drv_data->tx == drv_data->tx_end))
524 return 0;
525
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200526 pxa2xx_spi_write(drv_data, SSDR, *(u16 *)(drv_data->tx));
Stephen Street8d94cc52006-12-10 02:18:54 -0800527 drv_data->tx += 2;
528
529 return 1;
Stephen Streete0c99052006-03-07 23:53:24 -0800530}
531
Stephen Street8d94cc52006-12-10 02:18:54 -0800532static int u16_reader(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800533{
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200534 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
535 && (drv_data->rx < drv_data->rx_end)) {
536 *(u16 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
Stephen Streete0c99052006-03-07 23:53:24 -0800537 drv_data->rx += 2;
538 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800539
540 return drv_data->rx == drv_data->rx_end;
Stephen Streete0c99052006-03-07 23:53:24 -0800541}
Stephen Street8d94cc52006-12-10 02:18:54 -0800542
543static int u32_writer(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800544{
Weike Chen4fdb2422014-10-08 08:50:22 -0700545 if (pxa2xx_spi_txfifo_full(drv_data)
Stephen Street8d94cc52006-12-10 02:18:54 -0800546 || (drv_data->tx == drv_data->tx_end))
547 return 0;
548
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200549 pxa2xx_spi_write(drv_data, SSDR, *(u32 *)(drv_data->tx));
Stephen Street8d94cc52006-12-10 02:18:54 -0800550 drv_data->tx += 4;
551
552 return 1;
Stephen Streete0c99052006-03-07 23:53:24 -0800553}
554
Stephen Street8d94cc52006-12-10 02:18:54 -0800555static int u32_reader(struct driver_data *drv_data)
Stephen Streete0c99052006-03-07 23:53:24 -0800556{
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200557 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
558 && (drv_data->rx < drv_data->rx_end)) {
559 *(u32 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
Stephen Streete0c99052006-03-07 23:53:24 -0800560 drv_data->rx += 4;
561 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800562
563 return drv_data->rx == drv_data->rx_end;
Stephen Streete0c99052006-03-07 23:53:24 -0800564}
565
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800566static void reset_sccr1(struct driver_data *drv_data)
567{
Jarkko Nikula96579a42016-09-07 17:04:07 +0300568 struct chip_data *chip =
569 spi_get_ctldata(drv_data->master->cur_msg->spi);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800570 u32 sccr1_reg;
571
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200572 sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1;
Andy Shevchenko152bc192016-07-06 12:08:11 +0300573 switch (drv_data->ssp_type) {
574 case QUARK_X1000_SSP:
575 sccr1_reg &= ~QUARK_X1000_SSCR1_RFT;
576 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +0300577 case CE4100_SSP:
578 sccr1_reg &= ~CE4100_SSCR1_RFT;
579 break;
Andy Shevchenko152bc192016-07-06 12:08:11 +0300580 default:
581 sccr1_reg &= ~SSCR1_RFT;
582 break;
583 }
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800584 sccr1_reg |= chip->threshold;
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200585 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800586}
587
Stephen Street8d94cc52006-12-10 02:18:54 -0800588static void int_error_stop(struct driver_data *drv_data, const char* msg)
589{
Stephen Street8d94cc52006-12-10 02:18:54 -0800590 /* Stop and reset SSP */
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800591 write_SSSR_CS(drv_data, drv_data->clear_sr);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800592 reset_sccr1(drv_data);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800593 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200594 pxa2xx_spi_write(drv_data, SSTO, 0);
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200595 pxa2xx_spi_flush(drv_data);
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200596 pxa2xx_spi_write(drv_data, SSCR0,
597 pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
Stephen Street8d94cc52006-12-10 02:18:54 -0800598
599 dev_err(&drv_data->pdev->dev, "%s\n", msg);
600
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300601 drv_data->master->cur_msg->status = -EIO;
602 spi_finalize_current_transfer(drv_data->master);
Stephen Street8d94cc52006-12-10 02:18:54 -0800603}
604
605static void int_transfer_complete(struct driver_data *drv_data)
606{
Jarkko Nikula07550df2016-02-04 12:30:56 +0200607 /* Clear and disable interrupts */
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800608 write_SSSR_CS(drv_data, drv_data->clear_sr);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800609 reset_sccr1(drv_data);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800610 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200611 pxa2xx_spi_write(drv_data, SSTO, 0);
Stephen Street8d94cc52006-12-10 02:18:54 -0800612
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300613 spi_finalize_current_transfer(drv_data->master);
Stephen Street8d94cc52006-12-10 02:18:54 -0800614}
615
Stephen Streete0c99052006-03-07 23:53:24 -0800616static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
617{
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200618 u32 irq_mask = (pxa2xx_spi_read(drv_data, SSCR1) & SSCR1_TIE) ?
619 drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS;
Stephen Street8d94cc52006-12-10 02:18:54 -0800620
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200621 u32 irq_status = pxa2xx_spi_read(drv_data, SSSR) & irq_mask;
Stephen Streete0c99052006-03-07 23:53:24 -0800622
Stephen Street8d94cc52006-12-10 02:18:54 -0800623 if (irq_status & SSSR_ROR) {
624 int_error_stop(drv_data, "interrupt_transfer: fifo overrun");
625 return IRQ_HANDLED;
626 }
Stephen Streete0c99052006-03-07 23:53:24 -0800627
Stephen Street8d94cc52006-12-10 02:18:54 -0800628 if (irq_status & SSSR_TINT) {
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200629 pxa2xx_spi_write(drv_data, SSSR, SSSR_TINT);
Stephen Street8d94cc52006-12-10 02:18:54 -0800630 if (drv_data->read(drv_data)) {
631 int_transfer_complete(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -0800632 return IRQ_HANDLED;
633 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800634 }
Stephen Streete0c99052006-03-07 23:53:24 -0800635
Stephen Street8d94cc52006-12-10 02:18:54 -0800636 /* Drain rx fifo, Fill tx fifo and prevent overruns */
637 do {
638 if (drv_data->read(drv_data)) {
639 int_transfer_complete(drv_data);
640 return IRQ_HANDLED;
Stephen Streete0c99052006-03-07 23:53:24 -0800641 }
Stephen Street8d94cc52006-12-10 02:18:54 -0800642 } while (drv_data->write(drv_data));
Stephen Streete0c99052006-03-07 23:53:24 -0800643
Stephen Street8d94cc52006-12-10 02:18:54 -0800644 if (drv_data->read(drv_data)) {
645 int_transfer_complete(drv_data);
646 return IRQ_HANDLED;
647 }
Stephen Streete0c99052006-03-07 23:53:24 -0800648
Stephen Street8d94cc52006-12-10 02:18:54 -0800649 if (drv_data->tx == drv_data->tx_end) {
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800650 u32 bytes_left;
651 u32 sccr1_reg;
652
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200653 sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800654 sccr1_reg &= ~SSCR1_TIE;
655
656 /*
657 * PXA25x_SSP has no timeout, set up rx threshould for the
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300658 * remaining RX bytes.
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800659 */
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800660 if (pxa25x_ssp_comp(drv_data)) {
Weike Chen4fdb2422014-10-08 08:50:22 -0700661 u32 rx_thre;
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800662
Weike Chen4fdb2422014-10-08 08:50:22 -0700663 pxa2xx_spi_clear_rx_thre(drv_data, &sccr1_reg);
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800664
665 bytes_left = drv_data->rx_end - drv_data->rx;
666 switch (drv_data->n_bytes) {
667 case 4:
Gustavo A. R. Silva2c183372018-10-03 17:55:22 +0200668 bytes_left >>= 2;
669 break;
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800670 case 2:
671 bytes_left >>= 1;
Gustavo A. R. Silva2c183372018-10-03 17:55:22 +0200672 break;
Stephen Street8d94cc52006-12-10 02:18:54 -0800673 }
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800674
Weike Chen4fdb2422014-10-08 08:50:22 -0700675 rx_thre = pxa2xx_spi_get_rx_default_thre(drv_data);
676 if (rx_thre > bytes_left)
677 rx_thre = bytes_left;
Sebastian Andrzej Siewior579d3bb2010-11-22 17:12:17 -0800678
Weike Chen4fdb2422014-10-08 08:50:22 -0700679 pxa2xx_spi_set_rx_thre(drv_data, &sccr1_reg, rx_thre);
Stephen Streete0c99052006-03-07 23:53:24 -0800680 }
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200681 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
Stephen Streete0c99052006-03-07 23:53:24 -0800682 }
683
Stephen Street5daa3ba2006-05-20 15:00:19 -0700684 /* We did something */
685 return IRQ_HANDLED;
Stephen Streete0c99052006-03-07 23:53:24 -0800686}
687
Jan Kiszkab0312482017-01-16 19:44:54 +0100688static void handle_bad_msg(struct driver_data *drv_data)
689{
690 pxa2xx_spi_write(drv_data, SSCR0,
691 pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
692 pxa2xx_spi_write(drv_data, SSCR1,
693 pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1);
694 if (!pxa25x_ssp_comp(drv_data))
695 pxa2xx_spi_write(drv_data, SSTO, 0);
696 write_SSSR_CS(drv_data, drv_data->clear_sr);
697
698 dev_err(&drv_data->pdev->dev,
699 "bad message state in interrupt handler\n");
700}
701
David Howells7d12e782006-10-05 14:55:46 +0100702static irqreturn_t ssp_int(int irq, void *dev_id)
Stephen Streete0c99052006-03-07 23:53:24 -0800703{
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400704 struct driver_data *drv_data = dev_id;
Mika Westerberg7d94a502013-01-22 12:26:30 +0200705 u32 sccr1_reg;
Sebastian Andrzej Siewior49cbb1e2010-11-22 17:12:14 -0800706 u32 mask = drv_data->mask_sr;
707 u32 status;
708
Mika Westerberg7d94a502013-01-22 12:26:30 +0200709 /*
710 * The IRQ might be shared with other peripherals so we must first
711 * check that are we RPM suspended or not. If we are we assume that
712 * the IRQ was not for us (we shouldn't be RPM suspended when the
713 * interrupt is enabled).
714 */
715 if (pm_runtime_suspended(&drv_data->pdev->dev))
716 return IRQ_NONE;
717
Mika Westerberg269e4a42013-09-04 13:37:43 +0300718 /*
719 * If the device is not yet in RPM suspended state and we get an
720 * interrupt that is meant for another device, check if status bits
721 * are all set to one. That means that the device is already
722 * powered off.
723 */
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200724 status = pxa2xx_spi_read(drv_data, SSSR);
Mika Westerberg269e4a42013-09-04 13:37:43 +0300725 if (status == ~0)
726 return IRQ_NONE;
727
Jarkko Nikulac039dd22014-12-18 15:04:23 +0200728 sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
Sebastian Andrzej Siewior49cbb1e2010-11-22 17:12:14 -0800729
730 /* Ignore possible writes if we don't need to write */
731 if (!(sccr1_reg & SSCR1_TIE))
732 mask &= ~SSSR_TFS;
733
Tan, Jui Nee02bc9332015-09-01 10:22:51 +0800734 /* Ignore RX timeout interrupt if it is disabled */
735 if (!(sccr1_reg & SSCR1_TINTE))
736 mask &= ~SSSR_TINT;
737
Sebastian Andrzej Siewior49cbb1e2010-11-22 17:12:14 -0800738 if (!(status & mask))
739 return IRQ_NONE;
Stephen Streete0c99052006-03-07 23:53:24 -0800740
Jan Kiszkae51e9b92017-01-21 10:06:38 +0100741 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg & ~drv_data->int_cr1);
742 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
743
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300744 if (!drv_data->master->cur_msg) {
Jan Kiszkab0312482017-01-16 19:44:54 +0100745 handle_bad_msg(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -0800746 /* Never fail */
747 return IRQ_HANDLED;
748 }
749
750 return drv_data->transfer_handler(drv_data);
751}
752
Weike Chene5262d02014-11-26 02:35:10 -0800753/*
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200754 * The Quark SPI has an additional 24 bit register (DDS_CLK_RATE) to multiply
755 * input frequency by fractions of 2^24. It also has a divider by 5.
756 *
757 * There are formulas to get baud rate value for given input frequency and
758 * divider parameters, such as DDS_CLK_RATE and SCR:
759 *
760 * Fsys = 200MHz
761 *
762 * Fssp = Fsys * DDS_CLK_RATE / 2^24 (1)
763 * Baud rate = Fsclk = Fssp / (2 * (SCR + 1)) (2)
764 *
765 * DDS_CLK_RATE either 2^n or 2^n / 5.
766 * SCR is in range 0 .. 255
767 *
768 * Divisor = 5^i * 2^j * 2 * k
769 * i = [0, 1] i = 1 iff j = 0 or j > 3
770 * j = [0, 23] j = 0 iff i = 1
771 * k = [1, 256]
772 * Special case: j = 0, i = 1: Divisor = 2 / 5
773 *
774 * Accordingly to the specification the recommended values for DDS_CLK_RATE
775 * are:
776 * Case 1: 2^n, n = [0, 23]
777 * Case 2: 2^24 * 2 / 5 (0x666666)
778 * Case 3: less than or equal to 2^24 / 5 / 16 (0x33333)
779 *
780 * In all cases the lowest possible value is better.
781 *
782 * The function calculates parameters for all cases and chooses the one closest
783 * to the asked baud rate.
Weike Chene5262d02014-11-26 02:35:10 -0800784 */
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200785static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds)
Weike Chene5262d02014-11-26 02:35:10 -0800786{
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200787 unsigned long xtal = 200000000;
788 unsigned long fref = xtal / 2; /* mandatory division by 2,
789 see (2) */
790 /* case 3 */
791 unsigned long fref1 = fref / 2; /* case 1 */
792 unsigned long fref2 = fref * 2 / 5; /* case 2 */
793 unsigned long scale;
794 unsigned long q, q1, q2;
795 long r, r1, r2;
796 u32 mul;
Weike Chene5262d02014-11-26 02:35:10 -0800797
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200798 /* Case 1 */
799
800 /* Set initial value for DDS_CLK_RATE */
801 mul = (1 << 24) >> 1;
802
803 /* Calculate initial quot */
Andy Shevchenko3ad48062015-10-13 17:09:14 +0300804 q1 = DIV_ROUND_UP(fref1, rate);
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200805
806 /* Scale q1 if it's too big */
807 if (q1 > 256) {
808 /* Scale q1 to range [1, 512] */
809 scale = fls_long(q1 - 1);
810 if (scale > 9) {
811 q1 >>= scale - 9;
812 mul >>= scale - 9;
813 }
814
815 /* Round the result if we have a remainder */
816 q1 += q1 & 1;
817 }
818
819 /* Decrease DDS_CLK_RATE as much as we can without loss in precision */
820 scale = __ffs(q1);
821 q1 >>= scale;
822 mul >>= scale;
823
824 /* Get the remainder */
825 r1 = abs(fref1 / (1 << (24 - fls_long(mul))) / q1 - rate);
826
827 /* Case 2 */
828
Andy Shevchenko3ad48062015-10-13 17:09:14 +0300829 q2 = DIV_ROUND_UP(fref2, rate);
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200830 r2 = abs(fref2 / q2 - rate);
831
832 /*
833 * Choose the best between two: less remainder we have the better. We
834 * can't go case 2 if q2 is greater than 256 since SCR register can
835 * hold only values 0 .. 255.
836 */
837 if (r2 >= r1 || q2 > 256) {
838 /* case 1 is better */
839 r = r1;
840 q = q1;
841 } else {
842 /* case 2 is better */
843 r = r2;
844 q = q2;
845 mul = (1 << 24) * 2 / 5;
846 }
847
Andy Shevchenko3ad48062015-10-13 17:09:14 +0300848 /* Check case 3 only if the divisor is big enough */
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200849 if (fref / rate >= 80) {
850 u64 fssp;
851 u32 m;
852
853 /* Calculate initial quot */
Andy Shevchenko3ad48062015-10-13 17:09:14 +0300854 q1 = DIV_ROUND_UP(fref, rate);
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200855 m = (1 << 24) / q1;
856
857 /* Get the remainder */
858 fssp = (u64)fref * m;
859 do_div(fssp, 1 << 24);
860 r1 = abs(fssp - rate);
861
862 /* Choose this one if it suits better */
863 if (r1 < r) {
864 /* case 3 is better */
865 q = 1;
866 mul = m;
Weike Chene5262d02014-11-26 02:35:10 -0800867 }
868 }
869
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200870 *dds = mul;
871 return q - 1;
Weike Chene5262d02014-11-26 02:35:10 -0800872}
873
Mika Westerberg3343b7a2013-01-22 12:26:27 +0200874static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
eric miao2f1a74e2007-11-21 18:50:53 +0800875{
Jarkko Nikula0eca7cf2015-09-25 10:27:17 +0300876 unsigned long ssp_clk = drv_data->master->max_speed_hz;
Mika Westerberg3343b7a2013-01-22 12:26:27 +0200877 const struct ssp_device *ssp = drv_data->ssp;
878
879 rate = min_t(int, ssp_clk, rate);
eric miao2f1a74e2007-11-21 18:50:53 +0800880
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -0800881 if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200882 return (ssp_clk / (2 * rate) - 1) & 0xff;
eric miao2f1a74e2007-11-21 18:50:53 +0800883 else
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200884 return (ssp_clk / rate - 1) & 0xfff;
eric miao2f1a74e2007-11-21 18:50:53 +0800885}
886
Weike Chene5262d02014-11-26 02:35:10 -0800887static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data,
Andy Shevchenkod2c2f6a2015-10-22 16:44:40 +0300888 int rate)
Weike Chene5262d02014-11-26 02:35:10 -0800889{
Jarkko Nikula96579a42016-09-07 17:04:07 +0300890 struct chip_data *chip =
891 spi_get_ctldata(drv_data->master->cur_msg->spi);
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200892 unsigned int clk_div;
Weike Chene5262d02014-11-26 02:35:10 -0800893
894 switch (drv_data->ssp_type) {
895 case QUARK_X1000_SSP:
Andy Shevchenko9df461e2015-03-25 15:06:16 +0200896 clk_div = quark_x1000_get_clk_div(rate, &chip->dds_rate);
Dan Carpentereecacf72015-03-31 16:49:38 +0300897 break;
Weike Chene5262d02014-11-26 02:35:10 -0800898 default:
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200899 clk_div = ssp_get_clk_div(drv_data, rate);
Dan Carpentereecacf72015-03-31 16:49:38 +0300900 break;
Weike Chene5262d02014-11-26 02:35:10 -0800901 }
Andy Shevchenko025ffe82015-03-24 17:43:21 +0200902 return clk_div << 8;
Weike Chene5262d02014-11-26 02:35:10 -0800903}
904
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +0200905static bool pxa2xx_spi_can_dma(struct spi_controller *master,
Jarkko Nikulab6ced292016-06-21 13:21:34 +0300906 struct spi_device *spi,
907 struct spi_transfer *xfer)
908{
909 struct chip_data *chip = spi_get_ctldata(spi);
910
911 return chip->enable_dma &&
912 xfer->len <= MAX_DMA_LEN &&
913 xfer->len >= chip->dma_burst_size;
914}
915
kbuild test robot71293a62018-04-18 03:53:23 +0800916static int pxa2xx_spi_transfer_one(struct spi_controller *master,
917 struct spi_device *spi,
918 struct spi_transfer *transfer)
Stephen Streete0c99052006-03-07 23:53:24 -0800919{
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300920 struct driver_data *drv_data = spi_controller_get_devdata(master);
Jarkko Nikula4fc0caa2016-09-07 17:04:06 +0300921 struct spi_message *message = master->cur_msg;
Jarkko Nikula96579a42016-09-07 17:04:07 +0300922 struct chip_data *chip = spi_get_ctldata(message->spi);
923 u32 dma_thresh = chip->dma_threshold;
924 u32 dma_burst = chip->dma_burst_size;
925 u32 change_mask = pxa2xx_spi_get_ssrc1_change_mask(drv_data);
Jarkko Nikulabffc9672016-09-07 17:04:05 +0300926 u32 clk_div;
927 u8 bits;
928 u32 speed;
Stephen Street9708c122006-03-28 14:05:23 -0800929 u32 cr0;
Stephen Street8d94cc52006-12-10 02:18:54 -0800930 u32 cr1;
Andy Shevchenko7d1f1bf2016-03-24 15:35:42 +0200931 int err;
Jarkko Nikulab6ced292016-06-21 13:21:34 +0300932 int dma_mapped;
Stephen Streete0c99052006-03-07 23:53:24 -0800933
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200934 /* Check if we can DMA this transfer */
Jarkko Nikulab6ced292016-06-21 13:21:34 +0300935 if (transfer->len > MAX_DMA_LEN && chip->enable_dma) {
Ned Forrester7e964452008-09-13 02:33:18 -0700936
937 /* reject already-mapped transfers; PIO won't always work */
938 if (message->is_dma_mapped
939 || transfer->rx_dma || transfer->tx_dma) {
940 dev_err(&drv_data->pdev->dev,
Jarkko Nikula8ae55af2018-04-17 17:20:01 +0300941 "Mapped transfer length of %u is greater than %d\n",
Ned Forrester7e964452008-09-13 02:33:18 -0700942 transfer->len, MAX_DMA_LEN);
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300943 return -EINVAL;
Ned Forrester7e964452008-09-13 02:33:18 -0700944 }
945
946 /* warn ... we force this to PIO mode */
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +0300947 dev_warn_ratelimited(&message->spi->dev,
Jarkko Nikula8ae55af2018-04-17 17:20:01 +0300948 "DMA disabled for transfer length %ld greater than %d\n",
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300949 (long)transfer->len, MAX_DMA_LEN);
Stephen Street8d94cc52006-12-10 02:18:54 -0800950 }
951
Stephen Streete0c99052006-03-07 23:53:24 -0800952 /* Setup the transfer state based on the type of transfer */
Mika Westerbergcd7bed02013-01-22 12:26:28 +0200953 if (pxa2xx_spi_flush(drv_data) == 0) {
Jarkko Nikula8ae55af2018-04-17 17:20:01 +0300954 dev_err(&drv_data->pdev->dev, "Flush failed\n");
Jarkko Nikulad5898e12018-04-17 17:20:02 +0300955 return -EIO;
Stephen Streete0c99052006-03-07 23:53:24 -0800956 }
Stephen Street9708c122006-03-28 14:05:23 -0800957 drv_data->n_bytes = chip->n_bytes;
Stephen Streete0c99052006-03-07 23:53:24 -0800958 drv_data->tx = (void *)transfer->tx_buf;
959 drv_data->tx_end = drv_data->tx + transfer->len;
960 drv_data->rx = transfer->rx_buf;
961 drv_data->rx_end = drv_data->rx + transfer->len;
Stephen Streete0c99052006-03-07 23:53:24 -0800962 drv_data->write = drv_data->tx ? chip->write : null_writer;
963 drv_data->read = drv_data->rx ? chip->read : null_reader;
Stephen Street9708c122006-03-28 14:05:23 -0800964
965 /* Change speed and bit per word on a per transfer */
Jarkko Nikula196b0e22015-09-15 16:26:27 +0300966 bits = transfer->bits_per_word;
967 speed = transfer->speed_hz;
Stephen Street9708c122006-03-28 14:05:23 -0800968
Andy Shevchenkod2c2f6a2015-10-22 16:44:40 +0300969 clk_div = pxa2xx_ssp_get_clk_div(drv_data, speed);
Stephen Street9708c122006-03-28 14:05:23 -0800970
Jarkko Nikula196b0e22015-09-15 16:26:27 +0300971 if (bits <= 8) {
972 drv_data->n_bytes = 1;
973 drv_data->read = drv_data->read != null_reader ?
974 u8_reader : null_reader;
975 drv_data->write = drv_data->write != null_writer ?
976 u8_writer : null_writer;
977 } else if (bits <= 16) {
978 drv_data->n_bytes = 2;
979 drv_data->read = drv_data->read != null_reader ?
980 u16_reader : null_reader;
981 drv_data->write = drv_data->write != null_writer ?
982 u16_writer : null_writer;
983 } else if (bits <= 32) {
984 drv_data->n_bytes = 4;
985 drv_data->read = drv_data->read != null_reader ?
986 u32_reader : null_reader;
987 drv_data->write = drv_data->write != null_writer ?
988 u32_writer : null_writer;
Stephen Street9708c122006-03-28 14:05:23 -0800989 }
Jarkko Nikula196b0e22015-09-15 16:26:27 +0300990 /*
991 * if bits/word is changed in dma mode, then must check the
992 * thresholds and burst also
993 */
994 if (chip->enable_dma) {
995 if (pxa2xx_spi_set_dma_burst_and_threshold(chip,
996 message->spi,
997 bits, &dma_burst,
998 &dma_thresh))
999 dev_warn_ratelimited(&message->spi->dev,
Jarkko Nikula8ae55af2018-04-17 17:20:01 +03001000 "DMA burst size reduced to match bits_per_word\n");
Jarkko Nikula196b0e22015-09-15 16:26:27 +03001001 }
1002
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001003 dma_mapped = master->can_dma &&
1004 master->can_dma(master, message->spi, transfer) &&
1005 master->cur_msg_mapped;
1006 if (dma_mapped) {
Stephen Streete0c99052006-03-07 23:53:24 -08001007
1008 /* Ensure we have the correct interrupt handler */
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001009 drv_data->transfer_handler = pxa2xx_spi_dma_transfer;
Stephen Streete0c99052006-03-07 23:53:24 -08001010
Jarkko Nikulad5898e12018-04-17 17:20:02 +03001011 err = pxa2xx_spi_dma_prepare(drv_data, transfer);
1012 if (err)
1013 return err;
Stephen Streete0c99052006-03-07 23:53:24 -08001014
Stephen Street8d94cc52006-12-10 02:18:54 -08001015 /* Clear status and start DMA engine */
1016 cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1;
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001017 pxa2xx_spi_write(drv_data, SSSR, drv_data->clear_sr);
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001018
1019 pxa2xx_spi_dma_start(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001020 } else {
1021 /* Ensure we have the correct interrupt handler */
1022 drv_data->transfer_handler = interrupt_transfer;
1023
Stephen Street8d94cc52006-12-10 02:18:54 -08001024 /* Clear status */
1025 cr1 = chip->cr1 | chip->threshold | drv_data->int_cr1;
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001026 write_SSSR_CS(drv_data, drv_data->clear_sr);
Stephen Street8d94cc52006-12-10 02:18:54 -08001027 }
1028
Jarkko Nikulaee036722016-01-26 15:33:21 +02001029 /* NOTE: PXA25x_SSP _could_ use external clocking ... */
1030 cr0 = pxa2xx_configure_sscr0(drv_data, clk_div, bits);
1031 if (!pxa25x_ssp_comp(drv_data))
1032 dev_dbg(&message->spi->dev, "%u Hz actual, %s\n",
Jarkko Nikula2d7537d2016-06-21 13:21:33 +03001033 master->max_speed_hz
Jarkko Nikulaee036722016-01-26 15:33:21 +02001034 / (1 + ((cr0 & SSCR0_SCR(0xfff)) >> 8)),
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001035 dma_mapped ? "DMA" : "PIO");
Jarkko Nikulaee036722016-01-26 15:33:21 +02001036 else
1037 dev_dbg(&message->spi->dev, "%u Hz actual, %s\n",
Jarkko Nikula2d7537d2016-06-21 13:21:33 +03001038 master->max_speed_hz / 2
Jarkko Nikulaee036722016-01-26 15:33:21 +02001039 / (1 + ((cr0 & SSCR0_SCR(0x0ff)) >> 8)),
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001040 dma_mapped ? "DMA" : "PIO");
Jarkko Nikulaee036722016-01-26 15:33:21 +02001041
Mika Westerberga0d26422013-01-22 12:26:32 +02001042 if (is_lpss_ssp(drv_data)) {
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001043 if ((pxa2xx_spi_read(drv_data, SSIRF) & 0xff)
1044 != chip->lpss_rx_threshold)
1045 pxa2xx_spi_write(drv_data, SSIRF,
1046 chip->lpss_rx_threshold);
1047 if ((pxa2xx_spi_read(drv_data, SSITF) & 0xffff)
1048 != chip->lpss_tx_threshold)
1049 pxa2xx_spi_write(drv_data, SSITF,
1050 chip->lpss_tx_threshold);
Mika Westerberga0d26422013-01-22 12:26:32 +02001051 }
1052
Weike Chene5262d02014-11-26 02:35:10 -08001053 if (is_quark_x1000_ssp(drv_data) &&
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001054 (pxa2xx_spi_read(drv_data, DDS_RATE) != chip->dds_rate))
1055 pxa2xx_spi_write(drv_data, DDS_RATE, chip->dds_rate);
Weike Chene5262d02014-11-26 02:35:10 -08001056
Stephen Street8d94cc52006-12-10 02:18:54 -08001057 /* see if we need to reload the config registers */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001058 if ((pxa2xx_spi_read(drv_data, SSCR0) != cr0)
1059 || (pxa2xx_spi_read(drv_data, SSCR1) & change_mask)
1060 != (cr1 & change_mask)) {
Ned Forresterb97c74b2008-02-23 15:23:40 -08001061 /* stop the SSP, and update the other bits */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001062 pxa2xx_spi_write(drv_data, SSCR0, cr0 & ~SSCR0_SSE);
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001063 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001064 pxa2xx_spi_write(drv_data, SSTO, chip->timeout);
Ned Forresterb97c74b2008-02-23 15:23:40 -08001065 /* first set CR1 without interrupt and service enables */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001066 pxa2xx_spi_write(drv_data, SSCR1, cr1 & change_mask);
Ned Forresterb97c74b2008-02-23 15:23:40 -08001067 /* restart the SSP */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001068 pxa2xx_spi_write(drv_data, SSCR0, cr0);
Ned Forresterb97c74b2008-02-23 15:23:40 -08001069
Stephen Street8d94cc52006-12-10 02:18:54 -08001070 } else {
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001071 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001072 pxa2xx_spi_write(drv_data, SSTO, chip->timeout);
Stephen Streete0c99052006-03-07 23:53:24 -08001073 }
Ned Forresterb97c74b2008-02-23 15:23:40 -08001074
Jarkko Nikulad5898e12018-04-17 17:20:02 +03001075 /*
1076 * Release the data by enabling service requests and interrupts,
1077 * without changing any mode bits
1078 */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001079 pxa2xx_spi_write(drv_data, SSCR1, cr1);
Jarkko Nikulad5898e12018-04-17 17:20:02 +03001080
1081 return 1;
Stephen Streete0c99052006-03-07 23:53:24 -08001082}
1083
Jarkko Nikulad5898e12018-04-17 17:20:02 +03001084static void pxa2xx_spi_handle_err(struct spi_controller *master,
1085 struct spi_message *msg)
Stephen Streete0c99052006-03-07 23:53:24 -08001086{
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001087 struct driver_data *drv_data = spi_controller_get_devdata(master);
Stephen Streete0c99052006-03-07 23:53:24 -08001088
Jarkko Nikulad5898e12018-04-17 17:20:02 +03001089 /* Disable the SSP */
1090 pxa2xx_spi_write(drv_data, SSCR0,
1091 pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
1092 /* Clear and disable interrupts and service requests */
1093 write_SSSR_CS(drv_data, drv_data->clear_sr);
1094 pxa2xx_spi_write(drv_data, SSCR1,
1095 pxa2xx_spi_read(drv_data, SSCR1)
1096 & ~(drv_data->int_cr1 | drv_data->dma_cr1));
1097 if (!pxa25x_ssp_comp(drv_data))
1098 pxa2xx_spi_write(drv_data, SSTO, 0);
Stephen Streete0c99052006-03-07 23:53:24 -08001099
Jarkko Nikulad5898e12018-04-17 17:20:02 +03001100 /*
1101 * Stop the DMA if running. Note DMA callback handler may have unset
1102 * the dma_running already, which is fine as stopping is not needed
1103 * then but we shouldn't rely this flag for anything else than
1104 * stopping. For instance to differentiate between PIO and DMA
1105 * transfers.
1106 */
1107 if (atomic_read(&drv_data->dma_running))
1108 pxa2xx_spi_dma_stop(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001109}
1110
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001111static int pxa2xx_spi_unprepare_transfer(struct spi_controller *master)
Mika Westerberg7d94a502013-01-22 12:26:30 +02001112{
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001113 struct driver_data *drv_data = spi_controller_get_devdata(master);
Mika Westerberg7d94a502013-01-22 12:26:30 +02001114
1115 /* Disable the SSP now */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001116 pxa2xx_spi_write(drv_data, SSCR0,
1117 pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
Mika Westerberg7d94a502013-01-22 12:26:30 +02001118
Mika Westerberg7d94a502013-01-22 12:26:30 +02001119 return 0;
1120}
1121
Eric Miaoa7bb3902009-04-06 19:00:54 -07001122static int setup_cs(struct spi_device *spi, struct chip_data *chip,
1123 struct pxa2xx_spi_chip *chip_info)
1124{
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001125 struct driver_data *drv_data =
1126 spi_controller_get_devdata(spi->controller);
Jan Kiszkac18d9252017-08-03 13:40:32 +02001127 struct gpio_desc *gpiod;
Eric Miaoa7bb3902009-04-06 19:00:54 -07001128 int err = 0;
1129
Mika Westerberg99f499c2016-09-26 15:19:50 +03001130 if (chip == NULL)
1131 return 0;
1132
Andy Shevchenko6ac5a432017-07-27 14:37:08 +03001133 if (drv_data->cs_gpiods) {
Andy Shevchenko6ac5a432017-07-27 14:37:08 +03001134 gpiod = drv_data->cs_gpiods[spi->chip_select];
1135 if (gpiod) {
Jan Kiszkac18d9252017-08-03 13:40:32 +02001136 chip->gpiod_cs = gpiod;
Andy Shevchenko6ac5a432017-07-27 14:37:08 +03001137 chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
1138 gpiod_set_value(gpiod, chip->gpio_cs_inverted);
Mika Westerberg99f499c2016-09-26 15:19:50 +03001139 }
1140
1141 return 0;
1142 }
1143
1144 if (chip_info == NULL)
Eric Miaoa7bb3902009-04-06 19:00:54 -07001145 return 0;
1146
1147 /* NOTE: setup() can be called multiple times, possibly with
1148 * different chip_info, release previously requested GPIO
1149 */
Jan Kiszkac18d9252017-08-03 13:40:32 +02001150 if (chip->gpiod_cs) {
Mark Browna885eeb2017-12-22 16:15:36 +00001151 gpiod_put(chip->gpiod_cs);
Jan Kiszkac18d9252017-08-03 13:40:32 +02001152 chip->gpiod_cs = NULL;
1153 }
Eric Miaoa7bb3902009-04-06 19:00:54 -07001154
1155 /* If (*cs_control) is provided, ignore GPIO chip select */
1156 if (chip_info->cs_control) {
1157 chip->cs_control = chip_info->cs_control;
1158 return 0;
1159 }
1160
1161 if (gpio_is_valid(chip_info->gpio_cs)) {
1162 err = gpio_request(chip_info->gpio_cs, "SPI_CS");
1163 if (err) {
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +03001164 dev_err(&spi->dev, "failed to request chip select GPIO%d\n",
1165 chip_info->gpio_cs);
Eric Miaoa7bb3902009-04-06 19:00:54 -07001166 return err;
1167 }
1168
Jan Kiszkac18d9252017-08-03 13:40:32 +02001169 gpiod = gpio_to_desc(chip_info->gpio_cs);
1170 chip->gpiod_cs = gpiod;
Eric Miaoa7bb3902009-04-06 19:00:54 -07001171 chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
1172
Jan Kiszkac18d9252017-08-03 13:40:32 +02001173 err = gpiod_direction_output(gpiod, !chip->gpio_cs_inverted);
Eric Miaoa7bb3902009-04-06 19:00:54 -07001174 }
1175
1176 return err;
1177}
1178
Stephen Streete0c99052006-03-07 23:53:24 -08001179static int setup(struct spi_device *spi)
1180{
Jarkko Nikulabffc9672016-09-07 17:04:05 +03001181 struct pxa2xx_spi_chip *chip_info;
Stephen Streete0c99052006-03-07 23:53:24 -08001182 struct chip_data *chip;
Jarkko Nikuladccf7362015-06-04 16:55:11 +03001183 const struct lpss_config *config;
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001184 struct driver_data *drv_data =
1185 spi_controller_get_devdata(spi->controller);
Mika Westerberga0d26422013-01-22 12:26:32 +02001186 uint tx_thres, tx_hi_thres, rx_thres;
1187
Weike Chene5262d02014-11-26 02:35:10 -08001188 switch (drv_data->ssp_type) {
1189 case QUARK_X1000_SSP:
1190 tx_thres = TX_THRESH_QUARK_X1000_DFLT;
1191 tx_hi_thres = 0;
1192 rx_thres = RX_THRESH_QUARK_X1000_DFLT;
1193 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001194 case CE4100_SSP:
1195 tx_thres = TX_THRESH_CE4100_DFLT;
1196 tx_hi_thres = 0;
1197 rx_thres = RX_THRESH_CE4100_DFLT;
1198 break;
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001199 case LPSS_LPT_SSP:
1200 case LPSS_BYT_SSP:
Mika Westerberg30f3a6a2016-02-08 17:14:31 +02001201 case LPSS_BSW_SSP:
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001202 case LPSS_SPT_SSP:
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +02001203 case LPSS_BXT_SSP:
Jarkko Nikulafc0b2ac2017-05-30 17:31:21 +03001204 case LPSS_CNL_SSP:
Jarkko Nikuladccf7362015-06-04 16:55:11 +03001205 config = lpss_get_config(drv_data);
1206 tx_thres = config->tx_threshold_lo;
1207 tx_hi_thres = config->tx_threshold_hi;
1208 rx_thres = config->rx_threshold;
Weike Chene5262d02014-11-26 02:35:10 -08001209 break;
1210 default:
Mika Westerberga0d26422013-01-22 12:26:32 +02001211 tx_thres = TX_THRESH_DFLT;
1212 tx_hi_thres = 0;
1213 rx_thres = RX_THRESH_DFLT;
Weike Chene5262d02014-11-26 02:35:10 -08001214 break;
Mika Westerberga0d26422013-01-22 12:26:32 +02001215 }
Stephen Streete0c99052006-03-07 23:53:24 -08001216
Stephen Street8d94cc52006-12-10 02:18:54 -08001217 /* Only alloc on first setup */
Stephen Streete0c99052006-03-07 23:53:24 -08001218 chip = spi_get_ctldata(spi);
Stephen Street8d94cc52006-12-10 02:18:54 -08001219 if (!chip) {
Stephen Streete0c99052006-03-07 23:53:24 -08001220 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
Jingoo Han9deae452014-04-29 17:19:38 +09001221 if (!chip)
Stephen Streete0c99052006-03-07 23:53:24 -08001222 return -ENOMEM;
1223
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001224 if (drv_data->ssp_type == CE4100_SSP) {
1225 if (spi->chip_select > 4) {
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +03001226 dev_err(&spi->dev,
1227 "failed setup: cs number must not be > 4.\n");
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001228 kfree(chip);
1229 return -EINVAL;
1230 }
1231
1232 chip->frm = spi->chip_select;
Jan Kiszkac18d9252017-08-03 13:40:32 +02001233 }
Dan O'Donovanc64e1262016-05-27 19:57:48 +01001234 chip->enable_dma = drv_data->master_info->enable_dma;
Vernon Sauderf1f640a2008-10-15 22:02:43 -07001235 chip->timeout = TIMOUT_DFLT;
Stephen Streete0c99052006-03-07 23:53:24 -08001236 }
1237
Stephen Street8d94cc52006-12-10 02:18:54 -08001238 /* protocol drivers may change the chip settings, so...
1239 * if chip_info exists, use it */
1240 chip_info = spi->controller_data;
1241
Stephen Streete0c99052006-03-07 23:53:24 -08001242 /* chip_info isn't always needed */
Stephen Street8d94cc52006-12-10 02:18:54 -08001243 chip->cr1 = 0;
Stephen Streete0c99052006-03-07 23:53:24 -08001244 if (chip_info) {
Vernon Sauderf1f640a2008-10-15 22:02:43 -07001245 if (chip_info->timeout)
1246 chip->timeout = chip_info->timeout;
1247 if (chip_info->tx_threshold)
1248 tx_thres = chip_info->tx_threshold;
Mika Westerberga0d26422013-01-22 12:26:32 +02001249 if (chip_info->tx_hi_threshold)
1250 tx_hi_thres = chip_info->tx_hi_threshold;
Vernon Sauderf1f640a2008-10-15 22:02:43 -07001251 if (chip_info->rx_threshold)
1252 rx_thres = chip_info->rx_threshold;
Stephen Streete0c99052006-03-07 23:53:24 -08001253 chip->dma_threshold = 0;
Stephen Streete0c99052006-03-07 23:53:24 -08001254 if (chip_info->enable_loopback)
1255 chip->cr1 = SSCR1_LBM;
1256 }
1257
Mika Westerberga0d26422013-01-22 12:26:32 +02001258 chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres);
1259 chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres)
1260 | SSITF_TxHiThresh(tx_hi_thres);
1261
Stephen Street8d94cc52006-12-10 02:18:54 -08001262 /* set dma burst and threshold outside of chip_info path so that if
1263 * chip_info goes away after setting chip->enable_dma, the
1264 * burst and threshold can still respond to changes in bits_per_word */
1265 if (chip->enable_dma) {
1266 /* set up legal burst and threshold for dma */
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001267 if (pxa2xx_spi_set_dma_burst_and_threshold(chip, spi,
1268 spi->bits_per_word,
Stephen Street8d94cc52006-12-10 02:18:54 -08001269 &chip->dma_burst_size,
1270 &chip->dma_threshold)) {
Jarkko Nikulaf6bd03a2013-10-11 13:54:00 +03001271 dev_warn(&spi->dev,
1272 "in setup: DMA burst size reduced to match bits_per_word\n");
Stephen Street8d94cc52006-12-10 02:18:54 -08001273 }
1274 }
1275
Weike Chene5262d02014-11-26 02:35:10 -08001276 switch (drv_data->ssp_type) {
1277 case QUARK_X1000_SSP:
1278 chip->threshold = (QUARK_X1000_SSCR1_RxTresh(rx_thres)
1279 & QUARK_X1000_SSCR1_RFT)
1280 | (QUARK_X1000_SSCR1_TxTresh(tx_thres)
1281 & QUARK_X1000_SSCR1_TFT);
1282 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001283 case CE4100_SSP:
1284 chip->threshold = (CE4100_SSCR1_RxTresh(rx_thres) & CE4100_SSCR1_RFT) |
1285 (CE4100_SSCR1_TxTresh(tx_thres) & CE4100_SSCR1_TFT);
1286 break;
Weike Chene5262d02014-11-26 02:35:10 -08001287 default:
1288 chip->threshold = (SSCR1_RxTresh(rx_thres) & SSCR1_RFT) |
1289 (SSCR1_TxTresh(tx_thres) & SSCR1_TFT);
1290 break;
1291 }
1292
Justin Clacherty7f6ee1a2007-01-26 00:56:44 -08001293 chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
1294 chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)
1295 | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);
Stephen Streete0c99052006-03-07 23:53:24 -08001296
Mika Westerbergb8331722013-01-22 12:26:31 +02001297 if (spi->mode & SPI_LOOP)
1298 chip->cr1 |= SSCR1_LBM;
1299
Stephen Streete0c99052006-03-07 23:53:24 -08001300 if (spi->bits_per_word <= 8) {
1301 chip->n_bytes = 1;
Stephen Streete0c99052006-03-07 23:53:24 -08001302 chip->read = u8_reader;
1303 chip->write = u8_writer;
1304 } else if (spi->bits_per_word <= 16) {
1305 chip->n_bytes = 2;
Stephen Streete0c99052006-03-07 23:53:24 -08001306 chip->read = u16_reader;
1307 chip->write = u16_writer;
1308 } else if (spi->bits_per_word <= 32) {
Stephen Streete0c99052006-03-07 23:53:24 -08001309 chip->n_bytes = 4;
Stephen Streete0c99052006-03-07 23:53:24 -08001310 chip->read = u32_reader;
1311 chip->write = u32_writer;
Stephen Streete0c99052006-03-07 23:53:24 -08001312 }
Stephen Streete0c99052006-03-07 23:53:24 -08001313
1314 spi_set_ctldata(spi, chip);
1315
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001316 if (drv_data->ssp_type == CE4100_SSP)
1317 return 0;
1318
Eric Miaoa7bb3902009-04-06 19:00:54 -07001319 return setup_cs(spi, chip, chip_info);
Stephen Streete0c99052006-03-07 23:53:24 -08001320}
1321
Hans-Peter Nilsson0ffa0282007-02-12 00:52:45 -08001322static void cleanup(struct spi_device *spi)
Stephen Streete0c99052006-03-07 23:53:24 -08001323{
Hans-Peter Nilsson0ffa0282007-02-12 00:52:45 -08001324 struct chip_data *chip = spi_get_ctldata(spi);
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001325 struct driver_data *drv_data =
1326 spi_controller_get_devdata(spi->controller);
Stephen Streete0c99052006-03-07 23:53:24 -08001327
Daniel Ribeiro7348d822009-05-12 13:19:36 -07001328 if (!chip)
1329 return;
1330
Andy Shevchenko6ac5a432017-07-27 14:37:08 +03001331 if (drv_data->ssp_type != CE4100_SSP && !drv_data->cs_gpiods &&
Jan Kiszkac18d9252017-08-03 13:40:32 +02001332 chip->gpiod_cs)
Mark Browna885eeb2017-12-22 16:15:36 +00001333 gpiod_put(chip->gpiod_cs);
Eric Miaoa7bb3902009-04-06 19:00:54 -07001334
Stephen Streete0c99052006-03-07 23:53:24 -08001335 kfree(chip);
1336}
1337
Jarkko Nikula0db64212015-10-28 15:13:43 +02001338#ifdef CONFIG_PCI
Mika Westerberga3496852013-01-22 12:26:33 +02001339#ifdef CONFIG_ACPI
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001340
Mathias Krause8422ddf2015-06-13 14:22:14 +02001341static const struct acpi_device_id pxa2xx_spi_acpi_match[] = {
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001342 { "INT33C0", LPSS_LPT_SSP },
1343 { "INT33C1", LPSS_LPT_SSP },
1344 { "INT3430", LPSS_LPT_SSP },
1345 { "INT3431", LPSS_LPT_SSP },
1346 { "80860F0E", LPSS_BYT_SSP },
Mika Westerberg30f3a6a2016-02-08 17:14:31 +02001347 { "8086228E", LPSS_BSW_SSP },
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001348 { },
1349};
1350MODULE_DEVICE_TABLE(acpi, pxa2xx_spi_acpi_match);
1351
Jarkko Nikula0db64212015-10-28 15:13:43 +02001352static int pxa2xx_spi_get_port_id(struct acpi_device *adev)
1353{
1354 unsigned int devid;
1355 int port_id = -1;
1356
1357 if (adev && adev->pnp.unique_id &&
1358 !kstrtouint(adev->pnp.unique_id, 0, &devid))
1359 port_id = devid;
1360 return port_id;
1361}
1362#else /* !CONFIG_ACPI */
1363static int pxa2xx_spi_get_port_id(struct acpi_device *adev)
1364{
1365 return -1;
1366}
1367#endif
1368
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001369/*
1370 * PCI IDs of compound devices that integrate both host controller and private
1371 * integrated DMA engine. Please note these are not used in module
1372 * autoloading and probing in this module but matching the LPSS SSP type.
1373 */
1374static const struct pci_device_id pxa2xx_spi_pci_compound_match[] = {
1375 /* SPT-LP */
1376 { PCI_VDEVICE(INTEL, 0x9d29), LPSS_SPT_SSP },
1377 { PCI_VDEVICE(INTEL, 0x9d2a), LPSS_SPT_SSP },
1378 /* SPT-H */
1379 { PCI_VDEVICE(INTEL, 0xa129), LPSS_SPT_SSP },
1380 { PCI_VDEVICE(INTEL, 0xa12a), LPSS_SPT_SSP },
Mika Westerberg704d2b02016-07-04 13:21:07 +03001381 /* KBL-H */
1382 { PCI_VDEVICE(INTEL, 0xa2a9), LPSS_SPT_SSP },
1383 { PCI_VDEVICE(INTEL, 0xa2aa), LPSS_SPT_SSP },
Jarkko Nikulac1b03f12016-03-02 09:54:14 +02001384 /* BXT A-Step */
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +02001385 { PCI_VDEVICE(INTEL, 0x0ac2), LPSS_BXT_SSP },
1386 { PCI_VDEVICE(INTEL, 0x0ac4), LPSS_BXT_SSP },
1387 { PCI_VDEVICE(INTEL, 0x0ac6), LPSS_BXT_SSP },
Jarkko Nikulac1b03f12016-03-02 09:54:14 +02001388 /* BXT B-Step */
1389 { PCI_VDEVICE(INTEL, 0x1ac2), LPSS_BXT_SSP },
1390 { PCI_VDEVICE(INTEL, 0x1ac4), LPSS_BXT_SSP },
1391 { PCI_VDEVICE(INTEL, 0x1ac6), LPSS_BXT_SSP },
David E. Boxe18a80a2017-01-19 16:25:21 +02001392 /* GLK */
1393 { PCI_VDEVICE(INTEL, 0x31c2), LPSS_BXT_SSP },
1394 { PCI_VDEVICE(INTEL, 0x31c4), LPSS_BXT_SSP },
1395 { PCI_VDEVICE(INTEL, 0x31c6), LPSS_BXT_SSP },
Mika Westerberg22d71a502018-06-28 13:52:23 +03001396 /* ICL-LP */
1397 { PCI_VDEVICE(INTEL, 0x34aa), LPSS_CNL_SSP },
1398 { PCI_VDEVICE(INTEL, 0x34ab), LPSS_CNL_SSP },
1399 { PCI_VDEVICE(INTEL, 0x34fb), LPSS_CNL_SSP },
Jarkko Nikulab7c08cf2015-10-28 15:13:42 +02001400 /* APL */
1401 { PCI_VDEVICE(INTEL, 0x5ac2), LPSS_BXT_SSP },
1402 { PCI_VDEVICE(INTEL, 0x5ac4), LPSS_BXT_SSP },
1403 { PCI_VDEVICE(INTEL, 0x5ac6), LPSS_BXT_SSP },
Jarkko Nikulafc0b2ac2017-05-30 17:31:21 +03001404 /* CNL-LP */
1405 { PCI_VDEVICE(INTEL, 0x9daa), LPSS_CNL_SSP },
1406 { PCI_VDEVICE(INTEL, 0x9dab), LPSS_CNL_SSP },
1407 { PCI_VDEVICE(INTEL, 0x9dfb), LPSS_CNL_SSP },
1408 /* CNL-H */
1409 { PCI_VDEVICE(INTEL, 0xa32a), LPSS_CNL_SSP },
1410 { PCI_VDEVICE(INTEL, 0xa32b), LPSS_CNL_SSP },
1411 { PCI_VDEVICE(INTEL, 0xa37b), LPSS_CNL_SSP },
Axel Lin94e5c232015-08-04 13:52:22 +08001412 { },
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001413};
1414
1415static bool pxa2xx_spi_idma_filter(struct dma_chan *chan, void *param)
1416{
1417 struct device *dev = param;
1418
1419 if (dev != chan->device->dev->parent)
1420 return false;
1421
1422 return true;
1423}
1424
Mika Westerberga3496852013-01-22 12:26:33 +02001425static struct pxa2xx_spi_master *
Jarkko Nikula0db64212015-10-28 15:13:43 +02001426pxa2xx_spi_init_pdata(struct platform_device *pdev)
Mika Westerberga3496852013-01-22 12:26:33 +02001427{
1428 struct pxa2xx_spi_master *pdata;
Mika Westerberga3496852013-01-22 12:26:33 +02001429 struct acpi_device *adev;
1430 struct ssp_device *ssp;
1431 struct resource *res;
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001432 const struct acpi_device_id *adev_id = NULL;
1433 const struct pci_device_id *pcidev_id = NULL;
Jarkko Nikula3b8b6d02015-10-22 16:44:41 +03001434 int type;
Mika Westerberga3496852013-01-22 12:26:33 +02001435
Jarkko Nikulab9f69402015-09-25 10:27:18 +03001436 adev = ACPI_COMPANION(&pdev->dev);
Mika Westerberga3496852013-01-22 12:26:33 +02001437
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001438 if (dev_is_pci(pdev->dev.parent))
1439 pcidev_id = pci_match_id(pxa2xx_spi_pci_compound_match,
1440 to_pci_dev(pdev->dev.parent));
Jarkko Nikula0db64212015-10-28 15:13:43 +02001441 else if (adev)
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001442 adev_id = acpi_match_device(pdev->dev.driver->acpi_match_table,
1443 &pdev->dev);
Jarkko Nikula0db64212015-10-28 15:13:43 +02001444 else
1445 return NULL;
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001446
1447 if (adev_id)
1448 type = (int)adev_id->driver_data;
1449 else if (pcidev_id)
1450 type = (int)pcidev_id->driver_data;
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001451 else
1452 return NULL;
1453
Mika Westerbergcc0ee982013-06-20 17:44:22 +03001454 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
Jingoo Han9deae452014-04-29 17:19:38 +09001455 if (!pdata)
Mika Westerberga3496852013-01-22 12:26:33 +02001456 return NULL;
Mika Westerberga3496852013-01-22 12:26:33 +02001457
1458 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1459 if (!res)
1460 return NULL;
1461
1462 ssp = &pdata->ssp;
1463
1464 ssp->phys_base = res->start;
Sachin Kamatcbfd6a22013-04-08 15:49:33 +05301465 ssp->mmio_base = devm_ioremap_resource(&pdev->dev, res);
1466 if (IS_ERR(ssp->mmio_base))
Mika Westerberg6dc81f62013-05-13 13:45:09 +03001467 return NULL;
Mika Westerberga3496852013-01-22 12:26:33 +02001468
Jarkko Nikula34cadd92015-07-30 16:30:07 +03001469 if (pcidev_id) {
1470 pdata->tx_param = pdev->dev.parent;
1471 pdata->rx_param = pdev->dev.parent;
1472 pdata->dma_filter = pxa2xx_spi_idma_filter;
1473 }
1474
Mika Westerberga3496852013-01-22 12:26:33 +02001475 ssp->clk = devm_clk_get(&pdev->dev, NULL);
1476 ssp->irq = platform_get_irq(pdev, 0);
Jarkko Nikula03fbf482015-06-04 16:55:10 +03001477 ssp->type = type;
Mika Westerberga3496852013-01-22 12:26:33 +02001478 ssp->pdev = pdev;
Jarkko Nikula0db64212015-10-28 15:13:43 +02001479 ssp->port_id = pxa2xx_spi_get_port_id(adev);
Mika Westerberga3496852013-01-22 12:26:33 +02001480
1481 pdata->num_chipselect = 1;
Mika Westerbergcddb3392013-05-13 13:45:10 +03001482 pdata->enable_dma = true;
Mika Westerberga3496852013-01-22 12:26:33 +02001483
1484 return pdata;
1485}
1486
Jarkko Nikula0db64212015-10-28 15:13:43 +02001487#else /* !CONFIG_PCI */
Mika Westerberga3496852013-01-22 12:26:33 +02001488static inline struct pxa2xx_spi_master *
Jarkko Nikula0db64212015-10-28 15:13:43 +02001489pxa2xx_spi_init_pdata(struct platform_device *pdev)
Mika Westerberga3496852013-01-22 12:26:33 +02001490{
1491 return NULL;
1492}
1493#endif
1494
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001495static int pxa2xx_spi_fw_translate_cs(struct spi_controller *master,
1496 unsigned int cs)
Mika Westerberg0c27d9c2016-02-08 17:14:29 +02001497{
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001498 struct driver_data *drv_data = spi_controller_get_devdata(master);
Mika Westerberg0c27d9c2016-02-08 17:14:29 +02001499
1500 if (has_acpi_companion(&drv_data->pdev->dev)) {
1501 switch (drv_data->ssp_type) {
1502 /*
1503 * For Atoms the ACPI DeviceSelection used by the Windows
1504 * driver starts from 1 instead of 0 so translate it here
1505 * to match what Linux expects.
1506 */
1507 case LPSS_BYT_SSP:
Mika Westerberg30f3a6a2016-02-08 17:14:31 +02001508 case LPSS_BSW_SSP:
Mika Westerberg0c27d9c2016-02-08 17:14:29 +02001509 return cs - 1;
1510
1511 default:
1512 break;
1513 }
1514 }
1515
1516 return cs;
1517}
1518
Grant Likelyfd4a3192012-12-07 16:57:14 +00001519static int pxa2xx_spi_probe(struct platform_device *pdev)
Stephen Streete0c99052006-03-07 23:53:24 -08001520{
1521 struct device *dev = &pdev->dev;
1522 struct pxa2xx_spi_master *platform_info;
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001523 struct spi_controller *master;
Guennadi Liakhovetski65a00a22008-10-15 22:02:42 -07001524 struct driver_data *drv_data;
eric miao2f1a74e2007-11-21 18:50:53 +08001525 struct ssp_device *ssp;
Jarkko Nikula8b136ba2015-10-28 15:13:41 +02001526 const struct lpss_config *config;
Mika Westerberg99f499c2016-09-26 15:19:50 +03001527 int status, count;
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001528 u32 tmp;
Stephen Streete0c99052006-03-07 23:53:24 -08001529
Mika Westerberg851bacf2013-01-07 12:44:33 +02001530 platform_info = dev_get_platdata(dev);
1531 if (!platform_info) {
Jarkko Nikula0db64212015-10-28 15:13:43 +02001532 platform_info = pxa2xx_spi_init_pdata(pdev);
Mika Westerberga3496852013-01-22 12:26:33 +02001533 if (!platform_info) {
1534 dev_err(&pdev->dev, "missing platform data\n");
1535 return -ENODEV;
1536 }
Mika Westerberg851bacf2013-01-07 12:44:33 +02001537 }
Stephen Streete0c99052006-03-07 23:53:24 -08001538
Haojian Zhuangbaffe162010-05-05 10:11:15 -04001539 ssp = pxa_ssp_request(pdev->id, pdev->name);
Mika Westerberg851bacf2013-01-07 12:44:33 +02001540 if (!ssp)
1541 ssp = &platform_info->ssp;
1542
1543 if (!ssp->mmio_base) {
1544 dev_err(&pdev->dev, "failed to get ssp\n");
Stephen Streete0c99052006-03-07 23:53:24 -08001545 return -ENODEV;
1546 }
1547
Jarkko Nikula757fe8d2015-08-05 10:04:05 +03001548 master = spi_alloc_master(dev, sizeof(struct driver_data));
Stephen Streete0c99052006-03-07 23:53:24 -08001549 if (!master) {
Guennadi Liakhovetski65a00a22008-10-15 22:02:42 -07001550 dev_err(&pdev->dev, "cannot alloc spi_master\n");
Haojian Zhuangbaffe162010-05-05 10:11:15 -04001551 pxa_ssp_free(ssp);
Stephen Streete0c99052006-03-07 23:53:24 -08001552 return -ENOMEM;
1553 }
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001554 drv_data = spi_controller_get_devdata(master);
Stephen Streete0c99052006-03-07 23:53:24 -08001555 drv_data->master = master;
1556 drv_data->master_info = platform_info;
1557 drv_data->pdev = pdev;
eric miao2f1a74e2007-11-21 18:50:53 +08001558 drv_data->ssp = ssp;
Stephen Streete0c99052006-03-07 23:53:24 -08001559
Sebastian Andrzej Siewior21486af2010-10-08 18:11:19 +02001560 master->dev.of_node = pdev->dev.of_node;
David Brownelle7db06b2009-06-17 16:26:04 -07001561 /* the spi->mode bits understood by this driver: */
Mika Westerbergb8331722013-01-22 12:26:31 +02001562 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
David Brownelle7db06b2009-06-17 16:26:04 -07001563
Mika Westerberg851bacf2013-01-07 12:44:33 +02001564 master->bus_num = ssp->port_id;
Mike Rapoport7ad0ba92009-04-06 19:00:57 -07001565 master->dma_alignment = DMA_ALIGNMENT;
Stephen Streete0c99052006-03-07 23:53:24 -08001566 master->cleanup = cleanup;
1567 master->setup = setup;
Jarkko Nikulad5898e12018-04-17 17:20:02 +03001568 master->set_cs = pxa2xx_spi_set_cs;
1569 master->transfer_one = pxa2xx_spi_transfer_one;
1570 master->handle_err = pxa2xx_spi_handle_err;
Mika Westerberg7d94a502013-01-22 12:26:30 +02001571 master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer;
Mika Westerberg0c27d9c2016-02-08 17:14:29 +02001572 master->fw_translate_cs = pxa2xx_spi_fw_translate_cs;
Mark Brown7dd62782013-07-28 15:35:21 +01001573 master->auto_runtime_pm = true;
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001574 master->flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX;
Stephen Streete0c99052006-03-07 23:53:24 -08001575
eric miao2f1a74e2007-11-21 18:50:53 +08001576 drv_data->ssp_type = ssp->type;
Stephen Streete0c99052006-03-07 23:53:24 -08001577
eric miao2f1a74e2007-11-21 18:50:53 +08001578 drv_data->ioaddr = ssp->mmio_base;
1579 drv_data->ssdr_physical = ssp->phys_base + SSDR;
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001580 if (pxa25x_ssp_comp(drv_data)) {
Weike Chene5262d02014-11-26 02:35:10 -08001581 switch (drv_data->ssp_type) {
1582 case QUARK_X1000_SSP:
1583 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
1584 break;
1585 default:
1586 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
1587 break;
1588 }
1589
Stephen Streete0c99052006-03-07 23:53:24 -08001590 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE;
1591 drv_data->dma_cr1 = 0;
1592 drv_data->clear_sr = SSSR_ROR;
1593 drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR;
1594 } else {
Stephen Warren24778be2013-05-21 20:36:35 -06001595 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
Stephen Streete0c99052006-03-07 23:53:24 -08001596 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE;
Mika Westerberg59288082013-01-22 12:26:29 +02001597 drv_data->dma_cr1 = DEFAULT_DMA_CR1;
Stephen Streete0c99052006-03-07 23:53:24 -08001598 drv_data->clear_sr = SSSR_ROR | SSSR_TINT;
1599 drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR;
1600 }
1601
Sebastian Andrzej Siewior49cbb1e2010-11-22 17:12:14 -08001602 status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev),
1603 drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001604 if (status < 0) {
Guennadi Liakhovetski65a00a22008-10-15 22:02:42 -07001605 dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq);
Stephen Streete0c99052006-03-07 23:53:24 -08001606 goto out_error_master_alloc;
1607 }
1608
1609 /* Setup DMA if requested */
Stephen Streete0c99052006-03-07 23:53:24 -08001610 if (platform_info->enable_dma) {
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001611 status = pxa2xx_spi_dma_setup(drv_data);
1612 if (status) {
Mika Westerbergcddb3392013-05-13 13:45:10 +03001613 dev_dbg(dev, "no DMA channels available, using PIO\n");
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001614 platform_info->enable_dma = false;
Jarkko Nikulab6ced292016-06-21 13:21:34 +03001615 } else {
1616 master->can_dma = pxa2xx_spi_can_dma;
Stephen Streete0c99052006-03-07 23:53:24 -08001617 }
Stephen Streete0c99052006-03-07 23:53:24 -08001618 }
1619
1620 /* Enable SOC clock */
Tobias Jordan62bbc862018-04-30 16:30:06 +02001621 status = clk_prepare_enable(ssp->clk);
1622 if (status)
1623 goto out_error_dma_irq_alloc;
Mika Westerberg3343b7a2013-01-22 12:26:27 +02001624
Jarkko Nikula0eca7cf2015-09-25 10:27:17 +03001625 master->max_speed_hz = clk_get_rate(ssp->clk);
Stephen Streete0c99052006-03-07 23:53:24 -08001626
1627 /* Load default SSP configuration */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001628 pxa2xx_spi_write(drv_data, SSCR0, 0);
Weike Chene5262d02014-11-26 02:35:10 -08001629 switch (drv_data->ssp_type) {
1630 case QUARK_X1000_SSP:
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001631 tmp = QUARK_X1000_SSCR1_RxTresh(RX_THRESH_QUARK_X1000_DFLT) |
1632 QUARK_X1000_SSCR1_TxTresh(TX_THRESH_QUARK_X1000_DFLT);
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001633 pxa2xx_spi_write(drv_data, SSCR1, tmp);
Weike Chene5262d02014-11-26 02:35:10 -08001634
1635 /* using the Motorola SPI protocol and use 8 bit frame */
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001636 tmp = QUARK_X1000_SSCR0_Motorola | QUARK_X1000_SSCR0_DataSize(8);
1637 pxa2xx_spi_write(drv_data, SSCR0, tmp);
Weike Chene5262d02014-11-26 02:35:10 -08001638 break;
Andy Shevchenko7c7289a2016-09-07 15:43:22 +03001639 case CE4100_SSP:
1640 tmp = CE4100_SSCR1_RxTresh(RX_THRESH_CE4100_DFLT) |
1641 CE4100_SSCR1_TxTresh(TX_THRESH_CE4100_DFLT);
1642 pxa2xx_spi_write(drv_data, SSCR1, tmp);
1643 tmp = SSCR0_SCR(2) | SSCR0_Motorola | SSCR0_DataSize(8);
1644 pxa2xx_spi_write(drv_data, SSCR0, tmp);
Andy Shevchenkoa2dd8af2017-01-02 13:44:28 +02001645 break;
Weike Chene5262d02014-11-26 02:35:10 -08001646 default:
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001647 tmp = SSCR1_RxTresh(RX_THRESH_DFLT) |
1648 SSCR1_TxTresh(TX_THRESH_DFLT);
1649 pxa2xx_spi_write(drv_data, SSCR1, tmp);
1650 tmp = SSCR0_SCR(2) | SSCR0_Motorola | SSCR0_DataSize(8);
1651 pxa2xx_spi_write(drv_data, SSCR0, tmp);
Weike Chene5262d02014-11-26 02:35:10 -08001652 break;
1653 }
1654
Sebastian Andrzej Siewior2a8626a2010-11-22 17:12:17 -08001655 if (!pxa25x_ssp_comp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001656 pxa2xx_spi_write(drv_data, SSTO, 0);
Weike Chene5262d02014-11-26 02:35:10 -08001657
1658 if (!is_quark_x1000_ssp(drv_data))
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001659 pxa2xx_spi_write(drv_data, SSPSP, 0);
Stephen Streete0c99052006-03-07 23:53:24 -08001660
Jarkko Nikula8b136ba2015-10-28 15:13:41 +02001661 if (is_lpss_ssp(drv_data)) {
1662 lpss_ssp_setup(drv_data);
1663 config = lpss_get_config(drv_data);
1664 if (config->reg_capabilities >= 0) {
1665 tmp = __lpss_ssp_read_priv(drv_data,
1666 config->reg_capabilities);
1667 tmp &= LPSS_CAPS_CS_EN_MASK;
1668 tmp >>= LPSS_CAPS_CS_EN_SHIFT;
1669 platform_info->num_chipselect = ffz(tmp);
Mika Westerberg30f3a6a2016-02-08 17:14:31 +02001670 } else if (config->cs_num) {
1671 platform_info->num_chipselect = config->cs_num;
Jarkko Nikula8b136ba2015-10-28 15:13:41 +02001672 }
1673 }
1674 master->num_chipselect = platform_info->num_chipselect;
1675
Mika Westerberg99f499c2016-09-26 15:19:50 +03001676 count = gpiod_count(&pdev->dev, "cs");
Andy Shevchenko6ac5a432017-07-27 14:37:08 +03001677 if (count > 0) {
1678 int i;
1679
Mika Westerberg99f499c2016-09-26 15:19:50 +03001680 master->num_chipselect = max_t(int, count,
1681 master->num_chipselect);
1682
Andy Shevchenko6ac5a432017-07-27 14:37:08 +03001683 drv_data->cs_gpiods = devm_kcalloc(&pdev->dev,
1684 master->num_chipselect, sizeof(struct gpio_desc *),
1685 GFP_KERNEL);
1686 if (!drv_data->cs_gpiods) {
1687 status = -ENOMEM;
1688 goto out_error_clock_enabled;
1689 }
1690
1691 for (i = 0; i < master->num_chipselect; i++) {
1692 struct gpio_desc *gpiod;
1693
Andy Shevchenkod35f2dc2017-07-27 18:49:33 +03001694 gpiod = devm_gpiod_get_index(dev, "cs", i, GPIOD_ASIS);
Andy Shevchenko6ac5a432017-07-27 14:37:08 +03001695 if (IS_ERR(gpiod)) {
1696 /* Means use native chip select */
1697 if (PTR_ERR(gpiod) == -ENOENT)
1698 continue;
1699
1700 status = (int)PTR_ERR(gpiod);
1701 goto out_error_clock_enabled;
1702 } else {
1703 drv_data->cs_gpiods[i] = gpiod;
1704 }
1705 }
1706 }
1707
Antonio Ospite836d1a222014-05-30 18:18:09 +02001708 pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
1709 pm_runtime_use_autosuspend(&pdev->dev);
1710 pm_runtime_set_active(&pdev->dev);
1711 pm_runtime_enable(&pdev->dev);
1712
Stephen Streete0c99052006-03-07 23:53:24 -08001713 /* Register with the SPI framework */
1714 platform_set_drvdata(pdev, drv_data);
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001715 status = devm_spi_register_controller(&pdev->dev, master);
Stephen Streete0c99052006-03-07 23:53:24 -08001716 if (status != 0) {
1717 dev_err(&pdev->dev, "problem registering spi master\n");
Mika Westerberg7f86bde2013-01-22 12:26:26 +02001718 goto out_error_clock_enabled;
Stephen Streete0c99052006-03-07 23:53:24 -08001719 }
1720
1721 return status;
1722
Stephen Streete0c99052006-03-07 23:53:24 -08001723out_error_clock_enabled:
Jarkko Nikulae2b714a2018-03-07 17:05:04 +02001724 pm_runtime_put_noidle(&pdev->dev);
1725 pm_runtime_disable(&pdev->dev);
Mika Westerberg3343b7a2013-01-22 12:26:27 +02001726 clk_disable_unprepare(ssp->clk);
Tobias Jordan62bbc862018-04-30 16:30:06 +02001727
1728out_error_dma_irq_alloc:
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001729 pxa2xx_spi_dma_release(drv_data);
eric miao2f1a74e2007-11-21 18:50:53 +08001730 free_irq(ssp->irq, drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001731
1732out_error_master_alloc:
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001733 spi_controller_put(master);
Haojian Zhuangbaffe162010-05-05 10:11:15 -04001734 pxa_ssp_free(ssp);
Stephen Streete0c99052006-03-07 23:53:24 -08001735 return status;
1736}
1737
1738static int pxa2xx_spi_remove(struct platform_device *pdev)
1739{
1740 struct driver_data *drv_data = platform_get_drvdata(pdev);
Julia Lawall51e911e2009-01-06 14:41:45 -08001741 struct ssp_device *ssp;
Stephen Streete0c99052006-03-07 23:53:24 -08001742
1743 if (!drv_data)
1744 return 0;
Julia Lawall51e911e2009-01-06 14:41:45 -08001745 ssp = drv_data->ssp;
Stephen Streete0c99052006-03-07 23:53:24 -08001746
Mika Westerberg7d94a502013-01-22 12:26:30 +02001747 pm_runtime_get_sync(&pdev->dev);
1748
Stephen Streete0c99052006-03-07 23:53:24 -08001749 /* Disable the SSP at the peripheral and SOC level */
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001750 pxa2xx_spi_write(drv_data, SSCR0, 0);
Mika Westerberg3343b7a2013-01-22 12:26:27 +02001751 clk_disable_unprepare(ssp->clk);
Stephen Streete0c99052006-03-07 23:53:24 -08001752
1753 /* Release DMA */
Mika Westerbergcd7bed02013-01-22 12:26:28 +02001754 if (drv_data->master_info->enable_dma)
1755 pxa2xx_spi_dma_release(drv_data);
Stephen Streete0c99052006-03-07 23:53:24 -08001756
Mika Westerberg7d94a502013-01-22 12:26:30 +02001757 pm_runtime_put_noidle(&pdev->dev);
1758 pm_runtime_disable(&pdev->dev);
1759
Stephen Streete0c99052006-03-07 23:53:24 -08001760 /* Release IRQ */
eric miao2f1a74e2007-11-21 18:50:53 +08001761 free_irq(ssp->irq, drv_data);
1762
1763 /* Release SSP */
Haojian Zhuangbaffe162010-05-05 10:11:15 -04001764 pxa_ssp_free(ssp);
Stephen Streete0c99052006-03-07 23:53:24 -08001765
Stephen Streete0c99052006-03-07 23:53:24 -08001766 return 0;
1767}
1768
Mika Westerberg382cebb2014-01-16 14:50:55 +02001769#ifdef CONFIG_PM_SLEEP
Mike Rapoport86d25932009-07-21 17:50:16 +03001770static int pxa2xx_spi_suspend(struct device *dev)
Stephen Streete0c99052006-03-07 23:53:24 -08001771{
Mike Rapoport86d25932009-07-21 17:50:16 +03001772 struct driver_data *drv_data = dev_get_drvdata(dev);
eric miao2f1a74e2007-11-21 18:50:53 +08001773 struct ssp_device *ssp = drv_data->ssp;
Jarkko Nikulabffc9672016-09-07 17:04:05 +03001774 int status;
Stephen Streete0c99052006-03-07 23:53:24 -08001775
Jarkko Nikula3cc7b0e2018-02-01 17:17:30 +02001776 status = spi_controller_suspend(drv_data->master);
Stephen Streete0c99052006-03-07 23:53:24 -08001777 if (status != 0)
1778 return status;
Jarkko Nikulac039dd22014-12-18 15:04:23 +02001779 pxa2xx_spi_write(drv_data, SSCR0, 0);
Dmitry Eremin-Solenikov2b9375b2014-11-06 14:08:29 +03001780
1781 if (!pm_runtime_suspended(dev))
1782 clk_disable_unprepare(ssp->clk);
Stephen Streete0c99052006-03-07 23:53:24 -08001783
1784 return 0;
1785}
1786
Mike Rapoport86d25932009-07-21 17:50:16 +03001787static int pxa2xx_spi_resume(struct device *dev)
Stephen Streete0c99052006-03-07 23:53:24 -08001788{
Mike Rapoport86d25932009-07-21 17:50:16 +03001789 struct driver_data *drv_data = dev_get_drvdata(dev);
eric miao2f1a74e2007-11-21 18:50:53 +08001790 struct ssp_device *ssp = drv_data->ssp;
Jarkko Nikulabffc9672016-09-07 17:04:05 +03001791 int status;
Stephen Streete0c99052006-03-07 23:53:24 -08001792
1793 /* Enable the SSP clock */
Tobias Jordan62bbc862018-04-30 16:30:06 +02001794 if (!pm_runtime_suspended(dev)) {
1795 status = clk_prepare_enable(ssp->clk);
1796 if (status)
1797 return status;
1798 }
Stephen Streete0c99052006-03-07 23:53:24 -08001799
Chew, Chiau Eec50325f2013-11-29 02:13:11 +08001800 /* Restore LPSS private register bits */
Jarkko Nikula48421ad2015-01-28 10:09:42 +02001801 if (is_lpss_ssp(drv_data))
1802 lpss_ssp_setup(drv_data);
Chew, Chiau Eec50325f2013-11-29 02:13:11 +08001803
Stephen Streete0c99052006-03-07 23:53:24 -08001804 /* Start the queue running */
Geert Uytterhoeven7c5d8a22018-09-05 10:51:57 +02001805 return spi_controller_resume(drv_data->master);
Stephen Streete0c99052006-03-07 23:53:24 -08001806}
Mika Westerberg7d94a502013-01-22 12:26:30 +02001807#endif
1808
Rafael J. Wysockiec833052014-12-13 00:41:15 +01001809#ifdef CONFIG_PM
Mika Westerberg7d94a502013-01-22 12:26:30 +02001810static int pxa2xx_spi_runtime_suspend(struct device *dev)
1811{
1812 struct driver_data *drv_data = dev_get_drvdata(dev);
1813
1814 clk_disable_unprepare(drv_data->ssp->clk);
1815 return 0;
1816}
1817
1818static int pxa2xx_spi_runtime_resume(struct device *dev)
1819{
1820 struct driver_data *drv_data = dev_get_drvdata(dev);
Tobias Jordan62bbc862018-04-30 16:30:06 +02001821 int status;
Mika Westerberg7d94a502013-01-22 12:26:30 +02001822
Tobias Jordan62bbc862018-04-30 16:30:06 +02001823 status = clk_prepare_enable(drv_data->ssp->clk);
1824 return status;
Mika Westerberg7d94a502013-01-22 12:26:30 +02001825}
1826#endif
Mike Rapoport86d25932009-07-21 17:50:16 +03001827
Alexey Dobriyan47145212009-12-14 18:00:08 -08001828static const struct dev_pm_ops pxa2xx_spi_pm_ops = {
Mika Westerberg7d94a502013-01-22 12:26:30 +02001829 SET_SYSTEM_SLEEP_PM_OPS(pxa2xx_spi_suspend, pxa2xx_spi_resume)
1830 SET_RUNTIME_PM_OPS(pxa2xx_spi_runtime_suspend,
1831 pxa2xx_spi_runtime_resume, NULL)
Mike Rapoport86d25932009-07-21 17:50:16 +03001832};
Stephen Streete0c99052006-03-07 23:53:24 -08001833
1834static struct platform_driver driver = {
1835 .driver = {
Mike Rapoport86d25932009-07-21 17:50:16 +03001836 .name = "pxa2xx-spi",
Mike Rapoport86d25932009-07-21 17:50:16 +03001837 .pm = &pxa2xx_spi_pm_ops,
Mika Westerberga3496852013-01-22 12:26:33 +02001838 .acpi_match_table = ACPI_PTR(pxa2xx_spi_acpi_match),
Stephen Streete0c99052006-03-07 23:53:24 -08001839 },
Sebastian Andrzej Siewiorfbd29a12010-11-19 09:00:11 -08001840 .probe = pxa2xx_spi_probe,
David Brownelld1e44d92007-10-16 01:27:46 -07001841 .remove = pxa2xx_spi_remove,
Stephen Streete0c99052006-03-07 23:53:24 -08001842};
1843
1844static int __init pxa2xx_spi_init(void)
1845{
Sebastian Andrzej Siewiorfbd29a12010-11-19 09:00:11 -08001846 return platform_driver_register(&driver);
Stephen Streete0c99052006-03-07 23:53:24 -08001847}
Antonio Ospite5b61a742009-09-22 16:46:10 -07001848subsys_initcall(pxa2xx_spi_init);
Stephen Streete0c99052006-03-07 23:53:24 -08001849
1850static void __exit pxa2xx_spi_exit(void)
1851{
1852 platform_driver_unregister(&driver);
1853}
1854module_exit(pxa2xx_spi_exit);