diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-05 22:04:09 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-05 22:04:09 -0500 |
commit | 8e128ce3318a147903c893de1891f6c2306f8a61 (patch) | |
tree | 3b45e780570e9beb9ec8e83c677f2d9fd9b458ce /drivers/i2c | |
parent | 0bbb2753584231db364b624bf8cf82551b94da7d (diff) | |
parent | 3f874b6643e189d3d07618928ceed0013d71593e (diff) |
Merge branch 'for-next' of git://git.o-hand.com/linux-mfd
* 'for-next' of git://git.o-hand.com/linux-mfd: (30 commits)
mfd: Fix section mismatch in da903x
mfd: move drivers/i2c/chips/menelaus.c to drivers/mfd
mfd: move drivers/i2c/chips/tps65010.c to drivers/mfd
mfd: dm355evm msp430 driver
mfd: Add missing break from wm3850-core
mfd: Add WM8351 support
mfd: Support configurable numbers of DCDCs and ISINKs on WM8350
mfd: Handle missing WM8350 platform data
mfd: Add WM8352 support
mfd: Use irq_to_desc in twl4030 code
power_supply: Add Dialog DA9030 battery charger driver
mfd: Dialog DA9030 battery charger MFD driver
mfd: Register WM8400 codec device
mfd: Pass driver_data onto child devices
mfd: Fix twl4030-core.c build error
mfd: twl4030 regulator bug fixes
mfd: twl4030: create some regulator devices
mfd: twl4030: cleanup symbols and OMAP dependency
mfd: twl4030: simplified child creation code
power_supply: Add battery health reporting for WM8350
...
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/chips/Kconfig | 23 | ||||
-rw-r--r-- | drivers/i2c/chips/Makefile | 2 | ||||
-rw-r--r-- | drivers/i2c/chips/menelaus.c | 1285 | ||||
-rw-r--r-- | drivers/i2c/chips/tps65010.c | 1072 |
4 files changed, 0 insertions, 2382 deletions
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig index 4c35702830ce..864ac561fdbb 100644 --- a/drivers/i2c/chips/Kconfig +++ b/drivers/i2c/chips/Kconfig | |||
@@ -126,19 +126,6 @@ config ISP1301_OMAP | |||
126 | This driver can also be built as a module. If so, the module | 126 | This driver can also be built as a module. If so, the module |
127 | will be called isp1301_omap. | 127 | will be called isp1301_omap. |
128 | 128 | ||
129 | config TPS65010 | ||
130 | tristate "TPS6501x Power Management chips" | ||
131 | depends on GPIOLIB | ||
132 | default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK | ||
133 | help | ||
134 | If you say yes here you get support for the TPS6501x series of | ||
135 | Power Management chips. These include voltage regulators, | ||
136 | lithium ion/polymer battery charging, and other features that | ||
137 | are often used in portable devices like cell phones and cameras. | ||
138 | |||
139 | This driver can also be built as a module. If so, the module | ||
140 | will be called tps65010. | ||
141 | |||
142 | config SENSORS_MAX6875 | 129 | config SENSORS_MAX6875 |
143 | tristate "Maxim MAX6875 Power supply supervisor" | 130 | tristate "Maxim MAX6875 Power supply supervisor" |
144 | depends on EXPERIMENTAL | 131 | depends on EXPERIMENTAL |
@@ -164,16 +151,6 @@ config SENSORS_TSL2550 | |||
164 | This driver can also be built as a module. If so, the module | 151 | This driver can also be built as a module. If so, the module |
165 | will be called tsl2550. | 152 | will be called tsl2550. |
166 | 153 | ||
167 | config MENELAUS | ||
168 | bool "TWL92330/Menelaus PM chip" | ||
169 | depends on I2C=y && ARCH_OMAP24XX | ||
170 | help | ||
171 | If you say yes here you get support for the Texas Instruments | ||
172 | TWL92330/Menelaus Power Management chip. This include voltage | ||
173 | regulators, Dual slot memory card tranceivers, real-time clock | ||
174 | and other features that are often used in portable devices like | ||
175 | cell phones and PDAs. | ||
176 | |||
177 | config MCU_MPC8349EMITX | 154 | config MCU_MPC8349EMITX |
178 | tristate "MPC8349E-mITX MCU driver" | 155 | tristate "MPC8349E-mITX MCU driver" |
179 | depends on I2C && PPC_83xx | 156 | depends on I2C && PPC_83xx |
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile index 23d2a31b0a64..8b95f41a5001 100644 --- a/drivers/i2c/chips/Makefile +++ b/drivers/i2c/chips/Makefile | |||
@@ -19,8 +19,6 @@ obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o | |||
19 | obj-$(CONFIG_PCF8575) += pcf8575.o | 19 | obj-$(CONFIG_PCF8575) += pcf8575.o |
20 | obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o | 20 | obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o |
21 | obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o | 21 | obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o |
22 | obj-$(CONFIG_TPS65010) += tps65010.o | ||
23 | obj-$(CONFIG_MENELAUS) += menelaus.o | ||
24 | obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o | 22 | obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o |
25 | obj-$(CONFIG_MCU_MPC8349EMITX) += mcu_mpc8349emitx.o | 23 | obj-$(CONFIG_MCU_MPC8349EMITX) += mcu_mpc8349emitx.o |
26 | 24 | ||
diff --git a/drivers/i2c/chips/menelaus.c b/drivers/i2c/chips/menelaus.c deleted file mode 100644 index 4b364bae6b3e..000000000000 --- a/drivers/i2c/chips/menelaus.c +++ /dev/null | |||
@@ -1,1285 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2004 Texas Instruments, Inc. | ||
3 | * | ||
4 | * Some parts based tps65010.c: | ||
5 | * Copyright (C) 2004 Texas Instruments and | ||
6 | * Copyright (C) 2004-2005 David Brownell | ||
7 | * | ||
8 | * Some parts based on tlv320aic24.c: | ||
9 | * Copyright (C) by Kai Svahn <kai.svahn@nokia.com> | ||
10 | * | ||
11 | * Changes for interrupt handling and clean-up by | ||
12 | * Tony Lindgren <tony@atomide.com> and Imre Deak <imre.deak@nokia.com> | ||
13 | * Cleanup and generalized support for voltage setting by | ||
14 | * Juha Yrjola | ||
15 | * Added support for controlling VCORE and regulator sleep states, | ||
16 | * Amit Kucheria <amit.kucheria@nokia.com> | ||
17 | * Copyright (C) 2005, 2006 Nokia Corporation | ||
18 | * | ||
19 | * This program is free software; you can redistribute it and/or modify | ||
20 | * it under the terms of the GNU General Public License as published by | ||
21 | * the Free Software Foundation; either version 2 of the License, or | ||
22 | * (at your option) any later version. | ||
23 | * | ||
24 | * This program is distributed in the hope that it will be useful, | ||
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
27 | * GNU General Public License for more details. | ||
28 | * | ||
29 | * You should have received a copy of the GNU General Public License | ||
30 | * along with this program; if not, write to the Free Software | ||
31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
32 | */ | ||
33 | |||
34 | #include <linux/module.h> | ||
35 | #include <linux/i2c.h> | ||
36 | #include <linux/interrupt.h> | ||
37 | #include <linux/sched.h> | ||
38 | #include <linux/mutex.h> | ||
39 | #include <linux/workqueue.h> | ||
40 | #include <linux/delay.h> | ||
41 | #include <linux/rtc.h> | ||
42 | #include <linux/bcd.h> | ||
43 | |||
44 | #include <asm/mach/irq.h> | ||
45 | |||
46 | #include <mach/gpio.h> | ||
47 | #include <mach/menelaus.h> | ||
48 | |||
49 | #define DRIVER_NAME "menelaus" | ||
50 | |||
51 | #define MENELAUS_I2C_ADDRESS 0x72 | ||
52 | |||
53 | #define MENELAUS_REV 0x01 | ||
54 | #define MENELAUS_VCORE_CTRL1 0x02 | ||
55 | #define MENELAUS_VCORE_CTRL2 0x03 | ||
56 | #define MENELAUS_VCORE_CTRL3 0x04 | ||
57 | #define MENELAUS_VCORE_CTRL4 0x05 | ||
58 | #define MENELAUS_VCORE_CTRL5 0x06 | ||
59 | #define MENELAUS_DCDC_CTRL1 0x07 | ||
60 | #define MENELAUS_DCDC_CTRL2 0x08 | ||
61 | #define MENELAUS_DCDC_CTRL3 0x09 | ||
62 | #define MENELAUS_LDO_CTRL1 0x0A | ||
63 | #define MENELAUS_LDO_CTRL2 0x0B | ||
64 | #define MENELAUS_LDO_CTRL3 0x0C | ||
65 | #define MENELAUS_LDO_CTRL4 0x0D | ||
66 | #define MENELAUS_LDO_CTRL5 0x0E | ||
67 | #define MENELAUS_LDO_CTRL6 0x0F | ||
68 | #define MENELAUS_LDO_CTRL7 0x10 | ||
69 | #define MENELAUS_LDO_CTRL8 0x11 | ||
70 | #define MENELAUS_SLEEP_CTRL1 0x12 | ||
71 | #define MENELAUS_SLEEP_CTRL2 0x13 | ||
72 | #define MENELAUS_DEVICE_OFF 0x14 | ||
73 | #define MENELAUS_OSC_CTRL 0x15 | ||
74 | #define MENELAUS_DETECT_CTRL 0x16 | ||
75 | #define MENELAUS_INT_MASK1 0x17 | ||
76 | #define MENELAUS_INT_MASK2 0x18 | ||
77 | #define MENELAUS_INT_STATUS1 0x19 | ||
78 | #define MENELAUS_INT_STATUS2 0x1A | ||
79 | #define MENELAUS_INT_ACK1 0x1B | ||
80 | #define MENELAUS_INT_ACK2 0x1C | ||
81 | #define MENELAUS_GPIO_CTRL 0x1D | ||
82 | #define MENELAUS_GPIO_IN 0x1E | ||
83 | #define MENELAUS_GPIO_OUT 0x1F | ||
84 | #define MENELAUS_BBSMS 0x20 | ||
85 | #define MENELAUS_RTC_CTRL 0x21 | ||
86 | #define MENELAUS_RTC_UPDATE 0x22 | ||
87 | #define MENELAUS_RTC_SEC 0x23 | ||
88 | #define MENELAUS_RTC_MIN 0x24 | ||
89 | #define MENELAUS_RTC_HR 0x25 | ||
90 | #define MENELAUS_RTC_DAY 0x26 | ||
91 | #define MENELAUS_RTC_MON 0x27 | ||
92 | #define MENELAUS_RTC_YR 0x28 | ||
93 | #define MENELAUS_RTC_WKDAY 0x29 | ||
94 | #define MENELAUS_RTC_AL_SEC 0x2A | ||
95 | #define MENELAUS_RTC_AL_MIN 0x2B | ||
96 | #define MENELAUS_RTC_AL_HR 0x2C | ||
97 | #define MENELAUS_RTC_AL_DAY 0x2D | ||
98 | #define MENELAUS_RTC_AL_MON 0x2E | ||
99 | #define MENELAUS_RTC_AL_YR 0x2F | ||
100 | #define MENELAUS_RTC_COMP_MSB 0x30 | ||
101 | #define MENELAUS_RTC_COMP_LSB 0x31 | ||
102 | #define MENELAUS_S1_PULL_EN 0x32 | ||
103 | #define MENELAUS_S1_PULL_DIR 0x33 | ||
104 | #define MENELAUS_S2_PULL_EN 0x34 | ||
105 | #define MENELAUS_S2_PULL_DIR 0x35 | ||
106 | #define MENELAUS_MCT_CTRL1 0x36 | ||
107 | #define MENELAUS_MCT_CTRL2 0x37 | ||
108 | #define MENELAUS_MCT_CTRL3 0x38 | ||
109 | #define MENELAUS_MCT_PIN_ST 0x39 | ||
110 | #define MENELAUS_DEBOUNCE1 0x3A | ||
111 | |||
112 | #define IH_MENELAUS_IRQS 12 | ||
113 | #define MENELAUS_MMC_S1CD_IRQ 0 /* MMC slot 1 card change */ | ||
114 | #define MENELAUS_MMC_S2CD_IRQ 1 /* MMC slot 2 card change */ | ||
115 | #define MENELAUS_MMC_S1D1_IRQ 2 /* MMC DAT1 low in slot 1 */ | ||
116 | #define MENELAUS_MMC_S2D1_IRQ 3 /* MMC DAT1 low in slot 2 */ | ||
117 | #define MENELAUS_LOWBAT_IRQ 4 /* Low battery */ | ||
118 | #define MENELAUS_HOTDIE_IRQ 5 /* Hot die detect */ | ||
119 | #define MENELAUS_UVLO_IRQ 6 /* UVLO detect */ | ||
120 | #define MENELAUS_TSHUT_IRQ 7 /* Thermal shutdown */ | ||
121 | #define MENELAUS_RTCTMR_IRQ 8 /* RTC timer */ | ||
122 | #define MENELAUS_RTCALM_IRQ 9 /* RTC alarm */ | ||
123 | #define MENELAUS_RTCERR_IRQ 10 /* RTC error */ | ||
124 | #define MENELAUS_PSHBTN_IRQ 11 /* Push button */ | ||
125 | #define MENELAUS_RESERVED12_IRQ 12 /* Reserved */ | ||
126 | #define MENELAUS_RESERVED13_IRQ 13 /* Reserved */ | ||
127 | #define MENELAUS_RESERVED14_IRQ 14 /* Reserved */ | ||
128 | #define MENELAUS_RESERVED15_IRQ 15 /* Reserved */ | ||
129 | |||
130 | static void menelaus_work(struct work_struct *_menelaus); | ||
131 | |||
132 | struct menelaus_chip { | ||
133 | struct mutex lock; | ||
134 | struct i2c_client *client; | ||
135 | struct work_struct work; | ||
136 | #ifdef CONFIG_RTC_DRV_TWL92330 | ||
137 | struct rtc_device *rtc; | ||
138 | u8 rtc_control; | ||
139 | unsigned uie:1; | ||
140 | #endif | ||
141 | unsigned vcore_hw_mode:1; | ||
142 | u8 mask1, mask2; | ||
143 | void (*handlers[16])(struct menelaus_chip *); | ||
144 | void (*mmc_callback)(void *data, u8 mask); | ||
145 | void *mmc_callback_data; | ||
146 | }; | ||
147 | |||
148 | static struct menelaus_chip *the_menelaus; | ||
149 | |||
150 | static int menelaus_write_reg(int reg, u8 value) | ||
151 | { | ||
152 | int val = i2c_smbus_write_byte_data(the_menelaus->client, reg, value); | ||
153 | |||
154 | if (val < 0) { | ||
155 | pr_err(DRIVER_NAME ": write error"); | ||
156 | return val; | ||
157 | } | ||
158 | |||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | static int menelaus_read_reg(int reg) | ||
163 | { | ||
164 | int val = i2c_smbus_read_byte_data(the_menelaus->client, reg); | ||
165 | |||
166 | if (val < 0) | ||
167 | pr_err(DRIVER_NAME ": read error"); | ||
168 | |||
169 | return val; | ||
170 | } | ||
171 | |||
172 | static int menelaus_enable_irq(int irq) | ||
173 | { | ||
174 | if (irq > 7) { | ||
175 | irq -= 8; | ||
176 | the_menelaus->mask2 &= ~(1 << irq); | ||
177 | return menelaus_write_reg(MENELAUS_INT_MASK2, | ||
178 | the_menelaus->mask2); | ||
179 | } else { | ||
180 | the_menelaus->mask1 &= ~(1 << irq); | ||
181 | return menelaus_write_reg(MENELAUS_INT_MASK1, | ||
182 | the_menelaus->mask1); | ||
183 | } | ||
184 | } | ||
185 | |||
186 | static int menelaus_disable_irq(int irq) | ||
187 | { | ||
188 | if (irq > 7) { | ||
189 | irq -= 8; | ||
190 | the_menelaus->mask2 |= (1 << irq); | ||
191 | return menelaus_write_reg(MENELAUS_INT_MASK2, | ||
192 | the_menelaus->mask2); | ||
193 | } else { | ||
194 | the_menelaus->mask1 |= (1 << irq); | ||
195 | return menelaus_write_reg(MENELAUS_INT_MASK1, | ||
196 | the_menelaus->mask1); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | static int menelaus_ack_irq(int irq) | ||
201 | { | ||
202 | if (irq > 7) | ||
203 | return menelaus_write_reg(MENELAUS_INT_ACK2, 1 << (irq - 8)); | ||
204 | else | ||
205 | return menelaus_write_reg(MENELAUS_INT_ACK1, 1 << irq); | ||
206 | } | ||
207 | |||
208 | /* Adds a handler for an interrupt. Does not run in interrupt context */ | ||
209 | static int menelaus_add_irq_work(int irq, | ||
210 | void (*handler)(struct menelaus_chip *)) | ||
211 | { | ||
212 | int ret = 0; | ||
213 | |||
214 | mutex_lock(&the_menelaus->lock); | ||
215 | the_menelaus->handlers[irq] = handler; | ||
216 | ret = menelaus_enable_irq(irq); | ||
217 | mutex_unlock(&the_menelaus->lock); | ||
218 | |||
219 | return ret; | ||
220 | } | ||
221 | |||
222 | /* Removes handler for an interrupt */ | ||
223 | static int menelaus_remove_irq_work(int irq) | ||
224 | { | ||
225 | int ret = 0; | ||
226 | |||
227 | mutex_lock(&the_menelaus->lock); | ||
228 | ret = menelaus_disable_irq(irq); | ||
229 | the_menelaus->handlers[irq] = NULL; | ||
230 | mutex_unlock(&the_menelaus->lock); | ||
231 | |||
232 | return ret; | ||
233 | } | ||
234 | |||
235 | /* | ||
236 | * Gets scheduled when a card detect interrupt happens. Note that in some cases | ||
237 | * this line is wired to card cover switch rather than the card detect switch | ||
238 | * in each slot. In this case the cards are not seen by menelaus. | ||
239 | * FIXME: Add handling for D1 too | ||
240 | */ | ||
241 | static void menelaus_mmc_cd_work(struct menelaus_chip *menelaus_hw) | ||
242 | { | ||
243 | int reg; | ||
244 | unsigned char card_mask = 0; | ||
245 | |||
246 | reg = menelaus_read_reg(MENELAUS_MCT_PIN_ST); | ||
247 | if (reg < 0) | ||
248 | return; | ||
249 | |||
250 | if (!(reg & 0x1)) | ||
251 | card_mask |= (1 << 0); | ||
252 | |||
253 | if (!(reg & 0x2)) | ||
254 | card_mask |= (1 << 1); | ||
255 | |||
256 | if (menelaus_hw->mmc_callback) | ||
257 | menelaus_hw->mmc_callback(menelaus_hw->mmc_callback_data, | ||
258 | card_mask); | ||
259 | } | ||
260 | |||
261 | /* | ||
262 | * Toggles the MMC slots between open-drain and push-pull mode. | ||
263 | */ | ||
264 | int menelaus_set_mmc_opendrain(int slot, int enable) | ||
265 | { | ||
266 | int ret, val; | ||
267 | |||
268 | if (slot != 1 && slot != 2) | ||
269 | return -EINVAL; | ||
270 | mutex_lock(&the_menelaus->lock); | ||
271 | ret = menelaus_read_reg(MENELAUS_MCT_CTRL1); | ||
272 | if (ret < 0) { | ||
273 | mutex_unlock(&the_menelaus->lock); | ||
274 | return ret; | ||
275 | } | ||
276 | val = ret; | ||
277 | if (slot == 1) { | ||
278 | if (enable) | ||
279 | val |= 1 << 2; | ||
280 | else | ||
281 | val &= ~(1 << 2); | ||
282 | } else { | ||
283 | if (enable) | ||
284 | val |= 1 << 3; | ||
285 | else | ||
286 | val &= ~(1 << 3); | ||
287 | } | ||
288 | ret = menelaus_write_reg(MENELAUS_MCT_CTRL1, val); | ||
289 | mutex_unlock(&the_menelaus->lock); | ||
290 | |||
291 | return ret; | ||
292 | } | ||
293 | EXPORT_SYMBOL(menelaus_set_mmc_opendrain); | ||
294 | |||
295 | int menelaus_set_slot_sel(int enable) | ||
296 | { | ||
297 | int ret; | ||
298 | |||
299 | mutex_lock(&the_menelaus->lock); | ||
300 | ret = menelaus_read_reg(MENELAUS_GPIO_CTRL); | ||
301 | if (ret < 0) | ||
302 | goto out; | ||
303 | ret |= 0x02; | ||
304 | if (enable) | ||
305 | ret |= 1 << 5; | ||
306 | else | ||
307 | ret &= ~(1 << 5); | ||
308 | ret = menelaus_write_reg(MENELAUS_GPIO_CTRL, ret); | ||
309 | out: | ||
310 | mutex_unlock(&the_menelaus->lock); | ||
311 | return ret; | ||
312 | } | ||
313 | EXPORT_SYMBOL(menelaus_set_slot_sel); | ||
314 | |||
315 | int menelaus_set_mmc_slot(int slot, int enable, int power, int cd_en) | ||
316 | { | ||
317 | int ret, val; | ||
318 | |||
319 | if (slot != 1 && slot != 2) | ||
320 | return -EINVAL; | ||
321 | if (power >= 3) | ||
322 | return -EINVAL; | ||
323 | |||
324 | mutex_lock(&the_menelaus->lock); | ||
325 | |||
326 | ret = menelaus_read_reg(MENELAUS_MCT_CTRL2); | ||
327 | if (ret < 0) | ||
328 | goto out; | ||
329 | val = ret; | ||
330 | if (slot == 1) { | ||
331 | if (cd_en) | ||
332 | val |= (1 << 4) | (1 << 6); | ||
333 | else | ||
334 | val &= ~((1 << 4) | (1 << 6)); | ||
335 | } else { | ||
336 | if (cd_en) | ||
337 | val |= (1 << 5) | (1 << 7); | ||
338 | else | ||
339 | val &= ~((1 << 5) | (1 << 7)); | ||
340 | } | ||
341 | ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, val); | ||
342 | if (ret < 0) | ||
343 | goto out; | ||
344 | |||
345 | ret = menelaus_read_reg(MENELAUS_MCT_CTRL3); | ||
346 | if (ret < 0) | ||
347 | goto out; | ||
348 | val = ret; | ||
349 | if (slot == 1) { | ||
350 | if (enable) | ||
351 | val |= 1 << 0; | ||
352 | else | ||
353 | val &= ~(1 << 0); | ||
354 | } else { | ||
355 | int b; | ||
356 | |||
357 | if (enable) | ||
358 | ret |= 1 << 1; | ||
359 | else | ||
360 | ret &= ~(1 << 1); | ||
361 | b = menelaus_read_reg(MENELAUS_MCT_CTRL2); | ||
362 | b &= ~0x03; | ||
363 | b |= power; | ||
364 | ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, b); | ||
365 | if (ret < 0) | ||
366 | goto out; | ||
367 | } | ||
368 | /* Disable autonomous shutdown */ | ||
369 | val &= ~(0x03 << 2); | ||
370 | ret = menelaus_write_reg(MENELAUS_MCT_CTRL3, val); | ||
371 | out: | ||
372 | mutex_unlock(&the_menelaus->lock); | ||
373 | return ret; | ||
374 | } | ||
375 | EXPORT_SYMBOL(menelaus_set_mmc_slot); | ||
376 | |||
377 | int menelaus_register_mmc_callback(void (*callback)(void *data, u8 card_mask), | ||
378 | void *data) | ||
379 | { | ||
380 | int ret = 0; | ||
381 | |||
382 | the_menelaus->mmc_callback_data = data; | ||
383 | the_menelaus->mmc_callback = callback; | ||
384 | ret = menelaus_add_irq_work(MENELAUS_MMC_S1CD_IRQ, | ||
385 | menelaus_mmc_cd_work); | ||
386 | if (ret < 0) | ||
387 | return ret; | ||
388 | ret = menelaus_add_irq_work(MENELAUS_MMC_S2CD_IRQ, | ||
389 | menelaus_mmc_cd_work); | ||
390 | if (ret < 0) | ||
391 | return ret; | ||
392 | ret = menelaus_add_irq_work(MENELAUS_MMC_S1D1_IRQ, | ||
393 | menelaus_mmc_cd_work); | ||
394 | if (ret < 0) | ||
395 | return ret; | ||
396 | ret = menelaus_add_irq_work(MENELAUS_MMC_S2D1_IRQ, | ||
397 | menelaus_mmc_cd_work); | ||
398 | |||
399 | return ret; | ||
400 | } | ||
401 | EXPORT_SYMBOL(menelaus_register_mmc_callback); | ||
402 | |||
403 | void menelaus_unregister_mmc_callback(void) | ||
404 | { | ||
405 | menelaus_remove_irq_work(MENELAUS_MMC_S1CD_IRQ); | ||
406 | menelaus_remove_irq_work(MENELAUS_MMC_S2CD_IRQ); | ||
407 | menelaus_remove_irq_work(MENELAUS_MMC_S1D1_IRQ); | ||
408 | menelaus_remove_irq_work(MENELAUS_MMC_S2D1_IRQ); | ||
409 | |||
410 | the_menelaus->mmc_callback = NULL; | ||
411 | the_menelaus->mmc_callback_data = 0; | ||
412 | } | ||
413 | EXPORT_SYMBOL(menelaus_unregister_mmc_callback); | ||
414 | |||
415 | struct menelaus_vtg { | ||
416 | const char *name; | ||
417 | u8 vtg_reg; | ||
418 | u8 vtg_shift; | ||
419 | u8 vtg_bits; | ||
420 | u8 mode_reg; | ||
421 | }; | ||
422 | |||
423 | struct menelaus_vtg_value { | ||
424 | u16 vtg; | ||
425 | u16 val; | ||
426 | }; | ||
427 | |||
428 | static int menelaus_set_voltage(const struct menelaus_vtg *vtg, int mV, | ||
429 | int vtg_val, int mode) | ||
430 | { | ||
431 | int val, ret; | ||
432 | struct i2c_client *c = the_menelaus->client; | ||
433 | |||
434 | mutex_lock(&the_menelaus->lock); | ||
435 | if (vtg == 0) | ||
436 | goto set_voltage; | ||
437 | |||
438 | ret = menelaus_read_reg(vtg->vtg_reg); | ||
439 | if (ret < 0) | ||
440 | goto out; | ||
441 | val = ret & ~(((1 << vtg->vtg_bits) - 1) << vtg->vtg_shift); | ||
442 | val |= vtg_val << vtg->vtg_shift; | ||
443 | |||
444 | dev_dbg(&c->dev, "Setting voltage '%s'" | ||
445 | "to %d mV (reg 0x%02x, val 0x%02x)\n", | ||
446 | vtg->name, mV, vtg->vtg_reg, val); | ||
447 | |||
448 | ret = menelaus_write_reg(vtg->vtg_reg, val); | ||
449 | if (ret < 0) | ||
450 | goto out; | ||
451 | set_voltage: | ||
452 | ret = menelaus_write_reg(vtg->mode_reg, mode); | ||
453 | out: | ||
454 | mutex_unlock(&the_menelaus->lock); | ||
455 | if (ret == 0) { | ||
456 | /* Wait for voltage to stabilize */ | ||
457 | msleep(1); | ||
458 | } | ||
459 | return ret; | ||
460 | } | ||
461 | |||
462 | static int menelaus_get_vtg_value(int vtg, const struct menelaus_vtg_value *tbl, | ||
463 | int n) | ||
464 | { | ||
465 | int i; | ||
466 | |||
467 | for (i = 0; i < n; i++, tbl++) | ||
468 | if (tbl->vtg == vtg) | ||
469 | return tbl->val; | ||
470 | return -EINVAL; | ||
471 | } | ||
472 | |||
473 | /* | ||
474 | * Vcore can be programmed in two ways: | ||
475 | * SW-controlled: Required voltage is programmed into VCORE_CTRL1 | ||
476 | * HW-controlled: Required range (roof-floor) is programmed into VCORE_CTRL3 | ||
477 | * and VCORE_CTRL4 | ||
478 | * | ||
479 | * Call correct 'set' function accordingly | ||
480 | */ | ||
481 | |||
482 | static const struct menelaus_vtg_value vcore_values[] = { | ||
483 | { 1000, 0 }, | ||
484 | { 1025, 1 }, | ||
485 | { 1050, 2 }, | ||
486 | { 1075, 3 }, | ||
487 | { 1100, 4 }, | ||
488 | { 1125, 5 }, | ||
489 | { 1150, 6 }, | ||
490 | { 1175, 7 }, | ||
491 | { 1200, 8 }, | ||
492 | { 1225, 9 }, | ||
493 | { 1250, 10 }, | ||
494 | { 1275, 11 }, | ||
495 | { 1300, 12 }, | ||
496 | { 1325, 13 }, | ||
497 | { 1350, 14 }, | ||
498 | { 1375, 15 }, | ||
499 | { 1400, 16 }, | ||
500 | { 1425, 17 }, | ||
501 | { 1450, 18 }, | ||
502 | }; | ||
503 | |||
504 | int menelaus_set_vcore_sw(unsigned int mV) | ||
505 | { | ||
506 | int val, ret; | ||
507 | struct i2c_client *c = the_menelaus->client; | ||
508 | |||
509 | val = menelaus_get_vtg_value(mV, vcore_values, | ||
510 | ARRAY_SIZE(vcore_values)); | ||
511 | if (val < 0) | ||
512 | return -EINVAL; | ||
513 | |||
514 | dev_dbg(&c->dev, "Setting VCORE to %d mV (val 0x%02x)\n", mV, val); | ||
515 | |||
516 | /* Set SW mode and the voltage in one go. */ | ||
517 | mutex_lock(&the_menelaus->lock); | ||
518 | ret = menelaus_write_reg(MENELAUS_VCORE_CTRL1, val); | ||
519 | if (ret == 0) | ||
520 | the_menelaus->vcore_hw_mode = 0; | ||
521 | mutex_unlock(&the_menelaus->lock); | ||
522 | msleep(1); | ||
523 | |||
524 | return ret; | ||
525 | } | ||
526 | |||
527 | int menelaus_set_vcore_hw(unsigned int roof_mV, unsigned int floor_mV) | ||
528 | { | ||
529 | int fval, rval, val, ret; | ||
530 | struct i2c_client *c = the_menelaus->client; | ||
531 | |||
532 | rval = menelaus_get_vtg_value(roof_mV, vcore_values, | ||
533 | ARRAY_SIZE(vcore_values)); | ||
534 | if (rval < 0) | ||
535 | return -EINVAL; | ||
536 | fval = menelaus_get_vtg_value(floor_mV, vcore_values, | ||
537 | ARRAY_SIZE(vcore_values)); | ||
538 | if (fval < 0) | ||
539 | return -EINVAL; | ||
540 | |||
541 | dev_dbg(&c->dev, "Setting VCORE FLOOR to %d mV and ROOF to %d mV\n", | ||
542 | floor_mV, roof_mV); | ||
543 | |||
544 | mutex_lock(&the_menelaus->lock); | ||
545 | ret = menelaus_write_reg(MENELAUS_VCORE_CTRL3, fval); | ||
546 | if (ret < 0) | ||
547 | goto out; | ||
548 | ret = menelaus_write_reg(MENELAUS_VCORE_CTRL4, rval); | ||
549 | if (ret < 0) | ||
550 | goto out; | ||
551 | if (!the_menelaus->vcore_hw_mode) { | ||
552 | val = menelaus_read_reg(MENELAUS_VCORE_CTRL1); | ||
553 | /* HW mode, turn OFF byte comparator */ | ||
554 | val |= ((1 << 7) | (1 << 5)); | ||
555 | ret = menelaus_write_reg(MENELAUS_VCORE_CTRL1, val); | ||
556 | the_menelaus->vcore_hw_mode = 1; | ||
557 | } | ||
558 | msleep(1); | ||
559 | out: | ||
560 | mutex_unlock(&the_menelaus->lock); | ||
561 | return ret; | ||
562 | } | ||
563 | |||
564 | static const struct menelaus_vtg vmem_vtg = { | ||
565 | .name = "VMEM", | ||
566 | .vtg_reg = MENELAUS_LDO_CTRL1, | ||
567 | .vtg_shift = 0, | ||
568 | .vtg_bits = 2, | ||
569 | .mode_reg = MENELAUS_LDO_CTRL3, | ||
570 | }; | ||
571 | |||
572 | static const struct menelaus_vtg_value vmem_values[] = { | ||
573 | { 1500, 0 }, | ||
574 | { 1800, 1 }, | ||
575 | { 1900, 2 }, | ||
576 | { 2500, 3 }, | ||
577 | }; | ||
578 | |||
579 | int menelaus_set_vmem(unsigned int mV) | ||
580 | { | ||
581 | int val; | ||
582 | |||
583 | if (mV == 0) | ||
584 | return menelaus_set_voltage(&vmem_vtg, 0, 0, 0); | ||
585 | |||
586 | val = menelaus_get_vtg_value(mV, vmem_values, ARRAY_SIZE(vmem_values)); | ||
587 | if (val < 0) | ||
588 | return -EINVAL; | ||
589 | return menelaus_set_voltage(&vmem_vtg, mV, val, 0x02); | ||
590 | } | ||
591 | EXPORT_SYMBOL(menelaus_set_vmem); | ||
592 | |||
593 | static const struct menelaus_vtg vio_vtg = { | ||
594 | .name = "VIO", | ||
595 | .vtg_reg = MENELAUS_LDO_CTRL1, | ||
596 | .vtg_shift = 2, | ||
597 | .vtg_bits = 2, | ||
598 | .mode_reg = MENELAUS_LDO_CTRL4, | ||
599 | }; | ||
600 | |||
601 | static const struct menelaus_vtg_value vio_values[] = { | ||
602 | { 1500, 0 }, | ||
603 | { 1800, 1 }, | ||
604 | { 2500, 2 }, | ||
605 | { 2800, 3 }, | ||
606 | }; | ||
607 | |||
608 | int menelaus_set_vio(unsigned int mV) | ||
609 | { | ||
610 | int val; | ||
611 | |||
612 | if (mV == 0) | ||
613 | return menelaus_set_voltage(&vio_vtg, 0, 0, 0); | ||
614 | |||
615 | val = menelaus_get_vtg_value(mV, vio_values, ARRAY_SIZE(vio_values)); | ||
616 | if (val < 0) | ||
617 | return -EINVAL; | ||
618 | return menelaus_set_voltage(&vio_vtg, mV, val, 0x02); | ||
619 | } | ||
620 | EXPORT_SYMBOL(menelaus_set_vio); | ||
621 | |||
622 | static const struct menelaus_vtg_value vdcdc_values[] = { | ||
623 | { 1500, 0 }, | ||
624 | { 1800, 1 }, | ||
625 | { 2000, 2 }, | ||
626 | { 2200, 3 }, | ||
627 | { 2400, 4 }, | ||
628 | { 2800, 5 }, | ||
629 | { 3000, 6 }, | ||
630 | { 3300, 7 }, | ||
631 | }; | ||
632 | |||
633 | static const struct menelaus_vtg vdcdc2_vtg = { | ||
634 | .name = "VDCDC2", | ||
635 | .vtg_reg = MENELAUS_DCDC_CTRL1, | ||
636 | .vtg_shift = 0, | ||
637 | .vtg_bits = 3, | ||
638 | .mode_reg = MENELAUS_DCDC_CTRL2, | ||
639 | }; | ||
640 | |||
641 | static const struct menelaus_vtg vdcdc3_vtg = { | ||
642 | .name = "VDCDC3", | ||
643 | .vtg_reg = MENELAUS_DCDC_CTRL1, | ||
644 | .vtg_shift = 3, | ||
645 | .vtg_bits = 3, | ||
646 | .mode_reg = MENELAUS_DCDC_CTRL3, | ||
647 | }; | ||
648 | |||
649 | int menelaus_set_vdcdc(int dcdc, unsigned int mV) | ||
650 | { | ||
651 | const struct menelaus_vtg *vtg; | ||
652 | int val; | ||
653 | |||
654 | if (dcdc != 2 && dcdc != 3) | ||
655 | return -EINVAL; | ||
656 | if (dcdc == 2) | ||
657 | vtg = &vdcdc2_vtg; | ||
658 | else | ||
659 | vtg = &vdcdc3_vtg; | ||
660 | |||
661 | if (mV == 0) | ||
662 | return menelaus_set_voltage(vtg, 0, 0, 0); | ||
663 | |||
664 | val = menelaus_get_vtg_value(mV, vdcdc_values, | ||
665 | ARRAY_SIZE(vdcdc_values)); | ||
666 | if (val < 0) | ||
667 | return -EINVAL; | ||
668 | return menelaus_set_voltage(vtg, mV, val, 0x03); | ||
669 | } | ||
670 | |||
671 | static const struct menelaus_vtg_value vmmc_values[] = { | ||
672 | { 1850, 0 }, | ||
673 | { 2800, 1 }, | ||
674 | { 3000, 2 }, | ||
675 | { 3100, 3 }, | ||
676 | }; | ||
677 | |||
678 | static const struct menelaus_vtg vmmc_vtg = { | ||
679 | .name = "VMMC", | ||
680 | .vtg_reg = MENELAUS_LDO_CTRL1, | ||
681 | .vtg_shift = 6, | ||
682 | .vtg_bits = 2, | ||
683 | .mode_reg = MENELAUS_LDO_CTRL7, | ||
684 | }; | ||
685 | |||
686 | int menelaus_set_vmmc(unsigned int mV) | ||
687 | { | ||
688 | int val; | ||
689 | |||
690 | if (mV == 0) | ||
691 | return menelaus_set_voltage(&vmmc_vtg, 0, 0, 0); | ||
692 | |||
693 | val = menelaus_get_vtg_value(mV, vmmc_values, ARRAY_SIZE(vmmc_values)); | ||
694 | if (val < 0) | ||
695 | return -EINVAL; | ||
696 | return menelaus_set_voltage(&vmmc_vtg, mV, val, 0x02); | ||
697 | } | ||
698 | EXPORT_SYMBOL(menelaus_set_vmmc); | ||
699 | |||
700 | |||
701 | static const struct menelaus_vtg_value vaux_values[] = { | ||
702 | { 1500, 0 }, | ||
703 | { 1800, 1 }, | ||
704 | { 2500, 2 }, | ||
705 | { 2800, 3 }, | ||
706 | }; | ||
707 | |||
708 | static const struct menelaus_vtg vaux_vtg = { | ||
709 | .name = "VAUX", | ||
710 | .vtg_reg = MENELAUS_LDO_CTRL1, | ||
711 | .vtg_shift = 4, | ||
712 | .vtg_bits = 2, | ||
713 | .mode_reg = MENELAUS_LDO_CTRL6, | ||
714 | }; | ||
715 | |||
716 | int menelaus_set_vaux(unsigned int mV) | ||
717 | { | ||
718 | int val; | ||
719 | |||
720 | if (mV == 0) | ||
721 | return menelaus_set_voltage(&vaux_vtg, 0, 0, 0); | ||
722 | |||
723 | val = menelaus_get_vtg_value(mV, vaux_values, ARRAY_SIZE(vaux_values)); | ||
724 | if (val < 0) | ||
725 | return -EINVAL; | ||
726 | return menelaus_set_voltage(&vaux_vtg, mV, val, 0x02); | ||
727 | } | ||
728 | EXPORT_SYMBOL(menelaus_set_vaux); | ||
729 | |||
730 | int menelaus_get_slot_pin_states(void) | ||
731 | { | ||
732 | return menelaus_read_reg(MENELAUS_MCT_PIN_ST); | ||
733 | } | ||
734 | EXPORT_SYMBOL(menelaus_get_slot_pin_states); | ||
735 | |||
736 | int menelaus_set_regulator_sleep(int enable, u32 val) | ||
737 | { | ||
738 | int t, ret; | ||
739 | struct i2c_client *c = the_menelaus->client; | ||
740 | |||
741 | mutex_lock(&the_menelaus->lock); | ||
742 | ret = menelaus_write_reg(MENELAUS_SLEEP_CTRL2, val); | ||
743 | if (ret < 0) | ||
744 | goto out; | ||
745 | |||
746 | dev_dbg(&c->dev, "regulator sleep configuration: %02x\n", val); | ||
747 | |||
748 | ret = menelaus_read_reg(MENELAUS_GPIO_CTRL); | ||
749 | if (ret < 0) | ||
750 | goto out; | ||
751 | t = ((1 << 6) | 0x04); | ||
752 | if (enable) | ||
753 | ret |= t; | ||
754 | else | ||
755 | ret &= ~t; | ||
756 | ret = menelaus_write_reg(MENELAUS_GPIO_CTRL, ret); | ||
757 | out: | ||
758 | mutex_unlock(&the_menelaus->lock); | ||
759 | return ret; | ||
760 | } | ||
761 | |||
762 | /*-----------------------------------------------------------------------*/ | ||
763 | |||
764 | /* Handles Menelaus interrupts. Does not run in interrupt context */ | ||
765 | static void menelaus_work(struct work_struct *_menelaus) | ||
766 | { | ||
767 | struct menelaus_chip *menelaus = | ||
768 | container_of(_menelaus, struct menelaus_chip, work); | ||
769 | void (*handler)(struct menelaus_chip *menelaus); | ||
770 | |||
771 | while (1) { | ||
772 | unsigned isr; | ||
773 | |||
774 | isr = (menelaus_read_reg(MENELAUS_INT_STATUS2) | ||
775 | & ~menelaus->mask2) << 8; | ||
776 | isr |= menelaus_read_reg(MENELAUS_INT_STATUS1) | ||
777 | & ~menelaus->mask1; | ||
778 | if (!isr) | ||
779 | break; | ||
780 | |||
781 | while (isr) { | ||
782 | int irq = fls(isr) - 1; | ||
783 | isr &= ~(1 << irq); | ||
784 | |||
785 | mutex_lock(&menelaus->lock); | ||
786 | menelaus_disable_irq(irq); | ||
787 | menelaus_ack_irq(irq); | ||
788 | handler = menelaus->handlers[irq]; | ||
789 | if (handler) | ||
790 | handler(menelaus); | ||
791 | menelaus_enable_irq(irq); | ||
792 | mutex_unlock(&menelaus->lock); | ||
793 | } | ||
794 | } | ||
795 | enable_irq(menelaus->client->irq); | ||
796 | } | ||
797 | |||
798 | /* | ||
799 | * We cannot use I2C in interrupt context, so we just schedule work. | ||
800 | */ | ||
801 | static irqreturn_t menelaus_irq(int irq, void *_menelaus) | ||
802 | { | ||
803 | struct menelaus_chip *menelaus = _menelaus; | ||
804 | |||
805 | disable_irq_nosync(irq); | ||
806 | (void)schedule_work(&menelaus->work); | ||
807 | |||
808 | return IRQ_HANDLED; | ||
809 | } | ||
810 | |||
811 | /*-----------------------------------------------------------------------*/ | ||
812 | |||
813 | /* | ||
814 | * The RTC needs to be set once, then it runs on backup battery power. | ||
815 | * It supports alarms, including system wake alarms (from some modes); | ||
816 | * and 1/second IRQs if requested. | ||
817 | */ | ||
818 | #ifdef CONFIG_RTC_DRV_TWL92330 | ||
819 | |||
820 | #define RTC_CTRL_RTC_EN (1 << 0) | ||
821 | #define RTC_CTRL_AL_EN (1 << 1) | ||
822 | #define RTC_CTRL_MODE12 (1 << 2) | ||
823 | #define RTC_CTRL_EVERY_MASK (3 << 3) | ||
824 | #define RTC_CTRL_EVERY_SEC (0 << 3) | ||
825 | #define RTC_CTRL_EVERY_MIN (1 << 3) | ||
826 | #define RTC_CTRL_EVERY_HR (2 << 3) | ||
827 | #define RTC_CTRL_EVERY_DAY (3 << 3) | ||
828 | |||
829 | #define RTC_UPDATE_EVERY 0x08 | ||
830 | |||
831 | #define RTC_HR_PM (1 << 7) | ||
832 | |||
833 | static void menelaus_to_time(char *regs, struct rtc_time *t) | ||
834 | { | ||
835 | t->tm_sec = bcd2bin(regs[0]); | ||
836 | t->tm_min = bcd2bin(regs[1]); | ||
837 | if (the_menelaus->rtc_control & RTC_CTRL_MODE12) { | ||
838 | t->tm_hour = bcd2bin(regs[2] & 0x1f) - 1; | ||
839 | if (regs[2] & RTC_HR_PM) | ||
840 | t->tm_hour += 12; | ||
841 | } else | ||
842 | t->tm_hour = bcd2bin(regs[2] & 0x3f); | ||
843 | t->tm_mday = bcd2bin(regs[3]); | ||
844 | t->tm_mon = bcd2bin(regs[4]) - 1; | ||
845 | t->tm_year = bcd2bin(regs[5]) + 100; | ||
846 | } | ||
847 | |||
848 | static int time_to_menelaus(struct rtc_time *t, int regnum) | ||
849 | { | ||
850 | int hour, status; | ||
851 | |||
852 | status = menelaus_write_reg(regnum++, bin2bcd(t->tm_sec)); | ||
853 | if (status < 0) | ||
854 | goto fail; | ||
855 | |||
856 | status = menelaus_write_reg(regnum++, bin2bcd(t->tm_min)); | ||
857 | if (status < 0) | ||
858 | goto fail; | ||
859 | |||
860 | if (the_menelaus->rtc_control & RTC_CTRL_MODE12) { | ||
861 | hour = t->tm_hour + 1; | ||
862 | if (hour > 12) | ||
863 | hour = RTC_HR_PM | bin2bcd(hour - 12); | ||
864 | else | ||
865 | hour = bin2bcd(hour); | ||
866 | } else | ||
867 | hour = bin2bcd(t->tm_hour); | ||
868 | status = menelaus_write_reg(regnum++, hour); | ||
869 | if (status < 0) | ||
870 | goto fail; | ||
871 | |||
872 | status = menelaus_write_reg(regnum++, bin2bcd(t->tm_mday)); | ||
873 | if (status < 0) | ||
874 | goto fail; | ||
875 | |||
876 | status = menelaus_write_reg(regnum++, bin2bcd(t->tm_mon + 1)); | ||
877 | if (status < 0) | ||
878 | goto fail; | ||
879 | |||
880 | status = menelaus_write_reg(regnum++, bin2bcd(t->tm_year - 100)); | ||
881 | if (status < 0) | ||
882 | goto fail; | ||
883 | |||
884 | return 0; | ||
885 | fail: | ||
886 | dev_err(&the_menelaus->client->dev, "rtc write reg %02x, err %d\n", | ||
887 | --regnum, status); | ||
888 | return status; | ||
889 | } | ||
890 | |||
891 | static int menelaus_read_time(struct device *dev, struct rtc_time *t) | ||
892 | { | ||
893 | struct i2c_msg msg[2]; | ||
894 | char regs[7]; | ||
895 | int status; | ||
896 | |||
897 | /* block read date and time registers */ | ||
898 | regs[0] = MENELAUS_RTC_SEC; | ||
899 | |||
900 | msg[0].addr = MENELAUS_I2C_ADDRESS; | ||
901 | msg[0].flags = 0; | ||
902 | msg[0].len = 1; | ||
903 | msg[0].buf = regs; | ||
904 | |||
905 | msg[1].addr = MENELAUS_I2C_ADDRESS; | ||
906 | msg[1].flags = I2C_M_RD; | ||
907 | msg[1].len = sizeof(regs); | ||
908 | msg[1].buf = regs; | ||
909 | |||
910 | status = i2c_transfer(the_menelaus->client->adapter, msg, 2); | ||
911 | if (status != 2) { | ||
912 | dev_err(dev, "%s error %d\n", "read", status); | ||
913 | return -EIO; | ||
914 | } | ||
915 | |||
916 | menelaus_to_time(regs, t); | ||
917 | t->tm_wday = bcd2bin(regs[6]); | ||
918 | |||
919 | return 0; | ||
920 | } | ||
921 | |||
922 | static int menelaus_set_time(struct device *dev, struct rtc_time *t) | ||
923 | { | ||
924 | int status; | ||
925 | |||
926 | /* write date and time registers */ | ||
927 | status = time_to_menelaus(t, MENELAUS_RTC_SEC); | ||
928 | if (status < 0) | ||
929 | return status; | ||
930 | status = menelaus_write_reg(MENELAUS_RTC_WKDAY, bin2bcd(t->tm_wday)); | ||
931 | if (status < 0) { | ||
932 | dev_err(&the_menelaus->client->dev, "rtc write reg %02x " | ||
933 | "err %d\n", MENELAUS_RTC_WKDAY, status); | ||
934 | return status; | ||
935 | } | ||
936 | |||
937 | /* now commit the write */ | ||
938 | status = menelaus_write_reg(MENELAUS_RTC_UPDATE, RTC_UPDATE_EVERY); | ||
939 | if (status < 0) | ||
940 | dev_err(&the_menelaus->client->dev, "rtc commit time, err %d\n", | ||
941 | status); | ||
942 | |||
943 | return 0; | ||
944 | } | ||
945 | |||
946 | static int menelaus_read_alarm(struct device *dev, struct rtc_wkalrm *w) | ||
947 | { | ||
948 | struct i2c_msg msg[2]; | ||
949 | char regs[6]; | ||
950 | int status; | ||
951 | |||
952 | /* block read alarm registers */ | ||
953 | regs[0] = MENELAUS_RTC_AL_SEC; | ||
954 | |||
955 | msg[0].addr = MENELAUS_I2C_ADDRESS; | ||
956 | msg[0].flags = 0; | ||
957 | msg[0].len = 1; | ||
958 | msg[0].buf = regs; | ||
959 | |||
960 | msg[1].addr = MENELAUS_I2C_ADDRESS; | ||
961 | msg[1].flags = I2C_M_RD; | ||
962 | msg[1].len = sizeof(regs); | ||
963 | msg[1].buf = regs; | ||
964 | |||
965 | status = i2c_transfer(the_menelaus->client->adapter, msg, 2); | ||
966 | if (status != 2) { | ||
967 | dev_err(dev, "%s error %d\n", "alarm read", status); | ||
968 | return -EIO; | ||
969 | } | ||
970 | |||
971 | menelaus_to_time(regs, &w->time); | ||
972 | |||
973 | w->enabled = !!(the_menelaus->rtc_control & RTC_CTRL_AL_EN); | ||
974 | |||
975 | /* NOTE we *could* check if actually pending... */ | ||
976 | w->pending = 0; | ||
977 | |||
978 | return 0; | ||
979 | } | ||
980 | |||
981 | static int menelaus_set_alarm(struct device *dev, struct rtc_wkalrm *w) | ||
982 | { | ||
983 | int status; | ||
984 | |||
985 | if (the_menelaus->client->irq <= 0 && w->enabled) | ||
986 | return -ENODEV; | ||
987 | |||
988 | /* clear previous alarm enable */ | ||
989 | if (the_menelaus->rtc_control & RTC_CTRL_AL_EN) { | ||
990 | the_menelaus->rtc_control &= ~RTC_CTRL_AL_EN; | ||
991 | status = menelaus_write_reg(MENELAUS_RTC_CTRL, | ||
992 | the_menelaus->rtc_control); | ||
993 | if (status < 0) | ||
994 | return status; | ||
995 | } | ||
996 | |||
997 | /* write alarm registers */ | ||
998 | status = time_to_menelaus(&w->time, MENELAUS_RTC_AL_SEC); | ||
999 | if (status < 0) | ||
1000 | return status; | ||
1001 | |||
1002 | /* enable alarm if requested */ | ||
1003 | if (w->enabled) { | ||
1004 | the_menelaus->rtc_control |= RTC_CTRL_AL_EN; | ||
1005 | status = menelaus_write_reg(MENELAUS_RTC_CTRL, | ||
1006 | the_menelaus->rtc_control); | ||
1007 | } | ||
1008 | |||
1009 | return status; | ||
1010 | } | ||
1011 | |||
1012 | #ifdef CONFIG_RTC_INTF_DEV | ||
1013 | |||
1014 | static void menelaus_rtc_update_work(struct menelaus_chip *m) | ||
1015 | { | ||
1016 | /* report 1/sec update */ | ||
1017 | local_irq_disable(); | ||
1018 | rtc_update_irq(m->rtc, 1, RTC_IRQF | RTC_UF); | ||
1019 | local_irq_enable(); | ||
1020 | } | ||
1021 | |||
1022 | static int menelaus_ioctl(struct device *dev, unsigned cmd, unsigned long arg) | ||
1023 | { | ||
1024 | int status; | ||
1025 | |||
1026 | if (the_menelaus->client->irq <= 0) | ||
1027 | return -ENOIOCTLCMD; | ||
1028 | |||
1029 | switch (cmd) { | ||
1030 | /* alarm IRQ */ | ||
1031 | case RTC_AIE_ON: | ||
1032 | if (the_menelaus->rtc_control & RTC_CTRL_AL_EN) | ||
1033 | return 0; | ||
1034 | the_menelaus->rtc_control |= RTC_CTRL_AL_EN; | ||
1035 | break; | ||
1036 | case RTC_AIE_OFF: | ||
1037 | if (!(the_menelaus->rtc_control & RTC_CTRL_AL_EN)) | ||
1038 | return 0; | ||
1039 | the_menelaus->rtc_control &= ~RTC_CTRL_AL_EN; | ||
1040 | break; | ||
1041 | /* 1/second "update" IRQ */ | ||
1042 | case RTC_UIE_ON: | ||
1043 | if (the_menelaus->uie) | ||
1044 | return 0; | ||
1045 | status = menelaus_remove_irq_work(MENELAUS_RTCTMR_IRQ); | ||
1046 | status = menelaus_add_irq_work(MENELAUS_RTCTMR_IRQ, | ||
1047 | menelaus_rtc_update_work); | ||
1048 | if (status == 0) | ||
1049 | the_menelaus->uie = 1; | ||
1050 | return status; | ||
1051 | case RTC_UIE_OFF: | ||
1052 | if (!the_menelaus->uie) | ||
1053 | return 0; | ||
1054 | status = menelaus_remove_irq_work(MENELAUS_RTCTMR_IRQ); | ||
1055 | if (status == 0) | ||
1056 | the_menelaus->uie = 0; | ||
1057 | return status; | ||
1058 | default: | ||
1059 | return -ENOIOCTLCMD; | ||
1060 | } | ||
1061 | return menelaus_write_reg(MENELAUS_RTC_CTRL, the_menelaus->rtc_control); | ||
1062 | } | ||
1063 | |||
1064 | #else | ||
1065 | #define menelaus_ioctl NULL | ||
1066 | #endif | ||
1067 | |||
1068 | /* REVISIT no compensation register support ... */ | ||
1069 | |||
1070 | static const struct rtc_class_ops menelaus_rtc_ops = { | ||
1071 | .ioctl = menelaus_ioctl, | ||
1072 | .read_time = menelaus_read_time, | ||
1073 | .set_time = menelaus_set_time, | ||
1074 | .read_alarm = menelaus_read_alarm, | ||
1075 | .set_alarm = menelaus_set_alarm, | ||
1076 | }; | ||
1077 | |||
1078 | static void menelaus_rtc_alarm_work(struct menelaus_chip *m) | ||
1079 | { | ||
1080 | /* report alarm */ | ||
1081 | local_irq_disable(); | ||
1082 | rtc_update_irq(m->rtc, 1, RTC_IRQF | RTC_AF); | ||
1083 | local_irq_enable(); | ||
1084 | |||
1085 | /* then disable it; alarms are oneshot */ | ||
1086 | the_menelaus->rtc_control &= ~RTC_CTRL_AL_EN; | ||
1087 | menelaus_write_reg(MENELAUS_RTC_CTRL, the_menelaus->rtc_control); | ||
1088 | } | ||
1089 | |||
1090 | static inline void menelaus_rtc_init(struct menelaus_chip *m) | ||
1091 | { | ||
1092 | int alarm = (m->client->irq > 0); | ||
1093 | |||
1094 | /* assume 32KDETEN pin is pulled high */ | ||
1095 | if (!(menelaus_read_reg(MENELAUS_OSC_CTRL) & 0x80)) { | ||
1096 | dev_dbg(&m->client->dev, "no 32k oscillator\n"); | ||
1097 | return; | ||
1098 | } | ||
1099 | |||
1100 | /* support RTC alarm; it can issue wakeups */ | ||
1101 | if (alarm) { | ||
1102 | if (menelaus_add_irq_work(MENELAUS_RTCALM_IRQ, | ||
1103 | menelaus_rtc_alarm_work) < 0) { | ||
1104 | dev_err(&m->client->dev, "can't handle RTC alarm\n"); | ||
1105 | return; | ||
1106 | } | ||
1107 | device_init_wakeup(&m->client->dev, 1); | ||
1108 | } | ||
1109 | |||
1110 | /* be sure RTC is enabled; allow 1/sec irqs; leave 12hr mode alone */ | ||
1111 | m->rtc_control = menelaus_read_reg(MENELAUS_RTC_CTRL); | ||
1112 | if (!(m->rtc_control & RTC_CTRL_RTC_EN) | ||
1113 | || (m->rtc_control & RTC_CTRL_AL_EN) | ||
1114 | || (m->rtc_control & RTC_CTRL_EVERY_MASK)) { | ||
1115 | if (!(m->rtc_control & RTC_CTRL_RTC_EN)) { | ||
1116 | dev_warn(&m->client->dev, "rtc clock needs setting\n"); | ||
1117 | m->rtc_control |= RTC_CTRL_RTC_EN; | ||
1118 | } | ||
1119 | m->rtc_control &= ~RTC_CTRL_EVERY_MASK; | ||
1120 | m->rtc_control &= ~RTC_CTRL_AL_EN; | ||
1121 | menelaus_write_reg(MENELAUS_RTC_CTRL, m->rtc_control); | ||
1122 | } | ||
1123 | |||
1124 | m->rtc = rtc_device_register(DRIVER_NAME, | ||
1125 | &m->client->dev, | ||
1126 | &menelaus_rtc_ops, THIS_MODULE); | ||
1127 | if (IS_ERR(m->rtc)) { | ||
1128 | if (alarm) { | ||
1129 | menelaus_remove_irq_work(MENELAUS_RTCALM_IRQ); | ||
1130 | device_init_wakeup(&m->client->dev, 0); | ||
1131 | } | ||
1132 | dev_err(&m->client->dev, "can't register RTC: %d\n", | ||
1133 | (int) PTR_ERR(m->rtc)); | ||
1134 | the_menelaus->rtc = NULL; | ||
1135 | } | ||
1136 | } | ||
1137 | |||
1138 | #else | ||
1139 | |||
1140 | static inline void menelaus_rtc_init(struct menelaus_chip *m) | ||
1141 | { | ||
1142 | /* nothing */ | ||
1143 | } | ||
1144 | |||
1145 | #endif | ||
1146 | |||
1147 | /*-----------------------------------------------------------------------*/ | ||
1148 | |||
1149 | static struct i2c_driver menelaus_i2c_driver; | ||
1150 | |||
1151 | static int menelaus_probe(struct i2c_client *client, | ||
1152 | const struct i2c_device_id *id) | ||
1153 | { | ||
1154 | struct menelaus_chip *menelaus; | ||
1155 | int rev = 0, val; | ||
1156 | int err = 0; | ||
1157 | struct menelaus_platform_data *menelaus_pdata = | ||
1158 | client->dev.platform_data; | ||
1159 | |||
1160 | if (the_menelaus) { | ||
1161 | dev_dbg(&client->dev, "only one %s for now\n", | ||
1162 | DRIVER_NAME); | ||
1163 | return -ENODEV; | ||
1164 | } | ||
1165 | |||
1166 | menelaus = kzalloc(sizeof *menelaus, GFP_KERNEL); | ||
1167 | if (!menelaus) | ||
1168 | return -ENOMEM; | ||
1169 | |||
1170 | i2c_set_clientdata(client, menelaus); | ||
1171 | |||
1172 | the_menelaus = menelaus; | ||
1173 | menelaus->client = client; | ||
1174 | |||
1175 | /* If a true probe check the device */ | ||
1176 | rev = menelaus_read_reg(MENELAUS_REV); | ||
1177 | if (rev < 0) { | ||
1178 | pr_err(DRIVER_NAME ": device not found"); | ||
1179 | err = -ENODEV; | ||
1180 | goto fail1; | ||
1181 | } | ||
1182 | |||
1183 | /* Ack and disable all Menelaus interrupts */ | ||
1184 | menelaus_write_reg(MENELAUS_INT_ACK1, 0xff); | ||
1185 | menelaus_write_reg(MENELAUS_INT_ACK2, 0xff); | ||
1186 | menelaus_write_reg(MENELAUS_INT_MASK1, 0xff); | ||
1187 | menelaus_write_reg(MENELAUS_INT_MASK2, 0xff); | ||
1188 | menelaus->mask1 = 0xff; | ||
1189 | menelaus->mask2 = 0xff; | ||
1190 | |||
1191 | /* Set output buffer strengths */ | ||
1192 | menelaus_write_reg(MENELAUS_MCT_CTRL1, 0x73); | ||
1193 | |||
1194 | if (client->irq > 0) { | ||
1195 | err = request_irq(client->irq, menelaus_irq, IRQF_DISABLED, | ||
1196 | DRIVER_NAME, menelaus); | ||
1197 | if (err) { | ||
1198 | dev_dbg(&client->dev, "can't get IRQ %d, err %d\n", | ||
1199 | client->irq, err); | ||
1200 | goto fail1; | ||
1201 | } | ||
1202 | } | ||
1203 | |||
1204 | mutex_init(&menelaus->lock); | ||
1205 | INIT_WORK(&menelaus->work, menelaus_work); | ||
1206 | |||
1207 | pr_info("Menelaus rev %d.%d\n", rev >> 4, rev & 0x0f); | ||
1208 | |||
1209 | val = menelaus_read_reg(MENELAUS_VCORE_CTRL1); | ||
1210 | if (val < 0) | ||
1211 | goto fail2; | ||
1212 | if (val & (1 << 7)) | ||
1213 | menelaus->vcore_hw_mode = 1; | ||
1214 | else | ||
1215 | menelaus->vcore_hw_mode = 0; | ||
1216 | |||
1217 | if (menelaus_pdata != NULL && menelaus_pdata->late_init != NULL) { | ||
1218 | err = menelaus_pdata->late_init(&client->dev); | ||
1219 | if (err < 0) | ||
1220 | goto fail2; | ||
1221 | } | ||
1222 | |||
1223 | menelaus_rtc_init(menelaus); | ||
1224 | |||
1225 | return 0; | ||
1226 | fail2: | ||
1227 | free_irq(client->irq, menelaus); | ||
1228 | flush_scheduled_work(); | ||
1229 | fail1: | ||
1230 | kfree(menelaus); | ||
1231 | return err; | ||
1232 | } | ||
1233 | |||
1234 | static int __exit menelaus_remove(struct i2c_client *client) | ||
1235 | { | ||
1236 | struct menelaus_chip *menelaus = i2c_get_clientdata(client); | ||
1237 | |||
1238 | free_irq(client->irq, menelaus); | ||
1239 | kfree(menelaus); | ||
1240 | i2c_set_clientdata(client, NULL); | ||
1241 | the_menelaus = NULL; | ||
1242 | return 0; | ||
1243 | } | ||
1244 | |||
1245 | static const struct i2c_device_id menelaus_id[] = { | ||
1246 | { "menelaus", 0 }, | ||
1247 | { } | ||
1248 | }; | ||
1249 | MODULE_DEVICE_TABLE(i2c, menelaus_id); | ||
1250 | |||
1251 | static struct i2c_driver menelaus_i2c_driver = { | ||
1252 | .driver = { | ||
1253 | .name = DRIVER_NAME, | ||
1254 | }, | ||
1255 | .probe = menelaus_probe, | ||
1256 | .remove = __exit_p(menelaus_remove), | ||
1257 | .id_table = menelaus_id, | ||
1258 | }; | ||
1259 | |||
1260 | static int __init menelaus_init(void) | ||
1261 | { | ||
1262 | int res; | ||
1263 | |||
1264 | res = i2c_add_driver(&menelaus_i2c_driver); | ||
1265 | if (res < 0) { | ||
1266 | pr_err(DRIVER_NAME ": driver registration failed\n"); | ||
1267 | return res; | ||
1268 | } | ||
1269 | |||
1270 | return 0; | ||
1271 | } | ||
1272 | |||
1273 | static void __exit menelaus_exit(void) | ||
1274 | { | ||
1275 | i2c_del_driver(&menelaus_i2c_driver); | ||
1276 | |||
1277 | /* FIXME: Shutdown menelaus parts that can be shut down */ | ||
1278 | } | ||
1279 | |||
1280 | MODULE_AUTHOR("Texas Instruments, Inc. (and others)"); | ||
1281 | MODULE_DESCRIPTION("I2C interface for Menelaus."); | ||
1282 | MODULE_LICENSE("GPL"); | ||
1283 | |||
1284 | module_init(menelaus_init); | ||
1285 | module_exit(menelaus_exit); | ||
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c deleted file mode 100644 index acf8b9d5f575..000000000000 --- a/drivers/i2c/chips/tps65010.c +++ /dev/null | |||
@@ -1,1072 +0,0 @@ | |||
1 | /* | ||
2 | * tps65010 - driver for tps6501x power management chips | ||
3 | * | ||
4 | * Copyright (C) 2004 Texas Instruments | ||
5 | * Copyright (C) 2004-2005 David Brownell | ||
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 as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <linux/interrupt.h> | ||
27 | #include <linux/i2c.h> | ||
28 | #include <linux/delay.h> | ||
29 | #include <linux/workqueue.h> | ||
30 | #include <linux/debugfs.h> | ||
31 | #include <linux/seq_file.h> | ||
32 | #include <linux/mutex.h> | ||
33 | #include <linux/platform_device.h> | ||
34 | |||
35 | #include <linux/i2c/tps65010.h> | ||
36 | |||
37 | #include <asm/gpio.h> | ||
38 | |||
39 | |||
40 | /*-------------------------------------------------------------------------*/ | ||
41 | |||
42 | #define DRIVER_VERSION "2 May 2005" | ||
43 | #define DRIVER_NAME (tps65010_driver.driver.name) | ||
44 | |||
45 | MODULE_DESCRIPTION("TPS6501x Power Management Driver"); | ||
46 | MODULE_LICENSE("GPL"); | ||
47 | |||
48 | static struct i2c_driver tps65010_driver; | ||
49 | |||
50 | /*-------------------------------------------------------------------------*/ | ||
51 | |||
52 | /* This driver handles a family of multipurpose chips, which incorporate | ||
53 | * voltage regulators, lithium ion/polymer battery charging, GPIOs, LEDs, | ||
54 | * and other features often needed in portable devices like cell phones | ||
55 | * or digital cameras. | ||
56 | * | ||
57 | * The tps65011 and tps65013 have different voltage settings compared | ||
58 | * to tps65010 and tps65012. The tps65013 has a NO_CHG status/irq. | ||
59 | * All except tps65010 have "wait" mode, possibly defaulted so that | ||
60 | * battery-insert != device-on. | ||
61 | * | ||
62 | * We could distinguish between some models by checking VDCDC1.UVLO or | ||
63 | * other registers, unless they've been changed already after powerup | ||
64 | * as part of board setup by a bootloader. | ||
65 | */ | ||
66 | enum tps_model { | ||
67 | TPS65010, | ||
68 | TPS65011, | ||
69 | TPS65012, | ||
70 | TPS65013, | ||
71 | }; | ||
72 | |||
73 | struct tps65010 { | ||
74 | struct i2c_client *client; | ||
75 | struct mutex lock; | ||
76 | struct delayed_work work; | ||
77 | struct dentry *file; | ||
78 | unsigned charging:1; | ||
79 | unsigned por:1; | ||
80 | unsigned model:8; | ||
81 | u16 vbus; | ||
82 | unsigned long flags; | ||
83 | #define FLAG_VBUS_CHANGED 0 | ||
84 | #define FLAG_IRQ_ENABLE 1 | ||
85 | |||
86 | /* copies of last register state */ | ||
87 | u8 chgstatus, regstatus, chgconf; | ||
88 | u8 nmask1, nmask2; | ||
89 | |||
90 | u8 outmask; | ||
91 | struct gpio_chip chip; | ||
92 | struct platform_device *leds; | ||
93 | }; | ||
94 | |||
95 | #define POWER_POLL_DELAY msecs_to_jiffies(5000) | ||
96 | |||
97 | /*-------------------------------------------------------------------------*/ | ||
98 | |||
99 | #if defined(DEBUG) || defined(CONFIG_DEBUG_FS) | ||
100 | |||
101 | static void dbg_chgstat(char *buf, size_t len, u8 chgstatus) | ||
102 | { | ||
103 | snprintf(buf, len, "%02x%s%s%s%s%s%s%s%s\n", | ||
104 | chgstatus, | ||
105 | (chgstatus & TPS_CHG_USB) ? " USB" : "", | ||
106 | (chgstatus & TPS_CHG_AC) ? " AC" : "", | ||
107 | (chgstatus & TPS_CHG_THERM) ? " therm" : "", | ||
108 | (chgstatus & TPS_CHG_TERM) ? " done" : | ||
109 | ((chgstatus & (TPS_CHG_USB|TPS_CHG_AC)) | ||
110 | ? " (charging)" : ""), | ||
111 | (chgstatus & TPS_CHG_TAPER_TMO) ? " taper_tmo" : "", | ||
112 | (chgstatus & TPS_CHG_CHG_TMO) ? " charge_tmo" : "", | ||
113 | (chgstatus & TPS_CHG_PRECHG_TMO) ? " prechg_tmo" : "", | ||
114 | (chgstatus & TPS_CHG_TEMP_ERR) ? " temp_err" : ""); | ||
115 | } | ||
116 | |||
117 | static void dbg_regstat(char *buf, size_t len, u8 regstatus) | ||
118 | { | ||
119 | snprintf(buf, len, "%02x %s%s%s%s%s%s%s%s\n", | ||
120 | regstatus, | ||
121 | (regstatus & TPS_REG_ONOFF) ? "off" : "(on)", | ||
122 | (regstatus & TPS_REG_COVER) ? " uncover" : "", | ||
123 | (regstatus & TPS_REG_UVLO) ? " UVLO" : "", | ||
124 | (regstatus & TPS_REG_NO_CHG) ? " NO_CHG" : "", | ||
125 | (regstatus & TPS_REG_PG_LD02) ? " ld02_bad" : "", | ||
126 | (regstatus & TPS_REG_PG_LD01) ? " ld01_bad" : "", | ||
127 | (regstatus & TPS_REG_PG_MAIN) ? " main_bad" : "", | ||
128 | (regstatus & TPS_REG_PG_CORE) ? " core_bad" : ""); | ||
129 | } | ||
130 | |||
131 | static void dbg_chgconf(int por, char *buf, size_t len, u8 chgconfig) | ||
132 | { | ||
133 | const char *hibit; | ||
134 | |||
135 | if (por) | ||
136 | hibit = (chgconfig & TPS_CHARGE_POR) | ||
137 | ? "POR=69ms" : "POR=1sec"; | ||
138 | else | ||
139 | hibit = (chgconfig & TPS65013_AUA) ? "AUA" : ""; | ||
140 | |||
141 | snprintf(buf, len, "%02x %s%s%s AC=%d%% USB=%dmA %sCharge\n", | ||
142 | chgconfig, hibit, | ||
143 | (chgconfig & TPS_CHARGE_RESET) ? " reset" : "", | ||
144 | (chgconfig & TPS_CHARGE_FAST) ? " fast" : "", | ||
145 | ({int p; switch ((chgconfig >> 3) & 3) { | ||
146 | case 3: p = 100; break; | ||
147 | case 2: p = 75; break; | ||
148 | case 1: p = 50; break; | ||
149 | default: p = 25; break; | ||
150 | }; p; }), | ||
151 | (chgconfig & TPS_VBUS_CHARGING) | ||
152 | ? ((chgconfig & TPS_VBUS_500MA) ? 500 : 100) | ||
153 | : 0, | ||
154 | (chgconfig & TPS_CHARGE_ENABLE) ? "" : "No"); | ||
155 | } | ||
156 | |||
157 | #endif | ||
158 | |||
159 | #ifdef DEBUG | ||
160 | |||
161 | static void show_chgstatus(const char *label, u8 chgstatus) | ||
162 | { | ||
163 | char buf [100]; | ||
164 | |||
165 | dbg_chgstat(buf, sizeof buf, chgstatus); | ||
166 | pr_debug("%s: %s %s", DRIVER_NAME, label, buf); | ||
167 | } | ||
168 | |||
169 | static void show_regstatus(const char *label, u8 regstatus) | ||
170 | { | ||
171 | char buf [100]; | ||
172 | |||
173 | dbg_regstat(buf, sizeof buf, regstatus); | ||
174 | pr_debug("%s: %s %s", DRIVER_NAME, label, buf); | ||
175 | } | ||
176 | |||
177 | static void show_chgconfig(int por, const char *label, u8 chgconfig) | ||
178 | { | ||
179 | char buf [100]; | ||
180 | |||
181 | dbg_chgconf(por, buf, sizeof buf, chgconfig); | ||
182 | pr_debug("%s: %s %s", DRIVER_NAME, label, buf); | ||
183 | } | ||
184 | |||
185 | #else | ||
186 | |||
187 | static inline void show_chgstatus(const char *label, u8 chgstatus) { } | ||
188 | static inline void show_regstatus(const char *label, u8 chgstatus) { } | ||
189 | static inline void show_chgconfig(int por, const char *label, u8 chgconfig) { } | ||
190 | |||
191 | #endif | ||
192 | |||
193 | #ifdef CONFIG_DEBUG_FS | ||
194 | |||
195 | static int dbg_show(struct seq_file *s, void *_) | ||
196 | { | ||
197 | struct tps65010 *tps = s->private; | ||
198 | u8 value, v2; | ||
199 | unsigned i; | ||
200 | char buf[100]; | ||
201 | const char *chip; | ||
202 | |||
203 | switch (tps->model) { | ||
204 | case TPS65010: chip = "tps65010"; break; | ||
205 | case TPS65011: chip = "tps65011"; break; | ||
206 | case TPS65012: chip = "tps65012"; break; | ||
207 | case TPS65013: chip = "tps65013"; break; | ||
208 | default: chip = NULL; break; | ||
209 | } | ||
210 | seq_printf(s, "driver %s\nversion %s\nchip %s\n\n", | ||
211 | DRIVER_NAME, DRIVER_VERSION, chip); | ||
212 | |||
213 | mutex_lock(&tps->lock); | ||
214 | |||
215 | /* FIXME how can we tell whether a battery is present? | ||
216 | * likely involves a charge gauging chip (like BQ26501). | ||
217 | */ | ||
218 | |||
219 | seq_printf(s, "%scharging\n\n", tps->charging ? "" : "(not) "); | ||
220 | |||
221 | |||
222 | /* registers for monitoring battery charging and status; note | ||
223 | * that reading chgstat and regstat may ack IRQs... | ||
224 | */ | ||
225 | value = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG); | ||
226 | dbg_chgconf(tps->por, buf, sizeof buf, value); | ||
227 | seq_printf(s, "chgconfig %s", buf); | ||
228 | |||
229 | value = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS); | ||
230 | dbg_chgstat(buf, sizeof buf, value); | ||
231 | seq_printf(s, "chgstat %s", buf); | ||
232 | value = i2c_smbus_read_byte_data(tps->client, TPS_MASK1); | ||
233 | dbg_chgstat(buf, sizeof buf, value); | ||
234 | seq_printf(s, "mask1 %s", buf); | ||
235 | /* ignore ackint1 */ | ||
236 | |||
237 | value = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS); | ||
238 | dbg_regstat(buf, sizeof buf, value); | ||
239 | seq_printf(s, "regstat %s", buf); | ||
240 | value = i2c_smbus_read_byte_data(tps->client, TPS_MASK2); | ||
241 | dbg_regstat(buf, sizeof buf, value); | ||
242 | seq_printf(s, "mask2 %s\n", buf); | ||
243 | /* ignore ackint2 */ | ||
244 | |||
245 | (void) schedule_delayed_work(&tps->work, POWER_POLL_DELAY); | ||
246 | |||
247 | |||
248 | /* VMAIN voltage, enable lowpower, etc */ | ||
249 | value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC1); | ||
250 | seq_printf(s, "vdcdc1 %02x\n", value); | ||
251 | |||
252 | /* VCORE voltage, vibrator on/off */ | ||
253 | value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC2); | ||
254 | seq_printf(s, "vdcdc2 %02x\n", value); | ||
255 | |||
256 | /* both LD0s, and their lowpower behavior */ | ||
257 | value = i2c_smbus_read_byte_data(tps->client, TPS_VREGS1); | ||
258 | seq_printf(s, "vregs1 %02x\n\n", value); | ||
259 | |||
260 | |||
261 | /* LEDs and GPIOs */ | ||
262 | value = i2c_smbus_read_byte_data(tps->client, TPS_LED1_ON); | ||
263 | v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED1_PER); | ||
264 | seq_printf(s, "led1 %s, on=%02x, per=%02x, %d/%d msec\n", | ||
265 | (value & 0x80) | ||
266 | ? ((v2 & 0x80) ? "on" : "off") | ||
267 | : ((v2 & 0x80) ? "blink" : "(nPG)"), | ||
268 | value, v2, | ||
269 | (value & 0x7f) * 10, (v2 & 0x7f) * 100); | ||
270 | |||
271 | value = i2c_smbus_read_byte_data(tps->client, TPS_LED2_ON); | ||
272 | v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED2_PER); | ||
273 | seq_printf(s, "led2 %s, on=%02x, per=%02x, %d/%d msec\n", | ||
274 | (value & 0x80) | ||
275 | ? ((v2 & 0x80) ? "on" : "off") | ||
276 | : ((v2 & 0x80) ? "blink" : "off"), | ||
277 | value, v2, | ||
278 | (value & 0x7f) * 10, (v2 & 0x7f) * 100); | ||
279 | |||
280 | value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO); | ||
281 | v2 = i2c_smbus_read_byte_data(tps->client, TPS_MASK3); | ||
282 | seq_printf(s, "defgpio %02x mask3 %02x\n", value, v2); | ||
283 | |||
284 | for (i = 0; i < 4; i++) { | ||
285 | if (value & (1 << (4 + i))) | ||
286 | seq_printf(s, " gpio%d-out %s\n", i + 1, | ||
287 | (value & (1 << i)) ? "low" : "hi "); | ||
288 | else | ||
289 | seq_printf(s, " gpio%d-in %s %s %s\n", i + 1, | ||
290 | (value & (1 << i)) ? "hi " : "low", | ||
291 | (v2 & (1 << i)) ? "no-irq" : "irq", | ||
292 | (v2 & (1 << (4 + i))) ? "rising" : "falling"); | ||
293 | } | ||
294 | |||
295 | mutex_unlock(&tps->lock); | ||
296 | return 0; | ||
297 | } | ||
298 | |||
299 | static int dbg_tps_open(struct inode *inode, struct file *file) | ||
300 | { | ||
301 | return single_open(file, dbg_show, inode->i_private); | ||
302 | } | ||
303 | |||
304 | static const struct file_operations debug_fops = { | ||
305 | .open = dbg_tps_open, | ||
306 | .read = seq_read, | ||
307 | .llseek = seq_lseek, | ||
308 | .release = single_release, | ||
309 | }; | ||
310 | |||
311 | #define DEBUG_FOPS &debug_fops | ||
312 | |||
313 | #else | ||
314 | #define DEBUG_FOPS NULL | ||
315 | #endif | ||
316 | |||
317 | /*-------------------------------------------------------------------------*/ | ||
318 | |||
319 | /* handle IRQS in a task context, so we can use I2C calls */ | ||
320 | static void tps65010_interrupt(struct tps65010 *tps) | ||
321 | { | ||
322 | u8 tmp = 0, mask, poll; | ||
323 | |||
324 | /* IRQs won't trigger for certain events, but we can get | ||
325 | * others by polling (normally, with external power applied). | ||
326 | */ | ||
327 | poll = 0; | ||
328 | |||
329 | /* regstatus irqs */ | ||
330 | if (tps->nmask2) { | ||
331 | tmp = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS); | ||
332 | mask = tmp ^ tps->regstatus; | ||
333 | tps->regstatus = tmp; | ||
334 | mask &= tps->nmask2; | ||
335 | } else | ||
336 | mask = 0; | ||
337 | if (mask) { | ||
338 | tps->regstatus = tmp; | ||
339 | /* may need to shut something down ... */ | ||
340 | |||
341 | /* "off" usually means deep sleep */ | ||
342 | if (tmp & TPS_REG_ONOFF) { | ||
343 | pr_info("%s: power off button\n", DRIVER_NAME); | ||
344 | #if 0 | ||
345 | /* REVISIT: this might need its own workqueue | ||
346 | * plus tweaks including deadlock avoidance ... | ||
347 | * also needs to get error handling and probably | ||
348 | * an #ifdef CONFIG_HIBERNATION | ||
349 | */ | ||
350 | hibernate(); | ||
351 | #endif | ||
352 | poll = 1; | ||
353 | } | ||
354 | } | ||
355 | |||
356 | /* chgstatus irqs */ | ||
357 | if (tps->nmask1) { | ||
358 | tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS); | ||
359 | mask = tmp ^ tps->chgstatus; | ||
360 | tps->chgstatus = tmp; | ||
361 | mask &= tps->nmask1; | ||
362 | } else | ||
363 | mask = 0; | ||
364 | if (mask) { | ||
365 | unsigned charging = 0; | ||
366 | |||
367 | show_chgstatus("chg/irq", tmp); | ||
368 | if (tmp & (TPS_CHG_USB|TPS_CHG_AC)) | ||
369 | show_chgconfig(tps->por, "conf", tps->chgconf); | ||
370 | |||
371 | /* Unless it was turned off or disabled, we charge any | ||
372 | * battery whenever there's power available for it | ||
373 | * and the charger hasn't been disabled. | ||
374 | */ | ||
375 | if (!(tps->chgstatus & ~(TPS_CHG_USB|TPS_CHG_AC)) | ||
376 | && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC)) | ||
377 | && (tps->chgconf & TPS_CHARGE_ENABLE) | ||
378 | ) { | ||
379 | if (tps->chgstatus & TPS_CHG_USB) { | ||
380 | /* VBUS options are readonly until reconnect */ | ||
381 | if (mask & TPS_CHG_USB) | ||
382 | set_bit(FLAG_VBUS_CHANGED, &tps->flags); | ||
383 | charging = 1; | ||
384 | } else if (tps->chgstatus & TPS_CHG_AC) | ||
385 | charging = 1; | ||
386 | } | ||
387 | if (charging != tps->charging) { | ||
388 | tps->charging = charging; | ||
389 | pr_info("%s: battery %scharging\n", | ||
390 | DRIVER_NAME, charging ? "" : | ||
391 | ((tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC)) | ||
392 | ? "NOT " : "dis")); | ||
393 | } | ||
394 | } | ||
395 | |||
396 | /* always poll to detect (a) power removal, without tps65013 | ||
397 | * NO_CHG IRQ; or (b) restart of charging after stop. | ||
398 | */ | ||
399 | if ((tps->model != TPS65013 || !tps->charging) | ||
400 | && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))) | ||
401 | poll = 1; | ||
402 | if (poll) | ||
403 | (void) schedule_delayed_work(&tps->work, POWER_POLL_DELAY); | ||
404 | |||
405 | /* also potentially gpio-in rise or fall */ | ||
406 | } | ||
407 | |||
408 | /* handle IRQs and polling using keventd for now */ | ||
409 | static void tps65010_work(struct work_struct *work) | ||
410 | { | ||
411 | struct tps65010 *tps; | ||
412 | |||
413 | tps = container_of(work, struct tps65010, work.work); | ||
414 | mutex_lock(&tps->lock); | ||
415 | |||
416 | tps65010_interrupt(tps); | ||
417 | |||
418 | if (test_and_clear_bit(FLAG_VBUS_CHANGED, &tps->flags)) { | ||
419 | int status; | ||
420 | u8 chgconfig, tmp; | ||
421 | |||
422 | chgconfig = i2c_smbus_read_byte_data(tps->client, | ||
423 | TPS_CHGCONFIG); | ||
424 | chgconfig &= ~(TPS_VBUS_500MA | TPS_VBUS_CHARGING); | ||
425 | if (tps->vbus == 500) | ||
426 | chgconfig |= TPS_VBUS_500MA | TPS_VBUS_CHARGING; | ||
427 | else if (tps->vbus >= 100) | ||
428 | chgconfig |= TPS_VBUS_CHARGING; | ||
429 | |||
430 | status = i2c_smbus_write_byte_data(tps->client, | ||
431 | TPS_CHGCONFIG, chgconfig); | ||
432 | |||
433 | /* vbus update fails unless VBUS is connected! */ | ||
434 | tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG); | ||
435 | tps->chgconf = tmp; | ||
436 | show_chgconfig(tps->por, "update vbus", tmp); | ||
437 | } | ||
438 | |||
439 | if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags)) | ||
440 | enable_irq(tps->client->irq); | ||
441 | |||
442 | mutex_unlock(&tps->lock); | ||
443 | } | ||
444 | |||
445 | static irqreturn_t tps65010_irq(int irq, void *_tps) | ||
446 | { | ||
447 | struct tps65010 *tps = _tps; | ||
448 | |||
449 | disable_irq_nosync(irq); | ||
450 | set_bit(FLAG_IRQ_ENABLE, &tps->flags); | ||
451 | (void) schedule_work(&tps->work.work); | ||
452 | return IRQ_HANDLED; | ||
453 | } | ||
454 | |||
455 | /*-------------------------------------------------------------------------*/ | ||
456 | |||
457 | /* offsets 0..3 == GPIO1..GPIO4 | ||
458 | * offsets 4..5 == LED1/nPG, LED2 (we set one of the non-BLINK modes) | ||
459 | * offset 6 == vibrator motor driver | ||
460 | */ | ||
461 | static void | ||
462 | tps65010_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
463 | { | ||
464 | if (offset < 4) | ||
465 | tps65010_set_gpio_out_value(offset + 1, value); | ||
466 | else if (offset < 6) | ||
467 | tps65010_set_led(offset - 3, value ? ON : OFF); | ||
468 | else | ||
469 | tps65010_set_vib(value); | ||
470 | } | ||
471 | |||
472 | static int | ||
473 | tps65010_output(struct gpio_chip *chip, unsigned offset, int value) | ||
474 | { | ||
475 | /* GPIOs may be input-only */ | ||
476 | if (offset < 4) { | ||
477 | struct tps65010 *tps; | ||
478 | |||
479 | tps = container_of(chip, struct tps65010, chip); | ||
480 | if (!(tps->outmask & (1 << offset))) | ||
481 | return -EINVAL; | ||
482 | tps65010_set_gpio_out_value(offset + 1, value); | ||
483 | } else if (offset < 6) | ||
484 | tps65010_set_led(offset - 3, value ? ON : OFF); | ||
485 | else | ||
486 | tps65010_set_vib(value); | ||
487 | |||
488 | return 0; | ||
489 | } | ||
490 | |||
491 | static int tps65010_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
492 | { | ||
493 | int value; | ||
494 | struct tps65010 *tps; | ||
495 | |||
496 | tps = container_of(chip, struct tps65010, chip); | ||
497 | |||
498 | if (offset < 4) { | ||
499 | value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO); | ||
500 | if (value < 0) | ||
501 | return 0; | ||
502 | if (value & (1 << (offset + 4))) /* output */ | ||
503 | return !(value & (1 << offset)); | ||
504 | else /* input */ | ||
505 | return (value & (1 << offset)); | ||
506 | } | ||
507 | |||
508 | /* REVISIT we *could* report LED1/nPG and LED2 state ... */ | ||
509 | return 0; | ||
510 | } | ||
511 | |||
512 | |||
513 | /*-------------------------------------------------------------------------*/ | ||
514 | |||
515 | static struct tps65010 *the_tps; | ||
516 | |||
517 | static int __exit tps65010_remove(struct i2c_client *client) | ||
518 | { | ||
519 | struct tps65010 *tps = i2c_get_clientdata(client); | ||
520 | struct tps65010_board *board = client->dev.platform_data; | ||
521 | |||
522 | if (board && board->teardown) { | ||
523 | int status = board->teardown(client, board->context); | ||
524 | if (status < 0) | ||
525 | dev_dbg(&client->dev, "board %s %s err %d\n", | ||
526 | "teardown", client->name, status); | ||
527 | } | ||
528 | if (client->irq > 0) | ||
529 | free_irq(client->irq, tps); | ||
530 | cancel_delayed_work(&tps->work); | ||
531 | flush_scheduled_work(); | ||
532 | debugfs_remove(tps->file); | ||
533 | kfree(tps); | ||
534 | i2c_set_clientdata(client, NULL); | ||
535 | the_tps = NULL; | ||
536 | return 0; | ||
537 | } | ||
538 | |||
539 | static int tps65010_probe(struct i2c_client *client, | ||
540 | const struct i2c_device_id *id) | ||
541 | { | ||
542 | struct tps65010 *tps; | ||
543 | int status; | ||
544 | struct tps65010_board *board = client->dev.platform_data; | ||
545 | |||
546 | if (the_tps) { | ||
547 | dev_dbg(&client->dev, "only one tps6501x chip allowed\n"); | ||
548 | return -ENODEV; | ||
549 | } | ||
550 | |||
551 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
552 | return -EINVAL; | ||
553 | |||
554 | tps = kzalloc(sizeof *tps, GFP_KERNEL); | ||
555 | if (!tps) | ||
556 | return -ENOMEM; | ||
557 | |||
558 | mutex_init(&tps->lock); | ||
559 | INIT_DELAYED_WORK(&tps->work, tps65010_work); | ||
560 | tps->client = client; | ||
561 | tps->model = id->driver_data; | ||
562 | |||
563 | /* the IRQ is active low, but many gpio lines can't support that | ||
564 | * so this driver uses falling-edge triggers instead. | ||
565 | */ | ||
566 | if (client->irq > 0) { | ||
567 | status = request_irq(client->irq, tps65010_irq, | ||
568 | IRQF_SAMPLE_RANDOM | IRQF_TRIGGER_FALLING, | ||
569 | DRIVER_NAME, tps); | ||
570 | if (status < 0) { | ||
571 | dev_dbg(&client->dev, "can't get IRQ %d, err %d\n", | ||
572 | client->irq, status); | ||
573 | goto fail1; | ||
574 | } | ||
575 | /* annoying race here, ideally we'd have an option | ||
576 | * to claim the irq now and enable it later. | ||
577 | * FIXME genirq IRQF_NOAUTOEN now solves that ... | ||
578 | */ | ||
579 | disable_irq(client->irq); | ||
580 | set_bit(FLAG_IRQ_ENABLE, &tps->flags); | ||
581 | } else | ||
582 | dev_warn(&client->dev, "IRQ not configured!\n"); | ||
583 | |||
584 | |||
585 | switch (tps->model) { | ||
586 | case TPS65010: | ||
587 | case TPS65012: | ||
588 | tps->por = 1; | ||
589 | break; | ||
590 | /* else CHGCONFIG.POR is replaced by AUA, enabling a WAIT mode */ | ||
591 | } | ||
592 | tps->chgconf = i2c_smbus_read_byte_data(client, TPS_CHGCONFIG); | ||
593 | show_chgconfig(tps->por, "conf/init", tps->chgconf); | ||
594 | |||
595 | show_chgstatus("chg/init", | ||
596 | i2c_smbus_read_byte_data(client, TPS_CHGSTATUS)); | ||
597 | show_regstatus("reg/init", | ||
598 | i2c_smbus_read_byte_data(client, TPS_REGSTATUS)); | ||
599 | |||
600 | pr_debug("%s: vdcdc1 0x%02x, vdcdc2 %02x, vregs1 %02x\n", DRIVER_NAME, | ||
601 | i2c_smbus_read_byte_data(client, TPS_VDCDC1), | ||
602 | i2c_smbus_read_byte_data(client, TPS_VDCDC2), | ||
603 | i2c_smbus_read_byte_data(client, TPS_VREGS1)); | ||
604 | pr_debug("%s: defgpio 0x%02x, mask3 0x%02x\n", DRIVER_NAME, | ||
605 | i2c_smbus_read_byte_data(client, TPS_DEFGPIO), | ||
606 | i2c_smbus_read_byte_data(client, TPS_MASK3)); | ||
607 | |||
608 | i2c_set_clientdata(client, tps); | ||
609 | the_tps = tps; | ||
610 | |||
611 | #if defined(CONFIG_USB_GADGET) && !defined(CONFIG_USB_OTG) | ||
612 | /* USB hosts can't draw VBUS. OTG devices could, later | ||
613 | * when OTG infrastructure enables it. USB peripherals | ||
614 | * could be relying on VBUS while booting, though. | ||
615 | */ | ||
616 | tps->vbus = 100; | ||
617 | #endif | ||
618 | |||
619 | /* unmask the "interesting" irqs, then poll once to | ||
620 | * kickstart monitoring, initialize shadowed status | ||
621 | * registers, and maybe disable VBUS draw. | ||
622 | */ | ||
623 | tps->nmask1 = ~0; | ||
624 | (void) i2c_smbus_write_byte_data(client, TPS_MASK1, ~tps->nmask1); | ||
625 | |||
626 | tps->nmask2 = TPS_REG_ONOFF; | ||
627 | if (tps->model == TPS65013) | ||
628 | tps->nmask2 |= TPS_REG_NO_CHG; | ||
629 | (void) i2c_smbus_write_byte_data(client, TPS_MASK2, ~tps->nmask2); | ||
630 | |||
631 | (void) i2c_smbus_write_byte_data(client, TPS_MASK3, 0x0f | ||
632 | | i2c_smbus_read_byte_data(client, TPS_MASK3)); | ||
633 | |||
634 | tps65010_work(&tps->work.work); | ||
635 | |||
636 | tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL, | ||
637 | tps, DEBUG_FOPS); | ||
638 | |||
639 | /* optionally register GPIOs */ | ||
640 | if (board && board->base > 0) { | ||
641 | tps->outmask = board->outmask; | ||
642 | |||
643 | tps->chip.label = client->name; | ||
644 | tps->chip.dev = &client->dev; | ||
645 | tps->chip.owner = THIS_MODULE; | ||
646 | |||
647 | tps->chip.set = tps65010_gpio_set; | ||
648 | tps->chip.direction_output = tps65010_output; | ||
649 | |||
650 | /* NOTE: only partial support for inputs; nyet IRQs */ | ||
651 | tps->chip.get = tps65010_gpio_get; | ||
652 | |||
653 | tps->chip.base = board->base; | ||
654 | tps->chip.ngpio = 7; | ||
655 | tps->chip.can_sleep = 1; | ||
656 | |||
657 | status = gpiochip_add(&tps->chip); | ||
658 | if (status < 0) | ||
659 | dev_err(&client->dev, "can't add gpiochip, err %d\n", | ||
660 | status); | ||
661 | else if (board->setup) { | ||
662 | status = board->setup(client, board->context); | ||
663 | if (status < 0) { | ||
664 | dev_dbg(&client->dev, | ||
665 | "board %s %s err %d\n", | ||
666 | "setup", client->name, status); | ||
667 | status = 0; | ||
668 | } | ||
669 | } | ||
670 | } | ||
671 | |||
672 | return 0; | ||
673 | fail1: | ||
674 | kfree(tps); | ||
675 | return status; | ||
676 | } | ||
677 | |||
678 | static const struct i2c_device_id tps65010_id[] = { | ||
679 | { "tps65010", TPS65010 }, | ||
680 | { "tps65011", TPS65011 }, | ||
681 | { "tps65012", TPS65012 }, | ||
682 | { "tps65013", TPS65013 }, | ||
683 | { "tps65014", TPS65011 }, /* tps65011 charging at 6.5V max */ | ||
684 | { } | ||
685 | }; | ||
686 | MODULE_DEVICE_TABLE(i2c, tps65010_id); | ||
687 | |||
688 | static struct i2c_driver tps65010_driver = { | ||
689 | .driver = { | ||
690 | .name = "tps65010", | ||
691 | }, | ||
692 | .probe = tps65010_probe, | ||
693 | .remove = __exit_p(tps65010_remove), | ||
694 | .id_table = tps65010_id, | ||
695 | }; | ||
696 | |||
697 | /*-------------------------------------------------------------------------*/ | ||
698 | |||
699 | /* Draw from VBUS: | ||
700 | * 0 mA -- DON'T DRAW (might supply power instead) | ||
701 | * 100 mA -- usb unit load (slowest charge rate) | ||
702 | * 500 mA -- usb high power (fast battery charge) | ||
703 | */ | ||
704 | int tps65010_set_vbus_draw(unsigned mA) | ||
705 | { | ||
706 | unsigned long flags; | ||
707 | |||
708 | if (!the_tps) | ||
709 | return -ENODEV; | ||
710 | |||
711 | /* assumes non-SMP */ | ||
712 | local_irq_save(flags); | ||
713 | if (mA >= 500) | ||
714 | mA = 500; | ||
715 | else if (mA >= 100) | ||
716 | mA = 100; | ||
717 | else | ||
718 | mA = 0; | ||
719 | the_tps->vbus = mA; | ||
720 | if ((the_tps->chgstatus & TPS_CHG_USB) | ||
721 | && test_and_set_bit( | ||
722 | FLAG_VBUS_CHANGED, &the_tps->flags)) { | ||
723 | /* gadget drivers call this in_irq() */ | ||
724 | (void) schedule_work(&the_tps->work.work); | ||
725 | } | ||
726 | local_irq_restore(flags); | ||
727 | |||
728 | return 0; | ||
729 | } | ||
730 | EXPORT_SYMBOL(tps65010_set_vbus_draw); | ||
731 | |||
732 | /*-------------------------------------------------------------------------*/ | ||
733 | /* tps65010_set_gpio_out_value parameter: | ||
734 | * gpio: GPIO1, GPIO2, GPIO3 or GPIO4 | ||
735 | * value: LOW or HIGH | ||
736 | */ | ||
737 | int tps65010_set_gpio_out_value(unsigned gpio, unsigned value) | ||
738 | { | ||
739 | int status; | ||
740 | unsigned defgpio; | ||
741 | |||
742 | if (!the_tps) | ||
743 | return -ENODEV; | ||
744 | if ((gpio < GPIO1) || (gpio > GPIO4)) | ||
745 | return -EINVAL; | ||
746 | |||
747 | mutex_lock(&the_tps->lock); | ||
748 | |||
749 | defgpio = i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO); | ||
750 | |||
751 | /* Configure GPIO for output */ | ||
752 | defgpio |= 1 << (gpio + 3); | ||
753 | |||
754 | /* Writing 1 forces a logic 0 on that GPIO and vice versa */ | ||
755 | switch (value) { | ||
756 | case LOW: | ||
757 | defgpio |= 1 << (gpio - 1); /* set GPIO low by writing 1 */ | ||
758 | break; | ||
759 | /* case HIGH: */ | ||
760 | default: | ||
761 | defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */ | ||
762 | break; | ||
763 | } | ||
764 | |||
765 | status = i2c_smbus_write_byte_data(the_tps->client, | ||
766 | TPS_DEFGPIO, defgpio); | ||
767 | |||
768 | pr_debug("%s: gpio%dout = %s, defgpio 0x%02x\n", DRIVER_NAME, | ||
769 | gpio, value ? "high" : "low", | ||
770 | i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO)); | ||
771 | |||
772 | mutex_unlock(&the_tps->lock); | ||
773 | return status; | ||
774 | } | ||
775 | EXPORT_SYMBOL(tps65010_set_gpio_out_value); | ||
776 | |||
777 | /*-------------------------------------------------------------------------*/ | ||
778 | /* tps65010_set_led parameter: | ||
779 | * led: LED1 or LED2 | ||
780 | * mode: ON, OFF or BLINK | ||
781 | */ | ||
782 | int tps65010_set_led(unsigned led, unsigned mode) | ||
783 | { | ||
784 | int status; | ||
785 | unsigned led_on, led_per, offs; | ||
786 | |||
787 | if (!the_tps) | ||
788 | return -ENODEV; | ||
789 | |||
790 | if (led == LED1) | ||
791 | offs = 0; | ||
792 | else { | ||
793 | offs = 2; | ||
794 | led = LED2; | ||
795 | } | ||
796 | |||
797 | mutex_lock(&the_tps->lock); | ||
798 | |||
799 | pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led, | ||
800 | i2c_smbus_read_byte_data(the_tps->client, | ||
801 | TPS_LED1_ON + offs)); | ||
802 | |||
803 | pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led, | ||
804 | i2c_smbus_read_byte_data(the_tps->client, | ||
805 | TPS_LED1_PER + offs)); | ||
806 | |||
807 | switch (mode) { | ||
808 | case OFF: | ||
809 | led_on = 1 << 7; | ||
810 | led_per = 0 << 7; | ||
811 | break; | ||
812 | case ON: | ||
813 | led_on = 1 << 7; | ||
814 | led_per = 1 << 7; | ||
815 | break; | ||
816 | case BLINK: | ||
817 | led_on = 0x30 | (0 << 7); | ||
818 | led_per = 0x08 | (1 << 7); | ||
819 | break; | ||
820 | default: | ||
821 | printk(KERN_ERR "%s: Wrong mode parameter for set_led()\n", | ||
822 | DRIVER_NAME); | ||
823 | mutex_unlock(&the_tps->lock); | ||
824 | return -EINVAL; | ||
825 | } | ||
826 | |||
827 | status = i2c_smbus_write_byte_data(the_tps->client, | ||
828 | TPS_LED1_ON + offs, led_on); | ||
829 | |||
830 | if (status != 0) { | ||
831 | printk(KERN_ERR "%s: Failed to write led%i_on register\n", | ||
832 | DRIVER_NAME, led); | ||
833 | mutex_unlock(&the_tps->lock); | ||
834 | return status; | ||
835 | } | ||
836 | |||
837 | pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led, | ||
838 | i2c_smbus_read_byte_data(the_tps->client, TPS_LED1_ON + offs)); | ||
839 | |||
840 | status = i2c_smbus_write_byte_data(the_tps->client, | ||
841 | TPS_LED1_PER + offs, led_per); | ||
842 | |||
843 | if (status != 0) { | ||
844 | printk(KERN_ERR "%s: Failed to write led%i_per register\n", | ||
845 | DRIVER_NAME, led); | ||
846 | mutex_unlock(&the_tps->lock); | ||
847 | return status; | ||
848 | } | ||
849 | |||
850 | pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led, | ||
851 | i2c_smbus_read_byte_data(the_tps->client, | ||
852 | TPS_LED1_PER + offs)); | ||
853 | |||
854 | mutex_unlock(&the_tps->lock); | ||
855 | |||
856 | return status; | ||
857 | } | ||
858 | EXPORT_SYMBOL(tps65010_set_led); | ||
859 | |||
860 | /*-------------------------------------------------------------------------*/ | ||
861 | /* tps65010_set_vib parameter: | ||
862 | * value: ON or OFF | ||
863 | */ | ||
864 | int tps65010_set_vib(unsigned value) | ||
865 | { | ||
866 | int status; | ||
867 | unsigned vdcdc2; | ||
868 | |||
869 | if (!the_tps) | ||
870 | return -ENODEV; | ||
871 | |||
872 | mutex_lock(&the_tps->lock); | ||
873 | |||
874 | vdcdc2 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC2); | ||
875 | vdcdc2 &= ~(1 << 1); | ||
876 | if (value) | ||
877 | vdcdc2 |= (1 << 1); | ||
878 | status = i2c_smbus_write_byte_data(the_tps->client, | ||
879 | TPS_VDCDC2, vdcdc2); | ||
880 | |||
881 | pr_debug("%s: vibrator %s\n", DRIVER_NAME, value ? "on" : "off"); | ||
882 | |||
883 | mutex_unlock(&the_tps->lock); | ||
884 | return status; | ||
885 | } | ||
886 | EXPORT_SYMBOL(tps65010_set_vib); | ||
887 | |||
888 | /*-------------------------------------------------------------------------*/ | ||
889 | /* tps65010_set_low_pwr parameter: | ||
890 | * mode: ON or OFF | ||
891 | */ | ||
892 | int tps65010_set_low_pwr(unsigned mode) | ||
893 | { | ||
894 | int status; | ||
895 | unsigned vdcdc1; | ||
896 | |||
897 | if (!the_tps) | ||
898 | return -ENODEV; | ||
899 | |||
900 | mutex_lock(&the_tps->lock); | ||
901 | |||
902 | pr_debug("%s: %s low_pwr, vdcdc1 0x%02x\n", DRIVER_NAME, | ||
903 | mode ? "enable" : "disable", | ||
904 | i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); | ||
905 | |||
906 | vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1); | ||
907 | |||
908 | switch (mode) { | ||
909 | case OFF: | ||
910 | vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */ | ||
911 | break; | ||
912 | /* case ON: */ | ||
913 | default: | ||
914 | vdcdc1 |= TPS_ENABLE_LP; /* enable ENABLE_LP bit */ | ||
915 | break; | ||
916 | } | ||
917 | |||
918 | status = i2c_smbus_write_byte_data(the_tps->client, | ||
919 | TPS_VDCDC1, vdcdc1); | ||
920 | |||
921 | if (status != 0) | ||
922 | printk(KERN_ERR "%s: Failed to write vdcdc1 register\n", | ||
923 | DRIVER_NAME); | ||
924 | else | ||
925 | pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME, | ||
926 | i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); | ||
927 | |||
928 | mutex_unlock(&the_tps->lock); | ||
929 | |||
930 | return status; | ||
931 | } | ||
932 | EXPORT_SYMBOL(tps65010_set_low_pwr); | ||
933 | |||
934 | /*-------------------------------------------------------------------------*/ | ||
935 | /* tps65010_config_vregs1 parameter: | ||
936 | * value to be written to VREGS1 register | ||
937 | * Note: The complete register is written, set all bits you need | ||
938 | */ | ||
939 | int tps65010_config_vregs1(unsigned value) | ||
940 | { | ||
941 | int status; | ||
942 | |||
943 | if (!the_tps) | ||
944 | return -ENODEV; | ||
945 | |||
946 | mutex_lock(&the_tps->lock); | ||
947 | |||
948 | pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME, | ||
949 | i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1)); | ||
950 | |||
951 | status = i2c_smbus_write_byte_data(the_tps->client, | ||
952 | TPS_VREGS1, value); | ||
953 | |||
954 | if (status != 0) | ||
955 | printk(KERN_ERR "%s: Failed to write vregs1 register\n", | ||
956 | DRIVER_NAME); | ||
957 | else | ||
958 | pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME, | ||
959 | i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1)); | ||
960 | |||
961 | mutex_unlock(&the_tps->lock); | ||
962 | |||
963 | return status; | ||
964 | } | ||
965 | EXPORT_SYMBOL(tps65010_config_vregs1); | ||
966 | |||
967 | /*-------------------------------------------------------------------------*/ | ||
968 | /* tps65013_set_low_pwr parameter: | ||
969 | * mode: ON or OFF | ||
970 | */ | ||
971 | |||
972 | /* FIXME: Assumes AC or USB power is present. Setting AUA bit is not | ||
973 | required if power supply is through a battery */ | ||
974 | |||
975 | int tps65013_set_low_pwr(unsigned mode) | ||
976 | { | ||
977 | int status; | ||
978 | unsigned vdcdc1, chgconfig; | ||
979 | |||
980 | if (!the_tps || the_tps->por) | ||
981 | return -ENODEV; | ||
982 | |||
983 | mutex_lock(&the_tps->lock); | ||
984 | |||
985 | pr_debug("%s: %s low_pwr, chgconfig 0x%02x vdcdc1 0x%02x\n", | ||
986 | DRIVER_NAME, | ||
987 | mode ? "enable" : "disable", | ||
988 | i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG), | ||
989 | i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); | ||
990 | |||
991 | chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG); | ||
992 | vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1); | ||
993 | |||
994 | switch (mode) { | ||
995 | case OFF: | ||
996 | chgconfig &= ~TPS65013_AUA; /* disable AUA bit */ | ||
997 | vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */ | ||
998 | break; | ||
999 | /* case ON: */ | ||
1000 | default: | ||
1001 | chgconfig |= TPS65013_AUA; /* enable AUA bit */ | ||
1002 | vdcdc1 |= TPS_ENABLE_LP; /* enable ENABLE_LP bit */ | ||
1003 | break; | ||
1004 | } | ||
1005 | |||
1006 | status = i2c_smbus_write_byte_data(the_tps->client, | ||
1007 | TPS_CHGCONFIG, chgconfig); | ||
1008 | if (status != 0) { | ||
1009 | printk(KERN_ERR "%s: Failed to write chconfig register\n", | ||
1010 | DRIVER_NAME); | ||
1011 | mutex_unlock(&the_tps->lock); | ||
1012 | return status; | ||
1013 | } | ||
1014 | |||
1015 | chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG); | ||
1016 | the_tps->chgconf = chgconfig; | ||
1017 | show_chgconfig(0, "chgconf", chgconfig); | ||
1018 | |||
1019 | status = i2c_smbus_write_byte_data(the_tps->client, | ||
1020 | TPS_VDCDC1, vdcdc1); | ||
1021 | |||
1022 | if (status != 0) | ||
1023 | printk(KERN_ERR "%s: Failed to write vdcdc1 register\n", | ||
1024 | DRIVER_NAME); | ||
1025 | else | ||
1026 | pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME, | ||
1027 | i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); | ||
1028 | |||
1029 | mutex_unlock(&the_tps->lock); | ||
1030 | |||
1031 | return status; | ||
1032 | } | ||
1033 | EXPORT_SYMBOL(tps65013_set_low_pwr); | ||
1034 | |||
1035 | /*-------------------------------------------------------------------------*/ | ||
1036 | |||
1037 | static int __init tps_init(void) | ||
1038 | { | ||
1039 | u32 tries = 3; | ||
1040 | int status = -ENODEV; | ||
1041 | |||
1042 | printk(KERN_INFO "%s: version %s\n", DRIVER_NAME, DRIVER_VERSION); | ||
1043 | |||
1044 | /* some boards have startup glitches */ | ||
1045 | while (tries--) { | ||
1046 | status = i2c_add_driver(&tps65010_driver); | ||
1047 | if (the_tps) | ||
1048 | break; | ||
1049 | i2c_del_driver(&tps65010_driver); | ||
1050 | if (!tries) { | ||
1051 | printk(KERN_ERR "%s: no chip?\n", DRIVER_NAME); | ||
1052 | return -ENODEV; | ||
1053 | } | ||
1054 | pr_debug("%s: re-probe ...\n", DRIVER_NAME); | ||
1055 | msleep(10); | ||
1056 | } | ||
1057 | |||
1058 | return status; | ||
1059 | } | ||
1060 | /* NOTE: this MUST be initialized before the other parts of the system | ||
1061 | * that rely on it ... but after the i2c bus on which this relies. | ||
1062 | * That is, much earlier than on PC-type systems, which don't often use | ||
1063 | * I2C as a core system bus. | ||
1064 | */ | ||
1065 | subsys_initcall(tps_init); | ||
1066 | |||
1067 | static void __exit tps_exit(void) | ||
1068 | { | ||
1069 | i2c_del_driver(&tps65010_driver); | ||
1070 | } | ||
1071 | module_exit(tps_exit); | ||
1072 | |||