1 From e06f04d55752e460d8f332f28317aebc27ab1b17 Mon Sep 17 00:00:00 2001
2 From: Matthew McClintock <mmcclint@codeaurora.org>
3 Date: Tue, 26 Apr 2016 12:57:46 -0500
4 Subject: [PATCH 09/69] spi: qup: refactor spi_qup_io_config in two functions
6 This is preparation for handling transactions larger than 64K-1 bytes in
7 block mode which is currently unsupported quietly fails.
9 We need to break these into two functions 1) prep is called once per
10 spi_message and 2) io_config is calle once per spi-qup bus transaction
12 This is just refactoring, there should be no functional change
14 Signed-off-by: Matthew McClintock <mmcclint@codeaurora.org>
16 drivers/spi/spi-qup.c | 141 ++++++++++++++++++++++++++++++--------------------
17 1 file changed, 86 insertions(+), 55 deletions(-)
19 --- a/drivers/spi/spi-qup.c
20 +++ b/drivers/spi/spi-qup.c
21 @@ -585,12 +585,11 @@ static irqreturn_t spi_qup_qup_irq(int i
25 -/* set clock freq ... bits per word */
26 -static int spi_qup_io_config(struct spi_device *spi, struct spi_transfer *xfer)
27 +/* set clock freq ... bits per word, determine mode */
28 +static int spi_qup_io_prep(struct spi_device *spi, struct spi_transfer *xfer)
30 struct spi_qup *controller = spi_master_get_devdata(spi->master);
31 - u32 config, iomode, control;
35 if (spi->mode & SPI_LOOP && xfer->len > controller->in_fifo_sz) {
36 dev_err(controller->dev, "too big size for loopback %d > %d\n",
37 @@ -605,56 +604,94 @@ static int spi_qup_io_config(struct spi_
41 - if (spi_qup_set_state(controller, QUP_STATE_RESET)) {
42 - dev_err(controller->dev, "cannot set RESET state\n");
46 controller->w_size = DIV_ROUND_UP(xfer->bits_per_word, 8);
47 controller->n_words = xfer->len / controller->w_size;
48 - n_words = controller->n_words;
50 - if (n_words <= (controller->in_fifo_sz / sizeof(u32))) {
51 + if (controller->n_words <= (controller->in_fifo_sz / sizeof(u32)))
52 controller->mode = QUP_IO_M_MODE_FIFO;
53 - writel_relaxed(n_words, controller->base + QUP_MX_READ_CNT);
54 - writel_relaxed(n_words, controller->base + QUP_MX_WRITE_CNT);
55 - /* must be zero for FIFO */
56 - writel_relaxed(0, controller->base + QUP_MX_INPUT_CNT);
57 - writel_relaxed(0, controller->base + QUP_MX_OUTPUT_CNT);
58 - } else if (spi->master->can_dma &&
59 - spi->master->can_dma(spi->master, spi, xfer) &&
60 - spi->master->cur_msg_mapped) {
61 + else if (spi->master->can_dma &&
62 + spi->master->can_dma(spi->master, spi, xfer) &&
63 + spi->master->cur_msg_mapped)
64 controller->mode = QUP_IO_M_MODE_BAM;
65 - writel_relaxed(n_words, controller->base + QUP_MX_INPUT_CNT);
66 - writel_relaxed(n_words, controller->base + QUP_MX_OUTPUT_CNT);
67 - /* must be zero for BLOCK and BAM */
68 - writel_relaxed(0, controller->base + QUP_MX_READ_CNT);
69 - writel_relaxed(0, controller->base + QUP_MX_WRITE_CNT);
71 - if (!controller->qup_v1) {
72 - void __iomem *input_cnt;
74 - input_cnt = controller->base + QUP_MX_INPUT_CNT;
76 - * for DMA transfers, both QUP_MX_INPUT_CNT and
77 - * QUP_MX_OUTPUT_CNT must be zero to all cases but one.
78 - * That case is a non-balanced transfer when there is
82 - writel_relaxed(0, input_cnt);
84 - writel_relaxed(n_words, input_cnt);
86 + controller->mode = QUP_IO_M_MODE_BLOCK;
91 +/* prep qup for another spi transaction of specific type */
92 +static int spi_qup_io_config(struct spi_device *spi, struct spi_transfer *xfer)
94 + struct spi_qup *controller = spi_master_get_devdata(spi->master);
95 + u32 config, iomode, control;
96 + unsigned long flags;
98 + reinit_completion(&controller->done);
99 + reinit_completion(&controller->dma_tx_done);
101 + spin_lock_irqsave(&controller->lock, flags);
102 + controller->xfer = xfer;
103 + controller->error = 0;
104 + controller->rx_bytes = 0;
105 + controller->tx_bytes = 0;
106 + spin_unlock_irqrestore(&controller->lock, flags);
109 + if (spi_qup_set_state(controller, QUP_STATE_RESET)) {
110 + dev_err(controller->dev, "cannot set RESET state\n");
114 + switch (controller->mode) {
115 + case QUP_IO_M_MODE_FIFO:
116 + writel_relaxed(controller->n_words,
117 + controller->base + QUP_MX_READ_CNT);
118 + writel_relaxed(controller->n_words,
119 + controller->base + QUP_MX_WRITE_CNT);
120 + /* must be zero for FIFO */
121 + writel_relaxed(0, controller->base + QUP_MX_INPUT_CNT);
122 writel_relaxed(0, controller->base + QUP_MX_OUTPUT_CNT);
125 - controller->mode = QUP_IO_M_MODE_BLOCK;
126 - writel_relaxed(n_words, controller->base + QUP_MX_INPUT_CNT);
127 - writel_relaxed(n_words, controller->base + QUP_MX_OUTPUT_CNT);
128 - /* must be zero for BLOCK and BAM */
129 - writel_relaxed(0, controller->base + QUP_MX_READ_CNT);
130 - writel_relaxed(0, controller->base + QUP_MX_WRITE_CNT);
132 + case QUP_IO_M_MODE_BAM:
133 + writel_relaxed(controller->n_words,
134 + controller->base + QUP_MX_INPUT_CNT);
135 + writel_relaxed(controller->n_words,
136 + controller->base + QUP_MX_OUTPUT_CNT);
137 + /* must be zero for BLOCK and BAM */
138 + writel_relaxed(0, controller->base + QUP_MX_READ_CNT);
139 + writel_relaxed(0, controller->base + QUP_MX_WRITE_CNT);
140 + if (!controller->qup_v1) {
141 + void __iomem *input_cnt;
143 + input_cnt = controller->base + QUP_MX_INPUT_CNT;
145 + * for DMA transfers, both QUP_MX_INPUT_CNT and
146 + * QUP_MX_OUTPUT_CNT must be zero to all cases
147 + * but one. That case is a non-balanced
148 + * transfer when there is only a rx_buf.
151 + writel_relaxed(0, input_cnt);
153 + writel_relaxed(controller->n_words,
156 + writel_relaxed(0, controller->base + QUP_MX_OUTPUT_CNT);
159 + case QUP_IO_M_MODE_BLOCK:
160 + writel_relaxed(controller->n_words,
161 + controller->base + QUP_MX_INPUT_CNT);
162 + writel_relaxed(controller->n_words,
163 + controller->base + QUP_MX_OUTPUT_CNT);
164 + /* must be zero for BLOCK and BAM */
165 + writel_relaxed(0, controller->base + QUP_MX_READ_CNT);
166 + writel_relaxed(0, controller->base + QUP_MX_WRITE_CNT);
169 + dev_err(controller->dev, "unknown mode = %d\n",
174 iomode = readl_relaxed(controller->base + QUP_IO_M_MODES);
175 @@ -743,6 +780,10 @@ static int spi_qup_transfer_one(struct s
176 unsigned long timeout, flags;
179 + ret = spi_qup_io_prep(spi, xfer);
183 ret = spi_qup_io_config(spi, xfer);
186 @@ -751,16 +792,6 @@ static int spi_qup_transfer_one(struct s
187 timeout = DIV_ROUND_UP(xfer->len * 8, timeout);
188 timeout = 100 * msecs_to_jiffies(timeout);
190 - reinit_completion(&controller->done);
191 - reinit_completion(&controller->dma_tx_done);
193 - spin_lock_irqsave(&controller->lock, flags);
194 - controller->xfer = xfer;
195 - controller->error = 0;
196 - controller->rx_bytes = 0;
197 - controller->tx_bytes = 0;
198 - spin_unlock_irqrestore(&controller->lock, flags);
200 if (spi_qup_is_dma_xfer(controller->mode))
201 ret = spi_qup_do_dma(master, xfer, timeout);