0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/kernel.h>
0010 #include <linux/module.h>
0011 #include <linux/init.h>
0012 #include <linux/slab.h>
0013 #include <linux/interrupt.h>
0014 #include <linux/i2c.h>
0015 #include <linux/delay.h>
0016 #include <linux/workqueue.h>
0017 #include <linux/debugfs.h>
0018 #include <linux/seq_file.h>
0019 #include <linux/mutex.h>
0020 #include <linux/platform_device.h>
0021
0022 #include <linux/mfd/tps65010.h>
0023
0024 #include <linux/gpio/driver.h>
0025
0026
0027
0028
0029 #define DRIVER_VERSION "2 May 2005"
0030 #define DRIVER_NAME (tps65010_driver.driver.name)
0031
0032 MODULE_DESCRIPTION("TPS6501x Power Management Driver");
0033 MODULE_LICENSE("GPL");
0034
0035 static struct i2c_driver tps65010_driver;
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 enum tps_model {
0054 TPS65010,
0055 TPS65011,
0056 TPS65012,
0057 TPS65013,
0058 };
0059
0060 struct tps65010 {
0061 struct i2c_client *client;
0062 struct mutex lock;
0063 struct delayed_work work;
0064 struct dentry *file;
0065 unsigned charging:1;
0066 unsigned por:1;
0067 unsigned model:8;
0068 u16 vbus;
0069 unsigned long flags;
0070 #define FLAG_VBUS_CHANGED 0
0071 #define FLAG_IRQ_ENABLE 1
0072
0073
0074 u8 chgstatus, regstatus, chgconf;
0075 u8 nmask1, nmask2;
0076
0077 u8 outmask;
0078 struct gpio_chip chip;
0079 struct platform_device *leds;
0080 };
0081
0082 #define POWER_POLL_DELAY msecs_to_jiffies(5000)
0083
0084
0085
0086 #if defined(DEBUG) || defined(CONFIG_DEBUG_FS)
0087
0088 static void dbg_chgstat(char *buf, size_t len, u8 chgstatus)
0089 {
0090 snprintf(buf, len, "%02x%s%s%s%s%s%s%s%s\n",
0091 chgstatus,
0092 (chgstatus & TPS_CHG_USB) ? " USB" : "",
0093 (chgstatus & TPS_CHG_AC) ? " AC" : "",
0094 (chgstatus & TPS_CHG_THERM) ? " therm" : "",
0095 (chgstatus & TPS_CHG_TERM) ? " done" :
0096 ((chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
0097 ? " (charging)" : ""),
0098 (chgstatus & TPS_CHG_TAPER_TMO) ? " taper_tmo" : "",
0099 (chgstatus & TPS_CHG_CHG_TMO) ? " charge_tmo" : "",
0100 (chgstatus & TPS_CHG_PRECHG_TMO) ? " prechg_tmo" : "",
0101 (chgstatus & TPS_CHG_TEMP_ERR) ? " temp_err" : "");
0102 }
0103
0104 static void dbg_regstat(char *buf, size_t len, u8 regstatus)
0105 {
0106 snprintf(buf, len, "%02x %s%s%s%s%s%s%s%s\n",
0107 regstatus,
0108 (regstatus & TPS_REG_ONOFF) ? "off" : "(on)",
0109 (regstatus & TPS_REG_COVER) ? " uncover" : "",
0110 (regstatus & TPS_REG_UVLO) ? " UVLO" : "",
0111 (regstatus & TPS_REG_NO_CHG) ? " NO_CHG" : "",
0112 (regstatus & TPS_REG_PG_LD02) ? " ld02_bad" : "",
0113 (regstatus & TPS_REG_PG_LD01) ? " ld01_bad" : "",
0114 (regstatus & TPS_REG_PG_MAIN) ? " main_bad" : "",
0115 (regstatus & TPS_REG_PG_CORE) ? " core_bad" : "");
0116 }
0117
0118 static void dbg_chgconf(int por, char *buf, size_t len, u8 chgconfig)
0119 {
0120 const char *hibit;
0121
0122 if (por)
0123 hibit = (chgconfig & TPS_CHARGE_POR)
0124 ? "POR=69ms" : "POR=1sec";
0125 else
0126 hibit = (chgconfig & TPS65013_AUA) ? "AUA" : "";
0127
0128 snprintf(buf, len, "%02x %s%s%s AC=%d%% USB=%dmA %sCharge\n",
0129 chgconfig, hibit,
0130 (chgconfig & TPS_CHARGE_RESET) ? " reset" : "",
0131 (chgconfig & TPS_CHARGE_FAST) ? " fast" : "",
0132 ({int p; switch ((chgconfig >> 3) & 3) {
0133 case 3: p = 100; break;
0134 case 2: p = 75; break;
0135 case 1: p = 50; break;
0136 default: p = 25; break;
0137 }; p; }),
0138 (chgconfig & TPS_VBUS_CHARGING)
0139 ? ((chgconfig & TPS_VBUS_500MA) ? 500 : 100)
0140 : 0,
0141 (chgconfig & TPS_CHARGE_ENABLE) ? "" : "No");
0142 }
0143
0144 #endif
0145
0146 #ifdef DEBUG
0147
0148 static void show_chgstatus(const char *label, u8 chgstatus)
0149 {
0150 char buf [100];
0151
0152 dbg_chgstat(buf, sizeof buf, chgstatus);
0153 pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
0154 }
0155
0156 static void show_regstatus(const char *label, u8 regstatus)
0157 {
0158 char buf [100];
0159
0160 dbg_regstat(buf, sizeof buf, regstatus);
0161 pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
0162 }
0163
0164 static void show_chgconfig(int por, const char *label, u8 chgconfig)
0165 {
0166 char buf [100];
0167
0168 dbg_chgconf(por, buf, sizeof buf, chgconfig);
0169 pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
0170 }
0171
0172 #else
0173
0174 static inline void show_chgstatus(const char *label, u8 chgstatus) { }
0175 static inline void show_regstatus(const char *label, u8 chgstatus) { }
0176 static inline void show_chgconfig(int por, const char *label, u8 chgconfig) { }
0177
0178 #endif
0179
0180 #ifdef CONFIG_DEBUG_FS
0181
0182 static int dbg_show(struct seq_file *s, void *_)
0183 {
0184 struct tps65010 *tps = s->private;
0185 u8 value, v2;
0186 unsigned i;
0187 char buf[100];
0188 const char *chip;
0189
0190 switch (tps->model) {
0191 case TPS65010: chip = "tps65010"; break;
0192 case TPS65011: chip = "tps65011"; break;
0193 case TPS65012: chip = "tps65012"; break;
0194 case TPS65013: chip = "tps65013"; break;
0195 default: chip = NULL; break;
0196 }
0197 seq_printf(s, "driver %s\nversion %s\nchip %s\n\n",
0198 DRIVER_NAME, DRIVER_VERSION, chip);
0199
0200 mutex_lock(&tps->lock);
0201
0202
0203
0204
0205
0206 seq_printf(s, "%scharging\n\n", tps->charging ? "" : "(not) ");
0207
0208
0209
0210
0211
0212 value = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG);
0213 dbg_chgconf(tps->por, buf, sizeof buf, value);
0214 seq_printf(s, "chgconfig %s", buf);
0215
0216 value = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS);
0217 dbg_chgstat(buf, sizeof buf, value);
0218 seq_printf(s, "chgstat %s", buf);
0219 value = i2c_smbus_read_byte_data(tps->client, TPS_MASK1);
0220 dbg_chgstat(buf, sizeof buf, value);
0221 seq_printf(s, "mask1 %s", buf);
0222
0223
0224 value = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS);
0225 dbg_regstat(buf, sizeof buf, value);
0226 seq_printf(s, "regstat %s", buf);
0227 value = i2c_smbus_read_byte_data(tps->client, TPS_MASK2);
0228 dbg_regstat(buf, sizeof buf, value);
0229 seq_printf(s, "mask2 %s\n", buf);
0230
0231
0232 queue_delayed_work(system_power_efficient_wq, &tps->work,
0233 POWER_POLL_DELAY);
0234
0235
0236 value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC1);
0237 seq_printf(s, "vdcdc1 %02x\n", value);
0238
0239
0240 value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC2);
0241 seq_printf(s, "vdcdc2 %02x\n", value);
0242
0243
0244 value = i2c_smbus_read_byte_data(tps->client, TPS_VREGS1);
0245 seq_printf(s, "vregs1 %02x\n\n", value);
0246
0247
0248
0249 value = i2c_smbus_read_byte_data(tps->client, TPS_LED1_ON);
0250 v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED1_PER);
0251 seq_printf(s, "led1 %s, on=%02x, per=%02x, %d/%d msec\n",
0252 (value & 0x80)
0253 ? ((v2 & 0x80) ? "on" : "off")
0254 : ((v2 & 0x80) ? "blink" : "(nPG)"),
0255 value, v2,
0256 (value & 0x7f) * 10, (v2 & 0x7f) * 100);
0257
0258 value = i2c_smbus_read_byte_data(tps->client, TPS_LED2_ON);
0259 v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED2_PER);
0260 seq_printf(s, "led2 %s, on=%02x, per=%02x, %d/%d msec\n",
0261 (value & 0x80)
0262 ? ((v2 & 0x80) ? "on" : "off")
0263 : ((v2 & 0x80) ? "blink" : "off"),
0264 value, v2,
0265 (value & 0x7f) * 10, (v2 & 0x7f) * 100);
0266
0267 value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO);
0268 v2 = i2c_smbus_read_byte_data(tps->client, TPS_MASK3);
0269 seq_printf(s, "defgpio %02x mask3 %02x\n", value, v2);
0270
0271 for (i = 0; i < 4; i++) {
0272 if (value & (1 << (4 + i)))
0273 seq_printf(s, " gpio%d-out %s\n", i + 1,
0274 (value & (1 << i)) ? "low" : "hi ");
0275 else
0276 seq_printf(s, " gpio%d-in %s %s %s\n", i + 1,
0277 (value & (1 << i)) ? "hi " : "low",
0278 (v2 & (1 << i)) ? "no-irq" : "irq",
0279 (v2 & (1 << (4 + i))) ? "rising" : "falling");
0280 }
0281
0282 mutex_unlock(&tps->lock);
0283 return 0;
0284 }
0285
0286 static int dbg_tps_open(struct inode *inode, struct file *file)
0287 {
0288 return single_open(file, dbg_show, inode->i_private);
0289 }
0290
0291 static const struct file_operations debug_fops = {
0292 .open = dbg_tps_open,
0293 .read = seq_read,
0294 .llseek = seq_lseek,
0295 .release = single_release,
0296 };
0297
0298 #define DEBUG_FOPS &debug_fops
0299
0300 #else
0301 #define DEBUG_FOPS NULL
0302 #endif
0303
0304
0305
0306
0307 static void tps65010_interrupt(struct tps65010 *tps)
0308 {
0309 u8 tmp = 0, mask, poll;
0310
0311
0312
0313
0314 poll = 0;
0315
0316
0317 if (tps->nmask2) {
0318 tmp = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS);
0319 mask = tmp ^ tps->regstatus;
0320 tps->regstatus = tmp;
0321 mask &= tps->nmask2;
0322 } else
0323 mask = 0;
0324 if (mask) {
0325 tps->regstatus = tmp;
0326
0327
0328
0329 if (tmp & TPS_REG_ONOFF) {
0330 pr_info("%s: power off button\n", DRIVER_NAME);
0331 #if 0
0332
0333
0334
0335
0336
0337 hibernate();
0338 #endif
0339 poll = 1;
0340 }
0341 }
0342
0343
0344 if (tps->nmask1) {
0345 tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS);
0346 mask = tmp ^ tps->chgstatus;
0347 tps->chgstatus = tmp;
0348 mask &= tps->nmask1;
0349 } else
0350 mask = 0;
0351 if (mask) {
0352 unsigned charging = 0;
0353
0354 show_chgstatus("chg/irq", tmp);
0355 if (tmp & (TPS_CHG_USB|TPS_CHG_AC))
0356 show_chgconfig(tps->por, "conf", tps->chgconf);
0357
0358
0359
0360
0361
0362 if (!(tps->chgstatus & ~(TPS_CHG_USB|TPS_CHG_AC))
0363 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
0364 && (tps->chgconf & TPS_CHARGE_ENABLE)
0365 ) {
0366 if (tps->chgstatus & TPS_CHG_USB) {
0367
0368 if (mask & TPS_CHG_USB)
0369 set_bit(FLAG_VBUS_CHANGED, &tps->flags);
0370 charging = 1;
0371 } else if (tps->chgstatus & TPS_CHG_AC)
0372 charging = 1;
0373 }
0374 if (charging != tps->charging) {
0375 tps->charging = charging;
0376 pr_info("%s: battery %scharging\n",
0377 DRIVER_NAME, charging ? "" :
0378 ((tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
0379 ? "NOT " : "dis"));
0380 }
0381 }
0382
0383
0384
0385
0386 if ((tps->model != TPS65013 || !tps->charging)
0387 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC)))
0388 poll = 1;
0389 if (poll)
0390 queue_delayed_work(system_power_efficient_wq, &tps->work,
0391 POWER_POLL_DELAY);
0392
0393
0394 }
0395
0396
0397 static void tps65010_work(struct work_struct *work)
0398 {
0399 struct tps65010 *tps;
0400
0401 tps = container_of(to_delayed_work(work), struct tps65010, work);
0402 mutex_lock(&tps->lock);
0403
0404 tps65010_interrupt(tps);
0405
0406 if (test_and_clear_bit(FLAG_VBUS_CHANGED, &tps->flags)) {
0407 u8 chgconfig, tmp;
0408
0409 chgconfig = i2c_smbus_read_byte_data(tps->client,
0410 TPS_CHGCONFIG);
0411 chgconfig &= ~(TPS_VBUS_500MA | TPS_VBUS_CHARGING);
0412 if (tps->vbus == 500)
0413 chgconfig |= TPS_VBUS_500MA | TPS_VBUS_CHARGING;
0414 else if (tps->vbus >= 100)
0415 chgconfig |= TPS_VBUS_CHARGING;
0416
0417 i2c_smbus_write_byte_data(tps->client,
0418 TPS_CHGCONFIG, chgconfig);
0419
0420
0421 tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG);
0422 tps->chgconf = tmp;
0423 show_chgconfig(tps->por, "update vbus", tmp);
0424 }
0425
0426 if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags))
0427 enable_irq(tps->client->irq);
0428
0429 mutex_unlock(&tps->lock);
0430 }
0431
0432 static irqreturn_t tps65010_irq(int irq, void *_tps)
0433 {
0434 struct tps65010 *tps = _tps;
0435
0436 disable_irq_nosync(irq);
0437 set_bit(FLAG_IRQ_ENABLE, &tps->flags);
0438 queue_delayed_work(system_power_efficient_wq, &tps->work, 0);
0439 return IRQ_HANDLED;
0440 }
0441
0442
0443
0444
0445
0446
0447
0448 static void
0449 tps65010_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
0450 {
0451 if (offset < 4)
0452 tps65010_set_gpio_out_value(offset + 1, value);
0453 else if (offset < 6)
0454 tps65010_set_led(offset - 3, value ? ON : OFF);
0455 else
0456 tps65010_set_vib(value);
0457 }
0458
0459 static int
0460 tps65010_output(struct gpio_chip *chip, unsigned offset, int value)
0461 {
0462
0463 if (offset < 4) {
0464 struct tps65010 *tps;
0465
0466 tps = gpiochip_get_data(chip);
0467 if (!(tps->outmask & (1 << offset)))
0468 return -EINVAL;
0469 tps65010_set_gpio_out_value(offset + 1, value);
0470 } else if (offset < 6)
0471 tps65010_set_led(offset - 3, value ? ON : OFF);
0472 else
0473 tps65010_set_vib(value);
0474
0475 return 0;
0476 }
0477
0478 static int tps65010_gpio_get(struct gpio_chip *chip, unsigned offset)
0479 {
0480 int value;
0481 struct tps65010 *tps;
0482
0483 tps = gpiochip_get_data(chip);
0484
0485 if (offset < 4) {
0486 value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO);
0487 if (value < 0)
0488 return value;
0489 if (value & (1 << (offset + 4)))
0490 return !(value & (1 << offset));
0491 else
0492 return !!(value & (1 << offset));
0493 }
0494
0495
0496 return 0;
0497 }
0498
0499
0500
0501
0502 static struct tps65010 *the_tps;
0503
0504 static int tps65010_remove(struct i2c_client *client)
0505 {
0506 struct tps65010 *tps = i2c_get_clientdata(client);
0507 struct tps65010_board *board = dev_get_platdata(&client->dev);
0508
0509 if (board && board->teardown) {
0510 int status = board->teardown(client, board->context);
0511 if (status < 0)
0512 dev_dbg(&client->dev, "board %s %s err %d\n",
0513 "teardown", client->name, status);
0514 }
0515 if (client->irq > 0)
0516 free_irq(client->irq, tps);
0517 cancel_delayed_work_sync(&tps->work);
0518 debugfs_remove(tps->file);
0519 the_tps = NULL;
0520 return 0;
0521 }
0522
0523 static int tps65010_probe(struct i2c_client *client,
0524 const struct i2c_device_id *id)
0525 {
0526 struct tps65010 *tps;
0527 int status;
0528 struct tps65010_board *board = dev_get_platdata(&client->dev);
0529
0530 if (the_tps) {
0531 dev_dbg(&client->dev, "only one tps6501x chip allowed\n");
0532 return -ENODEV;
0533 }
0534
0535 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
0536 return -EINVAL;
0537
0538 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
0539 if (!tps)
0540 return -ENOMEM;
0541
0542 mutex_init(&tps->lock);
0543 INIT_DELAYED_WORK(&tps->work, tps65010_work);
0544 tps->client = client;
0545 tps->model = id->driver_data;
0546
0547
0548
0549
0550 if (client->irq > 0) {
0551 status = request_irq(client->irq, tps65010_irq,
0552 IRQF_TRIGGER_FALLING, DRIVER_NAME, tps);
0553 if (status < 0) {
0554 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n",
0555 client->irq, status);
0556 return status;
0557 }
0558
0559
0560
0561
0562 disable_irq(client->irq);
0563 set_bit(FLAG_IRQ_ENABLE, &tps->flags);
0564 } else
0565 dev_warn(&client->dev, "IRQ not configured!\n");
0566
0567
0568 switch (tps->model) {
0569 case TPS65010:
0570 case TPS65012:
0571 tps->por = 1;
0572 break;
0573
0574 }
0575 tps->chgconf = i2c_smbus_read_byte_data(client, TPS_CHGCONFIG);
0576 show_chgconfig(tps->por, "conf/init", tps->chgconf);
0577
0578 show_chgstatus("chg/init",
0579 i2c_smbus_read_byte_data(client, TPS_CHGSTATUS));
0580 show_regstatus("reg/init",
0581 i2c_smbus_read_byte_data(client, TPS_REGSTATUS));
0582
0583 pr_debug("%s: vdcdc1 0x%02x, vdcdc2 %02x, vregs1 %02x\n", DRIVER_NAME,
0584 i2c_smbus_read_byte_data(client, TPS_VDCDC1),
0585 i2c_smbus_read_byte_data(client, TPS_VDCDC2),
0586 i2c_smbus_read_byte_data(client, TPS_VREGS1));
0587 pr_debug("%s: defgpio 0x%02x, mask3 0x%02x\n", DRIVER_NAME,
0588 i2c_smbus_read_byte_data(client, TPS_DEFGPIO),
0589 i2c_smbus_read_byte_data(client, TPS_MASK3));
0590
0591 i2c_set_clientdata(client, tps);
0592 the_tps = tps;
0593
0594 #if defined(CONFIG_USB_GADGET) && !defined(CONFIG_USB_OTG)
0595
0596
0597
0598
0599 tps->vbus = 100;
0600 #endif
0601
0602
0603
0604
0605
0606 tps->nmask1 = ~0;
0607 (void) i2c_smbus_write_byte_data(client, TPS_MASK1, ~tps->nmask1);
0608
0609 tps->nmask2 = TPS_REG_ONOFF;
0610 if (tps->model == TPS65013)
0611 tps->nmask2 |= TPS_REG_NO_CHG;
0612 (void) i2c_smbus_write_byte_data(client, TPS_MASK2, ~tps->nmask2);
0613
0614 (void) i2c_smbus_write_byte_data(client, TPS_MASK3, 0x0f
0615 | i2c_smbus_read_byte_data(client, TPS_MASK3));
0616
0617 tps65010_work(&tps->work.work);
0618
0619 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL,
0620 tps, DEBUG_FOPS);
0621
0622
0623 if (board && board->base != 0) {
0624 tps->outmask = board->outmask;
0625
0626 tps->chip.label = client->name;
0627 tps->chip.parent = &client->dev;
0628 tps->chip.owner = THIS_MODULE;
0629
0630 tps->chip.set = tps65010_gpio_set;
0631 tps->chip.direction_output = tps65010_output;
0632
0633
0634 tps->chip.get = tps65010_gpio_get;
0635
0636 tps->chip.base = board->base;
0637 tps->chip.ngpio = 7;
0638 tps->chip.can_sleep = 1;
0639
0640 status = gpiochip_add_data(&tps->chip, tps);
0641 if (status < 0)
0642 dev_err(&client->dev, "can't add gpiochip, err %d\n",
0643 status);
0644 else if (board->setup) {
0645 status = board->setup(client, board->context);
0646 if (status < 0) {
0647 dev_dbg(&client->dev,
0648 "board %s %s err %d\n",
0649 "setup", client->name, status);
0650 status = 0;
0651 }
0652 }
0653 }
0654
0655 return 0;
0656 }
0657
0658 static const struct i2c_device_id tps65010_id[] = {
0659 { "tps65010", TPS65010 },
0660 { "tps65011", TPS65011 },
0661 { "tps65012", TPS65012 },
0662 { "tps65013", TPS65013 },
0663 { "tps65014", TPS65011 },
0664 { }
0665 };
0666 MODULE_DEVICE_TABLE(i2c, tps65010_id);
0667
0668 static struct i2c_driver tps65010_driver = {
0669 .driver = {
0670 .name = "tps65010",
0671 },
0672 .probe = tps65010_probe,
0673 .remove = tps65010_remove,
0674 .id_table = tps65010_id,
0675 };
0676
0677
0678
0679
0680
0681
0682
0683
0684 int tps65010_set_vbus_draw(unsigned mA)
0685 {
0686 unsigned long flags;
0687
0688 if (!the_tps)
0689 return -ENODEV;
0690
0691
0692 local_irq_save(flags);
0693 if (mA >= 500)
0694 mA = 500;
0695 else if (mA >= 100)
0696 mA = 100;
0697 else
0698 mA = 0;
0699 the_tps->vbus = mA;
0700 if ((the_tps->chgstatus & TPS_CHG_USB)
0701 && test_and_set_bit(
0702 FLAG_VBUS_CHANGED, &the_tps->flags)) {
0703
0704 queue_delayed_work(system_power_efficient_wq, &the_tps->work,
0705 0);
0706 }
0707 local_irq_restore(flags);
0708
0709 return 0;
0710 }
0711 EXPORT_SYMBOL(tps65010_set_vbus_draw);
0712
0713
0714
0715
0716
0717
0718 int tps65010_set_gpio_out_value(unsigned gpio, unsigned value)
0719 {
0720 int status;
0721 unsigned defgpio;
0722
0723 if (!the_tps)
0724 return -ENODEV;
0725 if ((gpio < GPIO1) || (gpio > GPIO4))
0726 return -EINVAL;
0727
0728 mutex_lock(&the_tps->lock);
0729
0730 defgpio = i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO);
0731
0732
0733 defgpio |= 1 << (gpio + 3);
0734
0735
0736 switch (value) {
0737 case LOW:
0738 defgpio |= 1 << (gpio - 1);
0739 break;
0740
0741 default:
0742 defgpio &= ~(1 << (gpio - 1));
0743 break;
0744 }
0745
0746 status = i2c_smbus_write_byte_data(the_tps->client,
0747 TPS_DEFGPIO, defgpio);
0748
0749 pr_debug("%s: gpio%dout = %s, defgpio 0x%02x\n", DRIVER_NAME,
0750 gpio, value ? "high" : "low",
0751 i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO));
0752
0753 mutex_unlock(&the_tps->lock);
0754 return status;
0755 }
0756 EXPORT_SYMBOL(tps65010_set_gpio_out_value);
0757
0758
0759
0760
0761
0762
0763 int tps65010_set_led(unsigned led, unsigned mode)
0764 {
0765 int status;
0766 unsigned led_on, led_per, offs;
0767
0768 if (!the_tps)
0769 return -ENODEV;
0770
0771 if (led == LED1)
0772 offs = 0;
0773 else {
0774 offs = 2;
0775 led = LED2;
0776 }
0777
0778 mutex_lock(&the_tps->lock);
0779
0780 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
0781 i2c_smbus_read_byte_data(the_tps->client,
0782 TPS_LED1_ON + offs));
0783
0784 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
0785 i2c_smbus_read_byte_data(the_tps->client,
0786 TPS_LED1_PER + offs));
0787
0788 switch (mode) {
0789 case OFF:
0790 led_on = 1 << 7;
0791 led_per = 0 << 7;
0792 break;
0793 case ON:
0794 led_on = 1 << 7;
0795 led_per = 1 << 7;
0796 break;
0797 case BLINK:
0798 led_on = 0x30 | (0 << 7);
0799 led_per = 0x08 | (1 << 7);
0800 break;
0801 default:
0802 printk(KERN_ERR "%s: Wrong mode parameter for set_led()\n",
0803 DRIVER_NAME);
0804 mutex_unlock(&the_tps->lock);
0805 return -EINVAL;
0806 }
0807
0808 status = i2c_smbus_write_byte_data(the_tps->client,
0809 TPS_LED1_ON + offs, led_on);
0810
0811 if (status != 0) {
0812 printk(KERN_ERR "%s: Failed to write led%i_on register\n",
0813 DRIVER_NAME, led);
0814 mutex_unlock(&the_tps->lock);
0815 return status;
0816 }
0817
0818 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
0819 i2c_smbus_read_byte_data(the_tps->client, TPS_LED1_ON + offs));
0820
0821 status = i2c_smbus_write_byte_data(the_tps->client,
0822 TPS_LED1_PER + offs, led_per);
0823
0824 if (status != 0) {
0825 printk(KERN_ERR "%s: Failed to write led%i_per register\n",
0826 DRIVER_NAME, led);
0827 mutex_unlock(&the_tps->lock);
0828 return status;
0829 }
0830
0831 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
0832 i2c_smbus_read_byte_data(the_tps->client,
0833 TPS_LED1_PER + offs));
0834
0835 mutex_unlock(&the_tps->lock);
0836
0837 return status;
0838 }
0839 EXPORT_SYMBOL(tps65010_set_led);
0840
0841
0842
0843
0844
0845 int tps65010_set_vib(unsigned value)
0846 {
0847 int status;
0848 unsigned vdcdc2;
0849
0850 if (!the_tps)
0851 return -ENODEV;
0852
0853 mutex_lock(&the_tps->lock);
0854
0855 vdcdc2 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC2);
0856 vdcdc2 &= ~(1 << 1);
0857 if (value)
0858 vdcdc2 |= (1 << 1);
0859 status = i2c_smbus_write_byte_data(the_tps->client,
0860 TPS_VDCDC2, vdcdc2);
0861
0862 pr_debug("%s: vibrator %s\n", DRIVER_NAME, value ? "on" : "off");
0863
0864 mutex_unlock(&the_tps->lock);
0865 return status;
0866 }
0867 EXPORT_SYMBOL(tps65010_set_vib);
0868
0869
0870
0871
0872
0873 int tps65010_set_low_pwr(unsigned mode)
0874 {
0875 int status;
0876 unsigned vdcdc1;
0877
0878 if (!the_tps)
0879 return -ENODEV;
0880
0881 mutex_lock(&the_tps->lock);
0882
0883 pr_debug("%s: %s low_pwr, vdcdc1 0x%02x\n", DRIVER_NAME,
0884 mode ? "enable" : "disable",
0885 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
0886
0887 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
0888
0889 switch (mode) {
0890 case OFF:
0891 vdcdc1 &= ~TPS_ENABLE_LP;
0892 break;
0893
0894 default:
0895 vdcdc1 |= TPS_ENABLE_LP;
0896 break;
0897 }
0898
0899 status = i2c_smbus_write_byte_data(the_tps->client,
0900 TPS_VDCDC1, vdcdc1);
0901
0902 if (status != 0)
0903 printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
0904 DRIVER_NAME);
0905 else
0906 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
0907 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
0908
0909 mutex_unlock(&the_tps->lock);
0910
0911 return status;
0912 }
0913 EXPORT_SYMBOL(tps65010_set_low_pwr);
0914
0915
0916
0917
0918
0919
0920 int tps65010_config_vregs1(unsigned value)
0921 {
0922 int status;
0923
0924 if (!the_tps)
0925 return -ENODEV;
0926
0927 mutex_lock(&the_tps->lock);
0928
0929 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
0930 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
0931
0932 status = i2c_smbus_write_byte_data(the_tps->client,
0933 TPS_VREGS1, value);
0934
0935 if (status != 0)
0936 printk(KERN_ERR "%s: Failed to write vregs1 register\n",
0937 DRIVER_NAME);
0938 else
0939 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
0940 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
0941
0942 mutex_unlock(&the_tps->lock);
0943
0944 return status;
0945 }
0946 EXPORT_SYMBOL(tps65010_config_vregs1);
0947
0948 int tps65010_config_vdcdc2(unsigned value)
0949 {
0950 struct i2c_client *c;
0951 int status;
0952
0953 if (!the_tps)
0954 return -ENODEV;
0955
0956 c = the_tps->client;
0957 mutex_lock(&the_tps->lock);
0958
0959 pr_debug("%s: vdcdc2 0x%02x\n", DRIVER_NAME,
0960 i2c_smbus_read_byte_data(c, TPS_VDCDC2));
0961
0962 status = i2c_smbus_write_byte_data(c, TPS_VDCDC2, value);
0963
0964 if (status != 0)
0965 printk(KERN_ERR "%s: Failed to write vdcdc2 register\n",
0966 DRIVER_NAME);
0967 else
0968 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
0969 i2c_smbus_read_byte_data(c, TPS_VDCDC2));
0970
0971 mutex_unlock(&the_tps->lock);
0972 return status;
0973 }
0974 EXPORT_SYMBOL(tps65010_config_vdcdc2);
0975
0976
0977
0978
0979
0980
0981
0982
0983
0984 int tps65013_set_low_pwr(unsigned mode)
0985 {
0986 int status;
0987 unsigned vdcdc1, chgconfig;
0988
0989 if (!the_tps || the_tps->por)
0990 return -ENODEV;
0991
0992 mutex_lock(&the_tps->lock);
0993
0994 pr_debug("%s: %s low_pwr, chgconfig 0x%02x vdcdc1 0x%02x\n",
0995 DRIVER_NAME,
0996 mode ? "enable" : "disable",
0997 i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG),
0998 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
0999
1000 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
1001 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
1002
1003 switch (mode) {
1004 case OFF:
1005 chgconfig &= ~TPS65013_AUA;
1006 vdcdc1 &= ~TPS_ENABLE_LP;
1007 break;
1008
1009 default:
1010 chgconfig |= TPS65013_AUA;
1011 vdcdc1 |= TPS_ENABLE_LP;
1012 break;
1013 }
1014
1015 status = i2c_smbus_write_byte_data(the_tps->client,
1016 TPS_CHGCONFIG, chgconfig);
1017 if (status != 0) {
1018 printk(KERN_ERR "%s: Failed to write chconfig register\n",
1019 DRIVER_NAME);
1020 mutex_unlock(&the_tps->lock);
1021 return status;
1022 }
1023
1024 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
1025 the_tps->chgconf = chgconfig;
1026 show_chgconfig(0, "chgconf", chgconfig);
1027
1028 status = i2c_smbus_write_byte_data(the_tps->client,
1029 TPS_VDCDC1, vdcdc1);
1030
1031 if (status != 0)
1032 printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
1033 DRIVER_NAME);
1034 else
1035 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
1036 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
1037
1038 mutex_unlock(&the_tps->lock);
1039
1040 return status;
1041 }
1042 EXPORT_SYMBOL(tps65013_set_low_pwr);
1043
1044
1045
1046 static int __init tps_init(void)
1047 {
1048 return i2c_add_driver(&tps65010_driver);
1049 }
1050
1051
1052
1053
1054
1055 subsys_initcall(tps_init);
1056
1057 static void __exit tps_exit(void)
1058 {
1059 i2c_del_driver(&tps65010_driver);
1060 }
1061 module_exit(tps_exit);
1062