17 #include <linux/module.h>
18 #include <linux/kernel.h>
20 #include <linux/errno.h>
64 static int mpc512x_psc_spi_transfer_setup(
struct spi_device *
spi,
77 static void mpc512x_psc_spi_activate_cs(
struct spi_device *
spi)
110 bclkdiv = (mps->
mclk / 1000000) - 1;
112 ccr |= (((bclkdiv & 0xff) << 16) | (((bclkdiv >> 8) & 0xff) << 8));
120 static void mpc512x_psc_spi_deactivate_cs(
struct spi_device *spi)
130 #define MPC512x_PSC_FIFO_SZ(sz) ((sz & 0x7ff) << 2);
134 static int mpc512x_psc_spi_transfer_rxtx(
struct spi_device *spi,
144 if (!tx_buf && !rx_buf && t->
len)
163 count =
min(fifosz, len);
165 for (i = count; i > 0; i--) {
166 data = tx_buf ? *tx_buf++ : 0;
189 if (rxcount != count)
193 if (rxcount != count) {
194 dev_warn(&spi->
dev,
"expected %d bytes in rx fifo "
195 "but got %d\n", count, rxcount);
198 rxcount =
min(rxcount, count);
199 for (i = rxcount; i > 0; i--) {
223 spin_lock_irq(&mps->
lock);
225 while (!list_empty(&mps->
queue)) {
233 list_del_init(&m->
queue);
234 spin_unlock_irq(&mps->
lock);
241 status = mpc512x_psc_spi_transfer_setup(spi, t);
247 mpc512x_psc_spi_activate_cs(spi);
250 status = mpc512x_psc_spi_transfer_rxtx(spi, t);
259 mpc512x_psc_spi_deactivate_cs(spi);
265 if (status || !cs_change)
266 mpc512x_psc_spi_deactivate_cs(spi);
268 mpc512x_psc_spi_transfer_setup(spi,
NULL);
270 spin_lock_irq(&mps->
lock);
273 spin_unlock_irq(&mps->
lock);
276 static int mpc512x_psc_spi_setup(
struct spi_device *spi)
297 mpc512x_psc_spi_deactivate_cs(spi);
298 spin_unlock_irqrestore(&mps->
lock, flags);
303 static int mpc512x_psc_spi_transfer(
struct spi_device *spi,
315 spin_unlock_irqrestore(&mps->
lock, flags);
320 static void mpc512x_psc_spi_cleanup(
struct spi_device *spi)
325 static int mpc512x_psc_spi_port_config(
struct spi_master *master,
369 bclkdiv = (mps->
mclk / 1000000) - 1;
370 ccr |= (((bclkdiv & 0xff) << 16) | (((bclkdiv >> 8) & 0xff) << 8));
424 mps = spi_master_get_devdata(master);
428 dev_err(dev,
"probe called without platform data, no "
429 "cs_control function will be called\n");
441 master->
setup = mpc512x_psc_spi_setup;
442 master->
transfer = mpc512x_psc_spi_transfer;
443 master->
cleanup = mpc512x_psc_spi_cleanup;
446 tempp =
ioremap(regaddr, size);
448 dev_err(dev,
"could not ioremap I/O port range\n");
457 "mpc512x-psc-spi", mps);
461 ret = mpc512x_psc_spi_port_config(master, mps);
466 init_completion(&mps->
done);
468 INIT_LIST_HEAD(&mps->
queue);
490 spi_master_put(master);
506 spi_master_put(master);
513 const u32 *regaddr_p;
514 u64 regaddr64, size64;
525 if (op->
dev.platform_data ==
NULL) {
529 if (!psc_nump || *psc_nump > 11) {
530 dev_err(&op->
dev,
"mpc512x_psc_spi: Device node %s "
531 "has invalid cell-index property\n",
532 op->
dev.of_node->full_name);
538 return mpc512x_psc_spi_do_probe(&op->
dev, (
u32) regaddr64, (
u32) size64,
544 return mpc512x_psc_spi_do_remove(&op->
dev);
547 static struct of_device_id mpc512x_psc_spi_of_match[] = {
548 { .compatible =
"fsl,mpc5121-psc-spi", },
555 .probe = mpc512x_psc_spi_of_probe,
558 .name =
"mpc512x-psc-spi",
560 .of_match_table = mpc512x_psc_spi_of_match,