1 --- a/drivers/spi/spi-ath79.c
2 +++ b/drivers/spi/spi-ath79.c
5 #define ATH79_SPI_CS_LINE_MAX 2
7 +enum ath79_spi_state {
8 + ATH79_SPI_STATE_WAIT_CMD = 0,
9 + ATH79_SPI_STATE_WAIT_READ,
13 struct spi_bitbang bitbang;
15 @@ -44,6 +49,11 @@ struct ath79_spi {
20 + enum ath79_spi_state state;
22 + unsigned long read_addr;
23 + unsigned long ahb_rate;
26 static inline u32 ath79_spi_rr(struct ath79_spi *sp, unsigned reg)
27 @@ -108,9 +118,6 @@ static void ath79_spi_enable(struct ath7
28 /* save CTRL register */
29 sp->reg_ctrl = ath79_spi_rr(sp, AR71XX_SPI_REG_CTRL);
30 sp->ioc_base = ath79_spi_rr(sp, AR71XX_SPI_REG_IOC);
32 - /* TODO: setup speed? */
33 - ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, 0x43);
36 static void ath79_spi_disable(struct ath79_spi *sp)
37 @@ -222,6 +229,110 @@ static u32 ath79_spi_txrx_mode0(struct s
38 return ath79_spi_rr(sp, AR71XX_SPI_REG_RDS);
41 +static int ath79_spi_do_read_flash_data(struct spi_device *spi,
42 + struct spi_transfer *t)
44 + struct ath79_spi *sp = ath79_spidev_to_sp(spi);
46 + /* disable GPIO mode */
47 + ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0);
49 + memcpy_fromio(t->rx_buf, sp->base + sp->read_addr, t->len);
51 + /* enable GPIO mode */
52 + ath79_spi_wr(sp, AR71XX_SPI_REG_FS, AR71XX_SPI_FS_GPIO);
54 + /* restore IOC register */
55 + ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
60 +static int ath79_spi_do_read_flash_cmd(struct spi_device *spi,
61 + struct spi_transfer *t)
63 + struct ath79_spi *sp = ath79_spidev_to_sp(spi);
74 + sp->read_addr <<= 8;
75 + sp->read_addr |= *p;
81 +static bool ath79_spi_is_read_cmd(struct spi_device *spi,
82 + struct spi_transfer *t)
84 + return t->type == SPI_TRANSFER_FLASH_READ_CMD;
87 +static bool ath79_spi_is_data_read(struct spi_device *spi,
88 + struct spi_transfer *t)
90 + return t->type == SPI_TRANSFER_FLASH_READ_DATA;
93 +static int ath79_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
95 + struct ath79_spi *sp = ath79_spidev_to_sp(spi);
98 + switch (sp->state) {
99 + case ATH79_SPI_STATE_WAIT_CMD:
100 + if (ath79_spi_is_read_cmd(spi, t)) {
101 + ret = ath79_spi_do_read_flash_cmd(spi, t);
102 + sp->state = ATH79_SPI_STATE_WAIT_READ;
104 + ret = spi_bitbang_bufs(spi, t);
108 + case ATH79_SPI_STATE_WAIT_READ:
109 + if (ath79_spi_is_data_read(spi, t)) {
110 + ret = ath79_spi_do_read_flash_data(spi, t);
112 + dev_warn(&spi->dev, "flash data read expected\n");
115 + sp->state = ATH79_SPI_STATE_WAIT_CMD;
125 +static int ath79_spi_setup_transfer(struct spi_device *spi,
126 + struct spi_transfer *t)
128 + struct ath79_spi *sp = ath79_spidev_to_sp(spi);
129 + struct ath79_spi_controller_data *cdata;
132 + ret = spi_bitbang_setup_transfer(spi, t);
136 + cdata = spi->controller_data;
137 + if (cdata->is_flash)
138 + sp->bitbang.txrx_bufs = ath79_spi_txrx_bufs;
140 + sp->bitbang.txrx_bufs = spi_bitbang_bufs;
145 static __devinit int ath79_spi_probe(struct platform_device *pdev)
147 struct spi_master *master;
148 @@ -244,6 +355,8 @@ static __devinit int ath79_spi_probe(str
149 sp = spi_master_get_devdata(master);
150 platform_set_drvdata(pdev, sp);
152 + sp->state = ATH79_SPI_STATE_WAIT_CMD;
154 master->setup = ath79_spi_setup;
155 master->cleanup = ath79_spi_cleanup;
156 master->bus_num = pdata->bus_num;
157 @@ -252,7 +365,7 @@ static __devinit int ath79_spi_probe(str
158 sp->bitbang.master = spi_master_get(master);
159 sp->bitbang.chipselect = ath79_spi_chipselect;
160 sp->bitbang.txrx_word[SPI_MODE_0] = ath79_spi_txrx_mode0;
161 - sp->bitbang.setup_transfer = spi_bitbang_setup_transfer;
162 + sp->bitbang.setup_transfer = ath79_spi_setup_transfer;
163 sp->bitbang.flags = SPI_CS_HIGH;
165 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
166 @@ -277,7 +390,8 @@ static __devinit int ath79_spi_probe(str
170 - rate = DIV_ROUND_UP(clk_get_rate(sp->clk), MHZ);
171 + sp->ahb_rate = clk_get_rate(sp->clk);
172 + rate = DIV_ROUND_UP(sp->ahb_rate, MHZ);
175 goto err_clk_disable;
176 --- a/arch/mips/include/asm/mach-ath79/ath79_spi_platform.h
177 +++ b/arch/mips/include/asm/mach-ath79/ath79_spi_platform.h
178 @@ -24,6 +24,7 @@ enum ath79_spi_cs_type {
179 struct ath79_spi_controller_data {
180 enum ath79_spi_cs_type cs_type;
185 #endif /* _ATH79_SPI_PLATFORM_H */