blob: 6aa084e445e6ed9b9eba449ef5ced969c94eeb61 [file] [log] [blame]
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001/*
Mike Frysinger26fdc1f2008-02-06 01:38:21 -08002 * Blackfin On-Chip SPI Driver
Wu, Bryana5f6abd2007-05-06 14:50:34 -07003 *
Bryan Wu131b17d2007-12-04 23:45:12 -08004 * Copyright 2004-2007 Analog Devices Inc.
Wu, Bryana5f6abd2007-05-06 14:50:34 -07005 *
Mike Frysinger26fdc1f2008-02-06 01:38:21 -08006 * Enter bugs at http://blackfin.uclinux.org/
Wu, Bryana5f6abd2007-05-06 14:50:34 -07007 *
Mike Frysinger26fdc1f2008-02-06 01:38:21 -08008 * Licensed under the GPL-2 or later.
Wu, Bryana5f6abd2007-05-06 14:50:34 -07009 */
10
11#include <linux/init.h>
12#include <linux/module.h>
Bryan Wu131b17d2007-12-04 23:45:12 -080013#include <linux/delay.h>
Wu, Bryana5f6abd2007-05-06 14:50:34 -070014#include <linux/device.h>
Bryan Wu131b17d2007-12-04 23:45:12 -080015#include <linux/io.h>
Wu, Bryana5f6abd2007-05-06 14:50:34 -070016#include <linux/ioport.h>
Bryan Wu131b17d2007-12-04 23:45:12 -080017#include <linux/irq.h>
Wu, Bryana5f6abd2007-05-06 14:50:34 -070018#include <linux/errno.h>
19#include <linux/interrupt.h>
20#include <linux/platform_device.h>
21#include <linux/dma-mapping.h>
22#include <linux/spi/spi.h>
23#include <linux/workqueue.h>
Wu, Bryana5f6abd2007-05-06 14:50:34 -070024
Wu, Bryana5f6abd2007-05-06 14:50:34 -070025#include <asm/dma.h>
Bryan Wu131b17d2007-12-04 23:45:12 -080026#include <asm/portmux.h>
Wu, Bryana5f6abd2007-05-06 14:50:34 -070027#include <asm/bfin5xx_spi.h>
Vitja Makarov8cf58582009-04-06 19:00:31 -070028#include <asm/cacheflush.h>
29
Bryan Wua32c6912007-12-04 23:45:15 -080030#define DRV_NAME "bfin-spi"
31#define DRV_AUTHOR "Bryan Wu, Luke Yang"
Mike Frysinger138f97c2009-04-06 19:00:50 -070032#define DRV_DESC "Blackfin on-chip SPI Controller Driver"
Bryan Wua32c6912007-12-04 23:45:15 -080033#define DRV_VERSION "1.0"
34
35MODULE_AUTHOR(DRV_AUTHOR);
36MODULE_DESCRIPTION(DRV_DESC);
Wu, Bryana5f6abd2007-05-06 14:50:34 -070037MODULE_LICENSE("GPL");
38
Bryan Wubb90eb02007-12-04 23:45:18 -080039#define IS_DMA_ALIGNED(x) (((u32)(x)&0x07) == 0)
Wu, Bryana5f6abd2007-05-06 14:50:34 -070040
Bryan Wubb90eb02007-12-04 23:45:18 -080041#define START_STATE ((void *)0)
42#define RUNNING_STATE ((void *)1)
43#define DONE_STATE ((void *)2)
44#define ERROR_STATE ((void *)-1)
45#define QUEUE_RUNNING 0
46#define QUEUE_STOPPED 1
Wu, Bryana5f6abd2007-05-06 14:50:34 -070047
48struct driver_data {
49 /* Driver model hookup */
50 struct platform_device *pdev;
51
52 /* SPI framework hookup */
53 struct spi_master *master;
54
Bryan Wubb90eb02007-12-04 23:45:18 -080055 /* Regs base of SPI controller */
Bryan Wuf4521262007-12-04 23:45:22 -080056 void __iomem *regs_base;
Bryan Wubb90eb02007-12-04 23:45:18 -080057
Bryan Wu003d9222007-12-04 23:45:22 -080058 /* Pin request list */
59 u16 *pin_req;
60
Wu, Bryana5f6abd2007-05-06 14:50:34 -070061 /* BFIN hookup */
62 struct bfin5xx_spi_master *master_info;
63
64 /* Driver message queue */
65 struct workqueue_struct *workqueue;
66 struct work_struct pump_messages;
67 spinlock_t lock;
68 struct list_head queue;
69 int busy;
70 int run;
71
72 /* Message Transfer pump */
73 struct tasklet_struct pump_transfers;
74
75 /* Current message transfer state info */
76 struct spi_message *cur_msg;
77 struct spi_transfer *cur_transfer;
78 struct chip_data *cur_chip;
79 size_t len_in_bytes;
80 size_t len;
81 void *tx;
82 void *tx_end;
83 void *rx;
84 void *rx_end;
Bryan Wubb90eb02007-12-04 23:45:18 -080085
86 /* DMA stuffs */
87 int dma_channel;
Wu, Bryana5f6abd2007-05-06 14:50:34 -070088 int dma_mapped;
Bryan Wubb90eb02007-12-04 23:45:18 -080089 int dma_requested;
Wu, Bryana5f6abd2007-05-06 14:50:34 -070090 dma_addr_t rx_dma;
91 dma_addr_t tx_dma;
Bryan Wubb90eb02007-12-04 23:45:18 -080092
Wu, Bryana5f6abd2007-05-06 14:50:34 -070093 size_t rx_map_len;
94 size_t tx_map_len;
95 u8 n_bytes;
Bryan Wufad91c82007-12-04 23:45:14 -080096 int cs_change;
Wu, Bryana5f6abd2007-05-06 14:50:34 -070097 void (*write) (struct driver_data *);
98 void (*read) (struct driver_data *);
99 void (*duplex) (struct driver_data *);
100};
101
102struct chip_data {
103 u16 ctl_reg;
104 u16 baud;
105 u16 flag;
106
107 u8 chip_select_num;
108 u8 n_bytes;
Bryan Wu88b40362007-05-21 18:32:16 +0800109 u8 width; /* 0 or 1 */
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700110 u8 enable_dma;
111 u8 bits_per_word; /* 8 or 16 */
112 u8 cs_change_per_word;
Bryan Wu62310e52007-12-04 23:45:20 -0800113 u16 cs_chg_udelay; /* Some devices require > 255usec delay */
Michael Hennerich42c78b22009-04-06 19:00:51 -0700114 u32 cs_gpio;
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700115 void (*write) (struct driver_data *);
116 void (*read) (struct driver_data *);
117 void (*duplex) (struct driver_data *);
118};
119
Bryan Wubb90eb02007-12-04 23:45:18 -0800120#define DEFINE_SPI_REG(reg, off) \
121static inline u16 read_##reg(struct driver_data *drv_data) \
122 { return bfin_read16(drv_data->regs_base + off); } \
123static inline void write_##reg(struct driver_data *drv_data, u16 v) \
124 { bfin_write16(drv_data->regs_base + off, v); }
125
126DEFINE_SPI_REG(CTRL, 0x00)
127DEFINE_SPI_REG(FLAG, 0x04)
128DEFINE_SPI_REG(STAT, 0x08)
129DEFINE_SPI_REG(TDBR, 0x0C)
130DEFINE_SPI_REG(RDBR, 0x10)
131DEFINE_SPI_REG(BAUD, 0x14)
132DEFINE_SPI_REG(SHAW, 0x18)
133
Bryan Wu88b40362007-05-21 18:32:16 +0800134static void bfin_spi_enable(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700135{
136 u16 cr;
137
Bryan Wubb90eb02007-12-04 23:45:18 -0800138 cr = read_CTRL(drv_data);
139 write_CTRL(drv_data, (cr | BIT_CTL_ENABLE));
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700140}
141
Bryan Wu88b40362007-05-21 18:32:16 +0800142static void bfin_spi_disable(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700143{
144 u16 cr;
145
Bryan Wubb90eb02007-12-04 23:45:18 -0800146 cr = read_CTRL(drv_data);
147 write_CTRL(drv_data, (cr & (~BIT_CTL_ENABLE)));
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700148}
149
150/* Caculate the SPI_BAUD register value based on input HZ */
151static u16 hz_to_spi_baud(u32 speed_hz)
152{
153 u_long sclk = get_sclk();
154 u16 spi_baud = (sclk / (2 * speed_hz));
155
156 if ((sclk % (2 * speed_hz)) > 0)
157 spi_baud++;
158
Michael Hennerich7513e002009-04-06 19:00:32 -0700159 if (spi_baud < MIN_SPI_BAUD_VAL)
160 spi_baud = MIN_SPI_BAUD_VAL;
161
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700162 return spi_baud;
163}
164
Mike Frysinger138f97c2009-04-06 19:00:50 -0700165static int bfin_spi_flush(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700166{
167 unsigned long limit = loops_per_jiffy << 1;
168
169 /* wait for stop and clear stat */
Bryan Wubb90eb02007-12-04 23:45:18 -0800170 while (!(read_STAT(drv_data) & BIT_STAT_SPIF) && limit--)
Bryan Wud8c05002007-12-04 23:45:21 -0800171 cpu_relax();
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700172
Bryan Wubb90eb02007-12-04 23:45:18 -0800173 write_STAT(drv_data, BIT_STAT_CLR);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700174
175 return limit;
176}
177
Bryan Wufad91c82007-12-04 23:45:14 -0800178/* Chip select operation functions for cs_change flag */
Mike Frysinger138f97c2009-04-06 19:00:50 -0700179static void bfin_spi_cs_active(struct driver_data *drv_data, struct chip_data *chip)
Bryan Wufad91c82007-12-04 23:45:14 -0800180{
Michael Hennerich42c78b22009-04-06 19:00:51 -0700181 if (likely(chip->chip_select_num)) {
182 u16 flag = read_FLAG(drv_data);
Bryan Wufad91c82007-12-04 23:45:14 -0800183
Michael Hennerich42c78b22009-04-06 19:00:51 -0700184 flag |= chip->flag;
185 flag &= ~(chip->flag << 8);
Bryan Wufad91c82007-12-04 23:45:14 -0800186
Michael Hennerich42c78b22009-04-06 19:00:51 -0700187 write_FLAG(drv_data, flag);
188 } else {
189 gpio_set_value(chip->cs_gpio, 0);
190 }
Bryan Wufad91c82007-12-04 23:45:14 -0800191}
192
Mike Frysinger138f97c2009-04-06 19:00:50 -0700193static void bfin_spi_cs_deactive(struct driver_data *drv_data, struct chip_data *chip)
Bryan Wufad91c82007-12-04 23:45:14 -0800194{
Michael Hennerich42c78b22009-04-06 19:00:51 -0700195 if (likely(chip->chip_select_num)) {
196 u16 flag = read_FLAG(drv_data);
Bryan Wufad91c82007-12-04 23:45:14 -0800197
Michael Hennerich42c78b22009-04-06 19:00:51 -0700198 flag &= ~chip->flag;
199 flag |= (chip->flag << 8);
Bryan Wufad91c82007-12-04 23:45:14 -0800200
Michael Hennerich42c78b22009-04-06 19:00:51 -0700201 write_FLAG(drv_data, flag);
202 } else {
203 gpio_set_value(chip->cs_gpio, 1);
204 }
Bryan Wu62310e52007-12-04 23:45:20 -0800205
206 /* Move delay here for consistency */
207 if (chip->cs_chg_udelay)
208 udelay(chip->cs_chg_udelay);
Bryan Wufad91c82007-12-04 23:45:14 -0800209}
210
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700211/* stop controller and re-config current chip*/
Mike Frysinger138f97c2009-04-06 19:00:50 -0700212static void bfin_spi_restore_state(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700213{
214 struct chip_data *chip = drv_data->cur_chip;
215
216 /* Clear status and disable clock */
Bryan Wubb90eb02007-12-04 23:45:18 -0800217 write_STAT(drv_data, BIT_STAT_CLR);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700218 bfin_spi_disable(drv_data);
Bryan Wu88b40362007-05-21 18:32:16 +0800219 dev_dbg(&drv_data->pdev->dev, "restoring spi ctl state\n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700220
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700221 /* Load the registers */
Bryan Wubb90eb02007-12-04 23:45:18 -0800222 write_CTRL(drv_data, chip->ctl_reg);
Bryan Wu092e1fd2007-12-04 23:45:23 -0800223 write_BAUD(drv_data, chip->baud);
Sonic Zhangcc487e72007-12-04 23:45:17 -0800224
225 bfin_spi_enable(drv_data);
Mike Frysinger138f97c2009-04-06 19:00:50 -0700226 bfin_spi_cs_active(drv_data, chip);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700227}
228
229/* used to kick off transfer in rx mode */
Mike Frysinger138f97c2009-04-06 19:00:50 -0700230static unsigned short bfin_spi_dummy_read(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700231{
232 unsigned short tmp;
Bryan Wubb90eb02007-12-04 23:45:18 -0800233 tmp = read_RDBR(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700234 return tmp;
235}
236
Mike Frysinger138f97c2009-04-06 19:00:50 -0700237static void bfin_spi_null_writer(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700238{
239 u8 n_bytes = drv_data->n_bytes;
240
241 while (drv_data->tx < drv_data->tx_end) {
Bryan Wubb90eb02007-12-04 23:45:18 -0800242 write_TDBR(drv_data, 0);
243 while ((read_STAT(drv_data) & BIT_STAT_TXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800244 cpu_relax();
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700245 drv_data->tx += n_bytes;
246 }
247}
248
Mike Frysinger138f97c2009-04-06 19:00:50 -0700249static void bfin_spi_null_reader(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700250{
251 u8 n_bytes = drv_data->n_bytes;
Mike Frysinger138f97c2009-04-06 19:00:50 -0700252 bfin_spi_dummy_read(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700253
254 while (drv_data->rx < drv_data->rx_end) {
Bryan Wubb90eb02007-12-04 23:45:18 -0800255 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800256 cpu_relax();
Mike Frysinger138f97c2009-04-06 19:00:50 -0700257 bfin_spi_dummy_read(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700258 drv_data->rx += n_bytes;
259 }
260}
261
Mike Frysinger138f97c2009-04-06 19:00:50 -0700262static void bfin_spi_u8_writer(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700263{
Bryan Wu131b17d2007-12-04 23:45:12 -0800264 dev_dbg(&drv_data->pdev->dev,
Bryan Wubb90eb02007-12-04 23:45:18 -0800265 "cr8-s is 0x%x\n", read_STAT(drv_data));
Sonic Zhangcc487e72007-12-04 23:45:17 -0800266
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700267 while (drv_data->tx < drv_data->tx_end) {
Bryan Wubb90eb02007-12-04 23:45:18 -0800268 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
269 while (read_STAT(drv_data) & BIT_STAT_TXS)
Bryan Wud8c05002007-12-04 23:45:21 -0800270 cpu_relax();
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700271 ++drv_data->tx;
272 }
Sonic Zhang13f3e642008-02-06 01:38:20 -0800273
274 /* poll for SPI completion before return */
275 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
276 cpu_relax();
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700277}
278
Mike Frysinger138f97c2009-04-06 19:00:50 -0700279static void bfin_spi_u8_cs_chg_writer(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700280{
281 struct chip_data *chip = drv_data->cur_chip;
282
283 while (drv_data->tx < drv_data->tx_end) {
Mike Frysinger138f97c2009-04-06 19:00:50 -0700284 bfin_spi_cs_active(drv_data, chip);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700285
Bryan Wubb90eb02007-12-04 23:45:18 -0800286 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
287 while (read_STAT(drv_data) & BIT_STAT_TXS)
Bryan Wud8c05002007-12-04 23:45:21 -0800288 cpu_relax();
Bryan Wue26aa012008-02-06 01:38:18 -0800289 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
290 cpu_relax();
Bryan Wu62310e52007-12-04 23:45:20 -0800291
Mike Frysinger138f97c2009-04-06 19:00:50 -0700292 bfin_spi_cs_deactive(drv_data, chip);
Bryan Wu5fec5b52007-12-04 23:45:13 -0800293
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700294 ++drv_data->tx;
295 }
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700296}
297
Mike Frysinger138f97c2009-04-06 19:00:50 -0700298static void bfin_spi_u8_reader(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700299{
Bryan Wu131b17d2007-12-04 23:45:12 -0800300 dev_dbg(&drv_data->pdev->dev,
Bryan Wubb90eb02007-12-04 23:45:18 -0800301 "cr-8 is 0x%x\n", read_STAT(drv_data));
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700302
Sonic Zhang3f479a62007-12-04 23:45:18 -0800303 /* poll for SPI completion before start */
Bryan Wubb90eb02007-12-04 23:45:18 -0800304 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
Bryan Wud8c05002007-12-04 23:45:21 -0800305 cpu_relax();
Sonic Zhang3f479a62007-12-04 23:45:18 -0800306
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700307 /* clear TDBR buffer before read(else it will be shifted out) */
Bryan Wubb90eb02007-12-04 23:45:18 -0800308 write_TDBR(drv_data, 0xFFFF);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700309
Mike Frysinger138f97c2009-04-06 19:00:50 -0700310 bfin_spi_dummy_read(drv_data);
Sonic Zhangcc487e72007-12-04 23:45:17 -0800311
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700312 while (drv_data->rx < drv_data->rx_end - 1) {
Bryan Wubb90eb02007-12-04 23:45:18 -0800313 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800314 cpu_relax();
Bryan Wubb90eb02007-12-04 23:45:18 -0800315 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700316 ++drv_data->rx;
317 }
318
Bryan Wubb90eb02007-12-04 23:45:18 -0800319 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800320 cpu_relax();
Bryan Wubb90eb02007-12-04 23:45:18 -0800321 *(u8 *) (drv_data->rx) = read_SHAW(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700322 ++drv_data->rx;
323}
324
Mike Frysinger138f97c2009-04-06 19:00:50 -0700325static void bfin_spi_u8_cs_chg_reader(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700326{
327 struct chip_data *chip = drv_data->cur_chip;
328
Bryan Wue26aa012008-02-06 01:38:18 -0800329 while (drv_data->rx < drv_data->rx_end) {
Mike Frysinger138f97c2009-04-06 19:00:50 -0700330 bfin_spi_cs_active(drv_data, chip);
Bryan Wue26aa012008-02-06 01:38:18 -0800331 read_RDBR(drv_data); /* kick off */
Bryan Wu5fec5b52007-12-04 23:45:13 -0800332
Bryan Wubb90eb02007-12-04 23:45:18 -0800333 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800334 cpu_relax();
Bryan Wue26aa012008-02-06 01:38:18 -0800335 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
336 cpu_relax();
337
338 *(u8 *) (drv_data->rx) = read_SHAW(drv_data);
Mike Frysinger138f97c2009-04-06 19:00:50 -0700339 bfin_spi_cs_deactive(drv_data, chip);
Bryan Wue26aa012008-02-06 01:38:18 -0800340
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700341 ++drv_data->rx;
342 }
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700343}
344
Mike Frysinger138f97c2009-04-06 19:00:50 -0700345static void bfin_spi_u8_duplex(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700346{
347 /* in duplex mode, clk is triggered by writing of TDBR */
348 while (drv_data->rx < drv_data->rx_end) {
Bryan Wubb90eb02007-12-04 23:45:18 -0800349 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
Bryan Wu4fd432d2008-02-06 01:38:19 -0800350 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
Bryan Wud8c05002007-12-04 23:45:21 -0800351 cpu_relax();
Bryan Wubb90eb02007-12-04 23:45:18 -0800352 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800353 cpu_relax();
Bryan Wubb90eb02007-12-04 23:45:18 -0800354 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700355 ++drv_data->rx;
356 ++drv_data->tx;
357 }
358}
359
Mike Frysinger138f97c2009-04-06 19:00:50 -0700360static void bfin_spi_u8_cs_chg_duplex(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700361{
362 struct chip_data *chip = drv_data->cur_chip;
363
364 while (drv_data->rx < drv_data->rx_end) {
Mike Frysinger138f97c2009-04-06 19:00:50 -0700365 bfin_spi_cs_active(drv_data, chip);
Bryan Wu5fec5b52007-12-04 23:45:13 -0800366
Bryan Wubb90eb02007-12-04 23:45:18 -0800367 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
Bryan Wue26aa012008-02-06 01:38:18 -0800368
369 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
Bryan Wud8c05002007-12-04 23:45:21 -0800370 cpu_relax();
Bryan Wubb90eb02007-12-04 23:45:18 -0800371 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800372 cpu_relax();
Bryan Wubb90eb02007-12-04 23:45:18 -0800373 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
Bryan Wu62310e52007-12-04 23:45:20 -0800374
Mike Frysinger138f97c2009-04-06 19:00:50 -0700375 bfin_spi_cs_deactive(drv_data, chip);
Bryan Wu5fec5b52007-12-04 23:45:13 -0800376
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700377 ++drv_data->rx;
378 ++drv_data->tx;
379 }
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700380}
381
Mike Frysinger138f97c2009-04-06 19:00:50 -0700382static void bfin_spi_u16_writer(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700383{
Bryan Wu131b17d2007-12-04 23:45:12 -0800384 dev_dbg(&drv_data->pdev->dev,
Bryan Wubb90eb02007-12-04 23:45:18 -0800385 "cr16 is 0x%x\n", read_STAT(drv_data));
Bryan Wu88b40362007-05-21 18:32:16 +0800386
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700387 while (drv_data->tx < drv_data->tx_end) {
Bryan Wubb90eb02007-12-04 23:45:18 -0800388 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
389 while ((read_STAT(drv_data) & BIT_STAT_TXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800390 cpu_relax();
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700391 drv_data->tx += 2;
392 }
Sonic Zhang13f3e642008-02-06 01:38:20 -0800393
394 /* poll for SPI completion before return */
395 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
396 cpu_relax();
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700397}
398
Mike Frysinger138f97c2009-04-06 19:00:50 -0700399static void bfin_spi_u16_cs_chg_writer(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700400{
401 struct chip_data *chip = drv_data->cur_chip;
402
403 while (drv_data->tx < drv_data->tx_end) {
Mike Frysinger138f97c2009-04-06 19:00:50 -0700404 bfin_spi_cs_active(drv_data, chip);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700405
Bryan Wubb90eb02007-12-04 23:45:18 -0800406 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
407 while ((read_STAT(drv_data) & BIT_STAT_TXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800408 cpu_relax();
Sonic Zhang13f3e642008-02-06 01:38:20 -0800409 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
410 cpu_relax();
Bryan Wu62310e52007-12-04 23:45:20 -0800411
Mike Frysinger138f97c2009-04-06 19:00:50 -0700412 bfin_spi_cs_deactive(drv_data, chip);
Bryan Wu5fec5b52007-12-04 23:45:13 -0800413
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700414 drv_data->tx += 2;
415 }
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700416}
417
Mike Frysinger138f97c2009-04-06 19:00:50 -0700418static void bfin_spi_u16_reader(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700419{
Bryan Wu88b40362007-05-21 18:32:16 +0800420 dev_dbg(&drv_data->pdev->dev,
Bryan Wubb90eb02007-12-04 23:45:18 -0800421 "cr-16 is 0x%x\n", read_STAT(drv_data));
Sonic Zhangcc487e72007-12-04 23:45:17 -0800422
Sonic Zhang3f479a62007-12-04 23:45:18 -0800423 /* poll for SPI completion before start */
Bryan Wubb90eb02007-12-04 23:45:18 -0800424 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
Bryan Wud8c05002007-12-04 23:45:21 -0800425 cpu_relax();
Sonic Zhang3f479a62007-12-04 23:45:18 -0800426
Sonic Zhangcc487e72007-12-04 23:45:17 -0800427 /* clear TDBR buffer before read(else it will be shifted out) */
Bryan Wubb90eb02007-12-04 23:45:18 -0800428 write_TDBR(drv_data, 0xFFFF);
Sonic Zhangcc487e72007-12-04 23:45:17 -0800429
Mike Frysinger138f97c2009-04-06 19:00:50 -0700430 bfin_spi_dummy_read(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700431
432 while (drv_data->rx < (drv_data->rx_end - 2)) {
Bryan Wubb90eb02007-12-04 23:45:18 -0800433 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800434 cpu_relax();
Bryan Wubb90eb02007-12-04 23:45:18 -0800435 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700436 drv_data->rx += 2;
437 }
438
Bryan Wubb90eb02007-12-04 23:45:18 -0800439 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800440 cpu_relax();
Bryan Wubb90eb02007-12-04 23:45:18 -0800441 *(u16 *) (drv_data->rx) = read_SHAW(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700442 drv_data->rx += 2;
443}
444
Mike Frysinger138f97c2009-04-06 19:00:50 -0700445static void bfin_spi_u16_cs_chg_reader(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700446{
447 struct chip_data *chip = drv_data->cur_chip;
448
Sonic Zhang3f479a62007-12-04 23:45:18 -0800449 /* poll for SPI completion before start */
Bryan Wubb90eb02007-12-04 23:45:18 -0800450 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
Bryan Wud8c05002007-12-04 23:45:21 -0800451 cpu_relax();
Sonic Zhang3f479a62007-12-04 23:45:18 -0800452
Sonic Zhangcc487e72007-12-04 23:45:17 -0800453 /* clear TDBR buffer before read(else it will be shifted out) */
Bryan Wubb90eb02007-12-04 23:45:18 -0800454 write_TDBR(drv_data, 0xFFFF);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700455
Mike Frysinger138f97c2009-04-06 19:00:50 -0700456 bfin_spi_cs_active(drv_data, chip);
457 bfin_spi_dummy_read(drv_data);
Sonic Zhangcc487e72007-12-04 23:45:17 -0800458
Bryan Wuc3061ab2007-12-04 23:45:19 -0800459 while (drv_data->rx < drv_data->rx_end - 2) {
Mike Frysinger138f97c2009-04-06 19:00:50 -0700460 bfin_spi_cs_deactive(drv_data, chip);
Bryan Wu5fec5b52007-12-04 23:45:13 -0800461
Bryan Wubb90eb02007-12-04 23:45:18 -0800462 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800463 cpu_relax();
Mike Frysinger138f97c2009-04-06 19:00:50 -0700464 bfin_spi_cs_active(drv_data, chip);
Bryan Wubb90eb02007-12-04 23:45:18 -0800465 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700466 drv_data->rx += 2;
467 }
Mike Frysinger138f97c2009-04-06 19:00:50 -0700468 bfin_spi_cs_deactive(drv_data, chip);
Sonic Zhangcc487e72007-12-04 23:45:17 -0800469
Bryan Wubb90eb02007-12-04 23:45:18 -0800470 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800471 cpu_relax();
Bryan Wubb90eb02007-12-04 23:45:18 -0800472 *(u16 *) (drv_data->rx) = read_SHAW(drv_data);
Sonic Zhangcc487e72007-12-04 23:45:17 -0800473 drv_data->rx += 2;
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700474}
475
Mike Frysinger138f97c2009-04-06 19:00:50 -0700476static void bfin_spi_u16_duplex(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700477{
478 /* in duplex mode, clk is triggered by writing of TDBR */
479 while (drv_data->tx < drv_data->tx_end) {
Bryan Wubb90eb02007-12-04 23:45:18 -0800480 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
Bryan Wu4fd432d2008-02-06 01:38:19 -0800481 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
Bryan Wud8c05002007-12-04 23:45:21 -0800482 cpu_relax();
Bryan Wubb90eb02007-12-04 23:45:18 -0800483 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800484 cpu_relax();
Bryan Wubb90eb02007-12-04 23:45:18 -0800485 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700486 drv_data->rx += 2;
487 drv_data->tx += 2;
488 }
489}
490
Mike Frysinger138f97c2009-04-06 19:00:50 -0700491static void bfin_spi_u16_cs_chg_duplex(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700492{
493 struct chip_data *chip = drv_data->cur_chip;
494
495 while (drv_data->tx < drv_data->tx_end) {
Mike Frysinger138f97c2009-04-06 19:00:50 -0700496 bfin_spi_cs_active(drv_data, chip);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700497
Bryan Wubb90eb02007-12-04 23:45:18 -0800498 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
Bryan Wu4fd432d2008-02-06 01:38:19 -0800499 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
Bryan Wud8c05002007-12-04 23:45:21 -0800500 cpu_relax();
Bryan Wubb90eb02007-12-04 23:45:18 -0800501 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800502 cpu_relax();
Bryan Wubb90eb02007-12-04 23:45:18 -0800503 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
Bryan Wu62310e52007-12-04 23:45:20 -0800504
Mike Frysinger138f97c2009-04-06 19:00:50 -0700505 bfin_spi_cs_deactive(drv_data, chip);
Bryan Wu5fec5b52007-12-04 23:45:13 -0800506
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700507 drv_data->rx += 2;
508 drv_data->tx += 2;
509 }
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700510}
511
512/* test if ther is more transfer to be done */
Mike Frysinger138f97c2009-04-06 19:00:50 -0700513static void *bfin_spi_next_transfer(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700514{
515 struct spi_message *msg = drv_data->cur_msg;
516 struct spi_transfer *trans = drv_data->cur_transfer;
517
518 /* Move to next transfer */
519 if (trans->transfer_list.next != &msg->transfers) {
520 drv_data->cur_transfer =
521 list_entry(trans->transfer_list.next,
522 struct spi_transfer, transfer_list);
523 return RUNNING_STATE;
524 } else
525 return DONE_STATE;
526}
527
528/*
529 * caller already set message->status;
530 * dma and pio irqs are blocked give finished message back
531 */
Mike Frysinger138f97c2009-04-06 19:00:50 -0700532static void bfin_spi_giveback(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700533{
Bryan Wufad91c82007-12-04 23:45:14 -0800534 struct chip_data *chip = drv_data->cur_chip;
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700535 struct spi_transfer *last_transfer;
536 unsigned long flags;
537 struct spi_message *msg;
538
539 spin_lock_irqsave(&drv_data->lock, flags);
540 msg = drv_data->cur_msg;
541 drv_data->cur_msg = NULL;
542 drv_data->cur_transfer = NULL;
543 drv_data->cur_chip = NULL;
544 queue_work(drv_data->workqueue, &drv_data->pump_messages);
545 spin_unlock_irqrestore(&drv_data->lock, flags);
546
547 last_transfer = list_entry(msg->transfers.prev,
548 struct spi_transfer, transfer_list);
549
550 msg->state = NULL;
551
Bryan Wufad91c82007-12-04 23:45:14 -0800552 if (!drv_data->cs_change)
Mike Frysinger138f97c2009-04-06 19:00:50 -0700553 bfin_spi_cs_deactive(drv_data, chip);
Bryan Wufad91c82007-12-04 23:45:14 -0800554
Yi Lib9b2a762009-04-06 19:00:49 -0700555 /* Not stop spi in autobuffer mode */
556 if (drv_data->tx_dma != 0xFFFF)
557 bfin_spi_disable(drv_data);
558
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700559 if (msg->complete)
560 msg->complete(msg->context);
561}
562
Mike Frysinger138f97c2009-04-06 19:00:50 -0700563static irqreturn_t bfin_spi_dma_irq_handler(int irq, void *dev_id)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700564{
Jeff Garzik15aafa22008-02-06 01:36:20 -0800565 struct driver_data *drv_data = dev_id;
Bryan Wufad91c82007-12-04 23:45:14 -0800566 struct chip_data *chip = drv_data->cur_chip;
Bryan Wubb90eb02007-12-04 23:45:18 -0800567 struct spi_message *msg = drv_data->cur_msg;
Mike Frysingeraaaf9392009-04-06 19:00:42 -0700568 unsigned long timeout;
Mike Frysingerd24bd1d2009-04-06 19:00:38 -0700569 unsigned short dmastat = get_dma_curr_irqstat(drv_data->dma_channel);
Mike Frysinger04b95d22009-04-06 19:00:35 -0700570 u16 spistat = read_STAT(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700571
Mike Frysingerd24bd1d2009-04-06 19:00:38 -0700572 dev_dbg(&drv_data->pdev->dev,
573 "in dma_irq_handler dmastat:0x%x spistat:0x%x\n",
574 dmastat, spistat);
575
Bryan Wubb90eb02007-12-04 23:45:18 -0800576 clear_dma_irqstat(drv_data->dma_channel);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700577
Bryan Wud6fe89b2007-06-11 17:34:17 +0800578 /* Wait for DMA to complete */
Bryan Wubb90eb02007-12-04 23:45:18 -0800579 while (get_dma_curr_irqstat(drv_data->dma_channel) & DMA_RUN)
Bryan Wud8c05002007-12-04 23:45:21 -0800580 cpu_relax();
Bryan Wud6fe89b2007-06-11 17:34:17 +0800581
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700582 /*
Bryan Wud6fe89b2007-06-11 17:34:17 +0800583 * wait for the last transaction shifted out. HRM states:
584 * at this point there may still be data in the SPI DMA FIFO waiting
585 * to be transmitted ... software needs to poll TXS in the SPI_STAT
586 * register until it goes low for 2 successive reads
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700587 */
588 if (drv_data->tx != NULL) {
Bryan Wubb90eb02007-12-04 23:45:18 -0800589 while ((read_STAT(drv_data) & TXS) ||
590 (read_STAT(drv_data) & TXS))
Bryan Wud8c05002007-12-04 23:45:21 -0800591 cpu_relax();
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700592 }
593
Mike Frysingeraaaf9392009-04-06 19:00:42 -0700594 dev_dbg(&drv_data->pdev->dev,
595 "in dma_irq_handler dmastat:0x%x spistat:0x%x\n",
596 dmastat, read_STAT(drv_data));
597
598 timeout = jiffies + HZ;
Bryan Wubb90eb02007-12-04 23:45:18 -0800599 while (!(read_STAT(drv_data) & SPIF))
Mike Frysingeraaaf9392009-04-06 19:00:42 -0700600 if (!time_before(jiffies, timeout)) {
601 dev_warn(&drv_data->pdev->dev, "timeout waiting for SPIF");
602 break;
603 } else
604 cpu_relax();
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700605
Mike Frysinger40a29452009-04-06 19:00:38 -0700606 if ((dmastat & DMA_ERR) && (spistat & RBSY)) {
Mike Frysinger04b95d22009-04-06 19:00:35 -0700607 msg->state = ERROR_STATE;
608 dev_err(&drv_data->pdev->dev, "dma receive: fifo/buffer overflow\n");
609 } else {
610 msg->actual_length += drv_data->len_in_bytes;
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700611
Mike Frysinger04b95d22009-04-06 19:00:35 -0700612 if (drv_data->cs_change)
Mike Frysinger138f97c2009-04-06 19:00:50 -0700613 bfin_spi_cs_deactive(drv_data, chip);
Bryan Wufad91c82007-12-04 23:45:14 -0800614
Mike Frysinger04b95d22009-04-06 19:00:35 -0700615 /* Move to next transfer */
Mike Frysinger138f97c2009-04-06 19:00:50 -0700616 msg->state = bfin_spi_next_transfer(drv_data);
Mike Frysinger04b95d22009-04-06 19:00:35 -0700617 }
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700618
619 /* Schedule transfer tasklet */
620 tasklet_schedule(&drv_data->pump_transfers);
621
622 /* free the irq handler before next transfer */
Bryan Wu88b40362007-05-21 18:32:16 +0800623 dev_dbg(&drv_data->pdev->dev,
624 "disable dma channel irq%d\n",
Bryan Wubb90eb02007-12-04 23:45:18 -0800625 drv_data->dma_channel);
626 dma_disable_irq(drv_data->dma_channel);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700627
628 return IRQ_HANDLED;
629}
630
Mike Frysinger138f97c2009-04-06 19:00:50 -0700631static void bfin_spi_pump_transfers(unsigned long data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700632{
633 struct driver_data *drv_data = (struct driver_data *)data;
634 struct spi_message *message = NULL;
635 struct spi_transfer *transfer = NULL;
636 struct spi_transfer *previous = NULL;
637 struct chip_data *chip = NULL;
Bryan Wu88b40362007-05-21 18:32:16 +0800638 u8 width;
639 u16 cr, dma_width, dma_config;
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700640 u32 tranf_success = 1;
Vitja Makarov8eeb12e2008-05-01 04:35:03 -0700641 u8 full_duplex = 0;
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700642
643 /* Get current state information */
644 message = drv_data->cur_msg;
645 transfer = drv_data->cur_transfer;
646 chip = drv_data->cur_chip;
Bryan Wu092e1fd2007-12-04 23:45:23 -0800647
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700648 /*
649 * if msg is error or done, report it back using complete() callback
650 */
651
652 /* Handle for abort */
653 if (message->state == ERROR_STATE) {
Mike Frysingerd24bd1d2009-04-06 19:00:38 -0700654 dev_dbg(&drv_data->pdev->dev, "transfer: we've hit an error\n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700655 message->status = -EIO;
Mike Frysinger138f97c2009-04-06 19:00:50 -0700656 bfin_spi_giveback(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700657 return;
658 }
659
660 /* Handle end of message */
661 if (message->state == DONE_STATE) {
Mike Frysingerd24bd1d2009-04-06 19:00:38 -0700662 dev_dbg(&drv_data->pdev->dev, "transfer: all done!\n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700663 message->status = 0;
Mike Frysinger138f97c2009-04-06 19:00:50 -0700664 bfin_spi_giveback(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700665 return;
666 }
667
668 /* Delay if requested at end of transfer */
669 if (message->state == RUNNING_STATE) {
Mike Frysingerd24bd1d2009-04-06 19:00:38 -0700670 dev_dbg(&drv_data->pdev->dev, "transfer: still running ...\n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700671 previous = list_entry(transfer->transfer_list.prev,
672 struct spi_transfer, transfer_list);
673 if (previous->delay_usecs)
674 udelay(previous->delay_usecs);
675 }
676
677 /* Setup the transfer state based on the type of transfer */
Mike Frysinger138f97c2009-04-06 19:00:50 -0700678 if (bfin_spi_flush(drv_data) == 0) {
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700679 dev_err(&drv_data->pdev->dev, "pump_transfers: flush failed\n");
680 message->status = -EIO;
Mike Frysinger138f97c2009-04-06 19:00:50 -0700681 bfin_spi_giveback(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700682 return;
683 }
684
685 if (transfer->tx_buf != NULL) {
686 drv_data->tx = (void *)transfer->tx_buf;
687 drv_data->tx_end = drv_data->tx + transfer->len;
Bryan Wu88b40362007-05-21 18:32:16 +0800688 dev_dbg(&drv_data->pdev->dev, "tx_buf is %p, tx_end is %p\n",
689 transfer->tx_buf, drv_data->tx_end);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700690 } else {
691 drv_data->tx = NULL;
692 }
693
694 if (transfer->rx_buf != NULL) {
Vitja Makarov8eeb12e2008-05-01 04:35:03 -0700695 full_duplex = transfer->tx_buf != NULL;
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700696 drv_data->rx = transfer->rx_buf;
697 drv_data->rx_end = drv_data->rx + transfer->len;
Bryan Wu88b40362007-05-21 18:32:16 +0800698 dev_dbg(&drv_data->pdev->dev, "rx_buf is %p, rx_end is %p\n",
699 transfer->rx_buf, drv_data->rx_end);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700700 } else {
701 drv_data->rx = NULL;
702 }
703
704 drv_data->rx_dma = transfer->rx_dma;
705 drv_data->tx_dma = transfer->tx_dma;
706 drv_data->len_in_bytes = transfer->len;
Bryan Wufad91c82007-12-04 23:45:14 -0800707 drv_data->cs_change = transfer->cs_change;
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700708
Bryan Wu092e1fd2007-12-04 23:45:23 -0800709 /* Bits per word setup */
710 switch (transfer->bits_per_word) {
711 case 8:
712 drv_data->n_bytes = 1;
713 width = CFG_SPI_WORDSIZE8;
714 drv_data->read = chip->cs_change_per_word ?
Mike Frysinger138f97c2009-04-06 19:00:50 -0700715 bfin_spi_u8_cs_chg_reader : bfin_spi_u8_reader;
Bryan Wu092e1fd2007-12-04 23:45:23 -0800716 drv_data->write = chip->cs_change_per_word ?
Mike Frysinger138f97c2009-04-06 19:00:50 -0700717 bfin_spi_u8_cs_chg_writer : bfin_spi_u8_writer;
Bryan Wu092e1fd2007-12-04 23:45:23 -0800718 drv_data->duplex = chip->cs_change_per_word ?
Mike Frysinger138f97c2009-04-06 19:00:50 -0700719 bfin_spi_u8_cs_chg_duplex : bfin_spi_u8_duplex;
Bryan Wu092e1fd2007-12-04 23:45:23 -0800720 break;
721
722 case 16:
723 drv_data->n_bytes = 2;
724 width = CFG_SPI_WORDSIZE16;
725 drv_data->read = chip->cs_change_per_word ?
Mike Frysinger138f97c2009-04-06 19:00:50 -0700726 bfin_spi_u16_cs_chg_reader : bfin_spi_u16_reader;
Bryan Wu092e1fd2007-12-04 23:45:23 -0800727 drv_data->write = chip->cs_change_per_word ?
Mike Frysinger138f97c2009-04-06 19:00:50 -0700728 bfin_spi_u16_cs_chg_writer : bfin_spi_u16_writer;
Bryan Wu092e1fd2007-12-04 23:45:23 -0800729 drv_data->duplex = chip->cs_change_per_word ?
Mike Frysinger138f97c2009-04-06 19:00:50 -0700730 bfin_spi_u16_cs_chg_duplex : bfin_spi_u16_duplex;
Bryan Wu092e1fd2007-12-04 23:45:23 -0800731 break;
732
733 default:
734 /* No change, the same as default setting */
735 drv_data->n_bytes = chip->n_bytes;
736 width = chip->width;
Mike Frysinger138f97c2009-04-06 19:00:50 -0700737 drv_data->write = drv_data->tx ? chip->write : bfin_spi_null_writer;
738 drv_data->read = drv_data->rx ? chip->read : bfin_spi_null_reader;
739 drv_data->duplex = chip->duplex ? chip->duplex : bfin_spi_null_writer;
Bryan Wu092e1fd2007-12-04 23:45:23 -0800740 break;
741 }
742 cr = (read_CTRL(drv_data) & (~BIT_CTL_TIMOD));
743 cr |= (width << 8);
744 write_CTRL(drv_data, cr);
745
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700746 if (width == CFG_SPI_WORDSIZE16) {
747 drv_data->len = (transfer->len) >> 1;
748 } else {
749 drv_data->len = transfer->len;
750 }
Mike Frysinger4fb98ef2008-04-08 17:41:57 -0700751 dev_dbg(&drv_data->pdev->dev,
752 "transfer: drv_data->write is %p, chip->write is %p, null_wr is %p\n",
Mike Frysinger138f97c2009-04-06 19:00:50 -0700753 drv_data->write, chip->write, bfin_spi_null_writer);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700754
755 /* speed and width has been set on per message */
756 message->state = RUNNING_STATE;
757 dma_config = 0;
758
Bryan Wu092e1fd2007-12-04 23:45:23 -0800759 /* Speed setup (surely valid because already checked) */
760 if (transfer->speed_hz)
761 write_BAUD(drv_data, hz_to_spi_baud(transfer->speed_hz));
762 else
763 write_BAUD(drv_data, chip->baud);
764
Bryan Wubb90eb02007-12-04 23:45:18 -0800765 write_STAT(drv_data, BIT_STAT_CLR);
766 cr = (read_CTRL(drv_data) & (~BIT_CTL_TIMOD));
Yi Lib9b2a762009-04-06 19:00:49 -0700767 if (drv_data->cs_change)
Mike Frysinger138f97c2009-04-06 19:00:50 -0700768 bfin_spi_cs_active(drv_data, chip);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700769
Bryan Wu88b40362007-05-21 18:32:16 +0800770 dev_dbg(&drv_data->pdev->dev,
771 "now pumping a transfer: width is %d, len is %d\n",
772 width, transfer->len);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700773
774 /*
Vitja Makarov8cf58582009-04-06 19:00:31 -0700775 * Try to map dma buffer and do a dma transfer. If successful use,
776 * different way to r/w according to the enable_dma settings and if
777 * we are not doing a full duplex transfer (since the hardware does
778 * not support full duplex DMA transfers).
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700779 */
Vitja Makarov8eeb12e2008-05-01 04:35:03 -0700780 if (!full_duplex && drv_data->cur_chip->enable_dma
781 && drv_data->len > 6) {
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700782
Mike Frysinger11d6f592009-04-06 19:00:41 -0700783 unsigned long dma_start_addr, flags;
Mike Frysinger7aec3562009-04-06 19:00:36 -0700784
Bryan Wubb90eb02007-12-04 23:45:18 -0800785 disable_dma(drv_data->dma_channel);
786 clear_dma_irqstat(drv_data->dma_channel);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700787
788 /* config dma channel */
Bryan Wu88b40362007-05-21 18:32:16 +0800789 dev_dbg(&drv_data->pdev->dev, "doing dma transfer\n");
Mike Frysinger7aec3562009-04-06 19:00:36 -0700790 set_dma_x_count(drv_data->dma_channel, drv_data->len);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700791 if (width == CFG_SPI_WORDSIZE16) {
Bryan Wubb90eb02007-12-04 23:45:18 -0800792 set_dma_x_modify(drv_data->dma_channel, 2);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700793 dma_width = WDSIZE_16;
794 } else {
Bryan Wubb90eb02007-12-04 23:45:18 -0800795 set_dma_x_modify(drv_data->dma_channel, 1);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700796 dma_width = WDSIZE_8;
797 }
798
Sonic Zhang3f479a62007-12-04 23:45:18 -0800799 /* poll for SPI completion before start */
Bryan Wubb90eb02007-12-04 23:45:18 -0800800 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
Bryan Wud8c05002007-12-04 23:45:21 -0800801 cpu_relax();
Sonic Zhang3f479a62007-12-04 23:45:18 -0800802
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700803 /* dirty hack for autobuffer DMA mode */
804 if (drv_data->tx_dma == 0xFFFF) {
Bryan Wu88b40362007-05-21 18:32:16 +0800805 dev_dbg(&drv_data->pdev->dev,
806 "doing autobuffer DMA out.\n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700807
808 /* no irq in autobuffer mode */
809 dma_config =
810 (DMAFLOW_AUTO | RESTART | dma_width | DI_EN);
Bryan Wubb90eb02007-12-04 23:45:18 -0800811 set_dma_config(drv_data->dma_channel, dma_config);
812 set_dma_start_addr(drv_data->dma_channel,
Bryan Wua32c6912007-12-04 23:45:15 -0800813 (unsigned long)drv_data->tx);
Bryan Wubb90eb02007-12-04 23:45:18 -0800814 enable_dma(drv_data->dma_channel);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700815
Sonic Zhang07612e52007-12-04 23:45:21 -0800816 /* start SPI transfer */
Mike Frysinger11d6f592009-04-06 19:00:41 -0700817 write_CTRL(drv_data, cr | BIT_CTL_TIMOD_DMA_TX);
Sonic Zhang07612e52007-12-04 23:45:21 -0800818
819 /* just return here, there can only be one transfer
820 * in this mode
821 */
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700822 message->status = 0;
Mike Frysinger138f97c2009-04-06 19:00:50 -0700823 bfin_spi_giveback(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700824 return;
825 }
826
827 /* In dma mode, rx or tx must be NULL in one transfer */
Mike Frysinger7aec3562009-04-06 19:00:36 -0700828 dma_config = (RESTART | dma_width | DI_EN);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700829 if (drv_data->rx != NULL) {
830 /* set transfer mode, and enable SPI */
Mike Frysingerd24bd1d2009-04-06 19:00:38 -0700831 dev_dbg(&drv_data->pdev->dev, "doing DMA in to %p (size %zx)\n",
832 drv_data->rx, drv_data->len_in_bytes);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700833
Vitja Makarov8cf58582009-04-06 19:00:31 -0700834 /* invalidate caches, if needed */
835 if (bfin_addr_dcachable((unsigned long) drv_data->rx))
836 invalidate_dcache_range((unsigned long) drv_data->rx,
837 (unsigned long) (drv_data->rx +
Mike Frysingerace32862009-04-06 19:00:34 -0700838 drv_data->len_in_bytes));
Vitja Makarov8cf58582009-04-06 19:00:31 -0700839
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700840 /* clear tx reg soformer data is not shifted out */
Bryan Wubb90eb02007-12-04 23:45:18 -0800841 write_TDBR(drv_data, 0xFFFF);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700842
Mike Frysinger7aec3562009-04-06 19:00:36 -0700843 dma_config |= WNR;
844 dma_start_addr = (unsigned long)drv_data->rx;
Mike Frysingerb31e27a2009-04-06 19:00:39 -0700845 cr |= BIT_CTL_TIMOD_DMA_RX | BIT_CTL_SENDOPT;
Sonic Zhang07612e52007-12-04 23:45:21 -0800846
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700847 } else if (drv_data->tx != NULL) {
Bryan Wu88b40362007-05-21 18:32:16 +0800848 dev_dbg(&drv_data->pdev->dev, "doing DMA out.\n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700849
Vitja Makarov8cf58582009-04-06 19:00:31 -0700850 /* flush caches, if needed */
851 if (bfin_addr_dcachable((unsigned long) drv_data->tx))
852 flush_dcache_range((unsigned long) drv_data->tx,
853 (unsigned long) (drv_data->tx +
Mike Frysingerace32862009-04-06 19:00:34 -0700854 drv_data->len_in_bytes));
Vitja Makarov8cf58582009-04-06 19:00:31 -0700855
Mike Frysinger7aec3562009-04-06 19:00:36 -0700856 dma_start_addr = (unsigned long)drv_data->tx;
Mike Frysingerb31e27a2009-04-06 19:00:39 -0700857 cr |= BIT_CTL_TIMOD_DMA_TX;
Sonic Zhang07612e52007-12-04 23:45:21 -0800858
Mike Frysinger7aec3562009-04-06 19:00:36 -0700859 } else
860 BUG();
861
Mike Frysinger11d6f592009-04-06 19:00:41 -0700862 /* oh man, here there be monsters ... and i dont mean the
863 * fluffy cute ones from pixar, i mean the kind that'll eat
864 * your data, kick your dog, and love it all. do *not* try
865 * and change these lines unless you (1) heavily test DMA
866 * with SPI flashes on a loaded system (e.g. ping floods),
867 * (2) know just how broken the DMA engine interaction with
868 * the SPI peripheral is, and (3) have someone else to blame
869 * when you screw it all up anyways.
870 */
Mike Frysinger7aec3562009-04-06 19:00:36 -0700871 set_dma_start_addr(drv_data->dma_channel, dma_start_addr);
Mike Frysinger11d6f592009-04-06 19:00:41 -0700872 set_dma_config(drv_data->dma_channel, dma_config);
873 local_irq_save(flags);
Mike Frysingera963ea82009-04-06 19:00:43 -0700874 SSYNC();
Mike Frysinger11d6f592009-04-06 19:00:41 -0700875 write_CTRL(drv_data, cr);
Mike Frysingera963ea82009-04-06 19:00:43 -0700876 enable_dma(drv_data->dma_channel);
Mike Frysinger11d6f592009-04-06 19:00:41 -0700877 dma_enable_irq(drv_data->dma_channel);
878 local_irq_restore(flags);
Mike Frysinger7aec3562009-04-06 19:00:36 -0700879
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700880 } else {
881 /* IO mode write then read */
Bryan Wu88b40362007-05-21 18:32:16 +0800882 dev_dbg(&drv_data->pdev->dev, "doing IO transfer\n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700883
Vitja Makarov8eeb12e2008-05-01 04:35:03 -0700884 if (full_duplex) {
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700885 /* full duplex mode */
886 BUG_ON((drv_data->tx_end - drv_data->tx) !=
887 (drv_data->rx_end - drv_data->rx));
Bryan Wu88b40362007-05-21 18:32:16 +0800888 dev_dbg(&drv_data->pdev->dev,
889 "IO duplex: cr is 0x%x\n", cr);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700890
Sonic Zhangcc487e72007-12-04 23:45:17 -0800891 /* set SPI transfer mode */
Bryan Wubb90eb02007-12-04 23:45:18 -0800892 write_CTRL(drv_data, (cr | CFG_SPI_WRITE));
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700893
894 drv_data->duplex(drv_data);
895
896 if (drv_data->tx != drv_data->tx_end)
897 tranf_success = 0;
898 } else if (drv_data->tx != NULL) {
899 /* write only half duplex */
Bryan Wu131b17d2007-12-04 23:45:12 -0800900 dev_dbg(&drv_data->pdev->dev,
Bryan Wu88b40362007-05-21 18:32:16 +0800901 "IO write: cr is 0x%x\n", cr);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700902
Sonic Zhangcc487e72007-12-04 23:45:17 -0800903 /* set SPI transfer mode */
Bryan Wubb90eb02007-12-04 23:45:18 -0800904 write_CTRL(drv_data, (cr | CFG_SPI_WRITE));
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700905
906 drv_data->write(drv_data);
907
908 if (drv_data->tx != drv_data->tx_end)
909 tranf_success = 0;
910 } else if (drv_data->rx != NULL) {
911 /* read only half duplex */
Bryan Wu131b17d2007-12-04 23:45:12 -0800912 dev_dbg(&drv_data->pdev->dev,
Bryan Wu88b40362007-05-21 18:32:16 +0800913 "IO read: cr is 0x%x\n", cr);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700914
Sonic Zhangcc487e72007-12-04 23:45:17 -0800915 /* set SPI transfer mode */
Bryan Wubb90eb02007-12-04 23:45:18 -0800916 write_CTRL(drv_data, (cr | CFG_SPI_READ));
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700917
918 drv_data->read(drv_data);
919 if (drv_data->rx != drv_data->rx_end)
920 tranf_success = 0;
921 }
922
923 if (!tranf_success) {
Bryan Wu131b17d2007-12-04 23:45:12 -0800924 dev_dbg(&drv_data->pdev->dev,
Bryan Wu88b40362007-05-21 18:32:16 +0800925 "IO write error!\n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700926 message->state = ERROR_STATE;
927 } else {
928 /* Update total byte transfered */
Mike Frysingerace32862009-04-06 19:00:34 -0700929 message->actual_length += drv_data->len_in_bytes;
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700930 /* Move to next transfer of this msg */
Mike Frysinger138f97c2009-04-06 19:00:50 -0700931 message->state = bfin_spi_next_transfer(drv_data);
Yi Lib9b2a762009-04-06 19:00:49 -0700932 if (drv_data->cs_change)
Mike Frysinger138f97c2009-04-06 19:00:50 -0700933 bfin_spi_cs_deactive(drv_data, chip);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700934 }
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700935 /* Schedule next transfer tasklet */
936 tasklet_schedule(&drv_data->pump_transfers);
937
938 }
939}
940
941/* pop a msg from queue and kick off real transfer */
Mike Frysinger138f97c2009-04-06 19:00:50 -0700942static void bfin_spi_pump_messages(struct work_struct *work)
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700943{
Bryan Wu131b17d2007-12-04 23:45:12 -0800944 struct driver_data *drv_data;
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700945 unsigned long flags;
946
Bryan Wu131b17d2007-12-04 23:45:12 -0800947 drv_data = container_of(work, struct driver_data, pump_messages);
948
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700949 /* Lock queue and check for queue work */
950 spin_lock_irqsave(&drv_data->lock, flags);
951 if (list_empty(&drv_data->queue) || drv_data->run == QUEUE_STOPPED) {
952 /* pumper kicked off but no work to do */
953 drv_data->busy = 0;
954 spin_unlock_irqrestore(&drv_data->lock, flags);
955 return;
956 }
957
958 /* Make sure we are not already running a message */
959 if (drv_data->cur_msg) {
960 spin_unlock_irqrestore(&drv_data->lock, flags);
961 return;
962 }
963
964 /* Extract head of queue */
965 drv_data->cur_msg = list_entry(drv_data->queue.next,
966 struct spi_message, queue);
Bryan Wu5fec5b52007-12-04 23:45:13 -0800967
968 /* Setup the SSP using the per chip configuration */
969 drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
Mike Frysinger138f97c2009-04-06 19:00:50 -0700970 bfin_spi_restore_state(drv_data);
Bryan Wu5fec5b52007-12-04 23:45:13 -0800971
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700972 list_del_init(&drv_data->cur_msg->queue);
973
974 /* Initial message state */
975 drv_data->cur_msg->state = START_STATE;
976 drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next,
977 struct spi_transfer, transfer_list);
978
Bryan Wu5fec5b52007-12-04 23:45:13 -0800979 dev_dbg(&drv_data->pdev->dev, "got a message to pump, "
980 "state is set to: baud %d, flag 0x%x, ctl 0x%x\n",
981 drv_data->cur_chip->baud, drv_data->cur_chip->flag,
982 drv_data->cur_chip->ctl_reg);
Bryan Wu131b17d2007-12-04 23:45:12 -0800983
984 dev_dbg(&drv_data->pdev->dev,
Bryan Wu88b40362007-05-21 18:32:16 +0800985 "the first transfer len is %d\n",
986 drv_data->cur_transfer->len);
Wu, Bryana5f6abd2007-05-06 14:50:34 -0700987
988 /* Mark as busy and launch transfers */
989 tasklet_schedule(&drv_data->pump_transfers);
990
991 drv_data->busy = 1;
992 spin_unlock_irqrestore(&drv_data->lock, flags);
993}
994
995/*
996 * got a msg to transfer, queue it in drv_data->queue.
997 * And kick off message pumper
998 */
Mike Frysinger138f97c2009-04-06 19:00:50 -0700999static int bfin_spi_transfer(struct spi_device *spi, struct spi_message *msg)
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001000{
1001 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
1002 unsigned long flags;
1003
1004 spin_lock_irqsave(&drv_data->lock, flags);
1005
1006 if (drv_data->run == QUEUE_STOPPED) {
1007 spin_unlock_irqrestore(&drv_data->lock, flags);
1008 return -ESHUTDOWN;
1009 }
1010
1011 msg->actual_length = 0;
1012 msg->status = -EINPROGRESS;
1013 msg->state = START_STATE;
1014
Bryan Wu88b40362007-05-21 18:32:16 +08001015 dev_dbg(&spi->dev, "adding an msg in transfer() \n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001016 list_add_tail(&msg->queue, &drv_data->queue);
1017
1018 if (drv_data->run == QUEUE_RUNNING && !drv_data->busy)
1019 queue_work(drv_data->workqueue, &drv_data->pump_messages);
1020
1021 spin_unlock_irqrestore(&drv_data->lock, flags);
1022
1023 return 0;
1024}
1025
Sonic Zhang12e17c42007-12-04 23:45:16 -08001026#define MAX_SPI_SSEL 7
1027
Mike Frysinger4160bde2009-04-06 19:00:40 -07001028static u16 ssel[][MAX_SPI_SSEL] = {
Sonic Zhang12e17c42007-12-04 23:45:16 -08001029 {P_SPI0_SSEL1, P_SPI0_SSEL2, P_SPI0_SSEL3,
1030 P_SPI0_SSEL4, P_SPI0_SSEL5,
1031 P_SPI0_SSEL6, P_SPI0_SSEL7},
1032
1033 {P_SPI1_SSEL1, P_SPI1_SSEL2, P_SPI1_SSEL3,
1034 P_SPI1_SSEL4, P_SPI1_SSEL5,
1035 P_SPI1_SSEL6, P_SPI1_SSEL7},
1036
1037 {P_SPI2_SSEL1, P_SPI2_SSEL2, P_SPI2_SSEL3,
1038 P_SPI2_SSEL4, P_SPI2_SSEL5,
1039 P_SPI2_SSEL6, P_SPI2_SSEL7},
1040};
1041
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001042/* first setup for new devices */
Mike Frysinger138f97c2009-04-06 19:00:50 -07001043static int bfin_spi_setup(struct spi_device *spi)
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001044{
1045 struct bfin5xx_spi_chip *chip_info = NULL;
1046 struct chip_data *chip;
1047 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
Michael Hennerich42c78b22009-04-06 19:00:51 -07001048 int ret;
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001049
1050 /* Abort device setup if requested features are not supported */
1051 if (spi->mode & ~(SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST)) {
1052 dev_err(&spi->dev, "requested mode not fully supported\n");
1053 return -EINVAL;
1054 }
1055
1056 /* Zero (the default) here means 8 bits */
1057 if (!spi->bits_per_word)
1058 spi->bits_per_word = 8;
1059
1060 if (spi->bits_per_word != 8 && spi->bits_per_word != 16)
1061 return -EINVAL;
1062
1063 /* Only alloc (or use chip_info) on first setup */
1064 chip = spi_get_ctldata(spi);
1065 if (chip == NULL) {
1066 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
1067 if (!chip)
1068 return -ENOMEM;
1069
1070 chip->enable_dma = 0;
1071 chip_info = spi->controller_data;
1072 }
1073
1074 /* chip_info isn't always needed */
1075 if (chip_info) {
Mike Frysinger2ed35512007-12-04 23:45:14 -08001076 /* Make sure people stop trying to set fields via ctl_reg
1077 * when they should actually be using common SPI framework.
1078 * Currently we let through: WOM EMISO PSSE GM SZ TIMOD.
1079 * Not sure if a user actually needs/uses any of these,
1080 * but let's assume (for now) they do.
1081 */
1082 if (chip_info->ctl_reg & (SPE|MSTR|CPOL|CPHA|LSBF|SIZE)) {
1083 dev_err(&spi->dev, "do not set bits in ctl_reg "
1084 "that the SPI framework manages\n");
1085 return -EINVAL;
1086 }
1087
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001088 chip->enable_dma = chip_info->enable_dma != 0
1089 && drv_data->master_info->enable_dma;
1090 chip->ctl_reg = chip_info->ctl_reg;
1091 chip->bits_per_word = chip_info->bits_per_word;
1092 chip->cs_change_per_word = chip_info->cs_change_per_word;
1093 chip->cs_chg_udelay = chip_info->cs_chg_udelay;
Michael Hennerich42c78b22009-04-06 19:00:51 -07001094 chip->cs_gpio = chip_info->cs_gpio;
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001095 }
1096
1097 /* translate common spi framework into our register */
1098 if (spi->mode & SPI_CPOL)
1099 chip->ctl_reg |= CPOL;
1100 if (spi->mode & SPI_CPHA)
1101 chip->ctl_reg |= CPHA;
1102 if (spi->mode & SPI_LSB_FIRST)
1103 chip->ctl_reg |= LSBF;
1104 /* we dont support running in slave mode (yet?) */
1105 chip->ctl_reg |= MSTR;
1106
1107 /*
1108 * if any one SPI chip is registered and wants DMA, request the
1109 * DMA channel for it
1110 */
Bryan Wubb90eb02007-12-04 23:45:18 -08001111 if (chip->enable_dma && !drv_data->dma_requested) {
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001112 /* register dma irq handler */
Mike Frysinger59bfcc62009-04-06 19:00:37 -07001113 if (request_dma(drv_data->dma_channel, "BFIN_SPI_DMA") < 0) {
Bryan Wu88b40362007-05-21 18:32:16 +08001114 dev_dbg(&spi->dev,
1115 "Unable to request BlackFin SPI DMA channel\n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001116 return -ENODEV;
1117 }
Bryan Wubb90eb02007-12-04 23:45:18 -08001118 if (set_dma_callback(drv_data->dma_channel,
Mike Frysinger138f97c2009-04-06 19:00:50 -07001119 bfin_spi_dma_irq_handler, drv_data) < 0) {
Bryan Wu88b40362007-05-21 18:32:16 +08001120 dev_dbg(&spi->dev, "Unable to set dma callback\n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001121 return -EPERM;
1122 }
Bryan Wubb90eb02007-12-04 23:45:18 -08001123 dma_disable_irq(drv_data->dma_channel);
1124 drv_data->dma_requested = 1;
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001125 }
1126
1127 /*
1128 * Notice: for blackfin, the speed_hz is the value of register
1129 * SPI_BAUD, not the real baudrate
1130 */
1131 chip->baud = hz_to_spi_baud(spi->max_speed_hz);
Yi Li2cf36832009-04-06 19:00:44 -07001132 chip->flag = 1 << (spi->chip_select);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001133 chip->chip_select_num = spi->chip_select;
1134
Michael Hennerich42c78b22009-04-06 19:00:51 -07001135 if (chip->chip_select_num == 0) {
1136 ret = gpio_request(chip->cs_gpio, spi->modalias);
1137 if (ret) {
1138 if (drv_data->dma_requested)
1139 free_dma(drv_data->dma_channel);
1140 return ret;
1141 }
1142 gpio_direction_output(chip->cs_gpio, 1);
1143 }
1144
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001145 switch (chip->bits_per_word) {
1146 case 8:
1147 chip->n_bytes = 1;
1148 chip->width = CFG_SPI_WORDSIZE8;
1149 chip->read = chip->cs_change_per_word ?
Mike Frysinger138f97c2009-04-06 19:00:50 -07001150 bfin_spi_u8_cs_chg_reader : bfin_spi_u8_reader;
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001151 chip->write = chip->cs_change_per_word ?
Mike Frysinger138f97c2009-04-06 19:00:50 -07001152 bfin_spi_u8_cs_chg_writer : bfin_spi_u8_writer;
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001153 chip->duplex = chip->cs_change_per_word ?
Mike Frysinger138f97c2009-04-06 19:00:50 -07001154 bfin_spi_u8_cs_chg_duplex : bfin_spi_u8_duplex;
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001155 break;
1156
1157 case 16:
1158 chip->n_bytes = 2;
1159 chip->width = CFG_SPI_WORDSIZE16;
1160 chip->read = chip->cs_change_per_word ?
Mike Frysinger138f97c2009-04-06 19:00:50 -07001161 bfin_spi_u16_cs_chg_reader : bfin_spi_u16_reader;
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001162 chip->write = chip->cs_change_per_word ?
Mike Frysinger138f97c2009-04-06 19:00:50 -07001163 bfin_spi_u16_cs_chg_writer : bfin_spi_u16_writer;
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001164 chip->duplex = chip->cs_change_per_word ?
Mike Frysinger138f97c2009-04-06 19:00:50 -07001165 bfin_spi_u16_cs_chg_duplex : bfin_spi_u16_duplex;
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001166 break;
1167
1168 default:
1169 dev_err(&spi->dev, "%d bits_per_word is not supported\n",
1170 chip->bits_per_word);
Mike Frysinger138f97c2009-04-06 19:00:50 -07001171 if (chip_info)
1172 kfree(chip);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001173 return -ENODEV;
1174 }
1175
Joe Perches898eb712007-10-18 03:06:30 -07001176 dev_dbg(&spi->dev, "setup spi chip %s, width is %d, dma is %d\n",
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001177 spi->modalias, chip->width, chip->enable_dma);
Bryan Wu88b40362007-05-21 18:32:16 +08001178 dev_dbg(&spi->dev, "ctl_reg is 0x%x, flag_reg is 0x%x\n",
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001179 chip->ctl_reg, chip->flag);
1180
1181 spi_set_ctldata(spi, chip);
1182
Sonic Zhang12e17c42007-12-04 23:45:16 -08001183 dev_dbg(&spi->dev, "chip select number is %d\n", chip->chip_select_num);
1184 if ((chip->chip_select_num > 0)
1185 && (chip->chip_select_num <= spi->master->num_chipselect))
1186 peripheral_request(ssel[spi->master->bus_num]
Bryan Wuaab0d832008-02-06 01:38:17 -08001187 [chip->chip_select_num-1], spi->modalias);
Sonic Zhang12e17c42007-12-04 23:45:16 -08001188
Mike Frysinger138f97c2009-04-06 19:00:50 -07001189 bfin_spi_cs_deactive(drv_data, chip);
Sonic Zhang07612e52007-12-04 23:45:21 -08001190
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001191 return 0;
1192}
1193
1194/*
1195 * callback for spi framework.
1196 * clean driver specific data
1197 */
Mike Frysinger138f97c2009-04-06 19:00:50 -07001198static void bfin_spi_cleanup(struct spi_device *spi)
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001199{
Mike Frysinger27bb9e72007-06-11 15:31:30 +08001200 struct chip_data *chip = spi_get_ctldata(spi);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001201
Mike Frysingere7d02e32009-04-06 19:00:51 -07001202 if (!chip)
1203 return;
1204
Sonic Zhang12e17c42007-12-04 23:45:16 -08001205 if ((chip->chip_select_num > 0)
1206 && (chip->chip_select_num <= spi->master->num_chipselect))
1207 peripheral_free(ssel[spi->master->bus_num]
1208 [chip->chip_select_num-1]);
1209
Michael Hennerich42c78b22009-04-06 19:00:51 -07001210 if (chip->chip_select_num == 0)
1211 gpio_free(chip->cs_gpio);
1212
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001213 kfree(chip);
1214}
1215
Mike Frysinger138f97c2009-04-06 19:00:50 -07001216static inline int bfin_spi_init_queue(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001217{
1218 INIT_LIST_HEAD(&drv_data->queue);
1219 spin_lock_init(&drv_data->lock);
1220
1221 drv_data->run = QUEUE_STOPPED;
1222 drv_data->busy = 0;
1223
1224 /* init transfer tasklet */
1225 tasklet_init(&drv_data->pump_transfers,
Mike Frysinger138f97c2009-04-06 19:00:50 -07001226 bfin_spi_pump_transfers, (unsigned long)drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001227
1228 /* init messages workqueue */
Mike Frysinger138f97c2009-04-06 19:00:50 -07001229 INIT_WORK(&drv_data->pump_messages, bfin_spi_pump_messages);
Kay Sievers6c7377a2009-03-24 16:38:21 -07001230 drv_data->workqueue = create_singlethread_workqueue(
1231 dev_name(drv_data->master->dev.parent));
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001232 if (drv_data->workqueue == NULL)
1233 return -EBUSY;
1234
1235 return 0;
1236}
1237
Mike Frysinger138f97c2009-04-06 19:00:50 -07001238static inline int bfin_spi_start_queue(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001239{
1240 unsigned long flags;
1241
1242 spin_lock_irqsave(&drv_data->lock, flags);
1243
1244 if (drv_data->run == QUEUE_RUNNING || drv_data->busy) {
1245 spin_unlock_irqrestore(&drv_data->lock, flags);
1246 return -EBUSY;
1247 }
1248
1249 drv_data->run = QUEUE_RUNNING;
1250 drv_data->cur_msg = NULL;
1251 drv_data->cur_transfer = NULL;
1252 drv_data->cur_chip = NULL;
1253 spin_unlock_irqrestore(&drv_data->lock, flags);
1254
1255 queue_work(drv_data->workqueue, &drv_data->pump_messages);
1256
1257 return 0;
1258}
1259
Mike Frysinger138f97c2009-04-06 19:00:50 -07001260static inline int bfin_spi_stop_queue(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001261{
1262 unsigned long flags;
1263 unsigned limit = 500;
1264 int status = 0;
1265
1266 spin_lock_irqsave(&drv_data->lock, flags);
1267
1268 /*
1269 * This is a bit lame, but is optimized for the common execution path.
1270 * A wait_queue on the drv_data->busy could be used, but then the common
1271 * execution path (pump_messages) would be required to call wake_up or
1272 * friends on every SPI message. Do this instead
1273 */
1274 drv_data->run = QUEUE_STOPPED;
1275 while (!list_empty(&drv_data->queue) && drv_data->busy && limit--) {
1276 spin_unlock_irqrestore(&drv_data->lock, flags);
1277 msleep(10);
1278 spin_lock_irqsave(&drv_data->lock, flags);
1279 }
1280
1281 if (!list_empty(&drv_data->queue) || drv_data->busy)
1282 status = -EBUSY;
1283
1284 spin_unlock_irqrestore(&drv_data->lock, flags);
1285
1286 return status;
1287}
1288
Mike Frysinger138f97c2009-04-06 19:00:50 -07001289static inline int bfin_spi_destroy_queue(struct driver_data *drv_data)
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001290{
1291 int status;
1292
Mike Frysinger138f97c2009-04-06 19:00:50 -07001293 status = bfin_spi_stop_queue(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001294 if (status != 0)
1295 return status;
1296
1297 destroy_workqueue(drv_data->workqueue);
1298
1299 return 0;
1300}
1301
Mike Frysinger138f97c2009-04-06 19:00:50 -07001302static int __init bfin_spi_probe(struct platform_device *pdev)
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001303{
1304 struct device *dev = &pdev->dev;
1305 struct bfin5xx_spi_master *platform_info;
1306 struct spi_master *master;
1307 struct driver_data *drv_data = 0;
Bryan Wua32c6912007-12-04 23:45:15 -08001308 struct resource *res;
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001309 int status = 0;
1310
1311 platform_info = dev->platform_data;
1312
1313 /* Allocate master with space for drv_data */
1314 master = spi_alloc_master(dev, sizeof(struct driver_data) + 16);
1315 if (!master) {
1316 dev_err(&pdev->dev, "can not alloc spi_master\n");
1317 return -ENOMEM;
1318 }
Bryan Wu131b17d2007-12-04 23:45:12 -08001319
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001320 drv_data = spi_master_get_devdata(master);
1321 drv_data->master = master;
1322 drv_data->master_info = platform_info;
1323 drv_data->pdev = pdev;
Bryan Wu003d9222007-12-04 23:45:22 -08001324 drv_data->pin_req = platform_info->pin_req;
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001325
1326 master->bus_num = pdev->id;
1327 master->num_chipselect = platform_info->num_chipselect;
Mike Frysinger138f97c2009-04-06 19:00:50 -07001328 master->cleanup = bfin_spi_cleanup;
1329 master->setup = bfin_spi_setup;
1330 master->transfer = bfin_spi_transfer;
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001331
Bryan Wua32c6912007-12-04 23:45:15 -08001332 /* Find and map our resources */
1333 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1334 if (res == NULL) {
1335 dev_err(dev, "Cannot get IORESOURCE_MEM\n");
1336 status = -ENOENT;
1337 goto out_error_get_res;
1338 }
1339
Bryan Wuf4521262007-12-04 23:45:22 -08001340 drv_data->regs_base = ioremap(res->start, (res->end - res->start + 1));
1341 if (drv_data->regs_base == NULL) {
Bryan Wua32c6912007-12-04 23:45:15 -08001342 dev_err(dev, "Cannot map IO\n");
1343 status = -ENXIO;
1344 goto out_error_ioremap;
1345 }
1346
Bryan Wubb90eb02007-12-04 23:45:18 -08001347 drv_data->dma_channel = platform_get_irq(pdev, 0);
1348 if (drv_data->dma_channel < 0) {
Bryan Wua32c6912007-12-04 23:45:15 -08001349 dev_err(dev, "No DMA channel specified\n");
1350 status = -ENOENT;
1351 goto out_error_no_dma_ch;
1352 }
1353
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001354 /* Initial and start queue */
Mike Frysinger138f97c2009-04-06 19:00:50 -07001355 status = bfin_spi_init_queue(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001356 if (status != 0) {
Bryan Wua32c6912007-12-04 23:45:15 -08001357 dev_err(dev, "problem initializing queue\n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001358 goto out_error_queue_alloc;
1359 }
Bryan Wua32c6912007-12-04 23:45:15 -08001360
Mike Frysinger138f97c2009-04-06 19:00:50 -07001361 status = bfin_spi_start_queue(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001362 if (status != 0) {
Bryan Wua32c6912007-12-04 23:45:15 -08001363 dev_err(dev, "problem starting queue\n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001364 goto out_error_queue_alloc;
1365 }
1366
Vitja Makarovf9e522c2008-04-08 17:41:57 -07001367 status = peripheral_request_list(drv_data->pin_req, DRV_NAME);
1368 if (status != 0) {
1369 dev_err(&pdev->dev, ": Requesting Peripherals failed\n");
1370 goto out_error_queue_alloc;
1371 }
1372
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001373 /* Register with the SPI framework */
1374 platform_set_drvdata(pdev, drv_data);
1375 status = spi_register_master(master);
1376 if (status != 0) {
Bryan Wua32c6912007-12-04 23:45:15 -08001377 dev_err(dev, "problem registering spi master\n");
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001378 goto out_error_queue_alloc;
1379 }
Bryan Wua32c6912007-12-04 23:45:15 -08001380
Bryan Wuf4521262007-12-04 23:45:22 -08001381 dev_info(dev, "%s, Version %s, regs_base@%p, dma channel@%d\n",
Bryan Wubb90eb02007-12-04 23:45:18 -08001382 DRV_DESC, DRV_VERSION, drv_data->regs_base,
1383 drv_data->dma_channel);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001384 return status;
1385
Michael Hennerichcc2f81a2007-12-04 23:45:13 -08001386out_error_queue_alloc:
Mike Frysinger138f97c2009-04-06 19:00:50 -07001387 bfin_spi_destroy_queue(drv_data);
Bryan Wua32c6912007-12-04 23:45:15 -08001388out_error_no_dma_ch:
Bryan Wubb90eb02007-12-04 23:45:18 -08001389 iounmap((void *) drv_data->regs_base);
Bryan Wua32c6912007-12-04 23:45:15 -08001390out_error_ioremap:
1391out_error_get_res:
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001392 spi_master_put(master);
Michael Hennerichcc2f81a2007-12-04 23:45:13 -08001393
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001394 return status;
1395}
1396
1397/* stop hardware and remove the driver */
Mike Frysinger138f97c2009-04-06 19:00:50 -07001398static int __devexit bfin_spi_remove(struct platform_device *pdev)
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001399{
1400 struct driver_data *drv_data = platform_get_drvdata(pdev);
1401 int status = 0;
1402
1403 if (!drv_data)
1404 return 0;
1405
1406 /* Remove the queue */
Mike Frysinger138f97c2009-04-06 19:00:50 -07001407 status = bfin_spi_destroy_queue(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001408 if (status != 0)
1409 return status;
1410
1411 /* Disable the SSP at the peripheral and SOC level */
1412 bfin_spi_disable(drv_data);
1413
1414 /* Release DMA */
1415 if (drv_data->master_info->enable_dma) {
Bryan Wubb90eb02007-12-04 23:45:18 -08001416 if (dma_channel_active(drv_data->dma_channel))
1417 free_dma(drv_data->dma_channel);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001418 }
1419
1420 /* Disconnect from the SPI framework */
1421 spi_unregister_master(drv_data->master);
1422
Bryan Wu003d9222007-12-04 23:45:22 -08001423 peripheral_free_list(drv_data->pin_req);
Michael Hennerichcc2f81a2007-12-04 23:45:13 -08001424
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001425 /* Prevent double remove */
1426 platform_set_drvdata(pdev, NULL);
1427
1428 return 0;
1429}
1430
1431#ifdef CONFIG_PM
Mike Frysinger138f97c2009-04-06 19:00:50 -07001432static int bfin_spi_suspend(struct platform_device *pdev, pm_message_t state)
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001433{
1434 struct driver_data *drv_data = platform_get_drvdata(pdev);
1435 int status = 0;
1436
Mike Frysinger138f97c2009-04-06 19:00:50 -07001437 status = bfin_spi_stop_queue(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001438 if (status != 0)
1439 return status;
1440
1441 /* stop hardware */
1442 bfin_spi_disable(drv_data);
1443
1444 return 0;
1445}
1446
Mike Frysinger138f97c2009-04-06 19:00:50 -07001447static int bfin_spi_resume(struct platform_device *pdev)
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001448{
1449 struct driver_data *drv_data = platform_get_drvdata(pdev);
1450 int status = 0;
1451
1452 /* Enable the SPI interface */
1453 bfin_spi_enable(drv_data);
1454
1455 /* Start the queue running */
Mike Frysinger138f97c2009-04-06 19:00:50 -07001456 status = bfin_spi_start_queue(drv_data);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001457 if (status != 0) {
1458 dev_err(&pdev->dev, "problem starting queue (%d)\n", status);
1459 return status;
1460 }
1461
1462 return 0;
1463}
1464#else
Mike Frysinger138f97c2009-04-06 19:00:50 -07001465#define bfin_spi_suspend NULL
1466#define bfin_spi_resume NULL
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001467#endif /* CONFIG_PM */
1468
Kay Sievers7e38c3c2008-04-10 21:29:20 -07001469MODULE_ALIAS("platform:bfin-spi");
Mike Frysinger138f97c2009-04-06 19:00:50 -07001470static struct platform_driver bfin_spi_driver = {
David Brownellfc3ba952007-08-30 23:56:24 -07001471 .driver = {
Bryan Wua32c6912007-12-04 23:45:15 -08001472 .name = DRV_NAME,
Bryan Wu88b40362007-05-21 18:32:16 +08001473 .owner = THIS_MODULE,
1474 },
Mike Frysinger138f97c2009-04-06 19:00:50 -07001475 .suspend = bfin_spi_suspend,
1476 .resume = bfin_spi_resume,
1477 .remove = __devexit_p(bfin_spi_remove),
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001478};
1479
Mike Frysinger138f97c2009-04-06 19:00:50 -07001480static int __init bfin_spi_init(void)
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001481{
Mike Frysinger138f97c2009-04-06 19:00:50 -07001482 return platform_driver_probe(&bfin_spi_driver, bfin_spi_probe);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001483}
Mike Frysinger138f97c2009-04-06 19:00:50 -07001484module_init(bfin_spi_init);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001485
Mike Frysinger138f97c2009-04-06 19:00:50 -07001486static void __exit bfin_spi_exit(void)
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001487{
Mike Frysinger138f97c2009-04-06 19:00:50 -07001488 platform_driver_unregister(&bfin_spi_driver);
Wu, Bryana5f6abd2007-05-06 14:50:34 -07001489}
Mike Frysinger138f97c2009-04-06 19:00:50 -07001490module_exit(bfin_spi_exit);