1 From 8e948c035dd7983eccc3a889f2497e64044f3a31 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Wed, 11 Jan 2012 20:06:35 +0100
4 Subject: [PATCH 1/7] spi/ath79: add delay between SCK changes
6 The driver uses the "as fast as it can" approach
7 to drive the SCK signal. However this does not
8 work with certain low speed SPI chips (e.g. the
9 PCF2123 RTC chip). Add per-bit slowdowns in order
10 to be able to use the driver with such chips as
13 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
15 drivers/spi/spi-ath79.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
16 1 files changed, 43 insertions(+), 1 deletions(-)
18 --- a/drivers/spi/spi-ath79.c
19 +++ b/drivers/spi/spi-ath79.c
21 #include <linux/spi/spi_bitbang.h>
22 #include <linux/bitops.h>
23 #include <linux/gpio.h>
24 +#include <linux/clk.h>
25 +#include <linux/err.h>
27 #include <asm/mach-ath79/ar71xx_regs.h>
28 #include <asm/mach-ath79/ath79_spi_platform.h>
30 #define DRV_NAME "ath79-spi"
32 +#define ATH79_SPI_RRW_DELAY_FACTOR 12000
33 +#define MHZ (1000 * 1000)
36 struct spi_bitbang bitbang;
44 static inline u32 ath79_spi_rr(struct ath79_spi *sp, unsigned reg)
45 @@ -52,6 +59,12 @@ static inline struct ath79_spi *ath79_sp
46 return spi_master_get_devdata(spi->master);
49 +static inline void ath79_spi_delay(struct ath79_spi *sp, unsigned nsecs)
51 + if (nsecs > sp->rrw_delay)
52 + ndelay(nsecs - sp->rrw_delay);
55 static void ath79_spi_chipselect(struct spi_device *spi, int is_active)
57 struct ath79_spi *sp = ath79_spidev_to_sp(spi);
58 @@ -184,7 +197,9 @@ static u32 ath79_spi_txrx_mode0(struct s
60 /* setup MSB (to slave) on trailing edge */
61 ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out);
62 + ath79_spi_delay(sp, nsecs);
63 ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out | AR71XX_SPI_IOC_CLK);
64 + ath79_spi_delay(sp, nsecs);
68 @@ -198,6 +213,7 @@ static __devinit int ath79_spi_probe(str
70 struct ath79_spi_platform_data *pdata;
75 master = spi_alloc_master(&pdev->dev, sizeof(*sp));
76 @@ -239,12 +255,36 @@ static __devinit int ath79_spi_probe(str
80 + sp->clk = clk_get(&pdev->dev, "ahb");
81 + if (IS_ERR(sp->clk)) {
82 + ret = PTR_ERR(sp->clk);
86 + ret = clk_enable(sp->clk);
90 + rate = DIV_ROUND_UP(clk_get_rate(sp->clk), MHZ);
93 + goto err_clk_disable;
96 + sp->rrw_delay = ATH79_SPI_RRW_DELAY_FACTOR / rate;
97 + dev_dbg(&pdev->dev, "register read/write delay is %u nsecs\n",
100 ret = spi_bitbang_start(&sp->bitbang);
103 + goto err_clk_disable;
108 + clk_disable(sp->clk);
114 @@ -259,6 +299,8 @@ static __devexit int ath79_spi_remove(st
115 struct ath79_spi *sp = platform_get_drvdata(pdev);
117 spi_bitbang_stop(&sp->bitbang);
118 + clk_disable(sp->clk);
121 platform_set_drvdata(pdev, NULL);
122 spi_master_put(sp->bitbang.master);