diff options
author | Jiri Kosina <jkosina@suse.cz> | 2013-12-19 09:08:03 -0500 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2013-12-19 09:08:32 -0500 |
commit | e23c34bb41da65f354fb7eee04300c56ee48f60c (patch) | |
tree | 549fbe449d55273b81ef104a9755109bf4ae7817 /drivers/spi | |
parent | b481c2cb3534c85dca625973b33eba15f9af3e4c (diff) | |
parent | 319e2e3f63c348a9b66db4667efa73178e18b17d (diff) |
Merge branch 'master' into for-next
Sync with Linus' tree to be able to apply fixes on top of newer things
in tree (efi-stub).
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/spi')
56 files changed, 1148 insertions, 746 deletions
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 0170d4c4a8a3..eb1f1ef5fa2e 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig | |||
@@ -55,7 +55,6 @@ comment "SPI Master Controller Drivers" | |||
55 | 55 | ||
56 | config SPI_ALTERA | 56 | config SPI_ALTERA |
57 | tristate "Altera SPI Controller" | 57 | tristate "Altera SPI Controller" |
58 | depends on GENERIC_HARDIRQS | ||
59 | select SPI_BITBANG | 58 | select SPI_BITBANG |
60 | help | 59 | help |
61 | This is the driver for the Altera SPI Controller. | 60 | This is the driver for the Altera SPI Controller. |
@@ -265,6 +264,7 @@ config SPI_FSL_SPI | |||
265 | config SPI_FSL_DSPI | 264 | config SPI_FSL_DSPI |
266 | tristate "Freescale DSPI controller" | 265 | tristate "Freescale DSPI controller" |
267 | select SPI_BITBANG | 266 | select SPI_BITBANG |
267 | depends on SOC_VF610 || COMPILE_TEST | ||
268 | help | 268 | help |
269 | This enables support for the Freescale DSPI controller in master | 269 | This enables support for the Freescale DSPI controller in master |
270 | mode. VF610 platform uses the controller. | 270 | mode. VF610 platform uses the controller. |
@@ -358,7 +358,7 @@ config SPI_PXA2XX_DMA | |||
358 | 358 | ||
359 | config SPI_PXA2XX | 359 | config SPI_PXA2XX |
360 | tristate "PXA2xx SSP SPI master" | 360 | tristate "PXA2xx SSP SPI master" |
361 | depends on (ARCH_PXA || PCI || ACPI) && GENERIC_HARDIRQS | 361 | depends on (ARCH_PXA || PCI || ACPI) |
362 | select PXA_SSP if ARCH_PXA | 362 | select PXA_SSP if ARCH_PXA |
363 | help | 363 | help |
364 | This enables using a PXA2xx or Sodaville SSP port as a SPI master | 364 | This enables using a PXA2xx or Sodaville SSP port as a SPI master |
@@ -370,7 +370,7 @@ config SPI_PXA2XX_PCI | |||
370 | 370 | ||
371 | config SPI_RSPI | 371 | config SPI_RSPI |
372 | tristate "Renesas RSPI controller" | 372 | tristate "Renesas RSPI controller" |
373 | depends on SUPERH && SH_DMAE_BASE | 373 | depends on (SUPERH || ARCH_SHMOBILE) && SH_DMAE_BASE |
374 | help | 374 | help |
375 | SPI driver for Renesas RSPI blocks. | 375 | SPI driver for Renesas RSPI blocks. |
376 | 376 | ||
@@ -394,7 +394,7 @@ config SPI_S3C24XX_FIQ | |||
394 | 394 | ||
395 | config SPI_S3C64XX | 395 | config SPI_S3C64XX |
396 | tristate "Samsung S3C64XX series type SPI" | 396 | tristate "Samsung S3C64XX series type SPI" |
397 | depends on (ARCH_S3C24XX || ARCH_S3C64XX || ARCH_S5P64X0 || ARCH_EXYNOS) | 397 | depends on PLAT_SAMSUNG |
398 | select S3C64XX_DMA if ARCH_S3C64XX | 398 | select S3C64XX_DMA if ARCH_S3C64XX |
399 | help | 399 | help |
400 | SPI driver for Samsung S3C64XX and newer SoCs. | 400 | SPI driver for Samsung S3C64XX and newer SoCs. |
diff --git a/drivers/spi/spi-altera.c b/drivers/spi/spi-altera.c index f38855f76536..595b62cb545d 100644 --- a/drivers/spi/spi-altera.c +++ b/drivers/spi/spi-altera.c | |||
@@ -219,7 +219,7 @@ static int altera_spi_probe(struct platform_device *pdev) | |||
219 | platform_set_drvdata(pdev, hw); | 219 | platform_set_drvdata(pdev, hw); |
220 | 220 | ||
221 | /* setup the state for the bitbang driver */ | 221 | /* setup the state for the bitbang driver */ |
222 | hw->bitbang.master = spi_master_get(master); | 222 | hw->bitbang.master = master; |
223 | if (!hw->bitbang.master) | 223 | if (!hw->bitbang.master) |
224 | return err; | 224 | return err; |
225 | hw->bitbang.chipselect = altera_spi_chipsel; | 225 | hw->bitbang.chipselect = altera_spi_chipsel; |
@@ -276,6 +276,7 @@ static int altera_spi_remove(struct platform_device *dev) | |||
276 | #ifdef CONFIG_OF | 276 | #ifdef CONFIG_OF |
277 | static const struct of_device_id altera_spi_match[] = { | 277 | static const struct of_device_id altera_spi_match[] = { |
278 | { .compatible = "ALTR,spi-1.0", }, | 278 | { .compatible = "ALTR,spi-1.0", }, |
279 | { .compatible = "altr,spi-1.0", }, | ||
279 | {}, | 280 | {}, |
280 | }; | 281 | }; |
281 | MODULE_DEVICE_TABLE(of, altera_spi_match); | 282 | MODULE_DEVICE_TABLE(of, altera_spi_match); |
diff --git a/drivers/spi/spi-ath79.c b/drivers/spi/spi-ath79.c index 37bad952ab38..821bf7ac218d 100644 --- a/drivers/spi/spi-ath79.c +++ b/drivers/spi/spi-ath79.c | |||
@@ -231,7 +231,7 @@ static int ath79_spi_probe(struct platform_device *pdev) | |||
231 | master->num_chipselect = pdata->num_chipselect; | 231 | master->num_chipselect = pdata->num_chipselect; |
232 | } | 232 | } |
233 | 233 | ||
234 | sp->bitbang.master = spi_master_get(master); | 234 | sp->bitbang.master = master; |
235 | sp->bitbang.chipselect = ath79_spi_chipselect; | 235 | sp->bitbang.chipselect = ath79_spi_chipselect; |
236 | sp->bitbang.txrx_word[SPI_MODE_0] = ath79_spi_txrx_mode0; | 236 | sp->bitbang.txrx_word[SPI_MODE_0] = ath79_spi_txrx_mode0; |
237 | sp->bitbang.setup_transfer = spi_bitbang_setup_transfer; | 237 | sp->bitbang.setup_transfer = spi_bitbang_setup_transfer; |
diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index fd7cc566095a..273db0beb2b8 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c | |||
@@ -170,18 +170,18 @@ | |||
170 | /* Bit manipulation macros */ | 170 | /* Bit manipulation macros */ |
171 | #define SPI_BIT(name) \ | 171 | #define SPI_BIT(name) \ |
172 | (1 << SPI_##name##_OFFSET) | 172 | (1 << SPI_##name##_OFFSET) |
173 | #define SPI_BF(name,value) \ | 173 | #define SPI_BF(name, value) \ |
174 | (((value) & ((1 << SPI_##name##_SIZE) - 1)) << SPI_##name##_OFFSET) | 174 | (((value) & ((1 << SPI_##name##_SIZE) - 1)) << SPI_##name##_OFFSET) |
175 | #define SPI_BFEXT(name,value) \ | 175 | #define SPI_BFEXT(name, value) \ |
176 | (((value) >> SPI_##name##_OFFSET) & ((1 << SPI_##name##_SIZE) - 1)) | 176 | (((value) >> SPI_##name##_OFFSET) & ((1 << SPI_##name##_SIZE) - 1)) |
177 | #define SPI_BFINS(name,value,old) \ | 177 | #define SPI_BFINS(name, value, old) \ |
178 | ( ((old) & ~(((1 << SPI_##name##_SIZE) - 1) << SPI_##name##_OFFSET)) \ | 178 | (((old) & ~(((1 << SPI_##name##_SIZE) - 1) << SPI_##name##_OFFSET)) \ |
179 | | SPI_BF(name,value)) | 179 | | SPI_BF(name, value)) |
180 | 180 | ||
181 | /* Register access macros */ | 181 | /* Register access macros */ |
182 | #define spi_readl(port,reg) \ | 182 | #define spi_readl(port, reg) \ |
183 | __raw_readl((port)->regs + SPI_##reg) | 183 | __raw_readl((port)->regs + SPI_##reg) |
184 | #define spi_writel(port,reg,value) \ | 184 | #define spi_writel(port, reg, value) \ |
185 | __raw_writel((value), (port)->regs + SPI_##reg) | 185 | __raw_writel((value), (port)->regs + SPI_##reg) |
186 | 186 | ||
187 | /* use PIO for small transfers, avoiding DMA setup/teardown overhead and | 187 | /* use PIO for small transfers, avoiding DMA setup/teardown overhead and |
@@ -1401,8 +1401,8 @@ static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *msg) | |||
1401 | asd = spi->controller_state; | 1401 | asd = spi->controller_state; |
1402 | bits = (asd->csr >> 4) & 0xf; | 1402 | bits = (asd->csr >> 4) & 0xf; |
1403 | if (bits != xfer->bits_per_word - 8) { | 1403 | if (bits != xfer->bits_per_word - 8) { |
1404 | dev_dbg(&spi->dev, "you can't yet change " | 1404 | dev_dbg(&spi->dev, |
1405 | "bits_per_word in transfers\n"); | 1405 | "you can't yet change bits_per_word in transfers\n"); |
1406 | return -ENOPROTOOPT; | 1406 | return -ENOPROTOOPT; |
1407 | } | 1407 | } |
1408 | } | 1408 | } |
@@ -1516,7 +1516,7 @@ static int atmel_spi_probe(struct platform_device *pdev) | |||
1516 | 1516 | ||
1517 | /* setup spi core then atmel-specific driver state */ | 1517 | /* setup spi core then atmel-specific driver state */ |
1518 | ret = -ENOMEM; | 1518 | ret = -ENOMEM; |
1519 | master = spi_alloc_master(&pdev->dev, sizeof *as); | 1519 | master = spi_alloc_master(&pdev->dev, sizeof(*as)); |
1520 | if (!master) | 1520 | if (!master) |
1521 | goto out_free; | 1521 | goto out_free; |
1522 | 1522 | ||
@@ -1546,9 +1546,11 @@ static int atmel_spi_probe(struct platform_device *pdev) | |||
1546 | INIT_LIST_HEAD(&as->queue); | 1546 | INIT_LIST_HEAD(&as->queue); |
1547 | 1547 | ||
1548 | as->pdev = pdev; | 1548 | as->pdev = pdev; |
1549 | as->regs = ioremap(regs->start, resource_size(regs)); | 1549 | as->regs = devm_ioremap_resource(&pdev->dev, regs); |
1550 | if (!as->regs) | 1550 | if (IS_ERR(as->regs)) { |
1551 | ret = PTR_ERR(as->regs); | ||
1551 | goto out_free_buffer; | 1552 | goto out_free_buffer; |
1553 | } | ||
1552 | as->phybase = regs->start; | 1554 | as->phybase = regs->start; |
1553 | as->irq = irq; | 1555 | as->irq = irq; |
1554 | as->clk = clk; | 1556 | as->clk = clk; |
@@ -1583,7 +1585,7 @@ static int atmel_spi_probe(struct platform_device *pdev) | |||
1583 | /* Initialize the hardware */ | 1585 | /* Initialize the hardware */ |
1584 | ret = clk_prepare_enable(clk); | 1586 | ret = clk_prepare_enable(clk); |
1585 | if (ret) | 1587 | if (ret) |
1586 | goto out_unmap_regs; | 1588 | goto out_free_irq; |
1587 | spi_writel(as, CR, SPI_BIT(SWRST)); | 1589 | spi_writel(as, CR, SPI_BIT(SWRST)); |
1588 | spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */ | 1590 | spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */ |
1589 | if (as->caps.has_wdrbt) { | 1591 | if (as->caps.has_wdrbt) { |
@@ -1614,9 +1616,9 @@ out_free_dma: | |||
1614 | spi_writel(as, CR, SPI_BIT(SWRST)); | 1616 | spi_writel(as, CR, SPI_BIT(SWRST)); |
1615 | spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */ | 1617 | spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */ |
1616 | clk_disable_unprepare(clk); | 1618 | clk_disable_unprepare(clk); |
1619 | out_free_irq: | ||
1617 | free_irq(irq, master); | 1620 | free_irq(irq, master); |
1618 | out_unmap_regs: | 1621 | out_unmap_regs: |
1619 | iounmap(as->regs); | ||
1620 | out_free_buffer: | 1622 | out_free_buffer: |
1621 | if (!as->use_pdc) | 1623 | if (!as->use_pdc) |
1622 | tasklet_kill(&as->tasklet); | 1624 | tasklet_kill(&as->tasklet); |
@@ -1668,36 +1670,36 @@ static int atmel_spi_remove(struct platform_device *pdev) | |||
1668 | clk_disable_unprepare(as->clk); | 1670 | clk_disable_unprepare(as->clk); |
1669 | clk_put(as->clk); | 1671 | clk_put(as->clk); |
1670 | free_irq(as->irq, master); | 1672 | free_irq(as->irq, master); |
1671 | iounmap(as->regs); | ||
1672 | 1673 | ||
1673 | spi_unregister_master(master); | 1674 | spi_unregister_master(master); |
1674 | 1675 | ||
1675 | return 0; | 1676 | return 0; |
1676 | } | 1677 | } |
1677 | 1678 | ||
1678 | #ifdef CONFIG_PM | 1679 | #ifdef CONFIG_PM_SLEEP |
1679 | 1680 | static int atmel_spi_suspend(struct device *dev) | |
1680 | static int atmel_spi_suspend(struct platform_device *pdev, pm_message_t mesg) | ||
1681 | { | 1681 | { |
1682 | struct spi_master *master = platform_get_drvdata(pdev); | 1682 | struct spi_master *master = dev_get_drvdata(dev); |
1683 | struct atmel_spi *as = spi_master_get_devdata(master); | 1683 | struct atmel_spi *as = spi_master_get_devdata(master); |
1684 | 1684 | ||
1685 | clk_disable_unprepare(as->clk); | 1685 | clk_disable_unprepare(as->clk); |
1686 | return 0; | 1686 | return 0; |
1687 | } | 1687 | } |
1688 | 1688 | ||
1689 | static int atmel_spi_resume(struct platform_device *pdev) | 1689 | static int atmel_spi_resume(struct device *dev) |
1690 | { | 1690 | { |
1691 | struct spi_master *master = platform_get_drvdata(pdev); | 1691 | struct spi_master *master = dev_get_drvdata(dev); |
1692 | struct atmel_spi *as = spi_master_get_devdata(master); | 1692 | struct atmel_spi *as = spi_master_get_devdata(master); |
1693 | 1693 | ||
1694 | return clk_prepare_enable(as->clk); | 1694 | clk_prepare_enable(as->clk); |
1695 | return 0; | 1695 | return 0; |
1696 | } | 1696 | } |
1697 | 1697 | ||
1698 | static SIMPLE_DEV_PM_OPS(atmel_spi_pm_ops, atmel_spi_suspend, atmel_spi_resume); | ||
1699 | |||
1700 | #define ATMEL_SPI_PM_OPS (&atmel_spi_pm_ops) | ||
1698 | #else | 1701 | #else |
1699 | #define atmel_spi_suspend NULL | 1702 | #define ATMEL_SPI_PM_OPS NULL |
1700 | #define atmel_spi_resume NULL | ||
1701 | #endif | 1703 | #endif |
1702 | 1704 | ||
1703 | #if defined(CONFIG_OF) | 1705 | #if defined(CONFIG_OF) |
@@ -1713,10 +1715,9 @@ static struct platform_driver atmel_spi_driver = { | |||
1713 | .driver = { | 1715 | .driver = { |
1714 | .name = "atmel_spi", | 1716 | .name = "atmel_spi", |
1715 | .owner = THIS_MODULE, | 1717 | .owner = THIS_MODULE, |
1718 | .pm = ATMEL_SPI_PM_OPS, | ||
1716 | .of_match_table = of_match_ptr(atmel_spi_dt_ids), | 1719 | .of_match_table = of_match_ptr(atmel_spi_dt_ids), |
1717 | }, | 1720 | }, |
1718 | .suspend = atmel_spi_suspend, | ||
1719 | .resume = atmel_spi_resume, | ||
1720 | .probe = atmel_spi_probe, | 1721 | .probe = atmel_spi_probe, |
1721 | .remove = atmel_spi_remove, | 1722 | .remove = atmel_spi_remove, |
1722 | }; | 1723 | }; |
diff --git a/drivers/spi/spi-au1550.c b/drivers/spi/spi-au1550.c index 1d00d9b397dd..c4141c92bcff 100644 --- a/drivers/spi/spi-au1550.c +++ b/drivers/spi/spi-au1550.c | |||
@@ -775,7 +775,7 @@ static int au1550_spi_probe(struct platform_device *pdev) | |||
775 | 775 | ||
776 | hw = spi_master_get_devdata(master); | 776 | hw = spi_master_get_devdata(master); |
777 | 777 | ||
778 | hw->master = spi_master_get(master); | 778 | hw->master = master; |
779 | hw->pdata = dev_get_platdata(&pdev->dev); | 779 | hw->pdata = dev_get_platdata(&pdev->dev); |
780 | hw->dev = &pdev->dev; | 780 | hw->dev = &pdev->dev; |
781 | 781 | ||
@@ -985,6 +985,7 @@ static int au1550_spi_remove(struct platform_device *pdev) | |||
985 | MODULE_ALIAS("platform:au1550-spi"); | 985 | MODULE_ALIAS("platform:au1550-spi"); |
986 | 986 | ||
987 | static struct platform_driver au1550_spi_drv = { | 987 | static struct platform_driver au1550_spi_drv = { |
988 | .probe = au1550_spi_probe, | ||
988 | .remove = au1550_spi_remove, | 989 | .remove = au1550_spi_remove, |
989 | .driver = { | 990 | .driver = { |
990 | .name = "au1550-spi", | 991 | .name = "au1550-spi", |
@@ -1004,7 +1005,7 @@ static int __init au1550_spi_init(void) | |||
1004 | printk(KERN_ERR "au1550-spi: cannot add memory" | 1005 | printk(KERN_ERR "au1550-spi: cannot add memory" |
1005 | "dbdma device\n"); | 1006 | "dbdma device\n"); |
1006 | } | 1007 | } |
1007 | return platform_driver_probe(&au1550_spi_drv, au1550_spi_probe); | 1008 | return platform_driver_register(&au1550_spi_drv); |
1008 | } | 1009 | } |
1009 | module_init(au1550_spi_init); | 1010 | module_init(au1550_spi_init); |
1010 | 1011 | ||
diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index 52c81481c5c7..9025edd7dc45 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c | |||
@@ -217,7 +217,7 @@ static int bcm2835_spi_start_transfer(struct spi_device *spi, | |||
217 | cs |= spi->chip_select; | 217 | cs |= spi->chip_select; |
218 | } | 218 | } |
219 | 219 | ||
220 | INIT_COMPLETION(bs->done); | 220 | reinit_completion(&bs->done); |
221 | bs->tx_buf = tfr->tx_buf; | 221 | bs->tx_buf = tfr->tx_buf; |
222 | bs->rx_buf = tfr->rx_buf; | 222 | bs->rx_buf = tfr->rx_buf; |
223 | bs->len = tfr->len; | 223 | bs->len = tfr->len; |
@@ -358,7 +358,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev) | |||
358 | bcm2835_wr(bs, BCM2835_SPI_CS, | 358 | bcm2835_wr(bs, BCM2835_SPI_CS, |
359 | BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX); | 359 | BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX); |
360 | 360 | ||
361 | err = spi_register_master(master); | 361 | err = devm_spi_register_master(&pdev->dev, master); |
362 | if (err) { | 362 | if (err) { |
363 | dev_err(&pdev->dev, "could not register SPI master: %d\n", err); | 363 | dev_err(&pdev->dev, "could not register SPI master: %d\n", err); |
364 | goto out_free_irq; | 364 | goto out_free_irq; |
@@ -377,18 +377,16 @@ out_master_put: | |||
377 | 377 | ||
378 | static int bcm2835_spi_remove(struct platform_device *pdev) | 378 | static int bcm2835_spi_remove(struct platform_device *pdev) |
379 | { | 379 | { |
380 | struct spi_master *master = spi_master_get(platform_get_drvdata(pdev)); | 380 | struct spi_master *master = platform_get_drvdata(pdev); |
381 | struct bcm2835_spi *bs = spi_master_get_devdata(master); | 381 | struct bcm2835_spi *bs = spi_master_get_devdata(master); |
382 | 382 | ||
383 | free_irq(bs->irq, master); | 383 | free_irq(bs->irq, master); |
384 | spi_unregister_master(master); | ||
385 | 384 | ||
386 | /* Clear FIFOs, and disable the HW block */ | 385 | /* Clear FIFOs, and disable the HW block */ |
387 | bcm2835_wr(bs, BCM2835_SPI_CS, | 386 | bcm2835_wr(bs, BCM2835_SPI_CS, |
388 | BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX); | 387 | BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX); |
389 | 388 | ||
390 | clk_disable_unprepare(bs->clk); | 389 | clk_disable_unprepare(bs->clk); |
391 | spi_master_put(master); | ||
392 | 390 | ||
393 | return 0; | 391 | return 0; |
394 | } | 392 | } |
diff --git a/drivers/spi/spi-bcm63xx.c b/drivers/spi/spi-bcm63xx.c index 536b0e363826..469ecd876358 100644 --- a/drivers/spi/spi-bcm63xx.c +++ b/drivers/spi/spi-bcm63xx.c | |||
@@ -412,7 +412,7 @@ static int bcm63xx_spi_probe(struct platform_device *pdev) | |||
412 | bcm_spi_writeb(bs, SPI_INTR_CLEAR_ALL, SPI_INT_STATUS); | 412 | bcm_spi_writeb(bs, SPI_INTR_CLEAR_ALL, SPI_INT_STATUS); |
413 | 413 | ||
414 | /* register and we are done */ | 414 | /* register and we are done */ |
415 | ret = spi_register_master(master); | 415 | ret = devm_spi_register_master(dev, master); |
416 | if (ret) { | 416 | if (ret) { |
417 | dev_err(dev, "spi register failed\n"); | 417 | dev_err(dev, "spi register failed\n"); |
418 | goto out_clk_disable; | 418 | goto out_clk_disable; |
@@ -435,11 +435,9 @@ out: | |||
435 | 435 | ||
436 | static int bcm63xx_spi_remove(struct platform_device *pdev) | 436 | static int bcm63xx_spi_remove(struct platform_device *pdev) |
437 | { | 437 | { |
438 | struct spi_master *master = spi_master_get(platform_get_drvdata(pdev)); | 438 | struct spi_master *master = platform_get_drvdata(pdev); |
439 | struct bcm63xx_spi *bs = spi_master_get_devdata(master); | 439 | struct bcm63xx_spi *bs = spi_master_get_devdata(master); |
440 | 440 | ||
441 | spi_unregister_master(master); | ||
442 | |||
443 | /* reset spi block */ | 441 | /* reset spi block */ |
444 | bcm_spi_writeb(bs, 0, SPI_INT_MASK); | 442 | bcm_spi_writeb(bs, 0, SPI_INT_MASK); |
445 | 443 | ||
@@ -447,8 +445,6 @@ static int bcm63xx_spi_remove(struct platform_device *pdev) | |||
447 | clk_disable_unprepare(bs->clk); | 445 | clk_disable_unprepare(bs->clk); |
448 | clk_put(bs->clk); | 446 | clk_put(bs->clk); |
449 | 447 | ||
450 | spi_master_put(master); | ||
451 | |||
452 | return 0; | 448 | return 0; |
453 | } | 449 | } |
454 | 450 | ||
diff --git a/drivers/spi/spi-bfin-sport.c b/drivers/spi/spi-bfin-sport.c index 91921b5f5817..38941e5920b5 100644 --- a/drivers/spi/spi-bfin-sport.c +++ b/drivers/spi/spi-bfin-sport.c | |||
@@ -592,7 +592,7 @@ bfin_sport_spi_setup(struct spi_device *spi) | |||
592 | */ | 592 | */ |
593 | if (chip_info->ctl_reg || chip_info->enable_dma) { | 593 | if (chip_info->ctl_reg || chip_info->enable_dma) { |
594 | ret = -EINVAL; | 594 | ret = -EINVAL; |
595 | dev_err(&spi->dev, "don't set ctl_reg/enable_dma fields"); | 595 | dev_err(&spi->dev, "don't set ctl_reg/enable_dma fields\n"); |
596 | goto error; | 596 | goto error; |
597 | } | 597 | } |
598 | chip->cs_chg_udelay = chip_info->cs_chg_udelay; | 598 | chip->cs_chg_udelay = chip_info->cs_chg_udelay; |
@@ -879,11 +879,10 @@ static int bfin_sport_spi_remove(struct platform_device *pdev) | |||
879 | return 0; | 879 | return 0; |
880 | } | 880 | } |
881 | 881 | ||
882 | #ifdef CONFIG_PM | 882 | #ifdef CONFIG_PM_SLEEP |
883 | static int | 883 | static int bfin_sport_spi_suspend(struct device *dev) |
884 | bfin_sport_spi_suspend(struct platform_device *pdev, pm_message_t state) | ||
885 | { | 884 | { |
886 | struct bfin_sport_spi_master_data *drv_data = platform_get_drvdata(pdev); | 885 | struct bfin_sport_spi_master_data *drv_data = dev_get_drvdata(dev); |
887 | int status; | 886 | int status; |
888 | 887 | ||
889 | status = bfin_sport_spi_stop_queue(drv_data); | 888 | status = bfin_sport_spi_stop_queue(drv_data); |
@@ -896,10 +895,9 @@ bfin_sport_spi_suspend(struct platform_device *pdev, pm_message_t state) | |||
896 | return status; | 895 | return status; |
897 | } | 896 | } |
898 | 897 | ||
899 | static int | 898 | static int bfin_sport_spi_resume(struct device *dev) |
900 | bfin_sport_spi_resume(struct platform_device *pdev) | ||
901 | { | 899 | { |
902 | struct bfin_sport_spi_master_data *drv_data = platform_get_drvdata(pdev); | 900 | struct bfin_sport_spi_master_data *drv_data = dev_get_drvdata(dev); |
903 | int status; | 901 | int status; |
904 | 902 | ||
905 | /* Enable the SPI interface */ | 903 | /* Enable the SPI interface */ |
@@ -912,19 +910,22 @@ bfin_sport_spi_resume(struct platform_device *pdev) | |||
912 | 910 | ||
913 | return status; | 911 | return status; |
914 | } | 912 | } |
913 | |||
914 | static SIMPLE_DEV_PM_OPS(bfin_sport_spi_pm_ops, bfin_sport_spi_suspend, | ||
915 | bfin_sport_spi_resume); | ||
916 | |||
917 | #define BFIN_SPORT_SPI_PM_OPS (&bfin_sport_spi_pm_ops) | ||
915 | #else | 918 | #else |
916 | # define bfin_sport_spi_suspend NULL | 919 | #define BFIN_SPORT_SPI_PM_OPS NULL |
917 | # define bfin_sport_spi_resume NULL | ||
918 | #endif | 920 | #endif |
919 | 921 | ||
920 | static struct platform_driver bfin_sport_spi_driver = { | 922 | static struct platform_driver bfin_sport_spi_driver = { |
921 | .driver = { | 923 | .driver = { |
922 | .name = DRV_NAME, | 924 | .name = DRV_NAME, |
923 | .owner = THIS_MODULE, | 925 | .owner = THIS_MODULE, |
926 | .pm = BFIN_SPORT_SPI_PM_OPS, | ||
924 | }, | 927 | }, |
925 | .probe = bfin_sport_spi_probe, | 928 | .probe = bfin_sport_spi_probe, |
926 | .remove = bfin_sport_spi_remove, | 929 | .remove = bfin_sport_spi_remove, |
927 | .suspend = bfin_sport_spi_suspend, | ||
928 | .resume = bfin_sport_spi_resume, | ||
929 | }; | 930 | }; |
930 | module_platform_driver(bfin_sport_spi_driver); | 931 | module_platform_driver(bfin_sport_spi_driver); |
diff --git a/drivers/spi/spi-bfin-v3.c b/drivers/spi/spi-bfin-v3.c index f4bf81347d68..8f8598834b30 100644 --- a/drivers/spi/spi-bfin-v3.c +++ b/drivers/spi/spi-bfin-v3.c | |||
@@ -867,7 +867,7 @@ static int bfin_spi_probe(struct platform_device *pdev) | |||
867 | tasklet_init(&drv_data->pump_transfers, | 867 | tasklet_init(&drv_data->pump_transfers, |
868 | bfin_spi_pump_transfers, (unsigned long)drv_data); | 868 | bfin_spi_pump_transfers, (unsigned long)drv_data); |
869 | /* register with the SPI framework */ | 869 | /* register with the SPI framework */ |
870 | ret = spi_register_master(master); | 870 | ret = devm_spi_register_master(dev, master); |
871 | if (ret) { | 871 | if (ret) { |
872 | dev_err(dev, "can not register spi master\n"); | 872 | dev_err(dev, "can not register spi master\n"); |
873 | goto err_free_peripheral; | 873 | goto err_free_peripheral; |
@@ -898,7 +898,6 @@ static int bfin_spi_remove(struct platform_device *pdev) | |||
898 | free_dma(drv_data->rx_dma); | 898 | free_dma(drv_data->rx_dma); |
899 | free_dma(drv_data->tx_dma); | 899 | free_dma(drv_data->tx_dma); |
900 | 900 | ||
901 | spi_unregister_master(drv_data->master); | ||
902 | return 0; | 901 | return 0; |
903 | } | 902 | } |
904 | 903 | ||
diff --git a/drivers/spi/spi-bfin5xx.c b/drivers/spi/spi-bfin5xx.c index 45bdf73d6868..f0f195af75d4 100644 --- a/drivers/spi/spi-bfin5xx.c +++ b/drivers/spi/spi-bfin5xx.c | |||
@@ -524,7 +524,7 @@ static irqreturn_t bfin_spi_dma_irq_handler(int irq, void *dev_id) | |||
524 | timeout = jiffies + HZ; | 524 | timeout = jiffies + HZ; |
525 | while (!(bfin_read(&drv_data->regs->stat) & BIT_STAT_SPIF)) | 525 | while (!(bfin_read(&drv_data->regs->stat) & BIT_STAT_SPIF)) |
526 | if (!time_before(jiffies, timeout)) { | 526 | if (!time_before(jiffies, timeout)) { |
527 | dev_warn(&drv_data->pdev->dev, "timeout waiting for SPIF"); | 527 | dev_warn(&drv_data->pdev->dev, "timeout waiting for SPIF\n"); |
528 | break; | 528 | break; |
529 | } else | 529 | } else |
530 | cpu_relax(); | 530 | cpu_relax(); |
@@ -913,8 +913,9 @@ static void bfin_spi_pump_messages(struct work_struct *work) | |||
913 | drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next, | 913 | drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next, |
914 | struct spi_transfer, transfer_list); | 914 | struct spi_transfer, transfer_list); |
915 | 915 | ||
916 | dev_dbg(&drv_data->pdev->dev, "got a message to pump, " | 916 | dev_dbg(&drv_data->pdev->dev, |
917 | "state is set to: baud %d, flag 0x%x, ctl 0x%x\n", | 917 | "got a message to pump, state is set to: baud " |
918 | "%d, flag 0x%x, ctl 0x%x\n", | ||
918 | drv_data->cur_chip->baud, drv_data->cur_chip->flag, | 919 | drv_data->cur_chip->baud, drv_data->cur_chip->flag, |
919 | drv_data->cur_chip->ctl_reg); | 920 | drv_data->cur_chip->ctl_reg); |
920 | 921 | ||
@@ -1013,8 +1014,8 @@ static int bfin_spi_setup(struct spi_device *spi) | |||
1013 | * but let's assume (for now) they do. | 1014 | * but let's assume (for now) they do. |
1014 | */ | 1015 | */ |
1015 | if (chip_info->ctl_reg & ~bfin_ctl_reg) { | 1016 | if (chip_info->ctl_reg & ~bfin_ctl_reg) { |
1016 | dev_err(&spi->dev, "do not set bits in ctl_reg " | 1017 | dev_err(&spi->dev, |
1017 | "that the SPI framework manages\n"); | 1018 | "do not set bits in ctl_reg that the SPI framework manages\n"); |
1018 | goto error; | 1019 | goto error; |
1019 | } | 1020 | } |
1020 | chip->enable_dma = chip_info->enable_dma != 0 | 1021 | chip->enable_dma = chip_info->enable_dma != 0 |
@@ -1050,17 +1051,17 @@ static int bfin_spi_setup(struct spi_device *spi) | |||
1050 | chip->chip_select_num = spi->chip_select; | 1051 | chip->chip_select_num = spi->chip_select; |
1051 | if (chip->chip_select_num < MAX_CTRL_CS) { | 1052 | if (chip->chip_select_num < MAX_CTRL_CS) { |
1052 | if (!(spi->mode & SPI_CPHA)) | 1053 | if (!(spi->mode & SPI_CPHA)) |
1053 | dev_warn(&spi->dev, "Warning: SPI CPHA not set:" | 1054 | dev_warn(&spi->dev, |
1054 | " Slave Select not under software control!\n" | 1055 | "Warning: SPI CPHA not set: Slave Select not under software control!\n" |
1055 | " See Documentation/blackfin/bfin-spi-notes.txt"); | 1056 | "See Documentation/blackfin/bfin-spi-notes.txt\n"); |
1056 | 1057 | ||
1057 | chip->flag = (1 << spi->chip_select) << 8; | 1058 | chip->flag = (1 << spi->chip_select) << 8; |
1058 | } else | 1059 | } else |
1059 | chip->cs_gpio = chip->chip_select_num - MAX_CTRL_CS; | 1060 | chip->cs_gpio = chip->chip_select_num - MAX_CTRL_CS; |
1060 | 1061 | ||
1061 | if (chip->enable_dma && chip->pio_interrupt) { | 1062 | if (chip->enable_dma && chip->pio_interrupt) { |
1062 | dev_err(&spi->dev, "enable_dma is set, " | 1063 | dev_err(&spi->dev, |
1063 | "do not set pio_interrupt\n"); | 1064 | "enable_dma is set, do not set pio_interrupt\n"); |
1064 | goto error; | 1065 | goto error; |
1065 | } | 1066 | } |
1066 | /* | 1067 | /* |
@@ -1410,10 +1411,10 @@ static int bfin_spi_remove(struct platform_device *pdev) | |||
1410 | return 0; | 1411 | return 0; |
1411 | } | 1412 | } |
1412 | 1413 | ||
1413 | #ifdef CONFIG_PM | 1414 | #ifdef CONFIG_PM_SLEEP |
1414 | static int bfin_spi_suspend(struct platform_device *pdev, pm_message_t state) | 1415 | static int bfin_spi_suspend(struct device *dev) |
1415 | { | 1416 | { |
1416 | struct bfin_spi_master_data *drv_data = platform_get_drvdata(pdev); | 1417 | struct bfin_spi_master_data *drv_data = dev_get_drvdata(dev); |
1417 | int status = 0; | 1418 | int status = 0; |
1418 | 1419 | ||
1419 | status = bfin_spi_stop_queue(drv_data); | 1420 | status = bfin_spi_stop_queue(drv_data); |
@@ -1432,9 +1433,9 @@ static int bfin_spi_suspend(struct platform_device *pdev, pm_message_t state) | |||
1432 | return 0; | 1433 | return 0; |
1433 | } | 1434 | } |
1434 | 1435 | ||
1435 | static int bfin_spi_resume(struct platform_device *pdev) | 1436 | static int bfin_spi_resume(struct device *dev) |
1436 | { | 1437 | { |
1437 | struct bfin_spi_master_data *drv_data = platform_get_drvdata(pdev); | 1438 | struct bfin_spi_master_data *drv_data = dev_get_drvdata(dev); |
1438 | int status = 0; | 1439 | int status = 0; |
1439 | 1440 | ||
1440 | bfin_write(&drv_data->regs->ctl, drv_data->ctrl_reg); | 1441 | bfin_write(&drv_data->regs->ctl, drv_data->ctrl_reg); |
@@ -1443,31 +1444,34 @@ static int bfin_spi_resume(struct platform_device *pdev) | |||
1443 | /* Start the queue running */ | 1444 | /* Start the queue running */ |
1444 | status = bfin_spi_start_queue(drv_data); | 1445 | status = bfin_spi_start_queue(drv_data); |
1445 | if (status != 0) { | 1446 | if (status != 0) { |
1446 | dev_err(&pdev->dev, "problem starting queue (%d)\n", status); | 1447 | dev_err(dev, "problem starting queue (%d)\n", status); |
1447 | return status; | 1448 | return status; |
1448 | } | 1449 | } |
1449 | 1450 | ||
1450 | return 0; | 1451 | return 0; |
1451 | } | 1452 | } |
1453 | |||
1454 | static SIMPLE_DEV_PM_OPS(bfin_spi_pm_ops, bfin_spi_suspend, bfin_spi_resume); | ||
1455 | |||
1456 | #define BFIN_SPI_PM_OPS (&bfin_spi_pm_ops) | ||
1452 | #else | 1457 | #else |
1453 | #define bfin_spi_suspend NULL | 1458 | #define BFIN_SPI_PM_OPS NULL |
1454 | #define bfin_spi_resume NULL | 1459 | #endif |
1455 | #endif /* CONFIG_PM */ | ||
1456 | 1460 | ||
1457 | MODULE_ALIAS("platform:bfin-spi"); | 1461 | MODULE_ALIAS("platform:bfin-spi"); |
1458 | static struct platform_driver bfin_spi_driver = { | 1462 | static struct platform_driver bfin_spi_driver = { |
1459 | .driver = { | 1463 | .driver = { |
1460 | .name = DRV_NAME, | 1464 | .name = DRV_NAME, |
1461 | .owner = THIS_MODULE, | 1465 | .owner = THIS_MODULE, |
1466 | .pm = BFIN_SPI_PM_OPS, | ||
1462 | }, | 1467 | }, |
1463 | .suspend = bfin_spi_suspend, | 1468 | .probe = bfin_spi_probe, |
1464 | .resume = bfin_spi_resume, | ||
1465 | .remove = bfin_spi_remove, | 1469 | .remove = bfin_spi_remove, |
1466 | }; | 1470 | }; |
1467 | 1471 | ||
1468 | static int __init bfin_spi_init(void) | 1472 | static int __init bfin_spi_init(void) |
1469 | { | 1473 | { |
1470 | return platform_driver_probe(&bfin_spi_driver, bfin_spi_probe); | 1474 | return platform_driver_register(&bfin_spi_driver); |
1471 | } | 1475 | } |
1472 | subsys_initcall(bfin_spi_init); | 1476 | subsys_initcall(bfin_spi_init); |
1473 | 1477 | ||
diff --git a/drivers/spi/spi-bitbang.c b/drivers/spi/spi-bitbang.c index 8c11355dec23..bd222f6b677d 100644 --- a/drivers/spi/spi-bitbang.c +++ b/drivers/spi/spi-bitbang.c | |||
@@ -191,7 +191,7 @@ int spi_bitbang_setup(struct spi_device *spi) | |||
191 | bitbang = spi_master_get_devdata(spi->master); | 191 | bitbang = spi_master_get_devdata(spi->master); |
192 | 192 | ||
193 | if (!cs) { | 193 | if (!cs) { |
194 | cs = kzalloc(sizeof *cs, GFP_KERNEL); | 194 | cs = kzalloc(sizeof(*cs), GFP_KERNEL); |
195 | if (!cs) | 195 | if (!cs) |
196 | return -ENOMEM; | 196 | return -ENOMEM; |
197 | spi->controller_state = cs; | 197 | spi->controller_state = cs; |
@@ -258,7 +258,7 @@ static int spi_bitbang_bufs(struct spi_device *spi, struct spi_transfer *t) | |||
258 | 258 | ||
259 | static int spi_bitbang_prepare_hardware(struct spi_master *spi) | 259 | static int spi_bitbang_prepare_hardware(struct spi_master *spi) |
260 | { | 260 | { |
261 | struct spi_bitbang *bitbang; | 261 | struct spi_bitbang *bitbang; |
262 | unsigned long flags; | 262 | unsigned long flags; |
263 | 263 | ||
264 | bitbang = spi_master_get_devdata(spi); | 264 | bitbang = spi_master_get_devdata(spi); |
@@ -273,7 +273,7 @@ static int spi_bitbang_prepare_hardware(struct spi_master *spi) | |||
273 | static int spi_bitbang_transfer_one(struct spi_master *master, | 273 | static int spi_bitbang_transfer_one(struct spi_master *master, |
274 | struct spi_message *m) | 274 | struct spi_message *m) |
275 | { | 275 | { |
276 | struct spi_bitbang *bitbang; | 276 | struct spi_bitbang *bitbang; |
277 | unsigned nsecs; | 277 | unsigned nsecs; |
278 | struct spi_transfer *t = NULL; | 278 | struct spi_transfer *t = NULL; |
279 | unsigned cs_change; | 279 | unsigned cs_change; |
@@ -292,7 +292,7 @@ static int spi_bitbang_transfer_one(struct spi_master *master, | |||
292 | cs_change = 1; | 292 | cs_change = 1; |
293 | status = 0; | 293 | status = 0; |
294 | 294 | ||
295 | list_for_each_entry (t, &m->transfers, transfer_list) { | 295 | list_for_each_entry(t, &m->transfers, transfer_list) { |
296 | 296 | ||
297 | /* override speed or wordsize? */ | 297 | /* override speed or wordsize? */ |
298 | if (t->speed_hz || t->bits_per_word) | 298 | if (t->speed_hz || t->bits_per_word) |
@@ -349,7 +349,8 @@ static int spi_bitbang_transfer_one(struct spi_master *master, | |||
349 | if (t->delay_usecs) | 349 | if (t->delay_usecs) |
350 | udelay(t->delay_usecs); | 350 | udelay(t->delay_usecs); |
351 | 351 | ||
352 | if (cs_change && !list_is_last(&t->transfer_list, &m->transfers)) { | 352 | if (cs_change && |
353 | !list_is_last(&t->transfer_list, &m->transfers)) { | ||
353 | /* sometimes a short mid-message deselect of the chip | 354 | /* sometimes a short mid-message deselect of the chip |
354 | * may be needed to terminate a mode or command | 355 | * may be needed to terminate a mode or command |
355 | */ | 356 | */ |
@@ -378,7 +379,7 @@ static int spi_bitbang_transfer_one(struct spi_master *master, | |||
378 | 379 | ||
379 | static int spi_bitbang_unprepare_hardware(struct spi_master *spi) | 380 | static int spi_bitbang_unprepare_hardware(struct spi_master *spi) |
380 | { | 381 | { |
381 | struct spi_bitbang *bitbang; | 382 | struct spi_bitbang *bitbang; |
382 | unsigned long flags; | 383 | unsigned long flags; |
383 | 384 | ||
384 | bitbang = spi_master_get_devdata(spi); | 385 | bitbang = spi_master_get_devdata(spi); |
@@ -414,10 +415,16 @@ static int spi_bitbang_unprepare_hardware(struct spi_master *spi) | |||
414 | * This routine registers the spi_master, which will process requests in a | 415 | * This routine registers the spi_master, which will process requests in a |
415 | * dedicated task, keeping IRQs unblocked most of the time. To stop | 416 | * dedicated task, keeping IRQs unblocked most of the time. To stop |
416 | * processing those requests, call spi_bitbang_stop(). | 417 | * processing those requests, call spi_bitbang_stop(). |
418 | * | ||
419 | * On success, this routine will take a reference to master. The caller is | ||
420 | * responsible for calling spi_bitbang_stop() to decrement the reference and | ||
421 | * spi_master_put() as counterpart of spi_alloc_master() to prevent a memory | ||
422 | * leak. | ||
417 | */ | 423 | */ |
418 | int spi_bitbang_start(struct spi_bitbang *bitbang) | 424 | int spi_bitbang_start(struct spi_bitbang *bitbang) |
419 | { | 425 | { |
420 | struct spi_master *master = bitbang->master; | 426 | struct spi_master *master = bitbang->master; |
427 | int ret; | ||
421 | 428 | ||
422 | if (!master || !bitbang->chipselect) | 429 | if (!master || !bitbang->chipselect) |
423 | return -EINVAL; | 430 | return -EINVAL; |
@@ -449,7 +456,11 @@ int spi_bitbang_start(struct spi_bitbang *bitbang) | |||
449 | /* driver may get busy before register() returns, especially | 456 | /* driver may get busy before register() returns, especially |
450 | * if someone registered boardinfo for devices | 457 | * if someone registered boardinfo for devices |
451 | */ | 458 | */ |
452 | return spi_register_master(master); | 459 | ret = spi_register_master(spi_master_get(master)); |
460 | if (ret) | ||
461 | spi_master_put(master); | ||
462 | |||
463 | return 0; | ||
453 | } | 464 | } |
454 | EXPORT_SYMBOL_GPL(spi_bitbang_start); | 465 | EXPORT_SYMBOL_GPL(spi_bitbang_start); |
455 | 466 | ||
diff --git a/drivers/spi/spi-butterfly.c b/drivers/spi/spi-butterfly.c index 5ed08e537433..8081f96bd1d5 100644 --- a/drivers/spi/spi-butterfly.c +++ b/drivers/spi/spi-butterfly.c | |||
@@ -147,8 +147,8 @@ static void butterfly_chipselect(struct spi_device *spi, int value) | |||
147 | 147 | ||
148 | /* we only needed to implement one mode here, and choose SPI_MODE_0 */ | 148 | /* we only needed to implement one mode here, and choose SPI_MODE_0 */ |
149 | 149 | ||
150 | #define spidelay(X) do{}while(0) | 150 | #define spidelay(X) do { } while (0) |
151 | //#define spidelay ndelay | 151 | /* #define spidelay ndelay */ |
152 | 152 | ||
153 | #include "spi-bitbang-txrx.h" | 153 | #include "spi-bitbang-txrx.h" |
154 | 154 | ||
@@ -171,15 +171,15 @@ static struct mtd_partition partitions[] = { { | |||
171 | /* sector 0 = 8 pages * 264 bytes/page (1 block) | 171 | /* sector 0 = 8 pages * 264 bytes/page (1 block) |
172 | * sector 1 = 248 pages * 264 bytes/page | 172 | * sector 1 = 248 pages * 264 bytes/page |
173 | */ | 173 | */ |
174 | .name = "bookkeeping", // 66 KB | 174 | .name = "bookkeeping", /* 66 KB */ |
175 | .offset = 0, | 175 | .offset = 0, |
176 | .size = (8 + 248) * 264, | 176 | .size = (8 + 248) * 264, |
177 | // .mask_flags = MTD_WRITEABLE, | 177 | /* .mask_flags = MTD_WRITEABLE, */ |
178 | }, { | 178 | }, { |
179 | /* sector 2 = 256 pages * 264 bytes/page | 179 | /* sector 2 = 256 pages * 264 bytes/page |
180 | * sectors 3-5 = 512 pages * 264 bytes/page | 180 | * sectors 3-5 = 512 pages * 264 bytes/page |
181 | */ | 181 | */ |
182 | .name = "filesystem", // 462 KB | 182 | .name = "filesystem", /* 462 KB */ |
183 | .offset = MTDPART_OFS_APPEND, | 183 | .offset = MTDPART_OFS_APPEND, |
184 | .size = MTDPART_SIZ_FULL, | 184 | .size = MTDPART_SIZ_FULL, |
185 | } }; | 185 | } }; |
@@ -209,7 +209,7 @@ static void butterfly_attach(struct parport *p) | |||
209 | * and no way to be selective about what it binds to. | 209 | * and no way to be selective about what it binds to. |
210 | */ | 210 | */ |
211 | 211 | ||
212 | master = spi_alloc_master(dev, sizeof *pp); | 212 | master = spi_alloc_master(dev, sizeof(*pp)); |
213 | if (!master) { | 213 | if (!master) { |
214 | status = -ENOMEM; | 214 | status = -ENOMEM; |
215 | goto done; | 215 | goto done; |
@@ -225,7 +225,7 @@ static void butterfly_attach(struct parport *p) | |||
225 | master->bus_num = 42; | 225 | master->bus_num = 42; |
226 | master->num_chipselect = 2; | 226 | master->num_chipselect = 2; |
227 | 227 | ||
228 | pp->bitbang.master = spi_master_get(master); | 228 | pp->bitbang.master = master; |
229 | pp->bitbang.chipselect = butterfly_chipselect; | 229 | pp->bitbang.chipselect = butterfly_chipselect; |
230 | pp->bitbang.txrx_word[SPI_MODE_0] = butterfly_txrx_word_mode0; | 230 | pp->bitbang.txrx_word[SPI_MODE_0] = butterfly_txrx_word_mode0; |
231 | 231 | ||
@@ -289,7 +289,6 @@ static void butterfly_attach(struct parport *p) | |||
289 | pr_debug("%s: dataflash at %s\n", p->name, | 289 | pr_debug("%s: dataflash at %s\n", p->name, |
290 | dev_name(&pp->dataflash->dev)); | 290 | dev_name(&pp->dataflash->dev)); |
291 | 291 | ||
292 | // dev_info(_what?_, ...) | ||
293 | pr_info("%s: AVR Butterfly\n", p->name); | 292 | pr_info("%s: AVR Butterfly\n", p->name); |
294 | butterfly = pp; | 293 | butterfly = pp; |
295 | return; | 294 | return; |
diff --git a/drivers/spi/spi-clps711x.c b/drivers/spi/spi-clps711x.c index 5655acf55bfe..6f03d7e6435d 100644 --- a/drivers/spi/spi-clps711x.c +++ b/drivers/spi/spi-clps711x.c | |||
@@ -105,7 +105,7 @@ static int spi_clps711x_transfer_one_message(struct spi_master *master, | |||
105 | 105 | ||
106 | gpio_set_value(cs, !!(msg->spi->mode & SPI_CS_HIGH)); | 106 | gpio_set_value(cs, !!(msg->spi->mode & SPI_CS_HIGH)); |
107 | 107 | ||
108 | INIT_COMPLETION(hw->done); | 108 | reinit_completion(&hw->done); |
109 | 109 | ||
110 | hw->count = 0; | 110 | hw->count = 0; |
111 | hw->len = xfer->len; | 111 | hw->len = xfer->len; |
@@ -226,11 +226,10 @@ static int spi_clps711x_probe(struct platform_device *pdev) | |||
226 | dev_name(&pdev->dev), hw); | 226 | dev_name(&pdev->dev), hw); |
227 | if (ret) { | 227 | if (ret) { |
228 | dev_err(&pdev->dev, "Can't request IRQ\n"); | 228 | dev_err(&pdev->dev, "Can't request IRQ\n"); |
229 | clk_put(hw->spi_clk); | 229 | goto err_out; |
230 | goto clk_out; | ||
231 | } | 230 | } |
232 | 231 | ||
233 | ret = spi_register_master(master); | 232 | ret = devm_spi_register_master(&pdev->dev, master); |
234 | if (!ret) { | 233 | if (!ret) { |
235 | dev_info(&pdev->dev, | 234 | dev_info(&pdev->dev, |
236 | "SPI bus driver initialized. Master clock %u Hz\n", | 235 | "SPI bus driver initialized. Master clock %u Hz\n", |
@@ -240,14 +239,12 @@ static int spi_clps711x_probe(struct platform_device *pdev) | |||
240 | 239 | ||
241 | dev_err(&pdev->dev, "Failed to register master\n"); | 240 | dev_err(&pdev->dev, "Failed to register master\n"); |
242 | 241 | ||
243 | clk_out: | ||
244 | err_out: | 242 | err_out: |
245 | while (--i >= 0) | 243 | while (--i >= 0) |
246 | if (gpio_is_valid(hw->chipselect[i])) | 244 | if (gpio_is_valid(hw->chipselect[i])) |
247 | gpio_free(hw->chipselect[i]); | 245 | gpio_free(hw->chipselect[i]); |
248 | 246 | ||
249 | spi_master_put(master); | 247 | spi_master_put(master); |
250 | kfree(master); | ||
251 | 248 | ||
252 | return ret; | 249 | return ret; |
253 | } | 250 | } |
@@ -262,9 +259,6 @@ static int spi_clps711x_remove(struct platform_device *pdev) | |||
262 | if (gpio_is_valid(hw->chipselect[i])) | 259 | if (gpio_is_valid(hw->chipselect[i])) |
263 | gpio_free(hw->chipselect[i]); | 260 | gpio_free(hw->chipselect[i]); |
264 | 261 | ||
265 | spi_unregister_master(master); | ||
266 | kfree(master); | ||
267 | |||
268 | return 0; | 262 | return 0; |
269 | } | 263 | } |
270 | 264 | ||
diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c index 8fbfe2483ffd..50b2d88c8190 100644 --- a/drivers/spi/spi-davinci.c +++ b/drivers/spi/spi-davinci.c | |||
@@ -279,7 +279,8 @@ static int davinci_spi_setup_transfer(struct spi_device *spi, | |||
279 | struct davinci_spi *dspi; | 279 | struct davinci_spi *dspi; |
280 | struct davinci_spi_config *spicfg; | 280 | struct davinci_spi_config *spicfg; |
281 | u8 bits_per_word = 0; | 281 | u8 bits_per_word = 0; |
282 | u32 hz = 0, spifmt = 0, prescale = 0; | 282 | u32 hz = 0, spifmt = 0; |
283 | int prescale; | ||
283 | 284 | ||
284 | dspi = spi_master_get_devdata(spi->master); | 285 | dspi = spi_master_get_devdata(spi->master); |
285 | spicfg = (struct davinci_spi_config *)spi->controller_data; | 286 | spicfg = (struct davinci_spi_config *)spi->controller_data; |
@@ -553,7 +554,7 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t) | |||
553 | clear_io_bits(dspi->base + SPIGCR1, SPIGCR1_POWERDOWN_MASK); | 554 | clear_io_bits(dspi->base + SPIGCR1, SPIGCR1_POWERDOWN_MASK); |
554 | set_io_bits(dspi->base + SPIGCR1, SPIGCR1_SPIENA_MASK); | 555 | set_io_bits(dspi->base + SPIGCR1, SPIGCR1_SPIENA_MASK); |
555 | 556 | ||
556 | INIT_COMPLETION(dspi->done); | 557 | reinit_completion(&dspi->done); |
557 | 558 | ||
558 | if (spicfg->io_type == SPI_IO_TYPE_INTR) | 559 | if (spicfg->io_type == SPI_IO_TYPE_INTR) |
559 | set_io_bits(dspi->base + SPIINT, SPIINT_MASKINT); | 560 | set_io_bits(dspi->base + SPIINT, SPIINT_MASKINT); |
@@ -916,7 +917,7 @@ static int davinci_spi_probe(struct platform_device *pdev) | |||
916 | if (ret) | 917 | if (ret) |
917 | goto unmap_io; | 918 | goto unmap_io; |
918 | 919 | ||
919 | dspi->bitbang.master = spi_master_get(master); | 920 | dspi->bitbang.master = master; |
920 | if (dspi->bitbang.master == NULL) { | 921 | if (dspi->bitbang.master == NULL) { |
921 | ret = -ENODEV; | 922 | ret = -ENODEV; |
922 | goto irq_free; | 923 | goto irq_free; |
@@ -925,7 +926,7 @@ static int davinci_spi_probe(struct platform_device *pdev) | |||
925 | dspi->clk = clk_get(&pdev->dev, NULL); | 926 | dspi->clk = clk_get(&pdev->dev, NULL); |
926 | if (IS_ERR(dspi->clk)) { | 927 | if (IS_ERR(dspi->clk)) { |
927 | ret = -ENODEV; | 928 | ret = -ENODEV; |
928 | goto put_master; | 929 | goto irq_free; |
929 | } | 930 | } |
930 | clk_prepare_enable(dspi->clk); | 931 | clk_prepare_enable(dspi->clk); |
931 | 932 | ||
@@ -1015,8 +1016,6 @@ free_dma: | |||
1015 | free_clk: | 1016 | free_clk: |
1016 | clk_disable_unprepare(dspi->clk); | 1017 | clk_disable_unprepare(dspi->clk); |
1017 | clk_put(dspi->clk); | 1018 | clk_put(dspi->clk); |
1018 | put_master: | ||
1019 | spi_master_put(master); | ||
1020 | irq_free: | 1019 | irq_free: |
1021 | free_irq(dspi->irq, dspi); | 1020 | free_irq(dspi->irq, dspi); |
1022 | unmap_io: | 1021 | unmap_io: |
@@ -1024,7 +1023,7 @@ unmap_io: | |||
1024 | release_region: | 1023 | release_region: |
1025 | release_mem_region(dspi->pbase, resource_size(r)); | 1024 | release_mem_region(dspi->pbase, resource_size(r)); |
1026 | free_master: | 1025 | free_master: |
1027 | kfree(master); | 1026 | spi_master_put(master); |
1028 | err: | 1027 | err: |
1029 | return ret; | 1028 | return ret; |
1030 | } | 1029 | } |
@@ -1051,11 +1050,11 @@ static int davinci_spi_remove(struct platform_device *pdev) | |||
1051 | 1050 | ||
1052 | clk_disable_unprepare(dspi->clk); | 1051 | clk_disable_unprepare(dspi->clk); |
1053 | clk_put(dspi->clk); | 1052 | clk_put(dspi->clk); |
1054 | spi_master_put(master); | ||
1055 | free_irq(dspi->irq, dspi); | 1053 | free_irq(dspi->irq, dspi); |
1056 | iounmap(dspi->base); | 1054 | iounmap(dspi->base); |
1057 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1055 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1058 | release_mem_region(dspi->pbase, resource_size(r)); | 1056 | release_mem_region(dspi->pbase, resource_size(r)); |
1057 | spi_master_put(master); | ||
1059 | 1058 | ||
1060 | return 0; | 1059 | return 0; |
1061 | } | 1060 | } |
diff --git a/drivers/spi/spi-dw-mid.c b/drivers/spi/spi-dw-mid.c index b9f0192758d6..6d207afec8cb 100644 --- a/drivers/spi/spi-dw-mid.c +++ b/drivers/spi/spi-dw-mid.c | |||
@@ -150,7 +150,7 @@ static int mid_spi_dma_transfer(struct dw_spi *dws, int cs_change) | |||
150 | &dws->tx_sgl, | 150 | &dws->tx_sgl, |
151 | 1, | 151 | 1, |
152 | DMA_MEM_TO_DEV, | 152 | DMA_MEM_TO_DEV, |
153 | DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_DEST_UNMAP); | 153 | DMA_PREP_INTERRUPT); |
154 | txdesc->callback = dw_spi_dma_done; | 154 | txdesc->callback = dw_spi_dma_done; |
155 | txdesc->callback_param = dws; | 155 | txdesc->callback_param = dws; |
156 | 156 | ||
@@ -173,7 +173,7 @@ static int mid_spi_dma_transfer(struct dw_spi *dws, int cs_change) | |||
173 | &dws->rx_sgl, | 173 | &dws->rx_sgl, |
174 | 1, | 174 | 1, |
175 | DMA_DEV_TO_MEM, | 175 | DMA_DEV_TO_MEM, |
176 | DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_DEST_UNMAP); | 176 | DMA_PREP_INTERRUPT); |
177 | rxdesc->callback = dw_spi_dma_done; | 177 | rxdesc->callback = dw_spi_dma_done; |
178 | rxdesc->callback_param = dws; | 178 | rxdesc->callback_param = dws; |
179 | 179 | ||
diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c index 4aa8be865cc0..168c620947f4 100644 --- a/drivers/spi/spi-dw-mmio.c +++ b/drivers/spi/spi-dw-mmio.c | |||
@@ -74,7 +74,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev) | |||
74 | dwsmmio->clk = clk_get(&pdev->dev, NULL); | 74 | dwsmmio->clk = clk_get(&pdev->dev, NULL); |
75 | if (IS_ERR(dwsmmio->clk)) { | 75 | if (IS_ERR(dwsmmio->clk)) { |
76 | ret = PTR_ERR(dwsmmio->clk); | 76 | ret = PTR_ERR(dwsmmio->clk); |
77 | goto err_irq; | 77 | goto err_unmap; |
78 | } | 78 | } |
79 | clk_enable(dwsmmio->clk); | 79 | clk_enable(dwsmmio->clk); |
80 | 80 | ||
@@ -94,8 +94,6 @@ err_clk: | |||
94 | clk_disable(dwsmmio->clk); | 94 | clk_disable(dwsmmio->clk); |
95 | clk_put(dwsmmio->clk); | 95 | clk_put(dwsmmio->clk); |
96 | dwsmmio->clk = NULL; | 96 | dwsmmio->clk = NULL; |
97 | err_irq: | ||
98 | free_irq(dws->irq, dws); | ||
99 | err_unmap: | 97 | err_unmap: |
100 | iounmap(dws->regs); | 98 | iounmap(dws->regs); |
101 | err_release_reg: | 99 | err_release_reg: |
@@ -115,7 +113,6 @@ static int dw_spi_mmio_remove(struct platform_device *pdev) | |||
115 | clk_put(dwsmmio->clk); | 113 | clk_put(dwsmmio->clk); |
116 | dwsmmio->clk = NULL; | 114 | dwsmmio->clk = NULL; |
117 | 115 | ||
118 | free_irq(dwsmmio->dws.irq, &dwsmmio->dws); | ||
119 | dw_spi_remove_host(&dwsmmio->dws); | 116 | dw_spi_remove_host(&dwsmmio->dws); |
120 | iounmap(dwsmmio->dws.regs); | 117 | iounmap(dwsmmio->dws.regs); |
121 | kfree(dwsmmio); | 118 | kfree(dwsmmio); |
diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c index 6055c8d9fdd7..66fa9955ea14 100644 --- a/drivers/spi/spi-dw-pci.c +++ b/drivers/spi/spi-dw-pci.c | |||
@@ -40,7 +40,7 @@ static int spi_pci_probe(struct pci_dev *pdev, | |||
40 | int pci_bar = 0; | 40 | int pci_bar = 0; |
41 | int ret; | 41 | int ret; |
42 | 42 | ||
43 | printk(KERN_INFO "DW: found PCI SPI controller(ID: %04x:%04x)\n", | 43 | dev_info(&pdev->dev, "found PCI SPI controller(ID: %04x:%04x)\n", |
44 | pdev->vendor, pdev->device); | 44 | pdev->vendor, pdev->device); |
45 | 45 | ||
46 | ret = pci_enable_device(pdev); | 46 | ret = pci_enable_device(pdev); |
@@ -109,7 +109,6 @@ static void spi_pci_remove(struct pci_dev *pdev) | |||
109 | { | 109 | { |
110 | struct dw_spi_pci *dwpci = pci_get_drvdata(pdev); | 110 | struct dw_spi_pci *dwpci = pci_get_drvdata(pdev); |
111 | 111 | ||
112 | pci_set_drvdata(pdev, NULL); | ||
113 | dw_spi_remove_host(&dwpci->dws); | 112 | dw_spi_remove_host(&dwpci->dws); |
114 | iounmap(dwpci->dws.regs); | 113 | iounmap(dwpci->dws.regs); |
115 | pci_release_region(pdev, 0); | 114 | pci_release_region(pdev, 0); |
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c index 79c958e49f61..b897c4adb39d 100644 --- a/drivers/spi/spi-dw.c +++ b/drivers/spi/spi-dw.c | |||
@@ -870,8 +870,8 @@ void dw_spi_remove_host(struct dw_spi *dws) | |||
870 | /* Remove the queue */ | 870 | /* Remove the queue */ |
871 | status = destroy_queue(dws); | 871 | status = destroy_queue(dws); |
872 | if (status != 0) | 872 | if (status != 0) |
873 | dev_err(&dws->master->dev, "dw_spi_remove: workqueue will not " | 873 | dev_err(&dws->master->dev, |
874 | "complete, message memory not freed\n"); | 874 | "dw_spi_remove: workqueue will not complete, message memory not freed\n"); |
875 | 875 | ||
876 | if (dws->dma_ops && dws->dma_ops->dma_exit) | 876 | if (dws->dma_ops && dws->dma_ops->dma_exit) |
877 | dws->dma_ops->dma_exit(dws); | 877 | dws->dma_ops->dma_exit(dws); |
diff --git a/drivers/spi/spi-efm32.c b/drivers/spi/spi-efm32.c index 7d84418a01d8..d4d3cc534792 100644 --- a/drivers/spi/spi-efm32.c +++ b/drivers/spi/spi-efm32.c | |||
@@ -280,10 +280,6 @@ static irqreturn_t efm32_spi_txirq(int irq, void *data) | |||
280 | return IRQ_HANDLED; | 280 | return IRQ_HANDLED; |
281 | } | 281 | } |
282 | 282 | ||
283 | static const struct efm32_spi_pdata efm32_spi_pdata_default = { | ||
284 | .location = 1, | ||
285 | }; | ||
286 | |||
287 | static u32 efm32_spi_get_configured_location(struct efm32_spi_ddata *ddata) | 283 | static u32 efm32_spi_get_configured_location(struct efm32_spi_ddata *ddata) |
288 | { | 284 | { |
289 | u32 reg = efm32_spi_read32(ddata, REG_ROUTE); | 285 | u32 reg = efm32_spi_read32(ddata, REG_ROUTE); |
@@ -347,7 +343,7 @@ static int efm32_spi_probe(struct platform_device *pdev) | |||
347 | 343 | ||
348 | ddata = spi_master_get_devdata(master); | 344 | ddata = spi_master_get_devdata(master); |
349 | 345 | ||
350 | ddata->bitbang.master = spi_master_get(master); | 346 | ddata->bitbang.master = master; |
351 | ddata->bitbang.chipselect = efm32_spi_chipselect; | 347 | ddata->bitbang.chipselect = efm32_spi_chipselect; |
352 | ddata->bitbang.setup_transfer = efm32_spi_setup_transfer; | 348 | ddata->bitbang.setup_transfer = efm32_spi_setup_transfer; |
353 | ddata->bitbang.txrx_bufs = efm32_spi_txrx_bufs; | 349 | ddata->bitbang.txrx_bufs = efm32_spi_txrx_bufs; |
@@ -387,7 +383,7 @@ static int efm32_spi_probe(struct platform_device *pdev) | |||
387 | goto err; | 383 | goto err; |
388 | } | 384 | } |
389 | 385 | ||
390 | if (resource_size(res) < 60) { | 386 | if (resource_size(res) < 0x60) { |
391 | ret = -EINVAL; | 387 | ret = -EINVAL; |
392 | dev_err(&pdev->dev, "memory resource too small\n"); | 388 | dev_err(&pdev->dev, "memory resource too small\n"); |
393 | goto err; | 389 | goto err; |
@@ -467,7 +463,6 @@ err_disable_clk: | |||
467 | clk_disable_unprepare(ddata->clk); | 463 | clk_disable_unprepare(ddata->clk); |
468 | err: | 464 | err: |
469 | spi_master_put(master); | 465 | spi_master_put(master); |
470 | kfree(master); | ||
471 | } | 466 | } |
472 | 467 | ||
473 | return ret; | 468 | return ret; |
@@ -478,13 +473,14 @@ static int efm32_spi_remove(struct platform_device *pdev) | |||
478 | struct spi_master *master = platform_get_drvdata(pdev); | 473 | struct spi_master *master = platform_get_drvdata(pdev); |
479 | struct efm32_spi_ddata *ddata = spi_master_get_devdata(master); | 474 | struct efm32_spi_ddata *ddata = spi_master_get_devdata(master); |
480 | 475 | ||
476 | spi_bitbang_stop(&ddata->bitbang); | ||
477 | |||
481 | efm32_spi_write32(ddata, 0, REG_IEN); | 478 | efm32_spi_write32(ddata, 0, REG_IEN); |
482 | 479 | ||
483 | free_irq(ddata->txirq, ddata); | 480 | free_irq(ddata->txirq, ddata); |
484 | free_irq(ddata->rxirq, ddata); | 481 | free_irq(ddata->rxirq, ddata); |
485 | clk_disable_unprepare(ddata->clk); | 482 | clk_disable_unprepare(ddata->clk); |
486 | spi_master_put(master); | 483 | spi_master_put(master); |
487 | kfree(master); | ||
488 | 484 | ||
489 | return 0; | 485 | return 0; |
490 | } | 486 | } |
diff --git a/drivers/spi/spi-ep93xx.c b/drivers/spi/spi-ep93xx.c index d22c00a227b6..1bfaed6e4073 100644 --- a/drivers/spi/spi-ep93xx.c +++ b/drivers/spi/spi-ep93xx.c | |||
@@ -330,7 +330,7 @@ static int ep93xx_spi_chip_setup(const struct ep93xx_spi *espi, | |||
330 | 330 | ||
331 | dev_dbg(&espi->pdev->dev, "setup: mode %d, cpsr %d, scr %d, dss %d\n", | 331 | dev_dbg(&espi->pdev->dev, "setup: mode %d, cpsr %d, scr %d, dss %d\n", |
332 | chip->spi->mode, div_cpsr, div_scr, dss); | 332 | chip->spi->mode, div_cpsr, div_scr, dss); |
333 | dev_dbg(&espi->pdev->dev, "setup: cr0 %#x", cr0); | 333 | dev_dbg(&espi->pdev->dev, "setup: cr0 %#x\n", cr0); |
334 | 334 | ||
335 | ep93xx_spi_write_u8(espi, SSPCPSR, div_cpsr); | 335 | ep93xx_spi_write_u8(espi, SSPCPSR, div_cpsr); |
336 | ep93xx_spi_write_u16(espi, SSPCR0, cr0); | 336 | ep93xx_spi_write_u16(espi, SSPCR0, cr0); |
@@ -509,7 +509,7 @@ ep93xx_spi_dma_prepare(struct ep93xx_spi *espi, enum dma_transfer_direction dir) | |||
509 | } | 509 | } |
510 | 510 | ||
511 | if (WARN_ON(len)) { | 511 | if (WARN_ON(len)) { |
512 | dev_warn(&espi->pdev->dev, "len = %zu expected 0!", len); | 512 | dev_warn(&espi->pdev->dev, "len = %zu expected 0!\n", len); |
513 | return ERR_PTR(-EINVAL); | 513 | return ERR_PTR(-EINVAL); |
514 | } | 514 | } |
515 | 515 | ||
@@ -942,7 +942,7 @@ static int ep93xx_spi_probe(struct platform_device *pdev) | |||
942 | /* make sure that the hardware is disabled */ | 942 | /* make sure that the hardware is disabled */ |
943 | ep93xx_spi_write_u8(espi, SSPCR1, 0); | 943 | ep93xx_spi_write_u8(espi, SSPCR1, 0); |
944 | 944 | ||
945 | error = spi_register_master(master); | 945 | error = devm_spi_register_master(&pdev->dev, master); |
946 | if (error) { | 946 | if (error) { |
947 | dev_err(&pdev->dev, "failed to register SPI master\n"); | 947 | dev_err(&pdev->dev, "failed to register SPI master\n"); |
948 | goto fail_free_dma; | 948 | goto fail_free_dma; |
@@ -968,7 +968,6 @@ static int ep93xx_spi_remove(struct platform_device *pdev) | |||
968 | 968 | ||
969 | ep93xx_spi_release_dma(espi); | 969 | ep93xx_spi_release_dma(espi); |
970 | 970 | ||
971 | spi_unregister_master(master); | ||
972 | return 0; | 971 | return 0; |
973 | } | 972 | } |
974 | 973 | ||
diff --git a/drivers/spi/spi-fsl-cpm.c b/drivers/spi/spi-fsl-cpm.c index 07971e3fe58b..54b06376f03c 100644 --- a/drivers/spi/spi-fsl-cpm.c +++ b/drivers/spi/spi-fsl-cpm.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/spi/spi.h> | 20 | #include <linux/spi/spi.h> |
21 | #include <linux/fsl_devices.h> | 21 | #include <linux/fsl_devices.h> |
22 | #include <linux/dma-mapping.h> | 22 | #include <linux/dma-mapping.h> |
23 | #include <linux/of_address.h> | ||
23 | #include <asm/cpm.h> | 24 | #include <asm/cpm.h> |
24 | #include <asm/qe.h> | 25 | #include <asm/qe.h> |
25 | 26 | ||
@@ -299,7 +300,7 @@ int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi) | |||
299 | 300 | ||
300 | switch (mspi->subblock) { | 301 | switch (mspi->subblock) { |
301 | default: | 302 | default: |
302 | dev_warn(dev, "cell-index unspecified, assuming SPI1"); | 303 | dev_warn(dev, "cell-index unspecified, assuming SPI1\n"); |
303 | /* fall through */ | 304 | /* fall through */ |
304 | case 0: | 305 | case 0: |
305 | mspi->subblock = QE_CR_SUBBLOCK_SPI1; | 306 | mspi->subblock = QE_CR_SUBBLOCK_SPI1; |
diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 6cd07d13ecab..8641b03bdd7a 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c | |||
@@ -108,7 +108,7 @@ struct fsl_dspi { | |||
108 | struct spi_bitbang bitbang; | 108 | struct spi_bitbang bitbang; |
109 | struct platform_device *pdev; | 109 | struct platform_device *pdev; |
110 | 110 | ||
111 | void *base; | 111 | void __iomem *base; |
112 | int irq; | 112 | int irq; |
113 | struct clk *clk; | 113 | struct clk *clk; |
114 | 114 | ||
@@ -165,7 +165,7 @@ static void hz_to_spi_baud(char *pbr, char *br, int speed_hz, | |||
165 | } | 165 | } |
166 | } | 166 | } |
167 | 167 | ||
168 | pr_warn("Can not find valid buad rate,speed_hz is %d,clkrate is %ld\ | 168 | pr_warn("Can not find valid baud rate,speed_hz is %d,clkrate is %ld\ |
169 | ,we use the max prescaler value.\n", speed_hz, clkrate); | 169 | ,we use the max prescaler value.\n", speed_hz, clkrate); |
170 | *pbr = ARRAY_SIZE(pbr_tbl) - 1; | 170 | *pbr = ARRAY_SIZE(pbr_tbl) - 1; |
171 | *br = ARRAY_SIZE(brs) - 1; | 171 | *br = ARRAY_SIZE(brs) - 1; |
@@ -450,7 +450,7 @@ static int dspi_probe(struct platform_device *pdev) | |||
450 | 450 | ||
451 | dspi = spi_master_get_devdata(master); | 451 | dspi = spi_master_get_devdata(master); |
452 | dspi->pdev = pdev; | 452 | dspi->pdev = pdev; |
453 | dspi->bitbang.master = spi_master_get(master); | 453 | dspi->bitbang.master = master; |
454 | dspi->bitbang.chipselect = dspi_chipselect; | 454 | dspi->bitbang.chipselect = dspi_chipselect; |
455 | dspi->bitbang.setup_transfer = dspi_setup_transfer; | 455 | dspi->bitbang.setup_transfer = dspi_setup_transfer; |
456 | dspi->bitbang.txrx_bufs = dspi_txrx_transfer; | 456 | dspi->bitbang.txrx_bufs = dspi_txrx_transfer; |
@@ -476,15 +476,9 @@ static int dspi_probe(struct platform_device *pdev) | |||
476 | master->bus_num = bus_num; | 476 | master->bus_num = bus_num; |
477 | 477 | ||
478 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 478 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
479 | if (!res) { | ||
480 | dev_err(&pdev->dev, "can't get platform resource\n"); | ||
481 | ret = -EINVAL; | ||
482 | goto out_master_put; | ||
483 | } | ||
484 | |||
485 | dspi->base = devm_ioremap_resource(&pdev->dev, res); | 479 | dspi->base = devm_ioremap_resource(&pdev->dev, res); |
486 | if (!dspi->base) { | 480 | if (IS_ERR(dspi->base)) { |
487 | ret = -EINVAL; | 481 | ret = PTR_ERR(dspi->base); |
488 | goto out_master_put; | 482 | goto out_master_put; |
489 | } | 483 | } |
490 | 484 | ||
@@ -526,7 +520,6 @@ out_clk_put: | |||
526 | clk_disable_unprepare(dspi->clk); | 520 | clk_disable_unprepare(dspi->clk); |
527 | out_master_put: | 521 | out_master_put: |
528 | spi_master_put(master); | 522 | spi_master_put(master); |
529 | platform_set_drvdata(pdev, NULL); | ||
530 | 523 | ||
531 | return ret; | 524 | return ret; |
532 | } | 525 | } |
@@ -537,6 +530,7 @@ static int dspi_remove(struct platform_device *pdev) | |||
537 | 530 | ||
538 | /* Disconnect from the SPI framework */ | 531 | /* Disconnect from the SPI framework */ |
539 | spi_bitbang_stop(&dspi->bitbang); | 532 | spi_bitbang_stop(&dspi->bitbang); |
533 | clk_disable_unprepare(dspi->clk); | ||
540 | spi_master_put(dspi->bitbang.master); | 534 | spi_master_put(dspi->bitbang.master); |
541 | 535 | ||
542 | return 0; | 536 | return 0; |
@@ -553,5 +547,5 @@ static struct platform_driver fsl_dspi_driver = { | |||
553 | module_platform_driver(fsl_dspi_driver); | 547 | module_platform_driver(fsl_dspi_driver); |
554 | 548 | ||
555 | MODULE_DESCRIPTION("Freescale DSPI Controller Driver"); | 549 | MODULE_DESCRIPTION("Freescale DSPI Controller Driver"); |
556 | MODULE_LICENSE("GPL v2"); | 550 | MODULE_LICENSE("GPL"); |
557 | MODULE_ALIAS("platform:" DRIVER_NAME); | 551 | MODULE_ALIAS("platform:" DRIVER_NAME); |
diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index b8f1103fe28e..80d8f40f7e05 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c | |||
@@ -16,6 +16,8 @@ | |||
16 | #include <linux/fsl_devices.h> | 16 | #include <linux/fsl_devices.h> |
17 | #include <linux/mm.h> | 17 | #include <linux/mm.h> |
18 | #include <linux/of.h> | 18 | #include <linux/of.h> |
19 | #include <linux/of_address.h> | ||
20 | #include <linux/of_irq.h> | ||
19 | #include <linux/of_platform.h> | 21 | #include <linux/of_platform.h> |
20 | #include <linux/interrupt.h> | 22 | #include <linux/interrupt.h> |
21 | #include <linux/err.h> | 23 | #include <linux/err.h> |
@@ -230,7 +232,7 @@ static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t) | |||
230 | mpc8xxx_spi->tx = t->tx_buf; | 232 | mpc8xxx_spi->tx = t->tx_buf; |
231 | mpc8xxx_spi->rx = t->rx_buf; | 233 | mpc8xxx_spi->rx = t->rx_buf; |
232 | 234 | ||
233 | INIT_COMPLETION(mpc8xxx_spi->done); | 235 | reinit_completion(&mpc8xxx_spi->done); |
234 | 236 | ||
235 | /* Set SPCOM[CS] and SPCOM[TRANLEN] field */ | 237 | /* Set SPCOM[CS] and SPCOM[TRANLEN] field */ |
236 | if ((t->len - 1) > SPCOM_TRANLEN_MAX) { | 238 | if ((t->len - 1) > SPCOM_TRANLEN_MAX) { |
@@ -289,8 +291,8 @@ static void fsl_espi_do_trans(struct spi_message *m, | |||
289 | if ((first->bits_per_word != t->bits_per_word) || | 291 | if ((first->bits_per_word != t->bits_per_word) || |
290 | (first->speed_hz != t->speed_hz)) { | 292 | (first->speed_hz != t->speed_hz)) { |
291 | espi_trans->status = -EINVAL; | 293 | espi_trans->status = -EINVAL; |
292 | dev_err(mspi->dev, "bits_per_word/speed_hz should be" | 294 | dev_err(mspi->dev, |
293 | " same for the same SPI transfer\n"); | 295 | "bits_per_word/speed_hz should be same for the same SPI transfer\n"); |
294 | return; | 296 | return; |
295 | } | 297 | } |
296 | 298 | ||
@@ -687,7 +689,7 @@ static int of_fsl_espi_probe(struct platform_device *ofdev) | |||
687 | struct device_node *np = ofdev->dev.of_node; | 689 | struct device_node *np = ofdev->dev.of_node; |
688 | struct spi_master *master; | 690 | struct spi_master *master; |
689 | struct resource mem; | 691 | struct resource mem; |
690 | struct resource irq; | 692 | unsigned int irq; |
691 | int ret = -ENOMEM; | 693 | int ret = -ENOMEM; |
692 | 694 | ||
693 | ret = of_mpc8xxx_spi_probe(ofdev); | 695 | ret = of_mpc8xxx_spi_probe(ofdev); |
@@ -702,13 +704,13 @@ static int of_fsl_espi_probe(struct platform_device *ofdev) | |||
702 | if (ret) | 704 | if (ret) |
703 | goto err; | 705 | goto err; |
704 | 706 | ||
705 | ret = of_irq_to_resource(np, 0, &irq); | 707 | irq = irq_of_parse_and_map(np, 0); |
706 | if (!ret) { | 708 | if (!ret) { |
707 | ret = -EINVAL; | 709 | ret = -EINVAL; |
708 | goto err; | 710 | goto err; |
709 | } | 711 | } |
710 | 712 | ||
711 | master = fsl_espi_probe(dev, &mem, irq.start); | 713 | master = fsl_espi_probe(dev, &mem, irq); |
712 | if (IS_ERR(master)) { | 714 | if (IS_ERR(master)) { |
713 | ret = PTR_ERR(master); | 715 | ret = PTR_ERR(master); |
714 | goto err; | 716 | goto err; |
diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index 2129fcd1c31b..119f7af94537 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c | |||
@@ -339,7 +339,7 @@ static int fsl_spi_bufs(struct spi_device *spi, struct spi_transfer *t, | |||
339 | mpc8xxx_spi->tx = t->tx_buf; | 339 | mpc8xxx_spi->tx = t->tx_buf; |
340 | mpc8xxx_spi->rx = t->rx_buf; | 340 | mpc8xxx_spi->rx = t->rx_buf; |
341 | 341 | ||
342 | INIT_COMPLETION(mpc8xxx_spi->done); | 342 | reinit_completion(&mpc8xxx_spi->done); |
343 | 343 | ||
344 | if (mpc8xxx_spi->flags & SPI_CPM_MODE) | 344 | if (mpc8xxx_spi->flags & SPI_CPM_MODE) |
345 | ret = fsl_spi_cpm_bufs(mpc8xxx_spi, t, is_dma_mapped); | 345 | ret = fsl_spi_cpm_bufs(mpc8xxx_spi, t, is_dma_mapped); |
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 68b69fec13a9..3fb09f981980 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/init.h> | 22 | #include <linux/init.h> |
23 | #include <linux/platform_device.h> | 23 | #include <linux/platform_device.h> |
24 | #include <linux/gpio.h> | 24 | #include <linux/gpio.h> |
25 | #include <linux/of.h> | ||
25 | #include <linux/of_device.h> | 26 | #include <linux/of_device.h> |
26 | #include <linux/of_gpio.h> | 27 | #include <linux/of_gpio.h> |
27 | 28 | ||
@@ -467,7 +468,7 @@ static int spi_gpio_probe(struct platform_device *pdev) | |||
467 | } | 468 | } |
468 | #endif | 469 | #endif |
469 | 470 | ||
470 | spi_gpio->bitbang.master = spi_master_get(master); | 471 | spi_gpio->bitbang.master = master; |
471 | spi_gpio->bitbang.chipselect = spi_gpio_chipselect; | 472 | spi_gpio->bitbang.chipselect = spi_gpio_chipselect; |
472 | 473 | ||
473 | if ((master_flags & (SPI_MASTER_NO_TX | SPI_MASTER_NO_RX)) == 0) { | 474 | if ((master_flags & (SPI_MASTER_NO_TX | SPI_MASTER_NO_RX)) == 0) { |
@@ -486,7 +487,6 @@ static int spi_gpio_probe(struct platform_device *pdev) | |||
486 | 487 | ||
487 | status = spi_bitbang_start(&spi_gpio->bitbang); | 488 | status = spi_bitbang_start(&spi_gpio->bitbang); |
488 | if (status < 0) { | 489 | if (status < 0) { |
489 | spi_master_put(spi_gpio->bitbang.master); | ||
490 | gpio_free: | 490 | gpio_free: |
491 | if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) | 491 | if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) |
492 | gpio_free(SPI_MISO_GPIO); | 492 | gpio_free(SPI_MISO_GPIO); |
@@ -510,13 +510,13 @@ static int spi_gpio_remove(struct platform_device *pdev) | |||
510 | 510 | ||
511 | /* stop() unregisters child devices too */ | 511 | /* stop() unregisters child devices too */ |
512 | status = spi_bitbang_stop(&spi_gpio->bitbang); | 512 | status = spi_bitbang_stop(&spi_gpio->bitbang); |
513 | spi_master_put(spi_gpio->bitbang.master); | ||
514 | 513 | ||
515 | if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) | 514 | if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) |
516 | gpio_free(SPI_MISO_GPIO); | 515 | gpio_free(SPI_MISO_GPIO); |
517 | if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) | 516 | if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) |
518 | gpio_free(SPI_MOSI_GPIO); | 517 | gpio_free(SPI_MOSI_GPIO); |
519 | gpio_free(SPI_SCK_GPIO); | 518 | gpio_free(SPI_SCK_GPIO); |
519 | spi_master_put(spi_gpio->bitbang.master); | ||
520 | 520 | ||
521 | return status; | 521 | return status; |
522 | } | 522 | } |
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index 15323d8bd9cf..b80f2f70fef7 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c | |||
@@ -749,6 +749,35 @@ static void spi_imx_cleanup(struct spi_device *spi) | |||
749 | { | 749 | { |
750 | } | 750 | } |
751 | 751 | ||
752 | static int | ||
753 | spi_imx_prepare_message(struct spi_master *master, struct spi_message *msg) | ||
754 | { | ||
755 | struct spi_imx_data *spi_imx = spi_master_get_devdata(master); | ||
756 | int ret; | ||
757 | |||
758 | ret = clk_enable(spi_imx->clk_per); | ||
759 | if (ret) | ||
760 | return ret; | ||
761 | |||
762 | ret = clk_enable(spi_imx->clk_ipg); | ||
763 | if (ret) { | ||
764 | clk_disable(spi_imx->clk_per); | ||
765 | return ret; | ||
766 | } | ||
767 | |||
768 | return 0; | ||
769 | } | ||
770 | |||
771 | static int | ||
772 | spi_imx_unprepare_message(struct spi_master *master, struct spi_message *msg) | ||
773 | { | ||
774 | struct spi_imx_data *spi_imx = spi_master_get_devdata(master); | ||
775 | |||
776 | clk_disable(spi_imx->clk_ipg); | ||
777 | clk_disable(spi_imx->clk_per); | ||
778 | return 0; | ||
779 | } | ||
780 | |||
752 | static int spi_imx_probe(struct platform_device *pdev) | 781 | static int spi_imx_probe(struct platform_device *pdev) |
753 | { | 782 | { |
754 | struct device_node *np = pdev->dev.of_node; | 783 | struct device_node *np = pdev->dev.of_node; |
@@ -786,7 +815,7 @@ static int spi_imx_probe(struct platform_device *pdev) | |||
786 | master->num_chipselect = num_cs; | 815 | master->num_chipselect = num_cs; |
787 | 816 | ||
788 | spi_imx = spi_master_get_devdata(master); | 817 | spi_imx = spi_master_get_devdata(master); |
789 | spi_imx->bitbang.master = spi_master_get(master); | 818 | spi_imx->bitbang.master = master; |
790 | 819 | ||
791 | for (i = 0; i < master->num_chipselect; i++) { | 820 | for (i = 0; i < master->num_chipselect; i++) { |
792 | int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); | 821 | int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); |
@@ -810,6 +839,8 @@ static int spi_imx_probe(struct platform_device *pdev) | |||
810 | spi_imx->bitbang.txrx_bufs = spi_imx_transfer; | 839 | spi_imx->bitbang.txrx_bufs = spi_imx_transfer; |
811 | spi_imx->bitbang.master->setup = spi_imx_setup; | 840 | spi_imx->bitbang.master->setup = spi_imx_setup; |
812 | spi_imx->bitbang.master->cleanup = spi_imx_cleanup; | 841 | spi_imx->bitbang.master->cleanup = spi_imx_cleanup; |
842 | spi_imx->bitbang.master->prepare_message = spi_imx_prepare_message; | ||
843 | spi_imx->bitbang.master->unprepare_message = spi_imx_unprepare_message; | ||
813 | spi_imx->bitbang.master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; | 844 | spi_imx->bitbang.master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; |
814 | 845 | ||
815 | init_completion(&spi_imx->xfer_done); | 846 | init_completion(&spi_imx->xfer_done); |
@@ -872,6 +903,8 @@ static int spi_imx_probe(struct platform_device *pdev) | |||
872 | 903 | ||
873 | dev_info(&pdev->dev, "probed\n"); | 904 | dev_info(&pdev->dev, "probed\n"); |
874 | 905 | ||
906 | clk_disable(spi_imx->clk_ipg); | ||
907 | clk_disable(spi_imx->clk_per); | ||
875 | return ret; | 908 | return ret; |
876 | 909 | ||
877 | out_clk_put: | 910 | out_clk_put: |
diff --git a/drivers/spi/spi-lm70llp.c b/drivers/spi/spi-lm70llp.c index 0759b5db9883..41c5765be746 100644 --- a/drivers/spi/spi-lm70llp.c +++ b/drivers/spi/spi-lm70llp.c | |||
@@ -222,7 +222,7 @@ static void spi_lm70llp_attach(struct parport *p) | |||
222 | /* | 222 | /* |
223 | * SPI and bitbang hookup. | 223 | * SPI and bitbang hookup. |
224 | */ | 224 | */ |
225 | pp->bitbang.master = spi_master_get(master); | 225 | pp->bitbang.master = master; |
226 | pp->bitbang.chipselect = lm70_chipselect; | 226 | pp->bitbang.chipselect = lm70_chipselect; |
227 | pp->bitbang.txrx_word[SPI_MODE_0] = lm70_txrx; | 227 | pp->bitbang.txrx_word[SPI_MODE_0] = lm70_txrx; |
228 | pp->bitbang.flags = SPI_3WIRE; | 228 | pp->bitbang.flags = SPI_3WIRE; |
diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c index dbc5e999a1f5..87676587d783 100644 --- a/drivers/spi/spi-mpc512x-psc.c +++ b/drivers/spi/spi-mpc512x-psc.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/errno.h> | 20 | #include <linux/errno.h> |
21 | #include <linux/interrupt.h> | 21 | #include <linux/interrupt.h> |
22 | #include <linux/of_address.h> | 22 | #include <linux/of_address.h> |
23 | #include <linux/of_irq.h> | ||
23 | #include <linux/of_platform.h> | 24 | #include <linux/of_platform.h> |
24 | #include <linux/completion.h> | 25 | #include <linux/completion.h> |
25 | #include <linux/io.h> | 26 | #include <linux/io.h> |
@@ -166,7 +167,7 @@ static int mpc512x_psc_spi_transfer_rxtx(struct spi_device *spi, | |||
166 | } | 167 | } |
167 | 168 | ||
168 | /* have the ISR trigger when the TX FIFO is empty */ | 169 | /* have the ISR trigger when the TX FIFO is empty */ |
169 | INIT_COMPLETION(mps->txisrdone); | 170 | reinit_completion(&mps->txisrdone); |
170 | out_be32(&fifo->txisr, MPC512x_PSC_FIFO_EMPTY); | 171 | out_be32(&fifo->txisr, MPC512x_PSC_FIFO_EMPTY); |
171 | out_be32(&fifo->tximr, MPC512x_PSC_FIFO_EMPTY); | 172 | out_be32(&fifo->tximr, MPC512x_PSC_FIFO_EMPTY); |
172 | wait_for_completion(&mps->txisrdone); | 173 | wait_for_completion(&mps->txisrdone); |
@@ -522,8 +523,10 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, | |||
522 | psc_num = master->bus_num; | 523 | psc_num = master->bus_num; |
523 | snprintf(clk_name, sizeof(clk_name), "psc%d_mclk", psc_num); | 524 | snprintf(clk_name, sizeof(clk_name), "psc%d_mclk", psc_num); |
524 | clk = devm_clk_get(dev, clk_name); | 525 | clk = devm_clk_get(dev, clk_name); |
525 | if (IS_ERR(clk)) | 526 | if (IS_ERR(clk)) { |
527 | ret = PTR_ERR(clk); | ||
526 | goto free_irq; | 528 | goto free_irq; |
529 | } | ||
527 | ret = clk_prepare_enable(clk); | 530 | ret = clk_prepare_enable(clk); |
528 | if (ret) | 531 | if (ret) |
529 | goto free_irq; | 532 | goto free_irq; |
@@ -534,7 +537,7 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, | |||
534 | if (ret < 0) | 537 | if (ret < 0) |
535 | goto free_clock; | 538 | goto free_clock; |
536 | 539 | ||
537 | ret = spi_register_master(master); | 540 | ret = devm_spi_register_master(dev, master); |
538 | if (ret < 0) | 541 | if (ret < 0) |
539 | goto free_clock; | 542 | goto free_clock; |
540 | 543 | ||
@@ -554,15 +557,13 @@ free_master: | |||
554 | 557 | ||
555 | static int mpc512x_psc_spi_do_remove(struct device *dev) | 558 | static int mpc512x_psc_spi_do_remove(struct device *dev) |
556 | { | 559 | { |
557 | struct spi_master *master = spi_master_get(dev_get_drvdata(dev)); | 560 | struct spi_master *master = dev_get_drvdata(dev); |
558 | struct mpc512x_psc_spi *mps = spi_master_get_devdata(master); | 561 | struct mpc512x_psc_spi *mps = spi_master_get_devdata(master); |
559 | 562 | ||
560 | spi_unregister_master(master); | ||
561 | clk_disable_unprepare(mps->clk_mclk); | 563 | clk_disable_unprepare(mps->clk_mclk); |
562 | free_irq(mps->irq, mps); | 564 | free_irq(mps->irq, mps); |
563 | if (mps->psc) | 565 | if (mps->psc) |
564 | iounmap(mps->psc); | 566 | iounmap(mps->psc); |
565 | spi_master_put(master); | ||
566 | 567 | ||
567 | return 0; | 568 | return 0; |
568 | } | 569 | } |
diff --git a/drivers/spi/spi-mpc52xx-psc.c b/drivers/spi/spi-mpc52xx-psc.c index 6e925dc34396..00ba910ab302 100644 --- a/drivers/spi/spi-mpc52xx-psc.c +++ b/drivers/spi/spi-mpc52xx-psc.c | |||
@@ -383,8 +383,8 @@ static int mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr, | |||
383 | 383 | ||
384 | mps->irq = irq; | 384 | mps->irq = irq; |
385 | if (pdata == NULL) { | 385 | if (pdata == NULL) { |
386 | dev_warn(dev, "probe called without platform data, no " | 386 | dev_warn(dev, |
387 | "cs_control function will be called\n"); | 387 | "probe called without platform data, no cs_control function will be called\n"); |
388 | mps->cs_control = NULL; | 388 | mps->cs_control = NULL; |
389 | mps->sysclk = 0; | 389 | mps->sysclk = 0; |
390 | master->bus_num = bus_num; | 390 | master->bus_num = bus_num; |
diff --git a/drivers/spi/spi-mxs.c b/drivers/spi/spi-mxs.c index de7b1141b90f..3adebfa22e3d 100644 --- a/drivers/spi/spi-mxs.c +++ b/drivers/spi/spi-mxs.c | |||
@@ -57,34 +57,53 @@ | |||
57 | 57 | ||
58 | #define SG_MAXLEN 0xff00 | 58 | #define SG_MAXLEN 0xff00 |
59 | 59 | ||
60 | /* | ||
61 | * Flags for txrx functions. More efficient that using an argument register for | ||
62 | * each one. | ||
63 | */ | ||
64 | #define TXRX_WRITE (1<<0) /* This is a write */ | ||
65 | #define TXRX_DEASSERT_CS (1<<1) /* De-assert CS at end of txrx */ | ||
66 | |||
60 | struct mxs_spi { | 67 | struct mxs_spi { |
61 | struct mxs_ssp ssp; | 68 | struct mxs_ssp ssp; |
62 | struct completion c; | 69 | struct completion c; |
70 | unsigned int sck; /* Rate requested (vs actual) */ | ||
63 | }; | 71 | }; |
64 | 72 | ||
65 | static int mxs_spi_setup_transfer(struct spi_device *dev, | 73 | static int mxs_spi_setup_transfer(struct spi_device *dev, |
66 | struct spi_transfer *t) | 74 | const struct spi_transfer *t) |
67 | { | 75 | { |
68 | struct mxs_spi *spi = spi_master_get_devdata(dev->master); | 76 | struct mxs_spi *spi = spi_master_get_devdata(dev->master); |
69 | struct mxs_ssp *ssp = &spi->ssp; | 77 | struct mxs_ssp *ssp = &spi->ssp; |
70 | uint32_t hz = 0; | 78 | const unsigned int hz = min(dev->max_speed_hz, t->speed_hz); |
71 | 79 | ||
72 | hz = dev->max_speed_hz; | ||
73 | if (t && t->speed_hz) | ||
74 | hz = min(hz, t->speed_hz); | ||
75 | if (hz == 0) { | 80 | if (hz == 0) { |
76 | dev_err(&dev->dev, "Cannot continue with zero clock\n"); | 81 | dev_err(&dev->dev, "SPI clock rate of zero not allowed\n"); |
77 | return -EINVAL; | 82 | return -EINVAL; |
78 | } | 83 | } |
79 | 84 | ||
80 | mxs_ssp_set_clk_rate(ssp, hz); | 85 | if (hz != spi->sck) { |
86 | mxs_ssp_set_clk_rate(ssp, hz); | ||
87 | /* | ||
88 | * Save requested rate, hz, rather than the actual rate, | ||
89 | * ssp->clk_rate. Otherwise we would set the rate every trasfer | ||
90 | * when the actual rate is not quite the same as requested rate. | ||
91 | */ | ||
92 | spi->sck = hz; | ||
93 | /* | ||
94 | * Perhaps we should return an error if the actual clock is | ||
95 | * nowhere close to what was requested? | ||
96 | */ | ||
97 | } | ||
98 | |||
99 | writel(BM_SSP_CTRL0_LOCK_CS, | ||
100 | ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET); | ||
81 | 101 | ||
82 | writel(BF_SSP_CTRL1_SSP_MODE(BV_SSP_CTRL1_SSP_MODE__SPI) | | 102 | writel(BF_SSP_CTRL1_SSP_MODE(BV_SSP_CTRL1_SSP_MODE__SPI) | |
83 | BF_SSP_CTRL1_WORD_LENGTH | 103 | BF_SSP_CTRL1_WORD_LENGTH(BV_SSP_CTRL1_WORD_LENGTH__EIGHT_BITS) | |
84 | (BV_SSP_CTRL1_WORD_LENGTH__EIGHT_BITS) | | 104 | ((dev->mode & SPI_CPOL) ? BM_SSP_CTRL1_POLARITY : 0) | |
85 | ((dev->mode & SPI_CPOL) ? BM_SSP_CTRL1_POLARITY : 0) | | 105 | ((dev->mode & SPI_CPHA) ? BM_SSP_CTRL1_PHASE : 0), |
86 | ((dev->mode & SPI_CPHA) ? BM_SSP_CTRL1_PHASE : 0), | 106 | ssp->base + HW_SSP_CTRL1(ssp)); |
87 | ssp->base + HW_SSP_CTRL1(ssp)); | ||
88 | 107 | ||
89 | writel(0x0, ssp->base + HW_SSP_CMD0); | 108 | writel(0x0, ssp->base + HW_SSP_CMD0); |
90 | writel(0x0, ssp->base + HW_SSP_CMD1); | 109 | writel(0x0, ssp->base + HW_SSP_CMD1); |
@@ -94,26 +113,15 @@ static int mxs_spi_setup_transfer(struct spi_device *dev, | |||
94 | 113 | ||
95 | static int mxs_spi_setup(struct spi_device *dev) | 114 | static int mxs_spi_setup(struct spi_device *dev) |
96 | { | 115 | { |
97 | int err = 0; | ||
98 | |||
99 | if (!dev->bits_per_word) | 116 | if (!dev->bits_per_word) |
100 | dev->bits_per_word = 8; | 117 | dev->bits_per_word = 8; |
101 | 118 | ||
102 | if (dev->mode & ~(SPI_CPOL | SPI_CPHA)) | 119 | return 0; |
103 | return -EINVAL; | ||
104 | |||
105 | err = mxs_spi_setup_transfer(dev, NULL); | ||
106 | if (err) { | ||
107 | dev_err(&dev->dev, | ||
108 | "Failed to setup transfer, error = %d\n", err); | ||
109 | } | ||
110 | |||
111 | return err; | ||
112 | } | 120 | } |
113 | 121 | ||
114 | static uint32_t mxs_spi_cs_to_reg(unsigned cs) | 122 | static u32 mxs_spi_cs_to_reg(unsigned cs) |
115 | { | 123 | { |
116 | uint32_t select = 0; | 124 | u32 select = 0; |
117 | 125 | ||
118 | /* | 126 | /* |
119 | * i.MX28 Datasheet: 17.10.1: HW_SSP_CTRL0 | 127 | * i.MX28 Datasheet: 17.10.1: HW_SSP_CTRL0 |
@@ -131,43 +139,11 @@ static uint32_t mxs_spi_cs_to_reg(unsigned cs) | |||
131 | return select; | 139 | return select; |
132 | } | 140 | } |
133 | 141 | ||
134 | static void mxs_spi_set_cs(struct mxs_spi *spi, unsigned cs) | ||
135 | { | ||
136 | const uint32_t mask = | ||
137 | BM_SSP_CTRL0_WAIT_FOR_CMD | BM_SSP_CTRL0_WAIT_FOR_IRQ; | ||
138 | uint32_t select; | ||
139 | struct mxs_ssp *ssp = &spi->ssp; | ||
140 | |||
141 | writel(mask, ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR); | ||
142 | select = mxs_spi_cs_to_reg(cs); | ||
143 | writel(select, ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET); | ||
144 | } | ||
145 | |||
146 | static inline void mxs_spi_enable(struct mxs_spi *spi) | ||
147 | { | ||
148 | struct mxs_ssp *ssp = &spi->ssp; | ||
149 | |||
150 | writel(BM_SSP_CTRL0_LOCK_CS, | ||
151 | ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET); | ||
152 | writel(BM_SSP_CTRL0_IGNORE_CRC, | ||
153 | ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR); | ||
154 | } | ||
155 | |||
156 | static inline void mxs_spi_disable(struct mxs_spi *spi) | ||
157 | { | ||
158 | struct mxs_ssp *ssp = &spi->ssp; | ||
159 | |||
160 | writel(BM_SSP_CTRL0_LOCK_CS, | ||
161 | ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR); | ||
162 | writel(BM_SSP_CTRL0_IGNORE_CRC, | ||
163 | ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET); | ||
164 | } | ||
165 | |||
166 | static int mxs_ssp_wait(struct mxs_spi *spi, int offset, int mask, bool set) | 142 | static int mxs_ssp_wait(struct mxs_spi *spi, int offset, int mask, bool set) |
167 | { | 143 | { |
168 | const unsigned long timeout = jiffies + msecs_to_jiffies(SSP_TIMEOUT); | 144 | const unsigned long timeout = jiffies + msecs_to_jiffies(SSP_TIMEOUT); |
169 | struct mxs_ssp *ssp = &spi->ssp; | 145 | struct mxs_ssp *ssp = &spi->ssp; |
170 | uint32_t reg; | 146 | u32 reg; |
171 | 147 | ||
172 | do { | 148 | do { |
173 | reg = readl_relaxed(ssp->base + offset); | 149 | reg = readl_relaxed(ssp->base + offset); |
@@ -200,9 +176,9 @@ static irqreturn_t mxs_ssp_irq_handler(int irq, void *dev_id) | |||
200 | return IRQ_HANDLED; | 176 | return IRQ_HANDLED; |
201 | } | 177 | } |
202 | 178 | ||
203 | static int mxs_spi_txrx_dma(struct mxs_spi *spi, int cs, | 179 | static int mxs_spi_txrx_dma(struct mxs_spi *spi, |
204 | unsigned char *buf, int len, | 180 | unsigned char *buf, int len, |
205 | int *first, int *last, int write) | 181 | unsigned int flags) |
206 | { | 182 | { |
207 | struct mxs_ssp *ssp = &spi->ssp; | 183 | struct mxs_ssp *ssp = &spi->ssp; |
208 | struct dma_async_tx_descriptor *desc = NULL; | 184 | struct dma_async_tx_descriptor *desc = NULL; |
@@ -211,11 +187,11 @@ static int mxs_spi_txrx_dma(struct mxs_spi *spi, int cs, | |||
211 | const int sgs = DIV_ROUND_UP(len, desc_len); | 187 | const int sgs = DIV_ROUND_UP(len, desc_len); |
212 | int sg_count; | 188 | int sg_count; |
213 | int min, ret; | 189 | int min, ret; |
214 | uint32_t ctrl0; | 190 | u32 ctrl0; |
215 | struct page *vm_page; | 191 | struct page *vm_page; |
216 | void *sg_buf; | 192 | void *sg_buf; |
217 | struct { | 193 | struct { |
218 | uint32_t pio[4]; | 194 | u32 pio[4]; |
219 | struct scatterlist sg; | 195 | struct scatterlist sg; |
220 | } *dma_xfer; | 196 | } *dma_xfer; |
221 | 197 | ||
@@ -226,23 +202,27 @@ static int mxs_spi_txrx_dma(struct mxs_spi *spi, int cs, | |||
226 | if (!dma_xfer) | 202 | if (!dma_xfer) |
227 | return -ENOMEM; | 203 | return -ENOMEM; |
228 | 204 | ||
229 | INIT_COMPLETION(spi->c); | 205 | reinit_completion(&spi->c); |
230 | 206 | ||
207 | /* Chip select was already programmed into CTRL0 */ | ||
231 | ctrl0 = readl(ssp->base + HW_SSP_CTRL0); | 208 | ctrl0 = readl(ssp->base + HW_SSP_CTRL0); |
232 | ctrl0 &= ~BM_SSP_CTRL0_XFER_COUNT; | 209 | ctrl0 &= ~(BM_SSP_CTRL0_XFER_COUNT | BM_SSP_CTRL0_IGNORE_CRC | |
233 | ctrl0 |= BM_SSP_CTRL0_DATA_XFER | mxs_spi_cs_to_reg(cs); | 210 | BM_SSP_CTRL0_READ); |
211 | ctrl0 |= BM_SSP_CTRL0_DATA_XFER; | ||
234 | 212 | ||
235 | if (*first) | 213 | if (!(flags & TXRX_WRITE)) |
236 | ctrl0 |= BM_SSP_CTRL0_LOCK_CS; | ||
237 | if (!write) | ||
238 | ctrl0 |= BM_SSP_CTRL0_READ; | 214 | ctrl0 |= BM_SSP_CTRL0_READ; |
239 | 215 | ||
240 | /* Queue the DMA data transfer. */ | 216 | /* Queue the DMA data transfer. */ |
241 | for (sg_count = 0; sg_count < sgs; sg_count++) { | 217 | for (sg_count = 0; sg_count < sgs; sg_count++) { |
218 | /* Prepare the transfer descriptor. */ | ||
242 | min = min(len, desc_len); | 219 | min = min(len, desc_len); |
243 | 220 | ||
244 | /* Prepare the transfer descriptor. */ | 221 | /* |
245 | if ((sg_count + 1 == sgs) && *last) | 222 | * De-assert CS on last segment if flag is set (i.e., no more |
223 | * transfers will follow) | ||
224 | */ | ||
225 | if ((sg_count + 1 == sgs) && (flags & TXRX_DEASSERT_CS)) | ||
246 | ctrl0 |= BM_SSP_CTRL0_IGNORE_CRC; | 226 | ctrl0 |= BM_SSP_CTRL0_IGNORE_CRC; |
247 | 227 | ||
248 | if (ssp->devid == IMX23_SSP) { | 228 | if (ssp->devid == IMX23_SSP) { |
@@ -267,7 +247,7 @@ static int mxs_spi_txrx_dma(struct mxs_spi *spi, int cs, | |||
267 | 247 | ||
268 | sg_init_one(&dma_xfer[sg_count].sg, sg_buf, min); | 248 | sg_init_one(&dma_xfer[sg_count].sg, sg_buf, min); |
269 | ret = dma_map_sg(ssp->dev, &dma_xfer[sg_count].sg, 1, | 249 | ret = dma_map_sg(ssp->dev, &dma_xfer[sg_count].sg, 1, |
270 | write ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | 250 | (flags & TXRX_WRITE) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); |
271 | 251 | ||
272 | len -= min; | 252 | len -= min; |
273 | buf += min; | 253 | buf += min; |
@@ -287,7 +267,7 @@ static int mxs_spi_txrx_dma(struct mxs_spi *spi, int cs, | |||
287 | 267 | ||
288 | desc = dmaengine_prep_slave_sg(ssp->dmach, | 268 | desc = dmaengine_prep_slave_sg(ssp->dmach, |
289 | &dma_xfer[sg_count].sg, 1, | 269 | &dma_xfer[sg_count].sg, 1, |
290 | write ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, | 270 | (flags & TXRX_WRITE) ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, |
291 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | 271 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
292 | 272 | ||
293 | if (!desc) { | 273 | if (!desc) { |
@@ -324,7 +304,7 @@ err_vmalloc: | |||
324 | while (--sg_count >= 0) { | 304 | while (--sg_count >= 0) { |
325 | err_mapped: | 305 | err_mapped: |
326 | dma_unmap_sg(ssp->dev, &dma_xfer[sg_count].sg, 1, | 306 | dma_unmap_sg(ssp->dev, &dma_xfer[sg_count].sg, 1, |
327 | write ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | 307 | (flags & TXRX_WRITE) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); |
328 | } | 308 | } |
329 | 309 | ||
330 | kfree(dma_xfer); | 310 | kfree(dma_xfer); |
@@ -332,20 +312,19 @@ err_mapped: | |||
332 | return ret; | 312 | return ret; |
333 | } | 313 | } |
334 | 314 | ||
335 | static int mxs_spi_txrx_pio(struct mxs_spi *spi, int cs, | 315 | static int mxs_spi_txrx_pio(struct mxs_spi *spi, |
336 | unsigned char *buf, int len, | 316 | unsigned char *buf, int len, |
337 | int *first, int *last, int write) | 317 | unsigned int flags) |
338 | { | 318 | { |
339 | struct mxs_ssp *ssp = &spi->ssp; | 319 | struct mxs_ssp *ssp = &spi->ssp; |
340 | 320 | ||
341 | if (*first) | 321 | writel(BM_SSP_CTRL0_IGNORE_CRC, |
342 | mxs_spi_enable(spi); | 322 | ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR); |
343 | |||
344 | mxs_spi_set_cs(spi, cs); | ||
345 | 323 | ||
346 | while (len--) { | 324 | while (len--) { |
347 | if (*last && len == 0) | 325 | if (len == 0 && (flags & TXRX_DEASSERT_CS)) |
348 | mxs_spi_disable(spi); | 326 | writel(BM_SSP_CTRL0_IGNORE_CRC, |
327 | ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET); | ||
349 | 328 | ||
350 | if (ssp->devid == IMX23_SSP) { | 329 | if (ssp->devid == IMX23_SSP) { |
351 | writel(BM_SSP_CTRL0_XFER_COUNT, | 330 | writel(BM_SSP_CTRL0_XFER_COUNT, |
@@ -356,7 +335,7 @@ static int mxs_spi_txrx_pio(struct mxs_spi *spi, int cs, | |||
356 | writel(1, ssp->base + HW_SSP_XFER_SIZE); | 335 | writel(1, ssp->base + HW_SSP_XFER_SIZE); |
357 | } | 336 | } |
358 | 337 | ||
359 | if (write) | 338 | if (flags & TXRX_WRITE) |
360 | writel(BM_SSP_CTRL0_READ, | 339 | writel(BM_SSP_CTRL0_READ, |
361 | ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR); | 340 | ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR); |
362 | else | 341 | else |
@@ -369,13 +348,13 @@ static int mxs_spi_txrx_pio(struct mxs_spi *spi, int cs, | |||
369 | if (mxs_ssp_wait(spi, HW_SSP_CTRL0, BM_SSP_CTRL0_RUN, 1)) | 348 | if (mxs_ssp_wait(spi, HW_SSP_CTRL0, BM_SSP_CTRL0_RUN, 1)) |
370 | return -ETIMEDOUT; | 349 | return -ETIMEDOUT; |
371 | 350 | ||
372 | if (write) | 351 | if (flags & TXRX_WRITE) |
373 | writel(*buf, ssp->base + HW_SSP_DATA(ssp)); | 352 | writel(*buf, ssp->base + HW_SSP_DATA(ssp)); |
374 | 353 | ||
375 | writel(BM_SSP_CTRL0_DATA_XFER, | 354 | writel(BM_SSP_CTRL0_DATA_XFER, |
376 | ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET); | 355 | ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET); |
377 | 356 | ||
378 | if (!write) { | 357 | if (!(flags & TXRX_WRITE)) { |
379 | if (mxs_ssp_wait(spi, HW_SSP_STATUS(ssp), | 358 | if (mxs_ssp_wait(spi, HW_SSP_STATUS(ssp), |
380 | BM_SSP_STATUS_FIFO_EMPTY, 0)) | 359 | BM_SSP_STATUS_FIFO_EMPTY, 0)) |
381 | return -ETIMEDOUT; | 360 | return -ETIMEDOUT; |
@@ -400,14 +379,15 @@ static int mxs_spi_transfer_one(struct spi_master *master, | |||
400 | { | 379 | { |
401 | struct mxs_spi *spi = spi_master_get_devdata(master); | 380 | struct mxs_spi *spi = spi_master_get_devdata(master); |
402 | struct mxs_ssp *ssp = &spi->ssp; | 381 | struct mxs_ssp *ssp = &spi->ssp; |
403 | int first, last; | ||
404 | struct spi_transfer *t, *tmp_t; | 382 | struct spi_transfer *t, *tmp_t; |
383 | unsigned int flag; | ||
405 | int status = 0; | 384 | int status = 0; |
406 | int cs; | ||
407 | |||
408 | first = last = 0; | ||
409 | 385 | ||
410 | cs = m->spi->chip_select; | 386 | /* Program CS register bits here, it will be used for all transfers. */ |
387 | writel(BM_SSP_CTRL0_WAIT_FOR_CMD | BM_SSP_CTRL0_WAIT_FOR_IRQ, | ||
388 | ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR); | ||
389 | writel(mxs_spi_cs_to_reg(m->spi->chip_select), | ||
390 | ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET); | ||
411 | 391 | ||
412 | list_for_each_entry_safe(t, tmp_t, &m->transfers, transfer_list) { | 392 | list_for_each_entry_safe(t, tmp_t, &m->transfers, transfer_list) { |
413 | 393 | ||
@@ -415,16 +395,9 @@ static int mxs_spi_transfer_one(struct spi_master *master, | |||
415 | if (status) | 395 | if (status) |
416 | break; | 396 | break; |
417 | 397 | ||
418 | if (&t->transfer_list == m->transfers.next) | 398 | /* De-assert on last transfer, inverted by cs_change flag */ |
419 | first = 1; | 399 | flag = (&t->transfer_list == m->transfers.prev) ^ t->cs_change ? |
420 | if (&t->transfer_list == m->transfers.prev) | 400 | TXRX_DEASSERT_CS : 0; |
421 | last = 1; | ||
422 | if ((t->rx_buf && t->tx_buf) || (t->rx_dma && t->tx_dma)) { | ||
423 | dev_err(ssp->dev, | ||
424 | "Cannot send and receive simultaneously\n"); | ||
425 | status = -EINVAL; | ||
426 | break; | ||
427 | } | ||
428 | 401 | ||
429 | /* | 402 | /* |
430 | * Small blocks can be transfered via PIO. | 403 | * Small blocks can be transfered via PIO. |
@@ -441,26 +414,26 @@ static int mxs_spi_transfer_one(struct spi_master *master, | |||
441 | STMP_OFFSET_REG_CLR); | 414 | STMP_OFFSET_REG_CLR); |
442 | 415 | ||
443 | if (t->tx_buf) | 416 | if (t->tx_buf) |
444 | status = mxs_spi_txrx_pio(spi, cs, | 417 | status = mxs_spi_txrx_pio(spi, |
445 | (void *)t->tx_buf, | 418 | (void *)t->tx_buf, |
446 | t->len, &first, &last, 1); | 419 | t->len, flag | TXRX_WRITE); |
447 | if (t->rx_buf) | 420 | if (t->rx_buf) |
448 | status = mxs_spi_txrx_pio(spi, cs, | 421 | status = mxs_spi_txrx_pio(spi, |
449 | t->rx_buf, t->len, | 422 | t->rx_buf, t->len, |
450 | &first, &last, 0); | 423 | flag); |
451 | } else { | 424 | } else { |
452 | writel(BM_SSP_CTRL1_DMA_ENABLE, | 425 | writel(BM_SSP_CTRL1_DMA_ENABLE, |
453 | ssp->base + HW_SSP_CTRL1(ssp) + | 426 | ssp->base + HW_SSP_CTRL1(ssp) + |
454 | STMP_OFFSET_REG_SET); | 427 | STMP_OFFSET_REG_SET); |
455 | 428 | ||
456 | if (t->tx_buf) | 429 | if (t->tx_buf) |
457 | status = mxs_spi_txrx_dma(spi, cs, | 430 | status = mxs_spi_txrx_dma(spi, |
458 | (void *)t->tx_buf, t->len, | 431 | (void *)t->tx_buf, t->len, |
459 | &first, &last, 1); | 432 | flag | TXRX_WRITE); |
460 | if (t->rx_buf) | 433 | if (t->rx_buf) |
461 | status = mxs_spi_txrx_dma(spi, cs, | 434 | status = mxs_spi_txrx_dma(spi, |
462 | t->rx_buf, t->len, | 435 | t->rx_buf, t->len, |
463 | &first, &last, 0); | 436 | flag); |
464 | } | 437 | } |
465 | 438 | ||
466 | if (status) { | 439 | if (status) { |
@@ -469,7 +442,6 @@ static int mxs_spi_transfer_one(struct spi_master *master, | |||
469 | } | 442 | } |
470 | 443 | ||
471 | m->actual_length += t->len; | 444 | m->actual_length += t->len; |
472 | first = last = 0; | ||
473 | } | 445 | } |
474 | 446 | ||
475 | m->status = status; | 447 | m->status = status; |
@@ -563,7 +535,6 @@ static int mxs_spi_probe(struct platform_device *pdev) | |||
563 | goto out_dma_release; | 535 | goto out_dma_release; |
564 | 536 | ||
565 | clk_set_rate(ssp->clk, clk_freq); | 537 | clk_set_rate(ssp->clk, clk_freq); |
566 | ssp->clk_rate = clk_get_rate(ssp->clk) / 1000; | ||
567 | 538 | ||
568 | ret = stmp_reset_block(ssp->base); | 539 | ret = stmp_reset_block(ssp->base); |
569 | if (ret) | 540 | if (ret) |
@@ -571,7 +542,7 @@ static int mxs_spi_probe(struct platform_device *pdev) | |||
571 | 542 | ||
572 | platform_set_drvdata(pdev, master); | 543 | platform_set_drvdata(pdev, master); |
573 | 544 | ||
574 | ret = spi_register_master(master); | 545 | ret = devm_spi_register_master(&pdev->dev, master); |
575 | if (ret) { | 546 | if (ret) { |
576 | dev_err(&pdev->dev, "Cannot register SPI master, %d\n", ret); | 547 | dev_err(&pdev->dev, "Cannot register SPI master, %d\n", ret); |
577 | goto out_disable_clk; | 548 | goto out_disable_clk; |
@@ -594,14 +565,12 @@ static int mxs_spi_remove(struct platform_device *pdev) | |||
594 | struct mxs_spi *spi; | 565 | struct mxs_spi *spi; |
595 | struct mxs_ssp *ssp; | 566 | struct mxs_ssp *ssp; |
596 | 567 | ||
597 | master = spi_master_get(platform_get_drvdata(pdev)); | 568 | master = platform_get_drvdata(pdev); |
598 | spi = spi_master_get_devdata(master); | 569 | spi = spi_master_get_devdata(master); |
599 | ssp = &spi->ssp; | 570 | ssp = &spi->ssp; |
600 | 571 | ||
601 | spi_unregister_master(master); | ||
602 | clk_disable_unprepare(ssp->clk); | 572 | clk_disable_unprepare(ssp->clk); |
603 | dma_release_channel(ssp->dmach); | 573 | dma_release_channel(ssp->dmach); |
604 | spi_master_put(master); | ||
605 | 574 | ||
606 | return 0; | 575 | return 0; |
607 | } | 576 | } |
diff --git a/drivers/spi/spi-nuc900.c b/drivers/spi/spi-nuc900.c index 47a68b43bcd5..e0c32bc69ee2 100644 --- a/drivers/spi/spi-nuc900.c +++ b/drivers/spi/spi-nuc900.c | |||
@@ -349,7 +349,7 @@ static int nuc900_spi_probe(struct platform_device *pdev) | |||
349 | } | 349 | } |
350 | 350 | ||
351 | hw = spi_master_get_devdata(master); | 351 | hw = spi_master_get_devdata(master); |
352 | hw->master = spi_master_get(master); | 352 | hw->master = master; |
353 | hw->pdata = dev_get_platdata(&pdev->dev); | 353 | hw->pdata = dev_get_platdata(&pdev->dev); |
354 | hw->dev = &pdev->dev; | 354 | hw->dev = &pdev->dev; |
355 | 355 | ||
@@ -435,7 +435,6 @@ err_iomap: | |||
435 | kfree(hw->ioarea); | 435 | kfree(hw->ioarea); |
436 | err_pdata: | 436 | err_pdata: |
437 | spi_master_put(hw->master); | 437 | spi_master_put(hw->master); |
438 | |||
439 | err_nomem: | 438 | err_nomem: |
440 | return err; | 439 | return err; |
441 | } | 440 | } |
diff --git a/drivers/spi/spi-oc-tiny.c b/drivers/spi/spi-oc-tiny.c index 333cb1badcd7..91c668596202 100644 --- a/drivers/spi/spi-oc-tiny.c +++ b/drivers/spi/spi-oc-tiny.c | |||
@@ -306,7 +306,7 @@ static int tiny_spi_probe(struct platform_device *pdev) | |||
306 | platform_set_drvdata(pdev, hw); | 306 | platform_set_drvdata(pdev, hw); |
307 | 307 | ||
308 | /* setup the state for the bitbang driver */ | 308 | /* setup the state for the bitbang driver */ |
309 | hw->bitbang.master = spi_master_get(master); | 309 | hw->bitbang.master = master; |
310 | if (!hw->bitbang.master) | 310 | if (!hw->bitbang.master) |
311 | return err; | 311 | return err; |
312 | hw->bitbang.setup_transfer = tiny_spi_setup_transfer; | 312 | hw->bitbang.setup_transfer = tiny_spi_setup_transfer; |
diff --git a/drivers/spi/spi-octeon.c b/drivers/spi/spi-octeon.c index 5f28ddbe4f7e..67249a48b391 100644 --- a/drivers/spi/spi-octeon.c +++ b/drivers/spi/spi-octeon.c | |||
@@ -272,7 +272,7 @@ static int octeon_spi_probe(struct platform_device *pdev) | |||
272 | master->bits_per_word_mask = SPI_BPW_MASK(8); | 272 | master->bits_per_word_mask = SPI_BPW_MASK(8); |
273 | 273 | ||
274 | master->dev.of_node = pdev->dev.of_node; | 274 | master->dev.of_node = pdev->dev.of_node; |
275 | err = spi_register_master(master); | 275 | err = devm_spi_register_master(&pdev->dev, master); |
276 | if (err) { | 276 | if (err) { |
277 | dev_err(&pdev->dev, "register master failed: %d\n", err); | 277 | dev_err(&pdev->dev, "register master failed: %d\n", err); |
278 | goto fail; | 278 | goto fail; |
@@ -292,8 +292,6 @@ static int octeon_spi_remove(struct platform_device *pdev) | |||
292 | struct octeon_spi *p = spi_master_get_devdata(master); | 292 | struct octeon_spi *p = spi_master_get_devdata(master); |
293 | u64 register_base = p->register_base; | 293 | u64 register_base = p->register_base; |
294 | 294 | ||
295 | spi_unregister_master(master); | ||
296 | |||
297 | /* Clear the CSENA* and put everything in a known state. */ | 295 | /* Clear the CSENA* and put everything in a known state. */ |
298 | cvmx_write_csr(register_base + OCTEON_SPI_CFG, 0); | 296 | cvmx_write_csr(register_base + OCTEON_SPI_CFG, 0); |
299 | 297 | ||
diff --git a/drivers/spi/spi-omap-100k.c b/drivers/spi/spi-omap-100k.c index 69ecf05757dd..b6ed82beb01d 100644 --- a/drivers/spi/spi-omap-100k.c +++ b/drivers/spi/spi-omap-100k.c | |||
@@ -457,7 +457,7 @@ static int omap1_spi100k_probe(struct platform_device *pdev) | |||
457 | goto err; | 457 | goto err; |
458 | } | 458 | } |
459 | 459 | ||
460 | status = spi_register_master(master); | 460 | status = devm_spi_register_master(&pdev->dev, master); |
461 | if (status < 0) | 461 | if (status < 0) |
462 | goto err; | 462 | goto err; |
463 | 463 | ||
@@ -485,8 +485,6 @@ static int omap1_spi100k_remove(struct platform_device *pdev) | |||
485 | 485 | ||
486 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 486 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
487 | 487 | ||
488 | spi_unregister_master(master); | ||
489 | |||
490 | return 0; | 488 | return 0; |
491 | } | 489 | } |
492 | 490 | ||
diff --git a/drivers/spi/spi-omap-uwire.c b/drivers/spi/spi-omap-uwire.c index a6a8f0961750..9313fd3b413d 100644 --- a/drivers/spi/spi-omap-uwire.c +++ b/drivers/spi/spi-omap-uwire.c | |||
@@ -557,7 +557,8 @@ static struct platform_driver uwire_driver = { | |||
557 | .name = "omap_uwire", | 557 | .name = "omap_uwire", |
558 | .owner = THIS_MODULE, | 558 | .owner = THIS_MODULE, |
559 | }, | 559 | }, |
560 | .remove = uwire_remove, | 560 | .probe = uwire_probe, |
561 | .remove = uwire_remove, | ||
561 | // suspend ... unuse ck | 562 | // suspend ... unuse ck |
562 | // resume ... use ck | 563 | // resume ... use ck |
563 | }; | 564 | }; |
@@ -579,7 +580,7 @@ static int __init omap_uwire_init(void) | |||
579 | omap_writel(val | 0x00AAA000, OMAP7XX_IO_CONF_9); | 580 | omap_writel(val | 0x00AAA000, OMAP7XX_IO_CONF_9); |
580 | } | 581 | } |
581 | 582 | ||
582 | return platform_driver_probe(&uwire_driver, uwire_probe); | 583 | return platform_driver_register(&uwire_driver); |
583 | } | 584 | } |
584 | 585 | ||
585 | static void __exit omap_uwire_exit(void) | 586 | static void __exit omap_uwire_exit(void) |
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index ed4af4708d9a..443df39840bc 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c | |||
@@ -276,7 +276,7 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi, | |||
276 | struct omap2_mcspi_cs *cs = spi->controller_state; | 276 | struct omap2_mcspi_cs *cs = spi->controller_state; |
277 | struct omap2_mcspi *mcspi; | 277 | struct omap2_mcspi *mcspi; |
278 | unsigned int wcnt; | 278 | unsigned int wcnt; |
279 | int fifo_depth, bytes_per_word; | 279 | int max_fifo_depth, fifo_depth, bytes_per_word; |
280 | u32 chconf, xferlevel; | 280 | u32 chconf, xferlevel; |
281 | 281 | ||
282 | mcspi = spi_master_get_devdata(master); | 282 | mcspi = spi_master_get_devdata(master); |
@@ -287,7 +287,12 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi, | |||
287 | if (t->len % bytes_per_word != 0) | 287 | if (t->len % bytes_per_word != 0) |
288 | goto disable_fifo; | 288 | goto disable_fifo; |
289 | 289 | ||
290 | fifo_depth = gcd(t->len, OMAP2_MCSPI_MAX_FIFODEPTH); | 290 | if (t->rx_buf != NULL && t->tx_buf != NULL) |
291 | max_fifo_depth = OMAP2_MCSPI_MAX_FIFODEPTH / 2; | ||
292 | else | ||
293 | max_fifo_depth = OMAP2_MCSPI_MAX_FIFODEPTH; | ||
294 | |||
295 | fifo_depth = gcd(t->len, max_fifo_depth); | ||
291 | if (fifo_depth < 2 || fifo_depth % bytes_per_word != 0) | 296 | if (fifo_depth < 2 || fifo_depth % bytes_per_word != 0) |
292 | goto disable_fifo; | 297 | goto disable_fifo; |
293 | 298 | ||
@@ -299,7 +304,8 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi, | |||
299 | if (t->rx_buf != NULL) { | 304 | if (t->rx_buf != NULL) { |
300 | chconf |= OMAP2_MCSPI_CHCONF_FFER; | 305 | chconf |= OMAP2_MCSPI_CHCONF_FFER; |
301 | xferlevel |= (fifo_depth - 1) << 8; | 306 | xferlevel |= (fifo_depth - 1) << 8; |
302 | } else { | 307 | } |
308 | if (t->tx_buf != NULL) { | ||
303 | chconf |= OMAP2_MCSPI_CHCONF_FFET; | 309 | chconf |= OMAP2_MCSPI_CHCONF_FFET; |
304 | xferlevel |= fifo_depth - 1; | 310 | xferlevel |= fifo_depth - 1; |
305 | } | 311 | } |
@@ -498,7 +504,7 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer, | |||
498 | ((u32 *)xfer->rx_buf)[elements++] = w; | 504 | ((u32 *)xfer->rx_buf)[elements++] = w; |
499 | } else { | 505 | } else { |
500 | int bytes_per_word = mcspi_bytes_per_word(word_len); | 506 | int bytes_per_word = mcspi_bytes_per_word(word_len); |
501 | dev_err(&spi->dev, "DMA RX penultimate word empty"); | 507 | dev_err(&spi->dev, "DMA RX penultimate word empty\n"); |
502 | count -= (bytes_per_word << 1); | 508 | count -= (bytes_per_word << 1); |
503 | omap2_mcspi_set_enable(spi, 1); | 509 | omap2_mcspi_set_enable(spi, 1); |
504 | return count; | 510 | return count; |
@@ -516,7 +522,7 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer, | |||
516 | else /* word_len <= 32 */ | 522 | else /* word_len <= 32 */ |
517 | ((u32 *)xfer->rx_buf)[elements] = w; | 523 | ((u32 *)xfer->rx_buf)[elements] = w; |
518 | } else { | 524 | } else { |
519 | dev_err(&spi->dev, "DMA RX last word empty"); | 525 | dev_err(&spi->dev, "DMA RX last word empty\n"); |
520 | count -= mcspi_bytes_per_word(word_len); | 526 | count -= mcspi_bytes_per_word(word_len); |
521 | } | 527 | } |
522 | omap2_mcspi_set_enable(spi, 1); | 528 | omap2_mcspi_set_enable(spi, 1); |
@@ -1407,7 +1413,7 @@ static int omap2_mcspi_probe(struct platform_device *pdev) | |||
1407 | if (status < 0) | 1413 | if (status < 0) |
1408 | goto disable_pm; | 1414 | goto disable_pm; |
1409 | 1415 | ||
1410 | status = spi_register_master(master); | 1416 | status = devm_spi_register_master(&pdev->dev, master); |
1411 | if (status < 0) | 1417 | if (status < 0) |
1412 | goto disable_pm; | 1418 | goto disable_pm; |
1413 | 1419 | ||
@@ -1435,7 +1441,6 @@ static int omap2_mcspi_remove(struct platform_device *pdev) | |||
1435 | pm_runtime_put_sync(mcspi->dev); | 1441 | pm_runtime_put_sync(mcspi->dev); |
1436 | pm_runtime_disable(&pdev->dev); | 1442 | pm_runtime_disable(&pdev->dev); |
1437 | 1443 | ||
1438 | spi_unregister_master(master); | ||
1439 | kfree(dma_channels); | 1444 | kfree(dma_channels); |
1440 | 1445 | ||
1441 | return 0; | 1446 | return 0; |
diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c index 1d1d321d90c4..744841e095e4 100644 --- a/drivers/spi/spi-orion.c +++ b/drivers/spi/spi-orion.c | |||
@@ -84,8 +84,8 @@ static int orion_spi_set_transfer_size(struct orion_spi *orion_spi, int size) | |||
84 | orion_spi_clrbits(orion_spi, ORION_SPI_IF_CONFIG_REG, | 84 | orion_spi_clrbits(orion_spi, ORION_SPI_IF_CONFIG_REG, |
85 | ORION_SPI_IF_8_16_BIT_MODE); | 85 | ORION_SPI_IF_8_16_BIT_MODE); |
86 | } else { | 86 | } else { |
87 | pr_debug("Bad bits per word value %d (only 8 or 16 are " | 87 | pr_debug("Bad bits per word value %d (only 8 or 16 are allowed).\n", |
88 | "allowed).\n", size); | 88 | size); |
89 | return -EINVAL; | 89 | return -EINVAL; |
90 | } | 90 | } |
91 | 91 | ||
@@ -407,7 +407,7 @@ static int orion_spi_probe(struct platform_device *pdev) | |||
407 | const u32 *iprop; | 407 | const u32 *iprop; |
408 | int size; | 408 | int size; |
409 | 409 | ||
410 | master = spi_alloc_master(&pdev->dev, sizeof *spi); | 410 | master = spi_alloc_master(&pdev->dev, sizeof(*spi)); |
411 | if (master == NULL) { | 411 | if (master == NULL) { |
412 | dev_dbg(&pdev->dev, "master allocation failed\n"); | 412 | dev_dbg(&pdev->dev, "master allocation failed\n"); |
413 | return -ENOMEM; | 413 | return -ENOMEM; |
@@ -457,7 +457,7 @@ static int orion_spi_probe(struct platform_device *pdev) | |||
457 | goto out_rel_clk; | 457 | goto out_rel_clk; |
458 | 458 | ||
459 | master->dev.of_node = pdev->dev.of_node; | 459 | master->dev.of_node = pdev->dev.of_node; |
460 | status = spi_register_master(master); | 460 | status = devm_spi_register_master(&pdev->dev, master); |
461 | if (status < 0) | 461 | if (status < 0) |
462 | goto out_rel_clk; | 462 | goto out_rel_clk; |
463 | 463 | ||
@@ -483,8 +483,6 @@ static int orion_spi_remove(struct platform_device *pdev) | |||
483 | clk_disable_unprepare(spi->clk); | 483 | clk_disable_unprepare(spi->clk); |
484 | clk_put(spi->clk); | 484 | clk_put(spi->clk); |
485 | 485 | ||
486 | spi_unregister_master(master); | ||
487 | |||
488 | return 0; | 486 | return 0; |
489 | } | 487 | } |
490 | 488 | ||
diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c index 9c511a954d21..2789b452e711 100644 --- a/drivers/spi/spi-pl022.c +++ b/drivers/spi/spi-pl022.c | |||
@@ -1619,7 +1619,6 @@ static int verify_controller_parameters(struct pl022 *pl022, | |||
1619 | dev_err(&pl022->adev->dev, | 1619 | dev_err(&pl022->adev->dev, |
1620 | "RX FIFO Trigger Level is configured incorrectly\n"); | 1620 | "RX FIFO Trigger Level is configured incorrectly\n"); |
1621 | return -EINVAL; | 1621 | return -EINVAL; |
1622 | break; | ||
1623 | } | 1622 | } |
1624 | switch (chip_info->tx_lev_trig) { | 1623 | switch (chip_info->tx_lev_trig) { |
1625 | case SSP_TX_1_OR_MORE_EMPTY_LOC: | 1624 | case SSP_TX_1_OR_MORE_EMPTY_LOC: |
@@ -1645,7 +1644,6 @@ static int verify_controller_parameters(struct pl022 *pl022, | |||
1645 | dev_err(&pl022->adev->dev, | 1644 | dev_err(&pl022->adev->dev, |
1646 | "TX FIFO Trigger Level is configured incorrectly\n"); | 1645 | "TX FIFO Trigger Level is configured incorrectly\n"); |
1647 | return -EINVAL; | 1646 | return -EINVAL; |
1648 | break; | ||
1649 | } | 1647 | } |
1650 | if (chip_info->iface == SSP_INTERFACE_NATIONAL_MICROWIRE) { | 1648 | if (chip_info->iface == SSP_INTERFACE_NATIONAL_MICROWIRE) { |
1651 | if ((chip_info->ctrl_len < SSP_BITS_4) | 1649 | if ((chip_info->ctrl_len < SSP_BITS_4) |
@@ -2175,8 +2173,8 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id) | |||
2175 | status = -ENOMEM; | 2173 | status = -ENOMEM; |
2176 | goto err_no_ioremap; | 2174 | goto err_no_ioremap; |
2177 | } | 2175 | } |
2178 | printk(KERN_INFO "pl022: mapped registers from %pa to %p\n", | 2176 | dev_info(&adev->dev, "mapped registers from %pa to %p\n", |
2179 | &adev->res.start, pl022->virtbase); | 2177 | &adev->res.start, pl022->virtbase); |
2180 | 2178 | ||
2181 | pl022->clk = devm_clk_get(&adev->dev, NULL); | 2179 | pl022->clk = devm_clk_get(&adev->dev, NULL); |
2182 | if (IS_ERR(pl022->clk)) { | 2180 | if (IS_ERR(pl022->clk)) { |
@@ -2227,7 +2225,7 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id) | |||
2227 | 2225 | ||
2228 | /* Register with the SPI framework */ | 2226 | /* Register with the SPI framework */ |
2229 | amba_set_drvdata(adev, pl022); | 2227 | amba_set_drvdata(adev, pl022); |
2230 | status = spi_register_master(master); | 2228 | status = devm_spi_register_master(&adev->dev, master); |
2231 | if (status != 0) { | 2229 | if (status != 0) { |
2232 | dev_err(&adev->dev, | 2230 | dev_err(&adev->dev, |
2233 | "probe - problem registering spi master\n"); | 2231 | "probe - problem registering spi master\n"); |
@@ -2287,8 +2285,6 @@ pl022_remove(struct amba_device *adev) | |||
2287 | clk_unprepare(pl022->clk); | 2285 | clk_unprepare(pl022->clk); |
2288 | amba_release_regions(adev); | 2286 | amba_release_regions(adev); |
2289 | tasklet_disable(&pl022->pump_transfers); | 2287 | tasklet_disable(&pl022->pump_transfers); |
2290 | spi_unregister_master(pl022->master); | ||
2291 | amba_set_drvdata(adev, NULL); | ||
2292 | return 0; | 2288 | return 0; |
2293 | } | 2289 | } |
2294 | 2290 | ||
diff --git a/drivers/spi/spi-ppc4xx.c b/drivers/spi/spi-ppc4xx.c index 0ee53c25ba58..5ee56726f8d0 100644 --- a/drivers/spi/spi-ppc4xx.c +++ b/drivers/spi/spi-ppc4xx.c | |||
@@ -29,6 +29,8 @@ | |||
29 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
30 | #include <linux/errno.h> | 30 | #include <linux/errno.h> |
31 | #include <linux/wait.h> | 31 | #include <linux/wait.h> |
32 | #include <linux/of_address.h> | ||
33 | #include <linux/of_irq.h> | ||
32 | #include <linux/of_platform.h> | 34 | #include <linux/of_platform.h> |
33 | #include <linux/of_gpio.h> | 35 | #include <linux/of_gpio.h> |
34 | #include <linux/interrupt.h> | 36 | #include <linux/interrupt.h> |
@@ -396,7 +398,7 @@ static int spi_ppc4xx_of_probe(struct platform_device *op) | |||
396 | master->dev.of_node = np; | 398 | master->dev.of_node = np; |
397 | platform_set_drvdata(op, master); | 399 | platform_set_drvdata(op, master); |
398 | hw = spi_master_get_devdata(master); | 400 | hw = spi_master_get_devdata(master); |
399 | hw->master = spi_master_get(master); | 401 | hw->master = master; |
400 | hw->dev = dev; | 402 | hw->dev = dev; |
401 | 403 | ||
402 | init_completion(&hw->done); | 404 | init_completion(&hw->done); |
@@ -558,6 +560,7 @@ static int spi_ppc4xx_of_remove(struct platform_device *op) | |||
558 | free_irq(hw->irqnum, hw); | 560 | free_irq(hw->irqnum, hw); |
559 | iounmap(hw->regs); | 561 | iounmap(hw->regs); |
560 | free_gpios(hw); | 562 | free_gpios(hw); |
563 | spi_master_put(master); | ||
561 | return 0; | 564 | return 0; |
562 | } | 565 | } |
563 | 566 | ||
diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index 2eb06ee0b326..7765b1999537 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c | |||
@@ -546,8 +546,17 @@ static irqreturn_t ssp_int(int irq, void *dev_id) | |||
546 | if (pm_runtime_suspended(&drv_data->pdev->dev)) | 546 | if (pm_runtime_suspended(&drv_data->pdev->dev)) |
547 | return IRQ_NONE; | 547 | return IRQ_NONE; |
548 | 548 | ||
549 | sccr1_reg = read_SSCR1(reg); | 549 | /* |
550 | * If the device is not yet in RPM suspended state and we get an | ||
551 | * interrupt that is meant for another device, check if status bits | ||
552 | * are all set to one. That means that the device is already | ||
553 | * powered off. | ||
554 | */ | ||
550 | status = read_SSSR(reg); | 555 | status = read_SSSR(reg); |
556 | if (status == ~0) | ||
557 | return IRQ_NONE; | ||
558 | |||
559 | sccr1_reg = read_SSCR1(reg); | ||
551 | 560 | ||
552 | /* Ignore possible writes if we don't need to write */ | 561 | /* Ignore possible writes if we don't need to write */ |
553 | if (!(sccr1_reg & SSCR1_TIE)) | 562 | if (!(sccr1_reg & SSCR1_TIE)) |
@@ -564,8 +573,8 @@ static irqreturn_t ssp_int(int irq, void *dev_id) | |||
564 | write_SSTO(0, reg); | 573 | write_SSTO(0, reg); |
565 | write_SSSR_CS(drv_data, drv_data->clear_sr); | 574 | write_SSSR_CS(drv_data, drv_data->clear_sr); |
566 | 575 | ||
567 | dev_err(&drv_data->pdev->dev, "bad message state " | 576 | dev_err(&drv_data->pdev->dev, |
568 | "in interrupt handler\n"); | 577 | "bad message state in interrupt handler\n"); |
569 | 578 | ||
570 | /* Never fail */ | 579 | /* Never fail */ |
571 | return IRQ_HANDLED; | 580 | return IRQ_HANDLED; |
@@ -642,8 +651,8 @@ static void pump_transfers(unsigned long data) | |||
642 | if (message->is_dma_mapped | 651 | if (message->is_dma_mapped |
643 | || transfer->rx_dma || transfer->tx_dma) { | 652 | || transfer->rx_dma || transfer->tx_dma) { |
644 | dev_err(&drv_data->pdev->dev, | 653 | dev_err(&drv_data->pdev->dev, |
645 | "pump_transfers: mapped transfer length " | 654 | "pump_transfers: mapped transfer length of " |
646 | "of %u is greater than %d\n", | 655 | "%u is greater than %d\n", |
647 | transfer->len, MAX_DMA_LEN); | 656 | transfer->len, MAX_DMA_LEN); |
648 | message->status = -EINVAL; | 657 | message->status = -EINVAL; |
649 | giveback(drv_data); | 658 | giveback(drv_data); |
@@ -651,11 +660,10 @@ static void pump_transfers(unsigned long data) | |||
651 | } | 660 | } |
652 | 661 | ||
653 | /* warn ... we force this to PIO mode */ | 662 | /* warn ... we force this to PIO mode */ |
654 | if (printk_ratelimit()) | 663 | dev_warn_ratelimited(&message->spi->dev, |
655 | dev_warn(&message->spi->dev, "pump_transfers: " | 664 | "pump_transfers: DMA disabled for transfer length %ld " |
656 | "DMA disabled for transfer length %ld " | 665 | "greater than %d\n", |
657 | "greater than %d\n", | 666 | (long)drv_data->len, MAX_DMA_LEN); |
658 | (long)drv_data->len, MAX_DMA_LEN); | ||
659 | } | 667 | } |
660 | 668 | ||
661 | /* Setup the transfer state based on the type of transfer */ | 669 | /* Setup the transfer state based on the type of transfer */ |
@@ -717,11 +725,8 @@ static void pump_transfers(unsigned long data) | |||
717 | message->spi, | 725 | message->spi, |
718 | bits, &dma_burst, | 726 | bits, &dma_burst, |
719 | &dma_thresh)) | 727 | &dma_thresh)) |
720 | if (printk_ratelimit()) | 728 | dev_warn_ratelimited(&message->spi->dev, |
721 | dev_warn(&message->spi->dev, | 729 | "pump_transfers: DMA burst size reduced to match bits_per_word\n"); |
722 | "pump_transfers: " | ||
723 | "DMA burst size reduced to " | ||
724 | "match bits_per_word\n"); | ||
725 | } | 730 | } |
726 | 731 | ||
727 | cr0 = clk_div | 732 | cr0 = clk_div |
@@ -845,8 +850,8 @@ static int setup_cs(struct spi_device *spi, struct chip_data *chip, | |||
845 | if (gpio_is_valid(chip_info->gpio_cs)) { | 850 | if (gpio_is_valid(chip_info->gpio_cs)) { |
846 | err = gpio_request(chip_info->gpio_cs, "SPI_CS"); | 851 | err = gpio_request(chip_info->gpio_cs, "SPI_CS"); |
847 | if (err) { | 852 | if (err) { |
848 | dev_err(&spi->dev, "failed to request chip select " | 853 | dev_err(&spi->dev, "failed to request chip select GPIO%d\n", |
849 | "GPIO%d\n", chip_info->gpio_cs); | 854 | chip_info->gpio_cs); |
850 | return err; | 855 | return err; |
851 | } | 856 | } |
852 | 857 | ||
@@ -890,8 +895,8 @@ static int setup(struct spi_device *spi) | |||
890 | 895 | ||
891 | if (drv_data->ssp_type == CE4100_SSP) { | 896 | if (drv_data->ssp_type == CE4100_SSP) { |
892 | if (spi->chip_select > 4) { | 897 | if (spi->chip_select > 4) { |
893 | dev_err(&spi->dev, "failed setup: " | 898 | dev_err(&spi->dev, |
894 | "cs number must not be > 4.\n"); | 899 | "failed setup: cs number must not be > 4.\n"); |
895 | kfree(chip); | 900 | kfree(chip); |
896 | return -EINVAL; | 901 | return -EINVAL; |
897 | } | 902 | } |
@@ -947,8 +952,8 @@ static int setup(struct spi_device *spi) | |||
947 | spi->bits_per_word, | 952 | spi->bits_per_word, |
948 | &chip->dma_burst_size, | 953 | &chip->dma_burst_size, |
949 | &chip->dma_threshold)) { | 954 | &chip->dma_threshold)) { |
950 | dev_warn(&spi->dev, "in setup: DMA burst size reduced " | 955 | dev_warn(&spi->dev, |
951 | "to match bits_per_word\n"); | 956 | "in setup: DMA burst size reduced to match bits_per_word\n"); |
952 | } | 957 | } |
953 | } | 958 | } |
954 | 959 | ||
@@ -1068,6 +1073,8 @@ pxa2xx_spi_acpi_get_pdata(struct platform_device *pdev) | |||
1068 | static struct acpi_device_id pxa2xx_spi_acpi_match[] = { | 1073 | static struct acpi_device_id pxa2xx_spi_acpi_match[] = { |
1069 | { "INT33C0", 0 }, | 1074 | { "INT33C0", 0 }, |
1070 | { "INT33C1", 0 }, | 1075 | { "INT33C1", 0 }, |
1076 | { "INT3430", 0 }, | ||
1077 | { "INT3431", 0 }, | ||
1071 | { "80860F0E", 0 }, | 1078 | { "80860F0E", 0 }, |
1072 | { }, | 1079 | { }, |
1073 | }; | 1080 | }; |
@@ -1196,7 +1203,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) | |||
1196 | 1203 | ||
1197 | /* Register with the SPI framework */ | 1204 | /* Register with the SPI framework */ |
1198 | platform_set_drvdata(pdev, drv_data); | 1205 | platform_set_drvdata(pdev, drv_data); |
1199 | status = spi_register_master(master); | 1206 | status = devm_spi_register_master(&pdev->dev, master); |
1200 | if (status != 0) { | 1207 | if (status != 0) { |
1201 | dev_err(&pdev->dev, "problem registering spi master\n"); | 1208 | dev_err(&pdev->dev, "problem registering spi master\n"); |
1202 | goto out_error_clock_enabled; | 1209 | goto out_error_clock_enabled; |
@@ -1248,9 +1255,6 @@ static int pxa2xx_spi_remove(struct platform_device *pdev) | |||
1248 | /* Release SSP */ | 1255 | /* Release SSP */ |
1249 | pxa_ssp_free(ssp); | 1256 | pxa_ssp_free(ssp); |
1250 | 1257 | ||
1251 | /* Disconnect from the SPI framework */ | ||
1252 | spi_unregister_master(drv_data->master); | ||
1253 | |||
1254 | return 0; | 1258 | return 0; |
1255 | } | 1259 | } |
1256 | 1260 | ||
@@ -1289,6 +1293,9 @@ static int pxa2xx_spi_resume(struct device *dev) | |||
1289 | /* Enable the SSP clock */ | 1293 | /* Enable the SSP clock */ |
1290 | clk_prepare_enable(ssp->clk); | 1294 | clk_prepare_enable(ssp->clk); |
1291 | 1295 | ||
1296 | /* Restore LPSS private register bits */ | ||
1297 | lpss_ssp_setup(drv_data); | ||
1298 | |||
1292 | /* Start the queue running */ | 1299 | /* Start the queue running */ |
1293 | status = spi_master_resume(drv_data->master); | 1300 | status = spi_master_resume(drv_data->master); |
1294 | if (status != 0) { | 1301 | if (status != 0) { |
diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c index 8719206a03a0..9e829cee7357 100644 --- a/drivers/spi/spi-rspi.c +++ b/drivers/spi/spi-rspi.c | |||
@@ -59,6 +59,14 @@ | |||
59 | #define RSPI_SPCMD6 0x1c | 59 | #define RSPI_SPCMD6 0x1c |
60 | #define RSPI_SPCMD7 0x1e | 60 | #define RSPI_SPCMD7 0x1e |
61 | 61 | ||
62 | /*qspi only */ | ||
63 | #define QSPI_SPBFCR 0x18 | ||
64 | #define QSPI_SPBDCR 0x1a | ||
65 | #define QSPI_SPBMUL0 0x1c | ||
66 | #define QSPI_SPBMUL1 0x20 | ||
67 | #define QSPI_SPBMUL2 0x24 | ||
68 | #define QSPI_SPBMUL3 0x28 | ||
69 | |||
62 | /* SPCR */ | 70 | /* SPCR */ |
63 | #define SPCR_SPRIE 0x80 | 71 | #define SPCR_SPRIE 0x80 |
64 | #define SPCR_SPE 0x40 | 72 | #define SPCR_SPE 0x40 |
@@ -126,6 +134,8 @@ | |||
126 | #define SPCMD_LSBF 0x1000 | 134 | #define SPCMD_LSBF 0x1000 |
127 | #define SPCMD_SPB_MASK 0x0f00 | 135 | #define SPCMD_SPB_MASK 0x0f00 |
128 | #define SPCMD_SPB_8_TO_16(bit) (((bit - 1) << 8) & SPCMD_SPB_MASK) | 136 | #define SPCMD_SPB_8_TO_16(bit) (((bit - 1) << 8) & SPCMD_SPB_MASK) |
137 | #define SPCMD_SPB_8BIT 0x0000 /* qspi only */ | ||
138 | #define SPCMD_SPB_16BIT 0x0100 | ||
129 | #define SPCMD_SPB_20BIT 0x0000 | 139 | #define SPCMD_SPB_20BIT 0x0000 |
130 | #define SPCMD_SPB_24BIT 0x0100 | 140 | #define SPCMD_SPB_24BIT 0x0100 |
131 | #define SPCMD_SPB_32BIT 0x0200 | 141 | #define SPCMD_SPB_32BIT 0x0200 |
@@ -135,6 +145,10 @@ | |||
135 | #define SPCMD_CPOL 0x0002 | 145 | #define SPCMD_CPOL 0x0002 |
136 | #define SPCMD_CPHA 0x0001 | 146 | #define SPCMD_CPHA 0x0001 |
137 | 147 | ||
148 | /* SPBFCR */ | ||
149 | #define SPBFCR_TXRST 0x80 /* qspi only */ | ||
150 | #define SPBFCR_RXRST 0x40 /* qspi only */ | ||
151 | |||
138 | struct rspi_data { | 152 | struct rspi_data { |
139 | void __iomem *addr; | 153 | void __iomem *addr; |
140 | u32 max_speed_hz; | 154 | u32 max_speed_hz; |
@@ -145,6 +159,7 @@ struct rspi_data { | |||
145 | spinlock_t lock; | 159 | spinlock_t lock; |
146 | struct clk *clk; | 160 | struct clk *clk; |
147 | unsigned char spsr; | 161 | unsigned char spsr; |
162 | const struct spi_ops *ops; | ||
148 | 163 | ||
149 | /* for dmaengine */ | 164 | /* for dmaengine */ |
150 | struct dma_chan *chan_tx; | 165 | struct dma_chan *chan_tx; |
@@ -165,6 +180,11 @@ static void rspi_write16(struct rspi_data *rspi, u16 data, u16 offset) | |||
165 | iowrite16(data, rspi->addr + offset); | 180 | iowrite16(data, rspi->addr + offset); |
166 | } | 181 | } |
167 | 182 | ||
183 | static void rspi_write32(struct rspi_data *rspi, u32 data, u16 offset) | ||
184 | { | ||
185 | iowrite32(data, rspi->addr + offset); | ||
186 | } | ||
187 | |||
168 | static u8 rspi_read8(struct rspi_data *rspi, u16 offset) | 188 | static u8 rspi_read8(struct rspi_data *rspi, u16 offset) |
169 | { | 189 | { |
170 | return ioread8(rspi->addr + offset); | 190 | return ioread8(rspi->addr + offset); |
@@ -175,17 +195,103 @@ static u16 rspi_read16(struct rspi_data *rspi, u16 offset) | |||
175 | return ioread16(rspi->addr + offset); | 195 | return ioread16(rspi->addr + offset); |
176 | } | 196 | } |
177 | 197 | ||
178 | static unsigned char rspi_calc_spbr(struct rspi_data *rspi) | 198 | /* optional functions */ |
199 | struct spi_ops { | ||
200 | int (*set_config_register)(struct rspi_data *rspi, int access_size); | ||
201 | int (*send_pio)(struct rspi_data *rspi, struct spi_message *mesg, | ||
202 | struct spi_transfer *t); | ||
203 | int (*receive_pio)(struct rspi_data *rspi, struct spi_message *mesg, | ||
204 | struct spi_transfer *t); | ||
205 | |||
206 | }; | ||
207 | |||
208 | /* | ||
209 | * functions for RSPI | ||
210 | */ | ||
211 | static int rspi_set_config_register(struct rspi_data *rspi, int access_size) | ||
212 | { | ||
213 | int spbr; | ||
214 | |||
215 | /* Sets output mode(CMOS) and MOSI signal(from previous transfer) */ | ||
216 | rspi_write8(rspi, 0x00, RSPI_SPPCR); | ||
217 | |||
218 | /* Sets transfer bit rate */ | ||
219 | spbr = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz) - 1; | ||
220 | rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR); | ||
221 | |||
222 | /* Sets number of frames to be used: 1 frame */ | ||
223 | rspi_write8(rspi, 0x00, RSPI_SPDCR); | ||
224 | |||
225 | /* Sets RSPCK, SSL, next-access delay value */ | ||
226 | rspi_write8(rspi, 0x00, RSPI_SPCKD); | ||
227 | rspi_write8(rspi, 0x00, RSPI_SSLND); | ||
228 | rspi_write8(rspi, 0x00, RSPI_SPND); | ||
229 | |||
230 | /* Sets parity, interrupt mask */ | ||
231 | rspi_write8(rspi, 0x00, RSPI_SPCR2); | ||
232 | |||
233 | /* Sets SPCMD */ | ||
234 | rspi_write16(rspi, SPCMD_SPB_8_TO_16(access_size) | SPCMD_SSLKP, | ||
235 | RSPI_SPCMD0); | ||
236 | |||
237 | /* Sets RSPI mode */ | ||
238 | rspi_write8(rspi, SPCR_MSTR, RSPI_SPCR); | ||
239 | |||
240 | return 0; | ||
241 | } | ||
242 | |||
243 | /* | ||
244 | * functions for QSPI | ||
245 | */ | ||
246 | static int qspi_set_config_register(struct rspi_data *rspi, int access_size) | ||
179 | { | 247 | { |
180 | int tmp; | 248 | u16 spcmd; |
181 | unsigned char spbr; | 249 | int spbr; |
250 | |||
251 | /* Sets output mode(CMOS) and MOSI signal(from previous transfer) */ | ||
252 | rspi_write8(rspi, 0x00, RSPI_SPPCR); | ||
253 | |||
254 | /* Sets transfer bit rate */ | ||
255 | spbr = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz); | ||
256 | rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR); | ||
257 | |||
258 | /* Sets number of frames to be used: 1 frame */ | ||
259 | rspi_write8(rspi, 0x00, RSPI_SPDCR); | ||
260 | |||
261 | /* Sets RSPCK, SSL, next-access delay value */ | ||
262 | rspi_write8(rspi, 0x00, RSPI_SPCKD); | ||
263 | rspi_write8(rspi, 0x00, RSPI_SSLND); | ||
264 | rspi_write8(rspi, 0x00, RSPI_SPND); | ||
265 | |||
266 | /* Data Length Setting */ | ||
267 | if (access_size == 8) | ||
268 | spcmd = SPCMD_SPB_8BIT; | ||
269 | else if (access_size == 16) | ||
270 | spcmd = SPCMD_SPB_16BIT; | ||
271 | else if (access_size == 32) | ||
272 | spcmd = SPCMD_SPB_32BIT; | ||
273 | |||
274 | spcmd |= SPCMD_SCKDEN | SPCMD_SLNDEN | SPCMD_SSLKP | SPCMD_SPNDEN; | ||
275 | |||
276 | /* Resets transfer data length */ | ||
277 | rspi_write32(rspi, 0, QSPI_SPBMUL0); | ||
278 | |||
279 | /* Resets transmit and receive buffer */ | ||
280 | rspi_write8(rspi, SPBFCR_TXRST | SPBFCR_RXRST, QSPI_SPBFCR); | ||
281 | /* Sets buffer to allow normal operation */ | ||
282 | rspi_write8(rspi, 0x00, QSPI_SPBFCR); | ||
283 | |||
284 | /* Sets SPCMD */ | ||
285 | rspi_write16(rspi, spcmd, RSPI_SPCMD0); | ||
182 | 286 | ||
183 | tmp = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz) - 1; | 287 | /* Enables SPI function in a master mode */ |
184 | spbr = clamp(tmp, 0, 255); | 288 | rspi_write8(rspi, SPCR_SPE | SPCR_MSTR, RSPI_SPCR); |
185 | 289 | ||
186 | return spbr; | 290 | return 0; |
187 | } | 291 | } |
188 | 292 | ||
293 | #define set_config_register(spi, n) spi->ops->set_config_register(spi, n) | ||
294 | |||
189 | static void rspi_enable_irq(struct rspi_data *rspi, u8 enable) | 295 | static void rspi_enable_irq(struct rspi_data *rspi, u8 enable) |
190 | { | 296 | { |
191 | rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | enable, RSPI_SPCR); | 297 | rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | enable, RSPI_SPCR); |
@@ -220,54 +326,60 @@ static void rspi_negate_ssl(struct rspi_data *rspi) | |||
220 | rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~SPCR_SPE, RSPI_SPCR); | 326 | rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~SPCR_SPE, RSPI_SPCR); |
221 | } | 327 | } |
222 | 328 | ||
223 | static int rspi_set_config_register(struct rspi_data *rspi, int access_size) | 329 | static int rspi_send_pio(struct rspi_data *rspi, struct spi_message *mesg, |
330 | struct spi_transfer *t) | ||
224 | { | 331 | { |
225 | /* Sets output mode(CMOS) and MOSI signal(from previous transfer) */ | 332 | int remain = t->len; |
226 | rspi_write8(rspi, 0x00, RSPI_SPPCR); | 333 | u8 *data; |
227 | |||
228 | /* Sets transfer bit rate */ | ||
229 | rspi_write8(rspi, rspi_calc_spbr(rspi), RSPI_SPBR); | ||
230 | |||
231 | /* Sets number of frames to be used: 1 frame */ | ||
232 | rspi_write8(rspi, 0x00, RSPI_SPDCR); | ||
233 | 334 | ||
234 | /* Sets RSPCK, SSL, next-access delay value */ | 335 | data = (u8 *)t->tx_buf; |
235 | rspi_write8(rspi, 0x00, RSPI_SPCKD); | 336 | while (remain > 0) { |
236 | rspi_write8(rspi, 0x00, RSPI_SSLND); | 337 | rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | SPCR_TXMD, |
237 | rspi_write8(rspi, 0x00, RSPI_SPND); | 338 | RSPI_SPCR); |
238 | 339 | ||
239 | /* Sets parity, interrupt mask */ | 340 | if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) { |
240 | rspi_write8(rspi, 0x00, RSPI_SPCR2); | 341 | dev_err(&rspi->master->dev, |
342 | "%s: tx empty timeout\n", __func__); | ||
343 | return -ETIMEDOUT; | ||
344 | } | ||
241 | 345 | ||
242 | /* Sets SPCMD */ | 346 | rspi_write16(rspi, *data, RSPI_SPDR); |
243 | rspi_write16(rspi, SPCMD_SPB_8_TO_16(access_size) | SPCMD_SSLKP, | 347 | data++; |
244 | RSPI_SPCMD0); | 348 | remain--; |
349 | } | ||
245 | 350 | ||
246 | /* Sets RSPI mode */ | 351 | /* Waiting for the last transmition */ |
247 | rspi_write8(rspi, SPCR_MSTR, RSPI_SPCR); | 352 | rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE); |
248 | 353 | ||
249 | return 0; | 354 | return 0; |
250 | } | 355 | } |
251 | 356 | ||
252 | static int rspi_send_pio(struct rspi_data *rspi, struct spi_message *mesg, | 357 | static int qspi_send_pio(struct rspi_data *rspi, struct spi_message *mesg, |
253 | struct spi_transfer *t) | 358 | struct spi_transfer *t) |
254 | { | 359 | { |
255 | int remain = t->len; | 360 | int remain = t->len; |
256 | u8 *data; | 361 | u8 *data; |
257 | 362 | ||
363 | rspi_write8(rspi, SPBFCR_TXRST, QSPI_SPBFCR); | ||
364 | rspi_write8(rspi, 0x00, QSPI_SPBFCR); | ||
365 | |||
258 | data = (u8 *)t->tx_buf; | 366 | data = (u8 *)t->tx_buf; |
259 | while (remain > 0) { | 367 | while (remain > 0) { |
260 | rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | SPCR_TXMD, | ||
261 | RSPI_SPCR); | ||
262 | 368 | ||
263 | if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) { | 369 | if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) { |
264 | dev_err(&rspi->master->dev, | 370 | dev_err(&rspi->master->dev, |
265 | "%s: tx empty timeout\n", __func__); | 371 | "%s: tx empty timeout\n", __func__); |
266 | return -ETIMEDOUT; | 372 | return -ETIMEDOUT; |
267 | } | 373 | } |
374 | rspi_write8(rspi, *data++, RSPI_SPDR); | ||
375 | |||
376 | if (rspi_wait_for_interrupt(rspi, SPSR_SPRF, SPCR_SPRIE) < 0) { | ||
377 | dev_err(&rspi->master->dev, | ||
378 | "%s: receive timeout\n", __func__); | ||
379 | return -ETIMEDOUT; | ||
380 | } | ||
381 | rspi_read8(rspi, RSPI_SPDR); | ||
268 | 382 | ||
269 | rspi_write16(rspi, *data, RSPI_SPDR); | ||
270 | data++; | ||
271 | remain--; | 383 | remain--; |
272 | } | 384 | } |
273 | 385 | ||
@@ -277,6 +389,8 @@ static int rspi_send_pio(struct rspi_data *rspi, struct spi_message *mesg, | |||
277 | return 0; | 389 | return 0; |
278 | } | 390 | } |
279 | 391 | ||
392 | #define send_pio(spi, mesg, t) spi->ops->send_pio(spi, mesg, t) | ||
393 | |||
280 | static void rspi_dma_complete(void *arg) | 394 | static void rspi_dma_complete(void *arg) |
281 | { | 395 | { |
282 | struct rspi_data *rspi = arg; | 396 | struct rspi_data *rspi = arg; |
@@ -442,6 +556,51 @@ static int rspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg, | |||
442 | return 0; | 556 | return 0; |
443 | } | 557 | } |
444 | 558 | ||
559 | static void qspi_receive_init(struct rspi_data *rspi) | ||
560 | { | ||
561 | unsigned char spsr; | ||
562 | |||
563 | spsr = rspi_read8(rspi, RSPI_SPSR); | ||
564 | if (spsr & SPSR_SPRF) | ||
565 | rspi_read8(rspi, RSPI_SPDR); /* dummy read */ | ||
566 | rspi_write8(rspi, SPBFCR_TXRST | SPBFCR_RXRST, QSPI_SPBFCR); | ||
567 | rspi_write8(rspi, 0x00, QSPI_SPBFCR); | ||
568 | } | ||
569 | |||
570 | static int qspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg, | ||
571 | struct spi_transfer *t) | ||
572 | { | ||
573 | int remain = t->len; | ||
574 | u8 *data; | ||
575 | |||
576 | qspi_receive_init(rspi); | ||
577 | |||
578 | data = (u8 *)t->rx_buf; | ||
579 | while (remain > 0) { | ||
580 | |||
581 | if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) { | ||
582 | dev_err(&rspi->master->dev, | ||
583 | "%s: tx empty timeout\n", __func__); | ||
584 | return -ETIMEDOUT; | ||
585 | } | ||
586 | /* dummy write for generate clock */ | ||
587 | rspi_write8(rspi, 0x00, RSPI_SPDR); | ||
588 | |||
589 | if (rspi_wait_for_interrupt(rspi, SPSR_SPRF, SPCR_SPRIE) < 0) { | ||
590 | dev_err(&rspi->master->dev, | ||
591 | "%s: receive timeout\n", __func__); | ||
592 | return -ETIMEDOUT; | ||
593 | } | ||
594 | /* SPDR allows 8, 16 or 32-bit access */ | ||
595 | *data++ = rspi_read8(rspi, RSPI_SPDR); | ||
596 | remain--; | ||
597 | } | ||
598 | |||
599 | return 0; | ||
600 | } | ||
601 | |||
602 | #define receive_pio(spi, mesg, t) spi->ops->receive_pio(spi, mesg, t) | ||
603 | |||
445 | static int rspi_receive_dma(struct rspi_data *rspi, struct spi_transfer *t) | 604 | static int rspi_receive_dma(struct rspi_data *rspi, struct spi_transfer *t) |
446 | { | 605 | { |
447 | struct scatterlist sg, sg_dummy; | 606 | struct scatterlist sg, sg_dummy; |
@@ -581,7 +740,7 @@ static void rspi_work(struct work_struct *work) | |||
581 | if (rspi_is_dma(rspi, t)) | 740 | if (rspi_is_dma(rspi, t)) |
582 | ret = rspi_send_dma(rspi, t); | 741 | ret = rspi_send_dma(rspi, t); |
583 | else | 742 | else |
584 | ret = rspi_send_pio(rspi, mesg, t); | 743 | ret = send_pio(rspi, mesg, t); |
585 | if (ret < 0) | 744 | if (ret < 0) |
586 | goto error; | 745 | goto error; |
587 | } | 746 | } |
@@ -589,7 +748,7 @@ static void rspi_work(struct work_struct *work) | |||
589 | if (rspi_is_dma(rspi, t)) | 748 | if (rspi_is_dma(rspi, t)) |
590 | ret = rspi_receive_dma(rspi, t); | 749 | ret = rspi_receive_dma(rspi, t); |
591 | else | 750 | else |
592 | ret = rspi_receive_pio(rspi, mesg, t); | 751 | ret = receive_pio(rspi, mesg, t); |
593 | if (ret < 0) | 752 | if (ret < 0) |
594 | goto error; | 753 | goto error; |
595 | } | 754 | } |
@@ -616,7 +775,7 @@ static int rspi_setup(struct spi_device *spi) | |||
616 | spi->bits_per_word = 8; | 775 | spi->bits_per_word = 8; |
617 | rspi->max_speed_hz = spi->max_speed_hz; | 776 | rspi->max_speed_hz = spi->max_speed_hz; |
618 | 777 | ||
619 | rspi_set_config_register(rspi, 8); | 778 | set_config_register(rspi, 8); |
620 | 779 | ||
621 | return 0; | 780 | return 0; |
622 | } | 781 | } |
@@ -726,14 +885,13 @@ static void rspi_release_dma(struct rspi_data *rspi) | |||
726 | 885 | ||
727 | static int rspi_remove(struct platform_device *pdev) | 886 | static int rspi_remove(struct platform_device *pdev) |
728 | { | 887 | { |
729 | struct rspi_data *rspi = spi_master_get(platform_get_drvdata(pdev)); | 888 | struct rspi_data *rspi = platform_get_drvdata(pdev); |
730 | 889 | ||
731 | spi_unregister_master(rspi->master); | 890 | spi_unregister_master(rspi->master); |
732 | rspi_release_dma(rspi); | 891 | rspi_release_dma(rspi); |
733 | free_irq(platform_get_irq(pdev, 0), rspi); | 892 | free_irq(platform_get_irq(pdev, 0), rspi); |
734 | clk_put(rspi->clk); | 893 | clk_put(rspi->clk); |
735 | iounmap(rspi->addr); | 894 | iounmap(rspi->addr); |
736 | spi_master_put(rspi->master); | ||
737 | 895 | ||
738 | return 0; | 896 | return 0; |
739 | } | 897 | } |
@@ -745,7 +903,16 @@ static int rspi_probe(struct platform_device *pdev) | |||
745 | struct rspi_data *rspi; | 903 | struct rspi_data *rspi; |
746 | int ret, irq; | 904 | int ret, irq; |
747 | char clk_name[16]; | 905 | char clk_name[16]; |
748 | 906 | struct rspi_plat_data *rspi_pd = pdev->dev.platform_data; | |
907 | const struct spi_ops *ops; | ||
908 | const struct platform_device_id *id_entry = pdev->id_entry; | ||
909 | |||
910 | ops = (struct spi_ops *)id_entry->driver_data; | ||
911 | /* ops parameter check */ | ||
912 | if (!ops->set_config_register) { | ||
913 | dev_err(&pdev->dev, "there is no set_config_register\n"); | ||
914 | return -ENODEV; | ||
915 | } | ||
749 | /* get base addr */ | 916 | /* get base addr */ |
750 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 917 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
751 | if (unlikely(res == NULL)) { | 918 | if (unlikely(res == NULL)) { |
@@ -767,7 +934,7 @@ static int rspi_probe(struct platform_device *pdev) | |||
767 | 934 | ||
768 | rspi = spi_master_get_devdata(master); | 935 | rspi = spi_master_get_devdata(master); |
769 | platform_set_drvdata(pdev, rspi); | 936 | platform_set_drvdata(pdev, rspi); |
770 | 937 | rspi->ops = ops; | |
771 | rspi->master = master; | 938 | rspi->master = master; |
772 | rspi->addr = ioremap(res->start, resource_size(res)); | 939 | rspi->addr = ioremap(res->start, resource_size(res)); |
773 | if (rspi->addr == NULL) { | 940 | if (rspi->addr == NULL) { |
@@ -776,7 +943,7 @@ static int rspi_probe(struct platform_device *pdev) | |||
776 | goto error1; | 943 | goto error1; |
777 | } | 944 | } |
778 | 945 | ||
779 | snprintf(clk_name, sizeof(clk_name), "rspi%d", pdev->id); | 946 | snprintf(clk_name, sizeof(clk_name), "%s%d", id_entry->name, pdev->id); |
780 | rspi->clk = clk_get(&pdev->dev, clk_name); | 947 | rspi->clk = clk_get(&pdev->dev, clk_name); |
781 | if (IS_ERR(rspi->clk)) { | 948 | if (IS_ERR(rspi->clk)) { |
782 | dev_err(&pdev->dev, "cannot get clock\n"); | 949 | dev_err(&pdev->dev, "cannot get clock\n"); |
@@ -790,7 +957,10 @@ static int rspi_probe(struct platform_device *pdev) | |||
790 | INIT_WORK(&rspi->ws, rspi_work); | 957 | INIT_WORK(&rspi->ws, rspi_work); |
791 | init_waitqueue_head(&rspi->wait); | 958 | init_waitqueue_head(&rspi->wait); |
792 | 959 | ||
793 | master->num_chipselect = 2; | 960 | master->num_chipselect = rspi_pd->num_chipselect; |
961 | if (!master->num_chipselect) | ||
962 | master->num_chipselect = 2; /* default */ | ||
963 | |||
794 | master->bus_num = pdev->id; | 964 | master->bus_num = pdev->id; |
795 | master->setup = rspi_setup; | 965 | master->setup = rspi_setup; |
796 | master->transfer = rspi_transfer; | 966 | master->transfer = rspi_transfer; |
@@ -832,11 +1002,32 @@ error1: | |||
832 | return ret; | 1002 | return ret; |
833 | } | 1003 | } |
834 | 1004 | ||
1005 | static struct spi_ops rspi_ops = { | ||
1006 | .set_config_register = rspi_set_config_register, | ||
1007 | .send_pio = rspi_send_pio, | ||
1008 | .receive_pio = rspi_receive_pio, | ||
1009 | }; | ||
1010 | |||
1011 | static struct spi_ops qspi_ops = { | ||
1012 | .set_config_register = qspi_set_config_register, | ||
1013 | .send_pio = qspi_send_pio, | ||
1014 | .receive_pio = qspi_receive_pio, | ||
1015 | }; | ||
1016 | |||
1017 | static struct platform_device_id spi_driver_ids[] = { | ||
1018 | { "rspi", (kernel_ulong_t)&rspi_ops }, | ||
1019 | { "qspi", (kernel_ulong_t)&qspi_ops }, | ||
1020 | {}, | ||
1021 | }; | ||
1022 | |||
1023 | MODULE_DEVICE_TABLE(platform, spi_driver_ids); | ||
1024 | |||
835 | static struct platform_driver rspi_driver = { | 1025 | static struct platform_driver rspi_driver = { |
836 | .probe = rspi_probe, | 1026 | .probe = rspi_probe, |
837 | .remove = rspi_remove, | 1027 | .remove = rspi_remove, |
1028 | .id_table = spi_driver_ids, | ||
838 | .driver = { | 1029 | .driver = { |
839 | .name = "rspi", | 1030 | .name = "renesas_spi", |
840 | .owner = THIS_MODULE, | 1031 | .owner = THIS_MODULE, |
841 | }, | 1032 | }, |
842 | }; | 1033 | }; |
diff --git a/drivers/spi/spi-s3c24xx.c b/drivers/spi/spi-s3c24xx.c index ce318d95a6ee..0dc32a11bd3c 100644 --- a/drivers/spi/spi-s3c24xx.c +++ b/drivers/spi/spi-s3c24xx.c | |||
@@ -280,7 +280,7 @@ static inline u32 ack_bit(unsigned int irq) | |||
280 | * so the caller does not need to do anything more than start the transfer | 280 | * so the caller does not need to do anything more than start the transfer |
281 | * as normal, since the IRQ will have been re-routed to the FIQ handler. | 281 | * as normal, since the IRQ will have been re-routed to the FIQ handler. |
282 | */ | 282 | */ |
283 | void s3c24xx_spi_tryfiq(struct s3c24xx_spi *hw) | 283 | static void s3c24xx_spi_tryfiq(struct s3c24xx_spi *hw) |
284 | { | 284 | { |
285 | struct pt_regs regs; | 285 | struct pt_regs regs; |
286 | enum spi_fiq_mode mode; | 286 | enum spi_fiq_mode mode; |
@@ -524,7 +524,7 @@ static int s3c24xx_spi_probe(struct platform_device *pdev) | |||
524 | hw = spi_master_get_devdata(master); | 524 | hw = spi_master_get_devdata(master); |
525 | memset(hw, 0, sizeof(struct s3c24xx_spi)); | 525 | memset(hw, 0, sizeof(struct s3c24xx_spi)); |
526 | 526 | ||
527 | hw->master = spi_master_get(master); | 527 | hw->master = master; |
528 | hw->pdata = pdata = dev_get_platdata(&pdev->dev); | 528 | hw->pdata = pdata = dev_get_platdata(&pdev->dev); |
529 | hw->dev = &pdev->dev; | 529 | hw->dev = &pdev->dev; |
530 | 530 | ||
diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 512b8893893b..4c4b0a1219a7 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c | |||
@@ -205,7 +205,6 @@ struct s3c64xx_spi_driver_data { | |||
205 | #endif | 205 | #endif |
206 | struct s3c64xx_spi_port_config *port_conf; | 206 | struct s3c64xx_spi_port_config *port_conf; |
207 | unsigned int port_id; | 207 | unsigned int port_id; |
208 | unsigned long gpios[4]; | ||
209 | bool cs_gpio; | 208 | bool cs_gpio; |
210 | }; | 209 | }; |
211 | 210 | ||
@@ -559,25 +558,18 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd, | |||
559 | static inline void enable_cs(struct s3c64xx_spi_driver_data *sdd, | 558 | static inline void enable_cs(struct s3c64xx_spi_driver_data *sdd, |
560 | struct spi_device *spi) | 559 | struct spi_device *spi) |
561 | { | 560 | { |
562 | struct s3c64xx_spi_csinfo *cs; | ||
563 | |||
564 | if (sdd->tgl_spi != NULL) { /* If last device toggled after mssg */ | 561 | if (sdd->tgl_spi != NULL) { /* If last device toggled after mssg */ |
565 | if (sdd->tgl_spi != spi) { /* if last mssg on diff device */ | 562 | if (sdd->tgl_spi != spi) { /* if last mssg on diff device */ |
566 | /* Deselect the last toggled device */ | 563 | /* Deselect the last toggled device */ |
567 | cs = sdd->tgl_spi->controller_data; | 564 | if (spi->cs_gpio >= 0) |
568 | if (sdd->cs_gpio) | 565 | gpio_set_value(spi->cs_gpio, |
569 | gpio_set_value(cs->line, | ||
570 | spi->mode & SPI_CS_HIGH ? 0 : 1); | 566 | spi->mode & SPI_CS_HIGH ? 0 : 1); |
571 | } | 567 | } |
572 | sdd->tgl_spi = NULL; | 568 | sdd->tgl_spi = NULL; |
573 | } | 569 | } |
574 | 570 | ||
575 | cs = spi->controller_data; | 571 | if (spi->cs_gpio >= 0) |
576 | if (sdd->cs_gpio) | 572 | gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH ? 1 : 0); |
577 | gpio_set_value(cs->line, spi->mode & SPI_CS_HIGH ? 1 : 0); | ||
578 | |||
579 | /* Start the signals */ | ||
580 | writel(0, sdd->regs + S3C64XX_SPI_SLAVE_SEL); | ||
581 | } | 573 | } |
582 | 574 | ||
583 | static u32 s3c64xx_spi_wait_for_timeout(struct s3c64xx_spi_driver_data *sdd, | 575 | static u32 s3c64xx_spi_wait_for_timeout(struct s3c64xx_spi_driver_data *sdd, |
@@ -702,16 +694,11 @@ static int wait_for_xfer(struct s3c64xx_spi_driver_data *sdd, | |||
702 | static inline void disable_cs(struct s3c64xx_spi_driver_data *sdd, | 694 | static inline void disable_cs(struct s3c64xx_spi_driver_data *sdd, |
703 | struct spi_device *spi) | 695 | struct spi_device *spi) |
704 | { | 696 | { |
705 | struct s3c64xx_spi_csinfo *cs = spi->controller_data; | ||
706 | |||
707 | if (sdd->tgl_spi == spi) | 697 | if (sdd->tgl_spi == spi) |
708 | sdd->tgl_spi = NULL; | 698 | sdd->tgl_spi = NULL; |
709 | 699 | ||
710 | if (sdd->cs_gpio) | 700 | if (spi->cs_gpio >= 0) |
711 | gpio_set_value(cs->line, spi->mode & SPI_CS_HIGH ? 0 : 1); | 701 | gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH ? 0 : 1); |
712 | |||
713 | /* Quiese the signals */ | ||
714 | writel(S3C64XX_SPI_SLAVE_SIG_INACT, sdd->regs + S3C64XX_SPI_SLAVE_SEL); | ||
715 | } | 702 | } |
716 | 703 | ||
717 | static void s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd) | 704 | static void s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd) |
@@ -862,16 +849,12 @@ static void s3c64xx_spi_unmap_mssg(struct s3c64xx_spi_driver_data *sdd, | |||
862 | } | 849 | } |
863 | } | 850 | } |
864 | 851 | ||
865 | static int s3c64xx_spi_transfer_one_message(struct spi_master *master, | 852 | static int s3c64xx_spi_prepare_message(struct spi_master *master, |
866 | struct spi_message *msg) | 853 | struct spi_message *msg) |
867 | { | 854 | { |
868 | struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); | 855 | struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); |
869 | struct spi_device *spi = msg->spi; | 856 | struct spi_device *spi = msg->spi; |
870 | struct s3c64xx_spi_csinfo *cs = spi->controller_data; | 857 | struct s3c64xx_spi_csinfo *cs = spi->controller_data; |
871 | struct spi_transfer *xfer; | ||
872 | int status = 0, cs_toggle = 0; | ||
873 | u32 speed; | ||
874 | u8 bpw; | ||
875 | 858 | ||
876 | /* If Master's(controller) state differs from that needed by Slave */ | 859 | /* If Master's(controller) state differs from that needed by Slave */ |
877 | if (sdd->cur_speed != spi->max_speed_hz | 860 | if (sdd->cur_speed != spi->max_speed_hz |
@@ -887,106 +870,98 @@ static int s3c64xx_spi_transfer_one_message(struct spi_master *master, | |||
887 | if (s3c64xx_spi_map_mssg(sdd, msg)) { | 870 | if (s3c64xx_spi_map_mssg(sdd, msg)) { |
888 | dev_err(&spi->dev, | 871 | dev_err(&spi->dev, |
889 | "Xfer: Unable to map message buffers!\n"); | 872 | "Xfer: Unable to map message buffers!\n"); |
890 | status = -ENOMEM; | 873 | return -ENOMEM; |
891 | goto out; | ||
892 | } | 874 | } |
893 | 875 | ||
894 | /* Configure feedback delay */ | 876 | /* Configure feedback delay */ |
895 | writel(cs->fb_delay & 0x3, sdd->regs + S3C64XX_SPI_FB_CLK); | 877 | writel(cs->fb_delay & 0x3, sdd->regs + S3C64XX_SPI_FB_CLK); |
896 | 878 | ||
897 | list_for_each_entry(xfer, &msg->transfers, transfer_list) { | 879 | return 0; |
898 | 880 | } | |
899 | unsigned long flags; | ||
900 | int use_dma; | ||
901 | |||
902 | INIT_COMPLETION(sdd->xfer_completion); | ||
903 | |||
904 | /* Only BPW and Speed may change across transfers */ | ||
905 | bpw = xfer->bits_per_word; | ||
906 | speed = xfer->speed_hz ? : spi->max_speed_hz; | ||
907 | |||
908 | if (xfer->len % (bpw / 8)) { | ||
909 | dev_err(&spi->dev, | ||
910 | "Xfer length(%u) not a multiple of word size(%u)\n", | ||
911 | xfer->len, bpw / 8); | ||
912 | status = -EIO; | ||
913 | goto out; | ||
914 | } | ||
915 | 881 | ||
916 | if (bpw != sdd->cur_bpw || speed != sdd->cur_speed) { | 882 | static int s3c64xx_spi_transfer_one(struct spi_master *master, |
917 | sdd->cur_bpw = bpw; | 883 | struct spi_device *spi, |
918 | sdd->cur_speed = speed; | 884 | struct spi_transfer *xfer) |
919 | s3c64xx_spi_config(sdd); | 885 | { |
920 | } | 886 | struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); |
887 | int status; | ||
888 | u32 speed; | ||
889 | u8 bpw; | ||
890 | unsigned long flags; | ||
891 | int use_dma; | ||
921 | 892 | ||
922 | /* Polling method for xfers not bigger than FIFO capacity */ | 893 | reinit_completion(&sdd->xfer_completion); |
923 | use_dma = 0; | ||
924 | if (!is_polling(sdd) && | ||
925 | (sdd->rx_dma.ch && sdd->tx_dma.ch && | ||
926 | (xfer->len > ((FIFO_LVL_MASK(sdd) >> 1) + 1)))) | ||
927 | use_dma = 1; | ||
928 | 894 | ||
929 | spin_lock_irqsave(&sdd->lock, flags); | 895 | /* Only BPW and Speed may change across transfers */ |
896 | bpw = xfer->bits_per_word; | ||
897 | speed = xfer->speed_hz ? : spi->max_speed_hz; | ||
930 | 898 | ||
931 | /* Pending only which is to be done */ | 899 | if (xfer->len % (bpw / 8)) { |
932 | sdd->state &= ~RXBUSY; | 900 | dev_err(&spi->dev, |
933 | sdd->state &= ~TXBUSY; | 901 | "Xfer length(%u) not a multiple of word size(%u)\n", |
902 | xfer->len, bpw / 8); | ||
903 | return -EIO; | ||
904 | } | ||
934 | 905 | ||
935 | enable_datapath(sdd, spi, xfer, use_dma); | 906 | if (bpw != sdd->cur_bpw || speed != sdd->cur_speed) { |
907 | sdd->cur_bpw = bpw; | ||
908 | sdd->cur_speed = speed; | ||
909 | s3c64xx_spi_config(sdd); | ||
910 | } | ||
936 | 911 | ||
937 | /* Slave Select */ | 912 | /* Polling method for xfers not bigger than FIFO capacity */ |
938 | enable_cs(sdd, spi); | 913 | use_dma = 0; |
914 | if (!is_polling(sdd) && | ||
915 | (sdd->rx_dma.ch && sdd->tx_dma.ch && | ||
916 | (xfer->len > ((FIFO_LVL_MASK(sdd) >> 1) + 1)))) | ||
917 | use_dma = 1; | ||
939 | 918 | ||
940 | spin_unlock_irqrestore(&sdd->lock, flags); | 919 | spin_lock_irqsave(&sdd->lock, flags); |
941 | 920 | ||
942 | status = wait_for_xfer(sdd, xfer, use_dma); | 921 | /* Pending only which is to be done */ |
922 | sdd->state &= ~RXBUSY; | ||
923 | sdd->state &= ~TXBUSY; | ||
943 | 924 | ||
944 | if (status) { | 925 | enable_datapath(sdd, spi, xfer, use_dma); |
945 | dev_err(&spi->dev, "I/O Error: rx-%d tx-%d res:rx-%c tx-%c len-%d\n", | ||
946 | xfer->rx_buf ? 1 : 0, xfer->tx_buf ? 1 : 0, | ||
947 | (sdd->state & RXBUSY) ? 'f' : 'p', | ||
948 | (sdd->state & TXBUSY) ? 'f' : 'p', | ||
949 | xfer->len); | ||
950 | 926 | ||
951 | if (use_dma) { | 927 | /* Start the signals */ |
952 | if (xfer->tx_buf != NULL | 928 | writel(0, sdd->regs + S3C64XX_SPI_SLAVE_SEL); |
953 | && (sdd->state & TXBUSY)) | ||
954 | s3c64xx_spi_dma_stop(sdd, &sdd->tx_dma); | ||
955 | if (xfer->rx_buf != NULL | ||
956 | && (sdd->state & RXBUSY)) | ||
957 | s3c64xx_spi_dma_stop(sdd, &sdd->rx_dma); | ||
958 | } | ||
959 | 929 | ||
960 | goto out; | 930 | /* Start the signals */ |
961 | } | 931 | writel(0, sdd->regs + S3C64XX_SPI_SLAVE_SEL); |
962 | 932 | ||
963 | if (xfer->delay_usecs) | 933 | spin_unlock_irqrestore(&sdd->lock, flags); |
964 | udelay(xfer->delay_usecs); | ||
965 | 934 | ||
966 | if (xfer->cs_change) { | 935 | status = wait_for_xfer(sdd, xfer, use_dma); |
967 | /* Hint that the next mssg is gonna be | 936 | |
968 | for the same device */ | 937 | if (status) { |
969 | if (list_is_last(&xfer->transfer_list, | 938 | dev_err(&spi->dev, "I/O Error: rx-%d tx-%d res:rx-%c tx-%c len-%d\n", |
970 | &msg->transfers)) | 939 | xfer->rx_buf ? 1 : 0, xfer->tx_buf ? 1 : 0, |
971 | cs_toggle = 1; | 940 | (sdd->state & RXBUSY) ? 'f' : 'p', |
941 | (sdd->state & TXBUSY) ? 'f' : 'p', | ||
942 | xfer->len); | ||
943 | |||
944 | if (use_dma) { | ||
945 | if (xfer->tx_buf != NULL | ||
946 | && (sdd->state & TXBUSY)) | ||
947 | s3c64xx_spi_dma_stop(sdd, &sdd->tx_dma); | ||
948 | if (xfer->rx_buf != NULL | ||
949 | && (sdd->state & RXBUSY)) | ||
950 | s3c64xx_spi_dma_stop(sdd, &sdd->rx_dma); | ||
972 | } | 951 | } |
973 | 952 | } else { | |
974 | msg->actual_length += xfer->len; | ||
975 | |||
976 | flush_fifo(sdd); | 953 | flush_fifo(sdd); |
977 | } | 954 | } |
978 | 955 | ||
979 | out: | 956 | return status; |
980 | if (!cs_toggle || status) | 957 | } |
981 | disable_cs(sdd, spi); | ||
982 | else | ||
983 | sdd->tgl_spi = spi; | ||
984 | |||
985 | s3c64xx_spi_unmap_mssg(sdd, msg); | ||
986 | 958 | ||
987 | msg->status = status; | 959 | static int s3c64xx_spi_unprepare_message(struct spi_master *master, |
960 | struct spi_message *msg) | ||
961 | { | ||
962 | struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); | ||
988 | 963 | ||
989 | spi_finalize_current_message(master); | 964 | s3c64xx_spi_unmap_mssg(sdd, msg); |
990 | 965 | ||
991 | return 0; | 966 | return 0; |
992 | } | 967 | } |
@@ -1071,6 +1046,8 @@ static int s3c64xx_spi_setup(struct spi_device *spi) | |||
1071 | cs->line, err); | 1046 | cs->line, err); |
1072 | goto err_gpio_req; | 1047 | goto err_gpio_req; |
1073 | } | 1048 | } |
1049 | |||
1050 | spi->cs_gpio = cs->line; | ||
1074 | } | 1051 | } |
1075 | 1052 | ||
1076 | spi_set_ctldata(spi, cs); | 1053 | spi_set_ctldata(spi, cs); |
@@ -1117,11 +1094,14 @@ static int s3c64xx_spi_setup(struct spi_device *spi) | |||
1117 | } | 1094 | } |
1118 | 1095 | ||
1119 | pm_runtime_put(&sdd->pdev->dev); | 1096 | pm_runtime_put(&sdd->pdev->dev); |
1097 | writel(S3C64XX_SPI_SLAVE_SIG_INACT, sdd->regs + S3C64XX_SPI_SLAVE_SEL); | ||
1120 | disable_cs(sdd, spi); | 1098 | disable_cs(sdd, spi); |
1121 | return 0; | 1099 | return 0; |
1122 | 1100 | ||
1123 | setup_exit: | 1101 | setup_exit: |
1102 | pm_runtime_put(&sdd->pdev->dev); | ||
1124 | /* setup() returns with device de-selected */ | 1103 | /* setup() returns with device de-selected */ |
1104 | writel(S3C64XX_SPI_SLAVE_SIG_INACT, sdd->regs + S3C64XX_SPI_SLAVE_SEL); | ||
1125 | disable_cs(sdd, spi); | 1105 | disable_cs(sdd, spi); |
1126 | 1106 | ||
1127 | gpio_free(cs->line); | 1107 | gpio_free(cs->line); |
@@ -1140,8 +1120,8 @@ static void s3c64xx_spi_cleanup(struct spi_device *spi) | |||
1140 | struct s3c64xx_spi_driver_data *sdd; | 1120 | struct s3c64xx_spi_driver_data *sdd; |
1141 | 1121 | ||
1142 | sdd = spi_master_get_devdata(spi->master); | 1122 | sdd = spi_master_get_devdata(spi->master); |
1143 | if (cs && sdd->cs_gpio) { | 1123 | if (spi->cs_gpio) { |
1144 | gpio_free(cs->line); | 1124 | gpio_free(spi->cs_gpio); |
1145 | if (spi->dev.of_node) | 1125 | if (spi->dev.of_node) |
1146 | kfree(cs); | 1126 | kfree(cs); |
1147 | } | 1127 | } |
@@ -1359,7 +1339,9 @@ static int s3c64xx_spi_probe(struct platform_device *pdev) | |||
1359 | master->setup = s3c64xx_spi_setup; | 1339 | master->setup = s3c64xx_spi_setup; |
1360 | master->cleanup = s3c64xx_spi_cleanup; | 1340 | master->cleanup = s3c64xx_spi_cleanup; |
1361 | master->prepare_transfer_hardware = s3c64xx_spi_prepare_transfer; | 1341 | master->prepare_transfer_hardware = s3c64xx_spi_prepare_transfer; |
1362 | master->transfer_one_message = s3c64xx_spi_transfer_one_message; | 1342 | master->prepare_message = s3c64xx_spi_prepare_message; |
1343 | master->transfer_one = s3c64xx_spi_transfer_one; | ||
1344 | master->unprepare_message = s3c64xx_spi_unprepare_message; | ||
1363 | master->unprepare_transfer_hardware = s3c64xx_spi_unprepare_transfer; | 1345 | master->unprepare_transfer_hardware = s3c64xx_spi_unprepare_transfer; |
1364 | master->num_chipselect = sci->num_cs; | 1346 | master->num_chipselect = sci->num_cs; |
1365 | master->dma_alignment = 8; | 1347 | master->dma_alignment = 8; |
@@ -1428,9 +1410,12 @@ static int s3c64xx_spi_probe(struct platform_device *pdev) | |||
1428 | S3C64XX_SPI_INT_TX_OVERRUN_EN | S3C64XX_SPI_INT_TX_UNDERRUN_EN, | 1410 | S3C64XX_SPI_INT_TX_OVERRUN_EN | S3C64XX_SPI_INT_TX_UNDERRUN_EN, |
1429 | sdd->regs + S3C64XX_SPI_INT_EN); | 1411 | sdd->regs + S3C64XX_SPI_INT_EN); |
1430 | 1412 | ||
1431 | if (spi_register_master(master)) { | 1413 | pm_runtime_set_active(&pdev->dev); |
1432 | dev_err(&pdev->dev, "cannot register SPI master\n"); | 1414 | pm_runtime_enable(&pdev->dev); |
1433 | ret = -EBUSY; | 1415 | |
1416 | ret = devm_spi_register_master(&pdev->dev, master); | ||
1417 | if (ret != 0) { | ||
1418 | dev_err(&pdev->dev, "cannot register SPI master: %d\n", ret); | ||
1434 | goto err3; | 1419 | goto err3; |
1435 | } | 1420 | } |
1436 | 1421 | ||
@@ -1440,8 +1425,6 @@ static int s3c64xx_spi_probe(struct platform_device *pdev) | |||
1440 | mem_res, | 1425 | mem_res, |
1441 | sdd->rx_dma.dmach, sdd->tx_dma.dmach); | 1426 | sdd->rx_dma.dmach, sdd->tx_dma.dmach); |
1442 | 1427 | ||
1443 | pm_runtime_enable(&pdev->dev); | ||
1444 | |||
1445 | return 0; | 1428 | return 0; |
1446 | 1429 | ||
1447 | err3: | 1430 | err3: |
@@ -1461,16 +1444,12 @@ static int s3c64xx_spi_remove(struct platform_device *pdev) | |||
1461 | 1444 | ||
1462 | pm_runtime_disable(&pdev->dev); | 1445 | pm_runtime_disable(&pdev->dev); |
1463 | 1446 | ||
1464 | spi_unregister_master(master); | ||
1465 | |||
1466 | writel(0, sdd->regs + S3C64XX_SPI_INT_EN); | 1447 | writel(0, sdd->regs + S3C64XX_SPI_INT_EN); |
1467 | 1448 | ||
1468 | clk_disable_unprepare(sdd->src_clk); | 1449 | clk_disable_unprepare(sdd->src_clk); |
1469 | 1450 | ||
1470 | clk_disable_unprepare(sdd->clk); | 1451 | clk_disable_unprepare(sdd->clk); |
1471 | 1452 | ||
1472 | spi_master_put(master); | ||
1473 | |||
1474 | return 0; | 1453 | return 0; |
1475 | } | 1454 | } |
1476 | 1455 | ||
@@ -1480,11 +1459,14 @@ static int s3c64xx_spi_suspend(struct device *dev) | |||
1480 | struct spi_master *master = dev_get_drvdata(dev); | 1459 | struct spi_master *master = dev_get_drvdata(dev); |
1481 | struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); | 1460 | struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); |
1482 | 1461 | ||
1483 | spi_master_suspend(master); | 1462 | int ret = spi_master_suspend(master); |
1463 | if (ret) | ||
1464 | return ret; | ||
1484 | 1465 | ||
1485 | /* Disable the clock */ | 1466 | if (!pm_runtime_suspended(dev)) { |
1486 | clk_disable_unprepare(sdd->src_clk); | 1467 | clk_disable_unprepare(sdd->clk); |
1487 | clk_disable_unprepare(sdd->clk); | 1468 | clk_disable_unprepare(sdd->src_clk); |
1469 | } | ||
1488 | 1470 | ||
1489 | sdd->cur_speed = 0; /* Output Clock is stopped */ | 1471 | sdd->cur_speed = 0; /* Output Clock is stopped */ |
1490 | 1472 | ||
@@ -1500,15 +1482,14 @@ static int s3c64xx_spi_resume(struct device *dev) | |||
1500 | if (sci->cfg_gpio) | 1482 | if (sci->cfg_gpio) |
1501 | sci->cfg_gpio(); | 1483 | sci->cfg_gpio(); |
1502 | 1484 | ||
1503 | /* Enable the clock */ | 1485 | if (!pm_runtime_suspended(dev)) { |
1504 | clk_prepare_enable(sdd->src_clk); | 1486 | clk_prepare_enable(sdd->src_clk); |
1505 | clk_prepare_enable(sdd->clk); | 1487 | clk_prepare_enable(sdd->clk); |
1488 | } | ||
1506 | 1489 | ||
1507 | s3c64xx_spi_hwinit(sdd, sdd->port_id); | 1490 | s3c64xx_spi_hwinit(sdd, sdd->port_id); |
1508 | 1491 | ||
1509 | spi_master_resume(master); | 1492 | return spi_master_resume(master); |
1510 | |||
1511 | return 0; | ||
1512 | } | 1493 | } |
1513 | #endif /* CONFIG_PM_SLEEP */ | 1494 | #endif /* CONFIG_PM_SLEEP */ |
1514 | 1495 | ||
@@ -1528,9 +1509,17 @@ static int s3c64xx_spi_runtime_resume(struct device *dev) | |||
1528 | { | 1509 | { |
1529 | struct spi_master *master = dev_get_drvdata(dev); | 1510 | struct spi_master *master = dev_get_drvdata(dev); |
1530 | struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); | 1511 | struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); |
1512 | int ret; | ||
1531 | 1513 | ||
1532 | clk_prepare_enable(sdd->src_clk); | 1514 | ret = clk_prepare_enable(sdd->src_clk); |
1533 | clk_prepare_enable(sdd->clk); | 1515 | if (ret != 0) |
1516 | return ret; | ||
1517 | |||
1518 | ret = clk_prepare_enable(sdd->clk); | ||
1519 | if (ret != 0) { | ||
1520 | clk_disable_unprepare(sdd->src_clk); | ||
1521 | return ret; | ||
1522 | } | ||
1534 | 1523 | ||
1535 | return 0; | 1524 | return 0; |
1536 | } | 1525 | } |
@@ -1616,6 +1605,18 @@ static struct platform_device_id s3c64xx_spi_driver_ids[] = { | |||
1616 | }; | 1605 | }; |
1617 | 1606 | ||
1618 | static const struct of_device_id s3c64xx_spi_dt_match[] = { | 1607 | static const struct of_device_id s3c64xx_spi_dt_match[] = { |
1608 | { .compatible = "samsung,s3c2443-spi", | ||
1609 | .data = (void *)&s3c2443_spi_port_config, | ||
1610 | }, | ||
1611 | { .compatible = "samsung,s3c6410-spi", | ||
1612 | .data = (void *)&s3c6410_spi_port_config, | ||
1613 | }, | ||
1614 | { .compatible = "samsung,s5pc100-spi", | ||
1615 | .data = (void *)&s5pc100_spi_port_config, | ||
1616 | }, | ||
1617 | { .compatible = "samsung,s5pv210-spi", | ||
1618 | .data = (void *)&s5pv210_spi_port_config, | ||
1619 | }, | ||
1619 | { .compatible = "samsung,exynos4210-spi", | 1620 | { .compatible = "samsung,exynos4210-spi", |
1620 | .data = (void *)&exynos4_spi_port_config, | 1621 | .data = (void *)&exynos4_spi_port_config, |
1621 | }, | 1622 | }, |
@@ -1633,22 +1634,13 @@ static struct platform_driver s3c64xx_spi_driver = { | |||
1633 | .pm = &s3c64xx_spi_pm, | 1634 | .pm = &s3c64xx_spi_pm, |
1634 | .of_match_table = of_match_ptr(s3c64xx_spi_dt_match), | 1635 | .of_match_table = of_match_ptr(s3c64xx_spi_dt_match), |
1635 | }, | 1636 | }, |
1637 | .probe = s3c64xx_spi_probe, | ||
1636 | .remove = s3c64xx_spi_remove, | 1638 | .remove = s3c64xx_spi_remove, |
1637 | .id_table = s3c64xx_spi_driver_ids, | 1639 | .id_table = s3c64xx_spi_driver_ids, |
1638 | }; | 1640 | }; |
1639 | MODULE_ALIAS("platform:s3c64xx-spi"); | 1641 | MODULE_ALIAS("platform:s3c64xx-spi"); |
1640 | 1642 | ||
1641 | static int __init s3c64xx_spi_init(void) | 1643 | module_platform_driver(s3c64xx_spi_driver); |
1642 | { | ||
1643 | return platform_driver_probe(&s3c64xx_spi_driver, s3c64xx_spi_probe); | ||
1644 | } | ||
1645 | subsys_initcall(s3c64xx_spi_init); | ||
1646 | |||
1647 | static void __exit s3c64xx_spi_exit(void) | ||
1648 | { | ||
1649 | platform_driver_unregister(&s3c64xx_spi_driver); | ||
1650 | } | ||
1651 | module_exit(s3c64xx_spi_exit); | ||
1652 | 1644 | ||
1653 | MODULE_AUTHOR("Jaswinder Singh <jassi.brar@samsung.com>"); | 1645 | MODULE_AUTHOR("Jaswinder Singh <jassi.brar@samsung.com>"); |
1654 | MODULE_DESCRIPTION("S3C64XX SPI Controller Driver"); | 1646 | MODULE_DESCRIPTION("S3C64XX SPI Controller Driver"); |
diff --git a/drivers/spi/spi-sh-hspi.c b/drivers/spi/spi-sh-hspi.c index 0b68cb592fa4..292567ab4c6c 100644 --- a/drivers/spi/spi-sh-hspi.c +++ b/drivers/spi/spi-sh-hspi.c | |||
@@ -137,7 +137,7 @@ static void hspi_hw_setup(struct hspi_priv *hspi, | |||
137 | rate /= 16; | 137 | rate /= 16; |
138 | 138 | ||
139 | /* CLKCx calculation */ | 139 | /* CLKCx calculation */ |
140 | rate /= (((idiv_clk & 0x1F) + 1) * 2) ; | 140 | rate /= (((idiv_clk & 0x1F) + 1) * 2); |
141 | 141 | ||
142 | /* save best settings */ | 142 | /* save best settings */ |
143 | tmp = abs(target_rate - rate); | 143 | tmp = abs(target_rate - rate); |
@@ -296,21 +296,22 @@ static int hspi_probe(struct platform_device *pdev) | |||
296 | goto error1; | 296 | goto error1; |
297 | } | 297 | } |
298 | 298 | ||
299 | pm_runtime_enable(&pdev->dev); | ||
300 | |||
299 | master->num_chipselect = 1; | 301 | master->num_chipselect = 1; |
300 | master->bus_num = pdev->id; | 302 | master->bus_num = pdev->id; |
301 | master->setup = hspi_setup; | 303 | master->setup = hspi_setup; |
302 | master->cleanup = hspi_cleanup; | 304 | master->cleanup = hspi_cleanup; |
303 | master->mode_bits = SPI_CPOL | SPI_CPHA; | 305 | master->mode_bits = SPI_CPOL | SPI_CPHA; |
306 | master->dev.of_node = pdev->dev.of_node; | ||
304 | master->auto_runtime_pm = true; | 307 | master->auto_runtime_pm = true; |
305 | master->transfer_one_message = hspi_transfer_one_message; | 308 | master->transfer_one_message = hspi_transfer_one_message; |
306 | ret = spi_register_master(master); | 309 | ret = devm_spi_register_master(&pdev->dev, master); |
307 | if (ret < 0) { | 310 | if (ret < 0) { |
308 | dev_err(&pdev->dev, "spi_register_master error.\n"); | 311 | dev_err(&pdev->dev, "spi_register_master error.\n"); |
309 | goto error1; | 312 | goto error1; |
310 | } | 313 | } |
311 | 314 | ||
312 | pm_runtime_enable(&pdev->dev); | ||
313 | |||
314 | return 0; | 315 | return 0; |
315 | 316 | ||
316 | error1: | 317 | error1: |
@@ -328,17 +329,23 @@ static int hspi_remove(struct platform_device *pdev) | |||
328 | pm_runtime_disable(&pdev->dev); | 329 | pm_runtime_disable(&pdev->dev); |
329 | 330 | ||
330 | clk_put(hspi->clk); | 331 | clk_put(hspi->clk); |
331 | spi_unregister_master(hspi->master); | ||
332 | 332 | ||
333 | return 0; | 333 | return 0; |
334 | } | 334 | } |
335 | 335 | ||
336 | static struct of_device_id hspi_of_match[] = { | ||
337 | { .compatible = "renesas,hspi", }, | ||
338 | { /* sentinel */ } | ||
339 | }; | ||
340 | MODULE_DEVICE_TABLE(of, hspi_of_match); | ||
341 | |||
336 | static struct platform_driver hspi_driver = { | 342 | static struct platform_driver hspi_driver = { |
337 | .probe = hspi_probe, | 343 | .probe = hspi_probe, |
338 | .remove = hspi_remove, | 344 | .remove = hspi_remove, |
339 | .driver = { | 345 | .driver = { |
340 | .name = "sh-hspi", | 346 | .name = "sh-hspi", |
341 | .owner = THIS_MODULE, | 347 | .owner = THIS_MODULE, |
348 | .of_match_table = hspi_of_match, | ||
342 | }, | 349 | }, |
343 | }; | 350 | }; |
344 | module_platform_driver(hspi_driver); | 351 | module_platform_driver(hspi_driver); |
diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c index 2a95435a6a11..c74298cf70e2 100644 --- a/drivers/spi/spi-sh-msiof.c +++ b/drivers/spi/spi-sh-msiof.c | |||
@@ -465,7 +465,7 @@ static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, | |||
465 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, 0, CTR_TXE); | 465 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, 0, CTR_TXE); |
466 | 466 | ||
467 | /* start by setting frame bit */ | 467 | /* start by setting frame bit */ |
468 | INIT_COMPLETION(p->done); | 468 | reinit_completion(&p->done); |
469 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, 0, CTR_TFSE); | 469 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, 0, CTR_TFSE); |
470 | if (ret) { | 470 | if (ret) { |
471 | dev_err(&p->pdev->dev, "failed to start hardware\n"); | 471 | dev_err(&p->pdev->dev, "failed to start hardware\n"); |
diff --git a/drivers/spi/spi-sh-sci.c b/drivers/spi/spi-sh-sci.c index 8eefeb6007df..38eb24df796c 100644 --- a/drivers/spi/spi-sh-sci.c +++ b/drivers/spi/spi-sh-sci.c | |||
@@ -133,7 +133,7 @@ static int sh_sci_spi_probe(struct platform_device *dev) | |||
133 | sp->info = dev_get_platdata(&dev->dev); | 133 | sp->info = dev_get_platdata(&dev->dev); |
134 | 134 | ||
135 | /* setup spi bitbang adaptor */ | 135 | /* setup spi bitbang adaptor */ |
136 | sp->bitbang.master = spi_master_get(master); | 136 | sp->bitbang.master = master; |
137 | sp->bitbang.master->bus_num = sp->info->bus_num; | 137 | sp->bitbang.master->bus_num = sp->info->bus_num; |
138 | sp->bitbang.master->num_chipselect = sp->info->num_chipselect; | 138 | sp->bitbang.master->num_chipselect = sp->info->num_chipselect; |
139 | sp->bitbang.chipselect = sh_sci_spi_chipselect; | 139 | sp->bitbang.chipselect = sh_sci_spi_chipselect; |
diff --git a/drivers/spi/spi-sirf.c b/drivers/spi/spi-sirf.c index a1f21b747733..ed5e501c4652 100644 --- a/drivers/spi/spi-sirf.c +++ b/drivers/spi/spi-sirf.c | |||
@@ -305,8 +305,8 @@ static int spi_sirfsoc_transfer(struct spi_device *spi, struct spi_transfer *t) | |||
305 | sspi->tx = t->tx_buf ? t->tx_buf : sspi->dummypage; | 305 | sspi->tx = t->tx_buf ? t->tx_buf : sspi->dummypage; |
306 | sspi->rx = t->rx_buf ? t->rx_buf : sspi->dummypage; | 306 | sspi->rx = t->rx_buf ? t->rx_buf : sspi->dummypage; |
307 | sspi->left_tx_word = sspi->left_rx_word = t->len / sspi->word_width; | 307 | sspi->left_tx_word = sspi->left_rx_word = t->len / sspi->word_width; |
308 | INIT_COMPLETION(sspi->rx_done); | 308 | reinit_completion(&sspi->rx_done); |
309 | INIT_COMPLETION(sspi->tx_done); | 309 | reinit_completion(&sspi->tx_done); |
310 | 310 | ||
311 | writel(SIRFSOC_SPI_INT_MASK_ALL, sspi->base + SIRFSOC_SPI_INT_STATUS); | 311 | writel(SIRFSOC_SPI_INT_MASK_ALL, sspi->base + SIRFSOC_SPI_INT_STATUS); |
312 | 312 | ||
@@ -632,7 +632,7 @@ static int spi_sirfsoc_probe(struct platform_device *pdev) | |||
632 | if (ret) | 632 | if (ret) |
633 | goto free_master; | 633 | goto free_master; |
634 | 634 | ||
635 | sspi->bitbang.master = spi_master_get(master); | 635 | sspi->bitbang.master = master; |
636 | sspi->bitbang.chipselect = spi_sirfsoc_chipselect; | 636 | sspi->bitbang.chipselect = spi_sirfsoc_chipselect; |
637 | sspi->bitbang.setup_transfer = spi_sirfsoc_setup_transfer; | 637 | sspi->bitbang.setup_transfer = spi_sirfsoc_setup_transfer; |
638 | sspi->bitbang.txrx_bufs = spi_sirfsoc_transfer; | 638 | sspi->bitbang.txrx_bufs = spi_sirfsoc_transfer; |
diff --git a/drivers/spi/spi-tegra114.c b/drivers/spi/spi-tegra114.c index 145dd435483b..aaecfb3ebf58 100644 --- a/drivers/spi/spi-tegra114.c +++ b/drivers/spi/spi-tegra114.c | |||
@@ -182,6 +182,7 @@ struct tegra_spi_data { | |||
182 | u32 cur_speed; | 182 | u32 cur_speed; |
183 | 183 | ||
184 | struct spi_device *cur_spi; | 184 | struct spi_device *cur_spi; |
185 | struct spi_device *cs_control; | ||
185 | unsigned cur_pos; | 186 | unsigned cur_pos; |
186 | unsigned cur_len; | 187 | unsigned cur_len; |
187 | unsigned words_per_32bit; | 188 | unsigned words_per_32bit; |
@@ -267,7 +268,7 @@ static unsigned tegra_spi_calculate_curr_xfer_param( | |||
267 | unsigned max_len; | 268 | unsigned max_len; |
268 | unsigned total_fifo_words; | 269 | unsigned total_fifo_words; |
269 | 270 | ||
270 | tspi->bytes_per_word = (bits_per_word - 1) / 8 + 1; | 271 | tspi->bytes_per_word = DIV_ROUND_UP(bits_per_word, 8); |
271 | 272 | ||
272 | if (bits_per_word == 8 || bits_per_word == 16) { | 273 | if (bits_per_word == 8 || bits_per_word == 16) { |
273 | tspi->is_packed = 1; | 274 | tspi->is_packed = 1; |
@@ -450,7 +451,7 @@ static void tegra_spi_dma_complete(void *args) | |||
450 | 451 | ||
451 | static int tegra_spi_start_tx_dma(struct tegra_spi_data *tspi, int len) | 452 | static int tegra_spi_start_tx_dma(struct tegra_spi_data *tspi, int len) |
452 | { | 453 | { |
453 | INIT_COMPLETION(tspi->tx_dma_complete); | 454 | reinit_completion(&tspi->tx_dma_complete); |
454 | tspi->tx_dma_desc = dmaengine_prep_slave_single(tspi->tx_dma_chan, | 455 | tspi->tx_dma_desc = dmaengine_prep_slave_single(tspi->tx_dma_chan, |
455 | tspi->tx_dma_phys, len, DMA_MEM_TO_DEV, | 456 | tspi->tx_dma_phys, len, DMA_MEM_TO_DEV, |
456 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | 457 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
@@ -469,7 +470,7 @@ static int tegra_spi_start_tx_dma(struct tegra_spi_data *tspi, int len) | |||
469 | 470 | ||
470 | static int tegra_spi_start_rx_dma(struct tegra_spi_data *tspi, int len) | 471 | static int tegra_spi_start_rx_dma(struct tegra_spi_data *tspi, int len) |
471 | { | 472 | { |
472 | INIT_COMPLETION(tspi->rx_dma_complete); | 473 | reinit_completion(&tspi->rx_dma_complete); |
473 | tspi->rx_dma_desc = dmaengine_prep_slave_single(tspi->rx_dma_chan, | 474 | tspi->rx_dma_desc = dmaengine_prep_slave_single(tspi->rx_dma_chan, |
474 | tspi->rx_dma_phys, len, DMA_DEV_TO_MEM, | 475 | tspi->rx_dma_phys, len, DMA_DEV_TO_MEM, |
475 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | 476 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
@@ -676,15 +677,12 @@ static void tegra_spi_deinit_dma_param(struct tegra_spi_data *tspi, | |||
676 | dma_release_channel(dma_chan); | 677 | dma_release_channel(dma_chan); |
677 | } | 678 | } |
678 | 679 | ||
679 | static int tegra_spi_start_transfer_one(struct spi_device *spi, | 680 | static unsigned long tegra_spi_setup_transfer_one(struct spi_device *spi, |
680 | struct spi_transfer *t, bool is_first_of_msg, | 681 | struct spi_transfer *t, bool is_first_of_msg) |
681 | bool is_single_xfer) | ||
682 | { | 682 | { |
683 | struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master); | 683 | struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master); |
684 | u32 speed = t->speed_hz; | 684 | u32 speed = t->speed_hz; |
685 | u8 bits_per_word = t->bits_per_word; | 685 | u8 bits_per_word = t->bits_per_word; |
686 | unsigned total_fifo_words; | ||
687 | int ret; | ||
688 | unsigned long command1; | 686 | unsigned long command1; |
689 | int req_mode; | 687 | int req_mode; |
690 | 688 | ||
@@ -698,7 +696,6 @@ static int tegra_spi_start_transfer_one(struct spi_device *spi, | |||
698 | tspi->cur_rx_pos = 0; | 696 | tspi->cur_rx_pos = 0; |
699 | tspi->cur_tx_pos = 0; | 697 | tspi->cur_tx_pos = 0; |
700 | tspi->curr_xfer = t; | 698 | tspi->curr_xfer = t; |
701 | total_fifo_words = tegra_spi_calculate_curr_xfer_param(spi, tspi, t); | ||
702 | 699 | ||
703 | if (is_first_of_msg) { | 700 | if (is_first_of_msg) { |
704 | tegra_spi_clear_status(tspi); | 701 | tegra_spi_clear_status(tspi); |
@@ -717,7 +714,12 @@ static int tegra_spi_start_transfer_one(struct spi_device *spi, | |||
717 | else if (req_mode == SPI_MODE_3) | 714 | else if (req_mode == SPI_MODE_3) |
718 | command1 |= SPI_CONTROL_MODE_3; | 715 | command1 |= SPI_CONTROL_MODE_3; |
719 | 716 | ||
720 | tegra_spi_writel(tspi, command1, SPI_COMMAND1); | 717 | if (tspi->cs_control) { |
718 | if (tspi->cs_control != spi) | ||
719 | tegra_spi_writel(tspi, command1, SPI_COMMAND1); | ||
720 | tspi->cs_control = NULL; | ||
721 | } else | ||
722 | tegra_spi_writel(tspi, command1, SPI_COMMAND1); | ||
721 | 723 | ||
722 | command1 |= SPI_CS_SW_HW; | 724 | command1 |= SPI_CS_SW_HW; |
723 | if (spi->mode & SPI_CS_HIGH) | 725 | if (spi->mode & SPI_CS_HIGH) |
@@ -732,6 +734,18 @@ static int tegra_spi_start_transfer_one(struct spi_device *spi, | |||
732 | command1 |= SPI_BIT_LENGTH(bits_per_word - 1); | 734 | command1 |= SPI_BIT_LENGTH(bits_per_word - 1); |
733 | } | 735 | } |
734 | 736 | ||
737 | return command1; | ||
738 | } | ||
739 | |||
740 | static int tegra_spi_start_transfer_one(struct spi_device *spi, | ||
741 | struct spi_transfer *t, unsigned long command1) | ||
742 | { | ||
743 | struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master); | ||
744 | unsigned total_fifo_words; | ||
745 | int ret; | ||
746 | |||
747 | total_fifo_words = tegra_spi_calculate_curr_xfer_param(spi, tspi, t); | ||
748 | |||
735 | if (tspi->is_packed) | 749 | if (tspi->is_packed) |
736 | command1 |= SPI_PACKED; | 750 | command1 |= SPI_PACKED; |
737 | 751 | ||
@@ -803,29 +817,50 @@ static int tegra_spi_setup(struct spi_device *spi) | |||
803 | return 0; | 817 | return 0; |
804 | } | 818 | } |
805 | 819 | ||
820 | static void tegra_spi_transfer_delay(int delay) | ||
821 | { | ||
822 | if (!delay) | ||
823 | return; | ||
824 | |||
825 | if (delay >= 1000) | ||
826 | mdelay(delay / 1000); | ||
827 | |||
828 | udelay(delay % 1000); | ||
829 | } | ||
830 | |||
806 | static int tegra_spi_transfer_one_message(struct spi_master *master, | 831 | static int tegra_spi_transfer_one_message(struct spi_master *master, |
807 | struct spi_message *msg) | 832 | struct spi_message *msg) |
808 | { | 833 | { |
809 | bool is_first_msg = true; | 834 | bool is_first_msg = true; |
810 | int single_xfer; | ||
811 | struct tegra_spi_data *tspi = spi_master_get_devdata(master); | 835 | struct tegra_spi_data *tspi = spi_master_get_devdata(master); |
812 | struct spi_transfer *xfer; | 836 | struct spi_transfer *xfer; |
813 | struct spi_device *spi = msg->spi; | 837 | struct spi_device *spi = msg->spi; |
814 | int ret; | 838 | int ret; |
839 | bool skip = false; | ||
815 | 840 | ||
816 | msg->status = 0; | 841 | msg->status = 0; |
817 | msg->actual_length = 0; | 842 | msg->actual_length = 0; |
818 | 843 | ||
819 | single_xfer = list_is_singular(&msg->transfers); | ||
820 | list_for_each_entry(xfer, &msg->transfers, transfer_list) { | 844 | list_for_each_entry(xfer, &msg->transfers, transfer_list) { |
821 | INIT_COMPLETION(tspi->xfer_completion); | 845 | unsigned long cmd1; |
822 | ret = tegra_spi_start_transfer_one(spi, xfer, | 846 | |
823 | is_first_msg, single_xfer); | 847 | reinit_completion(&tspi->xfer_completion); |
848 | |||
849 | cmd1 = tegra_spi_setup_transfer_one(spi, xfer, is_first_msg); | ||
850 | |||
851 | if (!xfer->len) { | ||
852 | ret = 0; | ||
853 | skip = true; | ||
854 | goto complete_xfer; | ||
855 | } | ||
856 | |||
857 | ret = tegra_spi_start_transfer_one(spi, xfer, cmd1); | ||
824 | if (ret < 0) { | 858 | if (ret < 0) { |
825 | dev_err(tspi->dev, | 859 | dev_err(tspi->dev, |
826 | "spi can not start transfer, err %d\n", ret); | 860 | "spi can not start transfer, err %d\n", ret); |
827 | goto exit; | 861 | goto complete_xfer; |
828 | } | 862 | } |
863 | |||
829 | is_first_msg = false; | 864 | is_first_msg = false; |
830 | ret = wait_for_completion_timeout(&tspi->xfer_completion, | 865 | ret = wait_for_completion_timeout(&tspi->xfer_completion, |
831 | SPI_DMA_TIMEOUT); | 866 | SPI_DMA_TIMEOUT); |
@@ -833,24 +868,40 @@ static int tegra_spi_transfer_one_message(struct spi_master *master, | |||
833 | dev_err(tspi->dev, | 868 | dev_err(tspi->dev, |
834 | "spi trasfer timeout, err %d\n", ret); | 869 | "spi trasfer timeout, err %d\n", ret); |
835 | ret = -EIO; | 870 | ret = -EIO; |
836 | goto exit; | 871 | goto complete_xfer; |
837 | } | 872 | } |
838 | 873 | ||
839 | if (tspi->tx_status || tspi->rx_status) { | 874 | if (tspi->tx_status || tspi->rx_status) { |
840 | dev_err(tspi->dev, "Error in Transfer\n"); | 875 | dev_err(tspi->dev, "Error in Transfer\n"); |
841 | ret = -EIO; | 876 | ret = -EIO; |
842 | goto exit; | 877 | goto complete_xfer; |
843 | } | 878 | } |
844 | msg->actual_length += xfer->len; | 879 | msg->actual_length += xfer->len; |
845 | if (xfer->cs_change && xfer->delay_usecs) { | 880 | |
881 | complete_xfer: | ||
882 | if (ret < 0 || skip) { | ||
846 | tegra_spi_writel(tspi, tspi->def_command1_reg, | 883 | tegra_spi_writel(tspi, tspi->def_command1_reg, |
847 | SPI_COMMAND1); | 884 | SPI_COMMAND1); |
848 | udelay(xfer->delay_usecs); | 885 | tegra_spi_transfer_delay(xfer->delay_usecs); |
886 | goto exit; | ||
887 | } else if (msg->transfers.prev == &xfer->transfer_list) { | ||
888 | /* This is the last transfer in message */ | ||
889 | if (xfer->cs_change) | ||
890 | tspi->cs_control = spi; | ||
891 | else { | ||
892 | tegra_spi_writel(tspi, tspi->def_command1_reg, | ||
893 | SPI_COMMAND1); | ||
894 | tegra_spi_transfer_delay(xfer->delay_usecs); | ||
895 | } | ||
896 | } else if (xfer->cs_change) { | ||
897 | tegra_spi_writel(tspi, tspi->def_command1_reg, | ||
898 | SPI_COMMAND1); | ||
899 | tegra_spi_transfer_delay(xfer->delay_usecs); | ||
849 | } | 900 | } |
901 | |||
850 | } | 902 | } |
851 | ret = 0; | 903 | ret = 0; |
852 | exit: | 904 | exit: |
853 | tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1); | ||
854 | msg->status = ret; | 905 | msg->status = ret; |
855 | spi_finalize_current_message(master); | 906 | spi_finalize_current_message(master); |
856 | return ret; | 907 | return ret; |
@@ -1115,7 +1166,7 @@ static int tegra_spi_probe(struct platform_device *pdev) | |||
1115 | pm_runtime_put(&pdev->dev); | 1166 | pm_runtime_put(&pdev->dev); |
1116 | 1167 | ||
1117 | master->dev.of_node = pdev->dev.of_node; | 1168 | master->dev.of_node = pdev->dev.of_node; |
1118 | ret = spi_register_master(master); | 1169 | ret = devm_spi_register_master(&pdev->dev, master); |
1119 | if (ret < 0) { | 1170 | if (ret < 0) { |
1120 | dev_err(&pdev->dev, "can not register to master err %d\n", ret); | 1171 | dev_err(&pdev->dev, "can not register to master err %d\n", ret); |
1121 | goto exit_pm_disable; | 1172 | goto exit_pm_disable; |
@@ -1142,7 +1193,6 @@ static int tegra_spi_remove(struct platform_device *pdev) | |||
1142 | struct tegra_spi_data *tspi = spi_master_get_devdata(master); | 1193 | struct tegra_spi_data *tspi = spi_master_get_devdata(master); |
1143 | 1194 | ||
1144 | free_irq(tspi->irq, tspi); | 1195 | free_irq(tspi->irq, tspi); |
1145 | spi_unregister_master(master); | ||
1146 | 1196 | ||
1147 | if (tspi->tx_dma_chan) | 1197 | if (tspi->tx_dma_chan) |
1148 | tegra_spi_deinit_dma_param(tspi, false); | 1198 | tegra_spi_deinit_dma_param(tspi, false); |
diff --git a/drivers/spi/spi-tegra20-sflash.c b/drivers/spi/spi-tegra20-sflash.c index 1d814dc6e000..4dc8e8129459 100644 --- a/drivers/spi/spi-tegra20-sflash.c +++ b/drivers/spi/spi-tegra20-sflash.c | |||
@@ -173,7 +173,7 @@ static unsigned tegra_sflash_calculate_curr_xfer_param( | |||
173 | unsigned remain_len = t->len - tsd->cur_pos; | 173 | unsigned remain_len = t->len - tsd->cur_pos; |
174 | unsigned max_word; | 174 | unsigned max_word; |
175 | 175 | ||
176 | tsd->bytes_per_word = (t->bits_per_word - 1) / 8 + 1; | 176 | tsd->bytes_per_word = DIV_ROUND_UP(t->bits_per_word, 8); |
177 | max_word = remain_len / tsd->bytes_per_word; | 177 | max_word = remain_len / tsd->bytes_per_word; |
178 | if (max_word > SPI_FIFO_DEPTH) | 178 | if (max_word > SPI_FIFO_DEPTH) |
179 | max_word = SPI_FIFO_DEPTH; | 179 | max_word = SPI_FIFO_DEPTH; |
@@ -339,7 +339,7 @@ static int tegra_sflash_transfer_one_message(struct spi_master *master, | |||
339 | msg->actual_length = 0; | 339 | msg->actual_length = 0; |
340 | single_xfer = list_is_singular(&msg->transfers); | 340 | single_xfer = list_is_singular(&msg->transfers); |
341 | list_for_each_entry(xfer, &msg->transfers, transfer_list) { | 341 | list_for_each_entry(xfer, &msg->transfers, transfer_list) { |
342 | INIT_COMPLETION(tsd->xfer_completion); | 342 | reinit_completion(&tsd->xfer_completion); |
343 | ret = tegra_sflash_start_transfer_one(spi, xfer, | 343 | ret = tegra_sflash_start_transfer_one(spi, xfer, |
344 | is_first_msg, single_xfer); | 344 | is_first_msg, single_xfer); |
345 | if (ret < 0) { | 345 | if (ret < 0) { |
@@ -529,7 +529,7 @@ static int tegra_sflash_probe(struct platform_device *pdev) | |||
529 | pm_runtime_put(&pdev->dev); | 529 | pm_runtime_put(&pdev->dev); |
530 | 530 | ||
531 | master->dev.of_node = pdev->dev.of_node; | 531 | master->dev.of_node = pdev->dev.of_node; |
532 | ret = spi_register_master(master); | 532 | ret = devm_spi_register_master(&pdev->dev, master); |
533 | if (ret < 0) { | 533 | if (ret < 0) { |
534 | dev_err(&pdev->dev, "can not register to master err %d\n", ret); | 534 | dev_err(&pdev->dev, "can not register to master err %d\n", ret); |
535 | goto exit_pm_disable; | 535 | goto exit_pm_disable; |
@@ -553,7 +553,6 @@ static int tegra_sflash_remove(struct platform_device *pdev) | |||
553 | struct tegra_sflash_data *tsd = spi_master_get_devdata(master); | 553 | struct tegra_sflash_data *tsd = spi_master_get_devdata(master); |
554 | 554 | ||
555 | free_irq(tsd->irq, tsd); | 555 | free_irq(tsd->irq, tsd); |
556 | spi_unregister_master(master); | ||
557 | 556 | ||
558 | pm_runtime_disable(&pdev->dev); | 557 | pm_runtime_disable(&pdev->dev); |
559 | if (!pm_runtime_status_suspended(&pdev->dev)) | 558 | if (!pm_runtime_status_suspended(&pdev->dev)) |
diff --git a/drivers/spi/spi-tegra20-slink.c b/drivers/spi/spi-tegra20-slink.c index c70353672a23..e66715ba37ed 100644 --- a/drivers/spi/spi-tegra20-slink.c +++ b/drivers/spi/spi-tegra20-slink.c | |||
@@ -278,12 +278,12 @@ static unsigned tegra_slink_calculate_curr_xfer_param( | |||
278 | { | 278 | { |
279 | unsigned remain_len = t->len - tspi->cur_pos; | 279 | unsigned remain_len = t->len - tspi->cur_pos; |
280 | unsigned max_word; | 280 | unsigned max_word; |
281 | unsigned bits_per_word ; | 281 | unsigned bits_per_word; |
282 | unsigned max_len; | 282 | unsigned max_len; |
283 | unsigned total_fifo_words; | 283 | unsigned total_fifo_words; |
284 | 284 | ||
285 | bits_per_word = t->bits_per_word; | 285 | bits_per_word = t->bits_per_word; |
286 | tspi->bytes_per_word = (bits_per_word - 1) / 8 + 1; | 286 | tspi->bytes_per_word = DIV_ROUND_UP(bits_per_word, 8); |
287 | 287 | ||
288 | if (bits_per_word == 8 || bits_per_word == 16) { | 288 | if (bits_per_word == 8 || bits_per_word == 16) { |
289 | tspi->is_packed = 1; | 289 | tspi->is_packed = 1; |
@@ -462,7 +462,7 @@ static void tegra_slink_dma_complete(void *args) | |||
462 | 462 | ||
463 | static int tegra_slink_start_tx_dma(struct tegra_slink_data *tspi, int len) | 463 | static int tegra_slink_start_tx_dma(struct tegra_slink_data *tspi, int len) |
464 | { | 464 | { |
465 | INIT_COMPLETION(tspi->tx_dma_complete); | 465 | reinit_completion(&tspi->tx_dma_complete); |
466 | tspi->tx_dma_desc = dmaengine_prep_slave_single(tspi->tx_dma_chan, | 466 | tspi->tx_dma_desc = dmaengine_prep_slave_single(tspi->tx_dma_chan, |
467 | tspi->tx_dma_phys, len, DMA_MEM_TO_DEV, | 467 | tspi->tx_dma_phys, len, DMA_MEM_TO_DEV, |
468 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | 468 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
@@ -481,7 +481,7 @@ static int tegra_slink_start_tx_dma(struct tegra_slink_data *tspi, int len) | |||
481 | 481 | ||
482 | static int tegra_slink_start_rx_dma(struct tegra_slink_data *tspi, int len) | 482 | static int tegra_slink_start_rx_dma(struct tegra_slink_data *tspi, int len) |
483 | { | 483 | { |
484 | INIT_COMPLETION(tspi->rx_dma_complete); | 484 | reinit_completion(&tspi->rx_dma_complete); |
485 | tspi->rx_dma_desc = dmaengine_prep_slave_single(tspi->rx_dma_chan, | 485 | tspi->rx_dma_desc = dmaengine_prep_slave_single(tspi->rx_dma_chan, |
486 | tspi->rx_dma_phys, len, DMA_DEV_TO_MEM, | 486 | tspi->rx_dma_phys, len, DMA_DEV_TO_MEM, |
487 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | 487 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
@@ -707,8 +707,7 @@ static void tegra_slink_deinit_dma_param(struct tegra_slink_data *tspi, | |||
707 | } | 707 | } |
708 | 708 | ||
709 | static int tegra_slink_start_transfer_one(struct spi_device *spi, | 709 | static int tegra_slink_start_transfer_one(struct spi_device *spi, |
710 | struct spi_transfer *t, bool is_first_of_msg, | 710 | struct spi_transfer *t) |
711 | bool is_single_xfer) | ||
712 | { | 711 | { |
713 | struct tegra_slink_data *tspi = spi_master_get_devdata(spi->master); | 712 | struct tegra_slink_data *tspi = spi_master_get_devdata(spi->master); |
714 | u32 speed; | 713 | u32 speed; |
@@ -732,32 +731,12 @@ static int tegra_slink_start_transfer_one(struct spi_device *spi, | |||
732 | tspi->curr_xfer = t; | 731 | tspi->curr_xfer = t; |
733 | total_fifo_words = tegra_slink_calculate_curr_xfer_param(spi, tspi, t); | 732 | total_fifo_words = tegra_slink_calculate_curr_xfer_param(spi, tspi, t); |
734 | 733 | ||
735 | if (is_first_of_msg) { | 734 | command = tspi->command_reg; |
736 | tegra_slink_clear_status(tspi); | 735 | command &= ~SLINK_BIT_LENGTH(~0); |
736 | command |= SLINK_BIT_LENGTH(bits_per_word - 1); | ||
737 | 737 | ||
738 | command = tspi->def_command_reg; | 738 | command2 = tspi->command2_reg; |
739 | command |= SLINK_BIT_LENGTH(bits_per_word - 1); | 739 | command2 &= ~(SLINK_RXEN | SLINK_TXEN); |
740 | command |= SLINK_CS_SW | SLINK_CS_VALUE; | ||
741 | |||
742 | command2 = tspi->def_command2_reg; | ||
743 | command2 |= SLINK_SS_EN_CS(spi->chip_select); | ||
744 | |||
745 | command &= ~SLINK_MODES; | ||
746 | if (spi->mode & SPI_CPHA) | ||
747 | command |= SLINK_CK_SDA; | ||
748 | |||
749 | if (spi->mode & SPI_CPOL) | ||
750 | command |= SLINK_IDLE_SCLK_DRIVE_HIGH; | ||
751 | else | ||
752 | command |= SLINK_IDLE_SCLK_DRIVE_LOW; | ||
753 | } else { | ||
754 | command = tspi->command_reg; | ||
755 | command &= ~SLINK_BIT_LENGTH(~0); | ||
756 | command |= SLINK_BIT_LENGTH(bits_per_word - 1); | ||
757 | |||
758 | command2 = tspi->command2_reg; | ||
759 | command2 &= ~(SLINK_RXEN | SLINK_TXEN); | ||
760 | } | ||
761 | 740 | ||
762 | tegra_slink_writel(tspi, command, SLINK_COMMAND); | 741 | tegra_slink_writel(tspi, command, SLINK_COMMAND); |
763 | tspi->command_reg = command; | 742 | tspi->command_reg = command; |
@@ -824,58 +803,72 @@ static int tegra_slink_setup(struct spi_device *spi) | |||
824 | return 0; | 803 | return 0; |
825 | } | 804 | } |
826 | 805 | ||
827 | static int tegra_slink_transfer_one_message(struct spi_master *master, | 806 | static int tegra_slink_prepare_message(struct spi_master *master, |
828 | struct spi_message *msg) | 807 | struct spi_message *msg) |
829 | { | 808 | { |
830 | bool is_first_msg = true; | ||
831 | int single_xfer; | ||
832 | struct tegra_slink_data *tspi = spi_master_get_devdata(master); | 809 | struct tegra_slink_data *tspi = spi_master_get_devdata(master); |
833 | struct spi_transfer *xfer; | ||
834 | struct spi_device *spi = msg->spi; | 810 | struct spi_device *spi = msg->spi; |
835 | int ret; | ||
836 | 811 | ||
837 | msg->status = 0; | 812 | tegra_slink_clear_status(tspi); |
838 | msg->actual_length = 0; | ||
839 | 813 | ||
840 | single_xfer = list_is_singular(&msg->transfers); | 814 | tspi->command_reg = tspi->def_command_reg; |
841 | list_for_each_entry(xfer, &msg->transfers, transfer_list) { | 815 | tspi->command_reg |= SLINK_CS_SW | SLINK_CS_VALUE; |
842 | INIT_COMPLETION(tspi->xfer_completion); | ||
843 | ret = tegra_slink_start_transfer_one(spi, xfer, | ||
844 | is_first_msg, single_xfer); | ||
845 | if (ret < 0) { | ||
846 | dev_err(tspi->dev, | ||
847 | "spi can not start transfer, err %d\n", ret); | ||
848 | goto exit; | ||
849 | } | ||
850 | is_first_msg = false; | ||
851 | ret = wait_for_completion_timeout(&tspi->xfer_completion, | ||
852 | SLINK_DMA_TIMEOUT); | ||
853 | if (WARN_ON(ret == 0)) { | ||
854 | dev_err(tspi->dev, | ||
855 | "spi trasfer timeout, err %d\n", ret); | ||
856 | ret = -EIO; | ||
857 | goto exit; | ||
858 | } | ||
859 | 816 | ||
860 | if (tspi->tx_status || tspi->rx_status) { | 817 | tspi->command2_reg = tspi->def_command2_reg; |
861 | dev_err(tspi->dev, "Error in Transfer\n"); | 818 | tspi->command2_reg |= SLINK_SS_EN_CS(spi->chip_select); |
862 | ret = -EIO; | 819 | |
863 | goto exit; | 820 | tspi->command_reg &= ~SLINK_MODES; |
864 | } | 821 | if (spi->mode & SPI_CPHA) |
865 | msg->actual_length += xfer->len; | 822 | tspi->command_reg |= SLINK_CK_SDA; |
866 | if (xfer->cs_change && xfer->delay_usecs) { | 823 | |
867 | tegra_slink_writel(tspi, tspi->def_command_reg, | 824 | if (spi->mode & SPI_CPOL) |
868 | SLINK_COMMAND); | 825 | tspi->command_reg |= SLINK_IDLE_SCLK_DRIVE_HIGH; |
869 | udelay(xfer->delay_usecs); | 826 | else |
870 | } | 827 | tspi->command_reg |= SLINK_IDLE_SCLK_DRIVE_LOW; |
828 | |||
829 | return 0; | ||
830 | } | ||
831 | |||
832 | static int tegra_slink_transfer_one(struct spi_master *master, | ||
833 | struct spi_device *spi, | ||
834 | struct spi_transfer *xfer) | ||
835 | { | ||
836 | struct tegra_slink_data *tspi = spi_master_get_devdata(master); | ||
837 | int ret; | ||
838 | |||
839 | reinit_completion(&tspi->xfer_completion); | ||
840 | ret = tegra_slink_start_transfer_one(spi, xfer); | ||
841 | if (ret < 0) { | ||
842 | dev_err(tspi->dev, | ||
843 | "spi can not start transfer, err %d\n", ret); | ||
844 | return ret; | ||
871 | } | 845 | } |
872 | ret = 0; | 846 | |
873 | exit: | 847 | ret = wait_for_completion_timeout(&tspi->xfer_completion, |
848 | SLINK_DMA_TIMEOUT); | ||
849 | if (WARN_ON(ret == 0)) { | ||
850 | dev_err(tspi->dev, | ||
851 | "spi trasfer timeout, err %d\n", ret); | ||
852 | return -EIO; | ||
853 | } | ||
854 | |||
855 | if (tspi->tx_status) | ||
856 | return tspi->tx_status; | ||
857 | if (tspi->rx_status) | ||
858 | return tspi->rx_status; | ||
859 | |||
860 | return 0; | ||
861 | } | ||
862 | |||
863 | static int tegra_slink_unprepare_message(struct spi_master *master, | ||
864 | struct spi_message *msg) | ||
865 | { | ||
866 | struct tegra_slink_data *tspi = spi_master_get_devdata(master); | ||
867 | |||
874 | tegra_slink_writel(tspi, tspi->def_command_reg, SLINK_COMMAND); | 868 | tegra_slink_writel(tspi, tspi->def_command_reg, SLINK_COMMAND); |
875 | tegra_slink_writel(tspi, tspi->def_command2_reg, SLINK_COMMAND2); | 869 | tegra_slink_writel(tspi, tspi->def_command2_reg, SLINK_COMMAND2); |
876 | msg->status = ret; | 870 | |
877 | spi_finalize_current_message(master); | 871 | return 0; |
878 | return ret; | ||
879 | } | 872 | } |
880 | 873 | ||
881 | static irqreturn_t handle_cpu_based_xfer(struct tegra_slink_data *tspi) | 874 | static irqreturn_t handle_cpu_based_xfer(struct tegra_slink_data *tspi) |
@@ -1078,7 +1071,9 @@ static int tegra_slink_probe(struct platform_device *pdev) | |||
1078 | /* the spi->mode bits understood by this driver: */ | 1071 | /* the spi->mode bits understood by this driver: */ |
1079 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; | 1072 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; |
1080 | master->setup = tegra_slink_setup; | 1073 | master->setup = tegra_slink_setup; |
1081 | master->transfer_one_message = tegra_slink_transfer_one_message; | 1074 | master->prepare_message = tegra_slink_prepare_message; |
1075 | master->transfer_one = tegra_slink_transfer_one; | ||
1076 | master->unprepare_message = tegra_slink_unprepare_message; | ||
1082 | master->auto_runtime_pm = true; | 1077 | master->auto_runtime_pm = true; |
1083 | master->num_chipselect = MAX_CHIP_SELECT; | 1078 | master->num_chipselect = MAX_CHIP_SELECT; |
1084 | master->bus_num = -1; | 1079 | master->bus_num = -1; |
@@ -1164,7 +1159,7 @@ static int tegra_slink_probe(struct platform_device *pdev) | |||
1164 | pm_runtime_put(&pdev->dev); | 1159 | pm_runtime_put(&pdev->dev); |
1165 | 1160 | ||
1166 | master->dev.of_node = pdev->dev.of_node; | 1161 | master->dev.of_node = pdev->dev.of_node; |
1167 | ret = spi_register_master(master); | 1162 | ret = devm_spi_register_master(&pdev->dev, master); |
1168 | if (ret < 0) { | 1163 | if (ret < 0) { |
1169 | dev_err(&pdev->dev, "can not register to master err %d\n", ret); | 1164 | dev_err(&pdev->dev, "can not register to master err %d\n", ret); |
1170 | goto exit_pm_disable; | 1165 | goto exit_pm_disable; |
@@ -1191,7 +1186,6 @@ static int tegra_slink_remove(struct platform_device *pdev) | |||
1191 | struct tegra_slink_data *tspi = spi_master_get_devdata(master); | 1186 | struct tegra_slink_data *tspi = spi_master_get_devdata(master); |
1192 | 1187 | ||
1193 | free_irq(tspi->irq, tspi); | 1188 | free_irq(tspi->irq, tspi); |
1194 | spi_unregister_master(master); | ||
1195 | 1189 | ||
1196 | if (tspi->tx_dma_chan) | 1190 | if (tspi->tx_dma_chan) |
1197 | tegra_slink_deinit_dma_param(tspi, false); | 1191 | tegra_slink_deinit_dma_param(tspi, false); |
diff --git a/drivers/spi/spi-ti-qspi.c b/drivers/spi/spi-ti-qspi.c index e12d962a289f..4396bd448540 100644 --- a/drivers/spi/spi-ti-qspi.c +++ b/drivers/spi/spi-ti-qspi.c | |||
@@ -41,9 +41,6 @@ struct ti_qspi_regs { | |||
41 | struct ti_qspi { | 41 | struct ti_qspi { |
42 | struct completion transfer_complete; | 42 | struct completion transfer_complete; |
43 | 43 | ||
44 | /* IRQ synchronization */ | ||
45 | spinlock_t lock; | ||
46 | |||
47 | /* list synchronization */ | 44 | /* list synchronization */ |
48 | struct mutex list_lock; | 45 | struct mutex list_lock; |
49 | 46 | ||
@@ -57,7 +54,6 @@ struct ti_qspi { | |||
57 | u32 spi_max_frequency; | 54 | u32 spi_max_frequency; |
58 | u32 cmd; | 55 | u32 cmd; |
59 | u32 dc; | 56 | u32 dc; |
60 | u32 stat; | ||
61 | }; | 57 | }; |
62 | 58 | ||
63 | #define QSPI_PID (0x0) | 59 | #define QSPI_PID (0x0) |
@@ -165,7 +161,7 @@ static int ti_qspi_setup(struct spi_device *spi) | |||
165 | qspi->spi_max_frequency, clk_div); | 161 | qspi->spi_max_frequency, clk_div); |
166 | 162 | ||
167 | ret = pm_runtime_get_sync(qspi->dev); | 163 | ret = pm_runtime_get_sync(qspi->dev); |
168 | if (ret) { | 164 | if (ret < 0) { |
169 | dev_err(qspi->dev, "pm_runtime_get_sync() failed\n"); | 165 | dev_err(qspi->dev, "pm_runtime_get_sync() failed\n"); |
170 | return ret; | 166 | return ret; |
171 | } | 167 | } |
@@ -397,13 +393,12 @@ static irqreturn_t ti_qspi_isr(int irq, void *dev_id) | |||
397 | { | 393 | { |
398 | struct ti_qspi *qspi = dev_id; | 394 | struct ti_qspi *qspi = dev_id; |
399 | u16 int_stat; | 395 | u16 int_stat; |
396 | u32 stat; | ||
400 | 397 | ||
401 | irqreturn_t ret = IRQ_HANDLED; | 398 | irqreturn_t ret = IRQ_HANDLED; |
402 | 399 | ||
403 | spin_lock(&qspi->lock); | ||
404 | |||
405 | int_stat = ti_qspi_read(qspi, QSPI_INTR_STATUS_ENABLED_CLEAR); | 400 | int_stat = ti_qspi_read(qspi, QSPI_INTR_STATUS_ENABLED_CLEAR); |
406 | qspi->stat = ti_qspi_read(qspi, QSPI_SPI_STATUS_REG); | 401 | stat = ti_qspi_read(qspi, QSPI_SPI_STATUS_REG); |
407 | 402 | ||
408 | if (!int_stat) { | 403 | if (!int_stat) { |
409 | dev_dbg(qspi->dev, "No IRQ triggered\n"); | 404 | dev_dbg(qspi->dev, "No IRQ triggered\n"); |
@@ -411,35 +406,14 @@ static irqreturn_t ti_qspi_isr(int irq, void *dev_id) | |||
411 | goto out; | 406 | goto out; |
412 | } | 407 | } |
413 | 408 | ||
414 | ret = IRQ_WAKE_THREAD; | ||
415 | |||
416 | ti_qspi_write(qspi, QSPI_WC_INT_DISABLE, QSPI_INTR_ENABLE_CLEAR_REG); | ||
417 | ti_qspi_write(qspi, QSPI_WC_INT_DISABLE, | 409 | ti_qspi_write(qspi, QSPI_WC_INT_DISABLE, |
418 | QSPI_INTR_STATUS_ENABLED_CLEAR); | 410 | QSPI_INTR_STATUS_ENABLED_CLEAR); |
419 | 411 | if (stat & WC) | |
412 | complete(&qspi->transfer_complete); | ||
420 | out: | 413 | out: |
421 | spin_unlock(&qspi->lock); | ||
422 | |||
423 | return ret; | 414 | return ret; |
424 | } | 415 | } |
425 | 416 | ||
426 | static irqreturn_t ti_qspi_threaded_isr(int this_irq, void *dev_id) | ||
427 | { | ||
428 | struct ti_qspi *qspi = dev_id; | ||
429 | unsigned long flags; | ||
430 | |||
431 | spin_lock_irqsave(&qspi->lock, flags); | ||
432 | |||
433 | if (qspi->stat & WC) | ||
434 | complete(&qspi->transfer_complete); | ||
435 | |||
436 | spin_unlock_irqrestore(&qspi->lock, flags); | ||
437 | |||
438 | ti_qspi_write(qspi, QSPI_WC_INT_EN, QSPI_INTR_ENABLE_SET_REG); | ||
439 | |||
440 | return IRQ_HANDLED; | ||
441 | } | ||
442 | |||
443 | static int ti_qspi_runtime_resume(struct device *dev) | 417 | static int ti_qspi_runtime_resume(struct device *dev) |
444 | { | 418 | { |
445 | struct ti_qspi *qspi; | 419 | struct ti_qspi *qspi; |
@@ -472,7 +446,7 @@ static int ti_qspi_probe(struct platform_device *pdev) | |||
472 | if (!master) | 446 | if (!master) |
473 | return -ENOMEM; | 447 | return -ENOMEM; |
474 | 448 | ||
475 | master->mode_bits = SPI_CPOL | SPI_CPHA; | 449 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_RX_DUAL | SPI_RX_QUAD; |
476 | 450 | ||
477 | master->bus_num = -1; | 451 | master->bus_num = -1; |
478 | master->flags = SPI_MASTER_HALF_DUPLEX; | 452 | master->flags = SPI_MASTER_HALF_DUPLEX; |
@@ -485,11 +459,10 @@ static int ti_qspi_probe(struct platform_device *pdev) | |||
485 | if (!of_property_read_u32(np, "num-cs", &num_cs)) | 459 | if (!of_property_read_u32(np, "num-cs", &num_cs)) |
486 | master->num_chipselect = num_cs; | 460 | master->num_chipselect = num_cs; |
487 | 461 | ||
488 | platform_set_drvdata(pdev, master); | ||
489 | |||
490 | qspi = spi_master_get_devdata(master); | 462 | qspi = spi_master_get_devdata(master); |
491 | qspi->master = master; | 463 | qspi->master = master; |
492 | qspi->dev = &pdev->dev; | 464 | qspi->dev = &pdev->dev; |
465 | platform_set_drvdata(pdev, qspi); | ||
493 | 466 | ||
494 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 467 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
495 | 468 | ||
@@ -499,7 +472,6 @@ static int ti_qspi_probe(struct platform_device *pdev) | |||
499 | return irq; | 472 | return irq; |
500 | } | 473 | } |
501 | 474 | ||
502 | spin_lock_init(&qspi->lock); | ||
503 | mutex_init(&qspi->list_lock); | 475 | mutex_init(&qspi->list_lock); |
504 | 476 | ||
505 | qspi->base = devm_ioremap_resource(&pdev->dev, r); | 477 | qspi->base = devm_ioremap_resource(&pdev->dev, r); |
@@ -508,8 +480,7 @@ static int ti_qspi_probe(struct platform_device *pdev) | |||
508 | goto free_master; | 480 | goto free_master; |
509 | } | 481 | } |
510 | 482 | ||
511 | ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr, | 483 | ret = devm_request_irq(&pdev->dev, irq, ti_qspi_isr, 0, |
512 | ti_qspi_threaded_isr, 0, | ||
513 | dev_name(&pdev->dev), qspi); | 484 | dev_name(&pdev->dev), qspi); |
514 | if (ret < 0) { | 485 | if (ret < 0) { |
515 | dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n", | 486 | dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n", |
@@ -532,7 +503,7 @@ static int ti_qspi_probe(struct platform_device *pdev) | |||
532 | if (!of_property_read_u32(np, "spi-max-frequency", &max_freq)) | 503 | if (!of_property_read_u32(np, "spi-max-frequency", &max_freq)) |
533 | qspi->spi_max_frequency = max_freq; | 504 | qspi->spi_max_frequency = max_freq; |
534 | 505 | ||
535 | ret = spi_register_master(master); | 506 | ret = devm_spi_register_master(&pdev->dev, master); |
536 | if (ret) | 507 | if (ret) |
537 | goto free_master; | 508 | goto free_master; |
538 | 509 | ||
@@ -545,9 +516,25 @@ free_master: | |||
545 | 516 | ||
546 | static int ti_qspi_remove(struct platform_device *pdev) | 517 | static int ti_qspi_remove(struct platform_device *pdev) |
547 | { | 518 | { |
548 | struct ti_qspi *qspi = platform_get_drvdata(pdev); | 519 | struct spi_master *master; |
520 | struct ti_qspi *qspi; | ||
521 | int ret; | ||
522 | |||
523 | master = platform_get_drvdata(pdev); | ||
524 | qspi = spi_master_get_devdata(master); | ||
525 | |||
526 | ret = pm_runtime_get_sync(qspi->dev); | ||
527 | if (ret < 0) { | ||
528 | dev_err(qspi->dev, "pm_runtime_get_sync() failed\n"); | ||
529 | return ret; | ||
530 | } | ||
531 | |||
532 | ti_qspi_write(qspi, QSPI_WC_INT_DISABLE, QSPI_INTR_ENABLE_CLEAR_REG); | ||
533 | |||
534 | pm_runtime_put(qspi->dev); | ||
535 | pm_runtime_disable(&pdev->dev); | ||
549 | 536 | ||
550 | spi_unregister_master(qspi->master); | 537 | spi_unregister_master(master); |
551 | 538 | ||
552 | return 0; | 539 | return 0; |
553 | } | 540 | } |
@@ -558,7 +545,7 @@ static const struct dev_pm_ops ti_qspi_pm_ops = { | |||
558 | 545 | ||
559 | static struct platform_driver ti_qspi_driver = { | 546 | static struct platform_driver ti_qspi_driver = { |
560 | .probe = ti_qspi_probe, | 547 | .probe = ti_qspi_probe, |
561 | .remove = ti_qspi_remove, | 548 | .remove = ti_qspi_remove, |
562 | .driver = { | 549 | .driver = { |
563 | .name = "ti,dra7xxx-qspi", | 550 | .name = "ti,dra7xxx-qspi", |
564 | .owner = THIS_MODULE, | 551 | .owner = THIS_MODULE, |
diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c index eaeeed51bbbf..446131308acb 100644 --- a/drivers/spi/spi-topcliff-pch.c +++ b/drivers/spi/spi-topcliff-pch.c | |||
@@ -506,8 +506,8 @@ static int pch_spi_transfer(struct spi_device *pspi, struct spi_message *pmsg) | |||
506 | goto err_out; | 506 | goto err_out; |
507 | } | 507 | } |
508 | 508 | ||
509 | dev_dbg(&pspi->dev, "%s Transfer List not empty. " | 509 | dev_dbg(&pspi->dev, |
510 | "Transfer Speed is set.\n", __func__); | 510 | "%s Transfer List not empty. Transfer Speed is set.\n", __func__); |
511 | 511 | ||
512 | spin_lock_irqsave(&data->lock, flags); | 512 | spin_lock_irqsave(&data->lock, flags); |
513 | /* validate Tx/Rx buffers and Transfer length */ | 513 | /* validate Tx/Rx buffers and Transfer length */ |
@@ -526,8 +526,9 @@ static int pch_spi_transfer(struct spi_device *pspi, struct spi_message *pmsg) | |||
526 | goto err_return_spinlock; | 526 | goto err_return_spinlock; |
527 | } | 527 | } |
528 | 528 | ||
529 | dev_dbg(&pspi->dev, "%s Tx/Rx buffer valid. Transfer length" | 529 | dev_dbg(&pspi->dev, |
530 | " valid\n", __func__); | 530 | "%s Tx/Rx buffer valid. Transfer length valid\n", |
531 | __func__); | ||
531 | 532 | ||
532 | /* if baud rate has been specified validate the same */ | 533 | /* if baud rate has been specified validate the same */ |
533 | if (transfer->speed_hz > PCH_MAX_BAUDRATE) | 534 | if (transfer->speed_hz > PCH_MAX_BAUDRATE) |
@@ -1181,8 +1182,8 @@ static void pch_spi_process_messages(struct work_struct *pwork) | |||
1181 | spin_lock(&data->lock); | 1182 | spin_lock(&data->lock); |
1182 | /* check if suspend has been initiated;if yes flush queue */ | 1183 | /* check if suspend has been initiated;if yes flush queue */ |
1183 | if (data->board_dat->suspend_sts || (data->status == STATUS_EXITING)) { | 1184 | if (data->board_dat->suspend_sts || (data->status == STATUS_EXITING)) { |
1184 | dev_dbg(&data->master->dev, "%s suspend/remove initiated," | 1185 | dev_dbg(&data->master->dev, |
1185 | "flushing queue\n", __func__); | 1186 | "%s suspend/remove initiated, flushing queue\n", __func__); |
1186 | list_for_each_entry_safe(pmsg, tmp, data->queue.next, queue) { | 1187 | list_for_each_entry_safe(pmsg, tmp, data->queue.next, queue) { |
1187 | pmsg->status = -EIO; | 1188 | pmsg->status = -EIO; |
1188 | 1189 | ||
@@ -1410,13 +1411,13 @@ static int pch_spi_pd_probe(struct platform_device *plat_dev) | |||
1410 | /* baseaddress + address offset) */ | 1411 | /* baseaddress + address offset) */ |
1411 | data->io_base_addr = pci_resource_start(board_dat->pdev, 1) + | 1412 | data->io_base_addr = pci_resource_start(board_dat->pdev, 1) + |
1412 | PCH_ADDRESS_SIZE * plat_dev->id; | 1413 | PCH_ADDRESS_SIZE * plat_dev->id; |
1413 | data->io_remap_addr = pci_iomap(board_dat->pdev, 1, 0) + | 1414 | data->io_remap_addr = pci_iomap(board_dat->pdev, 1, 0); |
1414 | PCH_ADDRESS_SIZE * plat_dev->id; | ||
1415 | if (!data->io_remap_addr) { | 1415 | if (!data->io_remap_addr) { |
1416 | dev_err(&plat_dev->dev, "%s pci_iomap failed\n", __func__); | 1416 | dev_err(&plat_dev->dev, "%s pci_iomap failed\n", __func__); |
1417 | ret = -ENOMEM; | 1417 | ret = -ENOMEM; |
1418 | goto err_pci_iomap; | 1418 | goto err_pci_iomap; |
1419 | } | 1419 | } |
1420 | data->io_remap_addr += PCH_ADDRESS_SIZE * plat_dev->id; | ||
1420 | 1421 | ||
1421 | dev_dbg(&plat_dev->dev, "[ch%d] remap_addr=%p\n", | 1422 | dev_dbg(&plat_dev->dev, "[ch%d] remap_addr=%p\n", |
1422 | plat_dev->id, data->io_remap_addr); | 1423 | plat_dev->id, data->io_remap_addr); |
diff --git a/drivers/spi/spi-txx9.c b/drivers/spi/spi-txx9.c index 7c6d15766c72..18c9bb2b5f39 100644 --- a/drivers/spi/spi-txx9.c +++ b/drivers/spi/spi-txx9.c | |||
@@ -177,7 +177,7 @@ static void txx9spi_work_one(struct txx9spi *c, struct spi_message *m) | |||
177 | | 0x08, | 177 | | 0x08, |
178 | TXx9_SPCR0); | 178 | TXx9_SPCR0); |
179 | 179 | ||
180 | list_for_each_entry (t, &m->transfers, transfer_list) { | 180 | list_for_each_entry(t, &m->transfers, transfer_list) { |
181 | const void *txbuf = t->tx_buf; | 181 | const void *txbuf = t->tx_buf; |
182 | void *rxbuf = t->rx_buf; | 182 | void *rxbuf = t->rx_buf; |
183 | u32 data; | 183 | u32 data; |
@@ -308,7 +308,7 @@ static int txx9spi_transfer(struct spi_device *spi, struct spi_message *m) | |||
308 | m->actual_length = 0; | 308 | m->actual_length = 0; |
309 | 309 | ||
310 | /* check each transfer's parameters */ | 310 | /* check each transfer's parameters */ |
311 | list_for_each_entry (t, &m->transfers, transfer_list) { | 311 | list_for_each_entry(t, &m->transfers, transfer_list) { |
312 | u32 speed_hz = t->speed_hz ? : spi->max_speed_hz; | 312 | u32 speed_hz = t->speed_hz ? : spi->max_speed_hz; |
313 | u8 bits_per_word = t->bits_per_word; | 313 | u8 bits_per_word = t->bits_per_word; |
314 | 314 | ||
@@ -406,7 +406,7 @@ static int txx9spi_probe(struct platform_device *dev) | |||
406 | master->num_chipselect = (u16)UINT_MAX; /* any GPIO numbers */ | 406 | master->num_chipselect = (u16)UINT_MAX; /* any GPIO numbers */ |
407 | master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16); | 407 | master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16); |
408 | 408 | ||
409 | ret = spi_register_master(master); | 409 | ret = devm_spi_register_master(&dev->dev, master); |
410 | if (ret) | 410 | if (ret) |
411 | goto exit; | 411 | goto exit; |
412 | return 0; | 412 | return 0; |
@@ -425,14 +425,12 @@ exit: | |||
425 | 425 | ||
426 | static int txx9spi_remove(struct platform_device *dev) | 426 | static int txx9spi_remove(struct platform_device *dev) |
427 | { | 427 | { |
428 | struct spi_master *master = spi_master_get(platform_get_drvdata(dev)); | 428 | struct spi_master *master = platform_get_drvdata(dev); |
429 | struct txx9spi *c = spi_master_get_devdata(master); | 429 | struct txx9spi *c = spi_master_get_devdata(master); |
430 | 430 | ||
431 | spi_unregister_master(master); | ||
432 | destroy_workqueue(c->workqueue); | 431 | destroy_workqueue(c->workqueue); |
433 | clk_disable(c->clk); | 432 | clk_disable(c->clk); |
434 | clk_put(c->clk); | 433 | clk_put(c->clk); |
435 | spi_master_put(master); | ||
436 | return 0; | 434 | return 0; |
437 | } | 435 | } |
438 | 436 | ||
@@ -440,6 +438,7 @@ static int txx9spi_remove(struct platform_device *dev) | |||
440 | MODULE_ALIAS("platform:spi_txx9"); | 438 | MODULE_ALIAS("platform:spi_txx9"); |
441 | 439 | ||
442 | static struct platform_driver txx9spi_driver = { | 440 | static struct platform_driver txx9spi_driver = { |
441 | .probe = txx9spi_probe, | ||
443 | .remove = txx9spi_remove, | 442 | .remove = txx9spi_remove, |
444 | .driver = { | 443 | .driver = { |
445 | .name = "spi_txx9", | 444 | .name = "spi_txx9", |
@@ -449,7 +448,7 @@ static struct platform_driver txx9spi_driver = { | |||
449 | 448 | ||
450 | static int __init txx9spi_init(void) | 449 | static int __init txx9spi_init(void) |
451 | { | 450 | { |
452 | return platform_driver_probe(&txx9spi_driver, txx9spi_probe); | 451 | return platform_driver_register(&txx9spi_driver); |
453 | } | 452 | } |
454 | subsys_initcall(txx9spi_init); | 453 | subsys_initcall(txx9spi_init); |
455 | 454 | ||
diff --git a/drivers/spi/spi-xilinx.c b/drivers/spi/spi-xilinx.c index 0bf1b2c457a1..6d4ce4615163 100644 --- a/drivers/spi/spi-xilinx.c +++ b/drivers/spi/spi-xilinx.c | |||
@@ -258,7 +258,7 @@ static int xilinx_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) | |||
258 | xspi->tx_ptr = t->tx_buf; | 258 | xspi->tx_ptr = t->tx_buf; |
259 | xspi->rx_ptr = t->rx_buf; | 259 | xspi->rx_ptr = t->rx_buf; |
260 | xspi->remaining_bytes = t->len; | 260 | xspi->remaining_bytes = t->len; |
261 | INIT_COMPLETION(xspi->done); | 261 | reinit_completion(&xspi->done); |
262 | 262 | ||
263 | 263 | ||
264 | /* Enable the transmit empty interrupt, which we use to determine | 264 | /* Enable the transmit empty interrupt, which we use to determine |
@@ -372,7 +372,7 @@ static int xilinx_spi_probe(struct platform_device *pdev) | |||
372 | master->mode_bits = SPI_CPOL | SPI_CPHA; | 372 | master->mode_bits = SPI_CPOL | SPI_CPHA; |
373 | 373 | ||
374 | xspi = spi_master_get_devdata(master); | 374 | xspi = spi_master_get_devdata(master); |
375 | xspi->bitbang.master = spi_master_get(master); | 375 | xspi->bitbang.master = master; |
376 | xspi->bitbang.chipselect = xilinx_spi_chipselect; | 376 | xspi->bitbang.chipselect = xilinx_spi_chipselect; |
377 | xspi->bitbang.setup_transfer = xilinx_spi_setup_transfer; | 377 | xspi->bitbang.setup_transfer = xilinx_spi_setup_transfer; |
378 | xspi->bitbang.txrx_bufs = xilinx_spi_txrx_bufs; | 378 | xspi->bitbang.txrx_bufs = xilinx_spi_txrx_bufs; |
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 9e039c60c068..349ebba4b199 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c | |||
@@ -39,6 +39,9 @@ | |||
39 | #include <linux/ioport.h> | 39 | #include <linux/ioport.h> |
40 | #include <linux/acpi.h> | 40 | #include <linux/acpi.h> |
41 | 41 | ||
42 | #define CREATE_TRACE_POINTS | ||
43 | #include <trace/events/spi.h> | ||
44 | |||
42 | static void spidev_release(struct device *dev) | 45 | static void spidev_release(struct device *dev) |
43 | { | 46 | { |
44 | struct spi_device *spi = to_spi_device(dev); | 47 | struct spi_device *spi = to_spi_device(dev); |
@@ -58,11 +61,13 @@ modalias_show(struct device *dev, struct device_attribute *a, char *buf) | |||
58 | 61 | ||
59 | return sprintf(buf, "%s%s\n", SPI_MODULE_PREFIX, spi->modalias); | 62 | return sprintf(buf, "%s%s\n", SPI_MODULE_PREFIX, spi->modalias); |
60 | } | 63 | } |
64 | static DEVICE_ATTR_RO(modalias); | ||
61 | 65 | ||
62 | static struct device_attribute spi_dev_attrs[] = { | 66 | static struct attribute *spi_dev_attrs[] = { |
63 | __ATTR_RO(modalias), | 67 | &dev_attr_modalias.attr, |
64 | __ATTR_NULL, | 68 | NULL, |
65 | }; | 69 | }; |
70 | ATTRIBUTE_GROUPS(spi_dev); | ||
66 | 71 | ||
67 | /* modalias support makes "modprobe $MODALIAS" new-style hotplug work, | 72 | /* modalias support makes "modprobe $MODALIAS" new-style hotplug work, |
68 | * and the sysfs version makes coldplug work too. | 73 | * and the sysfs version makes coldplug work too. |
@@ -229,7 +234,7 @@ static const struct dev_pm_ops spi_pm = { | |||
229 | 234 | ||
230 | struct bus_type spi_bus_type = { | 235 | struct bus_type spi_bus_type = { |
231 | .name = "spi", | 236 | .name = "spi", |
232 | .dev_attrs = spi_dev_attrs, | 237 | .dev_groups = spi_dev_groups, |
233 | .match = spi_match_device, | 238 | .match = spi_match_device, |
234 | .uevent = spi_uevent, | 239 | .uevent = spi_uevent, |
235 | .pm = &spi_pm, | 240 | .pm = &spi_pm, |
@@ -240,15 +245,27 @@ EXPORT_SYMBOL_GPL(spi_bus_type); | |||
240 | static int spi_drv_probe(struct device *dev) | 245 | static int spi_drv_probe(struct device *dev) |
241 | { | 246 | { |
242 | const struct spi_driver *sdrv = to_spi_driver(dev->driver); | 247 | const struct spi_driver *sdrv = to_spi_driver(dev->driver); |
248 | struct spi_device *spi = to_spi_device(dev); | ||
249 | int ret; | ||
250 | |||
251 | acpi_dev_pm_attach(&spi->dev, true); | ||
252 | ret = sdrv->probe(spi); | ||
253 | if (ret) | ||
254 | acpi_dev_pm_detach(&spi->dev, true); | ||
243 | 255 | ||
244 | return sdrv->probe(to_spi_device(dev)); | 256 | return ret; |
245 | } | 257 | } |
246 | 258 | ||
247 | static int spi_drv_remove(struct device *dev) | 259 | static int spi_drv_remove(struct device *dev) |
248 | { | 260 | { |
249 | const struct spi_driver *sdrv = to_spi_driver(dev->driver); | 261 | const struct spi_driver *sdrv = to_spi_driver(dev->driver); |
262 | struct spi_device *spi = to_spi_device(dev); | ||
263 | int ret; | ||
264 | |||
265 | ret = sdrv->remove(spi); | ||
266 | acpi_dev_pm_detach(&spi->dev, true); | ||
250 | 267 | ||
251 | return sdrv->remove(to_spi_device(dev)); | 268 | return ret; |
252 | } | 269 | } |
253 | 270 | ||
254 | static void spi_drv_shutdown(struct device *dev) | 271 | static void spi_drv_shutdown(struct device *dev) |
@@ -323,7 +340,7 @@ struct spi_device *spi_alloc_device(struct spi_master *master) | |||
323 | if (!spi_master_get(master)) | 340 | if (!spi_master_get(master)) |
324 | return NULL; | 341 | return NULL; |
325 | 342 | ||
326 | spi = kzalloc(sizeof *spi, GFP_KERNEL); | 343 | spi = kzalloc(sizeof(*spi), GFP_KERNEL); |
327 | if (!spi) { | 344 | if (!spi) { |
328 | dev_err(dev, "cannot alloc spi_device\n"); | 345 | dev_err(dev, "cannot alloc spi_device\n"); |
329 | spi_master_put(master); | 346 | spi_master_put(master); |
@@ -340,6 +357,19 @@ struct spi_device *spi_alloc_device(struct spi_master *master) | |||
340 | } | 357 | } |
341 | EXPORT_SYMBOL_GPL(spi_alloc_device); | 358 | EXPORT_SYMBOL_GPL(spi_alloc_device); |
342 | 359 | ||
360 | static void spi_dev_set_name(struct spi_device *spi) | ||
361 | { | ||
362 | struct acpi_device *adev = ACPI_COMPANION(&spi->dev); | ||
363 | |||
364 | if (adev) { | ||
365 | dev_set_name(&spi->dev, "spi-%s", acpi_dev_name(adev)); | ||
366 | return; | ||
367 | } | ||
368 | |||
369 | dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev), | ||
370 | spi->chip_select); | ||
371 | } | ||
372 | |||
343 | /** | 373 | /** |
344 | * spi_add_device - Add spi_device allocated with spi_alloc_device | 374 | * spi_add_device - Add spi_device allocated with spi_alloc_device |
345 | * @spi: spi_device to register | 375 | * @spi: spi_device to register |
@@ -366,9 +396,7 @@ int spi_add_device(struct spi_device *spi) | |||
366 | } | 396 | } |
367 | 397 | ||
368 | /* Set the bus ID string */ | 398 | /* Set the bus ID string */ |
369 | dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev), | 399 | spi_dev_set_name(spi); |
370 | spi->chip_select); | ||
371 | |||
372 | 400 | ||
373 | /* We need to make sure there's no other device with this | 401 | /* We need to make sure there's no other device with this |
374 | * chipselect **BEFORE** we call setup(), else we'll trash | 402 | * chipselect **BEFORE** we call setup(), else we'll trash |
@@ -523,6 +551,95 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n) | |||
523 | 551 | ||
524 | /*-------------------------------------------------------------------------*/ | 552 | /*-------------------------------------------------------------------------*/ |
525 | 553 | ||
554 | static void spi_set_cs(struct spi_device *spi, bool enable) | ||
555 | { | ||
556 | if (spi->mode & SPI_CS_HIGH) | ||
557 | enable = !enable; | ||
558 | |||
559 | if (spi->cs_gpio >= 0) | ||
560 | gpio_set_value(spi->cs_gpio, !enable); | ||
561 | else if (spi->master->set_cs) | ||
562 | spi->master->set_cs(spi, !enable); | ||
563 | } | ||
564 | |||
565 | /* | ||
566 | * spi_transfer_one_message - Default implementation of transfer_one_message() | ||
567 | * | ||
568 | * This is a standard implementation of transfer_one_message() for | ||
569 | * drivers which impelment a transfer_one() operation. It provides | ||
570 | * standard handling of delays and chip select management. | ||
571 | */ | ||
572 | static int spi_transfer_one_message(struct spi_master *master, | ||
573 | struct spi_message *msg) | ||
574 | { | ||
575 | struct spi_transfer *xfer; | ||
576 | bool cur_cs = true; | ||
577 | bool keep_cs = false; | ||
578 | int ret = 0; | ||
579 | |||
580 | spi_set_cs(msg->spi, true); | ||
581 | |||
582 | list_for_each_entry(xfer, &msg->transfers, transfer_list) { | ||
583 | trace_spi_transfer_start(msg, xfer); | ||
584 | |||
585 | reinit_completion(&master->xfer_completion); | ||
586 | |||
587 | ret = master->transfer_one(master, msg->spi, xfer); | ||
588 | if (ret < 0) { | ||
589 | dev_err(&msg->spi->dev, | ||
590 | "SPI transfer failed: %d\n", ret); | ||
591 | goto out; | ||
592 | } | ||
593 | |||
594 | if (ret > 0) | ||
595 | wait_for_completion(&master->xfer_completion); | ||
596 | |||
597 | trace_spi_transfer_stop(msg, xfer); | ||
598 | |||
599 | if (msg->status != -EINPROGRESS) | ||
600 | goto out; | ||
601 | |||
602 | if (xfer->delay_usecs) | ||
603 | udelay(xfer->delay_usecs); | ||
604 | |||
605 | if (xfer->cs_change) { | ||
606 | if (list_is_last(&xfer->transfer_list, | ||
607 | &msg->transfers)) { | ||
608 | keep_cs = true; | ||
609 | } else { | ||
610 | cur_cs = !cur_cs; | ||
611 | spi_set_cs(msg->spi, cur_cs); | ||
612 | } | ||
613 | } | ||
614 | |||
615 | msg->actual_length += xfer->len; | ||
616 | } | ||
617 | |||
618 | out: | ||
619 | if (ret != 0 || !keep_cs) | ||
620 | spi_set_cs(msg->spi, false); | ||
621 | |||
622 | if (msg->status == -EINPROGRESS) | ||
623 | msg->status = ret; | ||
624 | |||
625 | spi_finalize_current_message(master); | ||
626 | |||
627 | return ret; | ||
628 | } | ||
629 | |||
630 | /** | ||
631 | * spi_finalize_current_transfer - report completion of a transfer | ||
632 | * | ||
633 | * Called by SPI drivers using the core transfer_one_message() | ||
634 | * implementation to notify it that the current interrupt driven | ||
635 | * transfer has finised and the next one may be scheduled. | ||
636 | */ | ||
637 | void spi_finalize_current_transfer(struct spi_master *master) | ||
638 | { | ||
639 | complete(&master->xfer_completion); | ||
640 | } | ||
641 | EXPORT_SYMBOL_GPL(spi_finalize_current_transfer); | ||
642 | |||
526 | /** | 643 | /** |
527 | * spi_pump_messages - kthread work function which processes spi message queue | 644 | * spi_pump_messages - kthread work function which processes spi message queue |
528 | * @work: pointer to kthread work struct contained in the master struct | 645 | * @work: pointer to kthread work struct contained in the master struct |
@@ -557,6 +674,7 @@ static void spi_pump_messages(struct kthread_work *work) | |||
557 | pm_runtime_mark_last_busy(master->dev.parent); | 674 | pm_runtime_mark_last_busy(master->dev.parent); |
558 | pm_runtime_put_autosuspend(master->dev.parent); | 675 | pm_runtime_put_autosuspend(master->dev.parent); |
559 | } | 676 | } |
677 | trace_spi_master_idle(master); | ||
560 | return; | 678 | return; |
561 | } | 679 | } |
562 | 680 | ||
@@ -585,6 +703,9 @@ static void spi_pump_messages(struct kthread_work *work) | |||
585 | } | 703 | } |
586 | } | 704 | } |
587 | 705 | ||
706 | if (!was_busy) | ||
707 | trace_spi_master_busy(master); | ||
708 | |||
588 | if (!was_busy && master->prepare_transfer_hardware) { | 709 | if (!was_busy && master->prepare_transfer_hardware) { |
589 | ret = master->prepare_transfer_hardware(master); | 710 | ret = master->prepare_transfer_hardware(master); |
590 | if (ret) { | 711 | if (ret) { |
@@ -597,6 +718,20 @@ static void spi_pump_messages(struct kthread_work *work) | |||
597 | } | 718 | } |
598 | } | 719 | } |
599 | 720 | ||
721 | trace_spi_message_start(master->cur_msg); | ||
722 | |||
723 | if (master->prepare_message) { | ||
724 | ret = master->prepare_message(master, master->cur_msg); | ||
725 | if (ret) { | ||
726 | dev_err(&master->dev, | ||
727 | "failed to prepare message: %d\n", ret); | ||
728 | master->cur_msg->status = ret; | ||
729 | spi_finalize_current_message(master); | ||
730 | return; | ||
731 | } | ||
732 | master->cur_msg_prepared = true; | ||
733 | } | ||
734 | |||
600 | ret = master->transfer_one_message(master, master->cur_msg); | 735 | ret = master->transfer_one_message(master, master->cur_msg); |
601 | if (ret) { | 736 | if (ret) { |
602 | dev_err(&master->dev, | 737 | dev_err(&master->dev, |
@@ -678,6 +813,7 @@ void spi_finalize_current_message(struct spi_master *master) | |||
678 | { | 813 | { |
679 | struct spi_message *mesg; | 814 | struct spi_message *mesg; |
680 | unsigned long flags; | 815 | unsigned long flags; |
816 | int ret; | ||
681 | 817 | ||
682 | spin_lock_irqsave(&master->queue_lock, flags); | 818 | spin_lock_irqsave(&master->queue_lock, flags); |
683 | mesg = master->cur_msg; | 819 | mesg = master->cur_msg; |
@@ -686,9 +822,20 @@ void spi_finalize_current_message(struct spi_master *master) | |||
686 | queue_kthread_work(&master->kworker, &master->pump_messages); | 822 | queue_kthread_work(&master->kworker, &master->pump_messages); |
687 | spin_unlock_irqrestore(&master->queue_lock, flags); | 823 | spin_unlock_irqrestore(&master->queue_lock, flags); |
688 | 824 | ||
825 | if (master->cur_msg_prepared && master->unprepare_message) { | ||
826 | ret = master->unprepare_message(master, mesg); | ||
827 | if (ret) { | ||
828 | dev_err(&master->dev, | ||
829 | "failed to unprepare message: %d\n", ret); | ||
830 | } | ||
831 | } | ||
832 | master->cur_msg_prepared = false; | ||
833 | |||
689 | mesg->state = NULL; | 834 | mesg->state = NULL; |
690 | if (mesg->complete) | 835 | if (mesg->complete) |
691 | mesg->complete(mesg->context); | 836 | mesg->complete(mesg->context); |
837 | |||
838 | trace_spi_message_done(mesg); | ||
692 | } | 839 | } |
693 | EXPORT_SYMBOL_GPL(spi_finalize_current_message); | 840 | EXPORT_SYMBOL_GPL(spi_finalize_current_message); |
694 | 841 | ||
@@ -803,6 +950,8 @@ static int spi_master_initialize_queue(struct spi_master *master) | |||
803 | 950 | ||
804 | master->queued = true; | 951 | master->queued = true; |
805 | master->transfer = spi_queued_transfer; | 952 | master->transfer = spi_queued_transfer; |
953 | if (!master->transfer_one_message) | ||
954 | master->transfer_one_message = spi_transfer_one_message; | ||
806 | 955 | ||
807 | /* Initialize and start queue */ | 956 | /* Initialize and start queue */ |
808 | ret = spi_init_queue(master); | 957 | ret = spi_init_queue(master); |
@@ -838,10 +987,8 @@ static void of_register_spi_devices(struct spi_master *master) | |||
838 | { | 987 | { |
839 | struct spi_device *spi; | 988 | struct spi_device *spi; |
840 | struct device_node *nc; | 989 | struct device_node *nc; |
841 | const __be32 *prop; | ||
842 | char modalias[SPI_NAME_SIZE + 4]; | ||
843 | int rc; | 990 | int rc; |
844 | int len; | 991 | u32 value; |
845 | 992 | ||
846 | if (!master->dev.of_node) | 993 | if (!master->dev.of_node) |
847 | return; | 994 | return; |
@@ -866,14 +1013,14 @@ static void of_register_spi_devices(struct spi_master *master) | |||
866 | } | 1013 | } |
867 | 1014 | ||
868 | /* Device address */ | 1015 | /* Device address */ |
869 | prop = of_get_property(nc, "reg", &len); | 1016 | rc = of_property_read_u32(nc, "reg", &value); |
870 | if (!prop || len < sizeof(*prop)) { | 1017 | if (rc) { |
871 | dev_err(&master->dev, "%s has no 'reg' property\n", | 1018 | dev_err(&master->dev, "%s has no valid 'reg' property (%d)\n", |
872 | nc->full_name); | 1019 | nc->full_name, rc); |
873 | spi_dev_put(spi); | 1020 | spi_dev_put(spi); |
874 | continue; | 1021 | continue; |
875 | } | 1022 | } |
876 | spi->chip_select = be32_to_cpup(prop); | 1023 | spi->chip_select = value; |
877 | 1024 | ||
878 | /* Mode (clock phase/polarity/etc.) */ | 1025 | /* Mode (clock phase/polarity/etc.) */ |
879 | if (of_find_property(nc, "spi-cpha", NULL)) | 1026 | if (of_find_property(nc, "spi-cpha", NULL)) |
@@ -886,55 +1033,53 @@ static void of_register_spi_devices(struct spi_master *master) | |||
886 | spi->mode |= SPI_3WIRE; | 1033 | spi->mode |= SPI_3WIRE; |
887 | 1034 | ||
888 | /* Device DUAL/QUAD mode */ | 1035 | /* Device DUAL/QUAD mode */ |
889 | prop = of_get_property(nc, "spi-tx-bus-width", &len); | 1036 | if (!of_property_read_u32(nc, "spi-tx-bus-width", &value)) { |
890 | if (prop && len == sizeof(*prop)) { | 1037 | switch (value) { |
891 | switch (be32_to_cpup(prop)) { | 1038 | case 1: |
892 | case SPI_NBITS_SINGLE: | ||
893 | break; | 1039 | break; |
894 | case SPI_NBITS_DUAL: | 1040 | case 2: |
895 | spi->mode |= SPI_TX_DUAL; | 1041 | spi->mode |= SPI_TX_DUAL; |
896 | break; | 1042 | break; |
897 | case SPI_NBITS_QUAD: | 1043 | case 4: |
898 | spi->mode |= SPI_TX_QUAD; | 1044 | spi->mode |= SPI_TX_QUAD; |
899 | break; | 1045 | break; |
900 | default: | 1046 | default: |
901 | dev_err(&master->dev, | 1047 | dev_err(&master->dev, |
902 | "spi-tx-bus-width %d not supported\n", | 1048 | "spi-tx-bus-width %d not supported\n", |
903 | be32_to_cpup(prop)); | 1049 | value); |
904 | spi_dev_put(spi); | 1050 | spi_dev_put(spi); |
905 | continue; | 1051 | continue; |
906 | } | 1052 | } |
907 | } | 1053 | } |
908 | 1054 | ||
909 | prop = of_get_property(nc, "spi-rx-bus-width", &len); | 1055 | if (!of_property_read_u32(nc, "spi-rx-bus-width", &value)) { |
910 | if (prop && len == sizeof(*prop)) { | 1056 | switch (value) { |
911 | switch (be32_to_cpup(prop)) { | 1057 | case 1: |
912 | case SPI_NBITS_SINGLE: | ||
913 | break; | 1058 | break; |
914 | case SPI_NBITS_DUAL: | 1059 | case 2: |
915 | spi->mode |= SPI_RX_DUAL; | 1060 | spi->mode |= SPI_RX_DUAL; |
916 | break; | 1061 | break; |
917 | case SPI_NBITS_QUAD: | 1062 | case 4: |
918 | spi->mode |= SPI_RX_QUAD; | 1063 | spi->mode |= SPI_RX_QUAD; |
919 | break; | 1064 | break; |
920 | default: | 1065 | default: |
921 | dev_err(&master->dev, | 1066 | dev_err(&master->dev, |
922 | "spi-rx-bus-width %d not supported\n", | 1067 | "spi-rx-bus-width %d not supported\n", |
923 | be32_to_cpup(prop)); | 1068 | value); |
924 | spi_dev_put(spi); | 1069 | spi_dev_put(spi); |
925 | continue; | 1070 | continue; |
926 | } | 1071 | } |
927 | } | 1072 | } |
928 | 1073 | ||
929 | /* Device speed */ | 1074 | /* Device speed */ |
930 | prop = of_get_property(nc, "spi-max-frequency", &len); | 1075 | rc = of_property_read_u32(nc, "spi-max-frequency", &value); |
931 | if (!prop || len < sizeof(*prop)) { | 1076 | if (rc) { |
932 | dev_err(&master->dev, "%s has no 'spi-max-frequency' property\n", | 1077 | dev_err(&master->dev, "%s has no valid 'spi-max-frequency' property (%d)\n", |
933 | nc->full_name); | 1078 | nc->full_name, rc); |
934 | spi_dev_put(spi); | 1079 | spi_dev_put(spi); |
935 | continue; | 1080 | continue; |
936 | } | 1081 | } |
937 | spi->max_speed_hz = be32_to_cpup(prop); | 1082 | spi->max_speed_hz = value; |
938 | 1083 | ||
939 | /* IRQ */ | 1084 | /* IRQ */ |
940 | spi->irq = irq_of_parse_and_map(nc, 0); | 1085 | spi->irq = irq_of_parse_and_map(nc, 0); |
@@ -944,9 +1089,7 @@ static void of_register_spi_devices(struct spi_master *master) | |||
944 | spi->dev.of_node = nc; | 1089 | spi->dev.of_node = nc; |
945 | 1090 | ||
946 | /* Register the new device */ | 1091 | /* Register the new device */ |
947 | snprintf(modalias, sizeof(modalias), "%s%s", SPI_MODULE_PREFIX, | 1092 | request_module("%s%s", SPI_MODULE_PREFIX, spi->modalias); |
948 | spi->modalias); | ||
949 | request_module(modalias); | ||
950 | rc = spi_add_device(spi); | 1093 | rc = spi_add_device(spi); |
951 | if (rc) { | 1094 | if (rc) { |
952 | dev_err(&master->dev, "spi_device register error %s\n", | 1095 | dev_err(&master->dev, "spi_device register error %s\n", |
@@ -1012,7 +1155,7 @@ static acpi_status acpi_spi_add_device(acpi_handle handle, u32 level, | |||
1012 | return AE_NO_MEMORY; | 1155 | return AE_NO_MEMORY; |
1013 | } | 1156 | } |
1014 | 1157 | ||
1015 | ACPI_HANDLE_SET(&spi->dev, handle); | 1158 | ACPI_COMPANION_SET(&spi->dev, adev); |
1016 | spi->irq = -1; | 1159 | spi->irq = -1; |
1017 | 1160 | ||
1018 | INIT_LIST_HEAD(&resource_list); | 1161 | INIT_LIST_HEAD(&resource_list); |
@@ -1025,8 +1168,10 @@ static acpi_status acpi_spi_add_device(acpi_handle handle, u32 level, | |||
1025 | return AE_OK; | 1168 | return AE_OK; |
1026 | } | 1169 | } |
1027 | 1170 | ||
1028 | strlcpy(spi->modalias, dev_name(&adev->dev), sizeof(spi->modalias)); | 1171 | adev->power.flags.ignore_parent = true; |
1172 | strlcpy(spi->modalias, acpi_device_hid(adev), sizeof(spi->modalias)); | ||
1029 | if (spi_add_device(spi)) { | 1173 | if (spi_add_device(spi)) { |
1174 | adev->power.flags.ignore_parent = false; | ||
1030 | dev_err(&master->dev, "failed to add SPI device %s from ACPI\n", | 1175 | dev_err(&master->dev, "failed to add SPI device %s from ACPI\n", |
1031 | dev_name(&adev->dev)); | 1176 | dev_name(&adev->dev)); |
1032 | spi_dev_put(spi); | 1177 | spi_dev_put(spi); |
@@ -1097,7 +1242,7 @@ struct spi_master *spi_alloc_master(struct device *dev, unsigned size) | |||
1097 | if (!dev) | 1242 | if (!dev) |
1098 | return NULL; | 1243 | return NULL; |
1099 | 1244 | ||
1100 | master = kzalloc(size + sizeof *master, GFP_KERNEL); | 1245 | master = kzalloc(size + sizeof(*master), GFP_KERNEL); |
1101 | if (!master) | 1246 | if (!master) |
1102 | return NULL; | 1247 | return NULL; |
1103 | 1248 | ||
@@ -1122,7 +1267,7 @@ static int of_spi_register_master(struct spi_master *master) | |||
1122 | return 0; | 1267 | return 0; |
1123 | 1268 | ||
1124 | nb = of_gpio_named_count(np, "cs-gpios"); | 1269 | nb = of_gpio_named_count(np, "cs-gpios"); |
1125 | master->num_chipselect = max(nb, (int)master->num_chipselect); | 1270 | master->num_chipselect = max_t(int, nb, master->num_chipselect); |
1126 | 1271 | ||
1127 | /* Return error only for an incorrectly formed cs-gpios property */ | 1272 | /* Return error only for an incorrectly formed cs-gpios property */ |
1128 | if (nb == 0 || nb == -ENOENT) | 1273 | if (nb == 0 || nb == -ENOENT) |
@@ -1209,6 +1354,7 @@ int spi_register_master(struct spi_master *master) | |||
1209 | spin_lock_init(&master->bus_lock_spinlock); | 1354 | spin_lock_init(&master->bus_lock_spinlock); |
1210 | mutex_init(&master->bus_lock_mutex); | 1355 | mutex_init(&master->bus_lock_mutex); |
1211 | master->bus_lock_flag = 0; | 1356 | master->bus_lock_flag = 0; |
1357 | init_completion(&master->xfer_completion); | ||
1212 | 1358 | ||
1213 | /* register the device, then userspace will see it. | 1359 | /* register the device, then userspace will see it. |
1214 | * registration fails if the bus ID is in use. | 1360 | * registration fails if the bus ID is in use. |
@@ -1245,6 +1391,41 @@ done: | |||
1245 | } | 1391 | } |
1246 | EXPORT_SYMBOL_GPL(spi_register_master); | 1392 | EXPORT_SYMBOL_GPL(spi_register_master); |
1247 | 1393 | ||
1394 | static void devm_spi_unregister(struct device *dev, void *res) | ||
1395 | { | ||
1396 | spi_unregister_master(*(struct spi_master **)res); | ||
1397 | } | ||
1398 | |||
1399 | /** | ||
1400 | * dev_spi_register_master - register managed SPI master controller | ||
1401 | * @dev: device managing SPI master | ||
1402 | * @master: initialized master, originally from spi_alloc_master() | ||
1403 | * Context: can sleep | ||
1404 | * | ||
1405 | * Register a SPI device as with spi_register_master() which will | ||
1406 | * automatically be unregister | ||
1407 | */ | ||
1408 | int devm_spi_register_master(struct device *dev, struct spi_master *master) | ||
1409 | { | ||
1410 | struct spi_master **ptr; | ||
1411 | int ret; | ||
1412 | |||
1413 | ptr = devres_alloc(devm_spi_unregister, sizeof(*ptr), GFP_KERNEL); | ||
1414 | if (!ptr) | ||
1415 | return -ENOMEM; | ||
1416 | |||
1417 | ret = spi_register_master(master); | ||
1418 | if (!ret) { | ||
1419 | *ptr = master; | ||
1420 | devres_add(dev, ptr); | ||
1421 | } else { | ||
1422 | devres_free(ptr); | ||
1423 | } | ||
1424 | |||
1425 | return ret; | ||
1426 | } | ||
1427 | EXPORT_SYMBOL_GPL(devm_spi_register_master); | ||
1428 | |||
1248 | static int __unregister(struct device *dev, void *null) | 1429 | static int __unregister(struct device *dev, void *null) |
1249 | { | 1430 | { |
1250 | spi_unregister_device(to_spi_device(dev)); | 1431 | spi_unregister_device(to_spi_device(dev)); |
@@ -1402,8 +1583,7 @@ int spi_setup(struct spi_device *spi) | |||
1402 | if (spi->master->setup) | 1583 | if (spi->master->setup) |
1403 | status = spi->master->setup(spi); | 1584 | status = spi->master->setup(spi); |
1404 | 1585 | ||
1405 | dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s" | 1586 | dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s%u bits/w, %u Hz max --> %d\n", |
1406 | "%u bits/w, %u Hz max --> %d\n", | ||
1407 | (int) (spi->mode & (SPI_CPOL | SPI_CPHA)), | 1587 | (int) (spi->mode & (SPI_CPOL | SPI_CPHA)), |
1408 | (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "", | 1588 | (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "", |
1409 | (spi->mode & SPI_LSB_FIRST) ? "lsb, " : "", | 1589 | (spi->mode & SPI_LSB_FIRST) ? "lsb, " : "", |
@@ -1421,6 +1601,10 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message) | |||
1421 | struct spi_master *master = spi->master; | 1601 | struct spi_master *master = spi->master; |
1422 | struct spi_transfer *xfer; | 1602 | struct spi_transfer *xfer; |
1423 | 1603 | ||
1604 | message->spi = spi; | ||
1605 | |||
1606 | trace_spi_message_submit(message); | ||
1607 | |||
1424 | if (list_empty(&message->transfers)) | 1608 | if (list_empty(&message->transfers)) |
1425 | return -EINVAL; | 1609 | return -EINVAL; |
1426 | if (!message->complete) | 1610 | if (!message->complete) |
@@ -1520,7 +1704,6 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message) | |||
1520 | } | 1704 | } |
1521 | } | 1705 | } |
1522 | 1706 | ||
1523 | message->spi = spi; | ||
1524 | message->status = -EINPROGRESS; | 1707 | message->status = -EINPROGRESS; |
1525 | return master->transfer(spi, message); | 1708 | return master->transfer(spi, message); |
1526 | } | 1709 | } |
@@ -1762,7 +1945,7 @@ int spi_bus_unlock(struct spi_master *master) | |||
1762 | EXPORT_SYMBOL_GPL(spi_bus_unlock); | 1945 | EXPORT_SYMBOL_GPL(spi_bus_unlock); |
1763 | 1946 | ||
1764 | /* portable code must never pass more than 32 bytes */ | 1947 | /* portable code must never pass more than 32 bytes */ |
1765 | #define SPI_BUFSIZ max(32,SMP_CACHE_BYTES) | 1948 | #define SPI_BUFSIZ max(32, SMP_CACHE_BYTES) |
1766 | 1949 | ||
1767 | static u8 *buf; | 1950 | static u8 *buf; |
1768 | 1951 | ||
@@ -1811,7 +1994,7 @@ int spi_write_then_read(struct spi_device *spi, | |||
1811 | } | 1994 | } |
1812 | 1995 | ||
1813 | spi_message_init(&message); | 1996 | spi_message_init(&message); |
1814 | memset(x, 0, sizeof x); | 1997 | memset(x, 0, sizeof(x)); |
1815 | if (n_tx) { | 1998 | if (n_tx) { |
1816 | x[0].len = n_tx; | 1999 | x[0].len = n_tx; |
1817 | spi_message_add_tail(&x[0], &message); | 2000 | spi_message_add_tail(&x[0], &message); |
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index ca5bcfe874d0..d7c6e36021e8 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c | |||
@@ -37,7 +37,7 @@ | |||
37 | #include <linux/spi/spi.h> | 37 | #include <linux/spi/spi.h> |
38 | #include <linux/spi/spidev.h> | 38 | #include <linux/spi/spidev.h> |
39 | 39 | ||
40 | #include <asm/uaccess.h> | 40 | #include <linux/uaccess.h> |
41 | 41 | ||
42 | 42 | ||
43 | /* | 43 | /* |
@@ -206,9 +206,9 @@ spidev_write(struct file *filp, const char __user *buf, | |||
206 | 206 | ||
207 | mutex_lock(&spidev->buf_lock); | 207 | mutex_lock(&spidev->buf_lock); |
208 | missing = copy_from_user(spidev->buffer, buf, count); | 208 | missing = copy_from_user(spidev->buffer, buf, count); |
209 | if (missing == 0) { | 209 | if (missing == 0) |
210 | status = spidev_sync_write(spidev, count); | 210 | status = spidev_sync_write(spidev, count); |
211 | } else | 211 | else |
212 | status = -EFAULT; | 212 | status = -EFAULT; |
213 | mutex_unlock(&spidev->buf_lock); | 213 | mutex_unlock(&spidev->buf_lock); |
214 | 214 | ||
@@ -629,7 +629,6 @@ static int spidev_remove(struct spi_device *spi) | |||
629 | /* make sure ops on existing fds can abort cleanly */ | 629 | /* make sure ops on existing fds can abort cleanly */ |
630 | spin_lock_irq(&spidev->spi_lock); | 630 | spin_lock_irq(&spidev->spi_lock); |
631 | spidev->spi = NULL; | 631 | spidev->spi = NULL; |
632 | spi_set_drvdata(spi, NULL); | ||
633 | spin_unlock_irq(&spidev->spi_lock); | 632 | spin_unlock_irq(&spidev->spi_lock); |
634 | 633 | ||
635 | /* prevent new opens */ | 634 | /* prevent new opens */ |