Lines Matching +full:vcore +full:- +full:supply
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * tps65010 - driver for tps6501x power management chips
6 * Copyright (C) 2004-2005 David Brownell
28 /*-------------------------------------------------------------------------*/
38 /*-------------------------------------------------------------------------*/
48 * battery-insert != device-on.
85 /*-------------------------------------------------------------------------*/
185 struct tps65010 *tps = s->private;
191 switch (tps->model) {
201 mutex_lock(&tps->lock);
207 seq_printf(s, "%scharging\n\n", tps->charging ? "" : "(not) ");
213 value = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG);
214 dbg_chgconf(tps->por, buf, sizeof buf, value);
217 value = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS);
220 value = i2c_smbus_read_byte_data(tps->client, TPS_MASK1);
225 value = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS);
228 value = i2c_smbus_read_byte_data(tps->client, TPS_MASK2);
233 queue_delayed_work(system_power_efficient_wq, &tps->work,
237 value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC1);
240 /* VCORE voltage, vibrator on/off */
241 value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC2);
245 value = i2c_smbus_read_byte_data(tps->client, TPS_VREGS1);
250 value = i2c_smbus_read_byte_data(tps->client, TPS_LED1_ON);
251 v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED1_PER);
259 value = i2c_smbus_read_byte_data(tps->client, TPS_LED2_ON);
260 v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED2_PER);
268 value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO);
269 v2 = i2c_smbus_read_byte_data(tps->client, TPS_MASK3);
274 seq_printf(s, " gpio%d-out %s\n", i + 1,
277 seq_printf(s, " gpio%d-in %s %s %s\n", i + 1,
279 (v2 & (1 << i)) ? "no-irq" : "irq",
283 mutex_unlock(&tps->lock);
289 return single_open(file, dbg_show, inode->i_private);
305 /*-------------------------------------------------------------------------*/
318 if (tps->nmask2) {
319 tmp = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS);
320 mask = tmp ^ tps->regstatus;
321 tps->regstatus = tmp;
322 mask &= tps->nmask2;
326 tps->regstatus = tmp;
345 if (tps->nmask1) {
346 tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS);
347 mask = tmp ^ tps->chgstatus;
348 tps->chgstatus = tmp;
349 mask &= tps->nmask1;
357 show_chgconfig(tps->por, "conf", tps->chgconf);
363 if (!(tps->chgstatus & ~(TPS_CHG_USB|TPS_CHG_AC))
364 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
365 && (tps->chgconf & TPS_CHARGE_ENABLE)
367 if (tps->chgstatus & TPS_CHG_USB) {
370 set_bit(FLAG_VBUS_CHANGED, &tps->flags);
372 } else if (tps->chgstatus & TPS_CHG_AC)
375 if (charging != tps->charging) {
376 tps->charging = charging;
379 ((tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
387 if ((tps->model != TPS65013 || !tps->charging)
388 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC)))
391 queue_delayed_work(system_power_efficient_wq, &tps->work,
394 /* also potentially gpio-in rise or fall */
403 mutex_lock(&tps->lock);
407 if (test_and_clear_bit(FLAG_VBUS_CHANGED, &tps->flags)) {
410 chgconfig = i2c_smbus_read_byte_data(tps->client,
413 if (tps->vbus == 500)
415 else if (tps->vbus >= 100)
418 i2c_smbus_write_byte_data(tps->client,
422 tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG);
423 tps->chgconf = tmp;
424 show_chgconfig(tps->por, "update vbus", tmp);
427 if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags))
428 enable_irq(tps->client->irq);
430 mutex_unlock(&tps->lock);
438 set_bit(FLAG_IRQ_ENABLE, &tps->flags);
439 queue_delayed_work(system_power_efficient_wq, &tps->work, 0);
443 /*-------------------------------------------------------------------------*/
446 * offsets 4..5 == LED1/nPG, LED2 (we set one of the non-BLINK modes)
455 tps65010_set_led(offset - 3, value ? ON : OFF);
463 /* GPIOs may be input-only */
468 if (!(tps->outmask & (1 << offset)))
469 return -EINVAL;
472 tps65010_set_led(offset - 3, value ? ON : OFF);
487 value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO);
501 /*-------------------------------------------------------------------------*/
508 struct tps65010_board *board = dev_get_platdata(&client->dev);
510 if (board && board->teardown)
511 board->teardown(client, &tps->chip);
512 if (client->irq > 0)
513 free_irq(client->irq, tps);
514 cancel_delayed_work_sync(&tps->work);
515 debugfs_remove(tps->file);
524 struct tps65010_board *board = dev_get_platdata(&client->dev);
527 dev_dbg(&client->dev, "only one tps6501x chip allowed\n");
528 return -ENODEV;
531 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
532 return -EINVAL;
534 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
536 return -ENOMEM;
538 mutex_init(&tps->lock);
539 INIT_DELAYED_WORK(&tps->work, tps65010_work);
540 tps->client = client;
541 tps->model = id->driver_data;
544 * so this driver uses falling-edge triggers instead.
546 if (client->irq > 0) {
547 status = request_irq(client->irq, tps65010_irq,
551 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n",
552 client->irq, status);
555 set_bit(FLAG_IRQ_ENABLE, &tps->flags);
557 dev_warn(&client->dev, "IRQ not configured!\n");
560 switch (tps->model) {
563 tps->por = 1;
567 tps->chgconf = i2c_smbus_read_byte_data(client, TPS_CHGCONFIG);
568 show_chgconfig(tps->por, "conf/init", tps->chgconf);
591 tps->vbus = 100;
598 tps->nmask1 = ~0;
599 (void) i2c_smbus_write_byte_data(client, TPS_MASK1, ~tps->nmask1);
601 tps->nmask2 = TPS_REG_ONOFF;
602 if (tps->model == TPS65013)
603 tps->nmask2 |= TPS_REG_NO_CHG;
604 (void) i2c_smbus_write_byte_data(client, TPS_MASK2, ~tps->nmask2);
609 tps65010_work(&tps->work.work);
611 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL,
616 tps->outmask = board->outmask;
618 tps->chip.label = client->name;
619 tps->chip.parent = &client->dev;
620 tps->chip.owner = THIS_MODULE;
622 tps->chip.set = tps65010_gpio_set;
623 tps->chip.direction_output = tps65010_output;
626 tps->chip.get = tps65010_gpio_get;
628 tps->chip.base = -1;
629 tps->chip.ngpio = 7;
630 tps->chip.can_sleep = 1;
632 status = gpiochip_add_data(&tps->chip, tps);
634 dev_err(&client->dev, "can't add gpiochip, err %d\n",
636 else if (board->setup) {
637 status = board->setup(client, &tps->chip);
639 dev_dbg(&client->dev,
641 "setup", client->name, status);
669 /*-------------------------------------------------------------------------*/
672 * 0 mA -- DON'T DRAW (might supply power instead)
673 * 100 mA -- usb unit load (slowest charge rate)
674 * 500 mA -- usb high power (fast battery charge)
681 return -ENODEV;
683 /* assumes non-SMP */
691 the_tps->vbus = mA;
692 if ((the_tps->chgstatus & TPS_CHG_USB)
694 FLAG_VBUS_CHANGED, &the_tps->flags)) {
696 queue_delayed_work(system_power_efficient_wq, &the_tps->work,
705 /*-------------------------------------------------------------------------*/
716 return -ENODEV;
718 return -EINVAL;
720 mutex_lock(&the_tps->lock);
722 defgpio = i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO);
730 defgpio |= 1 << (gpio - 1); /* set GPIO low by writing 1 */
734 defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */
738 status = i2c_smbus_write_byte_data(the_tps->client,
743 i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO));
745 mutex_unlock(&the_tps->lock);
750 /*-------------------------------------------------------------------------*/
761 return -ENODEV;
770 mutex_lock(&the_tps->lock);
773 i2c_smbus_read_byte_data(the_tps->client,
777 i2c_smbus_read_byte_data(the_tps->client,
796 mutex_unlock(&the_tps->lock);
797 return -EINVAL;
800 status = i2c_smbus_write_byte_data(the_tps->client,
806 mutex_unlock(&the_tps->lock);
811 i2c_smbus_read_byte_data(the_tps->client, TPS_LED1_ON + offs));
813 status = i2c_smbus_write_byte_data(the_tps->client,
819 mutex_unlock(&the_tps->lock);
824 i2c_smbus_read_byte_data(the_tps->client,
827 mutex_unlock(&the_tps->lock);
833 /*-------------------------------------------------------------------------*/
843 return -ENODEV;
845 mutex_lock(&the_tps->lock);
847 vdcdc2 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC2);
851 status = i2c_smbus_write_byte_data(the_tps->client,
856 mutex_unlock(&the_tps->lock);
861 /*-------------------------------------------------------------------------*/
871 return -ENODEV;
873 mutex_lock(&the_tps->lock);
877 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
879 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
891 status = i2c_smbus_write_byte_data(the_tps->client,
899 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
901 mutex_unlock(&the_tps->lock);
907 /*-------------------------------------------------------------------------*/
917 return -ENODEV;
919 mutex_lock(&the_tps->lock);
922 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
924 status = i2c_smbus_write_byte_data(the_tps->client,
932 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
934 mutex_unlock(&the_tps->lock);
946 return -ENODEV;
948 c = the_tps->client;
949 mutex_lock(&the_tps->lock);
963 mutex_unlock(&the_tps->lock);
968 /*-------------------------------------------------------------------------*/
974 required if power supply is through a battery */
981 if (!the_tps || the_tps->por)
982 return -ENODEV;
984 mutex_lock(&the_tps->lock);
989 i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG),
990 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
992 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
993 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
1007 status = i2c_smbus_write_byte_data(the_tps->client,
1012 mutex_unlock(&the_tps->lock);
1016 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
1017 the_tps->chgconf = chgconfig;
1020 status = i2c_smbus_write_byte_data(the_tps->client,
1028 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
1030 mutex_unlock(&the_tps->lock);
1036 /*-------------------------------------------------------------------------*/
1044 * That is, much earlier than on PC-type systems, which don't often use