Lines Matching refs:dws
70 struct dw_spi *dws; in spi_show_regs() local
75 dws = file->private_data; in spi_show_regs()
86 "CTRL0: \t\t0x%08x\n", dw_readl(dws, DW_SPI_CTRL0)); in spi_show_regs()
88 "CTRL1: \t\t0x%08x\n", dw_readl(dws, DW_SPI_CTRL1)); in spi_show_regs()
90 "SSIENR: \t0x%08x\n", dw_readl(dws, DW_SPI_SSIENR)); in spi_show_regs()
92 "SER: \t\t0x%08x\n", dw_readl(dws, DW_SPI_SER)); in spi_show_regs()
94 "BAUDR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_BAUDR)); in spi_show_regs()
96 "TXFTLR: \t0x%08x\n", dw_readl(dws, DW_SPI_TXFLTR)); in spi_show_regs()
98 "RXFTLR: \t0x%08x\n", dw_readl(dws, DW_SPI_RXFLTR)); in spi_show_regs()
100 "TXFLR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_TXFLR)); in spi_show_regs()
102 "RXFLR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_RXFLR)); in spi_show_regs()
104 "SR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_SR)); in spi_show_regs()
106 "IMR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_IMR)); in spi_show_regs()
108 "ISR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_ISR)); in spi_show_regs()
110 "DMACR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_DMACR)); in spi_show_regs()
112 "DMATDLR: \t0x%08x\n", dw_readl(dws, DW_SPI_DMATDLR)); in spi_show_regs()
114 "DMARDLR: \t0x%08x\n", dw_readl(dws, DW_SPI_DMARDLR)); in spi_show_regs()
130 static int mrst_spi_debugfs_init(struct dw_spi *dws) in mrst_spi_debugfs_init() argument
132 dws->debugfs = debugfs_create_dir("mrst_spi", NULL); in mrst_spi_debugfs_init()
133 if (!dws->debugfs) in mrst_spi_debugfs_init()
137 dws->debugfs, (void *)dws, &mrst_spi_regs_ops); in mrst_spi_debugfs_init()
141 static void mrst_spi_debugfs_remove(struct dw_spi *dws) in mrst_spi_debugfs_remove() argument
143 if (dws->debugfs) in mrst_spi_debugfs_remove()
144 debugfs_remove_recursive(dws->debugfs); in mrst_spi_debugfs_remove()
148 static inline int mrst_spi_debugfs_init(struct dw_spi *dws) in mrst_spi_debugfs_init() argument
153 static inline void mrst_spi_debugfs_remove(struct dw_spi *dws) in mrst_spi_debugfs_remove() argument
159 static inline u32 tx_max(struct dw_spi *dws) in tx_max() argument
163 tx_left = (dws->tx_end - dws->tx) / dws->n_bytes; in tx_max()
164 tx_room = dws->fifo_len - dw_readw(dws, DW_SPI_TXFLR); in tx_max()
174 rxtx_gap = ((dws->rx_end - dws->rx) - (dws->tx_end - dws->tx)) in tx_max()
175 / dws->n_bytes; in tx_max()
177 return min3(tx_left, tx_room, (u32) (dws->fifo_len - rxtx_gap)); in tx_max()
181 static inline u32 rx_max(struct dw_spi *dws) in rx_max() argument
183 u32 rx_left = (dws->rx_end - dws->rx) / dws->n_bytes; in rx_max()
185 return min(rx_left, (u32)dw_readw(dws, DW_SPI_RXFLR)); in rx_max()
188 static void dw_writer(struct dw_spi *dws) in dw_writer() argument
190 u32 max = tx_max(dws); in dw_writer()
195 if (dws->tx_end - dws->len) { in dw_writer()
196 if (dws->n_bytes == 1) in dw_writer()
197 txw = *(u8 *)(dws->tx); in dw_writer()
199 txw = *(u16 *)(dws->tx); in dw_writer()
201 dw_writew(dws, DW_SPI_DR, txw); in dw_writer()
202 dws->tx += dws->n_bytes; in dw_writer()
206 static void dw_reader(struct dw_spi *dws) in dw_reader() argument
208 u32 max = rx_max(dws); in dw_reader()
212 rxw = dw_readw(dws, DW_SPI_DR); in dw_reader()
214 if (dws->rx_end - dws->len) { in dw_reader()
215 if (dws->n_bytes == 1) in dw_reader()
216 *(u8 *)(dws->rx) = rxw; in dw_reader()
218 *(u16 *)(dws->rx) = rxw; in dw_reader()
220 dws->rx += dws->n_bytes; in dw_reader()
224 static void *next_transfer(struct dw_spi *dws) in next_transfer() argument
226 struct spi_message *msg = dws->cur_msg; in next_transfer()
227 struct spi_transfer *trans = dws->cur_transfer; in next_transfer()
231 dws->cur_transfer = in next_transfer()
245 static int map_dma_buffers(struct dw_spi *dws) in map_dma_buffers() argument
247 if (!dws->cur_msg->is_dma_mapped in map_dma_buffers()
248 || !dws->dma_inited in map_dma_buffers()
249 || !dws->cur_chip->enable_dma in map_dma_buffers()
250 || !dws->dma_ops) in map_dma_buffers()
253 if (dws->cur_transfer->tx_dma) in map_dma_buffers()
254 dws->tx_dma = dws->cur_transfer->tx_dma; in map_dma_buffers()
256 if (dws->cur_transfer->rx_dma) in map_dma_buffers()
257 dws->rx_dma = dws->cur_transfer->rx_dma; in map_dma_buffers()
263 static void giveback(struct dw_spi *dws) in giveback() argument
269 spin_lock_irqsave(&dws->lock, flags); in giveback()
270 msg = dws->cur_msg; in giveback()
271 dws->cur_msg = NULL; in giveback()
272 dws->cur_transfer = NULL; in giveback()
273 dws->prev_chip = dws->cur_chip; in giveback()
274 dws->cur_chip = NULL; in giveback()
275 dws->dma_mapped = 0; in giveback()
276 queue_work(dws->workqueue, &dws->pump_messages); in giveback()
277 spin_unlock_irqrestore(&dws->lock, flags); in giveback()
283 if (!last_transfer->cs_change && dws->cs_control) in giveback()
284 dws->cs_control(MRST_SPI_DEASSERT); in giveback()
291 static void int_error_stop(struct dw_spi *dws, const char *msg) in int_error_stop() argument
294 spi_enable_chip(dws, 0); in int_error_stop()
296 dev_err(&dws->master->dev, "%s\n", msg); in int_error_stop()
297 dws->cur_msg->state = ERROR_STATE; in int_error_stop()
298 tasklet_schedule(&dws->pump_transfers); in int_error_stop()
301 void dw_spi_xfer_done(struct dw_spi *dws) in dw_spi_xfer_done() argument
304 dws->cur_msg->actual_length += dws->len; in dw_spi_xfer_done()
307 dws->cur_msg->state = next_transfer(dws); in dw_spi_xfer_done()
310 if (dws->cur_msg->state == DONE_STATE) { in dw_spi_xfer_done()
311 dws->cur_msg->status = 0; in dw_spi_xfer_done()
312 giveback(dws); in dw_spi_xfer_done()
314 tasklet_schedule(&dws->pump_transfers); in dw_spi_xfer_done()
318 static irqreturn_t interrupt_transfer(struct dw_spi *dws) in interrupt_transfer() argument
320 u16 irq_status = dw_readw(dws, DW_SPI_ISR); in interrupt_transfer()
324 dw_readw(dws, DW_SPI_TXOICR); in interrupt_transfer()
325 dw_readw(dws, DW_SPI_RXOICR); in interrupt_transfer()
326 dw_readw(dws, DW_SPI_RXUICR); in interrupt_transfer()
327 int_error_stop(dws, "interrupt_transfer: fifo overrun/underrun"); in interrupt_transfer()
331 dw_reader(dws); in interrupt_transfer()
332 if (dws->rx_end == dws->rx) { in interrupt_transfer()
333 spi_mask_intr(dws, SPI_INT_TXEI); in interrupt_transfer()
334 dw_spi_xfer_done(dws); in interrupt_transfer()
338 spi_mask_intr(dws, SPI_INT_TXEI); in interrupt_transfer()
339 dw_writer(dws); in interrupt_transfer()
341 spi_umask_intr(dws, SPI_INT_TXEI); in interrupt_transfer()
349 struct dw_spi *dws = dev_id; in dw_spi_irq() local
350 u16 irq_status = dw_readw(dws, DW_SPI_ISR) & 0x3f; in dw_spi_irq()
355 if (!dws->cur_msg) { in dw_spi_irq()
356 spi_mask_intr(dws, SPI_INT_TXEI); in dw_spi_irq()
360 return dws->transfer_handler(dws); in dw_spi_irq()
364 static void poll_transfer(struct dw_spi *dws) in poll_transfer() argument
367 dw_writer(dws); in poll_transfer()
368 dw_reader(dws); in poll_transfer()
370 } while (dws->rx_end > dws->rx); in poll_transfer()
372 dw_spi_xfer_done(dws); in poll_transfer()
377 struct dw_spi *dws = (struct dw_spi *)data; in pump_transfers() local
392 message = dws->cur_msg; in pump_transfers()
393 transfer = dws->cur_transfer; in pump_transfers()
394 chip = dws->cur_chip; in pump_transfers()
398 chip->clk_div = dws->max_freq / chip->speed_hz; in pump_transfers()
420 dws->n_bytes = chip->n_bytes; in pump_transfers()
421 dws->dma_width = chip->dma_width; in pump_transfers()
422 dws->cs_control = chip->cs_control; in pump_transfers()
424 dws->rx_dma = transfer->rx_dma; in pump_transfers()
425 dws->tx_dma = transfer->tx_dma; in pump_transfers()
426 dws->tx = (void *)transfer->tx_buf; in pump_transfers()
427 dws->tx_end = dws->tx + transfer->len; in pump_transfers()
428 dws->rx = transfer->rx_buf; in pump_transfers()
429 dws->rx_end = dws->rx + transfer->len; in pump_transfers()
430 dws->cs_change = transfer->cs_change; in pump_transfers()
431 dws->len = dws->cur_transfer->len; in pump_transfers()
432 if (chip != dws->prev_chip) in pump_transfers()
443 if (speed > dws->max_freq) { in pump_transfers()
451 clk_div = dws->max_freq / speed; in pump_transfers()
464 dws->n_bytes = dws->dma_width = bits >> 3; in pump_transfers()
484 if (dws->cs_control) { in pump_transfers()
485 if (dws->rx && dws->tx) in pump_transfers()
487 else if (dws->rx) in pump_transfers()
497 dws->dma_mapped = map_dma_buffers(dws); in pump_transfers()
503 if (!dws->dma_mapped && !chip->poll_mode) { in pump_transfers()
504 int templen = dws->len / dws->n_bytes; in pump_transfers()
505 txint_level = dws->fifo_len / 2; in pump_transfers()
509 dws->transfer_handler = interrupt_transfer; in pump_transfers()
518 if (dw_readw(dws, DW_SPI_CTRL0) != cr0 || cs_change || clk_div || imask) { in pump_transfers()
519 spi_enable_chip(dws, 0); in pump_transfers()
521 if (dw_readw(dws, DW_SPI_CTRL0) != cr0) in pump_transfers()
522 dw_writew(dws, DW_SPI_CTRL0, cr0); in pump_transfers()
524 spi_set_clk(dws, clk_div ? clk_div : chip->clk_div); in pump_transfers()
525 spi_chip_sel(dws, spi->chip_select); in pump_transfers()
528 spi_mask_intr(dws, 0xff); in pump_transfers()
530 spi_umask_intr(dws, imask); in pump_transfers()
532 dw_writew(dws, DW_SPI_TXFLTR, txint_level); in pump_transfers()
534 spi_enable_chip(dws, 1); in pump_transfers()
536 dws->prev_chip = chip; in pump_transfers()
539 if (dws->dma_mapped) in pump_transfers()
540 dws->dma_ops->dma_transfer(dws, cs_change); in pump_transfers()
543 poll_transfer(dws); in pump_transfers()
548 giveback(dws); in pump_transfers()
554 struct dw_spi *dws = in pump_messages() local
559 spin_lock_irqsave(&dws->lock, flags); in pump_messages()
560 if (list_empty(&dws->queue) || dws->run == QUEUE_STOPPED) { in pump_messages()
561 dws->busy = 0; in pump_messages()
562 spin_unlock_irqrestore(&dws->lock, flags); in pump_messages()
567 if (dws->cur_msg) { in pump_messages()
568 spin_unlock_irqrestore(&dws->lock, flags); in pump_messages()
573 dws->cur_msg = list_entry(dws->queue.next, struct spi_message, queue); in pump_messages()
574 list_del_init(&dws->cur_msg->queue); in pump_messages()
577 dws->cur_msg->state = START_STATE; in pump_messages()
578 dws->cur_transfer = list_entry(dws->cur_msg->transfers.next, in pump_messages()
581 dws->cur_chip = spi_get_ctldata(dws->cur_msg->spi); in pump_messages()
584 tasklet_schedule(&dws->pump_transfers); in pump_messages()
586 dws->busy = 1; in pump_messages()
587 spin_unlock_irqrestore(&dws->lock, flags); in pump_messages()
593 struct dw_spi *dws = spi_master_get_devdata(spi->master); in dw_spi_transfer() local
596 spin_lock_irqsave(&dws->lock, flags); in dw_spi_transfer()
598 if (dws->run == QUEUE_STOPPED) { in dw_spi_transfer()
599 spin_unlock_irqrestore(&dws->lock, flags); in dw_spi_transfer()
607 list_add_tail(&msg->queue, &dws->queue); in dw_spi_transfer()
609 if (dws->run == QUEUE_RUNNING && !dws->busy) { in dw_spi_transfer()
611 if (dws->cur_transfer || dws->cur_msg) in dw_spi_transfer()
612 queue_work(dws->workqueue, in dw_spi_transfer()
613 &dws->pump_messages); in dw_spi_transfer()
616 spin_unlock_irqrestore(&dws->lock, flags); in dw_spi_transfer()
617 pump_messages(&dws->pump_messages); in dw_spi_transfer()
622 spin_unlock_irqrestore(&dws->lock, flags); in dw_spi_transfer()
699 static int __devinit init_queue(struct dw_spi *dws) in init_queue() argument
701 INIT_LIST_HEAD(&dws->queue); in init_queue()
702 spin_lock_init(&dws->lock); in init_queue()
704 dws->run = QUEUE_STOPPED; in init_queue()
705 dws->busy = 0; in init_queue()
707 tasklet_init(&dws->pump_transfers, in init_queue()
708 pump_transfers, (unsigned long)dws); in init_queue()
710 INIT_WORK(&dws->pump_messages, pump_messages); in init_queue()
711 dws->workqueue = create_singlethread_workqueue( in init_queue()
712 dev_name(dws->master->dev.parent)); in init_queue()
713 if (dws->workqueue == NULL) in init_queue()
719 static int start_queue(struct dw_spi *dws) in start_queue() argument
723 spin_lock_irqsave(&dws->lock, flags); in start_queue()
725 if (dws->run == QUEUE_RUNNING || dws->busy) { in start_queue()
726 spin_unlock_irqrestore(&dws->lock, flags); in start_queue()
730 dws->run = QUEUE_RUNNING; in start_queue()
731 dws->cur_msg = NULL; in start_queue()
732 dws->cur_transfer = NULL; in start_queue()
733 dws->cur_chip = NULL; in start_queue()
734 dws->prev_chip = NULL; in start_queue()
735 spin_unlock_irqrestore(&dws->lock, flags); in start_queue()
737 queue_work(dws->workqueue, &dws->pump_messages); in start_queue()
742 static int stop_queue(struct dw_spi *dws) in stop_queue() argument
748 spin_lock_irqsave(&dws->lock, flags); in stop_queue()
749 dws->run = QUEUE_STOPPED; in stop_queue()
750 while ((!list_empty(&dws->queue) || dws->busy) && limit--) { in stop_queue()
751 spin_unlock_irqrestore(&dws->lock, flags); in stop_queue()
753 spin_lock_irqsave(&dws->lock, flags); in stop_queue()
756 if (!list_empty(&dws->queue) || dws->busy) in stop_queue()
758 spin_unlock_irqrestore(&dws->lock, flags); in stop_queue()
763 static int destroy_queue(struct dw_spi *dws) in destroy_queue() argument
767 status = stop_queue(dws); in destroy_queue()
770 destroy_workqueue(dws->workqueue); in destroy_queue()
775 static void spi_hw_init(struct dw_spi *dws) in spi_hw_init() argument
777 spi_enable_chip(dws, 0); in spi_hw_init()
778 spi_mask_intr(dws, 0xff); in spi_hw_init()
779 spi_enable_chip(dws, 1); in spi_hw_init()
785 if (!dws->fifo_len) { in spi_hw_init()
788 dw_writew(dws, DW_SPI_TXFLTR, fifo); in spi_hw_init()
789 if (fifo != dw_readw(dws, DW_SPI_TXFLTR)) in spi_hw_init()
793 dws->fifo_len = (fifo == 257) ? 0 : fifo; in spi_hw_init()
794 dw_writew(dws, DW_SPI_TXFLTR, 0); in spi_hw_init()
798 int __devinit dw_spi_add_host(struct dw_spi *dws) in dw_spi_add_host() argument
803 BUG_ON(dws == NULL); in dw_spi_add_host()
805 master = spi_alloc_master(dws->parent_dev, 0); in dw_spi_add_host()
811 dws->master = master; in dw_spi_add_host()
812 dws->type = SSI_MOTO_SPI; in dw_spi_add_host()
813 dws->prev_chip = NULL; in dw_spi_add_host()
814 dws->dma_inited = 0; in dw_spi_add_host()
815 dws->dma_addr = (dma_addr_t)(dws->paddr + 0x60); in dw_spi_add_host()
816 snprintf(dws->name, sizeof(dws->name), "dw_spi%d", in dw_spi_add_host()
817 dws->bus_num); in dw_spi_add_host()
819 ret = request_irq(dws->irq, dw_spi_irq, IRQF_SHARED, in dw_spi_add_host()
820 dws->name, dws); in dw_spi_add_host()
827 master->bus_num = dws->bus_num; in dw_spi_add_host()
828 master->num_chipselect = dws->num_cs; in dw_spi_add_host()
834 spi_hw_init(dws); in dw_spi_add_host()
836 if (dws->dma_ops && dws->dma_ops->dma_init) { in dw_spi_add_host()
837 ret = dws->dma_ops->dma_init(dws); in dw_spi_add_host()
840 dws->dma_inited = 0; in dw_spi_add_host()
845 ret = init_queue(dws); in dw_spi_add_host()
850 ret = start_queue(dws); in dw_spi_add_host()
856 spi_master_set_devdata(master, dws); in dw_spi_add_host()
863 mrst_spi_debugfs_init(dws); in dw_spi_add_host()
867 destroy_queue(dws); in dw_spi_add_host()
868 if (dws->dma_ops && dws->dma_ops->dma_exit) in dw_spi_add_host()
869 dws->dma_ops->dma_exit(dws); in dw_spi_add_host()
871 spi_enable_chip(dws, 0); in dw_spi_add_host()
872 free_irq(dws->irq, dws); in dw_spi_add_host()
880 void __devexit dw_spi_remove_host(struct dw_spi *dws) in dw_spi_remove_host() argument
884 if (!dws) in dw_spi_remove_host()
886 mrst_spi_debugfs_remove(dws); in dw_spi_remove_host()
889 status = destroy_queue(dws); in dw_spi_remove_host()
891 dev_err(&dws->master->dev, "dw_spi_remove: workqueue will not " in dw_spi_remove_host()
894 if (dws->dma_ops && dws->dma_ops->dma_exit) in dw_spi_remove_host()
895 dws->dma_ops->dma_exit(dws); in dw_spi_remove_host()
896 spi_enable_chip(dws, 0); in dw_spi_remove_host()
898 spi_set_clk(dws, 0); in dw_spi_remove_host()
899 free_irq(dws->irq, dws); in dw_spi_remove_host()
902 spi_unregister_master(dws->master); in dw_spi_remove_host()
906 int dw_spi_suspend_host(struct dw_spi *dws) in dw_spi_suspend_host() argument
910 ret = stop_queue(dws); in dw_spi_suspend_host()
913 spi_enable_chip(dws, 0); in dw_spi_suspend_host()
914 spi_set_clk(dws, 0); in dw_spi_suspend_host()
919 int dw_spi_resume_host(struct dw_spi *dws) in dw_spi_resume_host() argument
923 spi_hw_init(dws); in dw_spi_resume_host()
924 ret = start_queue(dws); in dw_spi_resume_host()
926 dev_err(&dws->master->dev, "fail to start queue (%d)\n", ret); in dw_spi_resume_host()