mfd: Add irq support in 88pm860x
[safe/jmp/linux-2.6] / include / linux / mfd / 88pm860x.h
1 /*
2  * Marvell 88PM860x Interface
3  *
4  * Copyright (C) 2009 Marvell International Ltd.
5  *      Haojian Zhuang <haojian.zhuang@marvell.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #ifndef __LINUX_MFD_88PM860X_H
13 #define __LINUX_MFD_88PM860X_H
14
15 #include <linux/interrupt.h>
16
17 enum {
18         CHIP_INVALID = 0,
19         CHIP_PM8606,
20         CHIP_PM8607,
21         CHIP_MAX,
22 };
23
24 enum {
25         PM8607_ID_BUCK1 = 0,
26         PM8607_ID_BUCK2,
27         PM8607_ID_BUCK3,
28
29         PM8607_ID_LDO1,
30         PM8607_ID_LDO2,
31         PM8607_ID_LDO3,
32         PM8607_ID_LDO4,
33         PM8607_ID_LDO5,
34         PM8607_ID_LDO6,
35         PM8607_ID_LDO7,
36         PM8607_ID_LDO8,
37         PM8607_ID_LDO9,
38         PM8607_ID_LDO10,
39         PM8607_ID_LDO12,
40         PM8607_ID_LDO14,
41
42         PM8607_ID_RG_MAX,
43 };
44
45 #define PM8607_VERSION                  (0x40)  /* 8607 chip ID */
46 #define PM8607_VERSION_MASK             (0xF0)  /* 8607 chip ID mask */
47
48 /* Interrupt Registers */
49 #define PM8607_STATUS_1                 (0x01)
50 #define PM8607_STATUS_2                 (0x02)
51 #define PM8607_INT_STATUS1              (0x03)
52 #define PM8607_INT_STATUS2              (0x04)
53 #define PM8607_INT_STATUS3              (0x05)
54 #define PM8607_INT_MASK_1               (0x06)
55 #define PM8607_INT_MASK_2               (0x07)
56 #define PM8607_INT_MASK_3               (0x08)
57
58 /* Regulator Control Registers */
59 #define PM8607_LDO1                     (0x10)
60 #define PM8607_LDO2                     (0x11)
61 #define PM8607_LDO3                     (0x12)
62 #define PM8607_LDO4                     (0x13)
63 #define PM8607_LDO5                     (0x14)
64 #define PM8607_LDO6                     (0x15)
65 #define PM8607_LDO7                     (0x16)
66 #define PM8607_LDO8                     (0x17)
67 #define PM8607_LDO9                     (0x18)
68 #define PM8607_LDO10                    (0x19)
69 #define PM8607_LDO12                    (0x1A)
70 #define PM8607_LDO14                    (0x1B)
71 #define PM8607_SLEEP_MODE1              (0x1C)
72 #define PM8607_SLEEP_MODE2              (0x1D)
73 #define PM8607_SLEEP_MODE3              (0x1E)
74 #define PM8607_SLEEP_MODE4              (0x1F)
75 #define PM8607_GO                       (0x20)
76 #define PM8607_SLEEP_BUCK1              (0x21)
77 #define PM8607_SLEEP_BUCK2              (0x22)
78 #define PM8607_SLEEP_BUCK3              (0x23)
79 #define PM8607_BUCK1                    (0x24)
80 #define PM8607_BUCK2                    (0x25)
81 #define PM8607_BUCK3                    (0x26)
82 #define PM8607_BUCK_CONTROLS            (0x27)
83 #define PM8607_SUPPLIES_EN11            (0x2B)
84 #define PM8607_SUPPLIES_EN12            (0x2C)
85 #define PM8607_GROUP1                   (0x2D)
86 #define PM8607_GROUP2                   (0x2E)
87 #define PM8607_GROUP3                   (0x2F)
88 #define PM8607_GROUP4                   (0x30)
89 #define PM8607_GROUP5                   (0x31)
90 #define PM8607_GROUP6                   (0x32)
91 #define PM8607_SUPPLIES_EN21            (0x33)
92 #define PM8607_SUPPLIES_EN22            (0x34)
93
94 /* RTC Control Registers */
95 #define PM8607_RTC1                     (0xA0)
96 #define PM8607_RTC_COUNTER1             (0xA1)
97 #define PM8607_RTC_COUNTER2             (0xA2)
98 #define PM8607_RTC_COUNTER3             (0xA3)
99 #define PM8607_RTC_COUNTER4             (0xA4)
100 #define PM8607_RTC_EXPIRE1              (0xA5)
101 #define PM8607_RTC_EXPIRE2              (0xA6)
102 #define PM8607_RTC_EXPIRE3              (0xA7)
103 #define PM8607_RTC_EXPIRE4              (0xA8)
104 #define PM8607_RTC_TRIM1                (0xA9)
105 #define PM8607_RTC_TRIM2                (0xAA)
106 #define PM8607_RTC_TRIM3                (0xAB)
107 #define PM8607_RTC_TRIM4                (0xAC)
108 #define PM8607_RTC_MISC1                (0xAD)
109 #define PM8607_RTC_MISC2                (0xAE)
110 #define PM8607_RTC_MISC3                (0xAF)
111
112 /* Misc Registers */
113 #define PM8607_CHIP_ID                  (0x00)
114 #define PM8607_B0_MISC1                 (0x0C)
115 #define PM8607_LDO1                     (0x10)
116 #define PM8607_DVC3                     (0x26)
117 #define PM8607_A1_MISC1                 (0x40)
118
119 /* bit definitions of Status Query Interface */
120 #define PM8607_STATUS_CC                (1 << 3)
121 #define PM8607_STATUS_PEN               (1 << 4)
122 #define PM8607_STATUS_HEADSET           (1 << 5)
123 #define PM8607_STATUS_HOOK              (1 << 6)
124 #define PM8607_STATUS_MICIN             (1 << 7)
125 #define PM8607_STATUS_ONKEY             (1 << 8)
126 #define PM8607_STATUS_EXTON             (1 << 9)
127 #define PM8607_STATUS_CHG               (1 << 10)
128 #define PM8607_STATUS_BAT               (1 << 11)
129 #define PM8607_STATUS_VBUS              (1 << 12)
130 #define PM8607_STATUS_OV                (1 << 13)
131
132 /* bit definitions of BUCK3 */
133 #define PM8607_BUCK3_DOUBLE             (1 << 6)
134
135 /* bit definitions of Misc1 */
136 #define PM8607_A1_MISC1_PI2C            (1 << 0)
137 #define PM8607_B0_MISC1_INV_INT         (1 << 0)
138 #define PM8607_B0_MISC1_INT_CLEAR       (1 << 1)
139 #define PM8607_B0_MISC1_INT_MASK        (1 << 2)
140 #define PM8607_B0_MISC1_PI2C            (1 << 3)
141 #define PM8607_B0_MISC1_RESET           (1 << 6)
142
143 /* Interrupt Number in 88PM8607 */
144 enum {
145         PM8607_IRQ_ONKEY = 0,
146         PM8607_IRQ_EXTON,
147         PM8607_IRQ_CHG,
148         PM8607_IRQ_BAT,
149         PM8607_IRQ_RTC,
150         PM8607_IRQ_VBAT = 8,
151         PM8607_IRQ_VCHG,
152         PM8607_IRQ_VSYS,
153         PM8607_IRQ_TINT,
154         PM8607_IRQ_GPADC0,
155         PM8607_IRQ_GPADC1,
156         PM8607_IRQ_GPADC2,
157         PM8607_IRQ_GPADC3,
158         PM8607_IRQ_AUDIO_SHORT = 16,
159         PM8607_IRQ_PEN,
160         PM8607_IRQ_HEADSET,
161         PM8607_IRQ_HOOK,
162         PM8607_IRQ_MICIN,
163         PM8607_IRQ_CHG_FAIL,
164         PM8607_IRQ_CHG_DONE,
165         PM8607_IRQ_CHG_FAULT,
166 };
167
168 enum {
169         PM8607_CHIP_A0 = 0x40,
170         PM8607_CHIP_A1 = 0x41,
171         PM8607_CHIP_B0 = 0x48,
172 };
173
174 #define PM860X_NUM_IRQ          24
175
176 struct pm860x_irq {
177         irq_handler_t           handler;
178         void                    *data;
179 };
180
181 struct pm860x_chip {
182         struct device           *dev;
183         struct mutex            io_lock;
184         struct mutex            irq_lock;
185         struct i2c_client       *client;
186         struct i2c_client       *companion;     /* companion chip client */
187         struct pm860x_irq       irq[PM860X_NUM_IRQ];
188
189         int                     buck3_double;   /* DVC ramp slope double */
190         unsigned short          companion_addr;
191         int                     id;
192         int                     irq_mode;
193         int                     chip_irq;
194         unsigned char           chip_version;
195
196 };
197
198 #define PM8607_MAX_REGULATOR    15      /* 3 Bucks, 12 LDOs */
199
200 enum {
201         GI2C_PORT = 0,
202         PI2C_PORT,
203 };
204
205 struct pm860x_platform_data {
206         unsigned short  companion_addr; /* I2C address of companion chip */
207         int             i2c_port;       /* Controlled by GI2C or PI2C */
208         int             irq_mode;       /* Clear interrupt by read/write(0/1) */
209         struct regulator_init_data *regulator[PM8607_MAX_REGULATOR];
210 };
211
212 extern int pm860x_reg_read(struct i2c_client *, int);
213 extern int pm860x_reg_write(struct i2c_client *, int, unsigned char);
214 extern int pm860x_bulk_read(struct i2c_client *, int, int, unsigned char *);
215 extern int pm860x_bulk_write(struct i2c_client *, int, int, unsigned char *);
216 extern int pm860x_set_bits(struct i2c_client *, int, unsigned char,
217                            unsigned char);
218
219 extern int pm860x_mask_irq(struct pm860x_chip *, int);
220 extern int pm860x_unmask_irq(struct pm860x_chip *, int);
221 extern int pm860x_request_irq(struct pm860x_chip *, int,
222                               irq_handler_t handler, void *);
223 extern int pm860x_free_irq(struct pm860x_chip *, int);
224
225 extern int pm860x_device_init(struct pm860x_chip *chip,
226                               struct pm860x_platform_data *pdata);
227 extern void pm860x_device_exit(struct pm860x_chip *chip);
228
229 #endif /* __LINUX_MFD_88PM860X_H */