blob: a0de12ac1debfe5eea2520ed65651087bfdd9014 [file] [log] [blame]
Grant Likely42bbb702009-11-04 15:34:18 -07001/*
2 * MPC52xx SPI bus driver.
3 *
4 * Copyright (C) 2008 Secret Lab Technologies Ltd.
5 *
6 * This file is released under the GPLv2
7 *
8 * This is the driver for the MPC5200's dedicated SPI controller.
9 *
10 * Note: this driver does not support the MPC5200 PSC in SPI mode. For
11 * that driver see drivers/spi/mpc52xx_psc_spi.c
12 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/errno.h>
17#include <linux/of_platform.h>
18#include <linux/interrupt.h>
19#include <linux/delay.h>
20#include <linux/spi/spi.h>
Grant Likely42bbb702009-11-04 15:34:18 -070021#include <linux/io.h>
Luotao Fub8d4e2c2009-11-13 10:41:17 +010022#include <linux/of_gpio.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Grant Likely42bbb702009-11-04 15:34:18 -070024#include <asm/time.h>
25#include <asm/mpc52xx.h>
26
27MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
28MODULE_DESCRIPTION("MPC52xx SPI (non-PSC) Driver");
29MODULE_LICENSE("GPL");
30
31/* Register offsets */
32#define SPI_CTRL1 0x00
33#define SPI_CTRL1_SPIE (1 << 7)
34#define SPI_CTRL1_SPE (1 << 6)
35#define SPI_CTRL1_MSTR (1 << 4)
36#define SPI_CTRL1_CPOL (1 << 3)
37#define SPI_CTRL1_CPHA (1 << 2)
38#define SPI_CTRL1_SSOE (1 << 1)
39#define SPI_CTRL1_LSBFE (1 << 0)
40
41#define SPI_CTRL2 0x01
42#define SPI_BRR 0x04
43
44#define SPI_STATUS 0x05
45#define SPI_STATUS_SPIF (1 << 7)
46#define SPI_STATUS_WCOL (1 << 6)
47#define SPI_STATUS_MODF (1 << 4)
48
49#define SPI_DATA 0x09
50#define SPI_PORTDATA 0x0d
51#define SPI_DATADIR 0x10
52
53/* FSM state return values */
54#define FSM_STOP 0 /* Nothing more for the state machine to */
55 /* do. If something interesting happens */
Wolfram Sang937041e2009-11-24 17:18:31 -070056 /* then an IRQ will be received */
Grant Likely42bbb702009-11-04 15:34:18 -070057#define FSM_POLL 1 /* need to poll for completion, an IRQ is */
58 /* not expected */
59#define FSM_CONTINUE 2 /* Keep iterating the state machine */
60
61/* Driver internal data */
62struct mpc52xx_spi {
63 struct spi_master *master;
Grant Likely42bbb702009-11-04 15:34:18 -070064 void __iomem *regs;
65 int irq0; /* MODF irq */
66 int irq1; /* SPIF irq */
Wolfram Sang937041e2009-11-24 17:18:31 -070067 unsigned int ipb_freq;
Grant Likely42bbb702009-11-04 15:34:18 -070068
Wolfram Sang937041e2009-11-24 17:18:31 -070069 /* Statistics; not used now, but will be reintroduced for debugfs */
Grant Likely42bbb702009-11-04 15:34:18 -070070 int msg_count;
71 int wcol_count;
72 int wcol_ticks;
73 u32 wcol_tx_timestamp;
74 int modf_count;
75 int byte_count;
76
77 struct list_head queue; /* queue of pending messages */
78 spinlock_t lock;
79 struct work_struct work;
80
Grant Likely42bbb702009-11-04 15:34:18 -070081 /* Details of current transfer (length, and buffer pointers) */
82 struct spi_message *message; /* current message */
83 struct spi_transfer *transfer; /* current transfer */
84 int (*state)(int irq, struct mpc52xx_spi *ms, u8 status, u8 data);
85 int len;
86 int timestamp;
87 u8 *rx_buf;
88 const u8 *tx_buf;
89 int cs_change;
Luotao Fub8d4e2c2009-11-13 10:41:17 +010090 int gpio_cs_count;
91 unsigned int *gpio_cs;
Grant Likely42bbb702009-11-04 15:34:18 -070092};
93
94/*
95 * CS control function
96 */
97static void mpc52xx_spi_chipsel(struct mpc52xx_spi *ms, int value)
98{
Luotao Fub8d4e2c2009-11-13 10:41:17 +010099 int cs;
100
101 if (ms->gpio_cs_count > 0) {
102 cs = ms->message->spi->chip_select;
103 gpio_set_value(ms->gpio_cs[cs], value ? 0 : 1);
104 } else
105 out_8(ms->regs + SPI_PORTDATA, value ? 0 : 0x08);
Grant Likely42bbb702009-11-04 15:34:18 -0700106}
107
108/*
109 * Start a new transfer. This is called both by the idle state
110 * for the first transfer in a message, and by the wait state when the
111 * previous transfer in a message is complete.
112 */
113static void mpc52xx_spi_start_transfer(struct mpc52xx_spi *ms)
114{
115 ms->rx_buf = ms->transfer->rx_buf;
116 ms->tx_buf = ms->transfer->tx_buf;
117 ms->len = ms->transfer->len;
118
119 /* Activate the chip select */
120 if (ms->cs_change)
121 mpc52xx_spi_chipsel(ms, 1);
122 ms->cs_change = ms->transfer->cs_change;
123
124 /* Write out the first byte */
125 ms->wcol_tx_timestamp = get_tbl();
126 if (ms->tx_buf)
127 out_8(ms->regs + SPI_DATA, *ms->tx_buf++);
128 else
129 out_8(ms->regs + SPI_DATA, 0);
130}
131
132/* Forward declaration of state handlers */
133static int mpc52xx_spi_fsmstate_transfer(int irq, struct mpc52xx_spi *ms,
134 u8 status, u8 data);
135static int mpc52xx_spi_fsmstate_wait(int irq, struct mpc52xx_spi *ms,
136 u8 status, u8 data);
137
138/*
139 * IDLE state
140 *
141 * No transfers are in progress; if another transfer is pending then retrieve
142 * it and kick it off. Otherwise, stop processing the state machine
143 */
144static int
145mpc52xx_spi_fsmstate_idle(int irq, struct mpc52xx_spi *ms, u8 status, u8 data)
146{
147 struct spi_device *spi;
148 int spr, sppr;
149 u8 ctrl1;
150
151 if (status && (irq != NO_IRQ))
152 dev_err(&ms->master->dev, "spurious irq, status=0x%.2x\n",
153 status);
154
155 /* Check if there is another transfer waiting. */
156 if (list_empty(&ms->queue))
157 return FSM_STOP;
158
159 /* get the head of the queue */
160 ms->message = list_first_entry(&ms->queue, struct spi_message, queue);
161 list_del_init(&ms->message->queue);
162
163 /* Setup the controller parameters */
164 ctrl1 = SPI_CTRL1_SPIE | SPI_CTRL1_SPE | SPI_CTRL1_MSTR;
165 spi = ms->message->spi;
166 if (spi->mode & SPI_CPHA)
167 ctrl1 |= SPI_CTRL1_CPHA;
168 if (spi->mode & SPI_CPOL)
169 ctrl1 |= SPI_CTRL1_CPOL;
170 if (spi->mode & SPI_LSB_FIRST)
171 ctrl1 |= SPI_CTRL1_LSBFE;
172 out_8(ms->regs + SPI_CTRL1, ctrl1);
173
174 /* Setup the controller speed */
175 /* minimum divider is '2'. Also, add '1' to force rounding the
176 * divider up. */
177 sppr = ((ms->ipb_freq / ms->message->spi->max_speed_hz) + 1) >> 1;
178 spr = 0;
179 if (sppr < 1)
180 sppr = 1;
181 while (((sppr - 1) & ~0x7) != 0) {
182 sppr = (sppr + 1) >> 1; /* add '1' to force rounding up */
183 spr++;
184 }
185 sppr--; /* sppr quantity in register is offset by 1 */
186 if (spr > 7) {
187 /* Don't overrun limits of SPI baudrate register */
188 spr = 7;
189 sppr = 7;
190 }
191 out_8(ms->regs + SPI_BRR, sppr << 4 | spr); /* Set speed */
192
193 ms->cs_change = 1;
194 ms->transfer = container_of(ms->message->transfers.next,
195 struct spi_transfer, transfer_list);
196
197 mpc52xx_spi_start_transfer(ms);
198 ms->state = mpc52xx_spi_fsmstate_transfer;
199
200 return FSM_CONTINUE;
201}
202
203/*
204 * TRANSFER state
205 *
206 * In the middle of a transfer. If the SPI core has completed processing
207 * a byte, then read out the received data and write out the next byte
208 * (unless this transfer is finished; in which case go on to the wait
209 * state)
210 */
211static int mpc52xx_spi_fsmstate_transfer(int irq, struct mpc52xx_spi *ms,
212 u8 status, u8 data)
213{
214 if (!status)
215 return ms->irq0 ? FSM_STOP : FSM_POLL;
216
217 if (status & SPI_STATUS_WCOL) {
218 /* The SPI controller is stoopid. At slower speeds, it may
219 * raise the SPIF flag before the state machine is actually
220 * finished, which causes a collision (internal to the state
221 * machine only). The manual recommends inserting a delay
222 * between receiving the interrupt and sending the next byte,
223 * but it can also be worked around simply by retrying the
224 * transfer which is what we do here. */
225 ms->wcol_count++;
226 ms->wcol_ticks += get_tbl() - ms->wcol_tx_timestamp;
227 ms->wcol_tx_timestamp = get_tbl();
228 data = 0;
229 if (ms->tx_buf)
Wolfram Sang937041e2009-11-24 17:18:31 -0700230 data = *(ms->tx_buf - 1);
Grant Likely42bbb702009-11-04 15:34:18 -0700231 out_8(ms->regs + SPI_DATA, data); /* try again */
232 return FSM_CONTINUE;
233 } else if (status & SPI_STATUS_MODF) {
234 ms->modf_count++;
235 dev_err(&ms->master->dev, "mode fault\n");
236 mpc52xx_spi_chipsel(ms, 0);
237 ms->message->status = -EIO;
Axel Lin0a6d3872014-04-02 22:21:04 +0800238 if (ms->message->complete)
239 ms->message->complete(ms->message->context);
Grant Likely42bbb702009-11-04 15:34:18 -0700240 ms->state = mpc52xx_spi_fsmstate_idle;
241 return FSM_CONTINUE;
242 }
243
244 /* Read data out of the spi device */
245 ms->byte_count++;
246 if (ms->rx_buf)
247 *ms->rx_buf++ = data;
248
249 /* Is the transfer complete? */
250 ms->len--;
251 if (ms->len == 0) {
252 ms->timestamp = get_tbl();
253 ms->timestamp += ms->transfer->delay_usecs * tb_ticks_per_usec;
254 ms->state = mpc52xx_spi_fsmstate_wait;
255 return FSM_CONTINUE;
256 }
257
258 /* Write out the next byte */
259 ms->wcol_tx_timestamp = get_tbl();
260 if (ms->tx_buf)
261 out_8(ms->regs + SPI_DATA, *ms->tx_buf++);
262 else
263 out_8(ms->regs + SPI_DATA, 0);
264
265 return FSM_CONTINUE;
266}
267
268/*
269 * WAIT state
270 *
271 * A transfer has completed; need to wait for the delay period to complete
272 * before starting the next transfer
273 */
274static int
275mpc52xx_spi_fsmstate_wait(int irq, struct mpc52xx_spi *ms, u8 status, u8 data)
276{
277 if (status && irq)
278 dev_err(&ms->master->dev, "spurious irq, status=0x%.2x\n",
279 status);
280
281 if (((int)get_tbl()) - ms->timestamp < 0)
282 return FSM_POLL;
283
284 ms->message->actual_length += ms->transfer->len;
285
286 /* Check if there is another transfer in this message. If there
287 * aren't then deactivate CS, notify sender, and drop back to idle
288 * to start the next message. */
289 if (ms->transfer->transfer_list.next == &ms->message->transfers) {
290 ms->msg_count++;
291 mpc52xx_spi_chipsel(ms, 0);
292 ms->message->status = 0;
Axel Lin0a6d3872014-04-02 22:21:04 +0800293 if (ms->message->complete)
294 ms->message->complete(ms->message->context);
Grant Likely42bbb702009-11-04 15:34:18 -0700295 ms->state = mpc52xx_spi_fsmstate_idle;
296 return FSM_CONTINUE;
297 }
298
299 /* There is another transfer; kick it off */
300
301 if (ms->cs_change)
302 mpc52xx_spi_chipsel(ms, 0);
303
304 ms->transfer = container_of(ms->transfer->transfer_list.next,
305 struct spi_transfer, transfer_list);
306 mpc52xx_spi_start_transfer(ms);
307 ms->state = mpc52xx_spi_fsmstate_transfer;
308 return FSM_CONTINUE;
309}
310
311/**
312 * mpc52xx_spi_fsm_process - Finite State Machine iteration function
313 * @irq: irq number that triggered the FSM or 0 for polling
314 * @ms: pointer to mpc52xx_spi driver data
315 */
316static void mpc52xx_spi_fsm_process(int irq, struct mpc52xx_spi *ms)
317{
318 int rc = FSM_CONTINUE;
319 u8 status, data;
320
321 while (rc == FSM_CONTINUE) {
322 /* Interrupt cleared by read of STATUS followed by
323 * read of DATA registers */
324 status = in_8(ms->regs + SPI_STATUS);
325 data = in_8(ms->regs + SPI_DATA);
326 rc = ms->state(irq, ms, status, data);
327 }
328
329 if (rc == FSM_POLL)
330 schedule_work(&ms->work);
331}
332
333/**
334 * mpc52xx_spi_irq - IRQ handler
335 */
336static irqreturn_t mpc52xx_spi_irq(int irq, void *_ms)
337{
338 struct mpc52xx_spi *ms = _ms;
339 spin_lock(&ms->lock);
340 mpc52xx_spi_fsm_process(irq, ms);
341 spin_unlock(&ms->lock);
342 return IRQ_HANDLED;
343}
344
345/**
346 * mpc52xx_spi_wq - Workqueue function for polling the state machine
347 */
348static void mpc52xx_spi_wq(struct work_struct *work)
349{
350 struct mpc52xx_spi *ms = container_of(work, struct mpc52xx_spi, work);
351 unsigned long flags;
352
353 spin_lock_irqsave(&ms->lock, flags);
354 mpc52xx_spi_fsm_process(0, ms);
355 spin_unlock_irqrestore(&ms->lock, flags);
356}
357
358/*
359 * spi_master ops
360 */
361
362static int mpc52xx_spi_setup(struct spi_device *spi)
363{
364 if (spi->bits_per_word % 8)
365 return -EINVAL;
366
367 if (spi->mode & ~(SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST))
368 return -EINVAL;
369
370 if (spi->chip_select >= spi->master->num_chipselect)
371 return -EINVAL;
372
373 return 0;
374}
375
376static int mpc52xx_spi_transfer(struct spi_device *spi, struct spi_message *m)
377{
378 struct mpc52xx_spi *ms = spi_master_get_devdata(spi->master);
379 unsigned long flags;
380
381 m->actual_length = 0;
382 m->status = -EINPROGRESS;
383
384 spin_lock_irqsave(&ms->lock, flags);
385 list_add_tail(&m->queue, &ms->queue);
386 spin_unlock_irqrestore(&ms->lock, flags);
387 schedule_work(&ms->work);
388
389 return 0;
390}
391
392/*
393 * OF Platform Bus Binding
394 */
Grant Likelyfd4a3192012-12-07 16:57:14 +0000395static int mpc52xx_spi_probe(struct platform_device *op)
Grant Likely42bbb702009-11-04 15:34:18 -0700396{
397 struct spi_master *master;
398 struct mpc52xx_spi *ms;
399 void __iomem *regs;
Luotao Fu4a495b12009-11-13 10:41:15 +0100400 u8 ctrl1;
Luotao Fub8d4e2c2009-11-13 10:41:17 +0100401 int rc, i = 0;
402 int gpio_cs;
Grant Likely42bbb702009-11-04 15:34:18 -0700403
404 /* MMIO registers */
405 dev_dbg(&op->dev, "probing mpc5200 SPI device\n");
Grant Likely61c7a082010-04-13 16:12:29 -0700406 regs = of_iomap(op->dev.of_node, 0);
Grant Likely42bbb702009-11-04 15:34:18 -0700407 if (!regs)
408 return -ENODEV;
409
410 /* initialize the device */
Luotao Fu4a495b12009-11-13 10:41:15 +0100411 ctrl1 = SPI_CTRL1_SPIE | SPI_CTRL1_SPE | SPI_CTRL1_MSTR;
412 out_8(regs + SPI_CTRL1, ctrl1);
Grant Likely42bbb702009-11-04 15:34:18 -0700413 out_8(regs + SPI_CTRL2, 0x0);
414 out_8(regs + SPI_DATADIR, 0xe); /* Set output pins */
415 out_8(regs + SPI_PORTDATA, 0x8); /* Deassert /SS signal */
416
417 /* Clear the status register and re-read it to check for a MODF
418 * failure. This driver cannot currently handle multiple masters
419 * on the SPI bus. This fault will also occur if the SPI signals
420 * are not connected to any pins (port_config setting) */
421 in_8(regs + SPI_STATUS);
Luotao Fu4a495b12009-11-13 10:41:15 +0100422 out_8(regs + SPI_CTRL1, ctrl1);
423
Grant Likely42bbb702009-11-04 15:34:18 -0700424 in_8(regs + SPI_DATA);
425 if (in_8(regs + SPI_STATUS) & SPI_STATUS_MODF) {
426 dev_err(&op->dev, "mode fault; is port_config correct?\n");
427 rc = -EIO;
428 goto err_init;
429 }
430
431 dev_dbg(&op->dev, "allocating spi_master struct\n");
432 master = spi_alloc_master(&op->dev, sizeof *ms);
433 if (!master) {
434 rc = -ENOMEM;
435 goto err_alloc;
436 }
Luotao Fub8d4e2c2009-11-13 10:41:17 +0100437
Grant Likely42bbb702009-11-04 15:34:18 -0700438 master->setup = mpc52xx_spi_setup;
439 master->transfer = mpc52xx_spi_transfer;
Luotao Fud65aea92009-11-13 10:41:16 +0100440 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
Anatolij Gustschin12b15e82010-07-27 22:35:58 +0200441 master->dev.of_node = op->dev.of_node;
Luotao Fud65aea92009-11-13 10:41:16 +0100442
Jingoo Han24b5a822013-05-23 19:20:40 +0900443 platform_set_drvdata(op, master);
Grant Likely42bbb702009-11-04 15:34:18 -0700444
445 ms = spi_master_get_devdata(master);
446 ms->master = master;
447 ms->regs = regs;
Grant Likely61c7a082010-04-13 16:12:29 -0700448 ms->irq0 = irq_of_parse_and_map(op->dev.of_node, 0);
449 ms->irq1 = irq_of_parse_and_map(op->dev.of_node, 1);
Grant Likely42bbb702009-11-04 15:34:18 -0700450 ms->state = mpc52xx_spi_fsmstate_idle;
Grant Likely61c7a082010-04-13 16:12:29 -0700451 ms->ipb_freq = mpc5xxx_get_bus_frequency(op->dev.of_node);
452 ms->gpio_cs_count = of_gpio_count(op->dev.of_node);
Luotao Fub8d4e2c2009-11-13 10:41:17 +0100453 if (ms->gpio_cs_count > 0) {
454 master->num_chipselect = ms->gpio_cs_count;
455 ms->gpio_cs = kmalloc(ms->gpio_cs_count * sizeof(unsigned int),
456 GFP_KERNEL);
457 if (!ms->gpio_cs) {
458 rc = -ENOMEM;
Guenter Roeck866c0f22012-08-18 09:29:21 -0700459 goto err_alloc_gpio;
Luotao Fub8d4e2c2009-11-13 10:41:17 +0100460 }
461
462 for (i = 0; i < ms->gpio_cs_count; i++) {
Grant Likely61c7a082010-04-13 16:12:29 -0700463 gpio_cs = of_get_gpio(op->dev.of_node, i);
Luotao Fub8d4e2c2009-11-13 10:41:17 +0100464 if (gpio_cs < 0) {
465 dev_err(&op->dev,
466 "could not parse the gpio field "
467 "in oftree\n");
468 rc = -ENODEV;
469 goto err_gpio;
470 }
471
472 rc = gpio_request(gpio_cs, dev_name(&op->dev));
473 if (rc) {
474 dev_err(&op->dev,
475 "can't request spi cs gpio #%d "
476 "on gpio line %d\n", i, gpio_cs);
477 goto err_gpio;
478 }
479
480 gpio_direction_output(gpio_cs, 1);
481 ms->gpio_cs[i] = gpio_cs;
482 }
Wolfram Sang937041e2009-11-24 17:18:31 -0700483 }
Luotao Fub8d4e2c2009-11-13 10:41:17 +0100484
Grant Likely42bbb702009-11-04 15:34:18 -0700485 spin_lock_init(&ms->lock);
486 INIT_LIST_HEAD(&ms->queue);
487 INIT_WORK(&ms->work, mpc52xx_spi_wq);
488
489 /* Decide if interrupts can be used */
490 if (ms->irq0 && ms->irq1) {
Wolfram Sang937041e2009-11-24 17:18:31 -0700491 rc = request_irq(ms->irq0, mpc52xx_spi_irq, 0,
Grant Likely42bbb702009-11-04 15:34:18 -0700492 "mpc5200-spi-modf", ms);
Wolfram Sang937041e2009-11-24 17:18:31 -0700493 rc |= request_irq(ms->irq1, mpc52xx_spi_irq, 0,
494 "mpc5200-spi-spif", ms);
Grant Likely42bbb702009-11-04 15:34:18 -0700495 if (rc) {
496 free_irq(ms->irq0, ms);
497 free_irq(ms->irq1, ms);
498 ms->irq0 = ms->irq1 = 0;
499 }
500 } else {
501 /* operate in polled mode */
502 ms->irq0 = ms->irq1 = 0;
503 }
504
505 if (!ms->irq0)
506 dev_info(&op->dev, "using polled mode\n");
507
508 dev_dbg(&op->dev, "registering spi_master struct\n");
509 rc = spi_register_master(master);
510 if (rc)
511 goto err_register;
512
Grant Likely42bbb702009-11-04 15:34:18 -0700513 dev_info(&ms->master->dev, "registered MPC5200 SPI bus\n");
514
515 return rc;
516
517 err_register:
518 dev_err(&ms->master->dev, "initialization failed\n");
Luotao Fub8d4e2c2009-11-13 10:41:17 +0100519 err_gpio:
520 while (i-- > 0)
521 gpio_free(ms->gpio_cs[i]);
522
Wolfram Sang937041e2009-11-24 17:18:31 -0700523 kfree(ms->gpio_cs);
Guenter Roeck866c0f22012-08-18 09:29:21 -0700524 err_alloc_gpio:
525 spi_master_put(master);
Grant Likely42bbb702009-11-04 15:34:18 -0700526 err_alloc:
527 err_init:
528 iounmap(regs);
529 return rc;
530}
531
Grant Likelyfd4a3192012-12-07 16:57:14 +0000532static int mpc52xx_spi_remove(struct platform_device *op)
Grant Likely42bbb702009-11-04 15:34:18 -0700533{
Jingoo Han24b5a822013-05-23 19:20:40 +0900534 struct spi_master *master = spi_master_get(platform_get_drvdata(op));
Grant Likely42bbb702009-11-04 15:34:18 -0700535 struct mpc52xx_spi *ms = spi_master_get_devdata(master);
Luotao Fub8d4e2c2009-11-13 10:41:17 +0100536 int i;
Grant Likely42bbb702009-11-04 15:34:18 -0700537
538 free_irq(ms->irq0, ms);
539 free_irq(ms->irq1, ms);
540
Luotao Fub8d4e2c2009-11-13 10:41:17 +0100541 for (i = 0; i < ms->gpio_cs_count; i++)
542 gpio_free(ms->gpio_cs[i]);
543
Wolfram Sang937041e2009-11-24 17:18:31 -0700544 kfree(ms->gpio_cs);
Grant Likely42bbb702009-11-04 15:34:18 -0700545 spi_unregister_master(master);
Grant Likely42bbb702009-11-04 15:34:18 -0700546 iounmap(ms->regs);
Guenter Roeckf95e1022012-08-18 09:29:22 -0700547 spi_master_put(master);
Grant Likely42bbb702009-11-04 15:34:18 -0700548
549 return 0;
550}
551
Grant Likelyfd4a3192012-12-07 16:57:14 +0000552static const struct of_device_id mpc52xx_spi_match[] = {
Grant Likely42bbb702009-11-04 15:34:18 -0700553 { .compatible = "fsl,mpc5200-spi", },
554 {}
555};
556MODULE_DEVICE_TABLE(of, mpc52xx_spi_match);
557
Grant Likely18d306d2011-02-22 21:02:43 -0700558static struct platform_driver mpc52xx_spi_of_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700559 .driver = {
560 .name = "mpc52xx-spi",
561 .owner = THIS_MODULE,
562 .of_match_table = mpc52xx_spi_match,
563 },
Grant Likely42bbb702009-11-04 15:34:18 -0700564 .probe = mpc52xx_spi_probe,
Grant Likelyfd4a3192012-12-07 16:57:14 +0000565 .remove = mpc52xx_spi_remove,
Grant Likely42bbb702009-11-04 15:34:18 -0700566};
Grant Likely940ab882011-10-05 11:29:49 -0600567module_platform_driver(mpc52xx_spi_of_driver);