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
27 /*-------------------------------------------------------------------------*/
37 /*-------------------------------------------------------------------------*/
47 * battery-insert != device-on.
84 /*-------------------------------------------------------------------------*/
184 struct tps65010 *tps = s->private; in dbg_show()
190 switch (tps->model) { in dbg_show()
200 mutex_lock(&tps->lock); in dbg_show()
206 seq_printf(s, "%scharging\n\n", tps->charging ? "" : "(not) "); in dbg_show()
212 value = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG); in dbg_show()
213 dbg_chgconf(tps->por, buf, sizeof buf, value); in dbg_show()
216 value = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS); in dbg_show()
219 value = i2c_smbus_read_byte_data(tps->client, TPS_MASK1); in dbg_show()
224 value = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS); in dbg_show()
227 value = i2c_smbus_read_byte_data(tps->client, TPS_MASK2); in dbg_show()
232 queue_delayed_work(system_power_efficient_wq, &tps->work, in dbg_show()
236 value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC1); in dbg_show()
239 /* VCORE voltage, vibrator on/off */ in dbg_show()
240 value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC2); in dbg_show()
244 value = i2c_smbus_read_byte_data(tps->client, TPS_VREGS1); in dbg_show()
249 value = i2c_smbus_read_byte_data(tps->client, TPS_LED1_ON); in dbg_show()
250 v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED1_PER); in dbg_show()
258 value = i2c_smbus_read_byte_data(tps->client, TPS_LED2_ON); in dbg_show()
259 v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED2_PER); in dbg_show()
267 value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO); in dbg_show()
268 v2 = i2c_smbus_read_byte_data(tps->client, TPS_MASK3); in dbg_show()
273 seq_printf(s, " gpio%d-out %s\n", i + 1, in dbg_show()
276 seq_printf(s, " gpio%d-in %s %s %s\n", i + 1, in dbg_show()
278 (v2 & (1 << i)) ? "no-irq" : "irq", in dbg_show()
282 mutex_unlock(&tps->lock); in dbg_show()
288 return single_open(file, dbg_show, inode->i_private); in dbg_tps_open()
304 /*-------------------------------------------------------------------------*/
317 if (tps->nmask2) { in tps65010_interrupt()
318 tmp = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS); in tps65010_interrupt()
319 mask = tmp ^ tps->regstatus; in tps65010_interrupt()
320 tps->regstatus = tmp; in tps65010_interrupt()
321 mask &= tps->nmask2; in tps65010_interrupt()
325 tps->regstatus = tmp; in tps65010_interrupt()
344 if (tps->nmask1) { in tps65010_interrupt()
345 tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS); in tps65010_interrupt()
346 mask = tmp ^ tps->chgstatus; in tps65010_interrupt()
347 tps->chgstatus = tmp; in tps65010_interrupt()
348 mask &= tps->nmask1; in tps65010_interrupt()
356 show_chgconfig(tps->por, "conf", tps->chgconf); in tps65010_interrupt()
362 if (!(tps->chgstatus & ~(TPS_CHG_USB|TPS_CHG_AC)) in tps65010_interrupt()
363 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC)) in tps65010_interrupt()
364 && (tps->chgconf & TPS_CHARGE_ENABLE) in tps65010_interrupt()
366 if (tps->chgstatus & TPS_CHG_USB) { in tps65010_interrupt()
369 set_bit(FLAG_VBUS_CHANGED, &tps->flags); in tps65010_interrupt()
371 } else if (tps->chgstatus & TPS_CHG_AC) in tps65010_interrupt()
374 if (charging != tps->charging) { in tps65010_interrupt()
375 tps->charging = charging; in tps65010_interrupt()
378 ((tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC)) in tps65010_interrupt()
386 if ((tps->model != TPS65013 || !tps->charging) in tps65010_interrupt()
387 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))) in tps65010_interrupt()
390 queue_delayed_work(system_power_efficient_wq, &tps->work, in tps65010_interrupt()
393 /* also potentially gpio-in rise or fall */ in tps65010_interrupt()
402 mutex_lock(&tps->lock); in tps65010_work()
406 if (test_and_clear_bit(FLAG_VBUS_CHANGED, &tps->flags)) { in tps65010_work()
409 chgconfig = i2c_smbus_read_byte_data(tps->client, in tps65010_work()
412 if (tps->vbus == 500) in tps65010_work()
414 else if (tps->vbus >= 100) in tps65010_work()
417 i2c_smbus_write_byte_data(tps->client, in tps65010_work()
421 tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG); in tps65010_work()
422 tps->chgconf = tmp; in tps65010_work()
423 show_chgconfig(tps->por, "update vbus", tmp); in tps65010_work()
426 if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags)) in tps65010_work()
427 enable_irq(tps->client->irq); in tps65010_work()
429 mutex_unlock(&tps->lock); in tps65010_work()
437 set_bit(FLAG_IRQ_ENABLE, &tps->flags); in tps65010_irq()
438 queue_delayed_work(system_power_efficient_wq, &tps->work, 0); in tps65010_irq()
442 /*-------------------------------------------------------------------------*/
445 * offsets 4..5 == LED1/nPG, LED2 (we set one of the non-BLINK modes)
454 tps65010_set_led(offset - 3, value ? ON : OFF); in tps65010_gpio_set()
462 /* GPIOs may be input-only */ in tps65010_output()
467 if (!(tps->outmask & (1 << offset))) in tps65010_output()
468 return -EINVAL; in tps65010_output()
471 tps65010_set_led(offset - 3, value ? ON : OFF); in tps65010_output()
486 value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO); in tps65010_gpio_get()
500 /*-------------------------------------------------------------------------*/
507 struct tps65010_board *board = dev_get_platdata(&client->dev); in tps65010_remove()
509 if (board && board->teardown) in tps65010_remove()
510 board->teardown(client, &tps->chip); in tps65010_remove()
511 if (client->irq > 0) in tps65010_remove()
512 free_irq(client->irq, tps); in tps65010_remove()
513 cancel_delayed_work_sync(&tps->work); in tps65010_remove()
514 debugfs_remove(tps->file); in tps65010_remove()
523 struct tps65010_board *board = dev_get_platdata(&client->dev); in tps65010_probe()
526 dev_dbg(&client->dev, "only one tps6501x chip allowed\n"); in tps65010_probe()
527 return -ENODEV; in tps65010_probe()
530 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in tps65010_probe()
531 return -EINVAL; in tps65010_probe()
533 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); in tps65010_probe()
535 return -ENOMEM; in tps65010_probe()
537 mutex_init(&tps->lock); in tps65010_probe()
538 INIT_DELAYED_WORK(&tps->work, tps65010_work); in tps65010_probe()
539 tps->client = client; in tps65010_probe()
540 tps->model = id->driver_data; in tps65010_probe()
543 * so this driver uses falling-edge triggers instead. in tps65010_probe()
545 if (client->irq > 0) { in tps65010_probe()
546 status = request_irq(client->irq, tps65010_irq, in tps65010_probe()
550 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n", in tps65010_probe()
551 client->irq, status); in tps65010_probe()
554 set_bit(FLAG_IRQ_ENABLE, &tps->flags); in tps65010_probe()
556 dev_warn(&client->dev, "IRQ not configured!\n"); in tps65010_probe()
559 switch (tps->model) { in tps65010_probe()
562 tps->por = 1; in tps65010_probe()
566 tps->chgconf = i2c_smbus_read_byte_data(client, TPS_CHGCONFIG); in tps65010_probe()
567 show_chgconfig(tps->por, "conf/init", tps->chgconf); in tps65010_probe()
590 tps->vbus = 100; in tps65010_probe()
597 tps->nmask1 = ~0; in tps65010_probe()
598 (void) i2c_smbus_write_byte_data(client, TPS_MASK1, ~tps->nmask1); in tps65010_probe()
600 tps->nmask2 = TPS_REG_ONOFF; in tps65010_probe()
601 if (tps->model == TPS65013) in tps65010_probe()
602 tps->nmask2 |= TPS_REG_NO_CHG; in tps65010_probe()
603 (void) i2c_smbus_write_byte_data(client, TPS_MASK2, ~tps->nmask2); in tps65010_probe()
608 tps65010_work(&tps->work.work); in tps65010_probe()
610 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL, in tps65010_probe()
615 tps->outmask = board->outmask; in tps65010_probe()
617 tps->chip.label = client->name; in tps65010_probe()
618 tps->chip.parent = &client->dev; in tps65010_probe()
619 tps->chip.owner = THIS_MODULE; in tps65010_probe()
621 tps->chip.set = tps65010_gpio_set; in tps65010_probe()
622 tps->chip.direction_output = tps65010_output; in tps65010_probe()
625 tps->chip.get = tps65010_gpio_get; in tps65010_probe()
627 tps->chip.base = -1; in tps65010_probe()
628 tps->chip.ngpio = 7; in tps65010_probe()
629 tps->chip.can_sleep = 1; in tps65010_probe()
631 status = gpiochip_add_data(&tps->chip, tps); in tps65010_probe()
633 dev_err(&client->dev, "can't add gpiochip, err %d\n", in tps65010_probe()
635 else if (board->setup) { in tps65010_probe()
636 status = board->setup(client, &tps->chip); in tps65010_probe()
638 dev_dbg(&client->dev, in tps65010_probe()
640 "setup", client->name, status); in tps65010_probe()
668 /*-------------------------------------------------------------------------*/
671 * 0 mA -- DON'T DRAW (might supply power instead)
672 * 100 mA -- usb unit load (slowest charge rate)
673 * 500 mA -- usb high power (fast battery charge)
680 return -ENODEV; in tps65010_set_vbus_draw()
682 /* assumes non-SMP */ in tps65010_set_vbus_draw()
690 the_tps->vbus = mA; in tps65010_set_vbus_draw()
691 if ((the_tps->chgstatus & TPS_CHG_USB) in tps65010_set_vbus_draw()
693 FLAG_VBUS_CHANGED, &the_tps->flags)) { in tps65010_set_vbus_draw()
695 queue_delayed_work(system_power_efficient_wq, &the_tps->work, in tps65010_set_vbus_draw()
704 /*-------------------------------------------------------------------------*/
715 return -ENODEV; in tps65010_set_gpio_out_value()
717 return -EINVAL; in tps65010_set_gpio_out_value()
719 mutex_lock(&the_tps->lock); in tps65010_set_gpio_out_value()
721 defgpio = i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO); in tps65010_set_gpio_out_value()
729 defgpio |= 1 << (gpio - 1); /* set GPIO low by writing 1 */ in tps65010_set_gpio_out_value()
733 defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */ in tps65010_set_gpio_out_value()
737 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_gpio_out_value()
742 i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO)); in tps65010_set_gpio_out_value()
744 mutex_unlock(&the_tps->lock); in tps65010_set_gpio_out_value()
749 /*-------------------------------------------------------------------------*/
760 return -ENODEV; in tps65010_set_led()
769 mutex_lock(&the_tps->lock); in tps65010_set_led()
772 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
776 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
795 mutex_unlock(&the_tps->lock); in tps65010_set_led()
796 return -EINVAL; in tps65010_set_led()
799 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_led()
805 mutex_unlock(&the_tps->lock); in tps65010_set_led()
810 i2c_smbus_read_byte_data(the_tps->client, TPS_LED1_ON + offs)); in tps65010_set_led()
812 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_led()
818 mutex_unlock(&the_tps->lock); in tps65010_set_led()
823 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
826 mutex_unlock(&the_tps->lock); in tps65010_set_led()
832 /*-------------------------------------------------------------------------*/
842 return -ENODEV; in tps65010_set_vib()
844 mutex_lock(&the_tps->lock); in tps65010_set_vib()
846 vdcdc2 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC2); in tps65010_set_vib()
850 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_vib()
855 mutex_unlock(&the_tps->lock); in tps65010_set_vib()
860 /*-------------------------------------------------------------------------*/
870 return -ENODEV; in tps65010_set_low_pwr()
872 mutex_lock(&the_tps->lock); in tps65010_set_low_pwr()
876 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65010_set_low_pwr()
878 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1); in tps65010_set_low_pwr()
890 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_low_pwr()
898 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65010_set_low_pwr()
900 mutex_unlock(&the_tps->lock); in tps65010_set_low_pwr()
906 /*-------------------------------------------------------------------------*/
916 return -ENODEV; in tps65010_config_vregs1()
918 mutex_lock(&the_tps->lock); in tps65010_config_vregs1()
921 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1)); in tps65010_config_vregs1()
923 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_config_vregs1()
931 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1)); in tps65010_config_vregs1()
933 mutex_unlock(&the_tps->lock); in tps65010_config_vregs1()
945 return -ENODEV; in tps65010_config_vdcdc2()
947 c = the_tps->client; in tps65010_config_vdcdc2()
948 mutex_lock(&the_tps->lock); in tps65010_config_vdcdc2()
962 mutex_unlock(&the_tps->lock); in tps65010_config_vdcdc2()
967 /*-------------------------------------------------------------------------*/
973 required if power supply is through a battery */
980 if (!the_tps || the_tps->por) in tps65013_set_low_pwr()
981 return -ENODEV; in tps65013_set_low_pwr()
983 mutex_lock(&the_tps->lock); in tps65013_set_low_pwr()
988 i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG), in tps65013_set_low_pwr()
989 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65013_set_low_pwr()
991 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG); in tps65013_set_low_pwr()
992 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1); in tps65013_set_low_pwr()
1006 status = i2c_smbus_write_byte_data(the_tps->client, in tps65013_set_low_pwr()
1011 mutex_unlock(&the_tps->lock); in tps65013_set_low_pwr()
1015 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG); in tps65013_set_low_pwr()
1016 the_tps->chgconf = chgconfig; in tps65013_set_low_pwr()
1019 status = i2c_smbus_write_byte_data(the_tps->client, in tps65013_set_low_pwr()
1027 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65013_set_low_pwr()
1029 mutex_unlock(&the_tps->lock); in tps65013_set_low_pwr()
1035 /*-------------------------------------------------------------------------*/
1043 * That is, much earlier than on PC-type systems, which don't often use