2 * tps65010 - driver for tps6501x power management chips
4 * Copyright (C) 2004 Texas Instruments
5 * Copyright (C) 2004-2005 David Brownell
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.
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.
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.
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/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>
34 #include <linux/mutex.h>
37 #include <asm/mach-types.h>
39 #include <asm/arch/gpio.h>
40 #include <asm/arch/mux.h>
41 #include <asm/arch/tps65010.h>
43 /*-------------------------------------------------------------------------*/
45 #define DRIVER_VERSION "2 May 2005"
46 #define DRIVER_NAME (tps65010_driver.driver.name)
48 MODULE_DESCRIPTION("TPS6501x Power Management Driver");
49 MODULE_LICENSE("GPL");
51 static unsigned short normal_i2c
[] = { 0x48, /* 0x49, */ I2C_CLIENT_END
};
55 static struct i2c_driver tps65010_driver
;
57 /*-------------------------------------------------------------------------*/
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
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.
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.
82 struct i2c_client client
;
85 struct delayed_work work
;
92 #define FLAG_VBUS_CHANGED 0
93 #define FLAG_IRQ_ENABLE 1
95 /* copies of last register state */
96 u8 chgstatus
, regstatus
, chgconf
;
99 /* not currently tracking GPIO state */
102 #define POWER_POLL_DELAY msecs_to_jiffies(5000)
104 /*-------------------------------------------------------------------------*/
106 #if defined(DEBUG) || defined(CONFIG_DEBUG_FS)
108 static void dbg_chgstat(char *buf
, size_t len
, u8 chgstatus
)
110 snprintf(buf
, len
, "%02x%s%s%s%s%s%s%s%s\n",
112 (chgstatus
& TPS_CHG_USB
) ? " USB" : "",
113 (chgstatus
& TPS_CHG_AC
) ? " AC" : "",
114 (chgstatus
& TPS_CHG_THERM
) ? " therm" : "",
115 (chgstatus
& TPS_CHG_TERM
) ? " done" :
116 ((chgstatus
& (TPS_CHG_USB
|TPS_CHG_AC
))
117 ? " (charging)" : ""),
118 (chgstatus
& TPS_CHG_TAPER_TMO
) ? " taper_tmo" : "",
119 (chgstatus
& TPS_CHG_CHG_TMO
) ? " charge_tmo" : "",
120 (chgstatus
& TPS_CHG_PRECHG_TMO
) ? " prechg_tmo" : "",
121 (chgstatus
& TPS_CHG_TEMP_ERR
) ? " temp_err" : "");
124 static void dbg_regstat(char *buf
, size_t len
, u8 regstatus
)
126 snprintf(buf
, len
, "%02x %s%s%s%s%s%s%s%s\n",
128 (regstatus
& TPS_REG_ONOFF
) ? "off" : "(on)",
129 (regstatus
& TPS_REG_COVER
) ? " uncover" : "",
130 (regstatus
& TPS_REG_UVLO
) ? " UVLO" : "",
131 (regstatus
& TPS_REG_NO_CHG
) ? " NO_CHG" : "",
132 (regstatus
& TPS_REG_PG_LD02
) ? " ld02_bad" : "",
133 (regstatus
& TPS_REG_PG_LD01
) ? " ld01_bad" : "",
134 (regstatus
& TPS_REG_PG_MAIN
) ? " main_bad" : "",
135 (regstatus
& TPS_REG_PG_CORE
) ? " core_bad" : "");
138 static void dbg_chgconf(int por
, char *buf
, size_t len
, u8 chgconfig
)
143 hibit
= (chgconfig
& TPS_CHARGE_POR
)
144 ? "POR=69ms" : "POR=1sec";
146 hibit
= (chgconfig
& TPS65013_AUA
) ? "AUA" : "";
148 snprintf(buf
, len
, "%02x %s%s%s AC=%d%% USB=%dmA %sCharge\n",
150 (chgconfig
& TPS_CHARGE_RESET
) ? " reset" : "",
151 (chgconfig
& TPS_CHARGE_FAST
) ? " fast" : "",
152 ({int p
; switch ((chgconfig
>> 3) & 3) {
153 case 3: p
= 100; break;
154 case 2: p
= 75; break;
155 case 1: p
= 50; break;
156 default: p
= 25; break;
158 (chgconfig
& TPS_VBUS_CHARGING
)
159 ? ((chgconfig
& TPS_VBUS_500MA
) ? 500 : 100)
161 (chgconfig
& TPS_CHARGE_ENABLE
) ? "" : "No");
168 static void show_chgstatus(const char *label
, u8 chgstatus
)
172 dbg_chgstat(buf
, sizeof buf
, chgstatus
);
173 pr_debug("%s: %s %s", DRIVER_NAME
, label
, buf
);
176 static void show_regstatus(const char *label
, u8 regstatus
)
180 dbg_regstat(buf
, sizeof buf
, regstatus
);
181 pr_debug("%s: %s %s", DRIVER_NAME
, label
, buf
);
184 static void show_chgconfig(int por
, const char *label
, u8 chgconfig
)
188 dbg_chgconf(por
, buf
, sizeof buf
, chgconfig
);
189 pr_debug("%s: %s %s", DRIVER_NAME
, label
, buf
);
194 static inline void show_chgstatus(const char *label
, u8 chgstatus
) { }
195 static inline void show_regstatus(const char *label
, u8 chgstatus
) { }
196 static inline void show_chgconfig(int por
, const char *label
, u8 chgconfig
) { }
200 #ifdef CONFIG_DEBUG_FS
202 static int dbg_show(struct seq_file
*s
, void *_
)
204 struct tps65010
*tps
= s
->private;
210 switch (tps
->model
) {
211 case TPS65010
: chip
= "tps65010"; break;
212 case TPS65011
: chip
= "tps65011"; break;
213 case TPS65012
: chip
= "tps65012"; break;
214 case TPS65013
: chip
= "tps65013"; break;
215 default: chip
= NULL
; break;
217 seq_printf(s
, "driver %s\nversion %s\nchip %s\n\n",
218 DRIVER_NAME
, DRIVER_VERSION
, chip
);
220 mutex_lock(&tps
->lock
);
222 /* FIXME how can we tell whether a battery is present?
223 * likely involves a charge gauging chip (like BQ26501).
226 seq_printf(s
, "%scharging\n\n", tps
->charging
? "" : "(not) ");
229 /* registers for monitoring battery charging and status; note
230 * that reading chgstat and regstat may ack IRQs...
232 value
= i2c_smbus_read_byte_data(&tps
->client
, TPS_CHGCONFIG
);
233 dbg_chgconf(tps
->por
, buf
, sizeof buf
, value
);
234 seq_printf(s
, "chgconfig %s", buf
);
236 value
= i2c_smbus_read_byte_data(&tps
->client
, TPS_CHGSTATUS
);
237 dbg_chgstat(buf
, sizeof buf
, value
);
238 seq_printf(s
, "chgstat %s", buf
);
239 value
= i2c_smbus_read_byte_data(&tps
->client
, TPS_MASK1
);
240 dbg_chgstat(buf
, sizeof buf
, value
);
241 seq_printf(s
, "mask1 %s", buf
);
244 value
= i2c_smbus_read_byte_data(&tps
->client
, TPS_REGSTATUS
);
245 dbg_regstat(buf
, sizeof buf
, value
);
246 seq_printf(s
, "regstat %s", buf
);
247 value
= i2c_smbus_read_byte_data(&tps
->client
, TPS_MASK2
);
248 dbg_regstat(buf
, sizeof buf
, value
);
249 seq_printf(s
, "mask2 %s\n", buf
);
252 (void) schedule_delayed_work(&tps
->work
, POWER_POLL_DELAY
);
255 /* VMAIN voltage, enable lowpower, etc */
256 value
= i2c_smbus_read_byte_data(&tps
->client
, TPS_VDCDC1
);
257 seq_printf(s
, "vdcdc1 %02x\n", value
);
259 /* VCORE voltage, vibrator on/off */
260 value
= i2c_smbus_read_byte_data(&tps
->client
, TPS_VDCDC2
);
261 seq_printf(s
, "vdcdc2 %02x\n", value
);
263 /* both LD0s, and their lowpower behavior */
264 value
= i2c_smbus_read_byte_data(&tps
->client
, TPS_VREGS1
);
265 seq_printf(s
, "vregs1 %02x\n\n", value
);
269 value
= i2c_smbus_read_byte_data(&tps
->client
, TPS_LED1_ON
);
270 v2
= i2c_smbus_read_byte_data(&tps
->client
, TPS_LED1_PER
);
271 seq_printf(s
, "led1 %s, on=%02x, per=%02x, %d/%d msec\n",
273 ? ((v2
& 0x80) ? "on" : "off")
274 : ((v2
& 0x80) ? "blink" : "(nPG)"),
276 (value
& 0x7f) * 10, (v2
& 0x7f) * 100);
278 value
= i2c_smbus_read_byte_data(&tps
->client
, TPS_LED2_ON
);
279 v2
= i2c_smbus_read_byte_data(&tps
->client
, TPS_LED2_PER
);
280 seq_printf(s
, "led2 %s, on=%02x, per=%02x, %d/%d msec\n",
282 ? ((v2
& 0x80) ? "on" : "off")
283 : ((v2
& 0x80) ? "blink" : "off"),
285 (value
& 0x7f) * 10, (v2
& 0x7f) * 100);
287 value
= i2c_smbus_read_byte_data(&tps
->client
, TPS_DEFGPIO
);
288 v2
= i2c_smbus_read_byte_data(&tps
->client
, TPS_MASK3
);
289 seq_printf(s
, "defgpio %02x mask3 %02x\n", value
, v2
);
291 for (i
= 0; i
< 4; i
++) {
292 if (value
& (1 << (4 + i
)))
293 seq_printf(s
, " gpio%d-out %s\n", i
+ 1,
294 (value
& (1 << i
)) ? "low" : "hi ");
296 seq_printf(s
, " gpio%d-in %s %s %s\n", i
+ 1,
297 (value
& (1 << i
)) ? "hi " : "low",
298 (v2
& (1 << i
)) ? "no-irq" : "irq",
299 (v2
& (1 << (4 + i
))) ? "rising" : "falling");
302 mutex_unlock(&tps
->lock
);
306 static int dbg_tps_open(struct inode
*inode
, struct file
*file
)
308 return single_open(file
, dbg_show
, inode
->i_private
);
311 static struct file_operations debug_fops
= {
312 .open
= dbg_tps_open
,
315 .release
= single_release
,
318 #define DEBUG_FOPS &debug_fops
321 #define DEBUG_FOPS NULL
324 /*-------------------------------------------------------------------------*/
326 /* handle IRQS in a task context, so we can use I2C calls */
327 static void tps65010_interrupt(struct tps65010
*tps
)
329 u8 tmp
= 0, mask
, poll
;
331 /* IRQs won't trigger for certain events, but we can get
332 * others by polling (normally, with external power applied).
338 tmp
= i2c_smbus_read_byte_data(&tps
->client
, TPS_REGSTATUS
);
339 mask
= tmp
^ tps
->regstatus
;
340 tps
->regstatus
= tmp
;
345 tps
->regstatus
= tmp
;
346 /* may need to shut something down ... */
348 /* "off" usually means deep sleep */
349 if (tmp
& TPS_REG_ONOFF
) {
350 pr_info("%s: power off button\n", DRIVER_NAME
);
352 /* REVISIT: this might need its own workqueue
353 * plus tweaks including deadlock avoidance ...
363 tmp
= i2c_smbus_read_byte_data(&tps
->client
, TPS_CHGSTATUS
);
364 mask
= tmp
^ tps
->chgstatus
;
365 tps
->chgstatus
= tmp
;
370 unsigned charging
= 0;
372 show_chgstatus("chg/irq", tmp
);
373 if (tmp
& (TPS_CHG_USB
|TPS_CHG_AC
))
374 show_chgconfig(tps
->por
, "conf", tps
->chgconf
);
376 /* Unless it was turned off or disabled, we charge any
377 * battery whenever there's power available for it
378 * and the charger hasn't been disabled.
380 if (!(tps
->chgstatus
& ~(TPS_CHG_USB
|TPS_CHG_AC
))
381 && (tps
->chgstatus
& (TPS_CHG_USB
|TPS_CHG_AC
))
382 && (tps
->chgconf
& TPS_CHARGE_ENABLE
)
384 if (tps
->chgstatus
& TPS_CHG_USB
) {
385 /* VBUS options are readonly until reconnect */
386 if (mask
& TPS_CHG_USB
)
387 set_bit(FLAG_VBUS_CHANGED
, &tps
->flags
);
389 } else if (tps
->chgstatus
& TPS_CHG_AC
)
392 if (charging
!= tps
->charging
) {
393 tps
->charging
= charging
;
394 pr_info("%s: battery %scharging\n",
395 DRIVER_NAME
, charging
? "" :
396 ((tps
->chgstatus
& (TPS_CHG_USB
|TPS_CHG_AC
))
401 /* always poll to detect (a) power removal, without tps65013
402 * NO_CHG IRQ; or (b) restart of charging after stop.
404 if ((tps
->model
!= TPS65013
|| !tps
->charging
)
405 && (tps
->chgstatus
& (TPS_CHG_USB
|TPS_CHG_AC
)))
408 (void) schedule_delayed_work(&tps
->work
, POWER_POLL_DELAY
);
410 /* also potentially gpio-in rise or fall */
413 /* handle IRQs and polling using keventd for now */
414 static void tps65010_work(struct work_struct
*work
)
416 struct tps65010
*tps
;
418 tps
= container_of(work
, struct tps65010
, work
.work
);
419 mutex_lock(&tps
->lock
);
421 tps65010_interrupt(tps
);
423 if (test_and_clear_bit(FLAG_VBUS_CHANGED
, &tps
->flags
)) {
427 chgconfig
= i2c_smbus_read_byte_data(&tps
->client
,
429 chgconfig
&= ~(TPS_VBUS_500MA
| TPS_VBUS_CHARGING
);
430 if (tps
->vbus
== 500)
431 chgconfig
|= TPS_VBUS_500MA
| TPS_VBUS_CHARGING
;
432 else if (tps
->vbus
>= 100)
433 chgconfig
|= TPS_VBUS_CHARGING
;
435 status
= i2c_smbus_write_byte_data(&tps
->client
,
436 TPS_CHGCONFIG
, chgconfig
);
438 /* vbus update fails unless VBUS is connected! */
439 tmp
= i2c_smbus_read_byte_data(&tps
->client
, TPS_CHGCONFIG
);
441 show_chgconfig(tps
->por
, "update vbus", tmp
);
444 if (test_and_clear_bit(FLAG_IRQ_ENABLE
, &tps
->flags
))
445 enable_irq(tps
->irq
);
447 mutex_unlock(&tps
->lock
);
450 static irqreturn_t
tps65010_irq(int irq
, void *_tps
)
452 struct tps65010
*tps
= _tps
;
454 disable_irq_nosync(irq
);
455 set_bit(FLAG_IRQ_ENABLE
, &tps
->flags
);
456 (void) schedule_work(&tps
->work
.work
);
460 /*-------------------------------------------------------------------------*/
462 static struct tps65010
*the_tps
;
464 static int __exit
tps65010_detach_client(struct i2c_client
*client
)
466 struct tps65010
*tps
;
468 tps
= container_of(client
, struct tps65010
, client
);
469 free_irq(tps
->irq
, tps
);
471 if (machine_is_omap_h2())
473 if (machine_is_omap_osk())
474 omap_free_gpio(OMAP_MPUIO(1));
476 cancel_delayed_work(&tps
->work
);
477 flush_scheduled_work();
478 debugfs_remove(tps
->file
);
479 if (i2c_detach_client(client
) == 0)
485 static int tps65010_noscan(struct i2c_adapter
*bus
)
487 /* pure paranoia, in case someone adds another i2c bus
488 * after our init section's gone...
493 /* no error returns, they'd just make bus scanning stop */
495 tps65010_probe(struct i2c_adapter
*bus
, int address
, int kind
)
497 struct tps65010
*tps
;
499 unsigned long irqflags
;
502 dev_dbg(&bus
->dev
, "only one %s for now\n", DRIVER_NAME
);
506 tps
= kzalloc(sizeof *tps
, GFP_KERNEL
);
510 mutex_init(&tps
->lock
);
511 INIT_DELAYED_WORK(&tps
->work
, tps65010_work
);
513 tps
->client
.addr
= address
;
514 tps
->client
.adapter
= bus
;
515 tps
->client
.driver
= &tps65010_driver
;
516 strlcpy(tps
->client
.name
, DRIVER_NAME
, I2C_NAME_SIZE
);
518 status
= i2c_attach_client(&tps
->client
);
520 dev_dbg(&bus
->dev
, "can't attach %s to device %d, err %d\n",
521 DRIVER_NAME
, address
, status
);
525 /* the IRQ is active low, but many gpio lines can't support that
526 * so this driver can use falling-edge triggers instead.
528 irqflags
= IRQF_SAMPLE_RANDOM
;
530 if (machine_is_omap_h2()) {
531 tps
->model
= TPS65010
;
532 omap_cfg_reg(W4_GPIO58
);
533 tps
->irq
= OMAP_GPIO_IRQ(58);
534 omap_request_gpio(58);
535 omap_set_gpio_direction(58, 1);
536 irqflags
|= IRQF_TRIGGER_FALLING
;
538 if (machine_is_omap_osk()) {
539 tps
->model
= TPS65010
;
540 // omap_cfg_reg(U19_1610_MPUIO1);
541 tps
->irq
= OMAP_GPIO_IRQ(OMAP_MPUIO(1));
542 omap_request_gpio(OMAP_MPUIO(1));
543 omap_set_gpio_direction(OMAP_MPUIO(1), 1);
544 irqflags
|= IRQF_TRIGGER_FALLING
;
546 if (machine_is_omap_h3()) {
547 tps
->model
= TPS65013
;
549 // FIXME set up this board's IRQ ...
554 status
= request_irq(tps
->irq
, tps65010_irq
,
555 irqflags
, DRIVER_NAME
, tps
);
557 dev_dbg(&tps
->client
.dev
, "can't get IRQ %d, err %d\n",
559 i2c_detach_client(&tps
->client
);
563 /* annoying race here, ideally we'd have an option
564 * to claim the irq now and enable it later.
566 disable_irq(tps
->irq
);
567 set_bit(FLAG_IRQ_ENABLE
, &tps
->flags
);
570 printk(KERN_WARNING
"%s: IRQ not configured!\n",
574 switch (tps
->model
) {
580 printk(KERN_WARNING
"%s: unknown TPS chip\n", DRIVER_NAME
);
582 /* else CHGCONFIG.POR is replaced by AUA, enabling a WAIT mode */
584 tps
->chgconf
= i2c_smbus_read_byte_data(&tps
->client
, TPS_CHGCONFIG
);
585 show_chgconfig(tps
->por
, "conf/init", tps
->chgconf
);
587 show_chgstatus("chg/init",
588 i2c_smbus_read_byte_data(&tps
->client
, TPS_CHGSTATUS
));
589 show_regstatus("reg/init",
590 i2c_smbus_read_byte_data(&tps
->client
, TPS_REGSTATUS
));
592 pr_debug("%s: vdcdc1 0x%02x, vdcdc2 %02x, vregs1 %02x\n", DRIVER_NAME
,
593 i2c_smbus_read_byte_data(&tps
->client
, TPS_VDCDC1
),
594 i2c_smbus_read_byte_data(&tps
->client
, TPS_VDCDC2
),
595 i2c_smbus_read_byte_data(&tps
->client
, TPS_VREGS1
));
596 pr_debug("%s: defgpio 0x%02x, mask3 0x%02x\n", DRIVER_NAME
,
597 i2c_smbus_read_byte_data(&tps
->client
, TPS_DEFGPIO
),
598 i2c_smbus_read_byte_data(&tps
->client
, TPS_MASK3
));
600 tps65010_driver
.attach_adapter
= tps65010_noscan
;
603 #if defined(CONFIG_USB_GADGET) && !defined(CONFIG_USB_OTG)
604 /* USB hosts can't draw VBUS. OTG devices could, later
605 * when OTG infrastructure enables it. USB peripherals
606 * could be relying on VBUS while booting, though.
611 /* unmask the "interesting" irqs, then poll once to
612 * kickstart monitoring, initialize shadowed status
613 * registers, and maybe disable VBUS draw.
616 (void) i2c_smbus_write_byte_data(&tps
->client
, TPS_MASK1
, ~tps
->nmask1
);
618 tps
->nmask2
= TPS_REG_ONOFF
;
619 if (tps
->model
== TPS65013
)
620 tps
->nmask2
|= TPS_REG_NO_CHG
;
621 (void) i2c_smbus_write_byte_data(&tps
->client
, TPS_MASK2
, ~tps
->nmask2
);
623 (void) i2c_smbus_write_byte_data(&tps
->client
, TPS_MASK3
, 0x0f
624 | i2c_smbus_read_byte_data(&tps
->client
, TPS_MASK3
));
626 tps65010_work(&tps
->work
.work
);
628 tps
->file
= debugfs_create_file(DRIVER_NAME
, S_IRUGO
, NULL
,
636 static int __init
tps65010_scan_bus(struct i2c_adapter
*bus
)
638 if (!i2c_check_functionality(bus
, I2C_FUNC_SMBUS_BYTE_DATA
))
640 return i2c_probe(bus
, &addr_data
, tps65010_probe
);
643 static struct i2c_driver tps65010_driver
= {
647 .attach_adapter
= tps65010_scan_bus
,
648 .detach_client
= __exit_p(tps65010_detach_client
),
651 /*-------------------------------------------------------------------------*/
654 * 0 mA -- DON'T DRAW (might supply power instead)
655 * 100 mA -- usb unit load (slowest charge rate)
656 * 500 mA -- usb high power (fast battery charge)
658 int tps65010_set_vbus_draw(unsigned mA
)
665 /* assumes non-SMP */
666 local_irq_save(flags
);
674 if ((the_tps
->chgstatus
& TPS_CHG_USB
)
676 FLAG_VBUS_CHANGED
, &the_tps
->flags
)) {
677 /* gadget drivers call this in_irq() */
678 (void) schedule_work(&the_tps
->work
.work
);
680 local_irq_restore(flags
);
684 EXPORT_SYMBOL(tps65010_set_vbus_draw
);
686 /*-------------------------------------------------------------------------*/
687 /* tps65010_set_gpio_out_value parameter:
688 * gpio: GPIO1, GPIO2, GPIO3 or GPIO4
691 int tps65010_set_gpio_out_value(unsigned gpio
, unsigned value
)
698 if ((gpio
< GPIO1
) || (gpio
> GPIO4
))
701 mutex_lock(&the_tps
->lock
);
703 defgpio
= i2c_smbus_read_byte_data(&the_tps
->client
, TPS_DEFGPIO
);
705 /* Configure GPIO for output */
706 defgpio
|= 1 << (gpio
+ 3);
708 /* Writing 1 forces a logic 0 on that GPIO and vice versa */
711 defgpio
|= 1 << (gpio
- 1); /* set GPIO low by writing 1 */
715 defgpio
&= ~(1 << (gpio
- 1)); /* set GPIO high by writing 0 */
719 status
= i2c_smbus_write_byte_data(&the_tps
->client
,
720 TPS_DEFGPIO
, defgpio
);
722 pr_debug("%s: gpio%dout = %s, defgpio 0x%02x\n", DRIVER_NAME
,
723 gpio
, value
? "high" : "low",
724 i2c_smbus_read_byte_data(&the_tps
->client
, TPS_DEFGPIO
));
726 mutex_unlock(&the_tps
->lock
);
729 EXPORT_SYMBOL(tps65010_set_gpio_out_value
);
731 /*-------------------------------------------------------------------------*/
732 /* tps65010_set_led parameter:
734 * mode: ON, OFF or BLINK
736 int tps65010_set_led(unsigned led
, unsigned mode
)
739 unsigned led_on
, led_per
, offs
;
751 mutex_lock(&the_tps
->lock
);
753 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME
, led
,
754 i2c_smbus_read_byte_data(&the_tps
->client
,
755 TPS_LED1_ON
+ offs
));
757 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME
, led
,
758 i2c_smbus_read_byte_data(&the_tps
->client
,
759 TPS_LED1_PER
+ offs
));
771 led_on
= 0x30 | (0 << 7);
772 led_per
= 0x08 | (1 << 7);
775 printk(KERN_ERR
"%s: Wrong mode parameter for set_led()\n",
777 mutex_unlock(&the_tps
->lock
);
781 status
= i2c_smbus_write_byte_data(&the_tps
->client
,
782 TPS_LED1_ON
+ offs
, led_on
);
785 printk(KERN_ERR
"%s: Failed to write led%i_on register\n",
787 mutex_unlock(&the_tps
->lock
);
791 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME
, led
,
792 i2c_smbus_read_byte_data(&the_tps
->client
, TPS_LED1_ON
+ offs
));
794 status
= i2c_smbus_write_byte_data(&the_tps
->client
,
795 TPS_LED1_PER
+ offs
, led_per
);
798 printk(KERN_ERR
"%s: Failed to write led%i_per register\n",
800 mutex_unlock(&the_tps
->lock
);
804 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME
, led
,
805 i2c_smbus_read_byte_data(&the_tps
->client
,
806 TPS_LED1_PER
+ offs
));
808 mutex_unlock(&the_tps
->lock
);
812 EXPORT_SYMBOL(tps65010_set_led
);
814 /*-------------------------------------------------------------------------*/
815 /* tps65010_set_vib parameter:
818 int tps65010_set_vib(unsigned value
)
826 mutex_lock(&the_tps
->lock
);
828 vdcdc2
= i2c_smbus_read_byte_data(&the_tps
->client
, TPS_VDCDC2
);
832 status
= i2c_smbus_write_byte_data(&the_tps
->client
,
835 pr_debug("%s: vibrator %s\n", DRIVER_NAME
, value
? "on" : "off");
837 mutex_unlock(&the_tps
->lock
);
840 EXPORT_SYMBOL(tps65010_set_vib
);
842 /*-------------------------------------------------------------------------*/
843 /* tps65010_set_low_pwr parameter:
846 int tps65010_set_low_pwr(unsigned mode
)
854 mutex_lock(&the_tps
->lock
);
856 pr_debug("%s: %s low_pwr, vdcdc1 0x%02x\n", DRIVER_NAME
,
857 mode
? "enable" : "disable",
858 i2c_smbus_read_byte_data(&the_tps
->client
, TPS_VDCDC1
));
860 vdcdc1
= i2c_smbus_read_byte_data(&the_tps
->client
, TPS_VDCDC1
);
864 vdcdc1
&= ~TPS_ENABLE_LP
; /* disable ENABLE_LP bit */
868 vdcdc1
|= TPS_ENABLE_LP
; /* enable ENABLE_LP bit */
872 status
= i2c_smbus_write_byte_data(&the_tps
->client
,
876 printk(KERN_ERR
"%s: Failed to write vdcdc1 register\n",
879 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME
,
880 i2c_smbus_read_byte_data(&the_tps
->client
, TPS_VDCDC1
));
882 mutex_unlock(&the_tps
->lock
);
886 EXPORT_SYMBOL(tps65010_set_low_pwr
);
888 /*-------------------------------------------------------------------------*/
889 /* tps65010_config_vregs1 parameter:
890 * value to be written to VREGS1 register
891 * Note: The complete register is written, set all bits you need
893 int tps65010_config_vregs1(unsigned value
)
900 mutex_lock(&the_tps
->lock
);
902 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME
,
903 i2c_smbus_read_byte_data(&the_tps
->client
, TPS_VREGS1
));
905 status
= i2c_smbus_write_byte_data(&the_tps
->client
,
909 printk(KERN_ERR
"%s: Failed to write vregs1 register\n",
912 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME
,
913 i2c_smbus_read_byte_data(&the_tps
->client
, TPS_VREGS1
));
915 mutex_unlock(&the_tps
->lock
);
919 EXPORT_SYMBOL(tps65010_config_vregs1
);
921 /*-------------------------------------------------------------------------*/
922 /* tps65013_set_low_pwr parameter:
926 /* FIXME: Assumes AC or USB power is present. Setting AUA bit is not
927 required if power supply is through a battery */
929 int tps65013_set_low_pwr(unsigned mode
)
932 unsigned vdcdc1
, chgconfig
;
934 if (!the_tps
|| the_tps
->por
)
937 mutex_lock(&the_tps
->lock
);
939 pr_debug("%s: %s low_pwr, chgconfig 0x%02x vdcdc1 0x%02x\n",
941 mode
? "enable" : "disable",
942 i2c_smbus_read_byte_data(&the_tps
->client
, TPS_CHGCONFIG
),
943 i2c_smbus_read_byte_data(&the_tps
->client
, TPS_VDCDC1
));
945 chgconfig
= i2c_smbus_read_byte_data(&the_tps
->client
, TPS_CHGCONFIG
);
946 vdcdc1
= i2c_smbus_read_byte_data(&the_tps
->client
, TPS_VDCDC1
);
950 chgconfig
&= ~TPS65013_AUA
; /* disable AUA bit */
951 vdcdc1
&= ~TPS_ENABLE_LP
; /* disable ENABLE_LP bit */
955 chgconfig
|= TPS65013_AUA
; /* enable AUA bit */
956 vdcdc1
|= TPS_ENABLE_LP
; /* enable ENABLE_LP bit */
960 status
= i2c_smbus_write_byte_data(&the_tps
->client
,
961 TPS_CHGCONFIG
, chgconfig
);
963 printk(KERN_ERR
"%s: Failed to write chconfig register\n",
965 mutex_unlock(&the_tps
->lock
);
969 chgconfig
= i2c_smbus_read_byte_data(&the_tps
->client
, TPS_CHGCONFIG
);
970 the_tps
->chgconf
= chgconfig
;
971 show_chgconfig(0, "chgconf", chgconfig
);
973 status
= i2c_smbus_write_byte_data(&the_tps
->client
,
977 printk(KERN_ERR
"%s: Failed to write vdcdc1 register\n",
980 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME
,
981 i2c_smbus_read_byte_data(&the_tps
->client
, TPS_VDCDC1
));
983 mutex_unlock(&the_tps
->lock
);
987 EXPORT_SYMBOL(tps65013_set_low_pwr
);
989 /*-------------------------------------------------------------------------*/
991 static int __init
tps_init(void)
994 int status
= -ENODEV
;
996 printk(KERN_INFO
"%s: version %s\n", DRIVER_NAME
, DRIVER_VERSION
);
998 /* some boards have startup glitches */
1000 status
= i2c_add_driver(&tps65010_driver
);
1003 i2c_del_driver(&tps65010_driver
);
1005 printk(KERN_ERR
"%s: no chip?\n", DRIVER_NAME
);
1008 pr_debug("%s: re-probe ...\n", DRIVER_NAME
);
1013 if (machine_is_omap_osk()) {
1015 // FIXME: More should be placed in the initialization code
1016 // of the submodules (DSP, ethernet, power management,
1017 // board-osk.c). Careful: I2C is initialized "late".
1019 /* Let LED1 (D9) blink */
1020 tps65010_set_led(LED1
, BLINK
);
1022 /* Disable LED 2 (D2) */
1023 tps65010_set_led(LED2
, OFF
);
1025 /* Set GPIO 1 HIGH to disable VBUS power supply;
1026 * OHCI driver powers it up/down as needed.
1028 tps65010_set_gpio_out_value(GPIO1
, HIGH
);
1030 /* Set GPIO 2 low to turn on LED D3 */
1031 tps65010_set_gpio_out_value(GPIO2
, HIGH
);
1033 /* Set GPIO 3 low to take ethernet out of reset */
1034 tps65010_set_gpio_out_value(GPIO3
, LOW
);
1036 /* gpio4 for VDD_DSP */
1038 /* Enable LOW_PWR */
1039 tps65010_set_low_pwr(ON
);
1041 /* Switch VLDO2 to 3.0V for AIC23 */
1042 tps65010_config_vregs1(TPS_LDO2_ENABLE
| TPS_VLDO2_3_0V
| TPS_LDO1_ENABLE
);
1044 } else if (machine_is_omap_h2()) {
1045 /* gpio3 for SD, gpio4 for VDD_DSP */
1047 /* Enable LOW_PWR */
1048 tps65010_set_low_pwr(ON
);
1049 } else if (machine_is_omap_h3()) {
1050 /* gpio4 for SD, gpio3 for VDD_DSP */
1052 /* Enable LOW_PWR */
1053 tps65013_set_low_pwr(ON
);
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.
1065 subsys_initcall(tps_init
);
1067 static void __exit
tps_exit(void)
1069 i2c_del_driver(&tps65010_driver
);
1071 module_exit(tps_exit
);