Lines Matching +full:num +full:- +full:transfer +full:- +full:bits
1 // SPDX-License-Identifier: GPL-2.0-only
79 #define MASK_SPBRR_SPBR_BITS ((1 << 10) - 1)
124 * struct pch_spi_data - Holds the SPI channel specific details
131 * @transfer_complete: Status of SPI Transfer
136 * @bpw_len: Length of data to be transferred in bits per
138 * @transfer_active: Flag showing active transfer
140 * transfer
142 * transfer
151 * @cur_trans: The current transfer that this SPI driver is
192 * struct pch_spi_board_data - Holds the SPI device specific details
195 * @num: The number of SPI device instance
200 int num; member
204 int num; member
218 * pch_spi_writereg() - Performs register writes
226 iowrite32(val, (data->io_remap_addr + idx)); in pch_spi_writereg()
230 * pch_spi_readreg() - Performs register reads
237 return ioread32(data->io_remap_addr + idx); in pch_spi_readreg()
254 * pch_spi_clear_fifo() - Clears the Transmit and Receive FIFOs
277 if (data->transfer_active) { in pch_spi_handler_sub()
278 rx_index = data->rx_index; in pch_spi_handler_sub()
279 tx_index = data->tx_index; in pch_spi_handler_sub()
280 bpw_len = data->bpw_len; in pch_spi_handler_sub()
281 pkt_rx_buffer = data->pkt_rx_buff; in pch_spi_handler_sub()
282 pkt_tx_buff = data->pkt_tx_buff; in pch_spi_handler_sub()
296 if ((bpw_len - rx_index) <= PCH_MAX_FIFO_DEPTH) { in pch_spi_handler_sub()
308 data->tx_index = tx_index; in pch_spi_handler_sub()
309 data->rx_index = rx_index; in pch_spi_handler_sub()
311 /* if transfer complete interrupt */ in pch_spi_handler_sub()
315 pch_spi_setclr_reg(data->master, PCH_SPCR, 0, in pch_spi_handler_sub()
318 /* transfer is completed; in pch_spi_handler_sub()
320 data->transfer_complete = true; in pch_spi_handler_sub()
321 data->transfer_active = false; in pch_spi_handler_sub()
322 wake_up(&data->wait); in pch_spi_handler_sub()
324 dev_vdbg(&data->master->dev, in pch_spi_handler_sub()
325 "%s : Transfer is not completed", in pch_spi_handler_sub()
333 * pch_spi_handler() - Interrupt handler
344 struct pch_spi_board_data *board_dat = data->board_dat; in pch_spi_handler()
346 if (board_dat->suspend_sts) { in pch_spi_handler()
347 dev_dbg(&board_dat->pdev->dev, in pch_spi_handler()
352 io_remap_addr = data->io_remap_addr; in pch_spi_handler()
358 dev_err(&board_dat->pdev->dev, "%s Over run error\n", __func__); in pch_spi_handler()
359 if (data->current_msg->complete) { in pch_spi_handler()
360 data->transfer_complete = true; in pch_spi_handler()
361 data->current_msg->status = -EIO; in pch_spi_handler()
362 data->current_msg->complete(data->current_msg->context); in pch_spi_handler()
363 data->bcurrent_msg_processing = false; in pch_spi_handler()
364 data->current_msg = NULL; in pch_spi_handler()
365 data->cur_trans = NULL; in pch_spi_handler()
369 if (data->use_dma) in pch_spi_handler()
378 dev_dbg(&board_dat->pdev->dev, "%s EXIT return value=%d\n", in pch_spi_handler()
385 * pch_spi_set_baud_rate() - Sets SPBR field in SPBRR
401 * pch_spi_set_bits_per_word() - Sets SIZE field in SPBRR
403 * @bits_per_word: Bits per word for SPI transfer.
415 * pch_spi_setup_transfer() - Configures the PCH SPI hardware for transfer
422 dev_dbg(&spi->dev, "%s SPBRR content =%x setting baud rate=%d\n", in pch_spi_setup_transfer()
423 __func__, pch_spi_readreg(spi->master, PCH_SPBRR), in pch_spi_setup_transfer()
424 spi->max_speed_hz); in pch_spi_setup_transfer()
425 pch_spi_set_baud_rate(spi->master, spi->max_speed_hz); in pch_spi_setup_transfer()
427 /* set bits per word */ in pch_spi_setup_transfer()
428 pch_spi_set_bits_per_word(spi->master, spi->bits_per_word); in pch_spi_setup_transfer()
430 if (!(spi->mode & SPI_LSB_FIRST)) in pch_spi_setup_transfer()
432 if (spi->mode & SPI_CPOL) in pch_spi_setup_transfer()
434 if (spi->mode & SPI_CPHA) in pch_spi_setup_transfer()
436 pch_spi_setclr_reg(spi->master, PCH_SPCR, flags, in pch_spi_setup_transfer()
440 pch_spi_clear_fifo(spi->master); in pch_spi_setup_transfer()
444 * pch_spi_reset() - Clears SPI registers
458 struct pch_spi_data *data = spi_master_get_devdata(pspi->master); in pch_spi_transfer()
463 if (data->status == STATUS_EXITING) { in pch_spi_transfer()
464 dev_err(&pspi->dev, "%s status = STATUS_EXITING.\n", __func__); in pch_spi_transfer()
465 retval = -ESHUTDOWN; in pch_spi_transfer()
469 /* If suspended ,return -EINVAL */ in pch_spi_transfer()
470 if (data->board_dat->suspend_sts) { in pch_spi_transfer()
471 dev_err(&pspi->dev, "%s suspend; returning EINVAL\n", __func__); in pch_spi_transfer()
472 retval = -EINVAL; in pch_spi_transfer()
477 pmsg->actual_length = 0; in pch_spi_transfer()
478 dev_dbg(&pspi->dev, "%s - pmsg->status =%d\n", __func__, pmsg->status); in pch_spi_transfer()
480 pmsg->status = -EINPROGRESS; in pch_spi_transfer()
481 spin_lock_irqsave(&data->lock, flags); in pch_spi_transfer()
483 list_add_tail(&pmsg->queue, &data->queue); in pch_spi_transfer()
484 spin_unlock_irqrestore(&data->lock, flags); in pch_spi_transfer()
486 dev_dbg(&pspi->dev, "%s - Invoked list_add_tail\n", __func__); in pch_spi_transfer()
488 schedule_work(&data->work); in pch_spi_transfer()
489 dev_dbg(&pspi->dev, "%s - Invoked queue work\n", __func__); in pch_spi_transfer()
494 dev_dbg(&pspi->dev, "%s RETURN=%d\n", __func__, retval); in pch_spi_transfer()
501 if (data->current_chip != NULL) { in pch_spi_select_chip()
502 if (pspi->chip_select != data->n_curnt_chip) { in pch_spi_select_chip()
503 dev_dbg(&pspi->dev, "%s : different slave\n", __func__); in pch_spi_select_chip()
504 data->current_chip = NULL; in pch_spi_select_chip()
508 data->current_chip = pspi; in pch_spi_select_chip()
510 data->n_curnt_chip = data->current_chip->chip_select; in pch_spi_select_chip()
512 dev_dbg(&pspi->dev, "%s :Invoking pch_spi_setup_transfer\n", __func__); in pch_spi_select_chip()
526 if (data->cur_trans->speed_hz) { in pch_spi_set_tx()
527 dev_dbg(&data->master->dev, "%s:setting baud rate\n", __func__); in pch_spi_set_tx()
528 pch_spi_set_baud_rate(data->master, data->cur_trans->speed_hz); in pch_spi_set_tx()
531 /* set bits per word if needed */ in pch_spi_set_tx()
532 if (data->cur_trans->bits_per_word && in pch_spi_set_tx()
533 (data->current_msg->spi->bits_per_word != data->cur_trans->bits_per_word)) { in pch_spi_set_tx()
534 dev_dbg(&data->master->dev, "%s:set bits per word\n", __func__); in pch_spi_set_tx()
535 pch_spi_set_bits_per_word(data->master, in pch_spi_set_tx()
536 data->cur_trans->bits_per_word); in pch_spi_set_tx()
537 *bpw = data->cur_trans->bits_per_word; in pch_spi_set_tx()
539 *bpw = data->current_msg->spi->bits_per_word; in pch_spi_set_tx()
543 data->tx_index = 0; in pch_spi_set_tx()
544 data->rx_index = 0; in pch_spi_set_tx()
546 data->bpw_len = data->cur_trans->len / (*bpw / 8); in pch_spi_set_tx()
549 size = data->cur_trans->len * sizeof(*data->pkt_tx_buff); in pch_spi_set_tx()
552 data->pkt_tx_buff = kzalloc(size, GFP_KERNEL); in pch_spi_set_tx()
553 if (data->pkt_tx_buff != NULL) { in pch_spi_set_tx()
554 data->pkt_rx_buff = kzalloc(size, GFP_KERNEL); in pch_spi_set_tx()
555 if (!data->pkt_rx_buff) { in pch_spi_set_tx()
556 kfree(data->pkt_tx_buff); in pch_spi_set_tx()
557 data->pkt_tx_buff = NULL; in pch_spi_set_tx()
561 if (!data->pkt_rx_buff) { in pch_spi_set_tx()
562 /* flush queue and set status of all transfers to -ENOMEM */ in pch_spi_set_tx()
563 list_for_each_entry_safe(pmsg, tmp, data->queue.next, queue) { in pch_spi_set_tx()
564 pmsg->status = -ENOMEM; in pch_spi_set_tx()
566 if (pmsg->complete) in pch_spi_set_tx()
567 pmsg->complete(pmsg->context); in pch_spi_set_tx()
570 list_del_init(&pmsg->queue); in pch_spi_set_tx()
576 if (data->cur_trans->tx_buf != NULL) { in pch_spi_set_tx()
578 tx_buf = data->cur_trans->tx_buf; in pch_spi_set_tx()
579 for (j = 0; j < data->bpw_len; j++) in pch_spi_set_tx()
580 data->pkt_tx_buff[j] = *tx_buf++; in pch_spi_set_tx()
582 tx_sbuf = data->cur_trans->tx_buf; in pch_spi_set_tx()
583 for (j = 0; j < data->bpw_len; j++) in pch_spi_set_tx()
584 data->pkt_tx_buff[j] = *tx_sbuf++; in pch_spi_set_tx()
589 n_writes = data->bpw_len; in pch_spi_set_tx()
593 dev_dbg(&data->master->dev, in pch_spi_set_tx()
594 "\n%s:Pulling down SSN low - writing 0x2 to SSNXCR\n", in pch_spi_set_tx()
596 pch_spi_writereg(data->master, PCH_SSNXCR, SSN_LOW); in pch_spi_set_tx()
599 pch_spi_writereg(data->master, PCH_SPDWR, data->pkt_tx_buff[j]); in pch_spi_set_tx()
602 data->tx_index = j; in pch_spi_set_tx()
604 /* reset transfer complete flag */ in pch_spi_set_tx()
605 data->transfer_complete = false; in pch_spi_set_tx()
606 data->transfer_active = true; in pch_spi_set_tx()
612 dev_dbg(&data->master->dev, "%s called\n", __func__); in pch_spi_nomore_transfer()
614 * [To the spi core..indicating end of transfer] */ in pch_spi_nomore_transfer()
615 data->current_msg->status = 0; in pch_spi_nomore_transfer()
617 if (data->current_msg->complete) { in pch_spi_nomore_transfer()
618 dev_dbg(&data->master->dev, in pch_spi_nomore_transfer()
620 data->current_msg->complete(data->current_msg->context); in pch_spi_nomore_transfer()
624 data->bcurrent_msg_processing = false; in pch_spi_nomore_transfer()
626 dev_dbg(&data->master->dev, in pch_spi_nomore_transfer()
627 "%s:data->bcurrent_msg_processing = false\n", __func__); in pch_spi_nomore_transfer()
629 data->current_msg = NULL; in pch_spi_nomore_transfer()
630 data->cur_trans = NULL; in pch_spi_nomore_transfer()
634 if ((list_empty(&data->queue) == 0) && in pch_spi_nomore_transfer()
635 (!data->board_dat->suspend_sts) && in pch_spi_nomore_transfer()
636 (data->status != STATUS_EXITING)) { in pch_spi_nomore_transfer()
641 dev_dbg(&data->master->dev, "%s:Invoke queue_work\n", __func__); in pch_spi_nomore_transfer()
642 schedule_work(&data->work); in pch_spi_nomore_transfer()
643 } else if (data->board_dat->suspend_sts || in pch_spi_nomore_transfer()
644 data->status == STATUS_EXITING) { in pch_spi_nomore_transfer()
645 dev_dbg(&data->master->dev, in pch_spi_nomore_transfer()
648 list_for_each_entry_safe(pmsg, tmp, data->queue.next, queue) { in pch_spi_nomore_transfer()
649 pmsg->status = -EIO; in pch_spi_nomore_transfer()
651 if (pmsg->complete) in pch_spi_nomore_transfer()
652 pmsg->complete(pmsg->context); in pch_spi_nomore_transfer()
655 list_del_init(&pmsg->queue); in pch_spi_nomore_transfer()
663 if ((data->bpw_len) > PCH_MAX_FIFO_DEPTH) in pch_spi_set_ir()
665 pch_spi_setclr_reg(data->master, PCH_SPCR, in pch_spi_set_ir()
672 pch_spi_setclr_reg(data->master, PCH_SPCR, in pch_spi_set_ir()
678 /* Wait until the transfer completes; go to sleep after in pch_spi_set_ir()
679 initiating the transfer. */ in pch_spi_set_ir()
680 dev_dbg(&data->master->dev, in pch_spi_set_ir()
681 "%s:waiting for transfer to get over\n", __func__); in pch_spi_set_ir()
683 wait_event_interruptible(data->wait, data->transfer_complete); in pch_spi_set_ir()
686 pch_spi_writereg(data->master, PCH_SPSR, in pch_spi_set_ir()
687 pch_spi_readreg(data->master, PCH_SPSR)); in pch_spi_set_ir()
688 /* Disable interrupts and SPI transfer */ in pch_spi_set_ir()
689 pch_spi_setclr_reg(data->master, PCH_SPCR, 0, PCH_ALL | SPCR_SPE_BIT); in pch_spi_set_ir()
691 pch_spi_clear_fifo(data->master); in pch_spi_set_ir()
701 if (!data->cur_trans->rx_buf) in pch_spi_copy_rx_data()
705 rx_buf = data->cur_trans->rx_buf; in pch_spi_copy_rx_data()
706 for (j = 0; j < data->bpw_len; j++) in pch_spi_copy_rx_data()
707 *rx_buf++ = data->pkt_rx_buff[j] & 0xFF; in pch_spi_copy_rx_data()
709 rx_sbuf = data->cur_trans->rx_buf; in pch_spi_copy_rx_data()
710 for (j = 0; j < data->bpw_len; j++) in pch_spi_copy_rx_data()
711 *rx_sbuf++ = data->pkt_rx_buff[j]; in pch_spi_copy_rx_data()
724 if (!data->cur_trans->rx_buf) in pch_spi_copy_rx_data_for_dma()
728 rx_buf = data->cur_trans->rx_buf; in pch_spi_copy_rx_data_for_dma()
729 rx_dma_buf = data->dma.rx_buf_virt; in pch_spi_copy_rx_data_for_dma()
730 for (j = 0; j < data->bpw_len; j++) in pch_spi_copy_rx_data_for_dma()
732 data->cur_trans->rx_buf = rx_buf; in pch_spi_copy_rx_data_for_dma()
734 rx_sbuf = data->cur_trans->rx_buf; in pch_spi_copy_rx_data_for_dma()
735 rx_dma_sbuf = data->dma.rx_buf_virt; in pch_spi_copy_rx_data_for_dma()
736 for (j = 0; j < data->bpw_len; j++) in pch_spi_copy_rx_data_for_dma()
738 data->cur_trans->rx_buf = rx_sbuf; in pch_spi_copy_rx_data_for_dma()
748 dma = &data->dma; in pch_spi_start_transfer()
750 spin_lock_irqsave(&data->lock, flags); in pch_spi_start_transfer()
753 pch_spi_setclr_reg(data->master, PCH_SPCR, SPCR_SPE_BIT, PCH_ALL); in pch_spi_start_transfer()
755 spin_unlock_irqrestore(&data->lock, flags); in pch_spi_start_transfer()
757 /* Wait until the transfer completes; go to sleep after in pch_spi_start_transfer()
758 initiating the transfer. */ in pch_spi_start_transfer()
759 dev_dbg(&data->master->dev, in pch_spi_start_transfer()
760 "%s:waiting for transfer to get over\n", __func__); in pch_spi_start_transfer()
761 rtn = wait_event_interruptible_timeout(data->wait, in pch_spi_start_transfer()
762 data->transfer_complete, in pch_spi_start_transfer()
765 dev_err(&data->master->dev, in pch_spi_start_transfer()
766 "%s wait-event timeout\n", __func__); in pch_spi_start_transfer()
768 dma_sync_sg_for_cpu(&data->master->dev, dma->sg_rx_p, dma->nent, in pch_spi_start_transfer()
771 dma_sync_sg_for_cpu(&data->master->dev, dma->sg_tx_p, dma->nent, in pch_spi_start_transfer()
773 memset(data->dma.tx_buf_virt, 0, PAGE_SIZE); in pch_spi_start_transfer()
775 async_tx_ack(dma->desc_rx); in pch_spi_start_transfer()
776 async_tx_ack(dma->desc_tx); in pch_spi_start_transfer()
777 kfree(dma->sg_tx_p); in pch_spi_start_transfer()
778 kfree(dma->sg_rx_p); in pch_spi_start_transfer()
780 spin_lock_irqsave(&data->lock, flags); in pch_spi_start_transfer()
782 /* clear fifo threshold, disable interrupts, disable SPI transfer */ in pch_spi_start_transfer()
783 pch_spi_setclr_reg(data->master, PCH_SPCR, 0, in pch_spi_start_transfer()
787 pch_spi_writereg(data->master, PCH_SPSR, in pch_spi_start_transfer()
788 pch_spi_readreg(data->master, PCH_SPSR)); in pch_spi_start_transfer()
790 pch_spi_clear_fifo(data->master); in pch_spi_start_transfer()
792 spin_unlock_irqrestore(&data->lock, flags); in pch_spi_start_transfer()
801 /* transfer is completed;inform pch_spi_process_messages_dma */ in pch_dma_rx_complete()
802 data->transfer_complete = true; in pch_dma_rx_complete()
803 wake_up_interruptible(&data->wait); in pch_dma_rx_complete()
810 if ((chan->chan_id == param->chan_id) && in pch_spi_filter()
811 (param->dma_dev == chan->device->dev)) { in pch_spi_filter()
812 chan->private = param; in pch_spi_filter()
833 dma = &data->dma; in pch_spi_request_dma()
838 dma_dev = pci_get_slot(data->board_dat->pdev->bus, in pch_spi_request_dma()
839 PCI_DEVFN(PCI_SLOT(data->board_dat->pdev->devfn), 0)); in pch_spi_request_dma()
842 param = &dma->param_tx; in pch_spi_request_dma()
843 param->dma_dev = &dma_dev->dev; in pch_spi_request_dma()
844 param->chan_id = data->ch * 2; /* Tx = 0, 2 */ in pch_spi_request_dma()
845 param->tx_reg = data->io_base_addr + PCH_SPDWR; in pch_spi_request_dma()
846 param->width = width; in pch_spi_request_dma()
849 dev_err(&data->master->dev, in pch_spi_request_dma()
853 dma->chan_tx = chan; in pch_spi_request_dma()
856 param = &dma->param_rx; in pch_spi_request_dma()
857 param->dma_dev = &dma_dev->dev; in pch_spi_request_dma()
858 param->chan_id = data->ch * 2 + 1; /* Rx = Tx + 1 */ in pch_spi_request_dma()
859 param->rx_reg = data->io_base_addr + PCH_SPDRR; in pch_spi_request_dma()
860 param->width = width; in pch_spi_request_dma()
863 dev_err(&data->master->dev, in pch_spi_request_dma()
865 dma_release_channel(dma->chan_tx); in pch_spi_request_dma()
866 dma->chan_tx = NULL; in pch_spi_request_dma()
869 dma->chan_rx = chan; in pch_spi_request_dma()
871 dma->dma_dev = dma_dev; in pch_spi_request_dma()
875 data->use_dma = 0; in pch_spi_request_dma()
882 dma = &data->dma; in pch_spi_release_dma()
883 if (dma->chan_tx) { in pch_spi_release_dma()
884 dma_release_channel(dma->chan_tx); in pch_spi_release_dma()
885 dma->chan_tx = NULL; in pch_spi_release_dma()
887 if (dma->chan_rx) { in pch_spi_release_dma()
888 dma_release_channel(dma->chan_rx); in pch_spi_release_dma()
889 dma->chan_rx = NULL; in pch_spi_release_dma()
892 pci_dev_put(dma->dma_dev); in pch_spi_release_dma()
904 int num; in pch_spi_handle_dma() local
912 dma = &data->dma; in pch_spi_handle_dma()
915 if (data->cur_trans->speed_hz) { in pch_spi_handle_dma()
916 dev_dbg(&data->master->dev, "%s:setting baud rate\n", __func__); in pch_spi_handle_dma()
917 spin_lock_irqsave(&data->lock, flags); in pch_spi_handle_dma()
918 pch_spi_set_baud_rate(data->master, data->cur_trans->speed_hz); in pch_spi_handle_dma()
919 spin_unlock_irqrestore(&data->lock, flags); in pch_spi_handle_dma()
922 /* set bits per word if needed */ in pch_spi_handle_dma()
923 if (data->cur_trans->bits_per_word && in pch_spi_handle_dma()
924 (data->current_msg->spi->bits_per_word != in pch_spi_handle_dma()
925 data->cur_trans->bits_per_word)) { in pch_spi_handle_dma()
926 dev_dbg(&data->master->dev, "%s:set bits per word\n", __func__); in pch_spi_handle_dma()
927 spin_lock_irqsave(&data->lock, flags); in pch_spi_handle_dma()
928 pch_spi_set_bits_per_word(data->master, in pch_spi_handle_dma()
929 data->cur_trans->bits_per_word); in pch_spi_handle_dma()
930 spin_unlock_irqrestore(&data->lock, flags); in pch_spi_handle_dma()
931 *bpw = data->cur_trans->bits_per_word; in pch_spi_handle_dma()
933 *bpw = data->current_msg->spi->bits_per_word; in pch_spi_handle_dma()
935 data->bpw_len = data->cur_trans->len / (*bpw / 8); in pch_spi_handle_dma()
937 if (data->bpw_len > PCH_BUF_SIZE) { in pch_spi_handle_dma()
938 data->bpw_len = PCH_BUF_SIZE; in pch_spi_handle_dma()
939 data->cur_trans->len -= PCH_BUF_SIZE; in pch_spi_handle_dma()
943 if (data->cur_trans->tx_buf != NULL) { in pch_spi_handle_dma()
945 tx_buf = data->cur_trans->tx_buf; in pch_spi_handle_dma()
946 tx_dma_buf = dma->tx_buf_virt; in pch_spi_handle_dma()
947 for (i = 0; i < data->bpw_len; i++) in pch_spi_handle_dma()
950 tx_sbuf = data->cur_trans->tx_buf; in pch_spi_handle_dma()
951 tx_dma_sbuf = dma->tx_buf_virt; in pch_spi_handle_dma()
952 for (i = 0; i < data->bpw_len; i++) in pch_spi_handle_dma()
958 if (data->bpw_len > PCH_DMA_TRANS_SIZE) { in pch_spi_handle_dma()
959 if (data->bpw_len % PCH_DMA_TRANS_SIZE) { in pch_spi_handle_dma()
960 num = data->bpw_len / PCH_DMA_TRANS_SIZE + 1; in pch_spi_handle_dma()
961 rem = data->bpw_len % PCH_DMA_TRANS_SIZE; in pch_spi_handle_dma()
963 num = data->bpw_len / PCH_DMA_TRANS_SIZE; in pch_spi_handle_dma()
968 num = 1; in pch_spi_handle_dma()
969 size = data->bpw_len; in pch_spi_handle_dma()
970 rem = data->bpw_len; in pch_spi_handle_dma()
972 dev_dbg(&data->master->dev, "%s num=%d size=%d rem=%d\n", in pch_spi_handle_dma()
973 __func__, num, size, rem); in pch_spi_handle_dma()
974 spin_lock_irqsave(&data->lock, flags); in pch_spi_handle_dma()
977 pch_spi_setclr_reg(data->master, PCH_SPCR, in pch_spi_handle_dma()
978 ((size - 1) << SPCR_RFIC_FIELD) | in pch_spi_handle_dma()
982 spin_unlock_irqrestore(&data->lock, flags); in pch_spi_handle_dma()
985 dma->sg_rx_p = kmalloc_array(num, sizeof(*dma->sg_rx_p), GFP_ATOMIC); in pch_spi_handle_dma()
986 if (!dma->sg_rx_p) in pch_spi_handle_dma()
989 sg_init_table(dma->sg_rx_p, num); /* Initialize SG table */ in pch_spi_handle_dma()
991 sg = dma->sg_rx_p; in pch_spi_handle_dma()
992 for (i = 0; i < num; i++, sg++) { in pch_spi_handle_dma()
993 if (i == (num - 2)) { in pch_spi_handle_dma()
994 sg->offset = size * i; in pch_spi_handle_dma()
995 sg->offset = sg->offset * (*bpw / 8); in pch_spi_handle_dma()
996 sg_set_page(sg, virt_to_page(dma->rx_buf_virt), rem, in pch_spi_handle_dma()
997 sg->offset); in pch_spi_handle_dma()
999 } else if (i == (num - 1)) { in pch_spi_handle_dma()
1000 sg->offset = size * (i - 1) + rem; in pch_spi_handle_dma()
1001 sg->offset = sg->offset * (*bpw / 8); in pch_spi_handle_dma()
1002 sg_set_page(sg, virt_to_page(dma->rx_buf_virt), size, in pch_spi_handle_dma()
1003 sg->offset); in pch_spi_handle_dma()
1006 sg->offset = size * i; in pch_spi_handle_dma()
1007 sg->offset = sg->offset * (*bpw / 8); in pch_spi_handle_dma()
1008 sg_set_page(sg, virt_to_page(dma->rx_buf_virt), size, in pch_spi_handle_dma()
1009 sg->offset); in pch_spi_handle_dma()
1012 sg_dma_address(sg) = dma->rx_buf_dma + sg->offset; in pch_spi_handle_dma()
1014 sg = dma->sg_rx_p; in pch_spi_handle_dma()
1015 desc_rx = dmaengine_prep_slave_sg(dma->chan_rx, sg, in pch_spi_handle_dma()
1016 num, DMA_DEV_TO_MEM, in pch_spi_handle_dma()
1019 dev_err(&data->master->dev, in pch_spi_handle_dma()
1023 dma_sync_sg_for_device(&data->master->dev, sg, num, DMA_FROM_DEVICE); in pch_spi_handle_dma()
1024 desc_rx->callback = pch_dma_rx_complete; in pch_spi_handle_dma()
1025 desc_rx->callback_param = data; in pch_spi_handle_dma()
1026 dma->nent = num; in pch_spi_handle_dma()
1027 dma->desc_rx = desc_rx; in pch_spi_handle_dma()
1030 if (data->bpw_len > PCH_MAX_FIFO_DEPTH) { in pch_spi_handle_dma()
1031 head = PCH_MAX_FIFO_DEPTH - PCH_DMA_TRANS_SIZE; in pch_spi_handle_dma()
1032 if (data->bpw_len % PCH_DMA_TRANS_SIZE > 4) { in pch_spi_handle_dma()
1033 num = data->bpw_len / PCH_DMA_TRANS_SIZE + 1; in pch_spi_handle_dma()
1034 rem = data->bpw_len % PCH_DMA_TRANS_SIZE - head; in pch_spi_handle_dma()
1036 num = data->bpw_len / PCH_DMA_TRANS_SIZE; in pch_spi_handle_dma()
1037 rem = data->bpw_len % PCH_DMA_TRANS_SIZE + in pch_spi_handle_dma()
1038 PCH_DMA_TRANS_SIZE - head; in pch_spi_handle_dma()
1042 num = 1; in pch_spi_handle_dma()
1043 size = data->bpw_len; in pch_spi_handle_dma()
1044 rem = data->bpw_len; in pch_spi_handle_dma()
1048 dma->sg_tx_p = kmalloc_array(num, sizeof(*dma->sg_tx_p), GFP_ATOMIC); in pch_spi_handle_dma()
1049 if (!dma->sg_tx_p) in pch_spi_handle_dma()
1052 sg_init_table(dma->sg_tx_p, num); /* Initialize SG table */ in pch_spi_handle_dma()
1054 sg = dma->sg_tx_p; in pch_spi_handle_dma()
1055 for (i = 0; i < num; i++, sg++) { in pch_spi_handle_dma()
1057 sg->offset = 0; in pch_spi_handle_dma()
1058 sg_set_page(sg, virt_to_page(dma->tx_buf_virt), size + head, in pch_spi_handle_dma()
1059 sg->offset); in pch_spi_handle_dma()
1061 } else if (i == (num - 1)) { in pch_spi_handle_dma()
1062 sg->offset = head + size * i; in pch_spi_handle_dma()
1063 sg->offset = sg->offset * (*bpw / 8); in pch_spi_handle_dma()
1064 sg_set_page(sg, virt_to_page(dma->tx_buf_virt), rem, in pch_spi_handle_dma()
1065 sg->offset); in pch_spi_handle_dma()
1068 sg->offset = head + size * i; in pch_spi_handle_dma()
1069 sg->offset = sg->offset * (*bpw / 8); in pch_spi_handle_dma()
1070 sg_set_page(sg, virt_to_page(dma->tx_buf_virt), size, in pch_spi_handle_dma()
1071 sg->offset); in pch_spi_handle_dma()
1074 sg_dma_address(sg) = dma->tx_buf_dma + sg->offset; in pch_spi_handle_dma()
1076 sg = dma->sg_tx_p; in pch_spi_handle_dma()
1077 desc_tx = dmaengine_prep_slave_sg(dma->chan_tx, in pch_spi_handle_dma()
1078 sg, num, DMA_MEM_TO_DEV, in pch_spi_handle_dma()
1081 dev_err(&data->master->dev, in pch_spi_handle_dma()
1085 dma_sync_sg_for_device(&data->master->dev, sg, num, DMA_TO_DEVICE); in pch_spi_handle_dma()
1086 desc_tx->callback = NULL; in pch_spi_handle_dma()
1087 desc_tx->callback_param = data; in pch_spi_handle_dma()
1088 dma->nent = num; in pch_spi_handle_dma()
1089 dma->desc_tx = desc_tx; in pch_spi_handle_dma()
1091 dev_dbg(&data->master->dev, "%s:Pulling down SSN low - writing 0x2 to SSNXCR\n", __func__); in pch_spi_handle_dma()
1093 spin_lock_irqsave(&data->lock, flags); in pch_spi_handle_dma()
1094 pch_spi_writereg(data->master, PCH_SSNXCR, SSN_LOW); in pch_spi_handle_dma()
1095 desc_rx->tx_submit(desc_rx); in pch_spi_handle_dma()
1096 desc_tx->tx_submit(desc_tx); in pch_spi_handle_dma()
1097 spin_unlock_irqrestore(&data->lock, flags); in pch_spi_handle_dma()
1099 /* reset transfer complete flag */ in pch_spi_handle_dma()
1100 data->transfer_complete = false; in pch_spi_handle_dma()
1110 dev_dbg(&data->master->dev, "%s data initialized\n", __func__); in pch_spi_process_messages()
1112 spin_lock(&data->lock); in pch_spi_process_messages()
1114 if (data->board_dat->suspend_sts || (data->status == STATUS_EXITING)) { in pch_spi_process_messages()
1115 dev_dbg(&data->master->dev, in pch_spi_process_messages()
1117 list_for_each_entry_safe(pmsg, tmp, data->queue.next, queue) { in pch_spi_process_messages()
1118 pmsg->status = -EIO; in pch_spi_process_messages()
1120 if (pmsg->complete) { in pch_spi_process_messages()
1121 spin_unlock(&data->lock); in pch_spi_process_messages()
1122 pmsg->complete(pmsg->context); in pch_spi_process_messages()
1123 spin_lock(&data->lock); in pch_spi_process_messages()
1127 list_del_init(&pmsg->queue); in pch_spi_process_messages()
1130 spin_unlock(&data->lock); in pch_spi_process_messages()
1134 data->bcurrent_msg_processing = true; in pch_spi_process_messages()
1135 dev_dbg(&data->master->dev, in pch_spi_process_messages()
1136 "%s Set data->bcurrent_msg_processing= true\n", __func__); in pch_spi_process_messages()
1139 data->current_msg = list_entry(data->queue.next, struct spi_message, in pch_spi_process_messages()
1142 list_del_init(&data->current_msg->queue); in pch_spi_process_messages()
1144 data->current_msg->status = 0; in pch_spi_process_messages()
1146 pch_spi_select_chip(data, data->current_msg->spi); in pch_spi_process_messages()
1148 spin_unlock(&data->lock); in pch_spi_process_messages()
1150 if (data->use_dma) in pch_spi_process_messages()
1152 data->current_msg->spi->bits_per_word); in pch_spi_process_messages()
1153 pch_spi_writereg(data->master, PCH_SSNXCR, SSN_NO_CONTROL); in pch_spi_process_messages()
1157 transfer structure from the message otherwise retrieve in pch_spi_process_messages()
1158 the 1st transfer request from the message. */ in pch_spi_process_messages()
1159 spin_lock(&data->lock); in pch_spi_process_messages()
1160 if (data->cur_trans == NULL) { in pch_spi_process_messages()
1161 data->cur_trans = in pch_spi_process_messages()
1162 list_entry(data->current_msg->transfers.next, in pch_spi_process_messages()
1164 dev_dbg(&data->master->dev, in pch_spi_process_messages()
1165 "%s :Getting 1st transfer message\n", in pch_spi_process_messages()
1168 data->cur_trans = in pch_spi_process_messages()
1169 list_entry(data->cur_trans->transfer_list.next, in pch_spi_process_messages()
1171 dev_dbg(&data->master->dev, in pch_spi_process_messages()
1172 "%s :Getting next transfer message\n", in pch_spi_process_messages()
1175 spin_unlock(&data->lock); in pch_spi_process_messages()
1177 if (!data->cur_trans->len) in pch_spi_process_messages()
1179 cnt = (data->cur_trans->len - 1) / PCH_BUF_SIZE + 1; in pch_spi_process_messages()
1180 data->save_total_len = data->cur_trans->len; in pch_spi_process_messages()
1181 if (data->use_dma) { in pch_spi_process_messages()
1183 char *save_rx_buf = data->cur_trans->rx_buf; in pch_spi_process_messages()
1188 data->transfer_complete = true; in pch_spi_process_messages()
1189 data->current_msg->status = -EIO; in pch_spi_process_messages()
1190 data->current_msg->complete in pch_spi_process_messages()
1191 (data->current_msg->context); in pch_spi_process_messages()
1192 data->bcurrent_msg_processing = false; in pch_spi_process_messages()
1193 data->current_msg = NULL; in pch_spi_process_messages()
1194 data->cur_trans = NULL; in pch_spi_process_messages()
1199 data->cur_trans->rx_buf = save_rx_buf; in pch_spi_process_messages()
1204 kfree(data->pkt_rx_buff); in pch_spi_process_messages()
1205 data->pkt_rx_buff = NULL; in pch_spi_process_messages()
1206 kfree(data->pkt_tx_buff); in pch_spi_process_messages()
1207 data->pkt_tx_buff = NULL; in pch_spi_process_messages()
1210 data->cur_trans->len = data->save_total_len; in pch_spi_process_messages()
1211 data->current_msg->actual_length += data->cur_trans->len; in pch_spi_process_messages()
1213 dev_dbg(&data->master->dev, in pch_spi_process_messages()
1214 "%s:data->current_msg->actual_length=%d\n", in pch_spi_process_messages()
1215 __func__, data->current_msg->actual_length); in pch_spi_process_messages()
1217 spi_transfer_delay_exec(data->cur_trans); in pch_spi_process_messages()
1219 spin_lock(&data->lock); in pch_spi_process_messages()
1221 /* No more transfer in this message. */ in pch_spi_process_messages()
1222 if ((data->cur_trans->transfer_list.next) == in pch_spi_process_messages()
1223 &(data->current_msg->transfers)) { in pch_spi_process_messages()
1227 spin_unlock(&data->lock); in pch_spi_process_messages()
1229 } while (data->cur_trans != NULL); in pch_spi_process_messages()
1232 pch_spi_writereg(data->master, PCH_SSNXCR, SSN_HIGH); in pch_spi_process_messages()
1233 if (data->use_dma) in pch_spi_process_messages()
1240 dev_dbg(&board_dat->pdev->dev, "%s ENTRY\n", __func__); in pch_spi_free_resources()
1242 flush_work(&data->work); in pch_spi_free_resources()
1248 dev_dbg(&board_dat->pdev->dev, "%s ENTRY\n", __func__); in pch_spi_get_resources()
1251 pch_spi_reset(data->master); in pch_spi_get_resources()
1252 dev_dbg(&board_dat->pdev->dev, in pch_spi_get_resources()
1255 dev_dbg(&board_dat->pdev->dev, "%s data->irq_reg_sts=true\n", __func__); in pch_spi_get_resources()
1265 dma = &data->dma; in pch_free_dma_buf()
1266 if (dma->tx_buf_dma) in pch_free_dma_buf()
1267 dma_free_coherent(&board_dat->pdev->dev, PCH_BUF_SIZE, in pch_free_dma_buf()
1268 dma->tx_buf_virt, dma->tx_buf_dma); in pch_free_dma_buf()
1269 if (dma->rx_buf_dma) in pch_free_dma_buf()
1270 dma_free_coherent(&board_dat->pdev->dev, PCH_BUF_SIZE, in pch_free_dma_buf()
1271 dma->rx_buf_virt, dma->rx_buf_dma); in pch_free_dma_buf()
1280 dma = &data->dma; in pch_alloc_dma_buf()
1283 dma->tx_buf_virt = dma_alloc_coherent(&board_dat->pdev->dev, in pch_alloc_dma_buf()
1284 PCH_BUF_SIZE, &dma->tx_buf_dma, GFP_KERNEL); in pch_alloc_dma_buf()
1285 if (!dma->tx_buf_virt) in pch_alloc_dma_buf()
1286 ret = -ENOMEM; in pch_alloc_dma_buf()
1289 dma->rx_buf_virt = dma_alloc_coherent(&board_dat->pdev->dev, in pch_alloc_dma_buf()
1290 PCH_BUF_SIZE, &dma->rx_buf_dma, GFP_KERNEL); in pch_alloc_dma_buf()
1291 if (!dma->rx_buf_virt) in pch_alloc_dma_buf()
1292 ret = -ENOMEM; in pch_alloc_dma_buf()
1301 struct pch_spi_board_data *board_dat = dev_get_platdata(&plat_dev->dev); in pch_spi_pd_probe()
1304 dev_dbg(&plat_dev->dev, "%s:debug\n", __func__); in pch_spi_pd_probe()
1306 master = spi_alloc_master(&board_dat->pdev->dev, in pch_spi_pd_probe()
1309 dev_err(&plat_dev->dev, "spi_alloc_master[%d] failed.\n", in pch_spi_pd_probe()
1310 plat_dev->id); in pch_spi_pd_probe()
1311 return -ENOMEM; in pch_spi_pd_probe()
1315 data->master = master; in pch_spi_pd_probe()
1320 data->io_base_addr = pci_resource_start(board_dat->pdev, 1) + in pch_spi_pd_probe()
1321 PCH_ADDRESS_SIZE * plat_dev->id; in pch_spi_pd_probe()
1322 data->io_remap_addr = pci_iomap(board_dat->pdev, 1, 0); in pch_spi_pd_probe()
1323 if (!data->io_remap_addr) { in pch_spi_pd_probe()
1324 dev_err(&plat_dev->dev, "%s pci_iomap failed\n", __func__); in pch_spi_pd_probe()
1325 ret = -ENOMEM; in pch_spi_pd_probe()
1328 data->io_remap_addr += PCH_ADDRESS_SIZE * plat_dev->id; in pch_spi_pd_probe()
1330 dev_dbg(&plat_dev->dev, "[ch%d] remap_addr=%p\n", in pch_spi_pd_probe()
1331 plat_dev->id, data->io_remap_addr); in pch_spi_pd_probe()
1334 master->num_chipselect = PCH_MAX_CS; in pch_spi_pd_probe()
1335 master->transfer = pch_spi_transfer; in pch_spi_pd_probe()
1336 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST; in pch_spi_pd_probe()
1337 master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16); in pch_spi_pd_probe()
1338 master->max_speed_hz = PCH_MAX_BAUDRATE; in pch_spi_pd_probe()
1339 master->flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX; in pch_spi_pd_probe()
1341 data->board_dat = board_dat; in pch_spi_pd_probe()
1342 data->plat_dev = plat_dev; in pch_spi_pd_probe()
1343 data->n_curnt_chip = 255; in pch_spi_pd_probe()
1344 data->status = STATUS_RUNNING; in pch_spi_pd_probe()
1345 data->ch = plat_dev->id; in pch_spi_pd_probe()
1346 data->use_dma = use_dma; in pch_spi_pd_probe()
1348 INIT_LIST_HEAD(&data->queue); in pch_spi_pd_probe()
1349 spin_lock_init(&data->lock); in pch_spi_pd_probe()
1350 INIT_WORK(&data->work, pch_spi_process_messages); in pch_spi_pd_probe()
1351 init_waitqueue_head(&data->wait); in pch_spi_pd_probe()
1355 dev_err(&plat_dev->dev, "%s fail(retval=%d)\n", __func__, ret); in pch_spi_pd_probe()
1359 ret = request_irq(board_dat->pdev->irq, pch_spi_handler, in pch_spi_pd_probe()
1362 dev_err(&plat_dev->dev, in pch_spi_pd_probe()
1366 data->irq_reg_sts = true; in pch_spi_pd_probe()
1371 dev_info(&plat_dev->dev, "Use DMA for data transfers\n"); in pch_spi_pd_probe()
1379 dev_err(&plat_dev->dev, in pch_spi_pd_probe()
1388 free_irq(board_dat->pdev->irq, data); in pch_spi_pd_probe()
1392 pci_iounmap(board_dat->pdev, data->io_remap_addr); in pch_spi_pd_probe()
1401 struct pch_spi_board_data *board_dat = dev_get_platdata(&plat_dev->dev); in pch_spi_pd_remove()
1406 dev_dbg(&plat_dev->dev, "%s:[ch%d] irq=%d\n", in pch_spi_pd_remove()
1407 __func__, plat_dev->id, board_dat->pdev->irq); in pch_spi_pd_remove()
1415 spin_lock_irqsave(&data->lock, flags); in pch_spi_pd_remove()
1416 data->status = STATUS_EXITING; in pch_spi_pd_remove()
1417 while ((list_empty(&data->queue) == 0) && --count) { in pch_spi_pd_remove()
1418 dev_dbg(&board_dat->pdev->dev, "%s :queue not empty\n", in pch_spi_pd_remove()
1420 spin_unlock_irqrestore(&data->lock, flags); in pch_spi_pd_remove()
1422 spin_lock_irqsave(&data->lock, flags); in pch_spi_pd_remove()
1424 spin_unlock_irqrestore(&data->lock, flags); in pch_spi_pd_remove()
1428 if (data->irq_reg_sts) { in pch_spi_pd_remove()
1430 pch_spi_setclr_reg(data->master, PCH_SPCR, 0, PCH_ALL); in pch_spi_pd_remove()
1431 data->irq_reg_sts = false; in pch_spi_pd_remove()
1432 free_irq(board_dat->pdev->irq, data); in pch_spi_pd_remove()
1435 pci_iounmap(board_dat->pdev, data->io_remap_addr); in pch_spi_pd_remove()
1436 spi_unregister_master(data->master); in pch_spi_pd_remove()
1445 struct pch_spi_board_data *board_dat = dev_get_platdata(&pd_dev->dev); in pch_spi_pd_suspend()
1448 dev_dbg(&pd_dev->dev, "%s ENTRY\n", __func__); in pch_spi_pd_suspend()
1451 dev_err(&pd_dev->dev, in pch_spi_pd_suspend()
1453 return -EFAULT; in pch_spi_pd_suspend()
1457 Only after thats done the transfer will be suspended */ in pch_spi_pd_suspend()
1459 while ((--count) > 0) { in pch_spi_pd_suspend()
1460 if (!(data->bcurrent_msg_processing)) in pch_spi_pd_suspend()
1466 if (data->irq_reg_sts) { in pch_spi_pd_suspend()
1468 pch_spi_setclr_reg(data->master, PCH_SPCR, 0, PCH_ALL); in pch_spi_pd_suspend()
1469 pch_spi_reset(data->master); in pch_spi_pd_suspend()
1470 free_irq(board_dat->pdev->irq, data); in pch_spi_pd_suspend()
1472 data->irq_reg_sts = false; in pch_spi_pd_suspend()
1473 dev_dbg(&pd_dev->dev, in pch_spi_pd_suspend()
1482 struct pch_spi_board_data *board_dat = dev_get_platdata(&pd_dev->dev); in pch_spi_pd_resume()
1487 dev_err(&pd_dev->dev, in pch_spi_pd_resume()
1489 return -EFAULT; in pch_spi_pd_resume()
1492 if (!data->irq_reg_sts) { in pch_spi_pd_resume()
1494 retval = request_irq(board_dat->pdev->irq, pch_spi_handler, in pch_spi_pd_resume()
1497 dev_err(&pd_dev->dev, in pch_spi_pd_resume()
1503 pch_spi_reset(data->master); in pch_spi_pd_resume()
1504 pch_spi_set_master_mode(data->master); in pch_spi_pd_resume()
1505 data->irq_reg_sts = true; in pch_spi_pd_resume()
1516 .name = "pch-spi",
1534 return -ENOMEM; in pch_spi_probe()
1538 retval = -ENOMEM; in pch_spi_probe()
1544 dev_err(&pdev->dev, "%s request_region failed\n", __func__); in pch_spi_probe()
1548 board_dat->pdev = pdev; in pch_spi_probe()
1549 board_dat->num = id->driver_data; in pch_spi_probe()
1550 pd_dev_save->num = id->driver_data; in pch_spi_probe()
1551 pd_dev_save->board_dat = board_dat; in pch_spi_probe()
1555 dev_err(&pdev->dev, "%s pci_enable_device failed\n", __func__); in pch_spi_probe()
1559 for (i = 0; i < board_dat->num; i++) { in pch_spi_probe()
1560 pd_dev = platform_device_alloc("pch-spi", i); in pch_spi_probe()
1562 dev_err(&pdev->dev, "platform_device_alloc failed\n"); in pch_spi_probe()
1563 retval = -ENOMEM; in pch_spi_probe()
1566 pd_dev_save->pd_save[i] = pd_dev; in pch_spi_probe()
1567 pd_dev->dev.parent = &pdev->dev; in pch_spi_probe()
1572 dev_err(&pdev->dev, in pch_spi_probe()
1580 dev_err(&pdev->dev, "platform_device_add failed\n"); in pch_spi_probe()
1591 while (--i >= 0) in pch_spi_probe()
1592 platform_device_unregister(pd_dev_save->pd_save[i]); in pch_spi_probe()
1609 dev_dbg(&pdev->dev, "%s ENTRY:pdev=%p\n", __func__, pdev); in pch_spi_remove()
1611 for (i = 0; i < pd_dev_save->num; i++) in pch_spi_remove()
1612 platform_device_unregister(pd_dev_save->pd_save[i]); in pch_spi_remove()
1616 kfree(pd_dev_save->board_dat); in pch_spi_remove()
1626 pd_dev_save->board_dat->suspend_sts = true; in pch_spi_suspend()
1638 pd_dev_save->board_dat->suspend_sts = false; in pch_spi_resume()