18 #include <linux/errno.h>
21 #include <linux/sched.h>
28 #include <linux/module.h>
32 #define SPI_FIFO_SIZE 4
33 #define SPI_MAX_DIVIDER 0xff
34 #define SPI_MIN_DIVIDER 1
36 #define TXx9_SPMCR 0x00
37 #define TXx9_SPCR0 0x04
38 #define TXx9_SPCR1 0x08
39 #define TXx9_SPFS 0x0c
40 #define TXx9_SPSR 0x14
41 #define TXx9_SPDR 0x18
44 #define TXx9_SPMCR_OPMODE 0xc0
45 #define TXx9_SPMCR_CONFIG 0x40
46 #define TXx9_SPMCR_ACTIVE 0x80
47 #define TXx9_SPMCR_SPSTP 0x02
48 #define TXx9_SPMCR_BCLR 0x01
51 #define TXx9_SPCR0_TXIFL_MASK 0xc000
52 #define TXx9_SPCR0_RXIFL_MASK 0x3000
53 #define TXx9_SPCR0_SIDIE 0x0800
54 #define TXx9_SPCR0_SOEIE 0x0400
55 #define TXx9_SPCR0_RBSIE 0x0200
56 #define TXx9_SPCR0_TBSIE 0x0100
57 #define TXx9_SPCR0_IFSPSE 0x0010
58 #define TXx9_SPCR0_SBOS 0x0004
59 #define TXx9_SPCR0_SPHA 0x0002
60 #define TXx9_SPCR0_SPOL 0x0001
63 #define TXx9_SPSR_TBSI 0x8000
64 #define TXx9_SPSR_RBSI 0x4000
65 #define TXx9_SPSR_TBS_MASK 0x3800
66 #define TXx9_SPSR_RBS_MASK 0x0700
67 #define TXx9_SPSR_SPOE 0x0080
68 #define TXx9_SPSR_IFSD 0x0008
69 #define TXx9_SPSR_SIDLE 0x0004
70 #define TXx9_SPSR_STRDY 0x0002
71 #define TXx9_SPSR_SRRDY 0x0001
98 int on,
unsigned int cs_delay)
116 static int txx9spi_setup(
struct spi_device *spi)
127 if (bits_per_word != 8 && bits_per_word != 16)
132 dev_err(&spi->
dev,
"Cannot setup GPIO for chipselect.\n");
139 spin_unlock(&c->
lock);
159 unsigned int cs_delay;
163 u32 prev_speed_hz = 0;
164 u8 prev_bits_per_word = 0;
186 const void *txbuf = t->
tx_buf;
189 unsigned int len = t->
len;
194 bits_per_word = bits_per_word ? : 8;
195 wsize = bits_per_word >> 3;
197 if (prev_speed_hz != speed_hz
198 || prev_bits_per_word != bits_per_word) {
204 txx9spi_wr(c, (n << 8) | bits_per_word,
TXx9_SPCR1);
213 txx9spi_cs_func(spi, c, 1, cs_delay);
220 if (len < count * wsize)
227 cr0 |= (count - 1) << 12;
232 for (i = 0; i <
count; i++) {
236 : *(
const u16 *)txbuf;
246 for (i = 0; i <
count; i++) {
252 *(
u16 *)rxbuf = data;
256 len -= count * wsize;
269 txx9spi_cs_func(spi, c, 0, cs_delay);
280 if (!(status == 0 && cs_change))
281 txx9spi_cs_func(spi, c, 0, cs_delay);
293 while (!list_empty(&c->
queue)) {
297 list_del_init(&m->
queue);
298 spin_unlock_irqrestore(&c->
lock, flags);
300 txx9spi_work_one(c, m);
304 spin_unlock_irqrestore(&c->
lock, flags);
310 struct txx9spi *c = spi_master_get_devdata(master);
321 bits_per_word = bits_per_word ? : 8;
324 if (bits_per_word != 8 && bits_per_word != 16)
326 if (t->
len & ((bits_per_word >> 3) - 1))
328 if (speed_hz < c->min_speed_hz || speed_hz > c->
max_speed_hz)
335 spin_unlock_irqrestore(&c->
lock, flags);
352 c = spi_master_get_devdata(master);
353 platform_set_drvdata(dev, master);
357 INIT_LIST_HEAD(&c->
queue);
361 if (IS_ERR(c->
clk)) {
362 ret = PTR_ERR(c->
clk);
394 ret = devm_request_irq(&dev->
dev, irq, txx9spi_interrupt, 0,
400 dev_name(master->
dev.parent));
406 (
unsigned long long)res->
start, irq,
407 (c->
baseclk + 500000) / 1000000);
413 master->
setup = txx9spi_setup;
414 master->
transfer = txx9spi_transfer;
430 platform_set_drvdata(dev,
NULL);
431 spi_master_put(master);
437 struct spi_master *master = spi_master_get(platform_get_drvdata(dev));
438 struct txx9spi *c = spi_master_get_devdata(master);
441 platform_set_drvdata(dev,
NULL);
445 spi_master_put(master);
460 static int __init txx9spi_init(
void)
466 static void __exit txx9spi_exit(
void)