Lines Matching +full:ac +full:- +full:detect +full:- +full:gpios

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 /*-------------------------------------------------------------------------*/
40 * voltage regulators, lithium ion/polymer battery charging, GPIOs, LEDs,
47 * battery-insert != device-on.
84 /*-------------------------------------------------------------------------*/
93 (chgstatus & TPS_CHG_AC) ? " AC" : "", in dbg_chgstat()
128 snprintf(buf, len, "%02x %s%s%s AC=%d%% USB=%dmA %sCharge\n", in dbg_chgconf()
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()
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()
248 /* LEDs and GPIOs */ 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()
383 /* always poll to detect (a) power removal, without tps65013 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 int status = board->teardown(client, board->context); in tps65010_remove()
512 dev_dbg(&client->dev, "board %s %s err %d\n", in tps65010_remove()
513 "teardown", client->name, status); in tps65010_remove()
515 if (client->irq > 0) in tps65010_remove()
516 free_irq(client->irq, tps); in tps65010_remove()
517 cancel_delayed_work_sync(&tps->work); in tps65010_remove()
518 debugfs_remove(tps->file); in tps65010_remove()
528 struct tps65010_board *board = dev_get_platdata(&client->dev); in tps65010_probe()
531 dev_dbg(&client->dev, "only one tps6501x chip allowed\n"); in tps65010_probe()
532 return -ENODEV; in tps65010_probe()
535 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in tps65010_probe()
536 return -EINVAL; in tps65010_probe()
538 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); in tps65010_probe()
540 return -ENOMEM; in tps65010_probe()
542 mutex_init(&tps->lock); in tps65010_probe()
543 INIT_DELAYED_WORK(&tps->work, tps65010_work); in tps65010_probe()
544 tps->client = client; in tps65010_probe()
545 tps->model = id->driver_data; in tps65010_probe()
548 * so this driver uses falling-edge triggers instead. in tps65010_probe()
550 if (client->irq > 0) { in tps65010_probe()
551 status = request_irq(client->irq, tps65010_irq, in tps65010_probe()
554 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n", in tps65010_probe()
555 client->irq, status); in tps65010_probe()
562 disable_irq(client->irq); in tps65010_probe()
563 set_bit(FLAG_IRQ_ENABLE, &tps->flags); in tps65010_probe()
565 dev_warn(&client->dev, "IRQ not configured!\n"); in tps65010_probe()
568 switch (tps->model) { in tps65010_probe()
571 tps->por = 1; in tps65010_probe()
575 tps->chgconf = i2c_smbus_read_byte_data(client, TPS_CHGCONFIG); in tps65010_probe()
576 show_chgconfig(tps->por, "conf/init", tps->chgconf); in tps65010_probe()
599 tps->vbus = 100; in tps65010_probe()
606 tps->nmask1 = ~0; in tps65010_probe()
607 (void) i2c_smbus_write_byte_data(client, TPS_MASK1, ~tps->nmask1); in tps65010_probe()
609 tps->nmask2 = TPS_REG_ONOFF; in tps65010_probe()
610 if (tps->model == TPS65013) in tps65010_probe()
611 tps->nmask2 |= TPS_REG_NO_CHG; in tps65010_probe()
612 (void) i2c_smbus_write_byte_data(client, TPS_MASK2, ~tps->nmask2); in tps65010_probe()
617 tps65010_work(&tps->work.work); in tps65010_probe()
619 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL, in tps65010_probe()
622 /* optionally register GPIOs */ in tps65010_probe()
623 if (board && board->base != 0) { in tps65010_probe()
624 tps->outmask = board->outmask; in tps65010_probe()
626 tps->chip.label = client->name; in tps65010_probe()
627 tps->chip.parent = &client->dev; in tps65010_probe()
628 tps->chip.owner = THIS_MODULE; in tps65010_probe()
630 tps->chip.set = tps65010_gpio_set; in tps65010_probe()
631 tps->chip.direction_output = tps65010_output; in tps65010_probe()
634 tps->chip.get = tps65010_gpio_get; in tps65010_probe()
636 tps->chip.base = board->base; in tps65010_probe()
637 tps->chip.ngpio = 7; in tps65010_probe()
638 tps->chip.can_sleep = 1; in tps65010_probe()
640 status = gpiochip_add_data(&tps->chip, tps); in tps65010_probe()
642 dev_err(&client->dev, "can't add gpiochip, err %d\n", in tps65010_probe()
644 else if (board->setup) { in tps65010_probe()
645 status = board->setup(client, board->context); in tps65010_probe()
647 dev_dbg(&client->dev, in tps65010_probe()
649 "setup", client->name, status); in tps65010_probe()
677 /*-------------------------------------------------------------------------*/
680 * 0 mA -- DON'T DRAW (might supply power instead)
681 * 100 mA -- usb unit load (slowest charge rate)
682 * 500 mA -- usb high power (fast battery charge)
689 return -ENODEV; in tps65010_set_vbus_draw()
691 /* assumes non-SMP */ in tps65010_set_vbus_draw()
699 the_tps->vbus = mA; in tps65010_set_vbus_draw()
700 if ((the_tps->chgstatus & TPS_CHG_USB) in tps65010_set_vbus_draw()
702 FLAG_VBUS_CHANGED, &the_tps->flags)) { in tps65010_set_vbus_draw()
704 queue_delayed_work(system_power_efficient_wq, &the_tps->work, in tps65010_set_vbus_draw()
713 /*-------------------------------------------------------------------------*/
724 return -ENODEV; in tps65010_set_gpio_out_value()
726 return -EINVAL; in tps65010_set_gpio_out_value()
728 mutex_lock(&the_tps->lock); in tps65010_set_gpio_out_value()
730 defgpio = i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO); in tps65010_set_gpio_out_value()
738 defgpio |= 1 << (gpio - 1); /* set GPIO low by writing 1 */ in tps65010_set_gpio_out_value()
742 defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */ in tps65010_set_gpio_out_value()
746 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_gpio_out_value()
751 i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO)); in tps65010_set_gpio_out_value()
753 mutex_unlock(&the_tps->lock); in tps65010_set_gpio_out_value()
758 /*-------------------------------------------------------------------------*/
769 return -ENODEV; in tps65010_set_led()
778 mutex_lock(&the_tps->lock); in tps65010_set_led()
781 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
785 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
804 mutex_unlock(&the_tps->lock); in tps65010_set_led()
805 return -EINVAL; in tps65010_set_led()
808 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_led()
814 mutex_unlock(&the_tps->lock); in tps65010_set_led()
819 i2c_smbus_read_byte_data(the_tps->client, TPS_LED1_ON + offs)); in tps65010_set_led()
821 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_led()
827 mutex_unlock(&the_tps->lock); in tps65010_set_led()
832 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
835 mutex_unlock(&the_tps->lock); in tps65010_set_led()
841 /*-------------------------------------------------------------------------*/
851 return -ENODEV; in tps65010_set_vib()
853 mutex_lock(&the_tps->lock); in tps65010_set_vib()
855 vdcdc2 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC2); in tps65010_set_vib()
859 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_vib()
864 mutex_unlock(&the_tps->lock); in tps65010_set_vib()
869 /*-------------------------------------------------------------------------*/
879 return -ENODEV; in tps65010_set_low_pwr()
881 mutex_lock(&the_tps->lock); in tps65010_set_low_pwr()
885 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65010_set_low_pwr()
887 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1); in tps65010_set_low_pwr()
899 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_low_pwr()
907 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65010_set_low_pwr()
909 mutex_unlock(&the_tps->lock); in tps65010_set_low_pwr()
915 /*-------------------------------------------------------------------------*/
925 return -ENODEV; in tps65010_config_vregs1()
927 mutex_lock(&the_tps->lock); in tps65010_config_vregs1()
930 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1)); in tps65010_config_vregs1()
932 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_config_vregs1()
940 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1)); in tps65010_config_vregs1()
942 mutex_unlock(&the_tps->lock); in tps65010_config_vregs1()
954 return -ENODEV; in tps65010_config_vdcdc2()
956 c = the_tps->client; in tps65010_config_vdcdc2()
957 mutex_lock(&the_tps->lock); in tps65010_config_vdcdc2()
971 mutex_unlock(&the_tps->lock); in tps65010_config_vdcdc2()
976 /*-------------------------------------------------------------------------*/
981 /* FIXME: Assumes AC or USB power is present. Setting AUA bit is not
989 if (!the_tps || the_tps->por) in tps65013_set_low_pwr()
990 return -ENODEV; in tps65013_set_low_pwr()
992 mutex_lock(&the_tps->lock); in tps65013_set_low_pwr()
997 i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG), in tps65013_set_low_pwr()
998 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65013_set_low_pwr()
1000 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG); in tps65013_set_low_pwr()
1001 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1); in tps65013_set_low_pwr()
1015 status = i2c_smbus_write_byte_data(the_tps->client, in tps65013_set_low_pwr()
1020 mutex_unlock(&the_tps->lock); in tps65013_set_low_pwr()
1024 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG); in tps65013_set_low_pwr()
1025 the_tps->chgconf = chgconfig; in tps65013_set_low_pwr()
1028 status = i2c_smbus_write_byte_data(the_tps->client, in tps65013_set_low_pwr()
1036 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65013_set_low_pwr()
1038 mutex_unlock(&the_tps->lock); in tps65013_set_low_pwr()
1044 /*-------------------------------------------------------------------------*/
1052 * That is, much earlier than on PC-type systems, which don't often use