1
2
3
4
5
6
7
8
9#ifndef __ASM_BFIN_TWI_H__
10#define __ASM_BFIN_TWI_H__
11
12#include <linux/types.h>
13#include <linux/i2c.h>
14
15
16
17
18
19#define __BFP(m) u16 m; u16 __pad_##m
20
21
22
23
24struct bfin_twi_regs {
25 __BFP(clkdiv);
26 __BFP(control);
27 __BFP(slave_ctl);
28 __BFP(slave_stat);
29 __BFP(slave_addr);
30 __BFP(master_ctl);
31 __BFP(master_stat);
32 __BFP(master_addr);
33 __BFP(int_stat);
34 __BFP(int_mask);
35 __BFP(fifo_ctl);
36 __BFP(fifo_stat);
37 u32 __pad[20];
38 __BFP(xmt_data8);
39 __BFP(xmt_data16);
40 __BFP(rcv_data8);
41 __BFP(rcv_data16);
42};
43
44#undef __BFP
45
46struct bfin_twi_iface {
47 int irq;
48 spinlock_t lock;
49 char read_write;
50 u8 command;
51 u8 *transPtr;
52 int readNum;
53 int writeNum;
54 int cur_mode;
55 int manual_stop;
56 int result;
57 struct i2c_adapter adap;
58 struct completion complete;
59 struct i2c_msg *pmsg;
60 int msg_num;
61 int cur_msg;
62 u16 saved_clkdiv;
63 u16 saved_control;
64 struct bfin_twi_regs __iomem *regs_base;
65};
66
67#define DEFINE_TWI_REG(reg_name, reg) \
68static inline u16 read_##reg_name(struct bfin_twi_iface *iface) \
69 { return bfin_read16(&iface->regs_base->reg); } \
70static inline void write_##reg_name(struct bfin_twi_iface *iface, u16 v) \
71 { bfin_write16(&iface->regs_base->reg, v); }
72
73DEFINE_TWI_REG(CLKDIV, clkdiv)
74DEFINE_TWI_REG(CONTROL, control)
75DEFINE_TWI_REG(SLAVE_CTL, slave_ctl)
76DEFINE_TWI_REG(SLAVE_STAT, slave_stat)
77DEFINE_TWI_REG(SLAVE_ADDR, slave_addr)
78DEFINE_TWI_REG(MASTER_CTL, master_ctl)
79DEFINE_TWI_REG(MASTER_STAT, master_stat)
80DEFINE_TWI_REG(MASTER_ADDR, master_addr)
81DEFINE_TWI_REG(INT_STAT, int_stat)
82DEFINE_TWI_REG(INT_MASK, int_mask)
83DEFINE_TWI_REG(FIFO_CTL, fifo_ctl)
84DEFINE_TWI_REG(FIFO_STAT, fifo_stat)
85DEFINE_TWI_REG(XMT_DATA8, xmt_data8)
86DEFINE_TWI_REG(XMT_DATA16, xmt_data16)
87#if !ANOMALY_16000030
88DEFINE_TWI_REG(RCV_DATA8, rcv_data8)
89DEFINE_TWI_REG(RCV_DATA16, rcv_data16)
90#else
91static inline u16 read_RCV_DATA8(struct bfin_twi_iface *iface)
92{
93 u16 ret;
94 unsigned long flags;
95
96 flags = hard_local_irq_save();
97 ret = bfin_read16(&iface->regs_base->rcv_data8);
98 hard_local_irq_restore(flags);
99
100 return ret;
101}
102
103static inline u16 read_RCV_DATA16(struct bfin_twi_iface *iface)
104{
105 u16 ret;
106 unsigned long flags;
107
108 flags = hard_local_irq_save();
109 ret = bfin_read16(&iface->regs_base->rcv_data16);
110 hard_local_irq_restore(flags);
111
112 return ret;
113}
114#endif
115
116
117
118
119#define CLKLOW(x) ((x) & 0xFF)
120#define CLKHI(y) (((y)&0xFF)<<0x8)
121
122
123#define PRESCALE 0x007F
124#define TWI_ENA 0x0080
125#define SCCB 0x0200
126
127
128#define SEN 0x0001
129#define SADD_LEN 0x0002
130#define STDVAL 0x0004
131#define NAK 0x0008
132#define GEN 0x0010
133
134
135#define SDIR 0x0001
136#define GCALL 0x0002
137
138
139#define MEN 0x0001
140#define MADD_LEN 0x0002
141#define MDIR 0x0004
142#define FAST 0x0008
143#define STOP 0x0010
144#define RSTART 0x0020
145#define DCNT 0x3FC0
146#define SDAOVR 0x4000
147#define SCLOVR 0x8000
148
149
150#define MPROG 0x0001
151#define LOSTARB 0x0002
152#define ANAK 0x0004
153#define DNAK 0x0008
154#define BUFRDERR 0x0010
155#define BUFWRERR 0x0020
156#define SDASEN 0x0040
157#define SCLSEN 0x0080
158#define BUSBUSY 0x0100
159
160
161#define SINIT 0x0001
162#define SCOMP 0x0002
163#define SERR 0x0004
164#define SOVF 0x0008
165#define MCOMP 0x0010
166#define MERR 0x0020
167#define XMTSERV 0x0040
168#define RCVSERV 0x0080
169
170
171#define XMTFLUSH 0x0001
172#define RCVFLUSH 0x0002
173#define XMTINTLEN 0x0004
174#define RCVINTLEN 0x0008
175
176
177#define XMTSTAT 0x0003
178#define XMT_EMPTY 0x0000
179#define XMT_HALF 0x0001
180#define XMT_FULL 0x0003
181
182#define RCVSTAT 0x000C
183#define RCV_EMPTY 0x0000
184#define RCV_HALF 0x0004
185#define RCV_FULL 0x000C
186
187#endif
188