blob: 2fd8881fcd65c96ca76e5932bb310605a2ff1c49 [file] [log] [blame]
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001/*
2 * OMAP2 McSPI controller driver
3 *
4 * Copyright (C) 2005, 2006 Nokia Corporation
5 * Author: Samuel Ortiz <samuel.ortiz@nokia.com> and
Charulatha V1a5d8192011-02-02 17:52:14 +05306 * Juha Yrj�l� <juha.yrjola@nokia.com>
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070017 */
18
19#include <linux/kernel.h>
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070020#include <linux/interrupt.h>
21#include <linux/module.h>
22#include <linux/device.h>
23#include <linux/delay.h>
24#include <linux/dma-mapping.h>
Russell King53741ed2012-04-23 13:51:48 +010025#include <linux/dmaengine.h>
Pascal Huerstbeca3652015-11-19 16:18:28 +010026#include <linux/pinctrl/consumer.h>
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070027#include <linux/platform_device.h>
28#include <linux/err.h>
29#include <linux/clk.h>
30#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Govindraj.R1f1a4382011-02-02 17:52:15 +053032#include <linux/pm_runtime.h>
Benoit Coussond5a80032012-02-15 18:37:34 +010033#include <linux/of.h>
34#include <linux/of_device.h>
Illia Smyrnovd33f4732013-06-17 16:31:06 +030035#include <linux/gcd.h>
Vignesh R13d515c2018-10-15 12:08:27 +053036#include <linux/iopoll.h>
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070037
38#include <linux/spi/spi.h>
Michael Wellingbc7f9bb2015-05-08 13:31:01 -050039#include <linux/gpio.h>
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070040
Arnd Bergmann22037472012-08-24 15:21:06 +020041#include <linux/platform_data/spi-omap2-mcspi.h>
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070042
43#define OMAP2_MCSPI_MAX_FREQ 48000000
Stefan Sørensenfaee9b02014-02-02 16:24:25 +010044#define OMAP2_MCSPI_MAX_DIVIDER 4096
Illia Smyrnovd33f4732013-06-17 16:31:06 +030045#define OMAP2_MCSPI_MAX_FIFODEPTH 64
46#define OMAP2_MCSPI_MAX_FIFOWCNT 0xFFFF
Shubhrajyoti D27b52842012-03-26 17:04:22 +053047#define SPI_AUTOSUSPEND_TIMEOUT 2000
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070048
49#define OMAP2_MCSPI_REVISION 0x00
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070050#define OMAP2_MCSPI_SYSSTATUS 0x14
51#define OMAP2_MCSPI_IRQSTATUS 0x18
52#define OMAP2_MCSPI_IRQENABLE 0x1c
53#define OMAP2_MCSPI_WAKEUPENABLE 0x20
54#define OMAP2_MCSPI_SYST 0x24
55#define OMAP2_MCSPI_MODULCTRL 0x28
Illia Smyrnovd33f4732013-06-17 16:31:06 +030056#define OMAP2_MCSPI_XFERLEVEL 0x7c
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070057
58/* per-channel banks, 0x14 bytes each, first is: */
59#define OMAP2_MCSPI_CHCONF0 0x2c
60#define OMAP2_MCSPI_CHSTAT0 0x30
61#define OMAP2_MCSPI_CHCTRL0 0x34
62#define OMAP2_MCSPI_TX0 0x38
63#define OMAP2_MCSPI_RX0 0x3c
64
65/* per-register bitmasks: */
Illia Smyrnovd33f4732013-06-17 16:31:06 +030066#define OMAP2_MCSPI_IRQSTATUS_EOW BIT(17)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070067
Jouni Hogander7a8fa722009-09-22 16:45:58 -070068#define OMAP2_MCSPI_MODULCTRL_SINGLE BIT(0)
69#define OMAP2_MCSPI_MODULCTRL_MS BIT(2)
70#define OMAP2_MCSPI_MODULCTRL_STEST BIT(3)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070071
Jouni Hogander7a8fa722009-09-22 16:45:58 -070072#define OMAP2_MCSPI_CHCONF_PHA BIT(0)
73#define OMAP2_MCSPI_CHCONF_POL BIT(1)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070074#define OMAP2_MCSPI_CHCONF_CLKD_MASK (0x0f << 2)
Jouni Hogander7a8fa722009-09-22 16:45:58 -070075#define OMAP2_MCSPI_CHCONF_EPOL BIT(6)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070076#define OMAP2_MCSPI_CHCONF_WL_MASK (0x1f << 7)
Jouni Hogander7a8fa722009-09-22 16:45:58 -070077#define OMAP2_MCSPI_CHCONF_TRM_RX_ONLY BIT(12)
78#define OMAP2_MCSPI_CHCONF_TRM_TX_ONLY BIT(13)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070079#define OMAP2_MCSPI_CHCONF_TRM_MASK (0x03 << 12)
Jouni Hogander7a8fa722009-09-22 16:45:58 -070080#define OMAP2_MCSPI_CHCONF_DMAW BIT(14)
81#define OMAP2_MCSPI_CHCONF_DMAR BIT(15)
82#define OMAP2_MCSPI_CHCONF_DPE0 BIT(16)
83#define OMAP2_MCSPI_CHCONF_DPE1 BIT(17)
84#define OMAP2_MCSPI_CHCONF_IS BIT(18)
85#define OMAP2_MCSPI_CHCONF_TURBO BIT(19)
86#define OMAP2_MCSPI_CHCONF_FORCE BIT(20)
Illia Smyrnovd33f4732013-06-17 16:31:06 +030087#define OMAP2_MCSPI_CHCONF_FFET BIT(27)
88#define OMAP2_MCSPI_CHCONF_FFER BIT(28)
Stefan Sørensenfaee9b02014-02-02 16:24:25 +010089#define OMAP2_MCSPI_CHCONF_CLKG BIT(29)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070090
Jouni Hogander7a8fa722009-09-22 16:45:58 -070091#define OMAP2_MCSPI_CHSTAT_RXS BIT(0)
92#define OMAP2_MCSPI_CHSTAT_TXS BIT(1)
93#define OMAP2_MCSPI_CHSTAT_EOT BIT(2)
Illia Smyrnovd33f4732013-06-17 16:31:06 +030094#define OMAP2_MCSPI_CHSTAT_TXFFE BIT(3)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070095
Jouni Hogander7a8fa722009-09-22 16:45:58 -070096#define OMAP2_MCSPI_CHCTRL_EN BIT(0)
Stefan Sørensenfaee9b02014-02-02 16:24:25 +010097#define OMAP2_MCSPI_CHCTRL_EXTCLK_MASK (0xff << 8)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -070098
Jouni Hogander7a8fa722009-09-22 16:45:58 -070099#define OMAP2_MCSPI_WAKEUPENABLE_WKEN BIT(0)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700100
101/* We have 2 DMA channels per CS, one for RX and one for TX */
102struct omap2_mcspi_dma {
Russell King53741ed2012-04-23 13:51:48 +0100103 struct dma_chan *dma_tx;
104 struct dma_chan *dma_rx;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700105
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700106 struct completion dma_tx_completion;
107 struct completion dma_rx_completion;
Matt Porter74f3aaa2013-06-22 23:07:38 +0530108
109 char dma_rx_ch_name[14];
110 char dma_tx_ch_name[14];
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700111};
112
113/* use PIO for small transfers, avoiding DMA setup/teardown overhead and
114 * cache operations; better heuristics consider wordsize and bitrate.
115 */
Roman Tereshonkov8b66c132010-04-12 09:07:54 +0000116#define DMA_MIN_BYTES 160
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700117
118
Benoit Cousson1bd897f82012-03-26 15:32:33 +0530119/*
120 * Used for context save and restore, structure members to be updated whenever
121 * corresponding registers are modified.
122 */
123struct omap2_mcspi_regs {
124 u32 modulctrl;
125 u32 wakeupenable;
126 struct list_head cs;
127};
128
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700129struct omap2_mcspi {
Vignesh R89e8b9c2018-10-15 12:08:29 +0530130 struct completion txdone;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700131 struct spi_master *master;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700132 /* Virtual base address of the controller */
133 void __iomem *base;
Russell Kinge5480b732008-09-01 21:51:50 +0100134 unsigned long phys;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700135 /* SPI1 has 4 channels, while SPI2 has 2 */
136 struct omap2_mcspi_dma *dma_channels;
Benoit Cousson1bd897f82012-03-26 15:32:33 +0530137 struct device *dev;
Benoit Cousson1bd897f82012-03-26 15:32:33 +0530138 struct omap2_mcspi_regs ctx;
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300139 int fifo_depth;
Vignesh R89e8b9c2018-10-15 12:08:29 +0530140 bool slave_aborted;
Daniel Mack0384e902012-10-07 18:19:44 +0200141 unsigned int pin_dir:1;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700142};
143
144struct omap2_mcspi_cs {
145 void __iomem *base;
Russell Kinge5480b732008-09-01 21:51:50 +0100146 unsigned long phys;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700147 int word_len;
Mark A. Greer97ca0d62014-07-01 20:28:32 -0700148 u16 mode;
Tero Kristo89c05372009-09-22 16:46:17 -0700149 struct list_head node;
Hemanth Va41ae1a2009-09-22 16:46:16 -0700150 /* Context save and restore shadow register */
Stefan Sørensenfaee9b02014-02-02 16:24:25 +0100151 u32 chconf0, chctrl0;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700152};
153
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700154static inline void mcspi_write_reg(struct spi_master *master,
155 int idx, u32 val)
156{
157 struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
158
Victor Kamensky21b2ce52013-11-16 02:01:16 +0200159 writel_relaxed(val, mcspi->base + idx);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700160}
161
162static inline u32 mcspi_read_reg(struct spi_master *master, int idx)
163{
164 struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
165
Victor Kamensky21b2ce52013-11-16 02:01:16 +0200166 return readl_relaxed(mcspi->base + idx);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700167}
168
169static inline void mcspi_write_cs_reg(const struct spi_device *spi,
170 int idx, u32 val)
171{
172 struct omap2_mcspi_cs *cs = spi->controller_state;
173
Victor Kamensky21b2ce52013-11-16 02:01:16 +0200174 writel_relaxed(val, cs->base + idx);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700175}
176
177static inline u32 mcspi_read_cs_reg(const struct spi_device *spi, int idx)
178{
179 struct omap2_mcspi_cs *cs = spi->controller_state;
180
Victor Kamensky21b2ce52013-11-16 02:01:16 +0200181 return readl_relaxed(cs->base + idx);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700182}
183
Hemanth Va41ae1a2009-09-22 16:46:16 -0700184static inline u32 mcspi_cached_chconf0(const struct spi_device *spi)
185{
186 struct omap2_mcspi_cs *cs = spi->controller_state;
187
188 return cs->chconf0;
189}
190
191static inline void mcspi_write_chconf0(const struct spi_device *spi, u32 val)
192{
193 struct omap2_mcspi_cs *cs = spi->controller_state;
194
195 cs->chconf0 = val;
196 mcspi_write_cs_reg(spi, OMAP2_MCSPI_CHCONF0, val);
Roman Tereshonkova330ce22010-03-15 09:06:28 +0000197 mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHCONF0);
Hemanth Va41ae1a2009-09-22 16:46:16 -0700198}
199
Illia Smyrnov56cd5c12013-06-14 19:12:07 +0300200static inline int mcspi_bytes_per_word(int word_len)
201{
202 if (word_len <= 8)
203 return 1;
204 else if (word_len <= 16)
205 return 2;
206 else /* word_len <= 32 */
207 return 4;
208}
209
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700210static void omap2_mcspi_set_dma_req(const struct spi_device *spi,
211 int is_read, int enable)
212{
213 u32 l, rw;
214
Hemanth Va41ae1a2009-09-22 16:46:16 -0700215 l = mcspi_cached_chconf0(spi);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700216
217 if (is_read) /* 1 is read, 0 write */
218 rw = OMAP2_MCSPI_CHCONF_DMAR;
219 else
220 rw = OMAP2_MCSPI_CHCONF_DMAW;
221
Shubhrajyoti Daf4e9442012-08-22 11:35:13 +0530222 if (enable)
223 l |= rw;
224 else
225 l &= ~rw;
226
Hemanth Va41ae1a2009-09-22 16:46:16 -0700227 mcspi_write_chconf0(spi, l);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700228}
229
230static void omap2_mcspi_set_enable(const struct spi_device *spi, int enable)
231{
Stefan Sørensenfaee9b02014-02-02 16:24:25 +0100232 struct omap2_mcspi_cs *cs = spi->controller_state;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700233 u32 l;
234
Stefan Sørensenfaee9b02014-02-02 16:24:25 +0100235 l = cs->chctrl0;
236 if (enable)
237 l |= OMAP2_MCSPI_CHCTRL_EN;
238 else
239 l &= ~OMAP2_MCSPI_CHCTRL_EN;
240 cs->chctrl0 = l;
241 mcspi_write_cs_reg(spi, OMAP2_MCSPI_CHCTRL0, cs->chctrl0);
Roman Tereshonkov4743a0f2010-04-13 10:41:51 +0000242 /* Flash post-writes */
243 mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHCTRL0);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700244}
245
Michael Wellingddcad7e2015-05-12 12:38:57 -0500246static void omap2_mcspi_set_cs(struct spi_device *spi, bool enable)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700247{
Sebastian Reichel5f74db12015-07-22 20:46:09 +0200248 struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700249 u32 l;
250
Michael Welling4373f8b2015-05-23 21:13:43 -0500251 /* The controller handles the inverted chip selects
252 * using the OMAP2_MCSPI_CHCONF_EPOL bit so revert
253 * the inversion from the core spi_set_cs function.
254 */
255 if (spi->mode & SPI_CS_HIGH)
256 enable = !enable;
257
Michael Wellingddcad7e2015-05-12 12:38:57 -0500258 if (spi->controller_state) {
Sebastian Reichel5f74db12015-07-22 20:46:09 +0200259 int err = pm_runtime_get_sync(mcspi->dev);
260 if (err < 0) {
Tony Lindgren5a686b22018-04-27 08:50:07 -0700261 pm_runtime_put_noidle(mcspi->dev);
Sebastian Reichel5f74db12015-07-22 20:46:09 +0200262 dev_err(mcspi->dev, "failed to get sync: %d\n", err);
263 return;
264 }
265
Michael Wellingddcad7e2015-05-12 12:38:57 -0500266 l = mcspi_cached_chconf0(spi);
Shubhrajyoti Daf4e9442012-08-22 11:35:13 +0530267
Michael Wellingddcad7e2015-05-12 12:38:57 -0500268 if (enable)
269 l &= ~OMAP2_MCSPI_CHCONF_FORCE;
270 else
271 l |= OMAP2_MCSPI_CHCONF_FORCE;
272
273 mcspi_write_chconf0(spi, l);
Sebastian Reichel5f74db12015-07-22 20:46:09 +0200274
275 pm_runtime_mark_last_busy(mcspi->dev);
276 pm_runtime_put_autosuspend(mcspi->dev);
Michael Wellingddcad7e2015-05-12 12:38:57 -0500277 }
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700278}
279
Vignesh R89e8b9c2018-10-15 12:08:29 +0530280static void omap2_mcspi_set_mode(struct spi_master *master)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700281{
Benoit Cousson1bd897f82012-03-26 15:32:33 +0530282 struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
283 struct omap2_mcspi_regs *ctx = &mcspi->ctx;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700284 u32 l;
285
Benoit Cousson1bd897f82012-03-26 15:32:33 +0530286 /*
Vignesh R89e8b9c2018-10-15 12:08:29 +0530287 * Choose master or slave mode
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700288 */
289 l = mcspi_read_reg(master, OMAP2_MCSPI_MODULCTRL);
Vignesh R89e8b9c2018-10-15 12:08:29 +0530290 l &= ~(OMAP2_MCSPI_MODULCTRL_STEST);
291 if (spi_controller_is_slave(master)) {
292 l |= (OMAP2_MCSPI_MODULCTRL_MS);
293 } else {
294 l &= ~(OMAP2_MCSPI_MODULCTRL_MS);
295 l |= OMAP2_MCSPI_MODULCTRL_SINGLE;
296 }
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700297 mcspi_write_reg(master, OMAP2_MCSPI_MODULCTRL, l);
Hemanth Va41ae1a2009-09-22 16:46:16 -0700298
Benoit Cousson1bd897f82012-03-26 15:32:33 +0530299 ctx->modulctrl = l;
Hemanth Va41ae1a2009-09-22 16:46:16 -0700300}
301
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300302static void omap2_mcspi_set_fifo(const struct spi_device *spi,
303 struct spi_transfer *t, int enable)
304{
305 struct spi_master *master = spi->master;
306 struct omap2_mcspi_cs *cs = spi->controller_state;
307 struct omap2_mcspi *mcspi;
308 unsigned int wcnt;
Vignesh Rb682cff2018-10-15 12:08:28 +0530309 int max_fifo_depth, bytes_per_word;
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300310 u32 chconf, xferlevel;
311
312 mcspi = spi_master_get_devdata(master);
313
314 chconf = mcspi_cached_chconf0(spi);
315 if (enable) {
316 bytes_per_word = mcspi_bytes_per_word(cs->word_len);
317 if (t->len % bytes_per_word != 0)
318 goto disable_fifo;
319
Illia Smyrnov5db542e2013-10-09 15:05:08 +0300320 if (t->rx_buf != NULL && t->tx_buf != NULL)
321 max_fifo_depth = OMAP2_MCSPI_MAX_FIFODEPTH / 2;
322 else
323 max_fifo_depth = OMAP2_MCSPI_MAX_FIFODEPTH;
324
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300325 wcnt = t->len / bytes_per_word;
326 if (wcnt > OMAP2_MCSPI_MAX_FIFOWCNT)
327 goto disable_fifo;
328
329 xferlevel = wcnt << 16;
330 if (t->rx_buf != NULL) {
331 chconf |= OMAP2_MCSPI_CHCONF_FFER;
Vignesh Rb682cff2018-10-15 12:08:28 +0530332 xferlevel |= (bytes_per_word - 1) << 8;
Illia Smyrnov5db542e2013-10-09 15:05:08 +0300333 }
Vignesh Rb682cff2018-10-15 12:08:28 +0530334
Illia Smyrnov5db542e2013-10-09 15:05:08 +0300335 if (t->tx_buf != NULL) {
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300336 chconf |= OMAP2_MCSPI_CHCONF_FFET;
Vignesh Rb682cff2018-10-15 12:08:28 +0530337 xferlevel |= bytes_per_word - 1;
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300338 }
339
340 mcspi_write_reg(master, OMAP2_MCSPI_XFERLEVEL, xferlevel);
341 mcspi_write_chconf0(spi, chconf);
Vignesh Rb682cff2018-10-15 12:08:28 +0530342 mcspi->fifo_depth = max_fifo_depth;
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300343
344 return;
345 }
346
347disable_fifo:
348 if (t->rx_buf != NULL)
349 chconf &= ~OMAP2_MCSPI_CHCONF_FFER;
Jorge A. Ventura3d0763c2014-08-09 16:06:58 -0500350
351 if (t->tx_buf != NULL)
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300352 chconf &= ~OMAP2_MCSPI_CHCONF_FFET;
353
354 mcspi_write_chconf0(spi, chconf);
355 mcspi->fifo_depth = 0;
356}
357
Ilkka Koskinen2764c502010-10-19 17:07:31 +0300358static int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit)
359{
Vignesh R13d515c2018-10-15 12:08:27 +0530360 u32 val;
Ilkka Koskinen2764c502010-10-19 17:07:31 +0300361
Vignesh R13d515c2018-10-15 12:08:27 +0530362 return readl_poll_timeout(reg, val, val & bit, 1, MSEC_PER_SEC);
Ilkka Koskinen2764c502010-10-19 17:07:31 +0300363}
364
Vignesh R89e8b9c2018-10-15 12:08:29 +0530365static int mcspi_wait_for_completion(struct omap2_mcspi *mcspi,
366 struct completion *x)
367{
368 if (spi_controller_is_slave(mcspi->master)) {
369 if (wait_for_completion_interruptible(x) ||
370 mcspi->slave_aborted)
371 return -EINTR;
372 } else {
373 wait_for_completion(x);
374 }
375
376 return 0;
377}
378
Russell King53741ed2012-04-23 13:51:48 +0100379static void omap2_mcspi_rx_callback(void *data)
380{
381 struct spi_device *spi = data;
382 struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master);
383 struct omap2_mcspi_dma *mcspi_dma = &mcspi->dma_channels[spi->chip_select];
384
Russell King53741ed2012-04-23 13:51:48 +0100385 /* We must disable the DMA RX request */
386 omap2_mcspi_set_dma_req(spi, 1, 0);
Felipe Balbi830379e2012-12-12 10:45:59 +0200387
388 complete(&mcspi_dma->dma_rx_completion);
Russell King53741ed2012-04-23 13:51:48 +0100389}
390
391static void omap2_mcspi_tx_callback(void *data)
392{
393 struct spi_device *spi = data;
394 struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master);
395 struct omap2_mcspi_dma *mcspi_dma = &mcspi->dma_channels[spi->chip_select];
396
Russell King53741ed2012-04-23 13:51:48 +0100397 /* We must disable the DMA TX request */
398 omap2_mcspi_set_dma_req(spi, 0, 0);
Felipe Balbi830379e2012-12-12 10:45:59 +0200399
400 complete(&mcspi_dma->dma_tx_completion);
Russell King53741ed2012-04-23 13:51:48 +0100401}
402
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530403static void omap2_mcspi_tx_dma(struct spi_device *spi,
404 struct spi_transfer *xfer,
405 struct dma_slave_config cfg)
406{
407 struct omap2_mcspi *mcspi;
408 struct omap2_mcspi_dma *mcspi_dma;
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530409
410 mcspi = spi_master_get_devdata(spi->master);
411 mcspi_dma = &mcspi->dma_channels[spi->chip_select];
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530412
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530413 if (mcspi_dma->dma_tx) {
414 struct dma_async_tx_descriptor *tx;
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530415
416 dmaengine_slave_config(mcspi_dma->dma_tx, &cfg);
417
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -0500418 tx = dmaengine_prep_slave_sg(mcspi_dma->dma_tx, xfer->tx_sg.sgl,
419 xfer->tx_sg.nents,
420 DMA_MEM_TO_DEV,
421 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530422 if (tx) {
423 tx->callback = omap2_mcspi_tx_callback;
424 tx->callback_param = spi;
425 dmaengine_submit(tx);
426 } else {
427 /* FIXME: fall back to PIO? */
428 }
429 }
430 dma_async_issue_pending(mcspi_dma->dma_tx);
431 omap2_mcspi_set_dma_req(spi, 0, 1);
432
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530433}
434
435static unsigned
436omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,
437 struct dma_slave_config cfg,
438 unsigned es)
439{
440 struct omap2_mcspi *mcspi;
441 struct omap2_mcspi_dma *mcspi_dma;
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -0500442 unsigned int count, transfer_reduction = 0;
443 struct scatterlist *sg_out[2];
444 int nb_sizes = 0, out_mapped_nents[2], ret, x;
445 size_t sizes[2];
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530446 u32 l;
447 int elements = 0;
448 int word_len, element_count;
449 struct omap2_mcspi_cs *cs = spi->controller_state;
Akinobu Mita81261352017-03-22 09:18:26 +0900450 void __iomem *chstat_reg = cs->base + OMAP2_MCSPI_CHSTAT0;
451
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530452 mcspi = spi_master_get_devdata(spi->master);
453 mcspi_dma = &mcspi->dma_channels[spi->chip_select];
454 count = xfer->len;
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300455
Franklin S Cooper Jr4bd00412016-06-27 09:54:08 -0500456 /*
457 * In the "End-of-Transfer Procedure" section for DMA RX in OMAP35x TRM
458 * it mentions reducing DMA transfer length by one element in master
459 * normal mode.
460 */
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300461 if (mcspi->fifo_depth == 0)
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -0500462 transfer_reduction = es;
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300463
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530464 word_len = cs->word_len;
465 l = mcspi_cached_chconf0(spi);
466
467 if (word_len <= 8)
468 element_count = count;
469 else if (word_len <= 16)
470 element_count = count >> 1;
471 else /* word_len <= 32 */
472 element_count = count >> 2;
473
474 if (mcspi_dma->dma_rx) {
475 struct dma_async_tx_descriptor *tx;
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530476
477 dmaengine_slave_config(mcspi_dma->dma_rx, &cfg);
478
Franklin S Cooper Jr4bd00412016-06-27 09:54:08 -0500479 /*
480 * Reduce DMA transfer length by one more if McSPI is
481 * configured in turbo mode.
482 */
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300483 if ((l & OMAP2_MCSPI_CHCONF_TURBO) && mcspi->fifo_depth == 0)
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -0500484 transfer_reduction += es;
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530485
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -0500486 if (transfer_reduction) {
487 /* Split sgl into two. The second sgl won't be used. */
488 sizes[0] = count - transfer_reduction;
489 sizes[1] = transfer_reduction;
490 nb_sizes = 2;
491 } else {
492 /*
493 * Don't bother splitting the sgl. This essentially
494 * clones the original sgl.
495 */
496 sizes[0] = count;
497 nb_sizes = 1;
498 }
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530499
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -0500500 ret = sg_split(xfer->rx_sg.sgl, xfer->rx_sg.nents,
501 0, nb_sizes,
502 sizes,
503 sg_out, out_mapped_nents,
504 GFP_KERNEL);
505
506 if (ret < 0) {
507 dev_err(&spi->dev, "sg_split failed\n");
508 return 0;
509 }
510
511 tx = dmaengine_prep_slave_sg(mcspi_dma->dma_rx,
512 sg_out[0],
513 out_mapped_nents[0],
514 DMA_DEV_TO_MEM,
515 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530516 if (tx) {
517 tx->callback = omap2_mcspi_rx_callback;
518 tx->callback_param = spi;
519 dmaengine_submit(tx);
520 } else {
521 /* FIXME: fall back to PIO? */
522 }
523 }
524
525 dma_async_issue_pending(mcspi_dma->dma_rx);
526 omap2_mcspi_set_dma_req(spi, 1, 1);
527
Vignesh R89e8b9c2018-10-15 12:08:29 +0530528 ret = mcspi_wait_for_completion(mcspi, &mcspi_dma->dma_rx_completion);
529 if (ret || mcspi->slave_aborted) {
530 dmaengine_terminate_sync(mcspi_dma->dma_rx);
531 omap2_mcspi_set_dma_req(spi, 1, 0);
532 return 0;
533 }
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -0500534
535 for (x = 0; x < nb_sizes; x++)
536 kfree(sg_out[x]);
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300537
538 if (mcspi->fifo_depth > 0)
539 return count;
540
Franklin S Cooper Jr4bd00412016-06-27 09:54:08 -0500541 /*
542 * Due to the DMA transfer length reduction the missing bytes must
543 * be read manually to receive all of the expected data.
544 */
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530545 omap2_mcspi_set_enable(spi, 0);
546
547 elements = element_count - 1;
548
549 if (l & OMAP2_MCSPI_CHCONF_TURBO) {
550 elements--;
551
Akinobu Mita81261352017-03-22 09:18:26 +0900552 if (!mcspi_wait_for_reg_bit(chstat_reg,
553 OMAP2_MCSPI_CHSTAT_RXS)) {
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530554 u32 w;
555
556 w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0);
557 if (word_len <= 8)
558 ((u8 *)xfer->rx_buf)[elements++] = w;
559 else if (word_len <= 16)
560 ((u16 *)xfer->rx_buf)[elements++] = w;
561 else /* word_len <= 32 */
562 ((u32 *)xfer->rx_buf)[elements++] = w;
563 } else {
Illia Smyrnov56cd5c12013-06-14 19:12:07 +0300564 int bytes_per_word = mcspi_bytes_per_word(word_len);
Jarkko Nikulaa1829d22013-10-11 13:53:59 +0300565 dev_err(&spi->dev, "DMA RX penultimate word empty\n");
Illia Smyrnov56cd5c12013-06-14 19:12:07 +0300566 count -= (bytes_per_word << 1);
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530567 omap2_mcspi_set_enable(spi, 1);
568 return count;
569 }
570 }
Akinobu Mita81261352017-03-22 09:18:26 +0900571 if (!mcspi_wait_for_reg_bit(chstat_reg, OMAP2_MCSPI_CHSTAT_RXS)) {
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530572 u32 w;
573
574 w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0);
575 if (word_len <= 8)
576 ((u8 *)xfer->rx_buf)[elements] = w;
577 else if (word_len <= 16)
578 ((u16 *)xfer->rx_buf)[elements] = w;
579 else /* word_len <= 32 */
580 ((u32 *)xfer->rx_buf)[elements] = w;
581 } else {
Jarkko Nikulaa1829d22013-10-11 13:53:59 +0300582 dev_err(&spi->dev, "DMA RX last word empty\n");
Illia Smyrnov56cd5c12013-06-14 19:12:07 +0300583 count -= mcspi_bytes_per_word(word_len);
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530584 }
585 omap2_mcspi_set_enable(spi, 1);
586 return count;
587}
588
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700589static unsigned
590omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
591{
592 struct omap2_mcspi *mcspi;
593 struct omap2_mcspi_cs *cs = spi->controller_state;
594 struct omap2_mcspi_dma *mcspi_dma;
Russell King8c7494a2012-04-23 13:56:25 +0100595 unsigned int count;
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530596 u8 *rx;
597 const u8 *tx;
Russell King53741ed2012-04-23 13:51:48 +0100598 struct dma_slave_config cfg;
599 enum dma_slave_buswidth width;
600 unsigned es;
Shubhrajyoti De47a6822012-11-06 14:30:19 +0530601 void __iomem *chstat_reg;
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300602 void __iomem *irqstat_reg;
603 int wait_res;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700604
605 mcspi = spi_master_get_devdata(spi->master);
606 mcspi_dma = &mcspi->dma_channels[spi->chip_select];
Ilkka Koskinen2764c502010-10-19 17:07:31 +0300607
Russell King53741ed2012-04-23 13:51:48 +0100608 if (cs->word_len <= 8) {
609 width = DMA_SLAVE_BUSWIDTH_1_BYTE;
610 es = 1;
611 } else if (cs->word_len <= 16) {
612 width = DMA_SLAVE_BUSWIDTH_2_BYTES;
613 es = 2;
614 } else {
615 width = DMA_SLAVE_BUSWIDTH_4_BYTES;
616 es = 4;
617 }
618
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300619 count = xfer->len;
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300620
Russell King53741ed2012-04-23 13:51:48 +0100621 memset(&cfg, 0, sizeof(cfg));
622 cfg.src_addr = cs->phys + OMAP2_MCSPI_RX0;
623 cfg.dst_addr = cs->phys + OMAP2_MCSPI_TX0;
624 cfg.src_addr_width = width;
625 cfg.dst_addr_width = width;
Vignesh Rb682cff2018-10-15 12:08:28 +0530626 cfg.src_maxburst = es;
627 cfg.dst_maxburst = es;
Russell King53741ed2012-04-23 13:51:48 +0100628
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700629 rx = xfer->rx_buf;
630 tx = xfer->tx_buf;
631
Vignesh R89e8b9c2018-10-15 12:08:29 +0530632 mcspi->slave_aborted = false;
633 reinit_completion(&mcspi_dma->dma_tx_completion);
634 reinit_completion(&mcspi_dma->dma_rx_completion);
635 reinit_completion(&mcspi->txdone);
636 if (tx) {
637 /* Enable EOW IRQ to know end of tx in slave mode */
638 if (spi_controller_is_slave(spi->master))
639 mcspi_write_reg(spi->master,
640 OMAP2_MCSPI_IRQENABLE,
641 OMAP2_MCSPI_IRQSTATUS_EOW);
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530642 omap2_mcspi_tx_dma(spi, xfer, cfg);
Vignesh R89e8b9c2018-10-15 12:08:29 +0530643 }
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700644
Shubhrajyoti Dd7b43942012-09-11 12:13:20 +0530645 if (rx != NULL)
Shubhrajyoti De47a6822012-11-06 14:30:19 +0530646 count = omap2_mcspi_rx_dma(spi, xfer, cfg, es);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700647
Shubhrajyoti De47a6822012-11-06 14:30:19 +0530648 if (tx != NULL) {
Vignesh R89e8b9c2018-10-15 12:08:29 +0530649 int ret;
650
651 ret = mcspi_wait_for_completion(mcspi, &mcspi_dma->dma_tx_completion);
652 if (ret || mcspi->slave_aborted) {
653 dmaengine_terminate_sync(mcspi_dma->dma_tx);
654 omap2_mcspi_set_dma_req(spi, 0, 0);
655 return 0;
656 }
657
658 if (spi_controller_is_slave(mcspi->master)) {
659 ret = mcspi_wait_for_completion(mcspi, &mcspi->txdone);
660 if (ret || mcspi->slave_aborted)
661 return 0;
662 }
Shubhrajyoti De47a6822012-11-06 14:30:19 +0530663
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300664 if (mcspi->fifo_depth > 0) {
665 irqstat_reg = mcspi->base + OMAP2_MCSPI_IRQSTATUS;
666
667 if (mcspi_wait_for_reg_bit(irqstat_reg,
668 OMAP2_MCSPI_IRQSTATUS_EOW) < 0)
669 dev_err(&spi->dev, "EOW timed out\n");
670
671 mcspi_write_reg(mcspi->master, OMAP2_MCSPI_IRQSTATUS,
672 OMAP2_MCSPI_IRQSTATUS_EOW);
673 }
674
Shubhrajyoti De47a6822012-11-06 14:30:19 +0530675 /* for TX_ONLY mode, be sure all words have shifted out */
676 if (rx == NULL) {
Illia Smyrnovd33f4732013-06-17 16:31:06 +0300677 chstat_reg = cs->base + OMAP2_MCSPI_CHSTAT0;
678 if (mcspi->fifo_depth > 0) {
679 wait_res = mcspi_wait_for_reg_bit(chstat_reg,
680 OMAP2_MCSPI_CHSTAT_TXFFE);
681 if (wait_res < 0)
682 dev_err(&spi->dev, "TXFFE timed out\n");
683 } else {
684 wait_res = mcspi_wait_for_reg_bit(chstat_reg,
685 OMAP2_MCSPI_CHSTAT_TXS);
686 if (wait_res < 0)
687 dev_err(&spi->dev, "TXS timed out\n");
688 }
689 if (wait_res >= 0 &&
690 (mcspi_wait_for_reg_bit(chstat_reg,
691 OMAP2_MCSPI_CHSTAT_EOT) < 0))
Shubhrajyoti De47a6822012-11-06 14:30:19 +0530692 dev_err(&spi->dev, "EOT timed out\n");
693 }
694 }
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700695 return count;
696}
697
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700698static unsigned
699omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
700{
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700701 struct omap2_mcspi_cs *cs = spi->controller_state;
702 unsigned int count, c;
703 u32 l;
704 void __iomem *base = cs->base;
705 void __iomem *tx_reg;
706 void __iomem *rx_reg;
707 void __iomem *chstat_reg;
708 int word_len;
709
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700710 count = xfer->len;
711 c = count;
712 word_len = cs->word_len;
713
Hemanth Va41ae1a2009-09-22 16:46:16 -0700714 l = mcspi_cached_chconf0(spi);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700715
716 /* We store the pre-calculated register addresses on stack to speed
717 * up the transfer loop. */
718 tx_reg = base + OMAP2_MCSPI_TX0;
719 rx_reg = base + OMAP2_MCSPI_RX0;
720 chstat_reg = base + OMAP2_MCSPI_CHSTAT0;
721
Michael Jonesadef6582011-02-25 16:55:11 +0100722 if (c < (word_len>>3))
723 return 0;
724
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700725 if (word_len <= 8) {
726 u8 *rx;
727 const u8 *tx;
728
729 rx = xfer->rx_buf;
730 tx = xfer->tx_buf;
731
732 do {
Kalle Valofeed9ba2008-01-24 14:00:40 -0800733 c -= 1;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700734 if (tx != NULL) {
735 if (mcspi_wait_for_reg_bit(chstat_reg,
736 OMAP2_MCSPI_CHSTAT_TXS) < 0) {
737 dev_err(&spi->dev, "TXS timed out\n");
738 goto out;
739 }
Felipe Balbi079a1762010-09-29 17:31:29 +0900740 dev_vdbg(&spi->dev, "write-%d %02x\n",
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700741 word_len, *tx);
Victor Kamensky21b2ce52013-11-16 02:01:16 +0200742 writel_relaxed(*tx++, tx_reg);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700743 }
744 if (rx != NULL) {
745 if (mcspi_wait_for_reg_bit(chstat_reg,
746 OMAP2_MCSPI_CHSTAT_RXS) < 0) {
747 dev_err(&spi->dev, "RXS timed out\n");
748 goto out;
749 }
Roman Tereshonkov4743a0f2010-04-13 10:41:51 +0000750
751 if (c == 1 && tx == NULL &&
752 (l & OMAP2_MCSPI_CHCONF_TURBO)) {
753 omap2_mcspi_set_enable(spi, 0);
Victor Kamensky21b2ce52013-11-16 02:01:16 +0200754 *rx++ = readl_relaxed(rx_reg);
Felipe Balbi079a1762010-09-29 17:31:29 +0900755 dev_vdbg(&spi->dev, "read-%d %02x\n",
Roman Tereshonkov4743a0f2010-04-13 10:41:51 +0000756 word_len, *(rx - 1));
Roman Tereshonkov4743a0f2010-04-13 10:41:51 +0000757 if (mcspi_wait_for_reg_bit(chstat_reg,
758 OMAP2_MCSPI_CHSTAT_RXS) < 0) {
759 dev_err(&spi->dev,
760 "RXS timed out\n");
761 goto out;
762 }
763 c = 0;
764 } else if (c == 0 && tx == NULL) {
765 omap2_mcspi_set_enable(spi, 0);
766 }
767
Victor Kamensky21b2ce52013-11-16 02:01:16 +0200768 *rx++ = readl_relaxed(rx_reg);
Felipe Balbi079a1762010-09-29 17:31:29 +0900769 dev_vdbg(&spi->dev, "read-%d %02x\n",
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700770 word_len, *(rx - 1));
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700771 }
Jarkko Nikula95c5c3a2011-03-21 16:27:30 +0200772 } while (c);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700773 } else if (word_len <= 16) {
774 u16 *rx;
775 const u16 *tx;
776
777 rx = xfer->rx_buf;
778 tx = xfer->tx_buf;
779 do {
Kalle Valofeed9ba2008-01-24 14:00:40 -0800780 c -= 2;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700781 if (tx != NULL) {
782 if (mcspi_wait_for_reg_bit(chstat_reg,
783 OMAP2_MCSPI_CHSTAT_TXS) < 0) {
784 dev_err(&spi->dev, "TXS timed out\n");
785 goto out;
786 }
Felipe Balbi079a1762010-09-29 17:31:29 +0900787 dev_vdbg(&spi->dev, "write-%d %04x\n",
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700788 word_len, *tx);
Victor Kamensky21b2ce52013-11-16 02:01:16 +0200789 writel_relaxed(*tx++, tx_reg);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700790 }
791 if (rx != NULL) {
792 if (mcspi_wait_for_reg_bit(chstat_reg,
793 OMAP2_MCSPI_CHSTAT_RXS) < 0) {
794 dev_err(&spi->dev, "RXS timed out\n");
795 goto out;
796 }
Roman Tereshonkov4743a0f2010-04-13 10:41:51 +0000797
798 if (c == 2 && tx == NULL &&
799 (l & OMAP2_MCSPI_CHCONF_TURBO)) {
800 omap2_mcspi_set_enable(spi, 0);
Victor Kamensky21b2ce52013-11-16 02:01:16 +0200801 *rx++ = readl_relaxed(rx_reg);
Felipe Balbi079a1762010-09-29 17:31:29 +0900802 dev_vdbg(&spi->dev, "read-%d %04x\n",
Roman Tereshonkov4743a0f2010-04-13 10:41:51 +0000803 word_len, *(rx - 1));
Roman Tereshonkov4743a0f2010-04-13 10:41:51 +0000804 if (mcspi_wait_for_reg_bit(chstat_reg,
805 OMAP2_MCSPI_CHSTAT_RXS) < 0) {
806 dev_err(&spi->dev,
807 "RXS timed out\n");
808 goto out;
809 }
810 c = 0;
811 } else if (c == 0 && tx == NULL) {
812 omap2_mcspi_set_enable(spi, 0);
813 }
814
Victor Kamensky21b2ce52013-11-16 02:01:16 +0200815 *rx++ = readl_relaxed(rx_reg);
Felipe Balbi079a1762010-09-29 17:31:29 +0900816 dev_vdbg(&spi->dev, "read-%d %04x\n",
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700817 word_len, *(rx - 1));
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700818 }
Jarkko Nikula95c5c3a2011-03-21 16:27:30 +0200819 } while (c >= 2);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700820 } else if (word_len <= 32) {
821 u32 *rx;
822 const u32 *tx;
823
824 rx = xfer->rx_buf;
825 tx = xfer->tx_buf;
826 do {
Kalle Valofeed9ba2008-01-24 14:00:40 -0800827 c -= 4;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700828 if (tx != NULL) {
829 if (mcspi_wait_for_reg_bit(chstat_reg,
830 OMAP2_MCSPI_CHSTAT_TXS) < 0) {
831 dev_err(&spi->dev, "TXS timed out\n");
832 goto out;
833 }
Felipe Balbi079a1762010-09-29 17:31:29 +0900834 dev_vdbg(&spi->dev, "write-%d %08x\n",
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700835 word_len, *tx);
Victor Kamensky21b2ce52013-11-16 02:01:16 +0200836 writel_relaxed(*tx++, tx_reg);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700837 }
838 if (rx != NULL) {
839 if (mcspi_wait_for_reg_bit(chstat_reg,
840 OMAP2_MCSPI_CHSTAT_RXS) < 0) {
841 dev_err(&spi->dev, "RXS timed out\n");
842 goto out;
843 }
Roman Tereshonkov4743a0f2010-04-13 10:41:51 +0000844
845 if (c == 4 && tx == NULL &&
846 (l & OMAP2_MCSPI_CHCONF_TURBO)) {
847 omap2_mcspi_set_enable(spi, 0);
Victor Kamensky21b2ce52013-11-16 02:01:16 +0200848 *rx++ = readl_relaxed(rx_reg);
Felipe Balbi079a1762010-09-29 17:31:29 +0900849 dev_vdbg(&spi->dev, "read-%d %08x\n",
Roman Tereshonkov4743a0f2010-04-13 10:41:51 +0000850 word_len, *(rx - 1));
Roman Tereshonkov4743a0f2010-04-13 10:41:51 +0000851 if (mcspi_wait_for_reg_bit(chstat_reg,
852 OMAP2_MCSPI_CHSTAT_RXS) < 0) {
853 dev_err(&spi->dev,
854 "RXS timed out\n");
855 goto out;
856 }
857 c = 0;
858 } else if (c == 0 && tx == NULL) {
859 omap2_mcspi_set_enable(spi, 0);
860 }
861
Victor Kamensky21b2ce52013-11-16 02:01:16 +0200862 *rx++ = readl_relaxed(rx_reg);
Felipe Balbi079a1762010-09-29 17:31:29 +0900863 dev_vdbg(&spi->dev, "read-%d %08x\n",
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700864 word_len, *(rx - 1));
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700865 }
Jarkko Nikula95c5c3a2011-03-21 16:27:30 +0200866 } while (c >= 4);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700867 }
868
869 /* for TX_ONLY mode, be sure all words have shifted out */
870 if (xfer->rx_buf == NULL) {
871 if (mcspi_wait_for_reg_bit(chstat_reg,
872 OMAP2_MCSPI_CHSTAT_TXS) < 0) {
873 dev_err(&spi->dev, "TXS timed out\n");
874 } else if (mcspi_wait_for_reg_bit(chstat_reg,
875 OMAP2_MCSPI_CHSTAT_EOT) < 0)
876 dev_err(&spi->dev, "EOT timed out\n");
Jason Wange1993ed2010-10-19 18:03:27 +0800877
878 /* disable chan to purge rx datas received in TX_ONLY transfer,
879 * otherwise these rx datas will affect the direct following
880 * RX_ONLY transfer.
881 */
882 omap2_mcspi_set_enable(spi, 0);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700883 }
884out:
Roman Tereshonkov4743a0f2010-04-13 10:41:51 +0000885 omap2_mcspi_set_enable(spi, 1);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700886 return count - c;
887}
888
Hannu Heikkinen57d9c102011-02-24 21:31:33 +0200889static u32 omap2_mcspi_calc_divisor(u32 speed_hz)
890{
891 u32 div;
892
893 for (div = 0; div < 15; div++)
894 if (speed_hz >= (OMAP2_MCSPI_MAX_FREQ >> div))
895 return div;
896
897 return 15;
898}
899
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700900/* called only when no transfer is active to this device */
901static int omap2_mcspi_setup_transfer(struct spi_device *spi,
902 struct spi_transfer *t)
903{
904 struct omap2_mcspi_cs *cs = spi->controller_state;
905 struct omap2_mcspi *mcspi;
Stefan Sørensenfaee9b02014-02-02 16:24:25 +0100906 u32 l = 0, clkd = 0, div, extclk = 0, clkg = 0;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700907 u8 word_len = spi->bits_per_word;
Scott Ellis9bd45172010-03-10 14:23:13 -0700908 u32 speed_hz = spi->max_speed_hz;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700909
910 mcspi = spi_master_get_devdata(spi->master);
911
912 if (t != NULL && t->bits_per_word)
913 word_len = t->bits_per_word;
914
915 cs->word_len = word_len;
916
Scott Ellis9bd45172010-03-10 14:23:13 -0700917 if (t && t->speed_hz)
918 speed_hz = t->speed_hz;
919
Hannu Heikkinen57d9c102011-02-24 21:31:33 +0200920 speed_hz = min_t(u32, speed_hz, OMAP2_MCSPI_MAX_FREQ);
Stefan Sørensenfaee9b02014-02-02 16:24:25 +0100921 if (speed_hz < (OMAP2_MCSPI_MAX_FREQ / OMAP2_MCSPI_MAX_DIVIDER)) {
922 clkd = omap2_mcspi_calc_divisor(speed_hz);
923 speed_hz = OMAP2_MCSPI_MAX_FREQ >> clkd;
924 clkg = 0;
925 } else {
926 div = (OMAP2_MCSPI_MAX_FREQ + speed_hz - 1) / speed_hz;
927 speed_hz = OMAP2_MCSPI_MAX_FREQ / div;
928 clkd = (div - 1) & 0xf;
929 extclk = (div - 1) >> 4;
930 clkg = OMAP2_MCSPI_CHCONF_CLKG;
931 }
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700932
Hemanth Va41ae1a2009-09-22 16:46:16 -0700933 l = mcspi_cached_chconf0(spi);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700934
935 /* standard 4-wire master mode: SCK, MOSI/out, MISO/in, nCS
936 * REVISIT: this controller could support SPI_3WIRE mode.
937 */
Daniel Mack2cd45172012-11-14 11:14:26 +0800938 if (mcspi->pin_dir == MCSPI_PINDIR_D0_IN_D1_OUT) {
Daniel Mack0384e902012-10-07 18:19:44 +0200939 l &= ~OMAP2_MCSPI_CHCONF_IS;
940 l &= ~OMAP2_MCSPI_CHCONF_DPE1;
941 l |= OMAP2_MCSPI_CHCONF_DPE0;
942 } else {
943 l |= OMAP2_MCSPI_CHCONF_IS;
944 l |= OMAP2_MCSPI_CHCONF_DPE1;
945 l &= ~OMAP2_MCSPI_CHCONF_DPE0;
946 }
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700947
948 /* wordlength */
949 l &= ~OMAP2_MCSPI_CHCONF_WL_MASK;
950 l |= (word_len - 1) << 7;
951
952 /* set chipselect polarity; manage with FORCE */
953 if (!(spi->mode & SPI_CS_HIGH))
954 l |= OMAP2_MCSPI_CHCONF_EPOL; /* active-low; normal */
955 else
956 l &= ~OMAP2_MCSPI_CHCONF_EPOL;
957
958 /* set clock divisor */
959 l &= ~OMAP2_MCSPI_CHCONF_CLKD_MASK;
Stefan Sørensenfaee9b02014-02-02 16:24:25 +0100960 l |= clkd << 2;
961
962 /* set clock granularity */
963 l &= ~OMAP2_MCSPI_CHCONF_CLKG;
964 l |= clkg;
965 if (clkg) {
966 cs->chctrl0 &= ~OMAP2_MCSPI_CHCTRL_EXTCLK_MASK;
967 cs->chctrl0 |= extclk << 8;
968 mcspi_write_cs_reg(spi, OMAP2_MCSPI_CHCTRL0, cs->chctrl0);
969 }
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700970
971 /* set SPI mode 0..3 */
972 if (spi->mode & SPI_CPOL)
973 l |= OMAP2_MCSPI_CHCONF_POL;
974 else
975 l &= ~OMAP2_MCSPI_CHCONF_POL;
976 if (spi->mode & SPI_CPHA)
977 l |= OMAP2_MCSPI_CHCONF_PHA;
978 else
979 l &= ~OMAP2_MCSPI_CHCONF_PHA;
980
Hemanth Va41ae1a2009-09-22 16:46:16 -0700981 mcspi_write_chconf0(spi, l);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700982
Mark A. Greer97ca0d62014-07-01 20:28:32 -0700983 cs->mode = spi->mode;
984
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700985 dev_dbg(&spi->dev, "setup: speed %d, sample %s edge, clk %s\n",
Stefan Sørensenfaee9b02014-02-02 16:24:25 +0100986 speed_hz,
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700987 (spi->mode & SPI_CPHA) ? "trailing" : "leading",
988 (spi->mode & SPI_CPOL) ? "inverted" : "normal");
989
990 return 0;
991}
992
Tony Lindgrenddc5cdf2013-04-12 17:25:07 -0700993/*
994 * Note that we currently allow DMA only if we get a channel
995 * for both rx and tx. Otherwise we'll do PIO for both rx and tx.
996 */
Samuel Ortizccdc7bf2007-07-17 04:04:13 -0700997static int omap2_mcspi_request_dma(struct spi_device *spi)
998{
999 struct spi_master *master = spi->master;
1000 struct omap2_mcspi *mcspi;
1001 struct omap2_mcspi_dma *mcspi_dma;
Peter Ujfalusib085c612016-04-29 16:11:56 +03001002 int ret = 0;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001003
1004 mcspi = spi_master_get_devdata(master);
1005 mcspi_dma = mcspi->dma_channels + spi->chip_select;
1006
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001007 init_completion(&mcspi_dma->dma_rx_completion);
1008 init_completion(&mcspi_dma->dma_tx_completion);
1009
Peter Ujfalusib085c612016-04-29 16:11:56 +03001010 mcspi_dma->dma_rx = dma_request_chan(&master->dev,
1011 mcspi_dma->dma_rx_ch_name);
1012 if (IS_ERR(mcspi_dma->dma_rx)) {
1013 ret = PTR_ERR(mcspi_dma->dma_rx);
Russell King53741ed2012-04-23 13:51:48 +01001014 mcspi_dma->dma_rx = NULL;
Tony Lindgrenddc5cdf2013-04-12 17:25:07 -07001015 goto no_dma;
Russell King53741ed2012-04-23 13:51:48 +01001016 }
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001017
Peter Ujfalusib085c612016-04-29 16:11:56 +03001018 mcspi_dma->dma_tx = dma_request_chan(&master->dev,
1019 mcspi_dma->dma_tx_ch_name);
1020 if (IS_ERR(mcspi_dma->dma_tx)) {
1021 ret = PTR_ERR(mcspi_dma->dma_tx);
1022 mcspi_dma->dma_tx = NULL;
1023 dma_release_channel(mcspi_dma->dma_rx);
1024 mcspi_dma->dma_rx = NULL;
1025 }
Tony Lindgrenddc5cdf2013-04-12 17:25:07 -07001026
1027no_dma:
Peter Ujfalusib085c612016-04-29 16:11:56 +03001028 return ret;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001029}
1030
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001031static int omap2_mcspi_setup(struct spi_device *spi)
1032{
1033 int ret;
Benoit Cousson1bd897f82012-03-26 15:32:33 +05301034 struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master);
1035 struct omap2_mcspi_regs *ctx = &mcspi->ctx;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001036 struct omap2_mcspi_dma *mcspi_dma;
1037 struct omap2_mcspi_cs *cs = spi->controller_state;
1038
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001039 mcspi_dma = &mcspi->dma_channels[spi->chip_select];
1040
1041 if (!cs) {
Russell King10aa5a32012-06-18 11:27:04 +01001042 cs = kzalloc(sizeof *cs, GFP_KERNEL);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001043 if (!cs)
1044 return -ENOMEM;
1045 cs->base = mcspi->base + spi->chip_select * 0x14;
Russell Kinge5480b732008-09-01 21:51:50 +01001046 cs->phys = mcspi->phys + spi->chip_select * 0x14;
Mark A. Greer97ca0d62014-07-01 20:28:32 -07001047 cs->mode = 0;
Hemanth Va41ae1a2009-09-22 16:46:16 -07001048 cs->chconf0 = 0;
Stefan Sørensenfaee9b02014-02-02 16:24:25 +01001049 cs->chctrl0 = 0;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001050 spi->controller_state = cs;
Tero Kristo89c05372009-09-22 16:46:17 -07001051 /* Link this to context save list */
Benoit Cousson1bd897f82012-03-26 15:32:33 +05301052 list_add_tail(&cs->node, &ctx->cs);
Michael Welling2f538c02015-11-30 09:02:39 -06001053
1054 if (gpio_is_valid(spi->cs_gpio)) {
1055 ret = gpio_request(spi->cs_gpio, dev_name(&spi->dev));
1056 if (ret) {
1057 dev_err(&spi->dev, "failed to request gpio\n");
1058 return ret;
1059 }
1060 gpio_direction_output(spi->cs_gpio,
1061 !(spi->mode & SPI_CS_HIGH));
1062 }
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001063 }
1064
Russell King8c7494a2012-04-23 13:56:25 +01001065 if (!mcspi_dma->dma_rx || !mcspi_dma->dma_tx) {
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001066 ret = omap2_mcspi_request_dma(spi);
Peter Ujfalusib085c612016-04-29 16:11:56 +03001067 if (ret)
1068 dev_warn(&spi->dev, "not using DMA for McSPI (%d)\n",
1069 ret);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001070 }
1071
Shubhrajyoti D034d3dc2012-08-22 11:35:12 +05301072 ret = pm_runtime_get_sync(mcspi->dev);
Tony Lindgren5a686b22018-04-27 08:50:07 -07001073 if (ret < 0) {
1074 pm_runtime_put_noidle(mcspi->dev);
1075
Govindraj.R1f1a4382011-02-02 17:52:15 +05301076 return ret;
Tony Lindgren5a686b22018-04-27 08:50:07 -07001077 }
Hemanth Va41ae1a2009-09-22 16:46:16 -07001078
Kyungmin Park86eeb6f2007-10-16 01:27:45 -07001079 ret = omap2_mcspi_setup_transfer(spi, NULL);
Shubhrajyoti D034d3dc2012-08-22 11:35:12 +05301080 pm_runtime_mark_last_busy(mcspi->dev);
1081 pm_runtime_put_autosuspend(mcspi->dev);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001082
1083 return ret;
1084}
1085
1086static void omap2_mcspi_cleanup(struct spi_device *spi)
1087{
1088 struct omap2_mcspi *mcspi;
1089 struct omap2_mcspi_dma *mcspi_dma;
Tero Kristo89c05372009-09-22 16:46:17 -07001090 struct omap2_mcspi_cs *cs;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001091
1092 mcspi = spi_master_get_devdata(spi->master);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001093
Scott Ellis5e774942010-03-10 14:22:45 -07001094 if (spi->controller_state) {
1095 /* Unlink controller state from context save list */
1096 cs = spi->controller_state;
1097 list_del(&cs->node);
Tero Kristo89c05372009-09-22 16:46:17 -07001098
Russell King10aa5a32012-06-18 11:27:04 +01001099 kfree(cs);
Scott Ellis5e774942010-03-10 14:22:45 -07001100 }
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001101
Scott Ellis99f1a432010-05-24 14:20:27 +00001102 if (spi->chip_select < spi->master->num_chipselect) {
1103 mcspi_dma = &mcspi->dma_channels[spi->chip_select];
1104
Russell King53741ed2012-04-23 13:51:48 +01001105 if (mcspi_dma->dma_rx) {
1106 dma_release_channel(mcspi_dma->dma_rx);
1107 mcspi_dma->dma_rx = NULL;
Scott Ellis99f1a432010-05-24 14:20:27 +00001108 }
Russell King53741ed2012-04-23 13:51:48 +01001109 if (mcspi_dma->dma_tx) {
1110 dma_release_channel(mcspi_dma->dma_tx);
1111 mcspi_dma->dma_tx = NULL;
Scott Ellis99f1a432010-05-24 14:20:27 +00001112 }
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001113 }
Michael Wellingbc7f9bb2015-05-08 13:31:01 -05001114
1115 if (gpio_is_valid(spi->cs_gpio))
1116 gpio_free(spi->cs_gpio);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001117}
1118
Vignesh R89e8b9c2018-10-15 12:08:29 +05301119static irqreturn_t omap2_mcspi_irq_handler(int irq, void *data)
1120{
1121 struct omap2_mcspi *mcspi = data;
1122 u32 irqstat;
1123
1124 irqstat = mcspi_read_reg(mcspi->master, OMAP2_MCSPI_IRQSTATUS);
1125 if (!irqstat)
1126 return IRQ_NONE;
1127
1128 /* Disable IRQ and wakeup slave xfer task */
1129 mcspi_write_reg(mcspi->master, OMAP2_MCSPI_IRQENABLE, 0);
1130 if (irqstat & OMAP2_MCSPI_IRQSTATUS_EOW)
1131 complete(&mcspi->txdone);
1132
1133 return IRQ_HANDLED;
1134}
1135
1136static int omap2_mcspi_slave_abort(struct spi_master *master)
1137{
1138 struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
1139 struct omap2_mcspi_dma *mcspi_dma = mcspi->dma_channels;
1140
1141 mcspi->slave_aborted = true;
1142 complete(&mcspi_dma->dma_rx_completion);
1143 complete(&mcspi_dma->dma_tx_completion);
1144 complete(&mcspi->txdone);
1145
1146 return 0;
1147}
1148
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -05001149static int omap2_mcspi_transfer_one(struct spi_master *master,
1150 struct spi_device *spi,
1151 struct spi_transfer *t)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001152{
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001153
1154 /* We only enable one channel at a time -- the one whose message is
Shubhrajyoti D5fda88f2012-05-10 18:27:45 +05301155 * -- although this controller would gladly
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001156 * arbitrate among multiple channels. This corresponds to "single
1157 * channel" master mode. As a side effect, we need to manage the
1158 * chipselect with the FORCE bit ... CS != channel enable.
1159 */
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001160
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -05001161 struct omap2_mcspi *mcspi;
Tony Lindgrenddc5cdf2013-04-12 17:25:07 -07001162 struct omap2_mcspi_dma *mcspi_dma;
Shubhrajyoti D5fda88f2012-05-10 18:27:45 +05301163 struct omap2_mcspi_cs *cs;
1164 struct omap2_mcspi_device_config *cd;
1165 int par_override = 0;
1166 int status = 0;
1167 u32 chconf;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001168
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -05001169 mcspi = spi_master_get_devdata(master);
Tony Lindgrenddc5cdf2013-04-12 17:25:07 -07001170 mcspi_dma = mcspi->dma_channels + spi->chip_select;
Shubhrajyoti D5fda88f2012-05-10 18:27:45 +05301171 cs = spi->controller_state;
1172 cd = spi->controller_data;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001173
Mark A. Greer97ca0d62014-07-01 20:28:32 -07001174 /*
1175 * The slave driver could have changed spi->mode in which case
1176 * it will be different from cs->mode (the current hardware setup).
1177 * If so, set par_override (even though its not a parity issue) so
1178 * omap2_mcspi_setup_transfer will be called to configure the hardware
1179 * with the correct mode on the first iteration of the loop below.
1180 */
1181 if (spi->mode != cs->mode)
1182 par_override = 1;
1183
Illia Smyrnovd33f4732013-06-17 16:31:06 +03001184 omap2_mcspi_set_enable(spi, 0);
Matthias Brugger5cbc7ca2013-01-24 13:40:41 +01001185
Michael Wellinga06b4302015-05-23 21:13:44 -05001186 if (gpio_is_valid(spi->cs_gpio))
1187 omap2_mcspi_set_cs(spi, spi->mode & SPI_CS_HIGH);
1188
Michael Wellingb28cb942015-05-07 18:36:53 -05001189 if (par_override ||
1190 (t->speed_hz != spi->max_speed_hz) ||
1191 (t->bits_per_word != spi->bits_per_word)) {
1192 par_override = 1;
1193 status = omap2_mcspi_setup_transfer(spi, t);
1194 if (status < 0)
1195 goto out;
1196 if (t->speed_hz == spi->max_speed_hz &&
1197 t->bits_per_word == spi->bits_per_word)
1198 par_override = 0;
Shubhrajyoti D5fda88f2012-05-10 18:27:45 +05301199 }
Michael Wellingb28cb942015-05-07 18:36:53 -05001200 if (cd && cd->cs_per_word) {
1201 chconf = mcspi->ctx.modulctrl;
1202 chconf &= ~OMAP2_MCSPI_MODULCTRL_SINGLE;
1203 mcspi_write_reg(master, OMAP2_MCSPI_MODULCTRL, chconf);
1204 mcspi->ctx.modulctrl =
1205 mcspi_read_cs_reg(spi, OMAP2_MCSPI_MODULCTRL);
1206 }
1207
Michael Wellingb28cb942015-05-07 18:36:53 -05001208 chconf = mcspi_cached_chconf0(spi);
1209 chconf &= ~OMAP2_MCSPI_CHCONF_TRM_MASK;
1210 chconf &= ~OMAP2_MCSPI_CHCONF_TURBO;
1211
1212 if (t->tx_buf == NULL)
1213 chconf |= OMAP2_MCSPI_CHCONF_TRM_RX_ONLY;
1214 else if (t->rx_buf == NULL)
1215 chconf |= OMAP2_MCSPI_CHCONF_TRM_TX_ONLY;
1216
1217 if (cd && cd->turbo_mode && t->tx_buf == NULL) {
1218 /* Turbo mode is for more than one word */
1219 if (t->len > ((cs->word_len + 7) >> 3))
1220 chconf |= OMAP2_MCSPI_CHCONF_TURBO;
1221 }
1222
1223 mcspi_write_chconf0(spi, chconf);
1224
1225 if (t->len) {
1226 unsigned count;
1227
1228 if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) &&
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -05001229 master->cur_msg_mapped &&
1230 master->can_dma(master, spi, t))
Michael Wellingb28cb942015-05-07 18:36:53 -05001231 omap2_mcspi_set_fifo(spi, t, 1);
1232
1233 omap2_mcspi_set_enable(spi, 1);
1234
1235 /* RX_ONLY mode needs dummy data in TX reg */
1236 if (t->tx_buf == NULL)
1237 writel_relaxed(0, cs->base
1238 + OMAP2_MCSPI_TX0);
1239
1240 if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) &&
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -05001241 master->cur_msg_mapped &&
1242 master->can_dma(master, spi, t))
Michael Wellingb28cb942015-05-07 18:36:53 -05001243 count = omap2_mcspi_txrx_dma(spi, t);
1244 else
1245 count = omap2_mcspi_txrx_pio(spi, t);
1246
1247 if (count != t->len) {
1248 status = -EIO;
1249 goto out;
1250 }
1251 }
1252
Michael Wellingb28cb942015-05-07 18:36:53 -05001253 omap2_mcspi_set_enable(spi, 0);
1254
1255 if (mcspi->fifo_depth > 0)
1256 omap2_mcspi_set_fifo(spi, t, 0);
1257
1258out:
Shubhrajyoti D5fda88f2012-05-10 18:27:45 +05301259 /* Restore defaults if they were overriden */
1260 if (par_override) {
1261 par_override = 0;
1262 status = omap2_mcspi_setup_transfer(spi, NULL);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001263 }
1264
Matthias Brugger5cbc7ca2013-01-24 13:40:41 +01001265 if (cd && cd->cs_per_word) {
1266 chconf = mcspi->ctx.modulctrl;
1267 chconf |= OMAP2_MCSPI_MODULCTRL_SINGLE;
1268 mcspi_write_reg(master, OMAP2_MCSPI_MODULCTRL, chconf);
1269 mcspi->ctx.modulctrl =
1270 mcspi_read_cs_reg(spi, OMAP2_MCSPI_MODULCTRL);
1271 }
1272
Shubhrajyoti D5fda88f2012-05-10 18:27:45 +05301273 omap2_mcspi_set_enable(spi, 0);
1274
Michael Wellinga06b4302015-05-23 21:13:44 -05001275 if (gpio_is_valid(spi->cs_gpio))
1276 omap2_mcspi_set_cs(spi, !(spi->mode & SPI_CS_HIGH));
1277
Illia Smyrnovd33f4732013-06-17 16:31:06 +03001278 if (mcspi->fifo_depth > 0 && t)
1279 omap2_mcspi_set_fifo(spi, t, 0);
Shubhrajyoti D5fda88f2012-05-10 18:27:45 +05301280
Michael Wellingb28cb942015-05-07 18:36:53 -05001281 return status;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001282}
1283
Neil Armstrong468a3202015-10-09 15:47:41 +02001284static int omap2_mcspi_prepare_message(struct spi_master *master,
1285 struct spi_message *msg)
1286{
1287 struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
1288 struct omap2_mcspi_regs *ctx = &mcspi->ctx;
1289 struct omap2_mcspi_cs *cs;
1290
1291 /* Only a single channel can have the FORCE bit enabled
1292 * in its chconf0 register.
1293 * Scan all channels and disable them except the current one.
1294 * A FORCE can remain from a last transfer having cs_change enabled
1295 */
1296 list_for_each_entry(cs, &ctx->cs, node) {
1297 if (msg->spi->controller_state == cs)
1298 continue;
1299
1300 if ((cs->chconf0 & OMAP2_MCSPI_CHCONF_FORCE)) {
1301 cs->chconf0 &= ~OMAP2_MCSPI_CHCONF_FORCE;
1302 writel_relaxed(cs->chconf0,
1303 cs->base + OMAP2_MCSPI_CHCONF0);
1304 readl_relaxed(cs->base + OMAP2_MCSPI_CHCONF0);
1305 }
1306 }
1307
1308 return 0;
1309}
1310
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -05001311static bool omap2_mcspi_can_dma(struct spi_master *master,
1312 struct spi_device *spi,
1313 struct spi_transfer *xfer)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001314{
Vignesh R89e8b9c2018-10-15 12:08:29 +05301315 struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master);
1316 struct omap2_mcspi_dma *mcspi_dma =
1317 &mcspi->dma_channels[spi->chip_select];
1318
1319 if (!mcspi_dma->dma_rx || !mcspi_dma->dma_tx)
1320 return false;
1321
1322 if (spi_controller_is_slave(master))
1323 return true;
1324
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -05001325 return (xfer->len >= DMA_MIN_BYTES);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001326}
1327
Vignesh R89e8b9c2018-10-15 12:08:29 +05301328static int omap2_mcspi_controller_setup(struct omap2_mcspi *mcspi)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001329{
1330 struct spi_master *master = mcspi->master;
Benoit Cousson1bd897f82012-03-26 15:32:33 +05301331 struct omap2_mcspi_regs *ctx = &mcspi->ctx;
Benoit Cousson1bd897f82012-03-26 15:32:33 +05301332 int ret = 0;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001333
Shubhrajyoti D034d3dc2012-08-22 11:35:12 +05301334 ret = pm_runtime_get_sync(mcspi->dev);
Tony Lindgren5a686b22018-04-27 08:50:07 -07001335 if (ret < 0) {
1336 pm_runtime_put_noidle(mcspi->dev);
1337
Govindraj.R1f1a4382011-02-02 17:52:15 +05301338 return ret;
Tony Lindgren5a686b22018-04-27 08:50:07 -07001339 }
Jouni Hoganderddb22192009-07-29 15:02:11 -07001340
Shubhrajyoti D39f80522012-03-29 22:11:07 +05301341 mcspi_write_reg(master, OMAP2_MCSPI_WAKEUPENABLE,
Matthias Brugger18dd6192013-01-24 13:28:58 +01001342 OMAP2_MCSPI_WAKEUPENABLE_WKEN);
Shubhrajyoti D39f80522012-03-29 22:11:07 +05301343 ctx->wakeupenable = OMAP2_MCSPI_WAKEUPENABLE_WKEN;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001344
Vignesh R89e8b9c2018-10-15 12:08:29 +05301345 omap2_mcspi_set_mode(master);
Shubhrajyoti D034d3dc2012-08-22 11:35:12 +05301346 pm_runtime_mark_last_busy(mcspi->dev);
1347 pm_runtime_put_autosuspend(mcspi->dev);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001348 return 0;
1349}
1350
Tony Lindgren52e9a5b2018-04-25 07:08:43 -07001351/*
1352 * When SPI wake up from off-mode, CS is in activate state. If it was in
1353 * inactive state when driver was suspend, then force it to inactive state at
1354 * wake up.
1355 */
Govindraj.R1f1a4382011-02-02 17:52:15 +05301356static int omap_mcspi_runtime_resume(struct device *dev)
1357{
Tony Lindgren52e9a5b2018-04-25 07:08:43 -07001358 struct spi_master *master = dev_get_drvdata(dev);
1359 struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
1360 struct omap2_mcspi_regs *ctx = &mcspi->ctx;
1361 struct omap2_mcspi_cs *cs;
Govindraj.R1f1a4382011-02-02 17:52:15 +05301362
Tony Lindgren52e9a5b2018-04-25 07:08:43 -07001363 /* McSPI: context restore */
1364 mcspi_write_reg(master, OMAP2_MCSPI_MODULCTRL, ctx->modulctrl);
1365 mcspi_write_reg(master, OMAP2_MCSPI_WAKEUPENABLE, ctx->wakeupenable);
1366
1367 list_for_each_entry(cs, &ctx->cs, node) {
1368 /*
1369 * We need to toggle CS state for OMAP take this
1370 * change in account.
1371 */
1372 if ((cs->chconf0 & OMAP2_MCSPI_CHCONF_FORCE) == 0) {
1373 cs->chconf0 |= OMAP2_MCSPI_CHCONF_FORCE;
1374 writel_relaxed(cs->chconf0,
1375 cs->base + OMAP2_MCSPI_CHCONF0);
1376 cs->chconf0 &= ~OMAP2_MCSPI_CHCONF_FORCE;
1377 writel_relaxed(cs->chconf0,
1378 cs->base + OMAP2_MCSPI_CHCONF0);
1379 } else {
1380 writel_relaxed(cs->chconf0,
1381 cs->base + OMAP2_MCSPI_CHCONF0);
1382 }
1383 }
Govindraj.R1f1a4382011-02-02 17:52:15 +05301384
1385 return 0;
1386}
1387
Benoit Coussond5a80032012-02-15 18:37:34 +01001388static struct omap2_mcspi_platform_config omap2_pdata = {
1389 .regs_offset = 0,
1390};
1391
1392static struct omap2_mcspi_platform_config omap4_pdata = {
1393 .regs_offset = OMAP4_MCSPI_REG_OFFSET,
1394};
1395
1396static const struct of_device_id omap_mcspi_of_match[] = {
1397 {
1398 .compatible = "ti,omap2-mcspi",
1399 .data = &omap2_pdata,
1400 },
1401 {
1402 .compatible = "ti,omap4-mcspi",
1403 .data = &omap4_pdata,
1404 },
1405 { },
1406};
1407MODULE_DEVICE_TABLE(of, omap_mcspi_of_match);
Girishccc7bae2008-02-06 01:38:16 -08001408
Grant Likelyfd4a3192012-12-07 16:57:14 +00001409static int omap2_mcspi_probe(struct platform_device *pdev)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001410{
1411 struct spi_master *master;
Uwe Kleine-König83a01e72012-05-21 21:57:39 +02001412 const struct omap2_mcspi_platform_config *pdata;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001413 struct omap2_mcspi *mcspi;
1414 struct resource *r;
1415 int status = 0, i;
Benoit Coussond5a80032012-02-15 18:37:34 +01001416 u32 regs_offset = 0;
Benoit Coussond5a80032012-02-15 18:37:34 +01001417 struct device_node *node = pdev->dev.of_node;
1418 const struct of_device_id *match;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001419
Vignesh R89e8b9c2018-10-15 12:08:29 +05301420 if (of_property_read_bool(node, "spi-slave"))
1421 master = spi_alloc_slave(&pdev->dev, sizeof(*mcspi));
1422 else
1423 master = spi_alloc_master(&pdev->dev, sizeof(*mcspi));
1424 if (!master)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001425 return -ENOMEM;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001426
David Brownelle7db06b2009-06-17 16:26:04 -07001427 /* the spi->mode bits understood by this driver: */
1428 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
Stephen Warren24778be2013-05-21 20:36:35 -06001429 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001430 master->setup = omap2_mcspi_setup;
Mark Brownf0278a12013-07-28 15:34:37 +01001431 master->auto_runtime_pm = true;
Neil Armstrong468a3202015-10-09 15:47:41 +02001432 master->prepare_message = omap2_mcspi_prepare_message;
Franklin S Cooper Jr0ba18702016-07-07 12:17:50 -05001433 master->can_dma = omap2_mcspi_can_dma;
Michael Wellingb28cb942015-05-07 18:36:53 -05001434 master->transfer_one = omap2_mcspi_transfer_one;
Michael Wellingddcad7e2015-05-12 12:38:57 -05001435 master->set_cs = omap2_mcspi_set_cs;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001436 master->cleanup = omap2_mcspi_cleanup;
Vignesh R89e8b9c2018-10-15 12:08:29 +05301437 master->slave_abort = omap2_mcspi_slave_abort;
Benoit Coussond5a80032012-02-15 18:37:34 +01001438 master->dev.of_node = node;
Axel Linaca09242014-02-18 22:02:47 +08001439 master->max_speed_hz = OMAP2_MCSPI_MAX_FREQ;
1440 master->min_speed_hz = OMAP2_MCSPI_MAX_FREQ >> 15;
Benoit Coussond5a80032012-02-15 18:37:34 +01001441
Jingoo Han24b5a822013-05-23 19:20:40 +09001442 platform_set_drvdata(pdev, master);
Daniel Mack0384e902012-10-07 18:19:44 +02001443
1444 mcspi = spi_master_get_devdata(master);
1445 mcspi->master = master;
1446
Benoit Coussond5a80032012-02-15 18:37:34 +01001447 match = of_match_device(omap_mcspi_of_match, &pdev->dev);
1448 if (match) {
1449 u32 num_cs = 1; /* default number of chipselect */
1450 pdata = match->data;
1451
1452 of_property_read_u32(node, "ti,spi-num-cs", &num_cs);
1453 master->num_chipselect = num_cs;
Daniel Mack2cd45172012-11-14 11:14:26 +08001454 if (of_get_property(node, "ti,pindir-d0-out-d1-in", NULL))
1455 mcspi->pin_dir = MCSPI_PINDIR_D0_OUT_D1_IN;
Benoit Coussond5a80032012-02-15 18:37:34 +01001456 } else {
Jingoo Han8074cf02013-07-30 16:58:59 +09001457 pdata = dev_get_platdata(&pdev->dev);
Benoit Coussond5a80032012-02-15 18:37:34 +01001458 master->num_chipselect = pdata->num_cs;
Daniel Mack0384e902012-10-07 18:19:44 +02001459 mcspi->pin_dir = pdata->pin_dir;
Benoit Coussond5a80032012-02-15 18:37:34 +01001460 }
1461 regs_offset = pdata->regs_offset;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001462
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001463 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Thierry Redingb0ee5602013-01-21 11:09:18 +01001464 mcspi->base = devm_ioremap_resource(&pdev->dev, r);
1465 if (IS_ERR(mcspi->base)) {
1466 status = PTR_ERR(mcspi->base);
Shubhrajyoti D1a77b122012-03-17 12:44:01 +05301467 goto free_master;
Russell King55c381e2008-09-04 14:07:22 +01001468 }
Vikram Naf9e53f2016-09-30 19:53:11 +05301469 mcspi->phys = r->start + regs_offset;
1470 mcspi->base += regs_offset;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001471
Govindraj.R1f1a4382011-02-02 17:52:15 +05301472 mcspi->dev = &pdev->dev;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001473
Benoit Cousson1bd897f82012-03-26 15:32:33 +05301474 INIT_LIST_HEAD(&mcspi->ctx.cs);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001475
Axel Lina6f936d2014-03-29 21:37:44 +08001476 mcspi->dma_channels = devm_kcalloc(&pdev->dev, master->num_chipselect,
1477 sizeof(struct omap2_mcspi_dma),
1478 GFP_KERNEL);
1479 if (mcspi->dma_channels == NULL) {
1480 status = -ENOMEM;
Shubhrajyoti D1a77b122012-03-17 12:44:01 +05301481 goto free_master;
Axel Lina6f936d2014-03-29 21:37:44 +08001482 }
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001483
Charulatha V1a5d8192011-02-02 17:52:14 +05301484 for (i = 0; i < master->num_chipselect; i++) {
Peter Ujfalusib085c612016-04-29 16:11:56 +03001485 sprintf(mcspi->dma_channels[i].dma_rx_ch_name, "rx%d", i);
1486 sprintf(mcspi->dma_channels[i].dma_tx_ch_name, "tx%d", i);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001487 }
1488
Vignesh R89e8b9c2018-10-15 12:08:29 +05301489 status = platform_get_irq(pdev, 0);
1490 if (status == -EPROBE_DEFER)
1491 goto free_master;
1492 if (status < 0) {
1493 dev_err(&pdev->dev, "no irq resource found\n");
1494 goto free_master;
1495 }
1496 init_completion(&mcspi->txdone);
1497 status = devm_request_irq(&pdev->dev, status,
1498 omap2_mcspi_irq_handler, 0, pdev->name,
1499 mcspi);
1500 if (status) {
1501 dev_err(&pdev->dev, "Cannot request IRQ");
1502 goto free_master;
1503 }
1504
Shubhrajyoti D27b52842012-03-26 17:04:22 +05301505 pm_runtime_use_autosuspend(&pdev->dev);
1506 pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
Govindraj.R1f1a4382011-02-02 17:52:15 +05301507 pm_runtime_enable(&pdev->dev);
1508
Vignesh R89e8b9c2018-10-15 12:08:29 +05301509 status = omap2_mcspi_controller_setup(mcspi);
Wei Yongjun142e07b2013-04-18 11:14:59 +08001510 if (status < 0)
Shubhrajyoti D39f1b562011-10-28 17:14:19 +05301511 goto disable_pm;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001512
Vignesh R89e8b9c2018-10-15 12:08:29 +05301513 status = devm_spi_register_controller(&pdev->dev, master);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001514 if (status < 0)
Shubhrajyoti D37a2d842012-08-02 16:41:25 +05301515 goto disable_pm;
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001516
1517 return status;
1518
Shubhrajyoti D39f1b562011-10-28 17:14:19 +05301519disable_pm:
Tony Lindgren0e6f3572016-02-10 15:02:46 -08001520 pm_runtime_dont_use_autosuspend(&pdev->dev);
1521 pm_runtime_put_sync(&pdev->dev);
Shubhrajyoti D751c9252011-10-28 17:14:18 +05301522 pm_runtime_disable(&pdev->dev);
Shubhrajyoti D39f1b562011-10-28 17:14:19 +05301523free_master:
Shubhrajyoti D37a2d842012-08-02 16:41:25 +05301524 spi_master_put(master);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001525 return status;
1526}
1527
Grant Likelyfd4a3192012-12-07 16:57:14 +00001528static int omap2_mcspi_remove(struct platform_device *pdev)
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001529{
Axel Lina6f936d2014-03-29 21:37:44 +08001530 struct spi_master *master = platform_get_drvdata(pdev);
1531 struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001532
Tony Lindgren0e6f3572016-02-10 15:02:46 -08001533 pm_runtime_dont_use_autosuspend(mcspi->dev);
Shubhrajyoti Da93a2022012-08-22 11:35:14 +05301534 pm_runtime_put_sync(mcspi->dev);
Shubhrajyoti D751c9252011-10-28 17:14:18 +05301535 pm_runtime_disable(&pdev->dev);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001536
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001537 return 0;
1538}
1539
Kay Sievers7e38c3c2008-04-10 21:29:20 -07001540/* work with hotplug and coldplug */
1541MODULE_ALIAS("platform:omap2_mcspi");
1542
Tony Lindgren91b9dee2018-11-15 15:59:39 -08001543static int __maybe_unused omap2_mcspi_suspend(struct device *dev)
Gregory CLEMENT42ce7fd2010-12-29 11:52:53 +01001544{
Tony Lindgren91b9dee2018-11-15 15:59:39 -08001545 struct spi_master *master = dev_get_drvdata(dev);
1546 struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
1547 int error;
1548
1549 error = pinctrl_pm_select_sleep_state(dev);
1550 if (error)
1551 dev_warn(mcspi->dev, "%s: failed to set pins: %i\n",
1552 __func__, error);
1553
1554 error = spi_master_suspend(master);
1555 if (error)
1556 dev_warn(mcspi->dev, "%s: master suspend failed: %i\n",
1557 __func__, error);
1558
1559 return pm_runtime_force_suspend(dev);
Pascal Huerstbeca3652015-11-19 16:18:28 +01001560}
1561
Tony Lindgren91b9dee2018-11-15 15:59:39 -08001562static int __maybe_unused omap2_mcspi_resume(struct device *dev)
Tony Lindgren5a686b22018-04-27 08:50:07 -07001563{
1564 struct spi_master *master = dev_get_drvdata(dev);
1565 struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
1566 int error;
1567
1568 error = pinctrl_pm_select_default_state(dev);
1569 if (error)
1570 dev_warn(mcspi->dev, "%s: failed to set pins: %i\n",
1571 __func__, error);
1572
Tony Lindgren91b9dee2018-11-15 15:59:39 -08001573 error = spi_master_resume(master);
1574 if (error)
1575 dev_warn(mcspi->dev, "%s: master resume failed: %i\n",
1576 __func__, error);
1577
1578 return pm_runtime_force_resume(dev);
Tony Lindgren5a686b22018-04-27 08:50:07 -07001579}
1580
Gregory CLEMENT42ce7fd2010-12-29 11:52:53 +01001581static const struct dev_pm_ops omap2_mcspi_pm_ops = {
Tony Lindgren91b9dee2018-11-15 15:59:39 -08001582 SET_SYSTEM_SLEEP_PM_OPS(omap2_mcspi_suspend,
1583 omap2_mcspi_resume)
Govindraj.R1f1a4382011-02-02 17:52:15 +05301584 .runtime_resume = omap_mcspi_runtime_resume,
Gregory CLEMENT42ce7fd2010-12-29 11:52:53 +01001585};
1586
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001587static struct platform_driver omap2_mcspi_driver = {
1588 .driver = {
1589 .name = "omap2_mcspi",
Benoit Coussond5a80032012-02-15 18:37:34 +01001590 .pm = &omap2_mcspi_pm_ops,
1591 .of_match_table = omap_mcspi_of_match,
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001592 },
Felipe Balbi7d6b6d82012-03-14 11:18:30 +02001593 .probe = omap2_mcspi_probe,
Grant Likelyfd4a3192012-12-07 16:57:14 +00001594 .remove = omap2_mcspi_remove,
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001595};
1596
Felipe Balbi9fdca9d2012-03-14 11:18:31 +02001597module_platform_driver(omap2_mcspi_driver);
Samuel Ortizccdc7bf2007-07-17 04:04:13 -07001598MODULE_LICENSE("GPL");