24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/sched.h>
27 #include <linux/errno.h>
30 #include <linux/list.h>
37 #define SPI_SH_TBR 0x00
38 #define SPI_SH_RBR 0x00
39 #define SPI_SH_CR1 0x08
40 #define SPI_SH_CR2 0x10
41 #define SPI_SH_CR3 0x18
42 #define SPI_SH_CR4 0x20
43 #define SPI_SH_CR5 0x28
46 #define SPI_SH_TBE 0x80
47 #define SPI_SH_TBF 0x40
48 #define SPI_SH_RBE 0x20
49 #define SPI_SH_RBF 0x10
50 #define SPI_SH_PFONRD 0x08
51 #define SPI_SH_SSDB 0x04
52 #define SPI_SH_SSD 0x02
53 #define SPI_SH_SSA 0x01
56 #define SPI_SH_RSTF 0x80
57 #define SPI_SH_LOOPBK 0x40
58 #define SPI_SH_CPOL 0x20
59 #define SPI_SH_CPHA 0x10
60 #define SPI_SH_L1M0 0x08
63 #define SPI_SH_MAX_BYTE 0xFF
66 #define SPI_SH_TBEI 0x80
67 #define SPI_SH_TBFI 0x40
68 #define SPI_SH_RBEI 0x20
69 #define SPI_SH_RBFI 0x10
70 #define SPI_SH_WPABRT 0x04
71 #define SPI_SH_SSS 0x01
74 #define SPI_SH_P1L0 0x80
75 #define SPI_SH_PP1L0 0x40
76 #define SPI_SH_MUXI 0x20
77 #define SPI_SH_MUXIRQ 0x10
79 #define SPI_SH_FIFO_SIZE 32
80 #define SPI_SH_SEND_TIMEOUT (3 * HZ)
81 #define SPI_SH_RECEIVE_TIMEOUT (HZ >> 3)
103 else if (ss->
width == 32)
111 else if (ss->
width == 32)
117 static void spi_sh_set_bit(
struct spi_sh_data *ss,
unsigned long val,
118 unsigned long offset)
122 tmp = spi_sh_read(ss, offset);
124 spi_sh_write(ss, tmp, offset);
127 static void spi_sh_clear_bit(
struct spi_sh_data *ss,
unsigned long val,
128 unsigned long offset)
132 tmp = spi_sh_read(ss, offset);
134 spi_sh_write(ss, tmp, offset);
143 static int spi_sh_wait_receive_buffer(
struct spi_sh_data *ss)
155 static int spi_sh_wait_write_buffer_empty(
struct spi_sh_data *ss)
157 int timeout = 100000;
180 data = (
unsigned char *)t->
tx_buf;
183 for (i = 0; i < cur_len &&
188 spi_sh_write(ss, (
unsigned long)data[
i],
SPI_SH_TBR);
203 ss->
cr1 &= ~SPI_SH_TBE;
206 ss->
cr1 & SPI_SH_TBE,
208 if (ret == 0 && !(ss->
cr1 & SPI_SH_TBE)) {
221 ss->
cr1 &= ~SPI_SH_TBE;
224 ss->
cr1 & SPI_SH_TBE,
226 if (ret == 0 && (ss->
cr1 & SPI_SH_TBE)) {
255 spi_sh_wait_write_buffer_empty(ss);
257 data = (
unsigned char *)t->
rx_buf;
273 for (i = 0; i < cur_len; i++) {
274 if (spi_sh_wait_receive_buffer(ss))
305 while (!list_empty(&ss->
queue)) {
307 list_del_init(&mesg->
queue);
309 spin_unlock_irqrestore(&ss->
lock, flags);
311 pr_debug(
"tx_buf = %p, rx_buf = %p\n",
313 pr_debug(
"len = %d, delay_usecs = %d\n",
317 ret = spi_sh_send(ss, mesg, t);
322 ret = spi_sh_receive(ss, mesg, t);
343 spin_unlock_irqrestore(&ss->
lock, flags);
397 spin_unlock_irqrestore(&ss->
lock, flags);
402 static void spi_sh_cleanup(
struct spi_device *spi)
418 if (cr1 & SPI_SH_TBE)
422 if (cr1 & SPI_SH_RBE)
463 dev_err(&pdev->
dev,
"platform_get_irq error\n");
468 if (master ==
NULL) {
469 dev_err(&pdev->
dev,
"spi_alloc_master error.\n");
473 ss = spi_master_get_devdata(master);
496 INIT_LIST_HEAD(&ss->
queue);
501 dev_name(master->
dev.parent));
503 dev_err(&pdev->
dev,
"create workqueue error\n");
508 ret =
request_irq(irq, spi_sh_irq, 0,
"spi_sh", ss);
516 master->
setup = spi_sh_setup;
518 master->
cleanup = spi_sh_cleanup;
535 spi_master_put(master);
541 .probe = spi_sh_probe,