Lines Matching +full:their +full:- +full:claim +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 /*-------------------------------------------------------------------------*/
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()
243 /* both LD0s, and their lowpower behavior */ 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()
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()
549 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n", in tps65010_probe()
550 client->irq, status); in tps65010_probe()
554 * to claim the irq now and enable it later. in tps65010_probe()
557 disable_irq(client->irq); in tps65010_probe()
558 set_bit(FLAG_IRQ_ENABLE, &tps->flags); in tps65010_probe()
560 dev_warn(&client->dev, "IRQ not configured!\n"); in tps65010_probe()
563 switch (tps->model) { in tps65010_probe()
566 tps->por = 1; in tps65010_probe()
570 tps->chgconf = i2c_smbus_read_byte_data(client, TPS_CHGCONFIG); in tps65010_probe()
571 show_chgconfig(tps->por, "conf/init", tps->chgconf); in tps65010_probe()
594 tps->vbus = 100; in tps65010_probe()
601 tps->nmask1 = ~0; in tps65010_probe()
602 (void) i2c_smbus_write_byte_data(client, TPS_MASK1, ~tps->nmask1); in tps65010_probe()
604 tps->nmask2 = TPS_REG_ONOFF; in tps65010_probe()
605 if (tps->model == TPS65013) in tps65010_probe()
606 tps->nmask2 |= TPS_REG_NO_CHG; in tps65010_probe()
607 (void) i2c_smbus_write_byte_data(client, TPS_MASK2, ~tps->nmask2); in tps65010_probe()
612 tps65010_work(&tps->work.work); in tps65010_probe()
614 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL, in tps65010_probe()
617 /* optionally register GPIOs */ in tps65010_probe()
619 tps->outmask = board->outmask; in tps65010_probe()
621 tps->chip.label = client->name; in tps65010_probe()
622 tps->chip.parent = &client->dev; in tps65010_probe()
623 tps->chip.owner = THIS_MODULE; in tps65010_probe()
625 tps->chip.set = tps65010_gpio_set; in tps65010_probe()
626 tps->chip.direction_output = tps65010_output; in tps65010_probe()
629 tps->chip.get = tps65010_gpio_get; in tps65010_probe()
631 tps->chip.base = -1; in tps65010_probe()
632 tps->chip.ngpio = 7; in tps65010_probe()
633 tps->chip.can_sleep = 1; in tps65010_probe()
635 status = gpiochip_add_data(&tps->chip, tps); in tps65010_probe()
637 dev_err(&client->dev, "can't add gpiochip, err %d\n", in tps65010_probe()
639 else if (board->setup) { in tps65010_probe()
640 status = board->setup(client, &tps->chip); in tps65010_probe()
642 dev_dbg(&client->dev, in tps65010_probe()
644 "setup", client->name, status); in tps65010_probe()
672 /*-------------------------------------------------------------------------*/
675 * 0 mA -- DON'T DRAW (might supply power instead)
676 * 100 mA -- usb unit load (slowest charge rate)
677 * 500 mA -- usb high power (fast battery charge)
684 return -ENODEV; in tps65010_set_vbus_draw()
686 /* assumes non-SMP */ in tps65010_set_vbus_draw()
694 the_tps->vbus = mA; in tps65010_set_vbus_draw()
695 if ((the_tps->chgstatus & TPS_CHG_USB) in tps65010_set_vbus_draw()
697 FLAG_VBUS_CHANGED, &the_tps->flags)) { in tps65010_set_vbus_draw()
699 queue_delayed_work(system_power_efficient_wq, &the_tps->work, in tps65010_set_vbus_draw()
708 /*-------------------------------------------------------------------------*/
719 return -ENODEV; in tps65010_set_gpio_out_value()
721 return -EINVAL; in tps65010_set_gpio_out_value()
723 mutex_lock(&the_tps->lock); in tps65010_set_gpio_out_value()
725 defgpio = i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO); in tps65010_set_gpio_out_value()
733 defgpio |= 1 << (gpio - 1); /* set GPIO low by writing 1 */ in tps65010_set_gpio_out_value()
737 defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */ in tps65010_set_gpio_out_value()
741 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_gpio_out_value()
746 i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO)); in tps65010_set_gpio_out_value()
748 mutex_unlock(&the_tps->lock); in tps65010_set_gpio_out_value()
753 /*-------------------------------------------------------------------------*/
764 return -ENODEV; in tps65010_set_led()
773 mutex_lock(&the_tps->lock); in tps65010_set_led()
776 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
780 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
799 mutex_unlock(&the_tps->lock); in tps65010_set_led()
800 return -EINVAL; in tps65010_set_led()
803 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_led()
809 mutex_unlock(&the_tps->lock); in tps65010_set_led()
814 i2c_smbus_read_byte_data(the_tps->client, TPS_LED1_ON + offs)); in tps65010_set_led()
816 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_led()
822 mutex_unlock(&the_tps->lock); in tps65010_set_led()
827 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
830 mutex_unlock(&the_tps->lock); in tps65010_set_led()
836 /*-------------------------------------------------------------------------*/
846 return -ENODEV; in tps65010_set_vib()
848 mutex_lock(&the_tps->lock); in tps65010_set_vib()
850 vdcdc2 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC2); in tps65010_set_vib()
854 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_vib()
859 mutex_unlock(&the_tps->lock); in tps65010_set_vib()
864 /*-------------------------------------------------------------------------*/
874 return -ENODEV; in tps65010_set_low_pwr()
876 mutex_lock(&the_tps->lock); in tps65010_set_low_pwr()
880 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65010_set_low_pwr()
882 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1); in tps65010_set_low_pwr()
894 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_low_pwr()
902 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65010_set_low_pwr()
904 mutex_unlock(&the_tps->lock); in tps65010_set_low_pwr()
910 /*-------------------------------------------------------------------------*/
920 return -ENODEV; in tps65010_config_vregs1()
922 mutex_lock(&the_tps->lock); in tps65010_config_vregs1()
925 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1)); in tps65010_config_vregs1()
927 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_config_vregs1()
935 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1)); in tps65010_config_vregs1()
937 mutex_unlock(&the_tps->lock); in tps65010_config_vregs1()
949 return -ENODEV; in tps65010_config_vdcdc2()
951 c = the_tps->client; in tps65010_config_vdcdc2()
952 mutex_lock(&the_tps->lock); in tps65010_config_vdcdc2()
966 mutex_unlock(&the_tps->lock); in tps65010_config_vdcdc2()
971 /*-------------------------------------------------------------------------*/
984 if (!the_tps || the_tps->por) in tps65013_set_low_pwr()
985 return -ENODEV; in tps65013_set_low_pwr()
987 mutex_lock(&the_tps->lock); in tps65013_set_low_pwr()
992 i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG), in tps65013_set_low_pwr()
993 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65013_set_low_pwr()
995 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG); in tps65013_set_low_pwr()
996 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1); in tps65013_set_low_pwr()
1010 status = i2c_smbus_write_byte_data(the_tps->client, in tps65013_set_low_pwr()
1015 mutex_unlock(&the_tps->lock); in tps65013_set_low_pwr()
1019 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG); in tps65013_set_low_pwr()
1020 the_tps->chgconf = chgconfig; in tps65013_set_low_pwr()
1023 status = i2c_smbus_write_byte_data(the_tps->client, in tps65013_set_low_pwr()
1031 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65013_set_low_pwr()
1033 mutex_unlock(&the_tps->lock); in tps65013_set_low_pwr()
1039 /*-------------------------------------------------------------------------*/
1047 * That is, much earlier than on PC-type systems, which don't often use