diff options
author | Quentin Schulz <quentin.schulz@free-electrons.com> | 2017-04-12 03:05:19 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2017-04-12 05:47:52 -0400 |
commit | 05514c86965f98f9b0e57f73700771fa267050a7 (patch) | |
tree | 7ea3c5048921947f0ac983d9dab88412e9fd4dbc | |
parent | fafd67940774733fa97f4b09412aea6981b82e0a (diff) |
spi: atmel: factorize reusable code for SPI controller init
The SPI controller configuration during the init can be reused, for the
resume function for example.
Let's move this configuration to a separate function.
Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/spi/spi-atmel.c | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index 0e7712bac3b6..247d920a512f 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c | |||
@@ -1464,6 +1464,25 @@ static int atmel_spi_gpio_cs(struct platform_device *pdev) | |||
1464 | return 0; | 1464 | return 0; |
1465 | } | 1465 | } |
1466 | 1466 | ||
1467 | static void atmel_spi_init(struct atmel_spi *as) | ||
1468 | { | ||
1469 | spi_writel(as, CR, SPI_BIT(SWRST)); | ||
1470 | spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */ | ||
1471 | if (as->caps.has_wdrbt) { | ||
1472 | spi_writel(as, MR, SPI_BIT(WDRBT) | SPI_BIT(MODFDIS) | ||
1473 | | SPI_BIT(MSTR)); | ||
1474 | } else { | ||
1475 | spi_writel(as, MR, SPI_BIT(MSTR) | SPI_BIT(MODFDIS)); | ||
1476 | } | ||
1477 | |||
1478 | if (as->use_pdc) | ||
1479 | spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS)); | ||
1480 | spi_writel(as, CR, SPI_BIT(SPIEN)); | ||
1481 | |||
1482 | if (as->fifo_size) | ||
1483 | spi_writel(as, CR, SPI_BIT(FIFOEN)); | ||
1484 | } | ||
1485 | |||
1467 | static int atmel_spi_probe(struct platform_device *pdev) | 1486 | static int atmel_spi_probe(struct platform_device *pdev) |
1468 | { | 1487 | { |
1469 | struct resource *regs; | 1488 | struct resource *regs; |
@@ -1572,26 +1591,14 @@ static int atmel_spi_probe(struct platform_device *pdev) | |||
1572 | 1591 | ||
1573 | as->spi_clk = clk_get_rate(clk); | 1592 | as->spi_clk = clk_get_rate(clk); |
1574 | 1593 | ||
1575 | spi_writel(as, CR, SPI_BIT(SWRST)); | ||
1576 | spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */ | ||
1577 | if (as->caps.has_wdrbt) { | ||
1578 | spi_writel(as, MR, SPI_BIT(WDRBT) | SPI_BIT(MODFDIS) | ||
1579 | | SPI_BIT(MSTR)); | ||
1580 | } else { | ||
1581 | spi_writel(as, MR, SPI_BIT(MSTR) | SPI_BIT(MODFDIS)); | ||
1582 | } | ||
1583 | |||
1584 | if (as->use_pdc) | ||
1585 | spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS)); | ||
1586 | spi_writel(as, CR, SPI_BIT(SPIEN)); | ||
1587 | |||
1588 | as->fifo_size = 0; | 1594 | as->fifo_size = 0; |
1589 | if (!of_property_read_u32(pdev->dev.of_node, "atmel,fifo-size", | 1595 | if (!of_property_read_u32(pdev->dev.of_node, "atmel,fifo-size", |
1590 | &as->fifo_size)) { | 1596 | &as->fifo_size)) { |
1591 | dev_info(&pdev->dev, "Using FIFO (%u data)\n", as->fifo_size); | 1597 | dev_info(&pdev->dev, "Using FIFO (%u data)\n", as->fifo_size); |
1592 | spi_writel(as, CR, SPI_BIT(FIFOEN)); | ||
1593 | } | 1598 | } |
1594 | 1599 | ||
1600 | atmel_spi_init(as); | ||
1601 | |||
1595 | pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT); | 1602 | pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT); |
1596 | pm_runtime_use_autosuspend(&pdev->dev); | 1603 | pm_runtime_use_autosuspend(&pdev->dev); |
1597 | pm_runtime_set_active(&pdev->dev); | 1604 | pm_runtime_set_active(&pdev->dev); |