Subversion Repositories shark

Rev

Rev 420 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
420 giacomo 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
        unsigned long           base;
55
        unsigned                bsteps;
56
        int                     irq;
57
        struct semaphore        sem;
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
        int                     stopretry;
68
        struct timer_list       timeout_timer;
69
        struct completion       complete;
70
};
71
 
72
enum {
73
        state_idle,
74
        state_addr,
75
        state_read,
76
        state_write,
77
        state_stop,
78
        state_dead
79
};
80
 
81
/* Channel on an interface */
82
struct keywest_chan
83
{
84
        struct i2c_adapter      adapter;
85
        struct keywest_iface*   iface;
86
        unsigned                chan_no;
87
};
88
 
89
/* Register access */
90
 
91
static inline u8 __read_reg(struct keywest_iface *iface, reg_t reg)
92
{
93
        return in_8(((volatile u8 *)iface->base)
94
                + (((unsigned)reg) << iface->bsteps));
95
}
96
 
97
static inline void __write_reg(struct keywest_iface *iface, reg_t reg, u8 val)
98
{
99
        out_8(((volatile u8 *)iface->base)
100
                + (((unsigned)reg) << iface->bsteps), val);
101
        (void)__read_reg(iface, reg);
102
        udelay(10);
103
}
104
 
105
#define write_reg(reg, val)     __write_reg(iface, reg, val) 
106
#define read_reg(reg)           __read_reg(iface, reg) 
107
 
108
 
109
 
110
#endif /* __I2C_KEYWEST_H__ */