]> git.ipfire.org Git - thirdparty/kernel/stable.git/blob - drivers/i2c/busses/i2c-keywest.h
Linux-2.6.12-rc2
[thirdparty/kernel/stable.git] / drivers / i2c / busses / i2c-keywest.h
1 #ifndef __I2C_KEYWEST_H__
2 #define __I2C_KEYWEST_H__
3
4 /* The Tumbler audio equalizer can be really slow sometimes */
5 #define POLL_TIMEOUT (2*HZ)
6
7 /* Register indices */
8 typedef enum {
9 reg_mode = 0,
10 reg_control,
11 reg_status,
12 reg_isr,
13 reg_ier,
14 reg_addr,
15 reg_subaddr,
16 reg_data
17 } reg_t;
18
19
20 /* Mode register */
21 #define KW_I2C_MODE_100KHZ 0x00
22 #define KW_I2C_MODE_50KHZ 0x01
23 #define KW_I2C_MODE_25KHZ 0x02
24 #define KW_I2C_MODE_DUMB 0x00
25 #define KW_I2C_MODE_STANDARD 0x04
26 #define KW_I2C_MODE_STANDARDSUB 0x08
27 #define KW_I2C_MODE_COMBINED 0x0C
28 #define KW_I2C_MODE_MODE_MASK 0x0C
29 #define KW_I2C_MODE_CHAN_MASK 0xF0
30
31 /* Control register */
32 #define KW_I2C_CTL_AAK 0x01
33 #define KW_I2C_CTL_XADDR 0x02
34 #define KW_I2C_CTL_STOP 0x04
35 #define KW_I2C_CTL_START 0x08
36
37 /* Status register */
38 #define KW_I2C_STAT_BUSY 0x01
39 #define KW_I2C_STAT_LAST_AAK 0x02
40 #define KW_I2C_STAT_LAST_RW 0x04
41 #define KW_I2C_STAT_SDA 0x08
42 #define KW_I2C_STAT_SCL 0x10
43
44 /* IER & ISR registers */
45 #define KW_I2C_IRQ_DATA 0x01
46 #define KW_I2C_IRQ_ADDR 0x02
47 #define KW_I2C_IRQ_STOP 0x04
48 #define KW_I2C_IRQ_START 0x08
49 #define KW_I2C_IRQ_MASK 0x0F
50
51 /* Physical interface */
52 struct keywest_iface
53 {
54 struct device_node *node;
55 void __iomem * base;
56 unsigned bsteps;
57 int irq;
58 spinlock_t lock;
59 struct keywest_chan *channels;
60 unsigned chan_count;
61 u8 cur_mode;
62 char read_write;
63 u8 *data;
64 unsigned datalen;
65 int state;
66 int result;
67 struct timer_list timeout_timer;
68 struct completion complete;
69 };
70
71 enum {
72 state_idle,
73 state_addr,
74 state_read,
75 state_write,
76 state_stop,
77 state_dead
78 };
79
80 /* Channel on an interface */
81 struct keywest_chan
82 {
83 struct i2c_adapter adapter;
84 struct keywest_iface* iface;
85 unsigned chan_no;
86 };
87
88 /* Register access */
89
90 static inline u8 __read_reg(struct keywest_iface *iface, reg_t reg)
91 {
92 return in_8(iface->base
93 + (((unsigned)reg) << iface->bsteps));
94 }
95
96 static inline void __write_reg(struct keywest_iface *iface, reg_t reg, u8 val)
97 {
98 out_8(iface->base
99 + (((unsigned)reg) << iface->bsteps), val);
100 (void)__read_reg(iface, reg_subaddr);
101 }
102
103 #define write_reg(reg, val) __write_reg(iface, reg, val)
104 #define read_reg(reg) __read_reg(iface, reg)
105
106
107
108 #endif /* __I2C_KEYWEST_H__ */