Lines Matching refs:ms
83 int (*state)(int irq, struct mpc52xx_spi *ms, u8 status, u8 data);
96 static void mpc52xx_spi_chipsel(struct mpc52xx_spi *ms, int value) in mpc52xx_spi_chipsel() argument
100 if (ms->gpio_cs_count > 0) { in mpc52xx_spi_chipsel()
101 cs = ms->message->spi->chip_select; in mpc52xx_spi_chipsel()
102 gpio_set_value(ms->gpio_cs[cs], value ? 0 : 1); in mpc52xx_spi_chipsel()
104 out_8(ms->regs + SPI_PORTDATA, value ? 0 : 0x08); in mpc52xx_spi_chipsel()
112 static void mpc52xx_spi_start_transfer(struct mpc52xx_spi *ms) in mpc52xx_spi_start_transfer() argument
114 ms->rx_buf = ms->transfer->rx_buf; in mpc52xx_spi_start_transfer()
115 ms->tx_buf = ms->transfer->tx_buf; in mpc52xx_spi_start_transfer()
116 ms->len = ms->transfer->len; in mpc52xx_spi_start_transfer()
119 if (ms->cs_change) in mpc52xx_spi_start_transfer()
120 mpc52xx_spi_chipsel(ms, 1); in mpc52xx_spi_start_transfer()
121 ms->cs_change = ms->transfer->cs_change; in mpc52xx_spi_start_transfer()
124 ms->wcol_tx_timestamp = get_tbl(); in mpc52xx_spi_start_transfer()
125 if (ms->tx_buf) in mpc52xx_spi_start_transfer()
126 out_8(ms->regs + SPI_DATA, *ms->tx_buf++); in mpc52xx_spi_start_transfer()
128 out_8(ms->regs + SPI_DATA, 0); in mpc52xx_spi_start_transfer()
132 static int mpc52xx_spi_fsmstate_transfer(int irq, struct mpc52xx_spi *ms,
134 static int mpc52xx_spi_fsmstate_wait(int irq, struct mpc52xx_spi *ms,
144 mpc52xx_spi_fsmstate_idle(int irq, struct mpc52xx_spi *ms, u8 status, u8 data) in mpc52xx_spi_fsmstate_idle() argument
151 dev_err(&ms->master->dev, "spurious irq, status=0x%.2x\n", in mpc52xx_spi_fsmstate_idle()
155 if (list_empty(&ms->queue)) in mpc52xx_spi_fsmstate_idle()
159 ms->message = list_first_entry(&ms->queue, struct spi_message, queue); in mpc52xx_spi_fsmstate_idle()
160 list_del_init(&ms->message->queue); in mpc52xx_spi_fsmstate_idle()
164 spi = ms->message->spi; in mpc52xx_spi_fsmstate_idle()
171 out_8(ms->regs + SPI_CTRL1, ctrl1); in mpc52xx_spi_fsmstate_idle()
176 sppr = ((ms->ipb_freq / ms->message->spi->max_speed_hz) + 1) >> 1; in mpc52xx_spi_fsmstate_idle()
190 out_8(ms->regs + SPI_BRR, sppr << 4 | spr); /* Set speed */ in mpc52xx_spi_fsmstate_idle()
192 ms->cs_change = 1; in mpc52xx_spi_fsmstate_idle()
193 ms->transfer = container_of(ms->message->transfers.next, in mpc52xx_spi_fsmstate_idle()
196 mpc52xx_spi_start_transfer(ms); in mpc52xx_spi_fsmstate_idle()
197 ms->state = mpc52xx_spi_fsmstate_transfer; in mpc52xx_spi_fsmstate_idle()
210 static int mpc52xx_spi_fsmstate_transfer(int irq, struct mpc52xx_spi *ms, in mpc52xx_spi_fsmstate_transfer() argument
214 return ms->irq0 ? FSM_STOP : FSM_POLL; in mpc52xx_spi_fsmstate_transfer()
224 ms->wcol_count++; in mpc52xx_spi_fsmstate_transfer()
225 ms->wcol_ticks += get_tbl() - ms->wcol_tx_timestamp; in mpc52xx_spi_fsmstate_transfer()
226 ms->wcol_tx_timestamp = get_tbl(); in mpc52xx_spi_fsmstate_transfer()
228 if (ms->tx_buf) in mpc52xx_spi_fsmstate_transfer()
229 data = *(ms->tx_buf - 1); in mpc52xx_spi_fsmstate_transfer()
230 out_8(ms->regs + SPI_DATA, data); /* try again */ in mpc52xx_spi_fsmstate_transfer()
233 ms->modf_count++; in mpc52xx_spi_fsmstate_transfer()
234 dev_err(&ms->master->dev, "mode fault\n"); in mpc52xx_spi_fsmstate_transfer()
235 mpc52xx_spi_chipsel(ms, 0); in mpc52xx_spi_fsmstate_transfer()
236 ms->message->status = -EIO; in mpc52xx_spi_fsmstate_transfer()
237 if (ms->message->complete) in mpc52xx_spi_fsmstate_transfer()
238 ms->message->complete(ms->message->context); in mpc52xx_spi_fsmstate_transfer()
239 ms->state = mpc52xx_spi_fsmstate_idle; in mpc52xx_spi_fsmstate_transfer()
244 ms->byte_count++; in mpc52xx_spi_fsmstate_transfer()
245 if (ms->rx_buf) in mpc52xx_spi_fsmstate_transfer()
246 *ms->rx_buf++ = data; in mpc52xx_spi_fsmstate_transfer()
249 ms->len--; in mpc52xx_spi_fsmstate_transfer()
250 if (ms->len == 0) { in mpc52xx_spi_fsmstate_transfer()
251 ms->timestamp = get_tbl(); in mpc52xx_spi_fsmstate_transfer()
252 ms->timestamp += ms->transfer->delay_usecs * tb_ticks_per_usec; in mpc52xx_spi_fsmstate_transfer()
253 ms->state = mpc52xx_spi_fsmstate_wait; in mpc52xx_spi_fsmstate_transfer()
258 ms->wcol_tx_timestamp = get_tbl(); in mpc52xx_spi_fsmstate_transfer()
259 if (ms->tx_buf) in mpc52xx_spi_fsmstate_transfer()
260 out_8(ms->regs + SPI_DATA, *ms->tx_buf++); in mpc52xx_spi_fsmstate_transfer()
262 out_8(ms->regs + SPI_DATA, 0); in mpc52xx_spi_fsmstate_transfer()
274 mpc52xx_spi_fsmstate_wait(int irq, struct mpc52xx_spi *ms, u8 status, u8 data) in mpc52xx_spi_fsmstate_wait() argument
277 dev_err(&ms->master->dev, "spurious irq, status=0x%.2x\n", in mpc52xx_spi_fsmstate_wait()
280 if (((int)get_tbl()) - ms->timestamp < 0) in mpc52xx_spi_fsmstate_wait()
283 ms->message->actual_length += ms->transfer->len; in mpc52xx_spi_fsmstate_wait()
288 if (ms->transfer->transfer_list.next == &ms->message->transfers) { in mpc52xx_spi_fsmstate_wait()
289 ms->msg_count++; in mpc52xx_spi_fsmstate_wait()
290 mpc52xx_spi_chipsel(ms, 0); in mpc52xx_spi_fsmstate_wait()
291 ms->message->status = 0; in mpc52xx_spi_fsmstate_wait()
292 if (ms->message->complete) in mpc52xx_spi_fsmstate_wait()
293 ms->message->complete(ms->message->context); in mpc52xx_spi_fsmstate_wait()
294 ms->state = mpc52xx_spi_fsmstate_idle; in mpc52xx_spi_fsmstate_wait()
300 if (ms->cs_change) in mpc52xx_spi_fsmstate_wait()
301 mpc52xx_spi_chipsel(ms, 0); in mpc52xx_spi_fsmstate_wait()
303 ms->transfer = container_of(ms->transfer->transfer_list.next, in mpc52xx_spi_fsmstate_wait()
305 mpc52xx_spi_start_transfer(ms); in mpc52xx_spi_fsmstate_wait()
306 ms->state = mpc52xx_spi_fsmstate_transfer; in mpc52xx_spi_fsmstate_wait()
315 static void mpc52xx_spi_fsm_process(int irq, struct mpc52xx_spi *ms) in mpc52xx_spi_fsm_process() argument
323 status = in_8(ms->regs + SPI_STATUS); in mpc52xx_spi_fsm_process()
324 data = in_8(ms->regs + SPI_DATA); in mpc52xx_spi_fsm_process()
325 rc = ms->state(irq, ms, status, data); in mpc52xx_spi_fsm_process()
329 schedule_work(&ms->work); in mpc52xx_spi_fsm_process()
337 struct mpc52xx_spi *ms = _ms; in mpc52xx_spi_irq() local
338 spin_lock(&ms->lock); in mpc52xx_spi_irq()
339 mpc52xx_spi_fsm_process(irq, ms); in mpc52xx_spi_irq()
340 spin_unlock(&ms->lock); in mpc52xx_spi_irq()
349 struct mpc52xx_spi *ms = container_of(work, struct mpc52xx_spi, work); in mpc52xx_spi_wq() local
352 spin_lock_irqsave(&ms->lock, flags); in mpc52xx_spi_wq()
353 mpc52xx_spi_fsm_process(0, ms); in mpc52xx_spi_wq()
354 spin_unlock_irqrestore(&ms->lock, flags); in mpc52xx_spi_wq()
363 struct mpc52xx_spi *ms = spi_master_get_devdata(spi->master); in mpc52xx_spi_transfer() local
369 spin_lock_irqsave(&ms->lock, flags); in mpc52xx_spi_transfer()
370 list_add_tail(&m->queue, &ms->queue); in mpc52xx_spi_transfer()
371 spin_unlock_irqrestore(&ms->lock, flags); in mpc52xx_spi_transfer()
372 schedule_work(&ms->work); in mpc52xx_spi_transfer()
383 struct mpc52xx_spi *ms; in mpc52xx_spi_probe() local
417 master = spi_alloc_master(&op->dev, sizeof *ms); in mpc52xx_spi_probe()
430 ms = spi_master_get_devdata(master); in mpc52xx_spi_probe()
431 ms->master = master; in mpc52xx_spi_probe()
432 ms->regs = regs; in mpc52xx_spi_probe()
433 ms->irq0 = irq_of_parse_and_map(op->dev.of_node, 0); in mpc52xx_spi_probe()
434 ms->irq1 = irq_of_parse_and_map(op->dev.of_node, 1); in mpc52xx_spi_probe()
435 ms->state = mpc52xx_spi_fsmstate_idle; in mpc52xx_spi_probe()
436 ms->ipb_freq = mpc5xxx_get_bus_frequency(op->dev.of_node); in mpc52xx_spi_probe()
437 ms->gpio_cs_count = of_gpio_count(op->dev.of_node); in mpc52xx_spi_probe()
438 if (ms->gpio_cs_count > 0) { in mpc52xx_spi_probe()
439 master->num_chipselect = ms->gpio_cs_count; in mpc52xx_spi_probe()
440 ms->gpio_cs = kmalloc(ms->gpio_cs_count * sizeof(unsigned int), in mpc52xx_spi_probe()
442 if (!ms->gpio_cs) { in mpc52xx_spi_probe()
447 for (i = 0; i < ms->gpio_cs_count; i++) { in mpc52xx_spi_probe()
466 ms->gpio_cs[i] = gpio_cs; in mpc52xx_spi_probe()
470 spin_lock_init(&ms->lock); in mpc52xx_spi_probe()
471 INIT_LIST_HEAD(&ms->queue); in mpc52xx_spi_probe()
472 INIT_WORK(&ms->work, mpc52xx_spi_wq); in mpc52xx_spi_probe()
475 if (ms->irq0 && ms->irq1) { in mpc52xx_spi_probe()
476 rc = request_irq(ms->irq0, mpc52xx_spi_irq, 0, in mpc52xx_spi_probe()
477 "mpc5200-spi-modf", ms); in mpc52xx_spi_probe()
478 rc |= request_irq(ms->irq1, mpc52xx_spi_irq, 0, in mpc52xx_spi_probe()
479 "mpc5200-spi-spif", ms); in mpc52xx_spi_probe()
481 free_irq(ms->irq0, ms); in mpc52xx_spi_probe()
482 free_irq(ms->irq1, ms); in mpc52xx_spi_probe()
483 ms->irq0 = ms->irq1 = 0; in mpc52xx_spi_probe()
487 ms->irq0 = ms->irq1 = 0; in mpc52xx_spi_probe()
490 if (!ms->irq0) in mpc52xx_spi_probe()
498 dev_info(&ms->master->dev, "registered MPC5200 SPI bus\n"); in mpc52xx_spi_probe()
503 dev_err(&ms->master->dev, "initialization failed\n"); in mpc52xx_spi_probe()
506 gpio_free(ms->gpio_cs[i]); in mpc52xx_spi_probe()
508 kfree(ms->gpio_cs); in mpc52xx_spi_probe()
520 struct mpc52xx_spi *ms = spi_master_get_devdata(master); in mpc52xx_spi_remove() local
523 free_irq(ms->irq0, ms); in mpc52xx_spi_remove()
524 free_irq(ms->irq1, ms); in mpc52xx_spi_remove()
526 for (i = 0; i < ms->gpio_cs_count; i++) in mpc52xx_spi_remove()
527 gpio_free(ms->gpio_cs[i]); in mpc52xx_spi_remove()
529 kfree(ms->gpio_cs); in mpc52xx_spi_remove()
531 iounmap(ms->regs); in mpc52xx_spi_remove()