hostapd: remove old button hotplug script
[openwrt.git] / target / linux / ar71xx / patches-3.8 / 001-spi-ath79-add-delay-between-SCK-changes.patch
1 From 486c150478777ef53cfef6f0d46840b9406b0612 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Thu, 27 Dec 2012 10:42:24 +0100
4 Subject: [PATCH] spi/ath79: add delay between SCK changes
5
6 commit 440114fdb13cbc53ea734bcc05b86bcf5b1e430c upstream.
7
8 The driver uses the "as fast as it can" approach
9 to drive the SCK signal. However this does not
10 work with certain low speed SPI chips (e.g. the
11 PCF2123 RTC chip).
12
13 The patch adds per-bit slowdowns in order to be
14 able to use the driver with such chips as well.
15
16 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
17 Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
18 ---
19  drivers/spi/spi-ath79.c |   44 +++++++++++++++++++++++++++++++++++++++++++-
20  1 file changed, 43 insertions(+), 1 deletion(-)
21
22 --- a/drivers/spi/spi-ath79.c
23 +++ b/drivers/spi/spi-ath79.c
24 @@ -24,17 +24,24 @@
25  #include <linux/spi/spi_bitbang.h>
26  #include <linux/bitops.h>
27  #include <linux/gpio.h>
28 +#include <linux/clk.h>
29 +#include <linux/err.h>
30  
31  #include <asm/mach-ath79/ar71xx_regs.h>
32  #include <asm/mach-ath79/ath79_spi_platform.h>
33  
34  #define DRV_NAME       "ath79-spi"
35  
36 +#define ATH79_SPI_RRW_DELAY_FACTOR     12000
37 +#define MHZ                            (1000 * 1000)
38 +
39  struct ath79_spi {
40         struct spi_bitbang      bitbang;
41         u32                     ioc_base;
42         u32                     reg_ctrl;
43         void __iomem            *base;
44 +       struct clk              *clk;
45 +       unsigned                rrw_delay;
46  };
47  
48  static inline u32 ath79_spi_rr(struct ath79_spi *sp, unsigned reg)
49 @@ -52,6 +59,12 @@ static inline struct ath79_spi *ath79_sp
50         return spi_master_get_devdata(spi->master);
51  }
52  
53 +static inline void ath79_spi_delay(struct ath79_spi *sp, unsigned nsecs)
54 +{
55 +       if (nsecs > sp->rrw_delay)
56 +               ndelay(nsecs - sp->rrw_delay);
57 +}
58 +
59  static void ath79_spi_chipselect(struct spi_device *spi, int is_active)
60  {
61         struct ath79_spi *sp = ath79_spidev_to_sp(spi);
62 @@ -184,7 +197,9 @@ static u32 ath79_spi_txrx_mode0(struct s
63  
64                 /* setup MSB (to slave) on trailing edge */
65                 ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out);
66 +               ath79_spi_delay(sp, nsecs);
67                 ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out | AR71XX_SPI_IOC_CLK);
68 +               ath79_spi_delay(sp, nsecs);
69  
70                 word <<= 1;
71         }
72 @@ -198,6 +213,7 @@ static int ath79_spi_probe(struct platfo
73         struct ath79_spi *sp;
74         struct ath79_spi_platform_data *pdata;
75         struct resource *r;
76 +       unsigned long rate;
77         int ret;
78  
79         master = spi_alloc_master(&pdev->dev, sizeof(*sp));
80 @@ -236,12 +252,36 @@ static int ath79_spi_probe(struct platfo
81                 goto err_put_master;
82         }
83  
84 +       sp->clk = clk_get(&pdev->dev, "ahb");
85 +       if (IS_ERR(sp->clk)) {
86 +               ret = PTR_ERR(sp->clk);
87 +               goto err_unmap;
88 +       }
89 +
90 +       ret = clk_enable(sp->clk);
91 +       if (ret)
92 +               goto err_clk_put;
93 +
94 +       rate = DIV_ROUND_UP(clk_get_rate(sp->clk), MHZ);
95 +       if (!rate) {
96 +               ret = -EINVAL;
97 +               goto err_clk_disable;
98 +       }
99 +
100 +       sp->rrw_delay = ATH79_SPI_RRW_DELAY_FACTOR / rate;
101 +       dev_dbg(&pdev->dev, "register read/write delay is %u nsecs\n",
102 +               sp->rrw_delay);
103 +
104         ret = spi_bitbang_start(&sp->bitbang);
105         if (ret)
106 -               goto err_unmap;
107 +               goto err_clk_disable;
108  
109         return 0;
110  
111 +err_clk_disable:
112 +       clk_disable(sp->clk);
113 +err_clk_put:
114 +       clk_put(sp->clk);
115  err_unmap:
116         iounmap(sp->base);
117  err_put_master:
118 @@ -256,6 +296,8 @@ static int ath79_spi_remove(struct platf
119         struct ath79_spi *sp = platform_get_drvdata(pdev);
120  
121         spi_bitbang_stop(&sp->bitbang);
122 +       clk_disable(sp->clk);
123 +       clk_put(sp->clk);
124         iounmap(sp->base);
125         platform_set_drvdata(pdev, NULL);
126         spi_master_put(sp->bitbang.master);