blob: e320994b981cdd1b7f08f52f79ca5208298c9e0b [file] [log] [blame]
David Brownell72cd7992005-05-24 17:34:51 -07001/*
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 */
David Brownell72cd7992005-05-24 17:34:51 -070021
David Brownell72cd7992005-05-24 17:34:51 -070022#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/slab.h>
26#include <linux/interrupt.h>
David Brownell72cd7992005-05-24 17:34:51 -070027#include <linux/i2c.h>
28#include <linux/delay.h>
29#include <linux/workqueue.h>
David Brownell72cd7992005-05-24 17:34:51 -070030#include <linux/debugfs.h>
31#include <linux/seq_file.h>
Ingo Molnar5c085d32006-01-18 23:16:04 +010032#include <linux/mutex.h>
David Brownell72cd7992005-05-24 17:34:51 -070033
David Brownell72cd7992005-05-24 17:34:51 -070034#include <asm/arch/tps65010.h>
35
36/*-------------------------------------------------------------------------*/
37
38#define DRIVER_VERSION "2 May 2005"
David Brownell4801bc22006-08-11 22:53:08 +020039#define DRIVER_NAME (tps65010_driver.driver.name)
David Brownell72cd7992005-05-24 17:34:51 -070040
41MODULE_DESCRIPTION("TPS6501x Power Management Driver");
42MODULE_LICENSE("GPL");
43
David Brownell72cd7992005-05-24 17:34:51 -070044static struct i2c_driver tps65010_driver;
45
46/*-------------------------------------------------------------------------*/
47
48/* This driver handles a family of multipurpose chips, which incorporate
49 * voltage regulators, lithium ion/polymer battery charging, GPIOs, LEDs,
50 * and other features often needed in portable devices like cell phones
51 * or digital cameras.
52 *
53 * The tps65011 and tps65013 have different voltage settings compared
54 * to tps65010 and tps65012. The tps65013 has a NO_CHG status/irq.
55 * All except tps65010 have "wait" mode, possibly defaulted so that
56 * battery-insert != device-on.
57 *
58 * We could distinguish between some models by checking VDCDC1.UVLO or
59 * other registers, unless they've been changed already after powerup
60 * as part of board setup by a bootloader.
61 */
62enum tps_model {
63 TPS_UNKNOWN = 0,
64 TPS65010,
65 TPS65011,
66 TPS65012,
67 TPS65013,
68};
69
70struct tps65010 {
David Brownellb5067f82007-10-13 23:56:30 +020071 struct i2c_client *client;
Ingo Molnar5c085d32006-01-18 23:16:04 +010072 struct mutex lock;
David Brownell8c1bc04e2006-12-13 00:33:46 -080073 struct delayed_work work;
David Brownell72cd7992005-05-24 17:34:51 -070074 struct dentry *file;
75 unsigned charging:1;
76 unsigned por:1;
77 unsigned model:8;
78 u16 vbus;
79 unsigned long flags;
80#define FLAG_VBUS_CHANGED 0
81#define FLAG_IRQ_ENABLE 1
82
83 /* copies of last register state */
84 u8 chgstatus, regstatus, chgconf;
85 u8 nmask1, nmask2;
86
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -070087 /* not currently tracking GPIO state */
David Brownell72cd7992005-05-24 17:34:51 -070088};
89
David Brownell4801bc22006-08-11 22:53:08 +020090#define POWER_POLL_DELAY msecs_to_jiffies(5000)
David Brownell72cd7992005-05-24 17:34:51 -070091
92/*-------------------------------------------------------------------------*/
93
94#if defined(DEBUG) || defined(CONFIG_DEBUG_FS)
95
96static void dbg_chgstat(char *buf, size_t len, u8 chgstatus)
97{
98 snprintf(buf, len, "%02x%s%s%s%s%s%s%s%s\n",
99 chgstatus,
100 (chgstatus & TPS_CHG_USB) ? " USB" : "",
101 (chgstatus & TPS_CHG_AC) ? " AC" : "",
102 (chgstatus & TPS_CHG_THERM) ? " therm" : "",
103 (chgstatus & TPS_CHG_TERM) ? " done" :
104 ((chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
105 ? " (charging)" : ""),
106 (chgstatus & TPS_CHG_TAPER_TMO) ? " taper_tmo" : "",
107 (chgstatus & TPS_CHG_CHG_TMO) ? " charge_tmo" : "",
108 (chgstatus & TPS_CHG_PRECHG_TMO) ? " prechg_tmo" : "",
109 (chgstatus & TPS_CHG_TEMP_ERR) ? " temp_err" : "");
110}
111
112static void dbg_regstat(char *buf, size_t len, u8 regstatus)
113{
114 snprintf(buf, len, "%02x %s%s%s%s%s%s%s%s\n",
115 regstatus,
116 (regstatus & TPS_REG_ONOFF) ? "off" : "(on)",
117 (regstatus & TPS_REG_COVER) ? " uncover" : "",
118 (regstatus & TPS_REG_UVLO) ? " UVLO" : "",
119 (regstatus & TPS_REG_NO_CHG) ? " NO_CHG" : "",
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700120 (regstatus & TPS_REG_PG_LD02) ? " ld02_bad" : "",
David Brownell72cd7992005-05-24 17:34:51 -0700121 (regstatus & TPS_REG_PG_LD01) ? " ld01_bad" : "",
122 (regstatus & TPS_REG_PG_MAIN) ? " main_bad" : "",
123 (regstatus & TPS_REG_PG_CORE) ? " core_bad" : "");
124}
125
126static void dbg_chgconf(int por, char *buf, size_t len, u8 chgconfig)
127{
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700128 const char *hibit;
David Brownell72cd7992005-05-24 17:34:51 -0700129
130 if (por)
131 hibit = (chgconfig & TPS_CHARGE_POR)
132 ? "POR=69ms" : "POR=1sec";
133 else
134 hibit = (chgconfig & TPS65013_AUA) ? "AUA" : "";
135
136 snprintf(buf, len, "%02x %s%s%s AC=%d%% USB=%dmA %sCharge\n",
137 chgconfig, hibit,
138 (chgconfig & TPS_CHARGE_RESET) ? " reset" : "",
139 (chgconfig & TPS_CHARGE_FAST) ? " fast" : "",
140 ({int p; switch ((chgconfig >> 3) & 3) {
141 case 3: p = 100; break;
142 case 2: p = 75; break;
143 case 1: p = 50; break;
144 default: p = 25; break;
145 }; p; }),
146 (chgconfig & TPS_VBUS_CHARGING)
147 ? ((chgconfig & TPS_VBUS_500MA) ? 500 : 100)
148 : 0,
149 (chgconfig & TPS_CHARGE_ENABLE) ? "" : "No");
150}
151
152#endif
153
154#ifdef DEBUG
155
156static void show_chgstatus(const char *label, u8 chgstatus)
157{
158 char buf [100];
159
160 dbg_chgstat(buf, sizeof buf, chgstatus);
161 pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
162}
163
164static void show_regstatus(const char *label, u8 regstatus)
165{
166 char buf [100];
167
168 dbg_regstat(buf, sizeof buf, regstatus);
169 pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
170}
171
172static void show_chgconfig(int por, const char *label, u8 chgconfig)
173{
174 char buf [100];
175
176 dbg_chgconf(por, buf, sizeof buf, chgconfig);
177 pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
178}
179
180#else
181
182static inline void show_chgstatus(const char *label, u8 chgstatus) { }
183static inline void show_regstatus(const char *label, u8 chgstatus) { }
184static inline void show_chgconfig(int por, const char *label, u8 chgconfig) { }
185
186#endif
187
188#ifdef CONFIG_DEBUG_FS
189
190static int dbg_show(struct seq_file *s, void *_)
191{
192 struct tps65010 *tps = s->private;
193 u8 value, v2;
194 unsigned i;
195 char buf[100];
196 const char *chip;
197
198 switch (tps->model) {
199 case TPS65010: chip = "tps65010"; break;
200 case TPS65011: chip = "tps65011"; break;
201 case TPS65012: chip = "tps65012"; break;
202 case TPS65013: chip = "tps65013"; break;
203 default: chip = NULL; break;
204 }
205 seq_printf(s, "driver %s\nversion %s\nchip %s\n\n",
206 DRIVER_NAME, DRIVER_VERSION, chip);
207
Ingo Molnar5c085d32006-01-18 23:16:04 +0100208 mutex_lock(&tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700209
210 /* FIXME how can we tell whether a battery is present?
211 * likely involves a charge gauging chip (like BQ26501).
212 */
213
214 seq_printf(s, "%scharging\n\n", tps->charging ? "" : "(not) ");
215
216
217 /* registers for monitoring battery charging and status; note
218 * that reading chgstat and regstat may ack IRQs...
219 */
David Brownellb5067f82007-10-13 23:56:30 +0200220 value = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG);
David Brownell72cd7992005-05-24 17:34:51 -0700221 dbg_chgconf(tps->por, buf, sizeof buf, value);
222 seq_printf(s, "chgconfig %s", buf);
223
David Brownellb5067f82007-10-13 23:56:30 +0200224 value = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS);
David Brownell72cd7992005-05-24 17:34:51 -0700225 dbg_chgstat(buf, sizeof buf, value);
226 seq_printf(s, "chgstat %s", buf);
David Brownellb5067f82007-10-13 23:56:30 +0200227 value = i2c_smbus_read_byte_data(tps->client, TPS_MASK1);
David Brownell72cd7992005-05-24 17:34:51 -0700228 dbg_chgstat(buf, sizeof buf, value);
229 seq_printf(s, "mask1 %s", buf);
230 /* ignore ackint1 */
231
David Brownellb5067f82007-10-13 23:56:30 +0200232 value = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS);
David Brownell72cd7992005-05-24 17:34:51 -0700233 dbg_regstat(buf, sizeof buf, value);
234 seq_printf(s, "regstat %s", buf);
David Brownellb5067f82007-10-13 23:56:30 +0200235 value = i2c_smbus_read_byte_data(tps->client, TPS_MASK2);
David Brownell72cd7992005-05-24 17:34:51 -0700236 dbg_regstat(buf, sizeof buf, value);
237 seq_printf(s, "mask2 %s\n", buf);
238 /* ignore ackint2 */
239
240 (void) schedule_delayed_work(&tps->work, POWER_POLL_DELAY);
241
242
243 /* VMAIN voltage, enable lowpower, etc */
David Brownellb5067f82007-10-13 23:56:30 +0200244 value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC1);
David Brownell72cd7992005-05-24 17:34:51 -0700245 seq_printf(s, "vdcdc1 %02x\n", value);
246
247 /* VCORE voltage, vibrator on/off */
David Brownellb5067f82007-10-13 23:56:30 +0200248 value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC2);
David Brownell72cd7992005-05-24 17:34:51 -0700249 seq_printf(s, "vdcdc2 %02x\n", value);
250
251 /* both LD0s, and their lowpower behavior */
David Brownellb5067f82007-10-13 23:56:30 +0200252 value = i2c_smbus_read_byte_data(tps->client, TPS_VREGS1);
David Brownell72cd7992005-05-24 17:34:51 -0700253 seq_printf(s, "vregs1 %02x\n\n", value);
254
255
256 /* LEDs and GPIOs */
David Brownellb5067f82007-10-13 23:56:30 +0200257 value = i2c_smbus_read_byte_data(tps->client, TPS_LED1_ON);
258 v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED1_PER);
David Brownell72cd7992005-05-24 17:34:51 -0700259 seq_printf(s, "led1 %s, on=%02x, per=%02x, %d/%d msec\n",
260 (value & 0x80)
261 ? ((v2 & 0x80) ? "on" : "off")
262 : ((v2 & 0x80) ? "blink" : "(nPG)"),
263 value, v2,
264 (value & 0x7f) * 10, (v2 & 0x7f) * 100);
265
David Brownellb5067f82007-10-13 23:56:30 +0200266 value = i2c_smbus_read_byte_data(tps->client, TPS_LED2_ON);
267 v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED2_PER);
David Brownell72cd7992005-05-24 17:34:51 -0700268 seq_printf(s, "led2 %s, on=%02x, per=%02x, %d/%d msec\n",
269 (value & 0x80)
270 ? ((v2 & 0x80) ? "on" : "off")
271 : ((v2 & 0x80) ? "blink" : "off"),
272 value, v2,
273 (value & 0x7f) * 10, (v2 & 0x7f) * 100);
274
David Brownellb5067f82007-10-13 23:56:30 +0200275 value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO);
276 v2 = i2c_smbus_read_byte_data(tps->client, TPS_MASK3);
David Brownell72cd7992005-05-24 17:34:51 -0700277 seq_printf(s, "defgpio %02x mask3 %02x\n", value, v2);
278
279 for (i = 0; i < 4; i++) {
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700280 if (value & (1 << (4 + i)))
David Brownell72cd7992005-05-24 17:34:51 -0700281 seq_printf(s, " gpio%d-out %s\n", i + 1,
282 (value & (1 << i)) ? "low" : "hi ");
283 else
284 seq_printf(s, " gpio%d-in %s %s %s\n", i + 1,
285 (value & (1 << i)) ? "hi " : "low",
286 (v2 & (1 << i)) ? "no-irq" : "irq",
287 (v2 & (1 << (4 + i))) ? "rising" : "falling");
288 }
289
Ingo Molnar5c085d32006-01-18 23:16:04 +0100290 mutex_unlock(&tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700291 return 0;
292}
293
294static int dbg_tps_open(struct inode *inode, struct file *file)
295{
Theodore Ts'o8e18e292006-09-27 01:50:46 -0700296 return single_open(file, dbg_show, inode->i_private);
David Brownell72cd7992005-05-24 17:34:51 -0700297}
298
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800299static const struct file_operations debug_fops = {
David Brownell72cd7992005-05-24 17:34:51 -0700300 .open = dbg_tps_open,
301 .read = seq_read,
302 .llseek = seq_lseek,
303 .release = single_release,
304};
305
306#define DEBUG_FOPS &debug_fops
307
308#else
309#define DEBUG_FOPS NULL
310#endif
311
312/*-------------------------------------------------------------------------*/
313
314/* handle IRQS in a task context, so we can use I2C calls */
315static void tps65010_interrupt(struct tps65010 *tps)
316{
317 u8 tmp = 0, mask, poll;
318
David Brownell8c1bc04e2006-12-13 00:33:46 -0800319 /* IRQs won't trigger for certain events, but we can get
David Brownell72cd7992005-05-24 17:34:51 -0700320 * others by polling (normally, with external power applied).
321 */
322 poll = 0;
323
324 /* regstatus irqs */
325 if (tps->nmask2) {
David Brownellb5067f82007-10-13 23:56:30 +0200326 tmp = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS);
David Brownell72cd7992005-05-24 17:34:51 -0700327 mask = tmp ^ tps->regstatus;
328 tps->regstatus = tmp;
329 mask &= tps->nmask2;
330 } else
331 mask = 0;
332 if (mask) {
333 tps->regstatus = tmp;
334 /* may need to shut something down ... */
335
336 /* "off" usually means deep sleep */
337 if (tmp & TPS_REG_ONOFF) {
338 pr_info("%s: power off button\n", DRIVER_NAME);
339#if 0
340 /* REVISIT: this might need its own workqueue
341 * plus tweaks including deadlock avoidance ...
Johannes Bergab3bfca2007-05-06 14:50:49 -0700342 * also needs to get error handling and probably
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200343 * an #ifdef CONFIG_HIBERNATION
David Brownell72cd7992005-05-24 17:34:51 -0700344 */
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700345 hibernate();
David Brownell72cd7992005-05-24 17:34:51 -0700346#endif
347 poll = 1;
348 }
349 }
350
351 /* chgstatus irqs */
352 if (tps->nmask1) {
David Brownellb5067f82007-10-13 23:56:30 +0200353 tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS);
David Brownell72cd7992005-05-24 17:34:51 -0700354 mask = tmp ^ tps->chgstatus;
355 tps->chgstatus = tmp;
356 mask &= tps->nmask1;
357 } else
358 mask = 0;
359 if (mask) {
360 unsigned charging = 0;
361
362 show_chgstatus("chg/irq", tmp);
363 if (tmp & (TPS_CHG_USB|TPS_CHG_AC))
364 show_chgconfig(tps->por, "conf", tps->chgconf);
365
366 /* Unless it was turned off or disabled, we charge any
367 * battery whenever there's power available for it
368 * and the charger hasn't been disabled.
369 */
370 if (!(tps->chgstatus & ~(TPS_CHG_USB|TPS_CHG_AC))
371 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
372 && (tps->chgconf & TPS_CHARGE_ENABLE)
373 ) {
374 if (tps->chgstatus & TPS_CHG_USB) {
375 /* VBUS options are readonly until reconnect */
376 if (mask & TPS_CHG_USB)
377 set_bit(FLAG_VBUS_CHANGED, &tps->flags);
378 charging = 1;
379 } else if (tps->chgstatus & TPS_CHG_AC)
380 charging = 1;
381 }
382 if (charging != tps->charging) {
383 tps->charging = charging;
384 pr_info("%s: battery %scharging\n",
385 DRIVER_NAME, charging ? "" :
386 ((tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
387 ? "NOT " : "dis"));
388 }
389 }
390
391 /* always poll to detect (a) power removal, without tps65013
392 * NO_CHG IRQ; or (b) restart of charging after stop.
393 */
394 if ((tps->model != TPS65013 || !tps->charging)
395 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC)))
396 poll = 1;
397 if (poll)
398 (void) schedule_delayed_work(&tps->work, POWER_POLL_DELAY);
399
400 /* also potentially gpio-in rise or fall */
401}
402
403/* handle IRQs and polling using keventd for now */
David Brownell8c1bc04e2006-12-13 00:33:46 -0800404static void tps65010_work(struct work_struct *work)
David Brownell72cd7992005-05-24 17:34:51 -0700405{
David Brownell8c1bc04e2006-12-13 00:33:46 -0800406 struct tps65010 *tps;
David Brownell72cd7992005-05-24 17:34:51 -0700407
David Brownell8c1bc04e2006-12-13 00:33:46 -0800408 tps = container_of(work, struct tps65010, work.work);
Ingo Molnar5c085d32006-01-18 23:16:04 +0100409 mutex_lock(&tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700410
411 tps65010_interrupt(tps);
412
413 if (test_and_clear_bit(FLAG_VBUS_CHANGED, &tps->flags)) {
414 int status;
415 u8 chgconfig, tmp;
416
David Brownellb5067f82007-10-13 23:56:30 +0200417 chgconfig = i2c_smbus_read_byte_data(tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700418 TPS_CHGCONFIG);
419 chgconfig &= ~(TPS_VBUS_500MA | TPS_VBUS_CHARGING);
420 if (tps->vbus == 500)
421 chgconfig |= TPS_VBUS_500MA | TPS_VBUS_CHARGING;
422 else if (tps->vbus >= 100)
423 chgconfig |= TPS_VBUS_CHARGING;
424
David Brownellb5067f82007-10-13 23:56:30 +0200425 status = i2c_smbus_write_byte_data(tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700426 TPS_CHGCONFIG, chgconfig);
427
428 /* vbus update fails unless VBUS is connected! */
David Brownellb5067f82007-10-13 23:56:30 +0200429 tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG);
David Brownell72cd7992005-05-24 17:34:51 -0700430 tps->chgconf = tmp;
431 show_chgconfig(tps->por, "update vbus", tmp);
432 }
433
434 if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags))
David Brownell8056c6c2007-10-13 23:56:30 +0200435 enable_irq(tps->client->irq);
David Brownell72cd7992005-05-24 17:34:51 -0700436
Ingo Molnar5c085d32006-01-18 23:16:04 +0100437 mutex_unlock(&tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700438}
439
David Howells7d12e782006-10-05 14:55:46 +0100440static irqreturn_t tps65010_irq(int irq, void *_tps)
David Brownell72cd7992005-05-24 17:34:51 -0700441{
442 struct tps65010 *tps = _tps;
443
444 disable_irq_nosync(irq);
445 set_bit(FLAG_IRQ_ENABLE, &tps->flags);
David Brownell8c1bc04e2006-12-13 00:33:46 -0800446 (void) schedule_work(&tps->work.work);
David Brownell72cd7992005-05-24 17:34:51 -0700447 return IRQ_HANDLED;
448}
449
450/*-------------------------------------------------------------------------*/
451
452static struct tps65010 *the_tps;
453
David Brownell8056c6c2007-10-13 23:56:30 +0200454static int __exit tps65010_remove(struct i2c_client *client)
David Brownell72cd7992005-05-24 17:34:51 -0700455{
David Brownell8056c6c2007-10-13 23:56:30 +0200456 struct tps65010 *tps = i2c_get_clientdata(client);
David Brownell72cd7992005-05-24 17:34:51 -0700457
David Brownell8056c6c2007-10-13 23:56:30 +0200458 if (client->irq > 0)
459 free_irq(client->irq, tps);
David Brownell8c1bc04e2006-12-13 00:33:46 -0800460 cancel_delayed_work(&tps->work);
461 flush_scheduled_work();
David Brownell72cd7992005-05-24 17:34:51 -0700462 debugfs_remove(tps->file);
David Brownell8056c6c2007-10-13 23:56:30 +0200463 kfree(tps);
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700464 the_tps = NULL;
David Brownell72cd7992005-05-24 17:34:51 -0700465 return 0;
466}
467
David Brownell8056c6c2007-10-13 23:56:30 +0200468static int tps65010_probe(struct i2c_client *client)
David Brownell72cd7992005-05-24 17:34:51 -0700469{
470 struct tps65010 *tps;
471 int status;
472
473 if (the_tps) {
David Brownell8056c6c2007-10-13 23:56:30 +0200474 dev_dbg(&client->dev, "only one tps6501x chip allowed\n");
475 return -ENODEV;
David Brownell72cd7992005-05-24 17:34:51 -0700476 }
477
David Brownell8056c6c2007-10-13 23:56:30 +0200478 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
479 return -EINVAL;
480
Deepak Saxena5263ebb2005-10-17 23:09:43 +0200481 tps = kzalloc(sizeof *tps, GFP_KERNEL);
David Brownell72cd7992005-05-24 17:34:51 -0700482 if (!tps)
David Brownell8056c6c2007-10-13 23:56:30 +0200483 return -ENOMEM;
David Brownell72cd7992005-05-24 17:34:51 -0700484
Ingo Molnar5c085d32006-01-18 23:16:04 +0100485 mutex_init(&tps->lock);
David Brownell8c1bc04e2006-12-13 00:33:46 -0800486 INIT_DELAYED_WORK(&tps->work, tps65010_work);
David Brownell8056c6c2007-10-13 23:56:30 +0200487 tps->client = client;
David Brownell72cd7992005-05-24 17:34:51 -0700488
David Brownell8056c6c2007-10-13 23:56:30 +0200489 if (strcmp(client->name, "tps65010") == 0)
490 tps->model = TPS65010;
491 else if (strcmp(client->name, "tps65011") == 0)
492 tps->model = TPS65011;
493 else if (strcmp(client->name, "tps65012") == 0)
494 tps->model = TPS65012;
495 else if (strcmp(client->name, "tps65013") == 0)
496 tps->model = TPS65013;
497 else {
498 dev_warn(&client->dev, "unknown chip '%s'\n", client->name);
499 status = -ENODEV;
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700500 goto fail1;
David Brownell72cd7992005-05-24 17:34:51 -0700501 }
502
David Brownell4801bc22006-08-11 22:53:08 +0200503 /* the IRQ is active low, but many gpio lines can't support that
David Brownell8056c6c2007-10-13 23:56:30 +0200504 * so this driver uses falling-edge triggers instead.
David Brownell4801bc22006-08-11 22:53:08 +0200505 */
David Brownell8056c6c2007-10-13 23:56:30 +0200506 if (client->irq > 0) {
507 status = request_irq(client->irq, tps65010_irq,
508 IRQF_SAMPLE_RANDOM | IRQF_TRIGGER_FALLING,
509 DRIVER_NAME, tps);
David Brownell72cd7992005-05-24 17:34:51 -0700510 if (status < 0) {
David Brownellb5067f82007-10-13 23:56:30 +0200511 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n",
David Brownell8056c6c2007-10-13 23:56:30 +0200512 client->irq, status);
David Brownell72cd7992005-05-24 17:34:51 -0700513 goto fail1;
514 }
David Brownell72cd7992005-05-24 17:34:51 -0700515 /* annoying race here, ideally we'd have an option
516 * to claim the irq now and enable it later.
David Brownell8056c6c2007-10-13 23:56:30 +0200517 * FIXME genirq IRQF_NOAUTOEN now solves that ...
David Brownell72cd7992005-05-24 17:34:51 -0700518 */
David Brownell8056c6c2007-10-13 23:56:30 +0200519 disable_irq(client->irq);
David Brownell72cd7992005-05-24 17:34:51 -0700520 set_bit(FLAG_IRQ_ENABLE, &tps->flags);
David Brownell72cd7992005-05-24 17:34:51 -0700521 } else
David Brownell8056c6c2007-10-13 23:56:30 +0200522 dev_warn(&client->dev, "IRQ not configured!\n");
David Brownell72cd7992005-05-24 17:34:51 -0700523
524
525 switch (tps->model) {
526 case TPS65010:
527 case TPS65012:
528 tps->por = 1;
529 break;
530 case TPS_UNKNOWN:
531 printk(KERN_WARNING "%s: unknown TPS chip\n", DRIVER_NAME);
532 break;
533 /* else CHGCONFIG.POR is replaced by AUA, enabling a WAIT mode */
534 }
David Brownellb5067f82007-10-13 23:56:30 +0200535 tps->chgconf = i2c_smbus_read_byte_data(client, TPS_CHGCONFIG);
David Brownell72cd7992005-05-24 17:34:51 -0700536 show_chgconfig(tps->por, "conf/init", tps->chgconf);
537
538 show_chgstatus("chg/init",
David Brownellb5067f82007-10-13 23:56:30 +0200539 i2c_smbus_read_byte_data(client, TPS_CHGSTATUS));
David Brownell72cd7992005-05-24 17:34:51 -0700540 show_regstatus("reg/init",
David Brownellb5067f82007-10-13 23:56:30 +0200541 i2c_smbus_read_byte_data(client, TPS_REGSTATUS));
David Brownell72cd7992005-05-24 17:34:51 -0700542
543 pr_debug("%s: vdcdc1 0x%02x, vdcdc2 %02x, vregs1 %02x\n", DRIVER_NAME,
David Brownellb5067f82007-10-13 23:56:30 +0200544 i2c_smbus_read_byte_data(client, TPS_VDCDC1),
545 i2c_smbus_read_byte_data(client, TPS_VDCDC2),
546 i2c_smbus_read_byte_data(client, TPS_VREGS1));
David Brownell72cd7992005-05-24 17:34:51 -0700547 pr_debug("%s: defgpio 0x%02x, mask3 0x%02x\n", DRIVER_NAME,
David Brownellb5067f82007-10-13 23:56:30 +0200548 i2c_smbus_read_byte_data(client, TPS_DEFGPIO),
549 i2c_smbus_read_byte_data(client, TPS_MASK3));
David Brownell72cd7992005-05-24 17:34:51 -0700550
David Brownell72cd7992005-05-24 17:34:51 -0700551 the_tps = tps;
552
553#if defined(CONFIG_USB_GADGET) && !defined(CONFIG_USB_OTG)
554 /* USB hosts can't draw VBUS. OTG devices could, later
555 * when OTG infrastructure enables it. USB peripherals
556 * could be relying on VBUS while booting, though.
557 */
558 tps->vbus = 100;
559#endif
560
561 /* unmask the "interesting" irqs, then poll once to
562 * kickstart monitoring, initialize shadowed status
563 * registers, and maybe disable VBUS draw.
564 */
565 tps->nmask1 = ~0;
David Brownellb5067f82007-10-13 23:56:30 +0200566 (void) i2c_smbus_write_byte_data(client, TPS_MASK1, ~tps->nmask1);
David Brownell72cd7992005-05-24 17:34:51 -0700567
568 tps->nmask2 = TPS_REG_ONOFF;
569 if (tps->model == TPS65013)
570 tps->nmask2 |= TPS_REG_NO_CHG;
David Brownellb5067f82007-10-13 23:56:30 +0200571 (void) i2c_smbus_write_byte_data(client, TPS_MASK2, ~tps->nmask2);
David Brownell72cd7992005-05-24 17:34:51 -0700572
David Brownellb5067f82007-10-13 23:56:30 +0200573 (void) i2c_smbus_write_byte_data(client, TPS_MASK3, 0x0f
574 | i2c_smbus_read_byte_data(client, TPS_MASK3));
David Brownell72cd7992005-05-24 17:34:51 -0700575
David Brownell8c1bc04e2006-12-13 00:33:46 -0800576 tps65010_work(&tps->work.work);
David Brownell72cd7992005-05-24 17:34:51 -0700577
578 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL,
579 tps, DEBUG_FOPS);
580 return 0;
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700581fail1:
582 kfree(tps);
David Brownell8056c6c2007-10-13 23:56:30 +0200583 return status;
David Brownell72cd7992005-05-24 17:34:51 -0700584}
585
586static struct i2c_driver tps65010_driver = {
Laurent Riffarda9718b02005-11-26 20:36:00 +0100587 .driver = {
Laurent Riffarda9718b02005-11-26 20:36:00 +0100588 .name = "tps65010",
589 },
David Brownell8056c6c2007-10-13 23:56:30 +0200590 .probe = tps65010_probe,
591 .remove = __exit_p(tps65010_remove),
David Brownell72cd7992005-05-24 17:34:51 -0700592};
593
594/*-------------------------------------------------------------------------*/
595
596/* Draw from VBUS:
597 * 0 mA -- DON'T DRAW (might supply power instead)
598 * 100 mA -- usb unit load (slowest charge rate)
599 * 500 mA -- usb high power (fast battery charge)
600 */
601int tps65010_set_vbus_draw(unsigned mA)
602{
603 unsigned long flags;
604
605 if (!the_tps)
606 return -ENODEV;
607
608 /* assumes non-SMP */
609 local_irq_save(flags);
610 if (mA >= 500)
611 mA = 500;
612 else if (mA >= 100)
613 mA = 100;
614 else
615 mA = 0;
616 the_tps->vbus = mA;
617 if ((the_tps->chgstatus & TPS_CHG_USB)
618 && test_and_set_bit(
619 FLAG_VBUS_CHANGED, &the_tps->flags)) {
620 /* gadget drivers call this in_irq() */
David Brownell8c1bc04e2006-12-13 00:33:46 -0800621 (void) schedule_work(&the_tps->work.work);
David Brownell72cd7992005-05-24 17:34:51 -0700622 }
623 local_irq_restore(flags);
624
625 return 0;
626}
627EXPORT_SYMBOL(tps65010_set_vbus_draw);
628
629/*-------------------------------------------------------------------------*/
630/* tps65010_set_gpio_out_value parameter:
631 * gpio: GPIO1, GPIO2, GPIO3 or GPIO4
632 * value: LOW or HIGH
633 */
634int tps65010_set_gpio_out_value(unsigned gpio, unsigned value)
635{
636 int status;
637 unsigned defgpio;
638
639 if (!the_tps)
640 return -ENODEV;
641 if ((gpio < GPIO1) || (gpio > GPIO4))
642 return -EINVAL;
643
Ingo Molnar5c085d32006-01-18 23:16:04 +0100644 mutex_lock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700645
David Brownellb5067f82007-10-13 23:56:30 +0200646 defgpio = i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO);
David Brownell72cd7992005-05-24 17:34:51 -0700647
648 /* Configure GPIO for output */
649 defgpio |= 1 << (gpio + 3);
650
651 /* Writing 1 forces a logic 0 on that GPIO and vice versa */
652 switch (value) {
653 case LOW:
654 defgpio |= 1 << (gpio - 1); /* set GPIO low by writing 1 */
655 break;
656 /* case HIGH: */
657 default:
658 defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */
659 break;
660 }
661
David Brownellb5067f82007-10-13 23:56:30 +0200662 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700663 TPS_DEFGPIO, defgpio);
664
665 pr_debug("%s: gpio%dout = %s, defgpio 0x%02x\n", DRIVER_NAME,
666 gpio, value ? "high" : "low",
David Brownellb5067f82007-10-13 23:56:30 +0200667 i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO));
David Brownell72cd7992005-05-24 17:34:51 -0700668
Ingo Molnar5c085d32006-01-18 23:16:04 +0100669 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700670 return status;
671}
672EXPORT_SYMBOL(tps65010_set_gpio_out_value);
673
674/*-------------------------------------------------------------------------*/
675/* tps65010_set_led parameter:
676 * led: LED1 or LED2
677 * mode: ON, OFF or BLINK
678 */
679int tps65010_set_led(unsigned led, unsigned mode)
680{
681 int status;
682 unsigned led_on, led_per, offs;
683
684 if (!the_tps)
685 return -ENODEV;
686
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700687 if (led == LED1)
David Brownell72cd7992005-05-24 17:34:51 -0700688 offs = 0;
689 else {
690 offs = 2;
691 led = LED2;
692 }
693
Ingo Molnar5c085d32006-01-18 23:16:04 +0100694 mutex_lock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700695
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700696 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
David Brownellb5067f82007-10-13 23:56:30 +0200697 i2c_smbus_read_byte_data(the_tps->client,
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700698 TPS_LED1_ON + offs));
David Brownell72cd7992005-05-24 17:34:51 -0700699
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700700 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
David Brownellb5067f82007-10-13 23:56:30 +0200701 i2c_smbus_read_byte_data(the_tps->client,
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700702 TPS_LED1_PER + offs));
David Brownell72cd7992005-05-24 17:34:51 -0700703
704 switch (mode) {
705 case OFF:
706 led_on = 1 << 7;
707 led_per = 0 << 7;
708 break;
709 case ON:
710 led_on = 1 << 7;
711 led_per = 1 << 7;
712 break;
713 case BLINK:
714 led_on = 0x30 | (0 << 7);
715 led_per = 0x08 | (1 << 7);
716 break;
717 default:
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700718 printk(KERN_ERR "%s: Wrong mode parameter for set_led()\n",
David Brownell72cd7992005-05-24 17:34:51 -0700719 DRIVER_NAME);
Ingo Molnar5c085d32006-01-18 23:16:04 +0100720 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700721 return -EINVAL;
722 }
723
David Brownellb5067f82007-10-13 23:56:30 +0200724 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700725 TPS_LED1_ON + offs, led_on);
726
727 if (status != 0) {
728 printk(KERN_ERR "%s: Failed to write led%i_on register\n",
729 DRIVER_NAME, led);
Ingo Molnar5c085d32006-01-18 23:16:04 +0100730 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700731 return status;
732 }
733
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700734 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
David Brownellb5067f82007-10-13 23:56:30 +0200735 i2c_smbus_read_byte_data(the_tps->client, TPS_LED1_ON + offs));
David Brownell72cd7992005-05-24 17:34:51 -0700736
David Brownellb5067f82007-10-13 23:56:30 +0200737 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700738 TPS_LED1_PER + offs, led_per);
739
740 if (status != 0) {
741 printk(KERN_ERR "%s: Failed to write led%i_per register\n",
742 DRIVER_NAME, led);
Ingo Molnar5c085d32006-01-18 23:16:04 +0100743 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700744 return status;
745 }
746
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700747 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
David Brownellb5067f82007-10-13 23:56:30 +0200748 i2c_smbus_read_byte_data(the_tps->client,
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700749 TPS_LED1_PER + offs));
David Brownell72cd7992005-05-24 17:34:51 -0700750
Ingo Molnar5c085d32006-01-18 23:16:04 +0100751 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700752
753 return status;
754}
755EXPORT_SYMBOL(tps65010_set_led);
756
757/*-------------------------------------------------------------------------*/
758/* tps65010_set_vib parameter:
759 * value: ON or OFF
760 */
761int tps65010_set_vib(unsigned value)
762{
763 int status;
764 unsigned vdcdc2;
765
766 if (!the_tps)
767 return -ENODEV;
768
Ingo Molnar5c085d32006-01-18 23:16:04 +0100769 mutex_lock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700770
David Brownellb5067f82007-10-13 23:56:30 +0200771 vdcdc2 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC2);
David Brownell72cd7992005-05-24 17:34:51 -0700772 vdcdc2 &= ~(1 << 1);
773 if (value)
774 vdcdc2 |= (1 << 1);
David Brownellb5067f82007-10-13 23:56:30 +0200775 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700776 TPS_VDCDC2, vdcdc2);
777
778 pr_debug("%s: vibrator %s\n", DRIVER_NAME, value ? "on" : "off");
779
Ingo Molnar5c085d32006-01-18 23:16:04 +0100780 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700781 return status;
782}
783EXPORT_SYMBOL(tps65010_set_vib);
784
785/*-------------------------------------------------------------------------*/
786/* tps65010_set_low_pwr parameter:
787 * mode: ON or OFF
788 */
789int tps65010_set_low_pwr(unsigned mode)
790{
791 int status;
792 unsigned vdcdc1;
793
794 if (!the_tps)
795 return -ENODEV;
796
Ingo Molnar5c085d32006-01-18 23:16:04 +0100797 mutex_lock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700798
799 pr_debug("%s: %s low_pwr, vdcdc1 0x%02x\n", DRIVER_NAME,
800 mode ? "enable" : "disable",
David Brownellb5067f82007-10-13 23:56:30 +0200801 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
David Brownell72cd7992005-05-24 17:34:51 -0700802
David Brownellb5067f82007-10-13 23:56:30 +0200803 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
David Brownell72cd7992005-05-24 17:34:51 -0700804
805 switch (mode) {
806 case OFF:
807 vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */
808 break;
809 /* case ON: */
810 default:
811 vdcdc1 |= TPS_ENABLE_LP; /* enable ENABLE_LP bit */
812 break;
813 }
814
David Brownellb5067f82007-10-13 23:56:30 +0200815 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700816 TPS_VDCDC1, vdcdc1);
817
818 if (status != 0)
819 printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700820 DRIVER_NAME);
David Brownell72cd7992005-05-24 17:34:51 -0700821 else
822 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
David Brownellb5067f82007-10-13 23:56:30 +0200823 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
David Brownell72cd7992005-05-24 17:34:51 -0700824
Ingo Molnar5c085d32006-01-18 23:16:04 +0100825 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700826
827 return status;
828}
829EXPORT_SYMBOL(tps65010_set_low_pwr);
830
831/*-------------------------------------------------------------------------*/
832/* tps65010_config_vregs1 parameter:
833 * value to be written to VREGS1 register
834 * Note: The complete register is written, set all bits you need
835 */
836int tps65010_config_vregs1(unsigned value)
837{
838 int status;
839
840 if (!the_tps)
841 return -ENODEV;
842
Ingo Molnar5c085d32006-01-18 23:16:04 +0100843 mutex_lock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700844
845 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
David Brownellb5067f82007-10-13 23:56:30 +0200846 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
David Brownell72cd7992005-05-24 17:34:51 -0700847
David Brownellb5067f82007-10-13 23:56:30 +0200848 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700849 TPS_VREGS1, value);
850
851 if (status != 0)
852 printk(KERN_ERR "%s: Failed to write vregs1 register\n",
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700853 DRIVER_NAME);
David Brownell72cd7992005-05-24 17:34:51 -0700854 else
855 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
David Brownellb5067f82007-10-13 23:56:30 +0200856 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
David Brownell72cd7992005-05-24 17:34:51 -0700857
Ingo Molnar5c085d32006-01-18 23:16:04 +0100858 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700859
860 return status;
861}
862EXPORT_SYMBOL(tps65010_config_vregs1);
863
864/*-------------------------------------------------------------------------*/
865/* tps65013_set_low_pwr parameter:
866 * mode: ON or OFF
867 */
868
869/* FIXME: Assumes AC or USB power is present. Setting AUA bit is not
870 required if power supply is through a battery */
871
872int tps65013_set_low_pwr(unsigned mode)
873{
874 int status;
875 unsigned vdcdc1, chgconfig;
876
877 if (!the_tps || the_tps->por)
878 return -ENODEV;
879
Ingo Molnar5c085d32006-01-18 23:16:04 +0100880 mutex_lock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700881
882 pr_debug("%s: %s low_pwr, chgconfig 0x%02x vdcdc1 0x%02x\n",
883 DRIVER_NAME,
884 mode ? "enable" : "disable",
David Brownellb5067f82007-10-13 23:56:30 +0200885 i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG),
886 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
David Brownell72cd7992005-05-24 17:34:51 -0700887
David Brownellb5067f82007-10-13 23:56:30 +0200888 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
889 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
David Brownell72cd7992005-05-24 17:34:51 -0700890
891 switch (mode) {
892 case OFF:
893 chgconfig &= ~TPS65013_AUA; /* disable AUA bit */
894 vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */
895 break;
896 /* case ON: */
897 default:
898 chgconfig |= TPS65013_AUA; /* enable AUA bit */
899 vdcdc1 |= TPS_ENABLE_LP; /* enable ENABLE_LP bit */
900 break;
901 }
902
David Brownellb5067f82007-10-13 23:56:30 +0200903 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700904 TPS_CHGCONFIG, chgconfig);
905 if (status != 0) {
906 printk(KERN_ERR "%s: Failed to write chconfig register\n",
907 DRIVER_NAME);
Ingo Molnar5c085d32006-01-18 23:16:04 +0100908 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700909 return status;
910 }
911
David Brownellb5067f82007-10-13 23:56:30 +0200912 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
David Brownell72cd7992005-05-24 17:34:51 -0700913 the_tps->chgconf = chgconfig;
914 show_chgconfig(0, "chgconf", chgconfig);
915
David Brownellb5067f82007-10-13 23:56:30 +0200916 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700917 TPS_VDCDC1, vdcdc1);
918
919 if (status != 0)
920 printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
921 DRIVER_NAME);
922 else
923 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
David Brownellb5067f82007-10-13 23:56:30 +0200924 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
David Brownell72cd7992005-05-24 17:34:51 -0700925
Ingo Molnar5c085d32006-01-18 23:16:04 +0100926 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700927
928 return status;
929}
930EXPORT_SYMBOL(tps65013_set_low_pwr);
931
932/*-------------------------------------------------------------------------*/
933
934static int __init tps_init(void)
935{
936 u32 tries = 3;
937 int status = -ENODEV;
938
939 printk(KERN_INFO "%s: version %s\n", DRIVER_NAME, DRIVER_VERSION);
940
941 /* some boards have startup glitches */
942 while (tries--) {
943 status = i2c_add_driver(&tps65010_driver);
944 if (the_tps)
945 break;
946 i2c_del_driver(&tps65010_driver);
947 if (!tries) {
948 printk(KERN_ERR "%s: no chip?\n", DRIVER_NAME);
949 return -ENODEV;
950 }
951 pr_debug("%s: re-probe ...\n", DRIVER_NAME);
952 msleep(10);
953 }
954
David Brownell72cd7992005-05-24 17:34:51 -0700955 return status;
956}
957/* NOTE: this MUST be initialized before the other parts of the system
958 * that rely on it ... but after the i2c bus on which this relies.
959 * That is, much earlier than on PC-type systems, which don't often use
960 * I2C as a core system bus.
961 */
962subsys_initcall(tps_init);
963
964static void __exit tps_exit(void)
965{
966 i2c_del_driver(&tps65010_driver);
967}
968module_exit(tps_exit);
969