[ar71xx] refresh 3.2 patches
[openwrt.git] / target / linux / ar71xx / patches-3.2 / 205-spi-ath79-introduce-ath79_spi_-en-dis-able-helpers.patch
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
5
6 ---
7  drivers/spi/spi-ath79.c |   41 +++++++++++++++++++++++++----------------
8  1 files changed, 25 insertions(+), 16 deletions(-)
9
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
13  
14  }
15  
16 -static int ath79_spi_setup_cs(struct spi_device *spi)
17 +static void ath79_spi_enable(struct ath79_spi *sp)
18  {
19 -       struct ath79_spi *sp = ath79_spidev_to_sp(spi);
20 -       struct ath79_spi_controller_data *cdata;
21 -       int status;
22 -
23 -       cdata = spi->controller_data;
24 -       if (spi->chip_select && !cdata)
25 -               return -EINVAL;
26 -
27         /* enable GPIO mode */
28         ath79_spi_wr(sp, AR71XX_SPI_REG_FS, AR71XX_SPI_FS_GPIO);
29  
30 @@ -108,6 +100,25 @@ static int ath79_spi_setup_cs(struct spi
31  
32         /* TODO: setup speed? */
33         ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, 0x43);
34 +}
35 +
36 +static void ath79_spi_disable(struct ath79_spi *sp)
37 +{
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);
42 +}
43 +
44 +static int ath79_spi_setup_cs(struct spi_device *spi)
45 +{
46 +       struct ath79_spi *sp = ath79_spidev_to_sp(spi);
47 +       struct ath79_spi_controller_data *cdata;
48 +       int status;
49 +
50 +       cdata = spi->controller_data;
51 +       if (spi->chip_select && !cdata)
52 +               return -EINVAL;
53  
54         status = 0;
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);
59         }
60 -
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);
65  }
66  
67  static int ath79_spi_setup(struct spi_device *spi)
68 @@ -242,13 +248,15 @@ static __devinit int ath79_spi_probe(str
69                 goto err_put_master;
70         }
71  
72 +       ath79_spi_enable(sp);
73         ret = spi_bitbang_start(&sp->bitbang);
74         if (ret)
75 -               goto err_unmap;
76 +               goto err_disable;
77  
78         return 0;
79  
80 -err_unmap:
81 +err_disable:
82 +       ath79_spi_disable(sp);
83         iounmap(sp->base);
84  err_put_master:
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);
88  
89         spi_bitbang_stop(&sp->bitbang);
90 +       ath79_spi_disable(sp);
91         iounmap(sp->base);
92         platform_set_drvdata(pdev, NULL);
93         spi_master_put(sp->bitbang.master);