blob: 402d911a9e7ba04f8f21022c2991532162a18505 [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>
27#include <linux/device.h>
28#include <linux/i2c.h>
29#include <linux/delay.h>
30#include <linux/workqueue.h>
31#include <linux/suspend.h>
32#include <linux/debugfs.h>
33#include <linux/seq_file.h>
Ingo Molnar5c085d32006-01-18 23:16:04 +010034#include <linux/mutex.h>
David Brownell72cd7992005-05-24 17:34:51 -070035
36#include <asm/irq.h>
37#include <asm/mach-types.h>
38
39#include <asm/arch/gpio.h>
40#include <asm/arch/mux.h>
41#include <asm/arch/tps65010.h>
42
43/*-------------------------------------------------------------------------*/
44
45#define DRIVER_VERSION "2 May 2005"
David Brownell4801bc22006-08-11 22:53:08 +020046#define DRIVER_NAME (tps65010_driver.driver.name)
David Brownell72cd7992005-05-24 17:34:51 -070047
48MODULE_DESCRIPTION("TPS6501x Power Management Driver");
49MODULE_LICENSE("GPL");
50
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -070051static unsigned short normal_i2c[] = { 0x48, /* 0x49, */ I2C_CLIENT_END };
David Brownell72cd7992005-05-24 17:34:51 -070052
53I2C_CLIENT_INSMOD;
54
55static struct i2c_driver tps65010_driver;
56
57/*-------------------------------------------------------------------------*/
58
59/* This driver handles a family of multipurpose chips, which incorporate
60 * voltage regulators, lithium ion/polymer battery charging, GPIOs, LEDs,
61 * and other features often needed in portable devices like cell phones
62 * or digital cameras.
63 *
64 * The tps65011 and tps65013 have different voltage settings compared
65 * to tps65010 and tps65012. The tps65013 has a NO_CHG status/irq.
66 * All except tps65010 have "wait" mode, possibly defaulted so that
67 * battery-insert != device-on.
68 *
69 * We could distinguish between some models by checking VDCDC1.UVLO or
70 * other registers, unless they've been changed already after powerup
71 * as part of board setup by a bootloader.
72 */
73enum tps_model {
74 TPS_UNKNOWN = 0,
75 TPS65010,
76 TPS65011,
77 TPS65012,
78 TPS65013,
79};
80
81struct tps65010 {
David Brownellb5067f82007-10-13 23:56:30 +020082 struct i2c_client c;
83 struct i2c_client *client;
Ingo Molnar5c085d32006-01-18 23:16:04 +010084 struct mutex lock;
David Brownell72cd7992005-05-24 17:34:51 -070085 int irq;
David Brownell8c1bc042006-12-13 00:33:46 -080086 struct delayed_work work;
David Brownell72cd7992005-05-24 17:34:51 -070087 struct dentry *file;
88 unsigned charging:1;
89 unsigned por:1;
90 unsigned model:8;
91 u16 vbus;
92 unsigned long flags;
93#define FLAG_VBUS_CHANGED 0
94#define FLAG_IRQ_ENABLE 1
95
96 /* copies of last register state */
97 u8 chgstatus, regstatus, chgconf;
98 u8 nmask1, nmask2;
99
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700100 /* not currently tracking GPIO state */
David Brownell72cd7992005-05-24 17:34:51 -0700101};
102
David Brownell4801bc22006-08-11 22:53:08 +0200103#define POWER_POLL_DELAY msecs_to_jiffies(5000)
David Brownell72cd7992005-05-24 17:34:51 -0700104
105/*-------------------------------------------------------------------------*/
106
107#if defined(DEBUG) || defined(CONFIG_DEBUG_FS)
108
109static void dbg_chgstat(char *buf, size_t len, u8 chgstatus)
110{
111 snprintf(buf, len, "%02x%s%s%s%s%s%s%s%s\n",
112 chgstatus,
113 (chgstatus & TPS_CHG_USB) ? " USB" : "",
114 (chgstatus & TPS_CHG_AC) ? " AC" : "",
115 (chgstatus & TPS_CHG_THERM) ? " therm" : "",
116 (chgstatus & TPS_CHG_TERM) ? " done" :
117 ((chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
118 ? " (charging)" : ""),
119 (chgstatus & TPS_CHG_TAPER_TMO) ? " taper_tmo" : "",
120 (chgstatus & TPS_CHG_CHG_TMO) ? " charge_tmo" : "",
121 (chgstatus & TPS_CHG_PRECHG_TMO) ? " prechg_tmo" : "",
122 (chgstatus & TPS_CHG_TEMP_ERR) ? " temp_err" : "");
123}
124
125static void dbg_regstat(char *buf, size_t len, u8 regstatus)
126{
127 snprintf(buf, len, "%02x %s%s%s%s%s%s%s%s\n",
128 regstatus,
129 (regstatus & TPS_REG_ONOFF) ? "off" : "(on)",
130 (regstatus & TPS_REG_COVER) ? " uncover" : "",
131 (regstatus & TPS_REG_UVLO) ? " UVLO" : "",
132 (regstatus & TPS_REG_NO_CHG) ? " NO_CHG" : "",
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700133 (regstatus & TPS_REG_PG_LD02) ? " ld02_bad" : "",
David Brownell72cd7992005-05-24 17:34:51 -0700134 (regstatus & TPS_REG_PG_LD01) ? " ld01_bad" : "",
135 (regstatus & TPS_REG_PG_MAIN) ? " main_bad" : "",
136 (regstatus & TPS_REG_PG_CORE) ? " core_bad" : "");
137}
138
139static void dbg_chgconf(int por, char *buf, size_t len, u8 chgconfig)
140{
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700141 const char *hibit;
David Brownell72cd7992005-05-24 17:34:51 -0700142
143 if (por)
144 hibit = (chgconfig & TPS_CHARGE_POR)
145 ? "POR=69ms" : "POR=1sec";
146 else
147 hibit = (chgconfig & TPS65013_AUA) ? "AUA" : "";
148
149 snprintf(buf, len, "%02x %s%s%s AC=%d%% USB=%dmA %sCharge\n",
150 chgconfig, hibit,
151 (chgconfig & TPS_CHARGE_RESET) ? " reset" : "",
152 (chgconfig & TPS_CHARGE_FAST) ? " fast" : "",
153 ({int p; switch ((chgconfig >> 3) & 3) {
154 case 3: p = 100; break;
155 case 2: p = 75; break;
156 case 1: p = 50; break;
157 default: p = 25; break;
158 }; p; }),
159 (chgconfig & TPS_VBUS_CHARGING)
160 ? ((chgconfig & TPS_VBUS_500MA) ? 500 : 100)
161 : 0,
162 (chgconfig & TPS_CHARGE_ENABLE) ? "" : "No");
163}
164
165#endif
166
167#ifdef DEBUG
168
169static void show_chgstatus(const char *label, u8 chgstatus)
170{
171 char buf [100];
172
173 dbg_chgstat(buf, sizeof buf, chgstatus);
174 pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
175}
176
177static void show_regstatus(const char *label, u8 regstatus)
178{
179 char buf [100];
180
181 dbg_regstat(buf, sizeof buf, regstatus);
182 pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
183}
184
185static void show_chgconfig(int por, const char *label, u8 chgconfig)
186{
187 char buf [100];
188
189 dbg_chgconf(por, buf, sizeof buf, chgconfig);
190 pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
191}
192
193#else
194
195static inline void show_chgstatus(const char *label, u8 chgstatus) { }
196static inline void show_regstatus(const char *label, u8 chgstatus) { }
197static inline void show_chgconfig(int por, const char *label, u8 chgconfig) { }
198
199#endif
200
201#ifdef CONFIG_DEBUG_FS
202
203static int dbg_show(struct seq_file *s, void *_)
204{
205 struct tps65010 *tps = s->private;
206 u8 value, v2;
207 unsigned i;
208 char buf[100];
209 const char *chip;
210
211 switch (tps->model) {
212 case TPS65010: chip = "tps65010"; break;
213 case TPS65011: chip = "tps65011"; break;
214 case TPS65012: chip = "tps65012"; break;
215 case TPS65013: chip = "tps65013"; break;
216 default: chip = NULL; break;
217 }
218 seq_printf(s, "driver %s\nversion %s\nchip %s\n\n",
219 DRIVER_NAME, DRIVER_VERSION, chip);
220
Ingo Molnar5c085d32006-01-18 23:16:04 +0100221 mutex_lock(&tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700222
223 /* FIXME how can we tell whether a battery is present?
224 * likely involves a charge gauging chip (like BQ26501).
225 */
226
227 seq_printf(s, "%scharging\n\n", tps->charging ? "" : "(not) ");
228
229
230 /* registers for monitoring battery charging and status; note
231 * that reading chgstat and regstat may ack IRQs...
232 */
David Brownellb5067f82007-10-13 23:56:30 +0200233 value = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG);
David Brownell72cd7992005-05-24 17:34:51 -0700234 dbg_chgconf(tps->por, buf, sizeof buf, value);
235 seq_printf(s, "chgconfig %s", buf);
236
David Brownellb5067f82007-10-13 23:56:30 +0200237 value = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS);
David Brownell72cd7992005-05-24 17:34:51 -0700238 dbg_chgstat(buf, sizeof buf, value);
239 seq_printf(s, "chgstat %s", buf);
David Brownellb5067f82007-10-13 23:56:30 +0200240 value = i2c_smbus_read_byte_data(tps->client, TPS_MASK1);
David Brownell72cd7992005-05-24 17:34:51 -0700241 dbg_chgstat(buf, sizeof buf, value);
242 seq_printf(s, "mask1 %s", buf);
243 /* ignore ackint1 */
244
David Brownellb5067f82007-10-13 23:56:30 +0200245 value = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS);
David Brownell72cd7992005-05-24 17:34:51 -0700246 dbg_regstat(buf, sizeof buf, value);
247 seq_printf(s, "regstat %s", buf);
David Brownellb5067f82007-10-13 23:56:30 +0200248 value = i2c_smbus_read_byte_data(tps->client, TPS_MASK2);
David Brownell72cd7992005-05-24 17:34:51 -0700249 dbg_regstat(buf, sizeof buf, value);
250 seq_printf(s, "mask2 %s\n", buf);
251 /* ignore ackint2 */
252
253 (void) schedule_delayed_work(&tps->work, POWER_POLL_DELAY);
254
255
256 /* VMAIN voltage, enable lowpower, etc */
David Brownellb5067f82007-10-13 23:56:30 +0200257 value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC1);
David Brownell72cd7992005-05-24 17:34:51 -0700258 seq_printf(s, "vdcdc1 %02x\n", value);
259
260 /* VCORE voltage, vibrator on/off */
David Brownellb5067f82007-10-13 23:56:30 +0200261 value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC2);
David Brownell72cd7992005-05-24 17:34:51 -0700262 seq_printf(s, "vdcdc2 %02x\n", value);
263
264 /* both LD0s, and their lowpower behavior */
David Brownellb5067f82007-10-13 23:56:30 +0200265 value = i2c_smbus_read_byte_data(tps->client, TPS_VREGS1);
David Brownell72cd7992005-05-24 17:34:51 -0700266 seq_printf(s, "vregs1 %02x\n\n", value);
267
268
269 /* LEDs and GPIOs */
David Brownellb5067f82007-10-13 23:56:30 +0200270 value = i2c_smbus_read_byte_data(tps->client, TPS_LED1_ON);
271 v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED1_PER);
David Brownell72cd7992005-05-24 17:34:51 -0700272 seq_printf(s, "led1 %s, on=%02x, per=%02x, %d/%d msec\n",
273 (value & 0x80)
274 ? ((v2 & 0x80) ? "on" : "off")
275 : ((v2 & 0x80) ? "blink" : "(nPG)"),
276 value, v2,
277 (value & 0x7f) * 10, (v2 & 0x7f) * 100);
278
David Brownellb5067f82007-10-13 23:56:30 +0200279 value = i2c_smbus_read_byte_data(tps->client, TPS_LED2_ON);
280 v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED2_PER);
David Brownell72cd7992005-05-24 17:34:51 -0700281 seq_printf(s, "led2 %s, on=%02x, per=%02x, %d/%d msec\n",
282 (value & 0x80)
283 ? ((v2 & 0x80) ? "on" : "off")
284 : ((v2 & 0x80) ? "blink" : "off"),
285 value, v2,
286 (value & 0x7f) * 10, (v2 & 0x7f) * 100);
287
David Brownellb5067f82007-10-13 23:56:30 +0200288 value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO);
289 v2 = i2c_smbus_read_byte_data(tps->client, TPS_MASK3);
David Brownell72cd7992005-05-24 17:34:51 -0700290 seq_printf(s, "defgpio %02x mask3 %02x\n", value, v2);
291
292 for (i = 0; i < 4; i++) {
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700293 if (value & (1 << (4 + i)))
David Brownell72cd7992005-05-24 17:34:51 -0700294 seq_printf(s, " gpio%d-out %s\n", i + 1,
295 (value & (1 << i)) ? "low" : "hi ");
296 else
297 seq_printf(s, " gpio%d-in %s %s %s\n", i + 1,
298 (value & (1 << i)) ? "hi " : "low",
299 (v2 & (1 << i)) ? "no-irq" : "irq",
300 (v2 & (1 << (4 + i))) ? "rising" : "falling");
301 }
302
Ingo Molnar5c085d32006-01-18 23:16:04 +0100303 mutex_unlock(&tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700304 return 0;
305}
306
307static int dbg_tps_open(struct inode *inode, struct file *file)
308{
Theodore Ts'o8e18e292006-09-27 01:50:46 -0700309 return single_open(file, dbg_show, inode->i_private);
David Brownell72cd7992005-05-24 17:34:51 -0700310}
311
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800312static const struct file_operations debug_fops = {
David Brownell72cd7992005-05-24 17:34:51 -0700313 .open = dbg_tps_open,
314 .read = seq_read,
315 .llseek = seq_lseek,
316 .release = single_release,
317};
318
319#define DEBUG_FOPS &debug_fops
320
321#else
322#define DEBUG_FOPS NULL
323#endif
324
325/*-------------------------------------------------------------------------*/
326
327/* handle IRQS in a task context, so we can use I2C calls */
328static void tps65010_interrupt(struct tps65010 *tps)
329{
330 u8 tmp = 0, mask, poll;
331
David Brownell8c1bc042006-12-13 00:33:46 -0800332 /* IRQs won't trigger for certain events, but we can get
David Brownell72cd7992005-05-24 17:34:51 -0700333 * others by polling (normally, with external power applied).
334 */
335 poll = 0;
336
337 /* regstatus irqs */
338 if (tps->nmask2) {
David Brownellb5067f82007-10-13 23:56:30 +0200339 tmp = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS);
David Brownell72cd7992005-05-24 17:34:51 -0700340 mask = tmp ^ tps->regstatus;
341 tps->regstatus = tmp;
342 mask &= tps->nmask2;
343 } else
344 mask = 0;
345 if (mask) {
346 tps->regstatus = tmp;
347 /* may need to shut something down ... */
348
349 /* "off" usually means deep sleep */
350 if (tmp & TPS_REG_ONOFF) {
351 pr_info("%s: power off button\n", DRIVER_NAME);
352#if 0
353 /* REVISIT: this might need its own workqueue
354 * plus tweaks including deadlock avoidance ...
Johannes Bergab3bfca2007-05-06 14:50:49 -0700355 * also needs to get error handling and probably
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200356 * an #ifdef CONFIG_HIBERNATION
David Brownell72cd7992005-05-24 17:34:51 -0700357 */
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700358 hibernate();
David Brownell72cd7992005-05-24 17:34:51 -0700359#endif
360 poll = 1;
361 }
362 }
363
364 /* chgstatus irqs */
365 if (tps->nmask1) {
David Brownellb5067f82007-10-13 23:56:30 +0200366 tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS);
David Brownell72cd7992005-05-24 17:34:51 -0700367 mask = tmp ^ tps->chgstatus;
368 tps->chgstatus = tmp;
369 mask &= tps->nmask1;
370 } else
371 mask = 0;
372 if (mask) {
373 unsigned charging = 0;
374
375 show_chgstatus("chg/irq", tmp);
376 if (tmp & (TPS_CHG_USB|TPS_CHG_AC))
377 show_chgconfig(tps->por, "conf", tps->chgconf);
378
379 /* Unless it was turned off or disabled, we charge any
380 * battery whenever there's power available for it
381 * and the charger hasn't been disabled.
382 */
383 if (!(tps->chgstatus & ~(TPS_CHG_USB|TPS_CHG_AC))
384 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
385 && (tps->chgconf & TPS_CHARGE_ENABLE)
386 ) {
387 if (tps->chgstatus & TPS_CHG_USB) {
388 /* VBUS options are readonly until reconnect */
389 if (mask & TPS_CHG_USB)
390 set_bit(FLAG_VBUS_CHANGED, &tps->flags);
391 charging = 1;
392 } else if (tps->chgstatus & TPS_CHG_AC)
393 charging = 1;
394 }
395 if (charging != tps->charging) {
396 tps->charging = charging;
397 pr_info("%s: battery %scharging\n",
398 DRIVER_NAME, charging ? "" :
399 ((tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
400 ? "NOT " : "dis"));
401 }
402 }
403
404 /* always poll to detect (a) power removal, without tps65013
405 * NO_CHG IRQ; or (b) restart of charging after stop.
406 */
407 if ((tps->model != TPS65013 || !tps->charging)
408 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC)))
409 poll = 1;
410 if (poll)
411 (void) schedule_delayed_work(&tps->work, POWER_POLL_DELAY);
412
413 /* also potentially gpio-in rise or fall */
414}
415
416/* handle IRQs and polling using keventd for now */
David Brownell8c1bc042006-12-13 00:33:46 -0800417static void tps65010_work(struct work_struct *work)
David Brownell72cd7992005-05-24 17:34:51 -0700418{
David Brownell8c1bc042006-12-13 00:33:46 -0800419 struct tps65010 *tps;
David Brownell72cd7992005-05-24 17:34:51 -0700420
David Brownell8c1bc042006-12-13 00:33:46 -0800421 tps = container_of(work, struct tps65010, work.work);
Ingo Molnar5c085d32006-01-18 23:16:04 +0100422 mutex_lock(&tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700423
424 tps65010_interrupt(tps);
425
426 if (test_and_clear_bit(FLAG_VBUS_CHANGED, &tps->flags)) {
427 int status;
428 u8 chgconfig, tmp;
429
David Brownellb5067f82007-10-13 23:56:30 +0200430 chgconfig = i2c_smbus_read_byte_data(tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700431 TPS_CHGCONFIG);
432 chgconfig &= ~(TPS_VBUS_500MA | TPS_VBUS_CHARGING);
433 if (tps->vbus == 500)
434 chgconfig |= TPS_VBUS_500MA | TPS_VBUS_CHARGING;
435 else if (tps->vbus >= 100)
436 chgconfig |= TPS_VBUS_CHARGING;
437
David Brownellb5067f82007-10-13 23:56:30 +0200438 status = i2c_smbus_write_byte_data(tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700439 TPS_CHGCONFIG, chgconfig);
440
441 /* vbus update fails unless VBUS is connected! */
David Brownellb5067f82007-10-13 23:56:30 +0200442 tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG);
David Brownell72cd7992005-05-24 17:34:51 -0700443 tps->chgconf = tmp;
444 show_chgconfig(tps->por, "update vbus", tmp);
445 }
446
447 if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags))
448 enable_irq(tps->irq);
449
Ingo Molnar5c085d32006-01-18 23:16:04 +0100450 mutex_unlock(&tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700451}
452
David Howells7d12e782006-10-05 14:55:46 +0100453static irqreturn_t tps65010_irq(int irq, void *_tps)
David Brownell72cd7992005-05-24 17:34:51 -0700454{
455 struct tps65010 *tps = _tps;
456
457 disable_irq_nosync(irq);
458 set_bit(FLAG_IRQ_ENABLE, &tps->flags);
David Brownell8c1bc042006-12-13 00:33:46 -0800459 (void) schedule_work(&tps->work.work);
David Brownell72cd7992005-05-24 17:34:51 -0700460 return IRQ_HANDLED;
461}
462
463/*-------------------------------------------------------------------------*/
464
465static struct tps65010 *the_tps;
466
467static int __exit tps65010_detach_client(struct i2c_client *client)
468{
469 struct tps65010 *tps;
470
David Brownellb5067f82007-10-13 23:56:30 +0200471 tps = container_of(client, struct tps65010, c);
David Brownell8c1bc042006-12-13 00:33:46 -0800472 free_irq(tps->irq, tps);
David Brownell72cd7992005-05-24 17:34:51 -0700473#ifdef CONFIG_ARM
474 if (machine_is_omap_h2())
475 omap_free_gpio(58);
476 if (machine_is_omap_osk())
477 omap_free_gpio(OMAP_MPUIO(1));
478#endif
David Brownell8c1bc042006-12-13 00:33:46 -0800479 cancel_delayed_work(&tps->work);
480 flush_scheduled_work();
David Brownell72cd7992005-05-24 17:34:51 -0700481 debugfs_remove(tps->file);
482 if (i2c_detach_client(client) == 0)
483 kfree(tps);
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700484 the_tps = NULL;
David Brownell72cd7992005-05-24 17:34:51 -0700485 return 0;
486}
487
488static int tps65010_noscan(struct i2c_adapter *bus)
489{
490 /* pure paranoia, in case someone adds another i2c bus
491 * after our init section's gone...
492 */
493 return -ENODEV;
494}
495
496/* no error returns, they'd just make bus scanning stop */
497static int __init
498tps65010_probe(struct i2c_adapter *bus, int address, int kind)
499{
500 struct tps65010 *tps;
501 int status;
Russell King9ded96f2006-01-08 01:02:07 -0800502 unsigned long irqflags;
David Brownellb5067f82007-10-13 23:56:30 +0200503 struct i2c_client *client;
David Brownell72cd7992005-05-24 17:34:51 -0700504
505 if (the_tps) {
506 dev_dbg(&bus->dev, "only one %s for now\n", DRIVER_NAME);
507 return 0;
508 }
509
Deepak Saxena5263ebb2005-10-17 23:09:43 +0200510 tps = kzalloc(sizeof *tps, GFP_KERNEL);
David Brownell72cd7992005-05-24 17:34:51 -0700511 if (!tps)
512 return 0;
513
Ingo Molnar5c085d32006-01-18 23:16:04 +0100514 mutex_init(&tps->lock);
David Brownell8c1bc042006-12-13 00:33:46 -0800515 INIT_DELAYED_WORK(&tps->work, tps65010_work);
David Brownell72cd7992005-05-24 17:34:51 -0700516 tps->irq = -1;
David Brownellb5067f82007-10-13 23:56:30 +0200517 tps->c.addr = address;
518 tps->c.adapter = bus;
519 tps->c.driver = &tps65010_driver;
520 strlcpy(tps->c.name, DRIVER_NAME, I2C_NAME_SIZE);
521 tps->client = client = &tps->c;
David Brownell72cd7992005-05-24 17:34:51 -0700522
David Brownellb5067f82007-10-13 23:56:30 +0200523 status = i2c_attach_client(client);
David Brownell72cd7992005-05-24 17:34:51 -0700524 if (status < 0) {
525 dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n",
526 DRIVER_NAME, address, status);
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700527 goto fail1;
David Brownell72cd7992005-05-24 17:34:51 -0700528 }
529
David Brownell4801bc22006-08-11 22:53:08 +0200530 /* the IRQ is active low, but many gpio lines can't support that
531 * so this driver can use falling-edge triggers instead.
532 */
533 irqflags = IRQF_SAMPLE_RANDOM;
David Brownell72cd7992005-05-24 17:34:51 -0700534#ifdef CONFIG_ARM
535 if (machine_is_omap_h2()) {
536 tps->model = TPS65010;
537 omap_cfg_reg(W4_GPIO58);
538 tps->irq = OMAP_GPIO_IRQ(58);
539 omap_request_gpio(58);
540 omap_set_gpio_direction(58, 1);
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700541 irqflags |= IRQF_TRIGGER_FALLING;
David Brownell72cd7992005-05-24 17:34:51 -0700542 }
543 if (machine_is_omap_osk()) {
544 tps->model = TPS65010;
545 // omap_cfg_reg(U19_1610_MPUIO1);
546 tps->irq = OMAP_GPIO_IRQ(OMAP_MPUIO(1));
547 omap_request_gpio(OMAP_MPUIO(1));
548 omap_set_gpio_direction(OMAP_MPUIO(1), 1);
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700549 irqflags |= IRQF_TRIGGER_FALLING;
David Brownell72cd7992005-05-24 17:34:51 -0700550 }
551 if (machine_is_omap_h3()) {
552 tps->model = TPS65013;
553
554 // FIXME set up this board's IRQ ...
555 }
David Brownell72cd7992005-05-24 17:34:51 -0700556#endif
557
558 if (tps->irq > 0) {
David Brownell72cd7992005-05-24 17:34:51 -0700559 status = request_irq(tps->irq, tps65010_irq,
Russell King9ded96f2006-01-08 01:02:07 -0800560 irqflags, DRIVER_NAME, tps);
David Brownell72cd7992005-05-24 17:34:51 -0700561 if (status < 0) {
David Brownellb5067f82007-10-13 23:56:30 +0200562 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n",
David Brownell72cd7992005-05-24 17:34:51 -0700563 tps->irq, status);
David Brownellb5067f82007-10-13 23:56:30 +0200564 i2c_detach_client(client);
David Brownell72cd7992005-05-24 17:34:51 -0700565 goto fail1;
566 }
567#ifdef CONFIG_ARM
568 /* annoying race here, ideally we'd have an option
569 * to claim the irq now and enable it later.
570 */
571 disable_irq(tps->irq);
572 set_bit(FLAG_IRQ_ENABLE, &tps->flags);
573#endif
574 } else
575 printk(KERN_WARNING "%s: IRQ not configured!\n",
576 DRIVER_NAME);
577
578
579 switch (tps->model) {
580 case TPS65010:
581 case TPS65012:
582 tps->por = 1;
583 break;
584 case TPS_UNKNOWN:
585 printk(KERN_WARNING "%s: unknown TPS chip\n", DRIVER_NAME);
586 break;
587 /* else CHGCONFIG.POR is replaced by AUA, enabling a WAIT mode */
588 }
David Brownellb5067f82007-10-13 23:56:30 +0200589 tps->chgconf = i2c_smbus_read_byte_data(client, TPS_CHGCONFIG);
David Brownell72cd7992005-05-24 17:34:51 -0700590 show_chgconfig(tps->por, "conf/init", tps->chgconf);
591
592 show_chgstatus("chg/init",
David Brownellb5067f82007-10-13 23:56:30 +0200593 i2c_smbus_read_byte_data(client, TPS_CHGSTATUS));
David Brownell72cd7992005-05-24 17:34:51 -0700594 show_regstatus("reg/init",
David Brownellb5067f82007-10-13 23:56:30 +0200595 i2c_smbus_read_byte_data(client, TPS_REGSTATUS));
David Brownell72cd7992005-05-24 17:34:51 -0700596
597 pr_debug("%s: vdcdc1 0x%02x, vdcdc2 %02x, vregs1 %02x\n", DRIVER_NAME,
David Brownellb5067f82007-10-13 23:56:30 +0200598 i2c_smbus_read_byte_data(client, TPS_VDCDC1),
599 i2c_smbus_read_byte_data(client, TPS_VDCDC2),
600 i2c_smbus_read_byte_data(client, TPS_VREGS1));
David Brownell72cd7992005-05-24 17:34:51 -0700601 pr_debug("%s: defgpio 0x%02x, mask3 0x%02x\n", DRIVER_NAME,
David Brownellb5067f82007-10-13 23:56:30 +0200602 i2c_smbus_read_byte_data(client, TPS_DEFGPIO),
603 i2c_smbus_read_byte_data(client, TPS_MASK3));
David Brownell72cd7992005-05-24 17:34:51 -0700604
605 tps65010_driver.attach_adapter = tps65010_noscan;
606 the_tps = tps;
607
608#if defined(CONFIG_USB_GADGET) && !defined(CONFIG_USB_OTG)
609 /* USB hosts can't draw VBUS. OTG devices could, later
610 * when OTG infrastructure enables it. USB peripherals
611 * could be relying on VBUS while booting, though.
612 */
613 tps->vbus = 100;
614#endif
615
616 /* unmask the "interesting" irqs, then poll once to
617 * kickstart monitoring, initialize shadowed status
618 * registers, and maybe disable VBUS draw.
619 */
620 tps->nmask1 = ~0;
David Brownellb5067f82007-10-13 23:56:30 +0200621 (void) i2c_smbus_write_byte_data(client, TPS_MASK1, ~tps->nmask1);
David Brownell72cd7992005-05-24 17:34:51 -0700622
623 tps->nmask2 = TPS_REG_ONOFF;
624 if (tps->model == TPS65013)
625 tps->nmask2 |= TPS_REG_NO_CHG;
David Brownellb5067f82007-10-13 23:56:30 +0200626 (void) i2c_smbus_write_byte_data(client, TPS_MASK2, ~tps->nmask2);
David Brownell72cd7992005-05-24 17:34:51 -0700627
David Brownellb5067f82007-10-13 23:56:30 +0200628 (void) i2c_smbus_write_byte_data(client, TPS_MASK3, 0x0f
629 | i2c_smbus_read_byte_data(client, TPS_MASK3));
David Brownell72cd7992005-05-24 17:34:51 -0700630
David Brownell8c1bc042006-12-13 00:33:46 -0800631 tps65010_work(&tps->work.work);
David Brownell72cd7992005-05-24 17:34:51 -0700632
633 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL,
634 tps, DEBUG_FOPS);
635 return 0;
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700636fail1:
637 kfree(tps);
638 return 0;
David Brownell72cd7992005-05-24 17:34:51 -0700639}
640
641static int __init tps65010_scan_bus(struct i2c_adapter *bus)
642{
643 if (!i2c_check_functionality(bus, I2C_FUNC_SMBUS_BYTE_DATA))
644 return -EINVAL;
645 return i2c_probe(bus, &addr_data, tps65010_probe);
646}
647
648static struct i2c_driver tps65010_driver = {
Laurent Riffarda9718b02005-11-26 20:36:00 +0100649 .driver = {
Laurent Riffarda9718b02005-11-26 20:36:00 +0100650 .name = "tps65010",
651 },
David Brownell72cd7992005-05-24 17:34:51 -0700652 .attach_adapter = tps65010_scan_bus,
653 .detach_client = __exit_p(tps65010_detach_client),
654};
655
656/*-------------------------------------------------------------------------*/
657
658/* Draw from VBUS:
659 * 0 mA -- DON'T DRAW (might supply power instead)
660 * 100 mA -- usb unit load (slowest charge rate)
661 * 500 mA -- usb high power (fast battery charge)
662 */
663int tps65010_set_vbus_draw(unsigned mA)
664{
665 unsigned long flags;
666
667 if (!the_tps)
668 return -ENODEV;
669
670 /* assumes non-SMP */
671 local_irq_save(flags);
672 if (mA >= 500)
673 mA = 500;
674 else if (mA >= 100)
675 mA = 100;
676 else
677 mA = 0;
678 the_tps->vbus = mA;
679 if ((the_tps->chgstatus & TPS_CHG_USB)
680 && test_and_set_bit(
681 FLAG_VBUS_CHANGED, &the_tps->flags)) {
682 /* gadget drivers call this in_irq() */
David Brownell8c1bc042006-12-13 00:33:46 -0800683 (void) schedule_work(&the_tps->work.work);
David Brownell72cd7992005-05-24 17:34:51 -0700684 }
685 local_irq_restore(flags);
686
687 return 0;
688}
689EXPORT_SYMBOL(tps65010_set_vbus_draw);
690
691/*-------------------------------------------------------------------------*/
692/* tps65010_set_gpio_out_value parameter:
693 * gpio: GPIO1, GPIO2, GPIO3 or GPIO4
694 * value: LOW or HIGH
695 */
696int tps65010_set_gpio_out_value(unsigned gpio, unsigned value)
697{
698 int status;
699 unsigned defgpio;
700
701 if (!the_tps)
702 return -ENODEV;
703 if ((gpio < GPIO1) || (gpio > GPIO4))
704 return -EINVAL;
705
Ingo Molnar5c085d32006-01-18 23:16:04 +0100706 mutex_lock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700707
David Brownellb5067f82007-10-13 23:56:30 +0200708 defgpio = i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO);
David Brownell72cd7992005-05-24 17:34:51 -0700709
710 /* Configure GPIO for output */
711 defgpio |= 1 << (gpio + 3);
712
713 /* Writing 1 forces a logic 0 on that GPIO and vice versa */
714 switch (value) {
715 case LOW:
716 defgpio |= 1 << (gpio - 1); /* set GPIO low by writing 1 */
717 break;
718 /* case HIGH: */
719 default:
720 defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */
721 break;
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_DEFGPIO, defgpio);
726
727 pr_debug("%s: gpio%dout = %s, defgpio 0x%02x\n", DRIVER_NAME,
728 gpio, value ? "high" : "low",
David Brownellb5067f82007-10-13 23:56:30 +0200729 i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO));
David Brownell72cd7992005-05-24 17:34:51 -0700730
Ingo Molnar5c085d32006-01-18 23:16:04 +0100731 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700732 return status;
733}
734EXPORT_SYMBOL(tps65010_set_gpio_out_value);
735
736/*-------------------------------------------------------------------------*/
737/* tps65010_set_led parameter:
738 * led: LED1 or LED2
739 * mode: ON, OFF or BLINK
740 */
741int tps65010_set_led(unsigned led, unsigned mode)
742{
743 int status;
744 unsigned led_on, led_per, offs;
745
746 if (!the_tps)
747 return -ENODEV;
748
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700749 if (led == LED1)
David Brownell72cd7992005-05-24 17:34:51 -0700750 offs = 0;
751 else {
752 offs = 2;
753 led = LED2;
754 }
755
Ingo Molnar5c085d32006-01-18 23:16:04 +0100756 mutex_lock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700757
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700758 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
David Brownellb5067f82007-10-13 23:56:30 +0200759 i2c_smbus_read_byte_data(the_tps->client,
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700760 TPS_LED1_ON + offs));
David Brownell72cd7992005-05-24 17:34:51 -0700761
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700762 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
David Brownellb5067f82007-10-13 23:56:30 +0200763 i2c_smbus_read_byte_data(the_tps->client,
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700764 TPS_LED1_PER + offs));
David Brownell72cd7992005-05-24 17:34:51 -0700765
766 switch (mode) {
767 case OFF:
768 led_on = 1 << 7;
769 led_per = 0 << 7;
770 break;
771 case ON:
772 led_on = 1 << 7;
773 led_per = 1 << 7;
774 break;
775 case BLINK:
776 led_on = 0x30 | (0 << 7);
777 led_per = 0x08 | (1 << 7);
778 break;
779 default:
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700780 printk(KERN_ERR "%s: Wrong mode parameter for set_led()\n",
David Brownell72cd7992005-05-24 17:34:51 -0700781 DRIVER_NAME);
Ingo Molnar5c085d32006-01-18 23:16:04 +0100782 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700783 return -EINVAL;
784 }
785
David Brownellb5067f82007-10-13 23:56:30 +0200786 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700787 TPS_LED1_ON + offs, led_on);
788
789 if (status != 0) {
790 printk(KERN_ERR "%s: Failed to write led%i_on register\n",
791 DRIVER_NAME, led);
Ingo Molnar5c085d32006-01-18 23:16:04 +0100792 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700793 return status;
794 }
795
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700796 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
David Brownellb5067f82007-10-13 23:56:30 +0200797 i2c_smbus_read_byte_data(the_tps->client, TPS_LED1_ON + offs));
David Brownell72cd7992005-05-24 17:34:51 -0700798
David Brownellb5067f82007-10-13 23:56:30 +0200799 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700800 TPS_LED1_PER + offs, led_per);
801
802 if (status != 0) {
803 printk(KERN_ERR "%s: Failed to write led%i_per register\n",
804 DRIVER_NAME, led);
Ingo Molnar5c085d32006-01-18 23:16:04 +0100805 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700806 return status;
807 }
808
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700809 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
David Brownellb5067f82007-10-13 23:56:30 +0200810 i2c_smbus_read_byte_data(the_tps->client,
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700811 TPS_LED1_PER + offs));
David Brownell72cd7992005-05-24 17:34:51 -0700812
Ingo Molnar5c085d32006-01-18 23:16:04 +0100813 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700814
815 return status;
816}
817EXPORT_SYMBOL(tps65010_set_led);
818
819/*-------------------------------------------------------------------------*/
820/* tps65010_set_vib parameter:
821 * value: ON or OFF
822 */
823int tps65010_set_vib(unsigned value)
824{
825 int status;
826 unsigned vdcdc2;
827
828 if (!the_tps)
829 return -ENODEV;
830
Ingo Molnar5c085d32006-01-18 23:16:04 +0100831 mutex_lock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700832
David Brownellb5067f82007-10-13 23:56:30 +0200833 vdcdc2 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC2);
David Brownell72cd7992005-05-24 17:34:51 -0700834 vdcdc2 &= ~(1 << 1);
835 if (value)
836 vdcdc2 |= (1 << 1);
David Brownellb5067f82007-10-13 23:56:30 +0200837 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700838 TPS_VDCDC2, vdcdc2);
839
840 pr_debug("%s: vibrator %s\n", DRIVER_NAME, value ? "on" : "off");
841
Ingo Molnar5c085d32006-01-18 23:16:04 +0100842 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700843 return status;
844}
845EXPORT_SYMBOL(tps65010_set_vib);
846
847/*-------------------------------------------------------------------------*/
848/* tps65010_set_low_pwr parameter:
849 * mode: ON or OFF
850 */
851int tps65010_set_low_pwr(unsigned mode)
852{
853 int status;
854 unsigned vdcdc1;
855
856 if (!the_tps)
857 return -ENODEV;
858
Ingo Molnar5c085d32006-01-18 23:16:04 +0100859 mutex_lock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700860
861 pr_debug("%s: %s low_pwr, vdcdc1 0x%02x\n", DRIVER_NAME,
862 mode ? "enable" : "disable",
David Brownellb5067f82007-10-13 23:56:30 +0200863 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
David Brownell72cd7992005-05-24 17:34:51 -0700864
David Brownellb5067f82007-10-13 23:56:30 +0200865 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
David Brownell72cd7992005-05-24 17:34:51 -0700866
867 switch (mode) {
868 case OFF:
869 vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */
870 break;
871 /* case ON: */
872 default:
873 vdcdc1 |= TPS_ENABLE_LP; /* enable ENABLE_LP bit */
874 break;
875 }
876
David Brownellb5067f82007-10-13 23:56:30 +0200877 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700878 TPS_VDCDC1, vdcdc1);
879
880 if (status != 0)
881 printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700882 DRIVER_NAME);
David Brownell72cd7992005-05-24 17:34:51 -0700883 else
884 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
David Brownellb5067f82007-10-13 23:56:30 +0200885 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
David Brownell72cd7992005-05-24 17:34:51 -0700886
Ingo Molnar5c085d32006-01-18 23:16:04 +0100887 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700888
889 return status;
890}
891EXPORT_SYMBOL(tps65010_set_low_pwr);
892
893/*-------------------------------------------------------------------------*/
894/* tps65010_config_vregs1 parameter:
895 * value to be written to VREGS1 register
896 * Note: The complete register is written, set all bits you need
897 */
898int tps65010_config_vregs1(unsigned value)
899{
900 int status;
901
902 if (!the_tps)
903 return -ENODEV;
904
Ingo Molnar5c085d32006-01-18 23:16:04 +0100905 mutex_lock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700906
907 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
David Brownellb5067f82007-10-13 23:56:30 +0200908 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
David Brownell72cd7992005-05-24 17:34:51 -0700909
David Brownellb5067f82007-10-13 23:56:30 +0200910 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700911 TPS_VREGS1, value);
912
913 if (status != 0)
914 printk(KERN_ERR "%s: Failed to write vregs1 register\n",
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -0700915 DRIVER_NAME);
David Brownell72cd7992005-05-24 17:34:51 -0700916 else
917 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
David Brownellb5067f82007-10-13 23:56:30 +0200918 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
David Brownell72cd7992005-05-24 17:34:51 -0700919
Ingo Molnar5c085d32006-01-18 23:16:04 +0100920 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700921
922 return status;
923}
924EXPORT_SYMBOL(tps65010_config_vregs1);
925
926/*-------------------------------------------------------------------------*/
927/* tps65013_set_low_pwr parameter:
928 * mode: ON or OFF
929 */
930
931/* FIXME: Assumes AC or USB power is present. Setting AUA bit is not
932 required if power supply is through a battery */
933
934int tps65013_set_low_pwr(unsigned mode)
935{
936 int status;
937 unsigned vdcdc1, chgconfig;
938
939 if (!the_tps || the_tps->por)
940 return -ENODEV;
941
Ingo Molnar5c085d32006-01-18 23:16:04 +0100942 mutex_lock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700943
944 pr_debug("%s: %s low_pwr, chgconfig 0x%02x vdcdc1 0x%02x\n",
945 DRIVER_NAME,
946 mode ? "enable" : "disable",
David Brownellb5067f82007-10-13 23:56:30 +0200947 i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG),
948 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
David Brownell72cd7992005-05-24 17:34:51 -0700949
David Brownellb5067f82007-10-13 23:56:30 +0200950 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
951 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
David Brownell72cd7992005-05-24 17:34:51 -0700952
953 switch (mode) {
954 case OFF:
955 chgconfig &= ~TPS65013_AUA; /* disable AUA bit */
956 vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */
957 break;
958 /* case ON: */
959 default:
960 chgconfig |= TPS65013_AUA; /* enable AUA bit */
961 vdcdc1 |= TPS_ENABLE_LP; /* enable ENABLE_LP bit */
962 break;
963 }
964
David Brownellb5067f82007-10-13 23:56:30 +0200965 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700966 TPS_CHGCONFIG, chgconfig);
967 if (status != 0) {
968 printk(KERN_ERR "%s: Failed to write chconfig register\n",
969 DRIVER_NAME);
Ingo Molnar5c085d32006-01-18 23:16:04 +0100970 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700971 return status;
972 }
973
David Brownellb5067f82007-10-13 23:56:30 +0200974 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
David Brownell72cd7992005-05-24 17:34:51 -0700975 the_tps->chgconf = chgconfig;
976 show_chgconfig(0, "chgconf", chgconfig);
977
David Brownellb5067f82007-10-13 23:56:30 +0200978 status = i2c_smbus_write_byte_data(the_tps->client,
David Brownell72cd7992005-05-24 17:34:51 -0700979 TPS_VDCDC1, vdcdc1);
980
981 if (status != 0)
982 printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
983 DRIVER_NAME);
984 else
985 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
David Brownellb5067f82007-10-13 23:56:30 +0200986 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
David Brownell72cd7992005-05-24 17:34:51 -0700987
Ingo Molnar5c085d32006-01-18 23:16:04 +0100988 mutex_unlock(&the_tps->lock);
David Brownell72cd7992005-05-24 17:34:51 -0700989
990 return status;
991}
992EXPORT_SYMBOL(tps65013_set_low_pwr);
993
994/*-------------------------------------------------------------------------*/
995
996static int __init tps_init(void)
997{
998 u32 tries = 3;
999 int status = -ENODEV;
1000
1001 printk(KERN_INFO "%s: version %s\n", DRIVER_NAME, DRIVER_VERSION);
1002
1003 /* some boards have startup glitches */
1004 while (tries--) {
1005 status = i2c_add_driver(&tps65010_driver);
1006 if (the_tps)
1007 break;
1008 i2c_del_driver(&tps65010_driver);
1009 if (!tries) {
1010 printk(KERN_ERR "%s: no chip?\n", DRIVER_NAME);
1011 return -ENODEV;
1012 }
1013 pr_debug("%s: re-probe ...\n", DRIVER_NAME);
1014 msleep(10);
1015 }
1016
david-b@pacbell.net65fc50e2005-06-29 07:13:00 -07001017#ifdef CONFIG_ARM
David Brownell72cd7992005-05-24 17:34:51 -07001018 if (machine_is_omap_osk()) {
1019
1020 // FIXME: More should be placed in the initialization code
1021 // of the submodules (DSP, ethernet, power management,
1022 // board-osk.c). Careful: I2C is initialized "late".
1023
1024 /* Let LED1 (D9) blink */
1025 tps65010_set_led(LED1, BLINK);
1026
1027 /* Disable LED 2 (D2) */
1028 tps65010_set_led(LED2, OFF);
1029
1030 /* Set GPIO 1 HIGH to disable VBUS power supply;
1031 * OHCI driver powers it up/down as needed.
1032 */
1033 tps65010_set_gpio_out_value(GPIO1, HIGH);
1034
1035 /* Set GPIO 2 low to turn on LED D3 */
1036 tps65010_set_gpio_out_value(GPIO2, HIGH);
1037
1038 /* Set GPIO 3 low to take ethernet out of reset */
1039 tps65010_set_gpio_out_value(GPIO3, LOW);
1040
1041 /* gpio4 for VDD_DSP */
1042
1043 /* Enable LOW_PWR */
1044 tps65010_set_low_pwr(ON);
1045
1046 /* Switch VLDO2 to 3.0V for AIC23 */
1047 tps65010_config_vregs1(TPS_LDO2_ENABLE | TPS_VLDO2_3_0V | TPS_LDO1_ENABLE);
1048
1049 } else if (machine_is_omap_h2()) {
1050 /* gpio3 for SD, gpio4 for VDD_DSP */
1051
1052 /* Enable LOW_PWR */
1053 tps65010_set_low_pwr(ON);
1054 } else if (machine_is_omap_h3()) {
1055 /* gpio4 for SD, gpio3 for VDD_DSP */
1056#ifdef CONFIG_PM
1057 /* Enable LOW_PWR */
1058 tps65013_set_low_pwr(ON);
1059#endif
1060 }
1061#endif
1062
1063 return status;
1064}
1065/* NOTE: this MUST be initialized before the other parts of the system
1066 * that rely on it ... but after the i2c bus on which this relies.
1067 * That is, much earlier than on PC-type systems, which don't often use
1068 * I2C as a core system bus.
1069 */
1070subsys_initcall(tps_init);
1071
1072static void __exit tps_exit(void)
1073{
1074 i2c_del_driver(&tps65010_driver);
1075}
1076module_exit(tps_exit);
1077