blob: 38824a994131a29e512c63745d6bcd54fd19d226 [file] [log] [blame]
Magnus Damm8051eff2009-11-26 11:10:05 +00001/*
2 * SuperH MSIOF SPI Master Interface
3 *
4 * Copyright (c) 2009 Magnus Damm
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
Magnus Damm8051eff2009-11-26 11:10:05 +000012#include <linux/bitmap.h>
13#include <linux/clk.h>
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +010014#include <linux/completion.h>
15#include <linux/delay.h>
Magnus Dammac48eee2010-01-20 13:49:45 -070016#include <linux/err.h>
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +010017#include <linux/gpio.h>
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +010018#include <linux/interrupt.h>
19#include <linux/io.h>
20#include <linux/kernel.h>
Paul Gortmakerd7614de2011-07-03 15:44:29 -040021#include <linux/module.h>
Bastian Hechtcf9c86e2012-12-12 12:54:48 +010022#include <linux/of.h>
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +010023#include <linux/of_device.h>
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +010024#include <linux/platform_device.h>
25#include <linux/pm_runtime.h>
Magnus Damm8051eff2009-11-26 11:10:05 +000026
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +010027#include <linux/spi/sh_msiof.h>
Magnus Damm8051eff2009-11-26 11:10:05 +000028#include <linux/spi/spi.h>
Magnus Damm8051eff2009-11-26 11:10:05 +000029
Magnus Damm8051eff2009-11-26 11:10:05 +000030#include <asm/unaligned.h>
31
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +010032
33struct sh_msiof_chipdata {
34 u16 tx_fifo_size;
35 u16 rx_fifo_size;
Geert Uytterhoevenbeb74bb2014-02-25 11:21:10 +010036 u16 master_flags;
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +010037};
38
Magnus Damm8051eff2009-11-26 11:10:05 +000039struct sh_msiof_spi_priv {
Magnus Damm8051eff2009-11-26 11:10:05 +000040 void __iomem *mapbase;
41 struct clk *clk;
42 struct platform_device *pdev;
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +010043 const struct sh_msiof_chipdata *chipdata;
Magnus Damm8051eff2009-11-26 11:10:05 +000044 struct sh_msiof_spi_info *info;
45 struct completion done;
Magnus Damm8051eff2009-11-26 11:10:05 +000046 int tx_fifo_size;
47 int rx_fifo_size;
48};
49
Geert Uytterhoeven01cfef52014-02-20 15:43:03 +010050#define TMDR1 0x00 /* Transmit Mode Register 1 */
51#define TMDR2 0x04 /* Transmit Mode Register 2 */
52#define TMDR3 0x08 /* Transmit Mode Register 3 */
53#define RMDR1 0x10 /* Receive Mode Register 1 */
54#define RMDR2 0x14 /* Receive Mode Register 2 */
55#define RMDR3 0x18 /* Receive Mode Register 3 */
56#define TSCR 0x20 /* Transmit Clock Select Register */
57#define RSCR 0x22 /* Receive Clock Select Register (SH, A1, APE6) */
58#define CTR 0x28 /* Control Register */
59#define FCTR 0x30 /* FIFO Control Register */
60#define STR 0x40 /* Status Register */
61#define IER 0x44 /* Interrupt Enable Register */
62#define TDR1 0x48 /* Transmit Control Data Register 1 (SH, A1) */
63#define TDR2 0x4c /* Transmit Control Data Register 2 (SH, A1) */
64#define TFDR 0x50 /* Transmit FIFO Data Register */
65#define RDR1 0x58 /* Receive Control Data Register 1 (SH, A1) */
66#define RDR2 0x5c /* Receive Control Data Register 2 (SH, A1) */
67#define RFDR 0x60 /* Receive FIFO Data Register */
Magnus Damm8051eff2009-11-26 11:10:05 +000068
Geert Uytterhoeven01cfef52014-02-20 15:43:03 +010069/* TMDR1 and RMDR1 */
70#define MDR1_TRMD 0x80000000 /* Transfer Mode (1 = Master mode) */
71#define MDR1_SYNCMD_MASK 0x30000000 /* SYNC Mode */
72#define MDR1_SYNCMD_SPI 0x20000000 /* Level mode/SPI */
73#define MDR1_SYNCMD_LR 0x30000000 /* L/R mode */
74#define MDR1_SYNCAC_SHIFT 25 /* Sync Polarity (1 = Active-low) */
75#define MDR1_BITLSB_SHIFT 24 /* MSB/LSB First (1 = LSB first) */
76#define MDR1_FLD_MASK 0x000000c0 /* Frame Sync Signal Interval (0-3) */
77#define MDR1_FLD_SHIFT 2
78#define MDR1_XXSTP 0x00000001 /* Transmission/Reception Stop on FIFO */
79/* TMDR1 */
80#define TMDR1_PCON 0x40000000 /* Transfer Signal Connection */
Magnus Damm8051eff2009-11-26 11:10:05 +000081
Geert Uytterhoeven01cfef52014-02-20 15:43:03 +010082/* TMDR2 and RMDR2 */
83#define MDR2_BITLEN1(i) (((i) - 1) << 24) /* Data Size (8-32 bits) */
84#define MDR2_WDLEN1(i) (((i) - 1) << 16) /* Word Count (1-64/256 (SH, A1))) */
85#define MDR2_GRPMASK1 0x00000001 /* Group Output Mask 1 (SH, A1) */
86
87/* TSCR and RSCR */
88#define SCR_BRPS_MASK 0x1f00 /* Prescaler Setting (1-32) */
89#define SCR_BRPS(i) (((i) - 1) << 8)
90#define SCR_BRDV_MASK 0x0007 /* Baud Rate Generator's Division Ratio */
91#define SCR_BRDV_DIV_2 0x0000
92#define SCR_BRDV_DIV_4 0x0001
93#define SCR_BRDV_DIV_8 0x0002
94#define SCR_BRDV_DIV_16 0x0003
95#define SCR_BRDV_DIV_32 0x0004
96#define SCR_BRDV_DIV_1 0x0007
97
98/* CTR */
99#define CTR_TSCKIZ_MASK 0xc0000000 /* Transmit Clock I/O Polarity Select */
100#define CTR_TSCKIZ_SCK 0x80000000 /* Disable SCK when TX disabled */
101#define CTR_TSCKIZ_POL_SHIFT 30 /* Transmit Clock Polarity */
102#define CTR_RSCKIZ_MASK 0x30000000 /* Receive Clock Polarity Select */
103#define CTR_RSCKIZ_SCK 0x20000000 /* Must match CTR_TSCKIZ_SCK */
104#define CTR_RSCKIZ_POL_SHIFT 28 /* Receive Clock Polarity */
105#define CTR_TEDG_SHIFT 27 /* Transmit Timing (1 = falling edge) */
106#define CTR_REDG_SHIFT 26 /* Receive Timing (1 = falling edge) */
107#define CTR_TXDIZ_MASK 0x00c00000 /* Pin Output When TX is Disabled */
108#define CTR_TXDIZ_LOW 0x00000000 /* 0 */
109#define CTR_TXDIZ_HIGH 0x00400000 /* 1 */
110#define CTR_TXDIZ_HIZ 0x00800000 /* High-impedance */
111#define CTR_TSCKE 0x00008000 /* Transmit Serial Clock Output Enable */
112#define CTR_TFSE 0x00004000 /* Transmit Frame Sync Signal Output Enable */
113#define CTR_TXE 0x00000200 /* Transmit Enable */
114#define CTR_RXE 0x00000100 /* Receive Enable */
115
Geert Uytterhoeven2e2b3682014-06-20 12:16:16 +0200116/* FCTR */
117#define FCTR_TFWM_MASK 0xe0000000 /* Transmit FIFO Watermark */
118#define FCTR_TFWM_64 0x00000000 /* Transfer Request when 64 empty stages */
119#define FCTR_TFWM_32 0x20000000 /* Transfer Request when 32 empty stages */
120#define FCTR_TFWM_24 0x40000000 /* Transfer Request when 24 empty stages */
121#define FCTR_TFWM_16 0x60000000 /* Transfer Request when 16 empty stages */
122#define FCTR_TFWM_12 0x80000000 /* Transfer Request when 12 empty stages */
123#define FCTR_TFWM_8 0xa0000000 /* Transfer Request when 8 empty stages */
124#define FCTR_TFWM_4 0xc0000000 /* Transfer Request when 4 empty stages */
125#define FCTR_TFWM_1 0xe0000000 /* Transfer Request when 1 empty stage */
126#define FCTR_TFUA_MASK 0x07f00000 /* Transmit FIFO Usable Area */
127#define FCTR_TFUA_SHIFT 20
128#define FCTR_TFUA(i) ((i) << FCTR_TFUA_SHIFT)
129#define FCTR_RFWM_MASK 0x0000e000 /* Receive FIFO Watermark */
130#define FCTR_RFWM_1 0x00000000 /* Transfer Request when 1 valid stages */
131#define FCTR_RFWM_4 0x00002000 /* Transfer Request when 4 valid stages */
132#define FCTR_RFWM_8 0x00004000 /* Transfer Request when 8 valid stages */
133#define FCTR_RFWM_16 0x00006000 /* Transfer Request when 16 valid stages */
134#define FCTR_RFWM_32 0x00008000 /* Transfer Request when 32 valid stages */
135#define FCTR_RFWM_64 0x0000a000 /* Transfer Request when 64 valid stages */
136#define FCTR_RFWM_128 0x0000c000 /* Transfer Request when 128 valid stages */
137#define FCTR_RFWM_256 0x0000e000 /* Transfer Request when 256 valid stages */
138#define FCTR_RFUA_MASK 0x00001ff0 /* Receive FIFO Usable Area (0x40 = full) */
139#define FCTR_RFUA_SHIFT 4
140#define FCTR_RFUA(i) ((i) << FCTR_RFUA_SHIFT)
141
142/* STR */
143#define STR_TFEMP 0x20000000 /* Transmit FIFO Empty */
144#define STR_TDREQ 0x10000000 /* Transmit Data Transfer Request */
Geert Uytterhoeven01cfef52014-02-20 15:43:03 +0100145#define STR_TEOF 0x00800000 /* Frame Transmission End */
Geert Uytterhoeven2e2b3682014-06-20 12:16:16 +0200146#define STR_TFSERR 0x00200000 /* Transmit Frame Synchronization Error */
147#define STR_TFOVF 0x00100000 /* Transmit FIFO Overflow */
148#define STR_TFUDF 0x00080000 /* Transmit FIFO Underflow */
149#define STR_RFFUL 0x00002000 /* Receive FIFO Full */
150#define STR_RDREQ 0x00001000 /* Receive Data Transfer Request */
Geert Uytterhoeven01cfef52014-02-20 15:43:03 +0100151#define STR_REOF 0x00000080 /* Frame Reception End */
Geert Uytterhoeven2e2b3682014-06-20 12:16:16 +0200152#define STR_RFSERR 0x00000020 /* Receive Frame Synchronization Error */
153#define STR_RFUDF 0x00000010 /* Receive FIFO Underflow */
154#define STR_RFOVF 0x00000008 /* Receive FIFO Overflow */
155
156/* IER */
157#define IER_TDMAE 0x80000000 /* Transmit Data DMA Transfer Req. Enable */
158#define IER_TFEMPE 0x20000000 /* Transmit FIFO Empty Enable */
159#define IER_TDREQE 0x10000000 /* Transmit Data Transfer Request Enable */
160#define IER_TEOFE 0x00800000 /* Frame Transmission End Enable */
161#define IER_TFSERRE 0x00200000 /* Transmit Frame Sync Error Enable */
162#define IER_TFOVFE 0x00100000 /* Transmit FIFO Overflow Enable */
163#define IER_TFUDFE 0x00080000 /* Transmit FIFO Underflow Enable */
164#define IER_RDMAE 0x00008000 /* Receive Data DMA Transfer Req. Enable */
165#define IER_RFFULE 0x00002000 /* Receive FIFO Full Enable */
166#define IER_RDREQE 0x00001000 /* Receive Data Transfer Request Enable */
167#define IER_REOFE 0x00000080 /* Frame Reception End Enable */
168#define IER_RFSERRE 0x00000020 /* Receive Frame Sync Error Enable */
169#define IER_RFUDFE 0x00000010 /* Receive FIFO Underflow Enable */
170#define IER_RFOVFE 0x00000008 /* Receive FIFO Overflow Enable */
Geert Uytterhoeven01cfef52014-02-20 15:43:03 +0100171
Magnus Damm8051eff2009-11-26 11:10:05 +0000172
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100173static u32 sh_msiof_read(struct sh_msiof_spi_priv *p, int reg_offs)
Magnus Damm8051eff2009-11-26 11:10:05 +0000174{
175 switch (reg_offs) {
176 case TSCR:
177 case RSCR:
178 return ioread16(p->mapbase + reg_offs);
179 default:
180 return ioread32(p->mapbase + reg_offs);
181 }
182}
183
184static void sh_msiof_write(struct sh_msiof_spi_priv *p, int reg_offs,
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100185 u32 value)
Magnus Damm8051eff2009-11-26 11:10:05 +0000186{
187 switch (reg_offs) {
188 case TSCR:
189 case RSCR:
190 iowrite16(value, p->mapbase + reg_offs);
191 break;
192 default:
193 iowrite32(value, p->mapbase + reg_offs);
194 break;
195 }
196}
197
198static int sh_msiof_modify_ctr_wait(struct sh_msiof_spi_priv *p,
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100199 u32 clr, u32 set)
Magnus Damm8051eff2009-11-26 11:10:05 +0000200{
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100201 u32 mask = clr | set;
202 u32 data;
Magnus Damm8051eff2009-11-26 11:10:05 +0000203 int k;
204
205 data = sh_msiof_read(p, CTR);
206 data &= ~clr;
207 data |= set;
208 sh_msiof_write(p, CTR, data);
209
210 for (k = 100; k > 0; k--) {
211 if ((sh_msiof_read(p, CTR) & mask) == set)
212 break;
213
214 udelay(10);
215 }
216
217 return k > 0 ? 0 : -ETIMEDOUT;
218}
219
220static irqreturn_t sh_msiof_spi_irq(int irq, void *data)
221{
222 struct sh_msiof_spi_priv *p = data;
223
224 /* just disable the interrupt and wake up */
225 sh_msiof_write(p, IER, 0);
226 complete(&p->done);
227
228 return IRQ_HANDLED;
229}
230
231static struct {
232 unsigned short div;
233 unsigned short scr;
234} const sh_msiof_spi_clk_table[] = {
Geert Uytterhoeven01cfef52014-02-20 15:43:03 +0100235 { 1, SCR_BRPS( 1) | SCR_BRDV_DIV_1 },
236 { 2, SCR_BRPS( 1) | SCR_BRDV_DIV_2 },
237 { 4, SCR_BRPS( 1) | SCR_BRDV_DIV_4 },
238 { 8, SCR_BRPS( 1) | SCR_BRDV_DIV_8 },
239 { 16, SCR_BRPS( 1) | SCR_BRDV_DIV_16 },
240 { 32, SCR_BRPS( 1) | SCR_BRDV_DIV_32 },
241 { 64, SCR_BRPS(32) | SCR_BRDV_DIV_2 },
242 { 128, SCR_BRPS(32) | SCR_BRDV_DIV_4 },
243 { 256, SCR_BRPS(32) | SCR_BRDV_DIV_8 },
244 { 512, SCR_BRPS(32) | SCR_BRDV_DIV_16 },
245 { 1024, SCR_BRPS(32) | SCR_BRDV_DIV_32 },
Magnus Damm8051eff2009-11-26 11:10:05 +0000246};
247
248static void sh_msiof_spi_set_clk_regs(struct sh_msiof_spi_priv *p,
Geert Uytterhoeven6a85fc52014-02-20 15:43:02 +0100249 unsigned long parent_rate, u32 spi_hz)
Magnus Damm8051eff2009-11-26 11:10:05 +0000250{
251 unsigned long div = 1024;
252 size_t k;
253
254 if (!WARN_ON(!spi_hz || !parent_rate))
Takashi Yoshiie4d313f2013-12-02 03:19:13 +0900255 div = DIV_ROUND_UP(parent_rate, spi_hz);
Magnus Damm8051eff2009-11-26 11:10:05 +0000256
257 /* TODO: make more fine grained */
258
259 for (k = 0; k < ARRAY_SIZE(sh_msiof_spi_clk_table); k++) {
260 if (sh_msiof_spi_clk_table[k].div >= div)
261 break;
262 }
263
264 k = min_t(int, k, ARRAY_SIZE(sh_msiof_spi_clk_table) - 1);
265
266 sh_msiof_write(p, TSCR, sh_msiof_spi_clk_table[k].scr);
Geert Uytterhoevenbeb74bb2014-02-25 11:21:10 +0100267 if (!(p->chipdata->master_flags & SPI_MASTER_MUST_TX))
268 sh_msiof_write(p, RSCR, sh_msiof_spi_clk_table[k].scr);
Magnus Damm8051eff2009-11-26 11:10:05 +0000269}
270
271static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p,
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100272 u32 cpol, u32 cpha,
Takashi Yoshii50a77992013-12-02 03:19:15 +0900273 u32 tx_hi_z, u32 lsb_first, u32 cs_high)
Magnus Damm8051eff2009-11-26 11:10:05 +0000274{
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100275 u32 tmp;
Magnus Damm8051eff2009-11-26 11:10:05 +0000276 int edge;
277
278 /*
Markus Pietreke8708ef2010-02-02 11:29:15 +0900279 * CPOL CPHA TSCKIZ RSCKIZ TEDG REDG
280 * 0 0 10 10 1 1
281 * 0 1 10 10 0 0
282 * 1 0 11 11 0 0
283 * 1 1 11 11 1 1
Magnus Damm8051eff2009-11-26 11:10:05 +0000284 */
Magnus Damm8051eff2009-11-26 11:10:05 +0000285 sh_msiof_write(p, FCTR, 0);
Takashi Yoshii50a77992013-12-02 03:19:15 +0900286
Geert Uytterhoeven01cfef52014-02-20 15:43:03 +0100287 tmp = MDR1_SYNCMD_SPI | 1 << MDR1_FLD_SHIFT | MDR1_XXSTP;
288 tmp |= !cs_high << MDR1_SYNCAC_SHIFT;
289 tmp |= lsb_first << MDR1_BITLSB_SHIFT;
290 sh_msiof_write(p, TMDR1, tmp | MDR1_TRMD | TMDR1_PCON);
Geert Uytterhoevenbeb74bb2014-02-25 11:21:10 +0100291 if (p->chipdata->master_flags & SPI_MASTER_MUST_TX) {
292 /* These bits are reserved if RX needs TX */
293 tmp &= ~0x0000ffff;
294 }
Geert Uytterhoeven01cfef52014-02-20 15:43:03 +0100295 sh_msiof_write(p, RMDR1, tmp);
Magnus Damm8051eff2009-11-26 11:10:05 +0000296
Geert Uytterhoeven01cfef52014-02-20 15:43:03 +0100297 tmp = 0;
298 tmp |= CTR_TSCKIZ_SCK | cpol << CTR_TSCKIZ_POL_SHIFT;
299 tmp |= CTR_RSCKIZ_SCK | cpol << CTR_RSCKIZ_POL_SHIFT;
Magnus Damm8051eff2009-11-26 11:10:05 +0000300
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100301 edge = cpol ^ !cpha;
Magnus Damm8051eff2009-11-26 11:10:05 +0000302
Geert Uytterhoeven01cfef52014-02-20 15:43:03 +0100303 tmp |= edge << CTR_TEDG_SHIFT;
304 tmp |= edge << CTR_REDG_SHIFT;
305 tmp |= tx_hi_z ? CTR_TXDIZ_HIZ : CTR_TXDIZ_LOW;
Magnus Damm8051eff2009-11-26 11:10:05 +0000306 sh_msiof_write(p, CTR, tmp);
307}
308
309static void sh_msiof_spi_set_mode_regs(struct sh_msiof_spi_priv *p,
310 const void *tx_buf, void *rx_buf,
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100311 u32 bits, u32 words)
Magnus Damm8051eff2009-11-26 11:10:05 +0000312{
Geert Uytterhoeven01cfef52014-02-20 15:43:03 +0100313 u32 dr2 = MDR2_BITLEN1(bits) | MDR2_WDLEN1(words);
Magnus Damm8051eff2009-11-26 11:10:05 +0000314
Geert Uytterhoevenbeb74bb2014-02-25 11:21:10 +0100315 if (tx_buf || (p->chipdata->master_flags & SPI_MASTER_MUST_TX))
Magnus Damm8051eff2009-11-26 11:10:05 +0000316 sh_msiof_write(p, TMDR2, dr2);
317 else
Geert Uytterhoeven01cfef52014-02-20 15:43:03 +0100318 sh_msiof_write(p, TMDR2, dr2 | MDR2_GRPMASK1);
Magnus Damm8051eff2009-11-26 11:10:05 +0000319
320 if (rx_buf)
321 sh_msiof_write(p, RMDR2, dr2);
322
323 sh_msiof_write(p, IER, STR_TEOF | STR_REOF);
324}
325
326static void sh_msiof_reset_str(struct sh_msiof_spi_priv *p)
327{
328 sh_msiof_write(p, STR, sh_msiof_read(p, STR));
329}
330
331static void sh_msiof_spi_write_fifo_8(struct sh_msiof_spi_priv *p,
332 const void *tx_buf, int words, int fs)
333{
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100334 const u8 *buf_8 = tx_buf;
Magnus Damm8051eff2009-11-26 11:10:05 +0000335 int k;
336
337 for (k = 0; k < words; k++)
338 sh_msiof_write(p, TFDR, buf_8[k] << fs);
339}
340
341static void sh_msiof_spi_write_fifo_16(struct sh_msiof_spi_priv *p,
342 const void *tx_buf, int words, int fs)
343{
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100344 const u16 *buf_16 = tx_buf;
Magnus Damm8051eff2009-11-26 11:10:05 +0000345 int k;
346
347 for (k = 0; k < words; k++)
348 sh_msiof_write(p, TFDR, buf_16[k] << fs);
349}
350
351static void sh_msiof_spi_write_fifo_16u(struct sh_msiof_spi_priv *p,
352 const void *tx_buf, int words, int fs)
353{
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100354 const u16 *buf_16 = tx_buf;
Magnus Damm8051eff2009-11-26 11:10:05 +0000355 int k;
356
357 for (k = 0; k < words; k++)
358 sh_msiof_write(p, TFDR, get_unaligned(&buf_16[k]) << fs);
359}
360
361static void sh_msiof_spi_write_fifo_32(struct sh_msiof_spi_priv *p,
362 const void *tx_buf, int words, int fs)
363{
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100364 const u32 *buf_32 = tx_buf;
Magnus Damm8051eff2009-11-26 11:10:05 +0000365 int k;
366
367 for (k = 0; k < words; k++)
368 sh_msiof_write(p, TFDR, buf_32[k] << fs);
369}
370
371static void sh_msiof_spi_write_fifo_32u(struct sh_msiof_spi_priv *p,
372 const void *tx_buf, int words, int fs)
373{
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100374 const u32 *buf_32 = tx_buf;
Magnus Damm8051eff2009-11-26 11:10:05 +0000375 int k;
376
377 for (k = 0; k < words; k++)
378 sh_msiof_write(p, TFDR, get_unaligned(&buf_32[k]) << fs);
379}
380
Guennadi Liakhovetski9dabb3f2011-01-21 16:56:42 +0100381static void sh_msiof_spi_write_fifo_s32(struct sh_msiof_spi_priv *p,
382 const void *tx_buf, int words, int fs)
383{
384 const u32 *buf_32 = tx_buf;
385 int k;
386
387 for (k = 0; k < words; k++)
388 sh_msiof_write(p, TFDR, swab32(buf_32[k] << fs));
389}
390
391static void sh_msiof_spi_write_fifo_s32u(struct sh_msiof_spi_priv *p,
392 const void *tx_buf, int words, int fs)
393{
394 const u32 *buf_32 = tx_buf;
395 int k;
396
397 for (k = 0; k < words; k++)
398 sh_msiof_write(p, TFDR, swab32(get_unaligned(&buf_32[k]) << fs));
399}
400
Magnus Damm8051eff2009-11-26 11:10:05 +0000401static void sh_msiof_spi_read_fifo_8(struct sh_msiof_spi_priv *p,
402 void *rx_buf, int words, int fs)
403{
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100404 u8 *buf_8 = rx_buf;
Magnus Damm8051eff2009-11-26 11:10:05 +0000405 int k;
406
407 for (k = 0; k < words; k++)
408 buf_8[k] = sh_msiof_read(p, RFDR) >> fs;
409}
410
411static void sh_msiof_spi_read_fifo_16(struct sh_msiof_spi_priv *p,
412 void *rx_buf, int words, int fs)
413{
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100414 u16 *buf_16 = rx_buf;
Magnus Damm8051eff2009-11-26 11:10:05 +0000415 int k;
416
417 for (k = 0; k < words; k++)
418 buf_16[k] = sh_msiof_read(p, RFDR) >> fs;
419}
420
421static void sh_msiof_spi_read_fifo_16u(struct sh_msiof_spi_priv *p,
422 void *rx_buf, int words, int fs)
423{
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100424 u16 *buf_16 = rx_buf;
Magnus Damm8051eff2009-11-26 11:10:05 +0000425 int k;
426
427 for (k = 0; k < words; k++)
428 put_unaligned(sh_msiof_read(p, RFDR) >> fs, &buf_16[k]);
429}
430
431static void sh_msiof_spi_read_fifo_32(struct sh_msiof_spi_priv *p,
432 void *rx_buf, int words, int fs)
433{
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100434 u32 *buf_32 = rx_buf;
Magnus Damm8051eff2009-11-26 11:10:05 +0000435 int k;
436
437 for (k = 0; k < words; k++)
438 buf_32[k] = sh_msiof_read(p, RFDR) >> fs;
439}
440
441static void sh_msiof_spi_read_fifo_32u(struct sh_msiof_spi_priv *p,
442 void *rx_buf, int words, int fs)
443{
Guennadi Liakhovetskie2dbf5e2011-01-21 16:56:37 +0100444 u32 *buf_32 = rx_buf;
Magnus Damm8051eff2009-11-26 11:10:05 +0000445 int k;
446
447 for (k = 0; k < words; k++)
448 put_unaligned(sh_msiof_read(p, RFDR) >> fs, &buf_32[k]);
449}
450
Guennadi Liakhovetski9dabb3f2011-01-21 16:56:42 +0100451static void sh_msiof_spi_read_fifo_s32(struct sh_msiof_spi_priv *p,
452 void *rx_buf, int words, int fs)
453{
454 u32 *buf_32 = rx_buf;
455 int k;
456
457 for (k = 0; k < words; k++)
458 buf_32[k] = swab32(sh_msiof_read(p, RFDR) >> fs);
459}
460
461static void sh_msiof_spi_read_fifo_s32u(struct sh_msiof_spi_priv *p,
462 void *rx_buf, int words, int fs)
463{
464 u32 *buf_32 = rx_buf;
465 int k;
466
467 for (k = 0; k < words; k++)
468 put_unaligned(swab32(sh_msiof_read(p, RFDR) >> fs), &buf_32[k]);
469}
470
Geert Uytterhoeven8d195342014-02-20 15:43:04 +0100471static int sh_msiof_spi_setup(struct spi_device *spi)
Magnus Damm8051eff2009-11-26 11:10:05 +0000472{
Geert Uytterhoeven8d195342014-02-20 15:43:04 +0100473 struct device_node *np = spi->master->dev.of_node;
Magnus Damm8051eff2009-11-26 11:10:05 +0000474 struct sh_msiof_spi_priv *p = spi_master_get_devdata(spi->master);
Magnus Damm8051eff2009-11-26 11:10:05 +0000475
Geert Uytterhoeven8d195342014-02-20 15:43:04 +0100476 if (!np) {
477 /*
478 * Use spi->controller_data for CS (same strategy as spi_gpio),
479 * if any. otherwise let HW control CS
480 */
481 spi->cs_gpio = (uintptr_t)spi->controller_data;
Magnus Damm8051eff2009-11-26 11:10:05 +0000482 }
483
Geert Uytterhoevenc833ff72014-02-25 11:21:11 +0100484 /* Configure pins before deasserting CS */
485 sh_msiof_spi_set_pin_regs(p, !!(spi->mode & SPI_CPOL),
486 !!(spi->mode & SPI_CPHA),
487 !!(spi->mode & SPI_3WIRE),
488 !!(spi->mode & SPI_LSB_FIRST),
489 !!(spi->mode & SPI_CS_HIGH));
Magnus Damm8051eff2009-11-26 11:10:05 +0000490
Geert Uytterhoeven1bd6363bc02014-02-25 11:21:13 +0100491 if (spi->cs_gpio >= 0)
492 gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
493
494 return 0;
Geert Uytterhoeven8d195342014-02-20 15:43:04 +0100495}
496
Geert Uytterhoevenc833ff72014-02-25 11:21:11 +0100497static int sh_msiof_prepare_message(struct spi_master *master,
498 struct spi_message *msg)
499{
500 struct sh_msiof_spi_priv *p = spi_master_get_devdata(master);
501 const struct spi_device *spi = msg->spi;
502
Geert Uytterhoevenc833ff72014-02-25 11:21:11 +0100503 /* Configure pins before asserting CS */
504 sh_msiof_spi_set_pin_regs(p, !!(spi->mode & SPI_CPOL),
505 !!(spi->mode & SPI_CPHA),
506 !!(spi->mode & SPI_3WIRE),
507 !!(spi->mode & SPI_LSB_FIRST),
508 !!(spi->mode & SPI_CS_HIGH));
509 return 0;
Magnus Damm8051eff2009-11-26 11:10:05 +0000510}
511
512static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p,
513 void (*tx_fifo)(struct sh_msiof_spi_priv *,
514 const void *, int, int),
515 void (*rx_fifo)(struct sh_msiof_spi_priv *,
516 void *, int, int),
517 const void *tx_buf, void *rx_buf,
518 int words, int bits)
519{
520 int fifo_shift;
521 int ret;
522
523 /* limit maximum word transfer to rx/tx fifo size */
524 if (tx_buf)
525 words = min_t(int, words, p->tx_fifo_size);
526 if (rx_buf)
527 words = min_t(int, words, p->rx_fifo_size);
528
529 /* the fifo contents need shifting */
530 fifo_shift = 32 - bits;
531
532 /* setup msiof transfer mode registers */
533 sh_msiof_spi_set_mode_regs(p, tx_buf, rx_buf, bits, words);
534
535 /* write tx fifo */
536 if (tx_buf)
537 tx_fifo(p, tx_buf, words, fifo_shift);
538
539 /* setup clock and rx/tx signals */
540 ret = sh_msiof_modify_ctr_wait(p, 0, CTR_TSCKE);
541 if (rx_buf)
542 ret = ret ? ret : sh_msiof_modify_ctr_wait(p, 0, CTR_RXE);
543 ret = ret ? ret : sh_msiof_modify_ctr_wait(p, 0, CTR_TXE);
544
545 /* start by setting frame bit */
Wolfram Sang16735d02013-11-14 14:32:02 -0800546 reinit_completion(&p->done);
Magnus Damm8051eff2009-11-26 11:10:05 +0000547 ret = ret ? ret : sh_msiof_modify_ctr_wait(p, 0, CTR_TFSE);
548 if (ret) {
549 dev_err(&p->pdev->dev, "failed to start hardware\n");
550 goto err;
551 }
552
553 /* wait for tx fifo to be emptied / rx fifo to be filled */
554 wait_for_completion(&p->done);
555
556 /* read rx fifo */
557 if (rx_buf)
558 rx_fifo(p, rx_buf, words, fifo_shift);
559
560 /* clear status bits */
561 sh_msiof_reset_str(p);
562
Geert Uytterhoevena669c112014-02-20 15:43:01 +0100563 /* shut down frame, rx/tx and clock signals */
Magnus Damm8051eff2009-11-26 11:10:05 +0000564 ret = sh_msiof_modify_ctr_wait(p, CTR_TFSE, 0);
565 ret = ret ? ret : sh_msiof_modify_ctr_wait(p, CTR_TXE, 0);
566 if (rx_buf)
567 ret = ret ? ret : sh_msiof_modify_ctr_wait(p, CTR_RXE, 0);
568 ret = ret ? ret : sh_msiof_modify_ctr_wait(p, CTR_TSCKE, 0);
569 if (ret) {
570 dev_err(&p->pdev->dev, "failed to shut down hardware\n");
571 goto err;
572 }
573
574 return words;
575
576 err:
577 sh_msiof_write(p, IER, 0);
578 return ret;
579}
580
Geert Uytterhoeven1bd6363bc02014-02-25 11:21:13 +0100581static int sh_msiof_transfer_one(struct spi_master *master,
582 struct spi_device *spi,
583 struct spi_transfer *t)
Magnus Damm8051eff2009-11-26 11:10:05 +0000584{
Geert Uytterhoeven1bd6363bc02014-02-25 11:21:13 +0100585 struct sh_msiof_spi_priv *p = spi_master_get_devdata(master);
Magnus Damm8051eff2009-11-26 11:10:05 +0000586 void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, int, int);
587 void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, int, int);
588 int bits;
589 int bytes_per_word;
590 int bytes_done;
591 int words;
592 int n;
Guennadi Liakhovetski9dabb3f2011-01-21 16:56:42 +0100593 bool swab;
Magnus Damm8051eff2009-11-26 11:10:05 +0000594
Axel Linb1415862014-03-02 22:30:32 +0800595 bits = t->bits_per_word;
Magnus Damm8051eff2009-11-26 11:10:05 +0000596
Guennadi Liakhovetski9dabb3f2011-01-21 16:56:42 +0100597 if (bits <= 8 && t->len > 15 && !(t->len & 3)) {
598 bits = 32;
599 swab = true;
600 } else {
601 swab = false;
602 }
603
Magnus Damm8051eff2009-11-26 11:10:05 +0000604 /* setup bytes per word and fifo read/write functions */
605 if (bits <= 8) {
606 bytes_per_word = 1;
607 tx_fifo = sh_msiof_spi_write_fifo_8;
608 rx_fifo = sh_msiof_spi_read_fifo_8;
609 } else if (bits <= 16) {
610 bytes_per_word = 2;
611 if ((unsigned long)t->tx_buf & 0x01)
612 tx_fifo = sh_msiof_spi_write_fifo_16u;
613 else
614 tx_fifo = sh_msiof_spi_write_fifo_16;
615
616 if ((unsigned long)t->rx_buf & 0x01)
617 rx_fifo = sh_msiof_spi_read_fifo_16u;
618 else
619 rx_fifo = sh_msiof_spi_read_fifo_16;
Guennadi Liakhovetski9dabb3f2011-01-21 16:56:42 +0100620 } else if (swab) {
621 bytes_per_word = 4;
622 if ((unsigned long)t->tx_buf & 0x03)
623 tx_fifo = sh_msiof_spi_write_fifo_s32u;
624 else
625 tx_fifo = sh_msiof_spi_write_fifo_s32;
626
627 if ((unsigned long)t->rx_buf & 0x03)
628 rx_fifo = sh_msiof_spi_read_fifo_s32u;
629 else
630 rx_fifo = sh_msiof_spi_read_fifo_s32;
Magnus Damm8051eff2009-11-26 11:10:05 +0000631 } else {
632 bytes_per_word = 4;
633 if ((unsigned long)t->tx_buf & 0x03)
634 tx_fifo = sh_msiof_spi_write_fifo_32u;
635 else
636 tx_fifo = sh_msiof_spi_write_fifo_32;
637
638 if ((unsigned long)t->rx_buf & 0x03)
639 rx_fifo = sh_msiof_spi_read_fifo_32u;
640 else
641 rx_fifo = sh_msiof_spi_read_fifo_32;
642 }
643
644 /* setup clocks (clock already enabled in chipselect()) */
Axel Linb1415862014-03-02 22:30:32 +0800645 sh_msiof_spi_set_clk_regs(p, clk_get_rate(p->clk), t->speed_hz);
Magnus Damm8051eff2009-11-26 11:10:05 +0000646
647 /* transfer in fifo sized chunks */
648 words = t->len / bytes_per_word;
649 bytes_done = 0;
650
651 while (bytes_done < t->len) {
Guennadi Liakhovetski8a6afb92011-01-21 16:56:47 +0100652 void *rx_buf = t->rx_buf ? t->rx_buf + bytes_done : NULL;
653 const void *tx_buf = t->tx_buf ? t->tx_buf + bytes_done : NULL;
Magnus Damm8051eff2009-11-26 11:10:05 +0000654 n = sh_msiof_spi_txrx_once(p, tx_fifo, rx_fifo,
Guennadi Liakhovetski8a6afb92011-01-21 16:56:47 +0100655 tx_buf,
656 rx_buf,
Magnus Damm8051eff2009-11-26 11:10:05 +0000657 words, bits);
658 if (n < 0)
659 break;
660
661 bytes_done += n * bytes_per_word;
662 words -= n;
663 }
664
Magnus Damm8051eff2009-11-26 11:10:05 +0000665 return 0;
666}
667
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +0100668static const struct sh_msiof_chipdata sh_data = {
669 .tx_fifo_size = 64,
670 .rx_fifo_size = 64,
Geert Uytterhoevenbeb74bb2014-02-25 11:21:10 +0100671 .master_flags = 0,
672};
673
674static const struct sh_msiof_chipdata r8a779x_data = {
675 .tx_fifo_size = 64,
676 .rx_fifo_size = 256,
677 .master_flags = SPI_MASTER_MUST_TX,
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +0100678};
679
680static const struct of_device_id sh_msiof_match[] = {
681 { .compatible = "renesas,sh-msiof", .data = &sh_data },
682 { .compatible = "renesas,sh-mobile-msiof", .data = &sh_data },
Geert Uytterhoevenbeb74bb2014-02-25 11:21:10 +0100683 { .compatible = "renesas,msiof-r8a7790", .data = &r8a779x_data },
684 { .compatible = "renesas,msiof-r8a7791", .data = &r8a779x_data },
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +0100685 {},
686};
687MODULE_DEVICE_TABLE(of, sh_msiof_match);
688
Bastian Hechtcf9c86e2012-12-12 12:54:48 +0100689#ifdef CONFIG_OF
690static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev)
691{
692 struct sh_msiof_spi_info *info;
693 struct device_node *np = dev->of_node;
Geert Uytterhoeven32d3b2d2014-02-25 11:21:08 +0100694 u32 num_cs = 1;
Bastian Hechtcf9c86e2012-12-12 12:54:48 +0100695
696 info = devm_kzalloc(dev, sizeof(struct sh_msiof_spi_info), GFP_KERNEL);
Jingoo Han1e8231b2014-04-29 17:21:25 +0900697 if (!info)
Bastian Hechtcf9c86e2012-12-12 12:54:48 +0100698 return NULL;
Bastian Hechtcf9c86e2012-12-12 12:54:48 +0100699
700 /* Parse the MSIOF properties */
701 of_property_read_u32(np, "num-cs", &num_cs);
702 of_property_read_u32(np, "renesas,tx-fifo-size",
703 &info->tx_fifo_override);
704 of_property_read_u32(np, "renesas,rx-fifo-size",
705 &info->rx_fifo_override);
706
707 info->num_chipselect = num_cs;
708
709 return info;
710}
711#else
712static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev)
713{
714 return NULL;
715}
716#endif
717
Magnus Damm8051eff2009-11-26 11:10:05 +0000718static int sh_msiof_spi_probe(struct platform_device *pdev)
719{
720 struct resource *r;
721 struct spi_master *master;
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +0100722 const struct of_device_id *of_id;
Magnus Damm8051eff2009-11-26 11:10:05 +0000723 struct sh_msiof_spi_priv *p;
Magnus Damm8051eff2009-11-26 11:10:05 +0000724 int i;
725 int ret;
726
727 master = spi_alloc_master(&pdev->dev, sizeof(struct sh_msiof_spi_priv));
728 if (master == NULL) {
729 dev_err(&pdev->dev, "failed to allocate spi master\n");
Laurent Pinchartb4dd05d2013-11-28 02:39:42 +0100730 return -ENOMEM;
Magnus Damm8051eff2009-11-26 11:10:05 +0000731 }
732
733 p = spi_master_get_devdata(master);
734
735 platform_set_drvdata(pdev, p);
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +0100736
737 of_id = of_match_device(sh_msiof_match, &pdev->dev);
738 if (of_id) {
739 p->chipdata = of_id->data;
Bastian Hechtcf9c86e2012-12-12 12:54:48 +0100740 p->info = sh_msiof_spi_parse_dt(&pdev->dev);
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +0100741 } else {
742 p->chipdata = (const void *)pdev->id_entry->driver_data;
Jingoo Han8074cf02013-07-30 16:58:59 +0900743 p->info = dev_get_platdata(&pdev->dev);
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +0100744 }
Bastian Hechtcf9c86e2012-12-12 12:54:48 +0100745
746 if (!p->info) {
747 dev_err(&pdev->dev, "failed to obtain device info\n");
748 ret = -ENXIO;
749 goto err1;
750 }
751
Magnus Damm8051eff2009-11-26 11:10:05 +0000752 init_completion(&p->done);
753
Laurent Pinchartb4dd05d2013-11-28 02:39:42 +0100754 p->clk = devm_clk_get(&pdev->dev, NULL);
Magnus Damm8051eff2009-11-26 11:10:05 +0000755 if (IS_ERR(p->clk)) {
Bastian Hecht078b6ea2012-11-07 12:40:04 +0100756 dev_err(&pdev->dev, "cannot get clock\n");
Magnus Damm8051eff2009-11-26 11:10:05 +0000757 ret = PTR_ERR(p->clk);
758 goto err1;
759 }
760
Magnus Damm8051eff2009-11-26 11:10:05 +0000761 i = platform_get_irq(pdev, 0);
Laurent Pinchartb4dd05d2013-11-28 02:39:42 +0100762 if (i < 0) {
763 dev_err(&pdev->dev, "cannot get platform IRQ\n");
Magnus Damm8051eff2009-11-26 11:10:05 +0000764 ret = -ENOENT;
Laurent Pinchartb4dd05d2013-11-28 02:39:42 +0100765 goto err1;
Magnus Damm8051eff2009-11-26 11:10:05 +0000766 }
767
Laurent Pinchartb4dd05d2013-11-28 02:39:42 +0100768 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
769 p->mapbase = devm_ioremap_resource(&pdev->dev, r);
770 if (IS_ERR(p->mapbase)) {
771 ret = PTR_ERR(p->mapbase);
772 goto err1;
773 }
774
775 ret = devm_request_irq(&pdev->dev, i, sh_msiof_spi_irq, 0,
776 dev_name(&pdev->dev), p);
Magnus Damm8051eff2009-11-26 11:10:05 +0000777 if (ret) {
778 dev_err(&pdev->dev, "unable to request irq\n");
Laurent Pinchartb4dd05d2013-11-28 02:39:42 +0100779 goto err1;
Magnus Damm8051eff2009-11-26 11:10:05 +0000780 }
781
782 p->pdev = pdev;
783 pm_runtime_enable(&pdev->dev);
784
Magnus Damm8051eff2009-11-26 11:10:05 +0000785 /* Platform data may override FIFO sizes */
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +0100786 p->tx_fifo_size = p->chipdata->tx_fifo_size;
787 p->rx_fifo_size = p->chipdata->rx_fifo_size;
Magnus Damm8051eff2009-11-26 11:10:05 +0000788 if (p->info->tx_fifo_override)
789 p->tx_fifo_size = p->info->tx_fifo_override;
790 if (p->info->rx_fifo_override)
791 p->rx_fifo_size = p->info->rx_fifo_override;
792
Geert Uytterhoeven1bd6363bc02014-02-25 11:21:13 +0100793 /* init master code */
Magnus Damm8051eff2009-11-26 11:10:05 +0000794 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
795 master->mode_bits |= SPI_LSB_FIRST | SPI_3WIRE;
Geert Uytterhoevenbeb74bb2014-02-25 11:21:10 +0100796 master->flags = p->chipdata->master_flags;
Magnus Damm8051eff2009-11-26 11:10:05 +0000797 master->bus_num = pdev->id;
Geert Uytterhoevenf7c05e82014-02-20 15:43:00 +0100798 master->dev.of_node = pdev->dev.of_node;
Magnus Damm8051eff2009-11-26 11:10:05 +0000799 master->num_chipselect = p->info->num_chipselect;
Geert Uytterhoeven8d195342014-02-20 15:43:04 +0100800 master->setup = sh_msiof_spi_setup;
Geert Uytterhoevenc833ff72014-02-25 11:21:11 +0100801 master->prepare_message = sh_msiof_prepare_message;
Geert Uytterhoeven24162892014-02-25 11:21:12 +0100802 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32);
Geert Uytterhoevene2a0ba52014-03-11 10:59:11 +0100803 master->auto_runtime_pm = true;
Geert Uytterhoeven1bd6363bc02014-02-25 11:21:13 +0100804 master->transfer_one = sh_msiof_transfer_one;
Magnus Damm8051eff2009-11-26 11:10:05 +0000805
Geert Uytterhoeven1bd6363bc02014-02-25 11:21:13 +0100806 ret = devm_spi_register_master(&pdev->dev, master);
807 if (ret < 0) {
808 dev_err(&pdev->dev, "spi_register_master error.\n");
809 goto err2;
810 }
Magnus Damm8051eff2009-11-26 11:10:05 +0000811
Geert Uytterhoeven1bd6363bc02014-02-25 11:21:13 +0100812 return 0;
Magnus Damm8051eff2009-11-26 11:10:05 +0000813
Geert Uytterhoeven1bd6363bc02014-02-25 11:21:13 +0100814 err2:
Magnus Damm8051eff2009-11-26 11:10:05 +0000815 pm_runtime_disable(&pdev->dev);
Magnus Damm8051eff2009-11-26 11:10:05 +0000816 err1:
817 spi_master_put(master);
Magnus Damm8051eff2009-11-26 11:10:05 +0000818 return ret;
819}
820
821static int sh_msiof_spi_remove(struct platform_device *pdev)
822{
Geert Uytterhoeven1bd6363bc02014-02-25 11:21:13 +0100823 pm_runtime_disable(&pdev->dev);
Geert Uytterhoeven1bd6363bc02014-02-25 11:21:13 +0100824 return 0;
Magnus Damm8051eff2009-11-26 11:10:05 +0000825}
826
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +0100827static struct platform_device_id spi_driver_ids[] = {
828 { "spi_sh_msiof", (kernel_ulong_t)&sh_data },
Geert Uytterhoevenbeb74bb2014-02-25 11:21:10 +0100829 { "spi_r8a7790_msiof", (kernel_ulong_t)&r8a779x_data },
830 { "spi_r8a7791_msiof", (kernel_ulong_t)&r8a779x_data },
Bastian Hechtcf9c86e2012-12-12 12:54:48 +0100831 {},
832};
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +0100833MODULE_DEVICE_TABLE(platform, spi_driver_ids);
Bastian Hechtcf9c86e2012-12-12 12:54:48 +0100834
Magnus Damm8051eff2009-11-26 11:10:05 +0000835static struct platform_driver sh_msiof_spi_drv = {
836 .probe = sh_msiof_spi_probe,
837 .remove = sh_msiof_spi_remove,
Geert Uytterhoeven50a7e232014-02-25 11:21:09 +0100838 .id_table = spi_driver_ids,
Magnus Damm8051eff2009-11-26 11:10:05 +0000839 .driver = {
840 .name = "spi_sh_msiof",
841 .owner = THIS_MODULE,
Sachin Kamat691ee4e2013-03-14 15:31:51 +0530842 .of_match_table = of_match_ptr(sh_msiof_match),
Magnus Damm8051eff2009-11-26 11:10:05 +0000843 },
844};
Grant Likely940ab882011-10-05 11:29:49 -0600845module_platform_driver(sh_msiof_spi_drv);
Magnus Damm8051eff2009-11-26 11:10:05 +0000846
847MODULE_DESCRIPTION("SuperH MSIOF SPI Master Interface Driver");
848MODULE_AUTHOR("Magnus Damm");
849MODULE_LICENSE("GPL v2");
850MODULE_ALIAS("platform:spi_sh_msiof");