36 #include <linux/kernel.h>
44 #include <linux/slab.h>
48 #include <linux/module.h>
51 #include <mach/hardware.h>
63 #define UWIRE_BASE_PHYS 0xFFFB3000
66 #define UWIRE_IO_SIZE 0x20
67 #define UWIRE_TDR 0x00
68 #define UWIRE_RDR 0x00
69 #define UWIRE_CSR 0x01
70 #define UWIRE_SR1 0x02
71 #define UWIRE_SR2 0x03
72 #define UWIRE_SR3 0x04
73 #define UWIRE_SR4 0x05
74 #define UWIRE_SR5 0x06
77 #define RDRB (1 << 15)
78 #define CSRB (1 << 14)
79 #define START (1 << 13)
80 #define CS_CMD (1 << 12)
83 #define UWIRE_READ_FALLING_EDGE 0x0001
84 #define UWIRE_READ_RISING_EDGE 0x0000
85 #define UWIRE_WRITE_FALLING_EDGE 0x0000
86 #define UWIRE_WRITE_RISING_EDGE 0x0002
87 #define UWIRE_CS_ACTIVE_LOW 0x0000
88 #define UWIRE_CS_ACTIVE_HIGH 0x0004
89 #define UWIRE_FREQ_DIV_2 0x0000
90 #define UWIRE_FREQ_DIV_4 0x0008
91 #define UWIRE_FREQ_DIV_8 0x0010
92 #define UWIRE_CHK_READY 0x0020
93 #define UWIRE_CLK_INVERTED 0x0040
111 static unsigned int uwire_idx_shift;
112 static void __iomem *uwire_base;
114 static inline void uwire_write_reg(
int idx,
u16 val)
116 __raw_writew(val, uwire_base + (idx << uwire_idx_shift));
119 static inline u16 uwire_read_reg(
int idx)
121 return __raw_readw(uwire_base + (idx << uwire_idx_shift));
124 static inline void omap_uwire_configure_mode(
u8 cs,
unsigned long flags)
141 w = uwire_read_reg(reg);
142 w &= ~(0x3f << shift);
144 uwire_write_reg(reg, w);
147 static int wait_uwire_csr_flag(
u16 mask,
u16 val,
int might_not_catch)
151 unsigned long max_jiffies =
jiffies +
HZ;
155 if ((w & mask) == val)
159 "mask=%#06x val=%#06x\n",
160 __func__, w, mask, val);
164 if (might_not_catch && c > 64)
170 static void uwire_set_clk1_div(
int div1_idx)
190 old_cs = (w >> 10) & 0x03;
250 dev_name(&spi->
dev), bits, val);
252 if (wait_uwire_csr_flag(
CSRB, 0, 0))
258 val =
START | w | (bits << 5);
267 if (wait_uwire_csr_flag(
CSRB,
CSRB, 1))
274 if (wait_uwire_csr_flag(
CSRB, 0, 0))
288 val =
START | w | (bits << 0);
295 if (wait_uwire_csr_flag(
RDRB |
CSRB,
303 val &= (1 <<
bits) - 1;
310 dev_name(&spi->
dev), bits, val);
333 uwire = spi_master_get_devdata(spi->
master);
346 pr_debug(
"%s: wordsize %d?\n", dev_name(&spi->
dev), bits);
381 pr_debug(
"%s: zero speed?\n", dev_name(&spi->
dev));
387 for (div1_idx = 0; div1_idx < 4; div1_idx++) {
403 div2 = (rate / div1 + hz - 1) / hz;
408 pr_debug(
"%s: lowest clock %ld, need %d\n",
409 dev_name(&spi->
dev), rate / 10 / 8, hz);
418 uwire_set_clk1_div(div1_idx);
442 omap_uwire_configure_mode(spi->
chip_select, flags);
443 pr_debug(
"%s: uwire flags %02x, armxor %lu KHz, SCK %lu KHz\n",
452 static int uwire_setup(
struct spi_device *spi)
463 return uwire_setup_transfer(spi,
NULL);
466 static void uwire_cleanup(
struct spi_device *spi)
471 static void uwire_off(
struct uwire_spi *uwire)
476 spi_master_put(uwire->
bitbang.master);
489 uwire = spi_master_get_devdata(master);
494 spi_master_put(master);
501 if (IS_ERR(uwire->
ck)) {
502 status = PTR_ERR(uwire->
ck);
503 dev_dbg(&pdev->
dev,
"no functional clock?\n");
504 spi_master_put(master);
523 master->
setup = uwire_setup;
524 master->
cleanup = uwire_cleanup;
526 uwire->
bitbang.master = master;
527 uwire->
bitbang.chipselect = uwire_chipselect;
528 uwire->
bitbang.setup_transfer = uwire_setup_transfer;
529 uwire->
bitbang.txrx_bufs = uwire_txrx;
557 .name =
"omap_uwire",
565 static int __init omap_uwire_init(
void)
571 if (machine_is_omap_h2()) {
576 if (machine_is_omap_perseus2()) {
585 static void __exit omap_uwire_exit(
void)