1 From 4518ae06e5fc953abfd9c2b66c6155fc2b2696ce Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Mon, 9 Jan 2012 15:00:46 +0100
4 Subject: [PATCH 5/7] spi/ath79: introduce ath79_spi_{en,dis}able helpers
7 drivers/spi/spi-ath79.c | 41 +++++++++++++++++++++++++----------------
8 1 files changed, 25 insertions(+), 16 deletions(-)
10 --- a/drivers/spi/spi-ath79.c
11 +++ b/drivers/spi/spi-ath79.c
12 @@ -89,16 +89,8 @@ static void ath79_spi_chipselect(struct
16 -static int ath79_spi_setup_cs(struct spi_device *spi)
17 +static void ath79_spi_enable(struct ath79_spi *sp)
19 - struct ath79_spi *sp = ath79_spidev_to_sp(spi);
20 - struct ath79_spi_controller_data *cdata;
23 - cdata = spi->controller_data;
24 - if (spi->chip_select && !cdata)
27 /* enable GPIO mode */
28 ath79_spi_wr(sp, AR71XX_SPI_REG_FS, AR71XX_SPI_FS_GPIO);
30 @@ -108,6 +100,25 @@ static int ath79_spi_setup_cs(struct spi
32 /* TODO: setup speed? */
33 ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, 0x43);
36 +static void ath79_spi_disable(struct ath79_spi *sp)
38 + /* restore CTRL register */
39 + ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, sp->reg_ctrl);
40 + /* disable GPIO mode */
41 + ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0);
44 +static int ath79_spi_setup_cs(struct spi_device *spi)
46 + struct ath79_spi *sp = ath79_spidev_to_sp(spi);
47 + struct ath79_spi_controller_data *cdata;
50 + cdata = spi->controller_data;
51 + if (spi->chip_select && !cdata)
55 if (spi->chip_select) {
56 @@ -134,11 +145,6 @@ static void ath79_spi_cleanup_cs(struct
57 struct ath79_spi_controller_data *cdata = spi->controller_data;
58 gpio_free(cdata->gpio);
61 - /* restore CTRL register */
62 - ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, sp->reg_ctrl);
63 - /* disable GPIO mode */
64 - ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0);
67 static int ath79_spi_setup(struct spi_device *spi)
68 @@ -242,13 +248,15 @@ static __devinit int ath79_spi_probe(str
72 + ath79_spi_enable(sp);
73 ret = spi_bitbang_start(&sp->bitbang);
82 + ath79_spi_disable(sp);
85 platform_set_drvdata(pdev, NULL);
86 @@ -262,6 +270,7 @@ static __devexit int ath79_spi_remove(st
87 struct ath79_spi *sp = platform_get_drvdata(pdev);
89 spi_bitbang_stop(&sp->bitbang);
90 + ath79_spi_disable(sp);
92 platform_set_drvdata(pdev, NULL);
93 spi_master_put(sp->bitbang.master);