Lines Matching +full:shut +full:- +full:down +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()
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()
326 /* may need to shut something down ... */ 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 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()
527 struct tps65010_board *board = dev_get_platdata(&client->dev); in tps65010_probe()
530 dev_dbg(&client->dev, "only one tps6501x chip allowed\n"); in tps65010_probe()
531 return -ENODEV; in tps65010_probe()
534 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in tps65010_probe()
535 return -EINVAL; in tps65010_probe()
537 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); in tps65010_probe()
539 return -ENOMEM; in tps65010_probe()
541 mutex_init(&tps->lock); in tps65010_probe()
542 INIT_DELAYED_WORK(&tps->work, tps65010_work); in tps65010_probe()
543 tps->client = client; in tps65010_probe()
544 tps->model = id->driver_data; in tps65010_probe()
547 * so this driver uses falling-edge triggers instead. in tps65010_probe()
549 if (client->irq > 0) { in tps65010_probe()
550 status = request_irq(client->irq, tps65010_irq, in tps65010_probe()
553 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n", in tps65010_probe()
554 client->irq, status); in tps65010_probe()
561 disable_irq(client->irq); in tps65010_probe()
562 set_bit(FLAG_IRQ_ENABLE, &tps->flags); in tps65010_probe()
564 dev_warn(&client->dev, "IRQ not configured!\n"); in tps65010_probe()
567 switch (tps->model) { in tps65010_probe()
570 tps->por = 1; in tps65010_probe()
574 tps->chgconf = i2c_smbus_read_byte_data(client, TPS_CHGCONFIG); in tps65010_probe()
575 show_chgconfig(tps->por, "conf/init", tps->chgconf); in tps65010_probe()
598 tps->vbus = 100; in tps65010_probe()
605 tps->nmask1 = ~0; in tps65010_probe()
606 (void) i2c_smbus_write_byte_data(client, TPS_MASK1, ~tps->nmask1); in tps65010_probe()
608 tps->nmask2 = TPS_REG_ONOFF; in tps65010_probe()
609 if (tps->model == TPS65013) in tps65010_probe()
610 tps->nmask2 |= TPS_REG_NO_CHG; in tps65010_probe()
611 (void) i2c_smbus_write_byte_data(client, TPS_MASK2, ~tps->nmask2); in tps65010_probe()
616 tps65010_work(&tps->work.work); in tps65010_probe()
618 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL, in tps65010_probe()
621 /* optionally register GPIOs */ in tps65010_probe()
622 if (board && board->base != 0) { in tps65010_probe()
623 tps->outmask = board->outmask; in tps65010_probe()
625 tps->chip.label = client->name; in tps65010_probe()
626 tps->chip.parent = &client->dev; in tps65010_probe()
627 tps->chip.owner = THIS_MODULE; in tps65010_probe()
629 tps->chip.set = tps65010_gpio_set; in tps65010_probe()
630 tps->chip.direction_output = tps65010_output; in tps65010_probe()
633 tps->chip.get = tps65010_gpio_get; in tps65010_probe()
635 tps->chip.base = board->base; in tps65010_probe()
636 tps->chip.ngpio = 7; in tps65010_probe()
637 tps->chip.can_sleep = 1; in tps65010_probe()
639 status = gpiochip_add_data(&tps->chip, tps); in tps65010_probe()
641 dev_err(&client->dev, "can't add gpiochip, err %d\n", in tps65010_probe()
643 else if (board->setup) { in tps65010_probe()
644 status = board->setup(client, board->context); in tps65010_probe()
646 dev_dbg(&client->dev, in tps65010_probe()
648 "setup", client->name, status); in tps65010_probe()
676 /*-------------------------------------------------------------------------*/
679 * 0 mA -- DON'T DRAW (might supply power instead)
680 * 100 mA -- usb unit load (slowest charge rate)
681 * 500 mA -- usb high power (fast battery charge)
688 return -ENODEV; in tps65010_set_vbus_draw()
690 /* assumes non-SMP */ in tps65010_set_vbus_draw()
698 the_tps->vbus = mA; in tps65010_set_vbus_draw()
699 if ((the_tps->chgstatus & TPS_CHG_USB) in tps65010_set_vbus_draw()
701 FLAG_VBUS_CHANGED, &the_tps->flags)) { in tps65010_set_vbus_draw()
703 queue_delayed_work(system_power_efficient_wq, &the_tps->work, in tps65010_set_vbus_draw()
712 /*-------------------------------------------------------------------------*/
723 return -ENODEV; in tps65010_set_gpio_out_value()
725 return -EINVAL; in tps65010_set_gpio_out_value()
727 mutex_lock(&the_tps->lock); in tps65010_set_gpio_out_value()
729 defgpio = i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO); in tps65010_set_gpio_out_value()
737 defgpio |= 1 << (gpio - 1); /* set GPIO low by writing 1 */ in tps65010_set_gpio_out_value()
741 defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */ in tps65010_set_gpio_out_value()
745 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_gpio_out_value()
750 i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO)); in tps65010_set_gpio_out_value()
752 mutex_unlock(&the_tps->lock); in tps65010_set_gpio_out_value()
757 /*-------------------------------------------------------------------------*/
768 return -ENODEV; in tps65010_set_led()
777 mutex_lock(&the_tps->lock); in tps65010_set_led()
780 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
784 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
803 mutex_unlock(&the_tps->lock); in tps65010_set_led()
804 return -EINVAL; in tps65010_set_led()
807 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_led()
813 mutex_unlock(&the_tps->lock); in tps65010_set_led()
818 i2c_smbus_read_byte_data(the_tps->client, TPS_LED1_ON + offs)); in tps65010_set_led()
820 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_led()
826 mutex_unlock(&the_tps->lock); in tps65010_set_led()
831 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
834 mutex_unlock(&the_tps->lock); in tps65010_set_led()
840 /*-------------------------------------------------------------------------*/
850 return -ENODEV; in tps65010_set_vib()
852 mutex_lock(&the_tps->lock); in tps65010_set_vib()
854 vdcdc2 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC2); in tps65010_set_vib()
858 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_vib()
863 mutex_unlock(&the_tps->lock); in tps65010_set_vib()
868 /*-------------------------------------------------------------------------*/
878 return -ENODEV; in tps65010_set_low_pwr()
880 mutex_lock(&the_tps->lock); in tps65010_set_low_pwr()
884 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65010_set_low_pwr()
886 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1); in tps65010_set_low_pwr()
898 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_low_pwr()
906 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65010_set_low_pwr()
908 mutex_unlock(&the_tps->lock); in tps65010_set_low_pwr()
914 /*-------------------------------------------------------------------------*/
924 return -ENODEV; in tps65010_config_vregs1()
926 mutex_lock(&the_tps->lock); in tps65010_config_vregs1()
929 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1)); in tps65010_config_vregs1()
931 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_config_vregs1()
939 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1)); in tps65010_config_vregs1()
941 mutex_unlock(&the_tps->lock); in tps65010_config_vregs1()
953 return -ENODEV; in tps65010_config_vdcdc2()
955 c = the_tps->client; in tps65010_config_vdcdc2()
956 mutex_lock(&the_tps->lock); in tps65010_config_vdcdc2()
970 mutex_unlock(&the_tps->lock); in tps65010_config_vdcdc2()
975 /*-------------------------------------------------------------------------*/
988 if (!the_tps || the_tps->por) in tps65013_set_low_pwr()
989 return -ENODEV; in tps65013_set_low_pwr()
991 mutex_lock(&the_tps->lock); in tps65013_set_low_pwr()
996 i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG), in tps65013_set_low_pwr()
997 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65013_set_low_pwr()
999 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG); in tps65013_set_low_pwr()
1000 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1); in tps65013_set_low_pwr()
1014 status = i2c_smbus_write_byte_data(the_tps->client, in tps65013_set_low_pwr()
1019 mutex_unlock(&the_tps->lock); in tps65013_set_low_pwr()
1023 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG); in tps65013_set_low_pwr()
1024 the_tps->chgconf = chgconfig; in tps65013_set_low_pwr()
1027 status = i2c_smbus_write_byte_data(the_tps->client, in tps65013_set_low_pwr()
1035 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65013_set_low_pwr()
1037 mutex_unlock(&the_tps->lock); in tps65013_set_low_pwr()
1043 /*-------------------------------------------------------------------------*/
1051 * That is, much earlier than on PC-type systems, which don't often use