22 #include <linux/kernel.h>
23 #include <linux/module.h>
25 #include <linux/slab.h>
27 #include <linux/i2c.h>
42 #define DRIVER_VERSION "2 May 2005"
43 #define DRIVER_NAME (tps65010_driver.driver.name)
83 #define FLAG_VBUS_CHANGED 0
84 #define FLAG_IRQ_ENABLE 1
95 #define POWER_POLL_DELAY msecs_to_jiffies(5000)
99 #if defined(DEBUG) || defined(CONFIG_DEBUG_FS)
101 static void dbg_chgstat(
char *
buf,
size_t len,
u8 chgstatus)
103 snprintf(buf, len,
"%02x%s%s%s%s%s%s%s%s\n",
109 ((chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
110 ?
" (charging)" :
""),
117 static void dbg_regstat(
char *
buf,
size_t len,
u8 regstatus)
119 snprintf(buf, len,
"%02x %s%s%s%s%s%s%s%s\n",
131 static void dbg_chgconf(
int por,
char *buf,
size_t len,
u8 chgconfig)
137 ?
"POR=69ms" :
"POR=1sec";
141 snprintf(buf, len,
"%02x %s%s%s AC=%d%% USB=%dmA %sCharge\n",
145 ({
int p;
switch ((chgconfig >> 3) & 3) {
146 case 3: p = 100;
break;
147 case 2: p = 75;
break;
148 case 1: p = 50;
break;
149 default: p = 25;
break;
161 static void show_chgstatus(
const char *
label,
u8 chgstatus)
165 dbg_chgstat(buf,
sizeof buf, chgstatus);
169 static void show_regstatus(
const char *
label,
u8 regstatus)
173 dbg_regstat(buf,
sizeof buf, regstatus);
177 static void show_chgconfig(
int por,
const char *
label,
u8 chgconfig)
181 dbg_chgconf(por, buf,
sizeof buf, chgconfig);
187 static inline void show_chgstatus(
const char *
label,
u8 chgstatus) { }
188 static inline void show_regstatus(
const char *
label,
u8 chgstatus) { }
189 static inline void show_chgconfig(
int por,
const char *
label,
u8 chgconfig) { }
193 #ifdef CONFIG_DEBUG_FS
195 static int dbg_show(
struct seq_file *
s,
void *
_)
203 switch (tps->
model) {
204 case TPS65010: chip =
"tps65010";
break;
205 case TPS65011: chip =
"tps65011";
break;
206 case TPS65012: chip =
"tps65012";
break;
207 case TPS65013: chip =
"tps65013";
break;
208 default: chip =
NULL;
break;
210 seq_printf(s,
"driver %s\nversion %s\nchip %s\n\n",
226 dbg_chgconf(tps->
por, buf,
sizeof buf, value);
230 dbg_chgstat(buf,
sizeof buf, value);
233 dbg_chgstat(buf,
sizeof buf, value);
238 dbg_regstat(buf,
sizeof buf, value);
241 dbg_regstat(buf,
sizeof buf, value);
264 seq_printf(s,
"led1 %s, on=%02x, per=%02x, %d/%d msec\n",
266 ? ((v2 & 0x80) ?
"on" :
"off")
267 : ((v2 & 0x80) ?
"blink" :
"(nPG)"),
269 (value & 0x7f) * 10, (v2 & 0x7f) * 100);
273 seq_printf(s,
"led2 %s, on=%02x, per=%02x, %d/%d msec\n",
275 ? ((v2 & 0x80) ?
"on" :
"off")
276 : ((v2 & 0x80) ?
"blink" :
"off"),
278 (value & 0x7f) * 10, (v2 & 0x7f) * 100);
282 seq_printf(s,
"defgpio %02x mask3 %02x\n", value, v2);
284 for (i = 0; i < 4; i++) {
285 if (value & (1 << (4 + i)))
287 (value & (1 << i)) ?
"low" :
"hi ");
290 (value & (1 << i)) ?
"hi " :
"low",
291 (v2 & (1 << i)) ?
"no-irq" :
"irq",
292 (v2 & (1 << (4 + i))) ?
"rising" :
"falling");
305 .
open = dbg_tps_open,
311 #define DEBUG_FOPS &debug_fops
314 #define DEBUG_FOPS NULL
320 static void tps65010_interrupt(
struct tps65010 *tps)
342 if (tmp & TPS_REG_ONOFF) {
365 unsigned charging = 0;
367 show_chgstatus(
"chg/irq", tmp);
369 show_chgconfig(tps->
por,
"conf", tps->
chgconf);
389 pr_info(
"%s: battery %scharging\n",
416 tps65010_interrupt(tps);
425 if (tps->
vbus == 500)
427 else if (tps->
vbus >= 100)
436 show_chgconfig(tps->
por,
"update vbus", tmp);
445 static irqreturn_t tps65010_irq(
int irq,
void *_tps)
462 tps65010_gpio_set(
struct gpio_chip *chip,
unsigned offset,
int value)
473 tps65010_output(
struct gpio_chip *chip,
unsigned offset,
int value)
480 if (!(tps->
outmask & (1 << offset)))
483 }
else if (offset < 6)
491 static int tps65010_gpio_get(
struct gpio_chip *chip,
unsigned offset)
502 if (value & (1 << (offset + 4)))
503 return !(value & (1 <<
offset));
505 return (value & (1 << offset));
519 struct tps65010 *tps = i2c_get_clientdata(client);
526 "teardown", client->
name, status);
537 static int tps65010_probe(
struct i2c_client *client,
545 dev_dbg(&client->
dev,
"only one tps6501x chip allowed\n");
559 tps->
model =
id->driver_data;
564 if (client->
irq > 0) {
568 dev_dbg(&client->
dev,
"can't get IRQ %d, err %d\n",
569 client->
irq, status);
582 switch (tps->
model) {
590 show_chgconfig(tps->
por,
"conf/init", tps->
chgconf);
592 show_chgstatus(
"chg/init",
594 show_regstatus(
"reg/init",
605 i2c_set_clientdata(client, tps);
608 #if defined(CONFIG_USB_GADGET) && !defined(CONFIG_USB_OTG)
631 tps65010_work(&tps->
work.work);
637 if (board && board->
base != 0) {
644 tps->
chip.set = tps65010_gpio_set;
645 tps->
chip.direction_output = tps65010_output;
648 tps->
chip.get = tps65010_gpio_get;
652 tps->
chip.can_sleep = 1;
656 dev_err(&client->
dev,
"can't add gpiochip, err %d\n",
658 else if (board->
setup) {
662 "board %s %s err %d\n",
663 "setup", client->
name, status);
689 .probe = tps65010_probe,
690 .remove =
__exit_p(tps65010_remove),
691 .id_table = tps65010_id,
749 defgpio |= 1 << (gpio + 3);
754 defgpio |= 1 << (gpio - 1);
758 defgpio &= ~(1 << (gpio - 1));
766 gpio, value ?
"high" :
"low",
782 unsigned led_on, led_per,
offs;
814 led_on = 0x30 | (0 << 7);
815 led_per = 0x08 | (1 << 7);
900 mode ?
"enable" :
"disable",
1003 unsigned vdcdc1, chgconfig;
1005 if (!the_tps || the_tps->
por)
1010 pr_debug(
"%s: %s low_pwr, chgconfig 0x%02x vdcdc1 0x%02x\n",
1012 mode ?
"enable" :
"disable",
1042 show_chgconfig(0,
"chgconf", chgconfig);
1062 static int __init tps_init(
void)
1071 status = i2c_add_driver(&tps65010_driver);
1092 static void __exit tps_exit(
void)