diff options
-rw-r--r-- | drivers/spi/spi-mpc512x-psc.c | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c index dfddf336912d..759a937d5fa7 100644 --- a/drivers/spi/spi-mpc512x-psc.c +++ b/drivers/spi/spi-mpc512x-psc.c | |||
@@ -33,7 +33,6 @@ | |||
33 | 33 | ||
34 | struct mpc512x_psc_spi { | 34 | struct mpc512x_psc_spi { |
35 | void (*cs_control)(struct spi_device *spi, bool on); | 35 | void (*cs_control)(struct spi_device *spi, bool on); |
36 | u32 sysclk; | ||
37 | 36 | ||
38 | /* driver internal data */ | 37 | /* driver internal data */ |
39 | struct mpc52xx_psc __iomem *psc; | 38 | struct mpc52xx_psc __iomem *psc; |
@@ -42,7 +41,6 @@ struct mpc512x_psc_spi { | |||
42 | u8 bits_per_word; | 41 | u8 bits_per_word; |
43 | u8 busy; | 42 | u8 busy; |
44 | u32 mclk; | 43 | u32 mclk; |
45 | u8 eofbyte; | ||
46 | 44 | ||
47 | struct workqueue_struct *workqueue; | 45 | struct workqueue_struct *workqueue; |
48 | struct work_struct work; | 46 | struct work_struct work; |
@@ -50,7 +48,7 @@ struct mpc512x_psc_spi { | |||
50 | struct list_head queue; | 48 | struct list_head queue; |
51 | spinlock_t lock; /* Message queue lock */ | 49 | spinlock_t lock; /* Message queue lock */ |
52 | 50 | ||
53 | struct completion done; | 51 | struct completion txisrdone; |
54 | }; | 52 | }; |
55 | 53 | ||
56 | /* controller state */ | 54 | /* controller state */ |
@@ -138,7 +136,7 @@ static int mpc512x_psc_spi_transfer_rxtx(struct spi_device *spi, | |||
138 | struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master); | 136 | struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master); |
139 | struct mpc52xx_psc __iomem *psc = mps->psc; | 137 | struct mpc52xx_psc __iomem *psc = mps->psc; |
140 | struct mpc512x_psc_fifo __iomem *fifo = mps->fifo; | 138 | struct mpc512x_psc_fifo __iomem *fifo = mps->fifo; |
141 | size_t len = t->len; | 139 | size_t tx_len = t->len; |
142 | u8 *tx_buf = (u8 *)t->tx_buf; | 140 | u8 *tx_buf = (u8 *)t->tx_buf; |
143 | u8 *rx_buf = (u8 *)t->rx_buf; | 141 | u8 *rx_buf = (u8 *)t->rx_buf; |
144 | 142 | ||
@@ -152,58 +150,57 @@ static int mpc512x_psc_spi_transfer_rxtx(struct spi_device *spi, | |||
152 | /* enable transmiter/receiver */ | 150 | /* enable transmiter/receiver */ |
153 | out_8(&psc->command, MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE); | 151 | out_8(&psc->command, MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE); |
154 | 152 | ||
155 | while (len) { | 153 | while (tx_len) { |
156 | int count; | 154 | size_t txcount; |
157 | int i; | 155 | int i; |
158 | u8 data; | 156 | u8 data; |
159 | size_t fifosz; | 157 | size_t fifosz; |
160 | int rxcount; | 158 | size_t rxcount; |
161 | 159 | ||
162 | /* | 160 | /* |
163 | * The number of bytes that can be sent at a time | 161 | * The number of bytes that can be sent at a time |
164 | * depends on the fifo size. | 162 | * depends on the fifo size. |
165 | */ | 163 | */ |
166 | fifosz = MPC512x_PSC_FIFO_SZ(in_be32(&fifo->txsz)); | 164 | fifosz = MPC512x_PSC_FIFO_SZ(in_be32(&fifo->txsz)); |
167 | count = min(fifosz, len); | 165 | txcount = min(fifosz, tx_len); |
168 | 166 | ||
169 | for (i = count; i > 0; i--) { | 167 | for (i = txcount; i > 0; i--) { |
170 | data = tx_buf ? *tx_buf++ : 0; | 168 | data = tx_buf ? *tx_buf++ : 0; |
171 | if (len == EOFBYTE && t->cs_change) | 169 | if (tx_len == EOFBYTE && t->cs_change) |
172 | setbits32(&fifo->txcmd, MPC512x_PSC_FIFO_EOF); | 170 | setbits32(&fifo->txcmd, MPC512x_PSC_FIFO_EOF); |
173 | out_8(&fifo->txdata_8, data); | 171 | out_8(&fifo->txdata_8, data); |
174 | len--; | 172 | tx_len--; |
175 | } | 173 | } |
176 | 174 | ||
177 | INIT_COMPLETION(mps->done); | 175 | INIT_COMPLETION(mps->txisrdone); |
178 | 176 | ||
179 | /* interrupt on tx fifo empty */ | 177 | /* interrupt on tx fifo empty */ |
180 | out_be32(&fifo->txisr, MPC512x_PSC_FIFO_EMPTY); | 178 | out_be32(&fifo->txisr, MPC512x_PSC_FIFO_EMPTY); |
181 | out_be32(&fifo->tximr, MPC512x_PSC_FIFO_EMPTY); | 179 | out_be32(&fifo->tximr, MPC512x_PSC_FIFO_EMPTY); |
182 | 180 | ||
183 | wait_for_completion(&mps->done); | 181 | wait_for_completion(&mps->txisrdone); |
184 | 182 | ||
185 | mdelay(1); | 183 | mdelay(1); |
186 | 184 | ||
187 | /* rx fifo should have count bytes in it */ | 185 | /* rx fifo should have txcount bytes in it */ |
188 | rxcount = in_be32(&fifo->rxcnt); | 186 | rxcount = in_be32(&fifo->rxcnt); |
189 | if (rxcount != count) | 187 | if (rxcount != txcount) |
190 | mdelay(1); | 188 | mdelay(1); |
191 | 189 | ||
192 | rxcount = in_be32(&fifo->rxcnt); | 190 | rxcount = in_be32(&fifo->rxcnt); |
193 | if (rxcount != count) { | 191 | if (rxcount != txcount) { |
194 | dev_warn(&spi->dev, "expected %d bytes in rx fifo " | 192 | dev_warn(&spi->dev, "expected %d bytes in rx fifo " |
195 | "but got %d\n", count, rxcount); | 193 | "but got %d\n", txcount, rxcount); |
196 | } | 194 | } |
197 | 195 | ||
198 | rxcount = min(rxcount, count); | 196 | rxcount = min(rxcount, txcount); |
199 | for (i = rxcount; i > 0; i--) { | 197 | for (i = rxcount; i > 0; i--) { |
200 | data = in_8(&fifo->rxdata_8); | 198 | data = in_8(&fifo->rxdata_8); |
201 | if (rx_buf) | 199 | if (rx_buf) |
202 | *rx_buf++ = data; | 200 | *rx_buf++ = data; |
203 | } | 201 | } |
204 | while (in_be32(&fifo->rxcnt)) { | 202 | while (in_be32(&fifo->rxcnt)) |
205 | in_8(&fifo->rxdata_8); | 203 | in_8(&fifo->rxdata_8); |
206 | } | ||
207 | } | 204 | } |
208 | /* disable transmiter/receiver and fifo interrupt */ | 205 | /* disable transmiter/receiver and fifo interrupt */ |
209 | out_8(&psc->command, MPC52xx_PSC_TX_DISABLE | MPC52xx_PSC_RX_DISABLE); | 206 | out_8(&psc->command, MPC52xx_PSC_TX_DISABLE | MPC52xx_PSC_RX_DISABLE); |
@@ -412,7 +409,7 @@ static irqreturn_t mpc512x_psc_spi_isr(int irq, void *dev_id) | |||
412 | in_be32(&fifo->tximr) & MPC512x_PSC_FIFO_EMPTY) { | 409 | in_be32(&fifo->tximr) & MPC512x_PSC_FIFO_EMPTY) { |
413 | out_be32(&fifo->txisr, MPC512x_PSC_FIFO_EMPTY); | 410 | out_be32(&fifo->txisr, MPC512x_PSC_FIFO_EMPTY); |
414 | out_be32(&fifo->tximr, 0); | 411 | out_be32(&fifo->tximr, 0); |
415 | complete(&mps->done); | 412 | complete(&mps->txisrdone); |
416 | return IRQ_HANDLED; | 413 | return IRQ_HANDLED; |
417 | } | 414 | } |
418 | return IRQ_NONE; | 415 | return IRQ_NONE; |
@@ -444,11 +441,9 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, | |||
444 | 441 | ||
445 | if (pdata == NULL) { | 442 | if (pdata == NULL) { |
446 | mps->cs_control = mpc512x_spi_cs_control; | 443 | mps->cs_control = mpc512x_spi_cs_control; |
447 | mps->sysclk = 0; | ||
448 | master->bus_num = bus_num; | 444 | master->bus_num = bus_num; |
449 | } else { | 445 | } else { |
450 | mps->cs_control = pdata->cs_control; | 446 | mps->cs_control = pdata->cs_control; |
451 | mps->sysclk = pdata->sysclk; | ||
452 | master->bus_num = pdata->bus_num; | 447 | master->bus_num = pdata->bus_num; |
453 | master->num_chipselect = pdata->max_chipselect; | 448 | master->num_chipselect = pdata->max_chipselect; |
454 | } | 449 | } |
@@ -479,7 +474,7 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, | |||
479 | goto free_irq; | 474 | goto free_irq; |
480 | 475 | ||
481 | spin_lock_init(&mps->lock); | 476 | spin_lock_init(&mps->lock); |
482 | init_completion(&mps->done); | 477 | init_completion(&mps->txisrdone); |
483 | INIT_WORK(&mps->work, mpc512x_psc_spi_work); | 478 | INIT_WORK(&mps->work, mpc512x_psc_spi_work); |
484 | INIT_LIST_HEAD(&mps->queue); | 479 | INIT_LIST_HEAD(&mps->queue); |
485 | 480 | ||