diff options
author | Geert Uytterhoeven <geert+renesas@linux-m68k.org> | 2014-02-25 05:21:11 -0500 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-02-27 05:44:03 -0500 |
commit | c833ff7304511805ce5a3378d1637e39e00e00ea (patch) | |
tree | 48ac9aea926637f1e01f1c4191ce3c3d24d64aec | |
parent | beb74bb0875579c409778d853b8a050c124b3c79 (diff) |
spi: sh-msiof: Move clock management to (un)prepare_message()
Move clock management and pin configuration from the bitbang chipselect()
method to the SPI core prepare_message() and unprepare_message() methods.
As spi_master.{,un}prepare_message() is guaranteed to be called in
matching pairs, the clock management synchronization is no longer needed.
As sh_msiof_spi_set_pin_regs() is no longer called at spi_master.setup()
time (through spi_bitbang_setup() and the spi_bitbang.chipselect()
callback), we now have to take care of that ourselves.
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>
-rw-r--r-- | drivers/spi/spi-sh-msiof.c | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c index e7f4797fa59d..efeda03bbace 100644 --- a/drivers/spi/spi-sh-msiof.c +++ b/drivers/spi/spi-sh-msiof.c | |||
@@ -46,7 +46,6 @@ struct sh_msiof_spi_priv { | |||
46 | const struct sh_msiof_chipdata *chipdata; | 46 | const struct sh_msiof_chipdata *chipdata; |
47 | struct sh_msiof_spi_info *info; | 47 | struct sh_msiof_spi_info *info; |
48 | struct completion done; | 48 | struct completion done; |
49 | unsigned long flags; | ||
50 | int tx_fifo_size; | 49 | int tx_fifo_size; |
51 | int rx_fifo_size; | 50 | int rx_fifo_size; |
52 | }; | 51 | }; |
@@ -459,6 +458,7 @@ static int sh_msiof_spi_setup_transfer(struct spi_device *spi, | |||
459 | static int sh_msiof_spi_setup(struct spi_device *spi) | 458 | static int sh_msiof_spi_setup(struct spi_device *spi) |
460 | { | 459 | { |
461 | struct device_node *np = spi->master->dev.of_node; | 460 | struct device_node *np = spi->master->dev.of_node; |
461 | struct sh_msiof_spi_priv *p = spi_master_get_devdata(spi->master); | ||
462 | 462 | ||
463 | if (!np) { | 463 | if (!np) { |
464 | /* | 464 | /* |
@@ -468,12 +468,46 @@ static int sh_msiof_spi_setup(struct spi_device *spi) | |||
468 | spi->cs_gpio = (uintptr_t)spi->controller_data; | 468 | spi->cs_gpio = (uintptr_t)spi->controller_data; |
469 | } | 469 | } |
470 | 470 | ||
471 | /* Configure pins before deasserting CS */ | ||
472 | sh_msiof_spi_set_pin_regs(p, !!(spi->mode & SPI_CPOL), | ||
473 | !!(spi->mode & SPI_CPHA), | ||
474 | !!(spi->mode & SPI_3WIRE), | ||
475 | !!(spi->mode & SPI_LSB_FIRST), | ||
476 | !!(spi->mode & SPI_CS_HIGH)); | ||
477 | |||
471 | return spi_bitbang_setup(spi); | 478 | return spi_bitbang_setup(spi); |
472 | } | 479 | } |
473 | 480 | ||
481 | static int sh_msiof_prepare_message(struct spi_master *master, | ||
482 | struct spi_message *msg) | ||
483 | { | ||
484 | struct sh_msiof_spi_priv *p = spi_master_get_devdata(master); | ||
485 | const struct spi_device *spi = msg->spi; | ||
486 | |||
487 | pm_runtime_get_sync(&p->pdev->dev); | ||
488 | clk_enable(p->clk); | ||
489 | |||
490 | /* Configure pins before asserting CS */ | ||
491 | sh_msiof_spi_set_pin_regs(p, !!(spi->mode & SPI_CPOL), | ||
492 | !!(spi->mode & SPI_CPHA), | ||
493 | !!(spi->mode & SPI_3WIRE), | ||
494 | !!(spi->mode & SPI_LSB_FIRST), | ||
495 | !!(spi->mode & SPI_CS_HIGH)); | ||
496 | return 0; | ||
497 | } | ||
498 | |||
499 | static int sh_msiof_unprepare_message(struct spi_master *master, | ||
500 | struct spi_message *msg) | ||
501 | { | ||
502 | struct sh_msiof_spi_priv *p = spi_master_get_devdata(master); | ||
503 | |||
504 | clk_disable(p->clk); | ||
505 | pm_runtime_put(&p->pdev->dev); | ||
506 | return 0; | ||
507 | } | ||
508 | |||
474 | static void sh_msiof_spi_chipselect(struct spi_device *spi, int is_on) | 509 | static void sh_msiof_spi_chipselect(struct spi_device *spi, int is_on) |
475 | { | 510 | { |
476 | struct sh_msiof_spi_priv *p = spi_master_get_devdata(spi->master); | ||
477 | int value; | 511 | int value; |
478 | 512 | ||
479 | /* chip select is active low unless SPI_CS_HIGH is set */ | 513 | /* chip select is active low unless SPI_CS_HIGH is set */ |
@@ -482,29 +516,8 @@ static void sh_msiof_spi_chipselect(struct spi_device *spi, int is_on) | |||
482 | else | 516 | else |
483 | value = (is_on == BITBANG_CS_ACTIVE) ? 0 : 1; | 517 | value = (is_on == BITBANG_CS_ACTIVE) ? 0 : 1; |
484 | 518 | ||
485 | if (is_on == BITBANG_CS_ACTIVE) { | ||
486 | if (!test_and_set_bit(0, &p->flags)) { | ||
487 | pm_runtime_get_sync(&p->pdev->dev); | ||
488 | clk_enable(p->clk); | ||
489 | } | ||
490 | |||
491 | /* Configure pins before asserting CS */ | ||
492 | sh_msiof_spi_set_pin_regs(p, !!(spi->mode & SPI_CPOL), | ||
493 | !!(spi->mode & SPI_CPHA), | ||
494 | !!(spi->mode & SPI_3WIRE), | ||
495 | !!(spi->mode & SPI_LSB_FIRST), | ||
496 | !!(spi->mode & SPI_CS_HIGH)); | ||
497 | } | ||
498 | |||
499 | if (spi->cs_gpio >= 0) | 519 | if (spi->cs_gpio >= 0) |
500 | gpio_set_value(spi->cs_gpio, value); | 520 | gpio_set_value(spi->cs_gpio, value); |
501 | |||
502 | if (is_on == BITBANG_CS_INACTIVE) { | ||
503 | if (test_and_clear_bit(0, &p->flags)) { | ||
504 | clk_disable(p->clk); | ||
505 | pm_runtime_put(&p->pdev->dev); | ||
506 | } | ||
507 | } | ||
508 | } | 521 | } |
509 | 522 | ||
510 | static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, | 523 | static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, |
@@ -811,6 +824,8 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) | |||
811 | master->num_chipselect = p->info->num_chipselect; | 824 | master->num_chipselect = p->info->num_chipselect; |
812 | master->setup = sh_msiof_spi_setup; | 825 | master->setup = sh_msiof_spi_setup; |
813 | master->cleanup = spi_bitbang_cleanup; | 826 | master->cleanup = spi_bitbang_cleanup; |
827 | master->prepare_message = sh_msiof_prepare_message; | ||
828 | master->unprepare_message = sh_msiof_unprepare_message; | ||
814 | 829 | ||
815 | p->bitbang.master = master; | 830 | p->bitbang.master = master; |
816 | p->bitbang.chipselect = sh_msiof_spi_chipselect; | 831 | p->bitbang.chipselect = sh_msiof_spi_chipselect; |