Lines Matching +full:enable +full:- +full:otg +full:- +full:charging

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 /*-------------------------------------------------------------------------*/
41 * voltage regulators, lithium ion/polymer battery charging, GPIOs, LEDs,
48 * battery-insert != device-on.
66 unsigned charging:1;
85 /*-------------------------------------------------------------------------*/
98 ? " (charging)" : ""),
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) ");
210 /* registers for monitoring battery charging and status; note
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,
236 /* VMAIN voltage, enable lowpower, etc */
237 value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC1);
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;
353 unsigned charging = 0;
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);
371 charging = 1;
372 } else if (tps->chgstatus & TPS_CHG_AC)
373 charging = 1;
375 if (charging != tps->charging) {
376 tps->charging = charging;
378 DRIVER_NAME, charging ? "" :
379 ((tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
385 * NO_CHG IRQ; or (b) restart of charging after stop.
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);
465 /* GPIOs may be input-only */
470 if (!(tps->outmask & (1 << offset)))
471 return -EINVAL;
474 tps65010_set_led(offset - 3, value ? ON : OFF);
489 value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO);
503 /*-------------------------------------------------------------------------*/
510 struct tps65010_board *board = dev_get_platdata(&client->dev);
512 if (board && board->teardown)
513 board->teardown(client, &tps->chip);
514 if (client->irq > 0)
515 free_irq(client->irq, tps);
516 cancel_delayed_work_sync(&tps->work);
525 struct tps65010_board *board = dev_get_platdata(&client->dev);
528 dev_dbg(&client->dev, "only one tps6501x chip allowed\n");
529 return -ENODEV;
532 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
533 return -EINVAL;
535 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
537 return -ENOMEM;
539 mutex_init(&tps->lock);
540 INIT_DELAYED_WORK(&tps->work, tps65010_work);
541 tps->client = client;
542 tps->model = id->driver_data;
545 * so this driver uses falling-edge triggers instead.
547 if (client->irq > 0) {
548 status = request_irq(client->irq, tps65010_irq,
552 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n",
553 client->irq, status);
556 set_bit(FLAG_IRQ_ENABLE, &tps->flags);
558 dev_warn(&client->dev, "IRQ not configured!\n");
561 switch (tps->model) {
564 tps->por = 1;
568 tps->chgconf = i2c_smbus_read_byte_data(client, TPS_CHGCONFIG);
569 show_chgconfig(tps->por, "conf/init", tps->chgconf);
588 /* USB hosts can't draw VBUS. OTG devices could, later
589 * when OTG infrastructure enables it. USB peripherals
592 tps->vbus = 100;
599 tps->nmask1 = ~0;
600 (void) i2c_smbus_write_byte_data(client, TPS_MASK1, ~tps->nmask1);
602 tps->nmask2 = TPS_REG_ONOFF;
603 if (tps->model == TPS65013)
604 tps->nmask2 |= TPS_REG_NO_CHG;
605 (void) i2c_smbus_write_byte_data(client, TPS_MASK2, ~tps->nmask2);
610 tps65010_work(&tps->work.work);
612 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, client->debugfs,
617 tps->outmask = board->outmask;
619 tps->chip.label = client->name;
620 tps->chip.parent = &client->dev;
621 tps->chip.owner = THIS_MODULE;
623 tps->chip.set_rv = tps65010_gpio_set;
624 tps->chip.direction_output = tps65010_output;
627 tps->chip.get = tps65010_gpio_get;
629 tps->chip.base = -1;
630 tps->chip.ngpio = 7;
631 tps->chip.can_sleep = 1;
633 status = gpiochip_add_data(&tps->chip, tps);
635 dev_err(&client->dev, "can't add gpiochip, err %d\n",
637 else if (board->setup) {
638 status = board->setup(client, &tps->chip);
640 dev_dbg(&client->dev,
642 "setup", client->name, status);
656 { "tps65014", TPS65011 }, /* tps65011 charging at 6.5V max */
670 /*-------------------------------------------------------------------------*/
673 * 0 mA -- DON'T DRAW (might supply power instead)
674 * 100 mA -- usb unit load (slowest charge rate)
675 * 500 mA -- usb high power (fast battery charge)
682 return -ENODEV;
684 /* assumes non-SMP */
692 the_tps->vbus = mA;
693 if ((the_tps->chgstatus & TPS_CHG_USB)
695 FLAG_VBUS_CHANGED, &the_tps->flags)) {
697 queue_delayed_work(system_power_efficient_wq, &the_tps->work,
706 /*-------------------------------------------------------------------------*/
717 return -ENODEV;
719 return -EINVAL;
721 mutex_lock(&the_tps->lock);
723 defgpio = i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO);
731 defgpio |= 1 << (gpio - 1); /* set GPIO low by writing 1 */
735 defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */
739 status = i2c_smbus_write_byte_data(the_tps->client,
744 i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO));
746 mutex_unlock(&the_tps->lock);
751 /*-------------------------------------------------------------------------*/
762 return -ENODEV;
771 mutex_lock(&the_tps->lock);
774 i2c_smbus_read_byte_data(the_tps->client,
778 i2c_smbus_read_byte_data(the_tps->client,
797 mutex_unlock(&the_tps->lock);
798 return -EINVAL;
801 status = i2c_smbus_write_byte_data(the_tps->client,
807 mutex_unlock(&the_tps->lock);
812 i2c_smbus_read_byte_data(the_tps->client, TPS_LED1_ON + offs));
814 status = i2c_smbus_write_byte_data(the_tps->client,
820 mutex_unlock(&the_tps->lock);
825 i2c_smbus_read_byte_data(the_tps->client,
828 mutex_unlock(&the_tps->lock);
834 /*-------------------------------------------------------------------------*/
844 return -ENODEV;
846 mutex_lock(&the_tps->lock);
848 vdcdc2 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC2);
852 status = i2c_smbus_write_byte_data(the_tps->client,
857 mutex_unlock(&the_tps->lock);
862 /*-------------------------------------------------------------------------*/
872 return -ENODEV;
874 mutex_lock(&the_tps->lock);
878 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
880 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
888 vdcdc1 |= TPS_ENABLE_LP; /* enable ENABLE_LP bit */
892 status = i2c_smbus_write_byte_data(the_tps->client,
900 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
902 mutex_unlock(&the_tps->lock);
908 /*-------------------------------------------------------------------------*/
918 return -ENODEV;
920 mutex_lock(&the_tps->lock);
923 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
925 status = i2c_smbus_write_byte_data(the_tps->client,
933 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1));
935 mutex_unlock(&the_tps->lock);
947 return -ENODEV;
949 c = the_tps->client;
950 mutex_lock(&the_tps->lock);
964 mutex_unlock(&the_tps->lock);
969 /*-------------------------------------------------------------------------*/
982 if (!the_tps || the_tps->por)
983 return -ENODEV;
985 mutex_lock(&the_tps->lock);
990 i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG),
991 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
993 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
994 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1);
1003 chgconfig |= TPS65013_AUA; /* enable AUA bit */
1004 vdcdc1 |= TPS_ENABLE_LP; /* enable ENABLE_LP bit */
1008 status = i2c_smbus_write_byte_data(the_tps->client,
1013 mutex_unlock(&the_tps->lock);
1017 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG);
1018 the_tps->chgconf = chgconfig;
1021 status = i2c_smbus_write_byte_data(the_tps->client,
1029 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1));
1031 mutex_unlock(&the_tps->lock);
1037 /*-------------------------------------------------------------------------*/
1045 * That is, much earlier than on PC-type systems, which don't often use