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,24 @@ 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_controller_data *cdata;
49 + cdata = spi->controller_data;
50 + if (spi->chip_select && !cdata)
54 if (spi->chip_select) {
55 @@ -128,17 +138,10 @@ static int ath79_spi_setup_cs(struct spi
57 static void ath79_spi_cleanup_cs(struct spi_device *spi)
59 - struct ath79_spi *sp = ath79_spidev_to_sp(spi);
61 if (spi->chip_select) {
62 struct ath79_spi_controller_data *cdata = spi->controller_data;
63 gpio_free(cdata->gpio);
66 - /* restore CTRL register */
67 - ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, sp->reg_ctrl);
68 - /* disable GPIO mode */
69 - ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0);
72 static int ath79_spi_setup(struct spi_device *spi)
73 @@ -242,13 +245,15 @@ static __devinit int ath79_spi_probe(str
77 + ath79_spi_enable(sp);
78 ret = spi_bitbang_start(&sp->bitbang);
87 + ath79_spi_disable(sp);
90 platform_set_drvdata(pdev, NULL);
91 @@ -262,6 +267,7 @@ static __devexit int ath79_spi_remove(st
92 struct ath79_spi *sp = platform_get_drvdata(pdev);
94 spi_bitbang_stop(&sp->bitbang);
95 + ath79_spi_disable(sp);
97 platform_set_drvdata(pdev, NULL);
98 spi_master_put(sp->bitbang.master);