History

Merge tag 'spi-for-linus' of git://git.secretlab.ca/git/linux-2.6

Pull SPI changes from Grant Likely: "Bug fixes and new features for SPI device drivers. Also move device tree support code out of drivers/of and into drivers/spi/spi.c where it makes more sense." * tag 'spi-for-linus' of git://git.secretlab.ca/git/linux-2.6: spi: By default setup spi_masters with 1 chipselect and dynamics bus number SPI: PRIMA2: use the newest APIs of PINCTRL to fix compiling errors spi/spi-fsl-spi: reference correct pdata in fsl_spi_cs_control spi: refactor spi-coldfire-qspi to use SPI queue framework. spi/omap2-mcspi: convert to the pump message infrastructure spi/rspi: add dmaengine support spi/topcliff: use correct __devexit_p annotation spi: Dont call prepare/unprepare transfer if not populated spi/ep93xx: clean probe/remove routines spi/devicetree: Move devicetree support code into spi directory spi: use module_pci_driver spi/omap2-mcspi: Trivial optimisation spi: omap2-mcspi: add support for pm_runtime autosuspend spi/omap: Remove bus_num usage for instance index OMAP : SPI : use devm_* functions spi: omap2-mcspi: convert to module_platform_driver spi: omap2-mcspi: make it behave as a module

Linus Torvalds committed 14 years ago

Commit be122ab2 parents b343c8b 1e8a52e21 files · +736 −573Browse files

Unified · Split

21 files
  1. drivers/of/Kconfig +0 −6
  2. drivers/of/Makefile +0 −1
  3. drivers/of/of_spi.c +0 −99
  4. drivers/spi/spi-ath79.c +0 −3
  5. drivers/spi/spi-coldfire-qspi.c +114 −141
  6. drivers/spi/spi-dw-pci.c +1 −12
  7. drivers/spi/spi-ep93xx.c +10 −27
  8. drivers/spi/spi-fsl-espi.c +0 −1
  9. drivers/spi/spi-fsl-lib.c +1 −1
  10. drivers/spi/spi-fsl-spi.c +1 −1
  11. drivers/spi/spi-lm70llp.c +0 −3
  12. drivers/spi/spi-mpc52xx.c +0 −3
  13. drivers/spi/spi-omap2-mcspi.c +159 −214
  14. drivers/spi/spi-ppc4xx.c +0 −4
  15. drivers/spi/spi-pxa2xx-pci.c +1 −11
  16. drivers/spi/spi-rspi.c +314 −6
  17. drivers/spi/spi-sirf.c +8 −12
  18. drivers/spi/spi-topcliff-pch.c +1 −2
  19. drivers/spi/spi.c +95 −3
  20. include/linux/of_spi.h +0 −23
  21. include/linux/spi/rspi.h +31 −0
drivers/of/Kconfig+0−6
@@ -67,12 +67,6 @@ config OF_NET · 66 unmodified lines
6767 depends on NETDEVICES
6868 def_bool y
6969
70−config OF_SPI
71− def_tristate SPI
72− depends on SPI && !SPARC
73− help
74− OpenFirmware SPI accessors
75−
7670 config OF_MDIO
7771 def_tristate PHYLIB
7872 depends on PHYLIB
drivers/of/Makefile+0−1
@@ -7,7 +7,6 @@ obj-$(CONFIG_OF_DEVICE) += device.o platform.o · 6 unmodified lines
77 obj-$(CONFIG_OF_GPIO) += gpio.o
88 obj-$(CONFIG_OF_I2C) += of_i2c.o
99 obj-$(CONFIG_OF_NET) += of_net.o
10−obj-$(CONFIG_OF_SPI) += of_spi.o
1110 obj-$(CONFIG_OF_SELFTEST) += selftest.o
1211 obj-$(CONFIG_OF_MDIO) += of_mdio.o
1312 obj-$(CONFIG_OF_PCI) += of_pci.o
drivers/of/of_spi.c+0−99
@@ -1,99 +0,0 @@
1−/*
2− * SPI OF support routines
3− * Copyright (C) 2008 Secret Lab Technologies Ltd.
4− *
5− * Support routines for deriving SPI device attachments from the device
6− * tree.
7− */
8−
9−#include <linux/module.h>
10−#include <linux/of.h>
11−#include <linux/device.h>
12−#include <linux/spi/spi.h>
13−#include <linux/of_irq.h>
14−#include <linux/of_spi.h>
15−
16−/**
17− * of_register_spi_devices - Register child devices onto the SPI bus
18− * @master: Pointer to spi_master device
19− *
20− * Registers an spi_device for each child node of master node which has a 'reg'
21− * property.
22− */
23−void of_register_spi_devices(struct spi_master *master)
24−{
25− struct spi_device *spi;
26− struct device_node *nc;
27− const __be32 *prop;
28− int rc;
29− int len;
30−
31− if (!master->dev.of_node)
32− return;
33−
34− for_each_child_of_node(master->dev.of_node, nc) {
35− /* Alloc an spi_device */
36− spi = spi_alloc_device(master);
37− if (!spi) {
38− dev_err(&master->dev, "spi_device alloc error for %s\n",
39− nc->full_name);
40− spi_dev_put(spi);
41− continue;
42− }
43−
44− /* Select device driver */
45− if (of_modalias_node(nc, spi->modalias,
46− sizeof(spi->modalias)) < 0) {
47− dev_err(&master->dev, "cannot find modalias for %s\n",
48− nc->full_name);
49− spi_dev_put(spi);
50− continue;
51− }
52−
53− /* Device address */
54− prop = of_get_property(nc, "reg", &len);
55− if (!prop || len < sizeof(*prop)) {
56− dev_err(&master->dev, "%s has no 'reg' property\n",
57− nc->full_name);
58− spi_dev_put(spi);
59− continue;
60− }
61− spi->chip_select = be32_to_cpup(prop);
62−
63− /* Mode (clock phase/polarity/etc.) */
64− if (of_find_property(nc, "spi-cpha", NULL))
65− spi->mode |= SPI_CPHA;
66− if (of_find_property(nc, "spi-cpol", NULL))
67− spi->mode |= SPI_CPOL;
68− if (of_find_property(nc, "spi-cs-high", NULL))
69− spi->mode |= SPI_CS_HIGH;
70−
71− /* Device speed */
72− prop = of_get_property(nc, "spi-max-frequency", &len);
73− if (!prop || len < sizeof(*prop)) {
74− dev_err(&master->dev, "%s has no 'spi-max-frequency' property\n",
75− nc->full_name);
76− spi_dev_put(spi);
77− continue;
78− }
79− spi->max_speed_hz = be32_to_cpup(prop);
80−
81− /* IRQ */
82− spi->irq = irq_of_parse_and_map(nc, 0);
83−
84− /* Store a pointer to the node in the device structure */
85− of_node_get(nc);
86− spi->dev.of_node = nc;
87−
88− /* Register the new device */
89− request_module(spi->modalias);
90− rc = spi_add_device(spi);
91− if (rc) {
92− dev_err(&master->dev, "spi_device register error %s\n",
93− nc->full_name);
94− spi_dev_put(spi);
95− }
96−
97− }
98−}
99−EXPORT_SYMBOL(of_register_spi_devices);
drivers/spi/spi-ath79.c+0−3
@@ -216,9 +216,6 @@ static __devinit int ath79_spi_probe(struct platform_device *pdev) · 215 unmodified lines
216216 if (pdata) {
217217 master->bus_num = pdata->bus_num;
218218 master->num_chipselect = pdata->num_chipselect;
219− } else {
220− master->bus_num = -1;
221− master->num_chipselect = 1;
222219 }
223220
224221 sp->bitbang.master = spi_master_get(master);
drivers/spi/spi-coldfire-qspi.c+114−141
@@ -25,12 +25,12 @@ · 24 unmodified lines
2525 #include <linux/errno.h>
2626 #include <linux/platform_device.h>
2727 #include <linux/sched.h>
28−#include <linux/workqueue.h>
2928 #include <linux/delay.h>
3029 #include <linux/io.h>
3130 #include <linux/clk.h>
3231 #include <linux/err.h>
3332 #include <linux/spi/spi.h>
33+#include <linux/pm_runtime.h>
3434
3535 #include <asm/coldfire.h>
3636 #include <asm/mcfsim.h>
@@ -78,10 +78,7 @@ struct mcfqspi { · 41 unmodified lines
7878
7979 wait_queue_head_t waitq;
8080
81− struct work_struct work;
82− struct workqueue_struct *workq;
83− spinlock_t lock;
84− struct list_head msgq;
81+ struct device *dev;
8582 };
8683
8784 static void mcfqspi_wr_qmr(struct mcfqspi *mcfqspi, u16 val)
@@ -303,120 +300,80 @@ static void mcfqspi_transfer_msg16(struct mcfqspi *mcfqspi, unsigned count, · 215 unmodified lines
303300 }
304301 }
305302
306−static void mcfqspi_work(struct work_struct *work)
303+static int mcfqspi_transfer_one_message(struct spi_master *master,
304+ struct spi_message *msg)
307305 {
308− struct mcfqspi *mcfqspi = container_of(work, struct mcfqspi, work);
309− unsigned long flags;
310−
311− spin_lock_irqsave(&mcfqspi->lock, flags);
312− while (!list_empty(&mcfqspi->msgq)) {
313− struct spi_message *msg;
314− struct spi_device *spi;
315− struct spi_transfer *xfer;
316− int status = 0;
317−
318− msg = container_of(mcfqspi->msgq.next, struct spi_message,
319− queue);
320−
321− list_del_init(&msg->queue);
322− spin_unlock_irqrestore(&mcfqspi->lock, flags);
323−
324− spi = msg->spi;
325−
326− list_for_each_entry(xfer, &msg->transfers, transfer_list) {
327− bool cs_high = spi->mode & SPI_CS_HIGH;
328− u16 qmr = MCFQSPI_QMR_MSTR;
329−
330− if (xfer->bits_per_word)
331− qmr |= xfer->bits_per_word << 10;
332− else
333− qmr |= spi->bits_per_word << 10;
334− if (spi->mode & SPI_CPHA)
335− qmr |= MCFQSPI_QMR_CPHA;
336− if (spi->mode & SPI_CPOL)
337− qmr |= MCFQSPI_QMR_CPOL;
338− if (xfer->speed_hz)
339− qmr |= mcfqspi_qmr_baud(xfer->speed_hz);
340− else
341− qmr |= mcfqspi_qmr_baud(spi->max_speed_hz);
342− mcfqspi_wr_qmr(mcfqspi, qmr);
343−
344− mcfqspi_cs_select(mcfqspi, spi->chip_select, cs_high);
345−
346− mcfqspi_wr_qir(mcfqspi, MCFQSPI_QIR_SPIFE);
347− if ((xfer->bits_per_word ? xfer->bits_per_word :
348− spi->bits_per_word) == 8)
349− mcfqspi_transfer_msg8(mcfqspi, xfer->len,
350− xfer->tx_buf,
351− xfer->rx_buf);
352− else
353− mcfqspi_transfer_msg16(mcfqspi, xfer->len / 2,
354− xfer->tx_buf,
355− xfer->rx_buf);
356− mcfqspi_wr_qir(mcfqspi, 0);
357−
358− if (xfer->delay_usecs)
359− udelay(xfer->delay_usecs);
360− if (xfer->cs_change) {
361− if (!list_is_last(&xfer->transfer_list,
362− &msg->transfers))
363− mcfqspi_cs_deselect(mcfqspi,
364− spi->chip_select,
365− cs_high);
366− } else {
367− if (list_is_last(&xfer->transfer_list,
368− &msg->transfers))
369− mcfqspi_cs_deselect(mcfqspi,
370− spi->chip_select,
371− cs_high);
372− }
373− msg->actual_length += xfer->len;
306+ struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
307+ struct spi_device *spi = msg->spi;
308+ struct spi_transfer *t;
309+ int status = 0;
310+
311+ list_for_each_entry(t, &msg->transfers, transfer_list) {
312+ bool cs_high = spi->mode & SPI_CS_HIGH;
313+ u16 qmr = MCFQSPI_QMR_MSTR;
314+
315+ if (t->bits_per_word)
316+ qmr |= t->bits_per_word << 10;
317+ else
318+ qmr |= spi->bits_per_word << 10;
319+ if (spi->mode & SPI_CPHA)
320+ qmr |= MCFQSPI_QMR_CPHA;
321+ if (spi->mode & SPI_CPOL)
322+ qmr |= MCFQSPI_QMR_CPOL;
323+ if (t->speed_hz)
324+ qmr |= mcfqspi_qmr_baud(t->speed_hz);
325+ else
326+ qmr |= mcfqspi_qmr_baud(spi->max_speed_hz);
327+ mcfqspi_wr_qmr(mcfqspi, qmr);
328+
329+ mcfqspi_cs_select(mcfqspi, spi->chip_select, cs_high);
330+
331+ mcfqspi_wr_qir(mcfqspi, MCFQSPI_QIR_SPIFE);
332+ if ((t->bits_per_word ? t->bits_per_word :
333+ spi->bits_per_word) == 8)
334+ mcfqspi_transfer_msg8(mcfqspi, t->len, t->tx_buf,
335+ t->rx_buf);
336+ else
337+ mcfqspi_transfer_msg16(mcfqspi, t->len / 2, t->tx_buf,
338+ t->rx_buf);
339+ mcfqspi_wr_qir(mcfqspi, 0);
340+
341+ if (t->delay_usecs)
342+ udelay(t->delay_usecs);
343+ if (t->cs_change) {
344+ if (!list_is_last(&t->transfer_list, &msg->transfers))
345+ mcfqspi_cs_deselect(mcfqspi, spi->chip_select,
346+ cs_high);
347+ } else {
348+ if (list_is_last(&t->transfer_list, &msg->transfers))
349+ mcfqspi_cs_deselect(mcfqspi, spi->chip_select,
350+ cs_high);
374351 }
375− msg->status = status;
376− msg->complete(msg->context);
377−
378− spin_lock_irqsave(&mcfqspi->lock, flags);
352+ msg->actual_length += t->len;
379353 }
380− spin_unlock_irqrestore(&mcfqspi->lock, flags);
354+ msg->status = status;
355+ spi_finalize_current_message(master);
356+
357+ return status;
358+
381359 }
382360
383−static int mcfqspi_transfer(struct spi_device *spi, struct spi_message *msg)
361+static int mcfqspi_prepare_transfer_hw(struct spi_master *master)
384362 {
385− struct mcfqspi *mcfqspi;
386− struct spi_transfer *xfer;
387− unsigned long flags;
388−
389− mcfqspi = spi_master_get_devdata(spi->master);
390−
391− list_for_each_entry(xfer, &msg->transfers, transfer_list) {
392− if (xfer->bits_per_word && ((xfer->bits_per_word < 8)
393− || (xfer->bits_per_word > 16))) {
394− dev_dbg(&spi->dev,
395− "%d bits per word is not supported\n",
396− xfer->bits_per_word);
397− goto fail;
398− }
399− if (xfer->speed_hz) {
400− u32 real_speed = MCFQSPI_BUSCLK /
401− mcfqspi_qmr_baud(xfer->speed_hz);
402− if (real_speed != xfer->speed_hz)
403− dev_dbg(&spi->dev,
404− "using speed %d instead of %d\n",
405− real_speed, xfer->speed_hz);
406− }
407− }
408− msg->status = -EINPROGRESS;
409− msg->actual_length = 0;
363+ struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
410364
411− spin_lock_irqsave(&mcfqspi->lock, flags);
412− list_add_tail(&msg->queue, &mcfqspi->msgq);
413− queue_work(mcfqspi->workq, &mcfqspi->work);
414− spin_unlock_irqrestore(&mcfqspi->lock, flags);
365+ pm_runtime_get_sync(mcfqspi->dev);
366+
367+ return 0;
368+}
369+
370+static int mcfqspi_unprepare_transfer_hw(struct spi_master *master)
371+{
372+ struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
373+
374+ pm_runtime_put_sync(mcfqspi->dev);
415375
416376 return 0;
417−fail:
418− msg->status = -EINVAL;
419− return -EINVAL;
420377 }
421378
422379 static int mcfqspi_setup(struct spi_device *spi)
@@ -502,21 +459,10 @@ static int __devinit mcfqspi_probe(struct platform_device *pdev) · 79 unmodified lines
502459 }
503460 clk_enable(mcfqspi->clk);
504461
505− mcfqspi->workq = create_singlethread_workqueue(dev_name(master->dev.parent));
506− if (!mcfqspi->workq) {
507− dev_dbg(&pdev->dev, "create_workqueue failed\n");
508− status = -ENOMEM;
509− goto fail4;
510− }
511− INIT_WORK(&mcfqspi->work, mcfqspi_work);
512− spin_lock_init(&mcfqspi->lock);
513− INIT_LIST_HEAD(&mcfqspi->msgq);
514− init_waitqueue_head(&mcfqspi->waitq);
515−
516462 pdata = pdev->dev.platform_data;
517463 if (!pdata) {
518464 dev_dbg(&pdev->dev, "platform data is missing\n");
519− goto fail5;
465+ goto fail4;
520466 }
521467 master->bus_num = pdata->bus_num;
522468 master->num_chipselect = pdata->num_chipselect;
@@ -525,28 +471,33 @@ static int __devinit mcfqspi_probe(struct platform_device *pdev) · 2 unmodified lines
525471 status = mcfqspi_cs_setup(mcfqspi);
526472 if (status) {
527473 dev_dbg(&pdev->dev, "error initializing cs_control\n");
528− goto fail5;
474+ goto fail4;
529475 }
530476
477+ init_waitqueue_head(&mcfqspi->waitq);
478+ mcfqspi->dev = &pdev->dev;
479+
531480 master->mode_bits = SPI_CS_HIGH | SPI_CPOL | SPI_CPHA;
532481 master->setup = mcfqspi_setup;
533− master->transfer = mcfqspi_transfer;
482+ master->transfer_one_message = mcfqspi_transfer_one_message;
483+ master->prepare_transfer_hardware = mcfqspi_prepare_transfer_hw;
484+ master->unprepare_transfer_hardware = mcfqspi_unprepare_transfer_hw;
534485
535486 platform_set_drvdata(pdev, master);
536487
537488 status = spi_register_master(master);
538489 if (status) {
539490 dev_dbg(&pdev->dev, "spi_register_master failed\n");
540− goto fail6;
491+ goto fail5;
541492 }
493+ pm_runtime_enable(mcfqspi->dev);
494+
542495 dev_info(&pdev->dev, "Coldfire QSPI bus driver\n");
543496
544497 return 0;
545498
546−fail6:
547− mcfqspi_cs_teardown(mcfqspi);
548499 fail5:
549− destroy_workqueue(mcfqspi->workq);
500+ mcfqspi_cs_teardown(mcfqspi);
550501 fail4:
551502 clk_disable(mcfqspi->clk);
552503 clk_put(mcfqspi->clk);
@@ -570,12 +521,12 @@ static int __devexit mcfqspi_remove(struct platform_device *pdev) · 17 unmodified lines
570521 struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
571522 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
572523
524+ pm_runtime_disable(mcfqspi->dev);
573525 /* disable the hardware (set the baud rate to 0) */
574526 mcfqspi_wr_qmr(mcfqspi, MCFQSPI_QMR_MSTR);
575527
576528 platform_set_drvdata(pdev, NULL);
577529 mcfqspi_cs_teardown(mcfqspi);
578− destroy_workqueue(mcfqspi->workq);
579530 clk_disable(mcfqspi->clk);
580531 clk_put(mcfqspi->clk);
581532 free_irq(mcfqspi->irq, mcfqspi);
@@ -587,11 +538,13 @@ static int __devexit mcfqspi_remove(struct platform_device *pdev) · 5 unmodified lines
587538 return 0;
588539 }
589540
590−#ifdef CONFIG_PM
591−
541+#ifdef CONFIG_PM_SLEEP
592542 static int mcfqspi_suspend(struct device *dev)
593543 {
594− struct mcfqspi *mcfqspi = platform_get_drvdata(to_platform_device(dev));
544+ struct spi_master *master = spi_master_get(dev_get_drvdata(dev));
545+ struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
546+
547+ spi_master_suspend(master);
595548
596549 clk_disable(mcfqspi->clk);
597550
@@ -600,27 +553,47 @@ static int mcfqspi_suspend(struct device *dev) · 2 unmodified lines
600553
601554 static int mcfqspi_resume(struct device *dev)
602555 {
603− struct mcfqspi *mcfqspi = platform_get_drvdata(to_platform_device(dev));
556+ struct spi_master *master = spi_master_get(dev_get_drvdata(dev));
557+ struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
558+
559+ spi_master_resume(master);
604560
605561 clk_enable(mcfqspi->clk);
606562
607563 return 0;
608564 }
565+#endif
609566
610−static struct dev_pm_ops mcfqspi_dev_pm_ops = {
611− .suspend = mcfqspi_suspend,
612− .resume = mcfqspi_resume,
613−};
567+#ifdef CONFIG_PM_RUNTIME
568+static int mcfqspi_runtime_suspend(struct device *dev)
569+{
570+ struct mcfqspi *mcfqspi = platform_get_drvdata(to_platform_device(dev));
614571
615−#define MCFQSPI_DEV_PM_OPS (&mcfqspi_dev_pm_ops)
616−#else
617−#define MCFQSPI_DEV_PM_OPS NULL
572+ clk_disable(mcfqspi->clk);
573+
574+ return 0;
575+}
576+
577+static int mcfqspi_runtime_resume(struct device *dev)
578+{
579+ struct mcfqspi *mcfqspi = platform_get_drvdata(to_platform_device(dev));
580+
581+ clk_enable(mcfqspi->clk);
582+
583+ return 0;
584+}
618585 #endif
619586
587+static const struct dev_pm_ops mcfqspi_pm = {
588+ SET_SYSTEM_SLEEP_PM_OPS(mcfqspi_suspend, mcfqspi_resume)
589+ SET_RUNTIME_PM_OPS(mcfqspi_runtime_suspend, mcfqspi_runtime_resume,
590+ NULL)
591+};
592+
620593 static struct platform_driver mcfqspi_driver = {
621594 .driver.name = DRIVER_NAME,
622595 .driver.owner = THIS_MODULE,
623− .driver.pm = MCFQSPI_DEV_PM_OPS,
596+ .driver.pm = &mcfqspi_pm,
624597 .probe = mcfqspi_probe,
625598 .remove = __devexit_p(mcfqspi_remove),
626599 };
drivers/spi/spi-dw-pci.c+1−12
@@ -164,18 +164,7 @@ static struct pci_driver dw_spi_driver = { · 163 unmodified lines
164164 .resume = spi_resume,
165165 };
166166
167−static int __init mrst_spi_init(void)
168−{
169− return pci_register_driver(&dw_spi_driver);
170−}
171−
172−static void __exit mrst_spi_exit(void)
173−{
174− pci_unregister_driver(&dw_spi_driver);
175−}
176−
177−module_init(mrst_spi_init);
178−module_exit(mrst_spi_exit);
167+module_pci_driver(dw_spi_driver);
179168
180169 MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>");
181170 MODULE_DESCRIPTION("PCI interface driver for DW SPI Core");
drivers/spi/spi-ep93xx.c+10−27
@@ -76,7 +76,6 @@ · 75 unmodified lines
7676 * @clk: clock for the controller
7777 * @regs_base: pointer to ioremap()'d registers
7878 * @sspdr_phys: physical address of the SSPDR register
79− * @irq: IRQ number used by the driver
8079 * @min_rate: minimum clock rate (in Hz) supported by the controller
8180 * @max_rate: maximum clock rate (in Hz) supported by the controller
8281 * @running: is the queue running
@@ -114,7 +113,6 @@ struct ep93xx_spi { · 31 unmodified lines
114113 struct clk *clk;
115114 void __iomem *regs_base;
116115 unsigned long sspdr_phys;
117− int irq;
118116 unsigned long min_rate;
119117 unsigned long max_rate;
120118 bool running;
@@ -1031,6 +1029,7 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev) · 910 unmodified lines
10311029 struct ep93xx_spi_info *info;
10321030 struct ep93xx_spi *espi;
10331031 struct resource *res;
1032+ int irq;
10341033 int error;
10351034
10361035 info = pdev->dev.platform_data;
@@ -1070,8 +1069,8 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev) · 33 unmodified lines
10701069 espi->min_rate = clk_get_rate(espi->clk) / (254 * 256);
10711070 espi->pdev = pdev;
10721071
1073− espi->irq = platform_get_irq(pdev, 0);
1074− if (espi->irq < 0) {
1072+ irq = platform_get_irq(pdev, 0);
1073+ if (irq < 0) {
10751074 error = -EBUSY;
10761075 dev_err(&pdev->dev, "failed to get irq resources\n");
10771076 goto fail_put_clock;
@@ -1084,26 +1083,20 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev) · 6 unmodified lines
10841083 goto fail_put_clock;
10851084 }
10861085
1087− res = request_mem_region(res->start, resource_size(res), pdev->name);
1088− if (!res) {
1089− dev_err(&pdev->dev, "unable to request iomem resources\n");
1090− error = -EBUSY;
1091− goto fail_put_clock;
1092− }
1093−
10941086 espi->sspdr_phys = res->start + SSPDR;
1095− espi->regs_base = ioremap(res->start, resource_size(res));
1087+
1088+ espi->regs_base = devm_request_and_ioremap(&pdev->dev, res);
10961089 if (!espi->regs_base) {
10971090 dev_err(&pdev->dev, "failed to map resources\n");
10981091 error = -ENODEV;
1099− goto fail_free_mem;
1092+ goto fail_put_clock;
11001093 }
11011094
1102− error = request_irq(espi->irq, ep93xx_spi_interrupt, 0,
1103− "ep93xx-spi", espi);
1095+ error = devm_request_irq(&pdev->dev, irq, ep93xx_spi_interrupt,
1096+ 0, "ep93xx-spi", espi);
11041097 if (error) {
11051098 dev_err(&pdev->dev, "failed to request irq\n");
1106− goto fail_unmap_regs;
1099+ goto fail_put_clock;
11071100 }
11081101
11091102 if (info->use_dma && ep93xx_spi_setup_dma(espi))
@@ -1128,7 +1121,7 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev) · 18 unmodified lines
11281121 }
11291122
11301123 dev_info(&pdev->dev, "EP93xx SPI Controller at 0x%08lx irq %d\n",
1131− (unsigned long)res->start, espi->irq);
1124+ (unsigned long)res->start, irq);
11321125
11331126 return 0;
11341127
@@ -1136,11 +1129,6 @@ fail_free_queue: · 1 unmodified line
11361129 destroy_workqueue(espi->wq);
11371130 fail_free_dma:
11381131 ep93xx_spi_release_dma(espi);
1139− free_irq(espi->irq, espi);
1140−fail_unmap_regs:
1141− iounmap(espi->regs_base);
1142−fail_free_mem:
1143− release_mem_region(res->start, resource_size(res));
11441132 fail_put_clock:
11451133 clk_put(espi->clk);
11461134 fail_release_master:
@@ -1154,7 +1142,6 @@ static int __devexit ep93xx_spi_remove(struct platform_device *pdev) · 7 unmodified lines
11541142 {
11551143 struct spi_master *master = platform_get_drvdata(pdev);
11561144 struct ep93xx_spi *espi = spi_master_get_devdata(master);
1157− struct resource *res;
11581145
11591146 spin_lock_irq(&espi->lock);
11601147 espi->running = false;
@@ -1180,10 +1167,6 @@ static int __devexit ep93xx_spi_remove(struct platform_device *pdev) · 19 unmodified lines
11801167 spin_unlock_irq(&espi->lock);
11811168
11821169 ep93xx_spi_release_dma(espi);
1183− free_irq(espi->irq, espi);
1184− iounmap(espi->regs_base);
1185− res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1186− release_mem_region(res->start, resource_size(res));
11871170 clk_put(espi->clk);
11881171 platform_set_drvdata(pdev, NULL);
11891172
drivers/spi/spi-fsl-espi.c+0−1
@@ -17,7 +17,6 @@ · 16 unmodified lines
1717 #include <linux/mm.h>
1818 #include <linux/of.h>
1919 #include <linux/of_platform.h>
20−#include <linux/of_spi.h>
2120 #include <linux/interrupt.h>
2221 #include <linux/err.h>
2322 #include <sysdev/fsl_soc.h>
drivers/spi/spi-fsl-lib.c+1−1
@@ -22,7 +22,7 @@ · 21 unmodified lines
2222 #include <linux/dma-mapping.h>
2323 #include <linux/mm.h>
2424 #include <linux/of_platform.h>
25−#include <linux/of_spi.h>
25+#include <linux/spi/spi.h>
2626 #include <sysdev/fsl_soc.h>
2727
2828 #include "spi-fsl-lib.h"
drivers/spi/spi-fsl-spi.c+1−1
@@ -933,7 +933,7 @@ err: · 932 unmodified lines
933933
934934 static void fsl_spi_cs_control(struct spi_device *spi, bool on)
935935 {
936− struct device *dev = spi->dev.parent;
936+ struct device *dev = spi->dev.parent->parent;
937937 struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(dev->platform_data);
938938 u16 cs = spi->chip_select;
939939 int gpio = pinfo->gpios[cs];
drivers/spi/spi-lm70llp.c+0−3
@@ -219,9 +219,6 @@ static void spi_lm70llp_attach(struct parport *p) · 218 unmodified lines
219219 }
220220 pp = spi_master_get_devdata(master);
221221
222− master->bus_num = -1; /* dynamic alloc of a bus number */
223− master->num_chipselect = 1;
224−
225222 /*
226223 * SPI and bitbang hookup.
227224 */
drivers/spi/spi-mpc52xx.c+0−3
@@ -433,7 +433,6 @@ static int __devinit mpc52xx_spi_probe(struct platform_device *op) · 432 unmodified lines
433433 goto err_alloc;
434434 }
435435
436− master->bus_num = -1;
437436 master->setup = mpc52xx_spi_setup;
438437 master->transfer = mpc52xx_spi_transfer;
439438 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
@@ -479,8 +478,6 @@ static int __devinit mpc52xx_spi_probe(struct platform_device *op) · 39 unmodified lines
479478 gpio_direction_output(gpio_cs, 1);
480479 ms->gpio_cs[i] = gpio_cs;
481480 }
482− } else {
483− master->num_chipselect = 1;
484481 }
485482
486483 spin_lock_init(&ms->lock);
drivers/spi/spi-omap2-mcspi.c+159−214
@@ -44,9 +44,7 @@ · 43 unmodified lines
4444 #include <plat/mcspi.h>
4545
4646 #define OMAP2_MCSPI_MAX_FREQ 48000000
47−
48−/* OMAP2 has 3 SPI controllers, while OMAP3 has 4 */
49−#define OMAP2_MCSPI_MAX_CTRL 4
47+#define SPI_AUTOSUSPEND_TIMEOUT 2000
5048
5149 #define OMAP2_MCSPI_REVISION 0x00
5250 #define OMAP2_MCSPI_SYSSTATUS 0x14
@@ -111,19 +109,25 @@ struct omap2_mcspi_dma { · 58 unmodified lines
111109 #define DMA_MIN_BYTES 160
112110
113111
112+/*
113+ * Used for context save and restore, structure members to be updated whenever
114+ * corresponding registers are modified.
115+ */
116+struct omap2_mcspi_regs {
117+ u32 modulctrl;
118+ u32 wakeupenable;
119+ struct list_head cs;
120+};
121+
114122 struct omap2_mcspi {
115− struct work_struct work;
116− /* lock protects queue and registers */
117− spinlock_t lock;
118− struct list_head msg_queue;
119123 struct spi_master *master;
120124 /* Virtual base address of the controller */
121125 void __iomem *base;
122126 unsigned long phys;
123127 /* SPI1 has 4 channels, while SPI2 has 2 */
124128 struct omap2_mcspi_dma *dma_channels;
125− struct device *dev;
126− struct workqueue_struct *wq;
129+ struct device *dev;
130+ struct omap2_mcspi_regs ctx;
127131 };
128132
129133 struct omap2_mcspi_cs {
@@ -135,17 +139,6 @@ struct omap2_mcspi_cs { · 5 unmodified lines
135139 u32 chconf0;
136140 };
137141
138−/* used for context save and restore, structure members to be updated whenever
139− * corresponding registers are modified.
140− */
141−struct omap2_mcspi_regs {
142− u32 modulctrl;
143− u32 wakeupenable;
144− struct list_head cs;
145−};
146−
147−static struct omap2_mcspi_regs omap2_mcspi_ctx[OMAP2_MCSPI_MAX_CTRL];
148−
149142 #define MOD_REG_BIT(val, mask, set) do { \
150143 if (set) \
151144 val |= mask; \
@@ -236,9 +229,12 @@ static void omap2_mcspi_force_cs(struct spi_device *spi, int cs_active) · 84 unmodified lines
236229
237230 static void omap2_mcspi_set_master_mode(struct spi_master *master)
238231 {
232+ struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
233+ struct omap2_mcspi_regs *ctx = &mcspi->ctx;
239234 u32 l;
240235
241− /* setup when switching from (reset default) slave mode
236+ /*
237+ * Setup when switching from (reset default) slave mode
242238 * to single-channel master mode
243239 */
244240 l = mcspi_read_reg(master, OMAP2_MCSPI_MODULCTRL);
@@ -247,29 +243,26 @@ static void omap2_mcspi_set_master_mode(struct spi_master *master) · 2 unmodified lines
247243 MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_SINGLE, 1);
248244 mcspi_write_reg(master, OMAP2_MCSPI_MODULCTRL, l);
249245
250− omap2_mcspi_ctx[master->bus_num - 1].modulctrl = l;
246+ ctx->modulctrl = l;
251247 }
252248
253249 static void omap2_mcspi_restore_ctx(struct omap2_mcspi *mcspi)
254250 {
255− struct spi_master *spi_cntrl;
256− struct omap2_mcspi_cs *cs;
257− spi_cntrl = mcspi->master;
251+ struct spi_master *spi_cntrl = mcspi->master;
252+ struct omap2_mcspi_regs *ctx = &mcspi->ctx;
253+ struct omap2_mcspi_cs *cs;
258254
259255 /* McSPI: context restore */
260− mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_MODULCTRL,
261− omap2_mcspi_ctx[spi_cntrl->bus_num - 1].modulctrl);
262−
263− mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_WAKEUPENABLE,
264− omap2_mcspi_ctx[spi_cntrl->bus_num - 1].wakeupenable);
256+ mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_MODULCTRL, ctx->modulctrl);
257+ mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_WAKEUPENABLE, ctx->wakeupenable);
265258
266− list_for_each_entry(cs, &omap2_mcspi_ctx[spi_cntrl->bus_num - 1].cs,
267− node)
259+ list_for_each_entry(cs, &ctx->cs, node)
268260 __raw_writel(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0);
269261 }
270262 static void omap2_mcspi_disable_clocks(struct omap2_mcspi *mcspi)
271263 {
272− pm_runtime_put_sync(mcspi->dev);
264+ pm_runtime_mark_last_busy(mcspi->dev);
265+ pm_runtime_put_autosuspend(mcspi->dev);
273266 }
274267
275268 static int omap2_mcspi_enable_clocks(struct omap2_mcspi *mcspi)
@@ -277,6 +270,23 @@ static int omap2_mcspi_enable_clocks(struct omap2_mcspi *mcspi) · 1 unmodified line
277270 return pm_runtime_get_sync(mcspi->dev);
278271 }
279272
273+static int omap2_prepare_transfer(struct spi_master *master)
274+{
275+ struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
276+
277+ pm_runtime_get_sync(mcspi->dev);
278+ return 0;
279+}
280+
281+static int omap2_unprepare_transfer(struct spi_master *master)
282+{
283+ struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
284+
285+ pm_runtime_mark_last_busy(mcspi->dev);
286+ pm_runtime_put_autosuspend(mcspi->dev);
287+ return 0;
288+}
289+
280290 static int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit)
281291 {
282292 unsigned long timeout;
@@ -777,7 +787,8 @@ static int omap2_mcspi_request_dma(struct spi_device *spi) · 494 unmodified lines
777787 static int omap2_mcspi_setup(struct spi_device *spi)
778788 {
779789 int ret;
780− struct omap2_mcspi *mcspi;
790+ struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master);
791+ struct omap2_mcspi_regs *ctx = &mcspi->ctx;
781792 struct omap2_mcspi_dma *mcspi_dma;
782793 struct omap2_mcspi_cs *cs = spi->controller_state;
783794
@@ -787,11 +798,10 @@ static int omap2_mcspi_setup(struct spi_device *spi) · 3 unmodified lines
787798 return -EINVAL;
788799 }
789800
790− mcspi = spi_master_get_devdata(spi->master);
791801 mcspi_dma = &mcspi->dma_channels[spi->chip_select];
792802
793803 if (!cs) {
794− cs = kzalloc(sizeof *cs, GFP_KERNEL);
804+ cs = devm_kzalloc(&spi->dev , sizeof *cs, GFP_KERNEL);
795805 if (!cs)
796806 return -ENOMEM;
797807 cs->base = mcspi->base + spi->chip_select * 0x14;
@@ -799,8 +809,7 @@ static int omap2_mcspi_setup(struct spi_device *spi) · 1 unmodified line
799809 cs->chconf0 = 0;
800810 spi->controller_state = cs;
801811 /* Link this to context save list */
802− list_add_tail(&cs->node,
803− &omap2_mcspi_ctx[mcspi->master->bus_num - 1].cs);
812+ list_add_tail(&cs->node, &ctx->cs);
804813 }
805814
806815 if (mcspi_dma->dma_rx_channel == -1
@@ -833,7 +842,6 @@ static void omap2_mcspi_cleanup(struct spi_device *spi) · 26 unmodified lines
833842 cs = spi->controller_state;
834843 list_del(&cs->node);
835844
836− kfree(spi->controller_state);
837845 }
838846
839847 if (spi->chip_select < spi->master->num_chipselect) {
@@ -850,144 +858,122 @@ static void omap2_mcspi_cleanup(struct spi_device *spi) · 10 unmodified lines
850858 }
851859 }
852860
853−static void omap2_mcspi_work(struct work_struct *work)
861+static void omap2_mcspi_work(struct omap2_mcspi *mcspi, struct spi_message *m)
854862 {
855− struct omap2_mcspi *mcspi;
856−
857− mcspi = container_of(work, struct omap2_mcspi, work);
858−
859− if (omap2_mcspi_enable_clocks(mcspi) < 0)
860− return;
861−
862− spin_lock_irq(&mcspi->lock);
863863
864864 /* We only enable one channel at a time -- the one whose message is
865− * at the head of the queue -- although this controller would gladly
865+ * -- although this controller would gladly
866866 * arbitrate among multiple channels. This corresponds to "single
867867 * channel" master mode. As a side effect, we need to manage the
868868 * chipselect with the FORCE bit ... CS != channel enable.
869869 */
870− while (!list_empty(&mcspi->msg_queue)) {
871− struct spi_message *m;
872− struct spi_device *spi;
873− struct spi_transfer *t = NULL;
874− int cs_active = 0;
875− struct omap2_mcspi_cs *cs;
876− struct omap2_mcspi_device_config *cd;
877− int par_override = 0;
878− int status = 0;
879− u32 chconf;
880−
881− m = container_of(mcspi->msg_queue.next, struct spi_message,
882− queue);
883−
884− list_del_init(&m->queue);
885− spin_unlock_irq(&mcspi->lock);
886−
887− spi = m->spi;
888− cs = spi->controller_state;
889− cd = spi->controller_data;
890870
891− omap2_mcspi_set_enable(spi, 1);
892− list_for_each_entry(t, &m->transfers, transfer_list) {
893− if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) {
894− status = -EINVAL;
895− break;
896− }
897− if (par_override || t->speed_hz || t->bits_per_word) {
898− par_override = 1;
899− status = omap2_mcspi_setup_transfer(spi, t);
900− if (status < 0)
901− break;
902− if (!t->speed_hz && !t->bits_per_word)
903− par_override = 0;
904− }
871+ struct spi_device *spi;
872+ struct spi_transfer *t = NULL;
873+ int cs_active = 0;
874+ struct omap2_mcspi_cs *cs;
875+ struct omap2_mcspi_device_config *cd;
876+ int par_override = 0;
877+ int status = 0;
878+ u32 chconf;
905879
906− if (!cs_active) {
907− omap2_mcspi_force_cs(spi, 1);
908− cs_active = 1;
909− }
880+ spi = m->spi;
881+ cs = spi->controller_state;
882+ cd = spi->controller_data;
910883
911− chconf = mcspi_cached_chconf0(spi);
912− chconf &= ~OMAP2_MCSPI_CHCONF_TRM_MASK;
913− chconf &= ~OMAP2_MCSPI_CHCONF_TURBO;
884+ omap2_mcspi_set_enable(spi, 1);
885+ list_for_each_entry(t, &m->transfers, transfer_list) {
886+ if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) {
887+ status = -EINVAL;
888+ break;
889+ }
890+ if (par_override || t->speed_hz || t->bits_per_word) {
891+ par_override = 1;
892+ status = omap2_mcspi_setup_transfer(spi, t);
893+ if (status < 0)
894+ break;
895+ if (!t->speed_hz && !t->bits_per_word)
896+ par_override = 0;
897+ }
914898
915− if (t->tx_buf == NULL)
916− chconf |= OMAP2_MCSPI_CHCONF_TRM_RX_ONLY;
917− else if (t->rx_buf == NULL)
918− chconf |= OMAP2_MCSPI_CHCONF_TRM_TX_ONLY;
919−
920− if (cd && cd->turbo_mode && t->tx_buf == NULL) {
921− /* Turbo mode is for more than one word */
922− if (t->len > ((cs->word_len + 7) >> 3))
923− chconf |= OMAP2_MCSPI_CHCONF_TURBO;
924− }
899+ if (!cs_active) {
900+ omap2_mcspi_force_cs(spi, 1);
901+ cs_active = 1;
902+ }
925903
926− mcspi_write_chconf0(spi, chconf);
904+ chconf = mcspi_cached_chconf0(spi);
905+ chconf &= ~OMAP2_MCSPI_CHCONF_TRM_MASK;
906+ chconf &= ~OMAP2_MCSPI_CHCONF_TURBO;
927907
928− if (t->len) {
929− unsigned count;
908+ if (t->tx_buf == NULL)
909+ chconf |= OMAP2_MCSPI_CHCONF_TRM_RX_ONLY;
910+ else if (t->rx_buf == NULL)
911+ chconf |= OMAP2_MCSPI_CHCONF_TRM_TX_ONLY;
930912
931− /* RX_ONLY mode needs dummy data in TX reg */
932− if (t->tx_buf == NULL)
933− __raw_writel(0, cs->base
934− + OMAP2_MCSPI_TX0);
913+ if (cd && cd->turbo_mode && t->tx_buf == NULL) {
914+ /* Turbo mode is for more than one word */
915+ if (t->len > ((cs->word_len + 7) >> 3))
916+ chconf |= OMAP2_MCSPI_CHCONF_TURBO;
917+ }
935918
936− if (m->is_dma_mapped || t->len >= DMA_MIN_BYTES)
937− count = omap2_mcspi_txrx_dma(spi, t);
938− else
939− count = omap2_mcspi_txrx_pio(spi, t);
940− m->actual_length += count;
919+ mcspi_write_chconf0(spi, chconf);
941920
942− if (count != t->len) {
943− status = -EIO;
944− break;
945− }
946− }
921+ if (t->len) {
922+ unsigned count;
947923
948− if (t->delay_usecs)
949− udelay(t->delay_usecs);
924+ /* RX_ONLY mode needs dummy data in TX reg */
925+ if (t->tx_buf == NULL)
926+ __raw_writel(0, cs->base
927+ + OMAP2_MCSPI_TX0);
928+
929+ if (m->is_dma_mapped || t->len >= DMA_MIN_BYTES)
930+ count = omap2_mcspi_txrx_dma(spi, t);
931+ else
932+ count = omap2_mcspi_txrx_pio(spi, t);
933+ m->actual_length += count;
950934
951− /* ignore the "leave it on after last xfer" hint */
952− if (t->cs_change) {
953− omap2_mcspi_force_cs(spi, 0);
954− cs_active = 0;
935+ if (count != t->len) {
936+ status = -EIO;
937+ break;
955938 }
956939 }
957940
958− /* Restore defaults if they were overriden */
959− if (par_override) {
960− par_override = 0;
961− status = omap2_mcspi_setup_transfer(spi, NULL);
962− }
941+ if (t->delay_usecs)
942+ udelay(t->delay_usecs);
963943
964− if (cs_active)
944+ /* ignore the "leave it on after last xfer" hint */
945+ if (t->cs_change) {
965946 omap2_mcspi_force_cs(spi, 0);
947+ cs_active = 0;
948+ }
949+ }
950+ /* Restore defaults if they were overriden */
951+ if (par_override) {
952+ par_override = 0;
953+ status = omap2_mcspi_setup_transfer(spi, NULL);
954+ }
966955
967− omap2_mcspi_set_enable(spi, 0);
968−
969− m->status = status;
970− m->complete(m->context);
956+ if (cs_active)
957+ omap2_mcspi_force_cs(spi, 0);
971958
972− spin_lock_irq(&mcspi->lock);
973− }
959+ omap2_mcspi_set_enable(spi, 0);
974960
975− spin_unlock_irq(&mcspi->lock);
961+ m->status = status;
976962
977− omap2_mcspi_disable_clocks(mcspi);
978963 }
979964
980−static int omap2_mcspi_transfer(struct spi_device *spi, struct spi_message *m)
965+static int omap2_mcspi_transfer_one_message(struct spi_master *master,
966+ struct spi_message *m)
981967 {
982968 struct omap2_mcspi *mcspi;
983− unsigned long flags;
984969 struct spi_transfer *t;
985970
971+ mcspi = spi_master_get_devdata(master);
986972 m->actual_length = 0;
987973 m->status = 0;
988974
989975 /* reject invalid messages and transfers */
990− if (list_empty(&m->transfers) || !m->complete)
976+ if (list_empty(&m->transfers))
991977 return -EINVAL;
992978 list_for_each_entry(t, &m->transfers, transfer_list) {
993979 const void *tx_buf = t->tx_buf;
@@ -999,7 +985,7 @@ static int omap2_mcspi_transfer(struct spi_device *spi, struct spi_message *m) · 5 unmodified lines
999985 || (t->bits_per_word &&
1000986 ( t->bits_per_word < 4
1001987 || t->bits_per_word > 32))) {
1002− dev_dbg(&spi->dev, "transfer: %d Hz, %d %s%s, %d bpw\n",
988+ dev_dbg(mcspi->dev, "transfer: %d Hz, %d %s%s, %d bpw\n",
1003989 t->speed_hz,
1004990 len,
1005991 tx_buf ? "tx" : "",
@@ -1008,7 +994,7 @@ static int omap2_mcspi_transfer(struct spi_device *spi, struct spi_message *m) · 2 unmodified lines
1008994 return -EINVAL;
1009995 }
1010996 if (t->speed_hz && t->speed_hz < (OMAP2_MCSPI_MAX_FREQ >> 15)) {
1011− dev_dbg(&spi->dev, "speed_hz %d below minimum %d Hz\n",
997+ dev_dbg(mcspi->dev, "speed_hz %d below minimum %d Hz\n",
1012998 t->speed_hz,
1013999 OMAP2_MCSPI_MAX_FREQ >> 15);
10141000 return -EINVAL;
@@ -1018,51 +1004,46 @@ static int omap2_mcspi_transfer(struct spi_device *spi, struct spi_message *m) · 3 unmodified lines
10181004 continue;
10191005
10201006 if (tx_buf != NULL) {
1021− t->tx_dma = dma_map_single(&spi->dev, (void *) tx_buf,
1007+ t->tx_dma = dma_map_single(mcspi->dev, (void *) tx_buf,
10221008 len, DMA_TO_DEVICE);
1023− if (dma_mapping_error(&spi->dev, t->tx_dma)) {
1024− dev_dbg(&spi->dev, "dma %cX %d bytes error\n",
1009+ if (dma_mapping_error(mcspi->dev, t->tx_dma)) {
1010+ dev_dbg(mcspi->dev, "dma %cX %d bytes error\n",
10251011 'T', len);
10261012 return -EINVAL;
10271013 }
10281014 }
10291015 if (rx_buf != NULL) {
1030− t->rx_dma = dma_map_single(&spi->dev, rx_buf, t->len,
1016+ t->rx_dma = dma_map_single(mcspi->dev, rx_buf, t->len,
10311017 DMA_FROM_DEVICE);
1032− if (dma_mapping_error(&spi->dev, t->rx_dma)) {
1033− dev_dbg(&spi->dev, "dma %cX %d bytes error\n",
1018+ if (dma_mapping_error(mcspi->dev, t->rx_dma)) {
1019+ dev_dbg(mcspi->dev, "dma %cX %d bytes error\n",
10341020 'R', len);
10351021 if (tx_buf != NULL)
1036− dma_unmap_single(&spi->dev, t->tx_dma,
1022+ dma_unmap_single(mcspi->dev, t->tx_dma,
10371023 len, DMA_TO_DEVICE);
10381024 return -EINVAL;
10391025 }
10401026 }
10411027 }
10421028
1043− mcspi = spi_master_get_devdata(spi->master);
1044−
1045− spin_lock_irqsave(&mcspi->lock, flags);
1046− list_add_tail(&m->queue, &mcspi->msg_queue);
1047− queue_work(mcspi->wq, &mcspi->work);
1048− spin_unlock_irqrestore(&mcspi->lock, flags);
1049−
1029+ omap2_mcspi_work(mcspi, m);
1030+ spi_finalize_current_message(master);
10501031 return 0;
10511032 }
10521033
10531034 static int __init omap2_mcspi_master_setup(struct omap2_mcspi *mcspi)
10541035 {
10551036 struct spi_master *master = mcspi->master;
1056− u32 tmp;
1057− int ret = 0;
1037+ struct omap2_mcspi_regs *ctx = &mcspi->ctx;
1038+ int ret = 0;
10581039
10591040 ret = omap2_mcspi_enable_clocks(mcspi);
10601041 if (ret < 0)
10611042 return ret;
10621043
1063− tmp = OMAP2_MCSPI_WAKEUPENABLE_WKEN;
1064− mcspi_write_reg(master, OMAP2_MCSPI_WAKEUPENABLE, tmp);
1065− omap2_mcspi_ctx[master->bus_num - 1].wakeupenable = tmp;
1044+ mcspi_write_reg(master, OMAP2_MCSPI_WAKEUPENABLE,
1045+ OMAP2_MCSPI_WAKEUPENABLE_WKEN);
1046+ ctx->wakeupenable = OMAP2_MCSPI_WAKEUPENABLE_WKEN;
10661047
10671048 omap2_mcspi_set_master_mode(master);
10681049 omap2_mcspi_disable_clocks(mcspi);
@@ -1102,14 +1083,13 @@ static const struct of_device_id omap_mcspi_of_match[] = { · 33 unmodified lines
11021083 };
11031084 MODULE_DEVICE_TABLE(of, omap_mcspi_of_match);
11041085
1105−static int __init omap2_mcspi_probe(struct platform_device *pdev)
1086+static int __devinit omap2_mcspi_probe(struct platform_device *pdev)
11061087 {
11071088 struct spi_master *master;
11081089 struct omap2_mcspi_platform_config *pdata;
11091090 struct omap2_mcspi *mcspi;
11101091 struct resource *r;
11111092 int status = 0, i;
1112− char wq_name[20];
11131093 u32 regs_offset = 0;
11141094 static int bus_num = 1;
11151095 struct device_node *node = pdev->dev.of_node;
@@ -1125,7 +1105,9 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev) · 9 unmodified lines
11251105 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
11261106
11271107 master->setup = omap2_mcspi_setup;
1128− master->transfer = omap2_mcspi_transfer;
1108+ master->prepare_transfer_hardware = omap2_prepare_transfer;
1109+ master->unprepare_transfer_hardware = omap2_unprepare_transfer;
1110+ master->transfer_one_message = omap2_mcspi_transfer_one_message;
11291111 master->cleanup = omap2_mcspi_cleanup;
11301112 master->dev.of_node = node;
11311113
@@ -1150,13 +1132,6 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev) · 18 unmodified lines
11501132 mcspi = spi_master_get_devdata(master);
11511133 mcspi->master = master;
11521134
1153− sprintf(wq_name, "omap2_mcspi/%d", master->bus_num);
1154− mcspi->wq = alloc_workqueue(wq_name, WQ_MEM_RECLAIM, 1);
1155− if (mcspi->wq == NULL) {
1156− status = -ENOMEM;
1157− goto free_master;
1158− }
1159−
11601135 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
11611136 if (r == NULL) {
11621137 status = -ENODEV;
@@ -1166,32 +1141,24 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev) · 3 unmodified lines
11661141 r->start += regs_offset;
11671142 r->end += regs_offset;
11681143 mcspi->phys = r->start;
1169− if (!request_mem_region(r->start, resource_size(r),
1170− dev_name(&pdev->dev))) {
1171− status = -EBUSY;
1172− goto free_master;
1173− }
11741144
1175− mcspi->base = ioremap(r->start, resource_size(r));
1145+ mcspi->base = devm_request_and_ioremap(&pdev->dev, r);
11761146 if (!mcspi->base) {
11771147 dev_dbg(&pdev->dev, "can't ioremap MCSPI\n");
11781148 status = -ENOMEM;
1179− goto release_region;
1149+ goto free_master;
11801150 }
11811151
11821152 mcspi->dev = &pdev->dev;
1183− INIT_WORK(&mcspi->work, omap2_mcspi_work);
11841153
1185− spin_lock_init(&mcspi->lock);
1186− INIT_LIST_HEAD(&mcspi->msg_queue);
1187− INIT_LIST_HEAD(&omap2_mcspi_ctx[master->bus_num - 1].cs);
1154+ INIT_LIST_HEAD(&mcspi->ctx.cs);
11881155
11891156 mcspi->dma_channels = kcalloc(master->num_chipselect,
11901157 sizeof(struct omap2_mcspi_dma),
11911158 GFP_KERNEL);
11921159
11931160 if (mcspi->dma_channels == NULL)
1194− goto unmap_io;
1161+ goto free_master;
11951162
11961163 for (i = 0; i < master->num_chipselect; i++) {
11971164 char dma_ch_name[14];
@@ -1224,6 +1191,8 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev) · 26 unmodified lines
12241191 if (status < 0)
12251192 goto dma_chnl_free;
12261193
1194+ pm_runtime_use_autosuspend(&pdev->dev);
1195+ pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
12271196 pm_runtime_enable(&pdev->dev);
12281197
12291198 if (status || omap2_mcspi_master_setup(mcspi) < 0)
@@ -1241,23 +1210,17 @@ disable_pm: · 11 unmodified lines
12411210 pm_runtime_disable(&pdev->dev);
12421211 dma_chnl_free:
12431212 kfree(mcspi->dma_channels);
1244−unmap_io:
1245− iounmap(mcspi->base);
1246−release_region:
1247− release_mem_region(r->start, resource_size(r));
12481213 free_master:
12491214 kfree(master);
12501215 platform_set_drvdata(pdev, NULL);
12511216 return status;
12521217 }
12531218
1254−static int __exit omap2_mcspi_remove(struct platform_device *pdev)
1219+static int __devexit omap2_mcspi_remove(struct platform_device *pdev)
12551220 {
12561221 struct spi_master *master;
12571222 struct omap2_mcspi *mcspi;
12581223 struct omap2_mcspi_dma *dma_channels;
1259− struct resource *r;
1260− void __iomem *base;
12611224
12621225 master = dev_get_drvdata(&pdev->dev);
12631226 mcspi = spi_master_get_devdata(master);
@@ -1265,14 +1228,9 @@ static int __exit omap2_mcspi_remove(struct platform_device *pdev) · 1 unmodified line
12651228
12661229 omap2_mcspi_disable_clocks(mcspi);
12671230 pm_runtime_disable(&pdev->dev);
1268− r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1269− release_mem_region(r->start, resource_size(r));
12701231
1271− base = mcspi->base;
12721232 spi_unregister_master(master);
1273− iounmap(base);
12741233 kfree(dma_channels);
1275− destroy_workqueue(mcspi->wq);
12761234 platform_set_drvdata(pdev, NULL);
12771235
12781236 return 0;
@@ -1291,13 +1249,12 @@ static int omap2_mcspi_resume(struct device *dev) · 12 unmodified lines
12911249 {
12921250 struct spi_master *master = dev_get_drvdata(dev);
12931251 struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
1294− struct omap2_mcspi_cs *cs;
1252+ struct omap2_mcspi_regs *ctx = &mcspi->ctx;
1253+ struct omap2_mcspi_cs *cs;
12951254
12961255 omap2_mcspi_enable_clocks(mcspi);
1297− list_for_each_entry(cs, &omap2_mcspi_ctx[master->bus_num - 1].cs,
1298− node) {
1256+ list_for_each_entry(cs, &ctx->cs, node) {
12991257 if ((cs->chconf0 & OMAP2_MCSPI_CHCONF_FORCE) == 0) {
1300−
13011258 /*
13021259 * We need to toggle CS state for OMAP take this
13031260 * change in account.
@@ -1327,21 +1284,9 @@ static struct platform_driver omap2_mcspi_driver = { · 23 unmodified lines
13271284 .pm = &omap2_mcspi_pm_ops,
13281285 .of_match_table = omap_mcspi_of_match,
13291286 },
1330− .remove = __exit_p(omap2_mcspi_remove),
1287+ .probe = omap2_mcspi_probe,
1288+ .remove = __devexit_p(omap2_mcspi_remove),
13311289 };
13321290
1333−
1334−static int __init omap2_mcspi_init(void)
1335−{
1336− return platform_driver_probe(&omap2_mcspi_driver, omap2_mcspi_probe);
1337−}
1338−subsys_initcall(omap2_mcspi_init);
1339−
1340−static void __exit omap2_mcspi_exit(void)
1341−{
1342− platform_driver_unregister(&omap2_mcspi_driver);
1343−
1344−}
1345−module_exit(omap2_mcspi_exit);
1346−
1291+module_platform_driver(omap2_mcspi_driver);
13471292 MODULE_LICENSE("GPL");
drivers/spi/spi-ppc4xx.c+0−4
@@ -30,7 +30,6 @@ · 29 unmodified lines
3030 #include <linux/errno.h>
3131 #include <linux/wait.h>
3232 #include <linux/of_platform.h>
33−#include <linux/of_spi.h>
3433 #include <linux/of_gpio.h>
3534 #include <linux/interrupt.h>
3635 #include <linux/delay.h>
@@ -467,9 +466,6 @@ static int __init spi_ppc4xx_of_probe(struct platform_device *op) · 430 unmodified lines
467466 bbp->master->setup = spi_ppc4xx_setup;
468467 bbp->master->cleanup = spi_ppc4xx_cleanup;
469468
470− /* Allocate bus num dynamically. */
471− bbp->master->bus_num = -1;
472−
473469 /* the spi->mode bits understood by this driver: */
474470 bbp->master->mode_bits =
475471 SPI_CPHA | SPI_CPOL | SPI_CS_HIGH | SPI_LSB_FIRST;
drivers/spi/spi-pxa2xx-pci.c+1−11
@@ -164,17 +164,7 @@ static struct pci_driver ce4100_spi_driver = { · 163 unmodified lines
164164 .remove = __devexit_p(ce4100_spi_remove),
165165 };
166166
167−static int __init ce4100_spi_init(void)
168−{
169− return pci_register_driver(&ce4100_spi_driver);
170−}
171−module_init(ce4100_spi_init);
172−
173−static void __exit ce4100_spi_exit(void)
174−{
175− pci_unregister_driver(&ce4100_spi_driver);
176−}
177−module_exit(ce4100_spi_exit);
167+module_pci_driver(ce4100_spi_driver);
178168
179169 MODULE_DESCRIPTION("CE4100 PCI-SPI glue code for PXA's driver");
180170 MODULE_LICENSE("GPL v2");
drivers/spi/spi-rspi.c+314−6
@@ -31,7 +31,11 @@ · 30 unmodified lines
3131 #include <linux/platform_device.h>
3232 #include <linux/io.h>
3333 #include <linux/clk.h>
34+#include <linux/dmaengine.h>
35+#include <linux/dma-mapping.h>
36+#include <linux/sh_dma.h>
3437 #include <linux/spi/spi.h>
38+#include <linux/spi/rspi.h>
3539
3640 #define RSPI_SPCR 0x00
3741 #define RSPI_SSLP 0x01
@@ -141,6 +145,16 @@ struct rspi_data { · 103 unmodified lines
141145 spinlock_t lock;
142146 struct clk *clk;
143147 unsigned char spsr;
148+
149+ /* for dmaengine */
150+ struct sh_dmae_slave dma_tx;
151+ struct sh_dmae_slave dma_rx;
152+ struct dma_chan *chan_tx;
153+ struct dma_chan *chan_rx;
154+ int irq;
155+
156+ unsigned dma_width_16bit:1;
157+ unsigned dma_callbacked:1;
144158 };
145159
146160 static void rspi_write8(struct rspi_data *rspi, u8 data, u16 offset)
@@ -265,11 +279,125 @@ static int rspi_send_pio(struct rspi_data *rspi, struct spi_message *mesg, · 118 unmodified lines
265279 return 0;
266280 }
267281
268−static int rspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg,
269− struct spi_transfer *t)
282+static void rspi_dma_complete(void *arg)
283+{
284+ struct rspi_data *rspi = arg;
285+
286+ rspi->dma_callbacked = 1;
287+ wake_up_interruptible(&rspi->wait);
288+}
289+
290+static int rspi_dma_map_sg(struct scatterlist *sg, void *buf, unsigned len,
291+ struct dma_chan *chan,
292+ enum dma_transfer_direction dir)
293+{
294+ sg_init_table(sg, 1);
295+ sg_set_buf(sg, buf, len);
296+ sg_dma_len(sg) = len;
297+ return dma_map_sg(chan->device->dev, sg, 1, dir);
298+}
299+
300+static void rspi_dma_unmap_sg(struct scatterlist *sg, struct dma_chan *chan,
301+ enum dma_transfer_direction dir)
302+{
303+ dma_unmap_sg(chan->device->dev, sg, 1, dir);
304+}
305+
306+static void rspi_memory_to_8bit(void *buf, const void *data, unsigned len)
307+{
308+ u16 *dst = buf;
309+ const u8 *src = data;
310+
311+ while (len) {
312+ *dst++ = (u16)(*src++);
313+ len--;
314+ }
315+}
316+
317+static void rspi_memory_from_8bit(void *buf, const void *data, unsigned len)
318+{
319+ u8 *dst = buf;
320+ const u16 *src = data;
321+
322+ while (len) {
323+ *dst++ = (u8)*src++;
324+ len--;
325+ }
326+}
327+
328+static int rspi_send_dma(struct rspi_data *rspi, struct spi_transfer *t)
329+{
330+ struct scatterlist sg;
331+ void *buf = NULL;
332+ struct dma_async_tx_descriptor *desc;
333+ unsigned len;
334+ int ret = 0;
335+
336+ if (rspi->dma_width_16bit) {
337+ /*
338+ * If DMAC bus width is 16-bit, the driver allocates a dummy
339+ * buffer. And, the driver converts original data into the
340+ * DMAC data as the following format:
341+ * original data: 1st byte, 2nd byte ...
342+ * DMAC data: 1st byte, dummy, 2nd byte, dummy ...
343+ */
344+ len = t->len * 2;
345+ buf = kmalloc(len, GFP_KERNEL);
346+ if (!buf)
347+ return -ENOMEM;
348+ rspi_memory_to_8bit(buf, t->tx_buf, t->len);
349+ } else {
350+ len = t->len;
351+ buf = (void *)t->tx_buf;
352+ }
353+
354+ if (!rspi_dma_map_sg(&sg, buf, len, rspi->chan_tx, DMA_TO_DEVICE)) {
355+ ret = -EFAULT;
356+ goto end_nomap;
357+ }
358+ desc = dmaengine_prep_slave_sg(rspi->chan_tx, &sg, 1, DMA_TO_DEVICE,
359+ DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
360+ if (!desc) {
361+ ret = -EIO;
362+ goto end;
363+ }
364+
365+ /*
366+ * DMAC needs SPTIE, but if SPTIE is set, this IRQ routine will be
367+ * called. So, this driver disables the IRQ while DMA transfer.
368+ */
369+ disable_irq(rspi->irq);
370+
371+ rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | SPCR_TXMD, RSPI_SPCR);
372+ rspi_enable_irq(rspi, SPCR_SPTIE);
373+ rspi->dma_callbacked = 0;
374+
375+ desc->callback = rspi_dma_complete;
376+ desc->callback_param = rspi;
377+ dmaengine_submit(desc);
378+ dma_async_issue_pending(rspi->chan_tx);
379+
380+ ret = wait_event_interruptible_timeout(rspi->wait,
381+ rspi->dma_callbacked, HZ);
382+ if (ret > 0 && rspi->dma_callbacked)
383+ ret = 0;
384+ else if (!ret)
385+ ret = -ETIMEDOUT;
386+ rspi_disable_irq(rspi, SPCR_SPTIE);
387+
388+ enable_irq(rspi->irq);
389+
390+end:
391+ rspi_dma_unmap_sg(&sg, rspi->chan_tx, DMA_TO_DEVICE);
392+end_nomap:
393+ if (rspi->dma_width_16bit)
394+ kfree(buf);
395+
396+ return ret;
397+}
398+
399+static void rspi_receive_init(struct rspi_data *rspi)
270400 {
271− int remain = t->len;
272− u8 *data;
273401 unsigned char spsr;
274402
275403 spsr = rspi_read8(rspi, RSPI_SPSR);
@@ -278,6 +406,15 @@ static int rspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg, · 2 unmodified lines
278406 if (spsr & SPSR_OVRF)
279407 rspi_write8(rspi, rspi_read8(rspi, RSPI_SPSR) & ~SPSR_OVRF,
280408 RSPI_SPCR);
409+}
410+
411+static int rspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg,
412+ struct spi_transfer *t)
413+{
414+ int remain = t->len;
415+ u8 *data;
416+
417+ rspi_receive_init(rspi);
281418
282419 data = (u8 *)t->rx_buf;
283420 while (remain > 0) {
@@ -307,6 +444,120 @@ static int rspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg, · 23 unmodified lines
307444 return 0;
308445 }
309446
447+static int rspi_receive_dma(struct rspi_data *rspi, struct spi_transfer *t)
448+{
449+ struct scatterlist sg, sg_dummy;
450+ void *dummy = NULL, *rx_buf = NULL;
451+ struct dma_async_tx_descriptor *desc, *desc_dummy;
452+ unsigned len;
453+ int ret = 0;
454+
455+ if (rspi->dma_width_16bit) {
456+ /*
457+ * If DMAC bus width is 16-bit, the driver allocates a dummy
458+ * buffer. And, finally the driver converts the DMAC data into
459+ * actual data as the following format:
460+ * DMAC data: 1st byte, dummy, 2nd byte, dummy ...
461+ * actual data: 1st byte, 2nd byte ...
462+ */
463+ len = t->len * 2;
464+ rx_buf = kmalloc(len, GFP_KERNEL);
465+ if (!rx_buf)
466+ return -ENOMEM;
467+ } else {
468+ len = t->len;
469+ rx_buf = t->rx_buf;
470+ }
471+
472+ /* prepare dummy transfer to generate SPI clocks */
473+ dummy = kzalloc(len, GFP_KERNEL);
474+ if (!dummy) {
475+ ret = -ENOMEM;
476+ goto end_nomap;
477+ }
478+ if (!rspi_dma_map_sg(&sg_dummy, dummy, len, rspi->chan_tx,
479+ DMA_TO_DEVICE)) {
480+ ret = -EFAULT;
481+ goto end_nomap;
482+ }
483+ desc_dummy = dmaengine_prep_slave_sg(rspi->chan_tx, &sg_dummy, 1,
484+ DMA_TO_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
485+ if (!desc_dummy) {
486+ ret = -EIO;
487+ goto end_dummy_mapped;
488+ }
489+
490+ /* prepare receive transfer */
491+ if (!rspi_dma_map_sg(&sg, rx_buf, len, rspi->chan_rx,
492+ DMA_FROM_DEVICE)) {
493+ ret = -EFAULT;
494+ goto end_dummy_mapped;
495+
496+ }
497+ desc = dmaengine_prep_slave_sg(rspi->chan_rx, &sg, 1, DMA_FROM_DEVICE,
498+ DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
499+ if (!desc) {
500+ ret = -EIO;
501+ goto end;
502+ }
503+
504+ rspi_receive_init(rspi);
505+
506+ /*
507+ * DMAC needs SPTIE, but if SPTIE is set, this IRQ routine will be
508+ * called. So, this driver disables the IRQ while DMA transfer.
509+ */
510+ disable_irq(rspi->irq);
511+
512+ rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~SPCR_TXMD, RSPI_SPCR);
513+ rspi_enable_irq(rspi, SPCR_SPTIE | SPCR_SPRIE);
514+ rspi->dma_callbacked = 0;
515+
516+ desc->callback = rspi_dma_complete;
517+ desc->callback_param = rspi;
518+ dmaengine_submit(desc);
519+ dma_async_issue_pending(rspi->chan_rx);
520+
521+ desc_dummy->callback = NULL; /* No callback */
522+ dmaengine_submit(desc_dummy);
523+ dma_async_issue_pending(rspi->chan_tx);
524+
525+ ret = wait_event_interruptible_timeout(rspi->wait,
526+ rspi->dma_callbacked, HZ);
527+ if (ret > 0 && rspi->dma_callbacked)
528+ ret = 0;
529+ else if (!ret)
530+ ret = -ETIMEDOUT;
531+ rspi_disable_irq(rspi, SPCR_SPTIE | SPCR_SPRIE);
532+
533+ enable_irq(rspi->irq);
534+
535+end:
536+ rspi_dma_unmap_sg(&sg, rspi->chan_rx, DMA_FROM_DEVICE);
537+end_dummy_mapped:
538+ rspi_dma_unmap_sg(&sg_dummy, rspi->chan_tx, DMA_TO_DEVICE);
539+end_nomap:
540+ if (rspi->dma_width_16bit) {
541+ if (!ret)
542+ rspi_memory_from_8bit(t->rx_buf, rx_buf, t->len);
543+ kfree(rx_buf);
544+ }
545+ kfree(dummy);
546+
547+ return ret;
548+}
549+
550+static int rspi_is_dma(struct rspi_data *rspi, struct spi_transfer *t)
551+{
552+ if (t->tx_buf && rspi->chan_tx)
553+ return 1;
554+ /* If the module receives data by DMAC, it also needs TX DMAC */
555+ if (t->rx_buf && rspi->chan_tx && rspi->chan_rx)
556+ return 1;
557+
558+ return 0;
559+}
560+
310561 static void rspi_work(struct work_struct *work)
311562 {
312563 struct rspi_data *rspi = container_of(work, struct rspi_data, ws);
@@ -325,12 +576,18 @@ static void rspi_work(struct work_struct *work) · 12 unmodified lines
325576
326577 list_for_each_entry(t, &mesg->transfers, transfer_list) {
327578 if (t->tx_buf) {
328− ret = rspi_send_pio(rspi, mesg, t);
579+ if (rspi_is_dma(rspi, t))
580+ ret = rspi_send_dma(rspi, t);
581+ else
582+ ret = rspi_send_pio(rspi, mesg, t);
329583 if (ret < 0)
330584 goto error;
331585 }
332586 if (t->rx_buf) {
333− ret = rspi_receive_pio(rspi, mesg, t);
587+ if (rspi_is_dma(rspi, t))
588+ ret = rspi_receive_dma(rspi, t);
589+ else
590+ ret = rspi_receive_pio(rspi, mesg, t);
334591 if (ret < 0)
335592 goto error;
336593 }
@@ -406,11 +663,58 @@ static irqreturn_t rspi_irq(int irq, void *_sr) · 69 unmodified lines
406663 return ret;
407664 }
408665
666+static bool rspi_filter(struct dma_chan *chan, void *filter_param)
667+{
668+ chan->private = filter_param;
669+ return true;
670+}
671+
672+static void __devinit rspi_request_dma(struct rspi_data *rspi,
673+ struct platform_device *pdev)
674+{
675+ struct rspi_plat_data *rspi_pd = pdev->dev.platform_data;
676+ dma_cap_mask_t mask;
677+
678+ if (!rspi_pd)
679+ return;
680+
681+ rspi->dma_width_16bit = rspi_pd->dma_width_16bit;
682+
683+ /* If the module receives data by DMAC, it also needs TX DMAC */
684+ if (rspi_pd->dma_rx_id && rspi_pd->dma_tx_id) {
685+ dma_cap_zero(mask);
686+ dma_cap_set(DMA_SLAVE, mask);
687+ rspi->dma_rx.slave_id = rspi_pd->dma_rx_id;
688+ rspi->chan_rx = dma_request_channel(mask, rspi_filter,
689+ &rspi->dma_rx);
690+ if (rspi->chan_rx)
691+ dev_info(&pdev->dev, "Use DMA when rx.\n");
692+ }
693+ if (rspi_pd->dma_tx_id) {
694+ dma_cap_zero(mask);
695+ dma_cap_set(DMA_SLAVE, mask);
696+ rspi->dma_tx.slave_id = rspi_pd->dma_tx_id;
697+ rspi->chan_tx = dma_request_channel(mask, rspi_filter,
698+ &rspi->dma_tx);
699+ if (rspi->chan_tx)
700+ dev_info(&pdev->dev, "Use DMA when tx\n");
701+ }
702+}
703+
704+static void __devexit rspi_release_dma(struct rspi_data *rspi)
705+{
706+ if (rspi->chan_tx)
707+ dma_release_channel(rspi->chan_tx);
708+ if (rspi->chan_rx)
709+ dma_release_channel(rspi->chan_rx);
710+}
711+
409712 static int __devexit rspi_remove(struct platform_device *pdev)
410713 {
411714 struct rspi_data *rspi = dev_get_drvdata(&pdev->dev);
412715
413716 spi_unregister_master(rspi->master);
717+ rspi_release_dma(rspi);
414718 free_irq(platform_get_irq(pdev, 0), rspi);
415719 clk_put(rspi->clk);
416720 iounmap(rspi->addr);
@@ -483,6 +787,9 @@ static int __devinit rspi_probe(struct platform_device *pdev) · 66 unmodified lines
483787 goto error3;
484788 }
485789
790+ rspi->irq = irq;
791+ rspi_request_dma(rspi, pdev);
792+
486793 ret = spi_register_master(master);
487794 if (ret < 0) {
488795 dev_err(&pdev->dev, "spi_register_master error.\n");
@@ -494,6 +801,7 @@ static int __devinit rspi_probe(struct platform_device *pdev) · 5 unmodified lines
494801 return 0;
495802
496803 error4:
804+ rspi_release_dma(rspi);
497805 free_irq(irq, rspi);
498806 error3:
499807 clk_put(rspi->clk);
drivers/spi/spi-sirf.c+8−12
@@ -19,7 +19,7 @@ · 18 unmodified lines
1919 #include <linux/of_gpio.h>
2020 #include <linux/spi/spi.h>
2121 #include <linux/spi/spi_bitbang.h>
22−#include <linux/pinctrl/pinmux.h>
22+#include <linux/pinctrl/consumer.h>
2323
2424 #define DRIVER_NAME "sirfsoc_spi"
2525
@@ -127,7 +127,7 @@ struct sirfsoc_spi { · 101 unmodified lines
127127 void __iomem *base;
128128 u32 ctrl_freq; /* SPI controller clock speed */
129129 struct clk *clk;
130− struct pinmux *pmx;
130+ struct pinctrl *p;
131131
132132 /* rx & tx bufs from the spi_transfer */
133133 const void *tx;
@@ -560,17 +560,15 @@ static int __devinit spi_sirfsoc_probe(struct platform_device *pdev) · 426 unmodified lines
560560 master->bus_num = pdev->id;
561561 sspi->bitbang.master->dev.of_node = pdev->dev.of_node;
562562
563− sspi->pmx = pinmux_get(&pdev->dev, NULL);
564− ret = IS_ERR(sspi->pmx);
563+ sspi->p = pinctrl_get_select_default(&pdev->dev);
564+ ret = IS_ERR(sspi->p);
565565 if (ret)
566566 goto free_master;
567567
568− pinmux_enable(sspi->pmx);
569−
570568 sspi->clk = clk_get(&pdev->dev, NULL);
571569 if (IS_ERR(sspi->clk)) {
572570 ret = -EINVAL;
573− goto free_pmx;
571+ goto free_pin;
574572 }
575573 clk_enable(sspi->clk);
576574 sspi->ctrl_freq = clk_get_rate(sspi->clk);
@@ -598,9 +596,8 @@ static int __devinit spi_sirfsoc_probe(struct platform_device *pdev) · 21 unmodified lines
598596 free_clk:
599597 clk_disable(sspi->clk);
600598 clk_put(sspi->clk);
601−free_pmx:
602− pinmux_disable(sspi->pmx);
603− pinmux_put(sspi->pmx);
599+free_pin:
600+ pinctrl_put(sspi->p);
604601 free_master:
605602 spi_master_put(master);
606603 err_cs:
@@ -623,8 +620,7 @@ static int __devexit spi_sirfsoc_remove(struct platform_device *pdev) · 16 unmodified lines
623620 }
624621 clk_disable(sspi->clk);
625622 clk_put(sspi->clk);
626− pinmux_disable(sspi->pmx);
627− pinmux_put(sspi->pmx);
623+ pinctrl_put(sspi->p);
628624 spi_master_put(master);
629625 return 0;
630626 }
drivers/spi/spi-topcliff-pch.c+1−2
@@ -1438,7 +1438,6 @@ static int __devinit pch_spi_pd_probe(struct platform_device *plat_dev) · 1437 unmodified lines
14381438 plat_dev->id, data->io_remap_addr);
14391439
14401440 /* initialize members of SPI master */
1441− master->bus_num = -1;
14421441 master->num_chipselect = PCH_MAX_CS;
14431442 master->setup = pch_spi_setup;
14441443 master->transfer = pch_spi_transfer;
@@ -1779,7 +1778,7 @@ static struct pci_driver pch_spi_pcidev_driver = { · 334 unmodified lines
17791778 .name = "pch_spi",
17801779 .id_table = pch_spi_pcidev_id,
17811780 .probe = pch_spi_probe,
1782− .remove = pch_spi_remove,
1781+ .remove = __devexit_p(pch_spi_remove),
17831782 .suspend = pch_spi_suspend,
17841783 .resume = pch_spi_resume,
17851784 };
drivers/spi/spi.c+95−3
@@ -2,6 +2,7 @@ · 1 unmodified line
22 * SPI init/core code
33 *
44 * Copyright (C) 2005 David Brownell
5+ * Copyright (C) 2008 Secret Lab Technologies Ltd.
56 *
67 * This program is free software; you can redistribute it and/or modify
78 * it under the terms of the GNU General Public License as published by
@@ -19,15 +20,16 @@ · 11 unmodified lines
1920 */
2021
2122 #include <linux/kernel.h>
23+#include <linux/kmod.h>
2224 #include <linux/device.h>
2325 #include <linux/init.h>
2426 #include <linux/cache.h>
2527 #include <linux/mutex.h>
2628 #include <linux/of_device.h>
29+#include <linux/of_irq.h>
2730 #include <linux/slab.h>
2831 #include <linux/mod_devicetable.h>
2932 #include <linux/spi/spi.h>
30−#include <linux/of_spi.h>
3133 #include <linux/pm_runtime.h>
3234 #include <linux/export.h>
3335 #include <linux/sched.h>
@@ -530,7 +532,7 @@ static void spi_pump_messages(struct kthread_work *work) · 496 unmodified lines
530532 /* Lock queue and check for queue work */
531533 spin_lock_irqsave(&master->queue_lock, flags);
532534 if (list_empty(&master->queue) || !master->running) {
533− if (master->busy) {
535+ if (master->busy && master->unprepare_transfer_hardware) {
534536 ret = master->unprepare_transfer_hardware(master);
535537 if (ret) {
536538 spin_unlock_irqrestore(&master->queue_lock, flags);
@@ -560,7 +562,7 @@ static void spi_pump_messages(struct kthread_work *work) · 23 unmodified lines
560562 master->busy = true;
561563 spin_unlock_irqrestore(&master->queue_lock, flags);
562564
563− if (!was_busy) {
565+ if (!was_busy && master->prepare_transfer_hardware) {
564566 ret = master->prepare_transfer_hardware(master);
565567 if (ret) {
566568 dev_err(&master->dev,
@@ -798,6 +800,94 @@ err_init_queue: · 231 unmodified lines
798800
799801 /*-------------------------------------------------------------------------*/
800802
803+#if defined(CONFIG_OF) && !defined(CONFIG_SPARC)
804+/**
805+ * of_register_spi_devices() - Register child devices onto the SPI bus
806+ * @master: Pointer to spi_master device
807+ *
808+ * Registers an spi_device for each child node of master node which has a 'reg'
809+ * property.
810+ */
811+static void of_register_spi_devices(struct spi_master *master)
812+{
813+ struct spi_device *spi;
814+ struct device_node *nc;
815+ const __be32 *prop;
816+ int rc;
817+ int len;
818+
819+ if (!master->dev.of_node)
820+ return;
821+
822+ for_each_child_of_node(master->dev.of_node, nc) {
823+ /* Alloc an spi_device */
824+ spi = spi_alloc_device(master);
825+ if (!spi) {
826+ dev_err(&master->dev, "spi_device alloc error for %s\n",
827+ nc->full_name);
828+ spi_dev_put(spi);
829+ continue;
830+ }
831+
832+ /* Select device driver */
833+ if (of_modalias_node(nc, spi->modalias,
834+ sizeof(spi->modalias)) < 0) {
835+ dev_err(&master->dev, "cannot find modalias for %s\n",
836+ nc->full_name);
837+ spi_dev_put(spi);
838+ continue;
839+ }
840+
841+ /* Device address */
842+ prop = of_get_property(nc, "reg", &len);
843+ if (!prop || len < sizeof(*prop)) {
844+ dev_err(&master->dev, "%s has no 'reg' property\n",
845+ nc->full_name);
846+ spi_dev_put(spi);
847+ continue;
848+ }
849+ spi->chip_select = be32_to_cpup(prop);
850+
851+ /* Mode (clock phase/polarity/etc.) */
852+ if (of_find_property(nc, "spi-cpha", NULL))
853+ spi->mode |= SPI_CPHA;
854+ if (of_find_property(nc, "spi-cpol", NULL))
855+ spi->mode |= SPI_CPOL;
856+ if (of_find_property(nc, "spi-cs-high", NULL))
857+ spi->mode |= SPI_CS_HIGH;
858+
859+ /* Device speed */
860+ prop = of_get_property(nc, "spi-max-frequency", &len);
861+ if (!prop || len < sizeof(*prop)) {
862+ dev_err(&master->dev, "%s has no 'spi-max-frequency' property\n",
863+ nc->full_name);
864+ spi_dev_put(spi);
865+ continue;
866+ }
867+ spi->max_speed_hz = be32_to_cpup(prop);
868+
869+ /* IRQ */
870+ spi->irq = irq_of_parse_and_map(nc, 0);
871+
872+ /* Store a pointer to the node in the device structure */
873+ of_node_get(nc);
874+ spi->dev.of_node = nc;
875+
876+ /* Register the new device */
877+ request_module(spi->modalias);
878+ rc = spi_add_device(spi);
879+ if (rc) {
880+ dev_err(&master->dev, "spi_device register error %s\n",
881+ nc->full_name);
882+ spi_dev_put(spi);
883+ }
884+
885+ }
886+}
887+#else
888+static void of_register_spi_devices(struct spi_master *master) { }
889+#endif
890+
801891 static void spi_master_release(struct device *dev)
802892 {
803893 struct spi_master *master;
@@ -846,6 +936,8 @@ struct spi_master *spi_alloc_master(struct device *dev, unsigned size) · 42 unmodified lines
846936 return NULL;
847937
848938 device_initialize(&master->dev);
939+ master->bus_num = -1;
940+ master->num_chipselect = 1;
849941 master->dev.class = &spi_master_class;
850942 master->dev.parent = get_device(dev);
851943 spi_master_set_devdata(master, &master[1]);
include/linux/of_spi.h+0−23
@@ -1,23 +0,0 @@
1−/*
2− * OpenFirmware SPI support routines
3− * Copyright (C) 2008 Secret Lab Technologies Ltd.
4− *
5− * Support routines for deriving SPI device attachments from the device
6− * tree.
7− */
8−
9−#ifndef __LINUX_OF_SPI_H
10−#define __LINUX_OF_SPI_H
11−
12−#include <linux/spi/spi.h>
13−
14−#if defined(CONFIG_OF_SPI) || defined(CONFIG_OF_SPI_MODULE)
15−extern void of_register_spi_devices(struct spi_master *master);
16−#else
17−static inline void of_register_spi_devices(struct spi_master *master)
18−{
19− return;
20−}
21−#endif /* CONFIG_OF_SPI */
22−
23−#endif /* __LINUX_OF_SPI */
include/linux/spi/rspi.h+31−0
@@ -0,0 +1,31 @@
1+/*
2+ * Renesas SPI driver
3+ *
4+ * Copyright (C) 2012 Renesas Solutions Corp.
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; version 2 of the License.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program; if not, write to the Free Software
17+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+ *
19+ */
20+
21+#ifndef __LINUX_SPI_RENESAS_SPI_H__
22+#define __LINUX_SPI_RENESAS_SPI_H__
23+
24+struct rspi_plat_data {
25+ unsigned int dma_tx_id;
26+ unsigned int dma_rx_id;
27+
28+ unsigned dma_width_16bit:1; /* DMAC read/write width = 16-bit */
29+};
30+
31+#endif