14 #include <linux/module.h>
16 #include <linux/errno.h>
23 #include <linux/slab.h>
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)
41 #define SPI_CTRL2 0x01
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)
50 #define SPI_PORTDATA 0x0d
51 #define SPI_DATADIR 0x10
59 #define FSM_CONTINUE 2
102 cs = ms->
message->spi->chip_select;
113 static void mpc52xx_spi_start_transfer(
struct mpc52xx_spi *
ms)
121 mpc52xx_spi_chipsel(ms, 1);
133 static int mpc52xx_spi_fsmstate_transfer(
int irq,
struct mpc52xx_spi *ms,
135 static int mpc52xx_spi_fsmstate_wait(
int irq,
struct mpc52xx_spi *ms,
151 if (status && (irq !=
NO_IRQ))
156 if (list_empty(&ms->
queue))
161 list_del_init(&ms->
message->queue);
181 while (((sppr - 1) & ~0x7) != 0) {
182 sppr = (sppr + 1) >> 1;
197 mpc52xx_spi_start_transfer(ms);
198 ms->
state = mpc52xx_spi_fsmstate_transfer;
211 static int mpc52xx_spi_fsmstate_transfer(
int irq,
struct mpc52xx_spi *ms,
236 mpc52xx_spi_chipsel(ms, 0);
239 ms->
state = mpc52xx_spi_fsmstate_idle;
253 ms->
state = mpc52xx_spi_fsmstate_wait;
274 mpc52xx_spi_fsmstate_wait(
int irq,
struct mpc52xx_spi *ms,
u8 status,
u8 data)
280 if (((
int)get_tbl()) - ms->
timestamp < 0)
290 mpc52xx_spi_chipsel(ms, 0);
293 ms->
state = mpc52xx_spi_fsmstate_idle;
300 mpc52xx_spi_chipsel(ms, 0);
304 mpc52xx_spi_start_transfer(ms);
305 ms->
state = mpc52xx_spi_fsmstate_transfer;
314 static void mpc52xx_spi_fsm_process(
int irq,
struct mpc52xx_spi *ms)
324 rc = ms->
state(irq, ms, status, data);
334 static irqreturn_t mpc52xx_spi_irq(
int irq,
void *_ms)
337 spin_lock(&ms->
lock);
338 mpc52xx_spi_fsm_process(irq, ms);
339 spin_unlock(&ms->
lock);
352 mpc52xx_spi_fsm_process(0, ms);
353 spin_unlock_irqrestore(&ms->
lock, flags);
360 static int mpc52xx_spi_setup(
struct spi_device *spi)
384 spin_unlock_irqrestore(&ms->
lock, flags);
403 dev_dbg(&op->
dev,
"probing mpc5200 SPI device\n");
424 dev_err(&op->
dev,
"mode fault; is port_config correct?\n");
429 dev_dbg(&op->
dev,
"allocating spi_master struct\n");
436 master->
setup = mpc52xx_spi_setup;
437 master->
transfer = mpc52xx_spi_transfer;
439 master->
dev.of_node = op->
dev.of_node;
443 ms = spi_master_get_devdata(master);
448 ms->
state = mpc52xx_spi_fsmstate_idle;
461 gpio_cs = of_get_gpio(op->
dev.of_node, i);
464 "could not parse the gpio field "
473 "can't request spi cs gpio #%d "
474 "on gpio line %d\n", i, gpio_cs);
484 INIT_LIST_HEAD(&ms->
queue);
490 "mpc5200-spi-modf", ms);
492 "mpc5200-spi-spif", ms);
506 dev_dbg(&op->
dev,
"registering spi_master struct\n");
523 spi_master_put(master);
533 struct mpc52xx_spi *ms = spi_master_get_devdata(master);
545 spi_master_put(master);
551 { .compatible =
"fsl,mpc5200-spi", },
558 .name =
"mpc52xx-spi",
560 .of_match_table = mpc52xx_spi_match,
562 .probe = mpc52xx_spi_probe,