diff options
author | Geert Uytterhoeven <geert+renesas@linux-m68k.org> | 2014-02-25 05:21:13 -0500 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-02-27 05:44:04 -0500 |
commit | 1bd6363bc0c69ff6120b53daa35cf9459c3628ad (patch) | |
tree | 224b9dbe88eefa5f528a12a25065d7e200326b6d /drivers | |
parent | 2416289c714343ea855e725d59d42668a9ab3cf6 (diff) |
spi: sh-msiof: Use core message handling instead of spi-bitbang
The only remaining feature of spi-bitbang used by this driver is the
chipselect() callback, which just does conditional GPIO.
This is handled fine by the SPI core's spi_set_cs(), hence switch the
driver to use the core message handling through our own transfer_one()
method.
As the (optional) GPIO CS is no longer deasserted at spi_master.setup()
time (through spi_bitbang_setup() and the spi_bitbang.chipselect()
callback), we now have to take care of that ourselves.
Remove the call to spi_master_put() in sh_msiof_spi_remove(), as our SPI
master is now registered using devm_spi_register_master()
(spi_bitbang_start() uses the non-managed version).
Signed-off-by: Geert Uytterhoeven <geert+renesas@linux-m68k.org>
Acked-by: Magnus Damm <damm@opensource.se>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/spi/Kconfig | 1 | ||||
-rw-r--r-- | drivers/spi/spi-sh-msiof.c | 67 |
2 files changed, 20 insertions, 48 deletions
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index ba9310bc9acb..16f2987c29dc 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig | |||
@@ -416,7 +416,6 @@ config SPI_SH_MSIOF | |||
416 | tristate "SuperH MSIOF SPI controller" | 416 | tristate "SuperH MSIOF SPI controller" |
417 | depends on HAVE_CLK | 417 | depends on HAVE_CLK |
418 | depends on SUPERH || ARCH_SHMOBILE || COMPILE_TEST | 418 | depends on SUPERH || ARCH_SHMOBILE || COMPILE_TEST |
419 | select SPI_BITBANG | ||
420 | help | 419 | help |
421 | SPI driver for SuperH and SH Mobile MSIOF blocks. | 420 | SPI driver for SuperH and SH Mobile MSIOF blocks. |
422 | 421 | ||
diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c index a0380b7c977f..db687011dc4f 100644 --- a/drivers/spi/spi-sh-msiof.c +++ b/drivers/spi/spi-sh-msiof.c | |||
@@ -27,7 +27,6 @@ | |||
27 | 27 | ||
28 | #include <linux/spi/sh_msiof.h> | 28 | #include <linux/spi/sh_msiof.h> |
29 | #include <linux/spi/spi.h> | 29 | #include <linux/spi/spi.h> |
30 | #include <linux/spi/spi_bitbang.h> | ||
31 | 30 | ||
32 | #include <asm/unaligned.h> | 31 | #include <asm/unaligned.h> |
33 | 32 | ||
@@ -39,7 +38,6 @@ struct sh_msiof_chipdata { | |||
39 | }; | 38 | }; |
40 | 39 | ||
41 | struct sh_msiof_spi_priv { | 40 | struct sh_msiof_spi_priv { |
42 | struct spi_bitbang bitbang; /* must be first for spi_bitbang.c */ | ||
43 | void __iomem *mapbase; | 41 | void __iomem *mapbase; |
44 | struct clk *clk; | 42 | struct clk *clk; |
45 | struct platform_device *pdev; | 43 | struct platform_device *pdev; |
@@ -459,7 +457,10 @@ static int sh_msiof_spi_setup(struct spi_device *spi) | |||
459 | !!(spi->mode & SPI_LSB_FIRST), | 457 | !!(spi->mode & SPI_LSB_FIRST), |
460 | !!(spi->mode & SPI_CS_HIGH)); | 458 | !!(spi->mode & SPI_CS_HIGH)); |
461 | 459 | ||
462 | return spi_bitbang_setup(spi); | 460 | if (spi->cs_gpio >= 0) |
461 | gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); | ||
462 | |||
463 | return 0; | ||
463 | } | 464 | } |
464 | 465 | ||
465 | static int sh_msiof_prepare_message(struct spi_master *master, | 466 | static int sh_msiof_prepare_message(struct spi_master *master, |
@@ -490,20 +491,6 @@ static int sh_msiof_unprepare_message(struct spi_master *master, | |||
490 | return 0; | 491 | return 0; |
491 | } | 492 | } |
492 | 493 | ||
493 | static void sh_msiof_spi_chipselect(struct spi_device *spi, int is_on) | ||
494 | { | ||
495 | int value; | ||
496 | |||
497 | /* chip select is active low unless SPI_CS_HIGH is set */ | ||
498 | if (spi->mode & SPI_CS_HIGH) | ||
499 | value = (is_on == BITBANG_CS_ACTIVE) ? 1 : 0; | ||
500 | else | ||
501 | value = (is_on == BITBANG_CS_ACTIVE) ? 0 : 1; | ||
502 | |||
503 | if (spi->cs_gpio >= 0) | ||
504 | gpio_set_value(spi->cs_gpio, value); | ||
505 | } | ||
506 | |||
507 | static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, | 494 | static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, |
508 | void (*tx_fifo)(struct sh_msiof_spi_priv *, | 495 | void (*tx_fifo)(struct sh_msiof_spi_priv *, |
509 | const void *, int, int), | 496 | const void *, int, int), |
@@ -573,9 +560,11 @@ static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, | |||
573 | return ret; | 560 | return ret; |
574 | } | 561 | } |
575 | 562 | ||
576 | static int sh_msiof_spi_txrx(struct spi_device *spi, struct spi_transfer *t) | 563 | static int sh_msiof_transfer_one(struct spi_master *master, |
564 | struct spi_device *spi, | ||
565 | struct spi_transfer *t) | ||
577 | { | 566 | { |
578 | struct sh_msiof_spi_priv *p = spi_master_get_devdata(spi->master); | 567 | struct sh_msiof_spi_priv *p = spi_master_get_devdata(master); |
579 | void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, int, int); | 568 | void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, int, int); |
580 | void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, int, int); | 569 | void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, int, int); |
581 | int bits; | 570 | int bits; |
@@ -656,13 +645,6 @@ static int sh_msiof_spi_txrx(struct spi_device *spi, struct spi_transfer *t) | |||
656 | words -= n; | 645 | words -= n; |
657 | } | 646 | } |
658 | 647 | ||
659 | return bytes_done; | ||
660 | } | ||
661 | |||
662 | static u32 sh_msiof_spi_txrx_word(struct spi_device *spi, unsigned nsecs, | ||
663 | u32 word, u8 bits) | ||
664 | { | ||
665 | BUG(); /* unused but needed by bitbang code */ | ||
666 | return 0; | 648 | return 0; |
667 | } | 649 | } |
668 | 650 | ||
@@ -799,7 +781,7 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) | |||
799 | if (p->info->rx_fifo_override) | 781 | if (p->info->rx_fifo_override) |
800 | p->rx_fifo_size = p->info->rx_fifo_override; | 782 | p->rx_fifo_size = p->info->rx_fifo_override; |
801 | 783 | ||
802 | /* init master and bitbang code */ | 784 | /* init master code */ |
803 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; | 785 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; |
804 | master->mode_bits |= SPI_LSB_FIRST | SPI_3WIRE; | 786 | master->mode_bits |= SPI_LSB_FIRST | SPI_3WIRE; |
805 | master->flags = p->chipdata->master_flags; | 787 | master->flags = p->chipdata->master_flags; |
@@ -807,24 +789,20 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) | |||
807 | master->dev.of_node = pdev->dev.of_node; | 789 | master->dev.of_node = pdev->dev.of_node; |
808 | master->num_chipselect = p->info->num_chipselect; | 790 | master->num_chipselect = p->info->num_chipselect; |
809 | master->setup = sh_msiof_spi_setup; | 791 | master->setup = sh_msiof_spi_setup; |
810 | master->cleanup = spi_bitbang_cleanup; | ||
811 | master->prepare_message = sh_msiof_prepare_message; | 792 | master->prepare_message = sh_msiof_prepare_message; |
812 | master->unprepare_message = sh_msiof_unprepare_message; | 793 | master->unprepare_message = sh_msiof_unprepare_message; |
813 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32); | 794 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32); |
795 | master->transfer_one = sh_msiof_transfer_one; | ||
814 | 796 | ||
815 | p->bitbang.master = master; | 797 | ret = devm_spi_register_master(&pdev->dev, master); |
816 | p->bitbang.chipselect = sh_msiof_spi_chipselect; | 798 | if (ret < 0) { |
817 | p->bitbang.setup_transfer = spi_bitbang_setup_transfer; | 799 | dev_err(&pdev->dev, "spi_register_master error.\n"); |
818 | p->bitbang.txrx_bufs = sh_msiof_spi_txrx; | 800 | goto err2; |
819 | p->bitbang.txrx_word[SPI_MODE_0] = sh_msiof_spi_txrx_word; | 801 | } |
820 | p->bitbang.txrx_word[SPI_MODE_1] = sh_msiof_spi_txrx_word; | ||
821 | p->bitbang.txrx_word[SPI_MODE_2] = sh_msiof_spi_txrx_word; | ||
822 | p->bitbang.txrx_word[SPI_MODE_3] = sh_msiof_spi_txrx_word; | ||
823 | 802 | ||
824 | ret = spi_bitbang_start(&p->bitbang); | 803 | return 0; |
825 | if (ret == 0) | ||
826 | return 0; | ||
827 | 804 | ||
805 | err2: | ||
828 | pm_runtime_disable(&pdev->dev); | 806 | pm_runtime_disable(&pdev->dev); |
829 | clk_unprepare(p->clk); | 807 | clk_unprepare(p->clk); |
830 | err1: | 808 | err1: |
@@ -835,15 +813,10 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) | |||
835 | static int sh_msiof_spi_remove(struct platform_device *pdev) | 813 | static int sh_msiof_spi_remove(struct platform_device *pdev) |
836 | { | 814 | { |
837 | struct sh_msiof_spi_priv *p = platform_get_drvdata(pdev); | 815 | struct sh_msiof_spi_priv *p = platform_get_drvdata(pdev); |
838 | int ret; | ||
839 | 816 | ||
840 | ret = spi_bitbang_stop(&p->bitbang); | 817 | pm_runtime_disable(&pdev->dev); |
841 | if (!ret) { | 818 | clk_unprepare(p->clk); |
842 | pm_runtime_disable(&pdev->dev); | 819 | return 0; |
843 | clk_unprepare(p->clk); | ||
844 | spi_master_put(p->bitbang.master); | ||
845 | } | ||
846 | return ret; | ||
847 | } | 820 | } |
848 | 821 | ||
849 | static struct platform_device_id spi_driver_ids[] = { | 822 | static struct platform_device_id spi_driver_ids[] = { |