Lines Matching +full:dout +full:- +full:gpios
2 * tps65010 - driver for tps6501x power management chips
5 * Copyright (C) 2004-2005 David Brownell
40 /*-------------------------------------------------------------------------*/
50 /*-------------------------------------------------------------------------*/
53 * voltage regulators, lithium ion/polymer battery charging, GPIOs, LEDs,
60 * battery-insert != device-on.
97 /*-------------------------------------------------------------------------*/
197 struct tps65010 *tps = s->private; in dbg_show()
203 switch (tps->model) { in dbg_show()
213 mutex_lock(&tps->lock); in dbg_show()
219 seq_printf(s, "%scharging\n\n", tps->charging ? "" : "(not) "); in dbg_show()
225 value = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG); in dbg_show()
226 dbg_chgconf(tps->por, buf, sizeof buf, value); in dbg_show()
229 value = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS); in dbg_show()
232 value = i2c_smbus_read_byte_data(tps->client, TPS_MASK1); in dbg_show()
237 value = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS); in dbg_show()
240 value = i2c_smbus_read_byte_data(tps->client, TPS_MASK2); in dbg_show()
245 queue_delayed_work(system_power_efficient_wq, &tps->work, in dbg_show()
249 value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC1); in dbg_show()
253 value = i2c_smbus_read_byte_data(tps->client, TPS_VDCDC2); in dbg_show()
257 value = i2c_smbus_read_byte_data(tps->client, TPS_VREGS1); in dbg_show()
261 /* LEDs and GPIOs */ in dbg_show()
262 value = i2c_smbus_read_byte_data(tps->client, TPS_LED1_ON); in dbg_show()
263 v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED1_PER); in dbg_show()
271 value = i2c_smbus_read_byte_data(tps->client, TPS_LED2_ON); in dbg_show()
272 v2 = i2c_smbus_read_byte_data(tps->client, TPS_LED2_PER); in dbg_show()
280 value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO); in dbg_show()
281 v2 = i2c_smbus_read_byte_data(tps->client, TPS_MASK3); in dbg_show()
286 seq_printf(s, " gpio%d-out %s\n", i + 1, in dbg_show()
289 seq_printf(s, " gpio%d-in %s %s %s\n", i + 1, in dbg_show()
291 (v2 & (1 << i)) ? "no-irq" : "irq", in dbg_show()
295 mutex_unlock(&tps->lock); in dbg_show()
301 return single_open(file, dbg_show, inode->i_private); in dbg_tps_open()
317 /*-------------------------------------------------------------------------*/
330 if (tps->nmask2) { in tps65010_interrupt()
331 tmp = i2c_smbus_read_byte_data(tps->client, TPS_REGSTATUS); in tps65010_interrupt()
332 mask = tmp ^ tps->regstatus; in tps65010_interrupt()
333 tps->regstatus = tmp; in tps65010_interrupt()
334 mask &= tps->nmask2; in tps65010_interrupt()
338 tps->regstatus = tmp; in tps65010_interrupt()
357 if (tps->nmask1) { in tps65010_interrupt()
358 tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGSTATUS); in tps65010_interrupt()
359 mask = tmp ^ tps->chgstatus; in tps65010_interrupt()
360 tps->chgstatus = tmp; in tps65010_interrupt()
361 mask &= tps->nmask1; in tps65010_interrupt()
369 show_chgconfig(tps->por, "conf", tps->chgconf); in tps65010_interrupt()
375 if (!(tps->chgstatus & ~(TPS_CHG_USB|TPS_CHG_AC)) in tps65010_interrupt()
376 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC)) in tps65010_interrupt()
377 && (tps->chgconf & TPS_CHARGE_ENABLE) in tps65010_interrupt()
379 if (tps->chgstatus & TPS_CHG_USB) { in tps65010_interrupt()
382 set_bit(FLAG_VBUS_CHANGED, &tps->flags); in tps65010_interrupt()
384 } else if (tps->chgstatus & TPS_CHG_AC) in tps65010_interrupt()
387 if (charging != tps->charging) { in tps65010_interrupt()
388 tps->charging = charging; in tps65010_interrupt()
391 ((tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC)) in tps65010_interrupt()
399 if ((tps->model != TPS65013 || !tps->charging) in tps65010_interrupt()
400 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))) in tps65010_interrupt()
403 queue_delayed_work(system_power_efficient_wq, &tps->work, in tps65010_interrupt()
406 /* also potentially gpio-in rise or fall */ in tps65010_interrupt()
415 mutex_lock(&tps->lock); in tps65010_work()
419 if (test_and_clear_bit(FLAG_VBUS_CHANGED, &tps->flags)) { in tps65010_work()
423 chgconfig = i2c_smbus_read_byte_data(tps->client, in tps65010_work()
426 if (tps->vbus == 500) in tps65010_work()
428 else if (tps->vbus >= 100) in tps65010_work()
431 status = i2c_smbus_write_byte_data(tps->client, in tps65010_work()
435 tmp = i2c_smbus_read_byte_data(tps->client, TPS_CHGCONFIG); in tps65010_work()
436 tps->chgconf = tmp; in tps65010_work()
437 show_chgconfig(tps->por, "update vbus", tmp); in tps65010_work()
440 if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags)) in tps65010_work()
441 enable_irq(tps->client->irq); in tps65010_work()
443 mutex_unlock(&tps->lock); in tps65010_work()
451 set_bit(FLAG_IRQ_ENABLE, &tps->flags); in tps65010_irq()
452 queue_delayed_work(system_power_efficient_wq, &tps->work, 0); in tps65010_irq()
456 /*-------------------------------------------------------------------------*/
459 * offsets 4..5 == LED1/nPG, LED2 (we set one of the non-BLINK modes)
468 tps65010_set_led(offset - 3, value ? ON : OFF); in tps65010_gpio_set()
476 /* GPIOs may be input-only */ in tps65010_output()
481 if (!(tps->outmask & (1 << offset))) in tps65010_output()
482 return -EINVAL; in tps65010_output()
485 tps65010_set_led(offset - 3, value ? ON : OFF); in tps65010_output()
500 value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO); in tps65010_gpio_get()
514 /*-------------------------------------------------------------------------*/
521 struct tps65010_board *board = dev_get_platdata(&client->dev); in tps65010_remove()
523 if (board && board->teardown) { in tps65010_remove()
524 int status = board->teardown(client, board->context); in tps65010_remove()
526 dev_dbg(&client->dev, "board %s %s err %d\n", in tps65010_remove()
527 "teardown", client->name, status); in tps65010_remove()
529 if (client->irq > 0) in tps65010_remove()
530 free_irq(client->irq, tps); in tps65010_remove()
531 cancel_delayed_work_sync(&tps->work); in tps65010_remove()
532 debugfs_remove(tps->file); in tps65010_remove()
542 struct tps65010_board *board = dev_get_platdata(&client->dev); in tps65010_probe()
545 dev_dbg(&client->dev, "only one tps6501x chip allowed\n"); in tps65010_probe()
546 return -ENODEV; in tps65010_probe()
549 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) in tps65010_probe()
550 return -EINVAL; in tps65010_probe()
552 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); in tps65010_probe()
554 return -ENOMEM; in tps65010_probe()
556 mutex_init(&tps->lock); in tps65010_probe()
557 INIT_DELAYED_WORK(&tps->work, tps65010_work); in tps65010_probe()
558 tps->client = client; in tps65010_probe()
559 tps->model = id->driver_data; in tps65010_probe()
562 * so this driver uses falling-edge triggers instead. in tps65010_probe()
564 if (client->irq > 0) { in tps65010_probe()
565 status = request_irq(client->irq, tps65010_irq, in tps65010_probe()
568 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n", in tps65010_probe()
569 client->irq, status); in tps65010_probe()
576 disable_irq(client->irq); in tps65010_probe()
577 set_bit(FLAG_IRQ_ENABLE, &tps->flags); in tps65010_probe()
579 dev_warn(&client->dev, "IRQ not configured!\n"); in tps65010_probe()
582 switch (tps->model) { in tps65010_probe()
585 tps->por = 1; in tps65010_probe()
589 tps->chgconf = i2c_smbus_read_byte_data(client, TPS_CHGCONFIG); in tps65010_probe()
590 show_chgconfig(tps->por, "conf/init", tps->chgconf); in tps65010_probe()
613 tps->vbus = 100; in tps65010_probe()
620 tps->nmask1 = ~0; in tps65010_probe()
621 (void) i2c_smbus_write_byte_data(client, TPS_MASK1, ~tps->nmask1); in tps65010_probe()
623 tps->nmask2 = TPS_REG_ONOFF; in tps65010_probe()
624 if (tps->model == TPS65013) in tps65010_probe()
625 tps->nmask2 |= TPS_REG_NO_CHG; in tps65010_probe()
626 (void) i2c_smbus_write_byte_data(client, TPS_MASK2, ~tps->nmask2); in tps65010_probe()
631 tps65010_work(&tps->work.work); in tps65010_probe()
633 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL, in tps65010_probe()
636 /* optionally register GPIOs */ in tps65010_probe()
637 if (board && board->base != 0) { in tps65010_probe()
638 tps->outmask = board->outmask; in tps65010_probe()
640 tps->chip.label = client->name; in tps65010_probe()
641 tps->chip.parent = &client->dev; in tps65010_probe()
642 tps->chip.owner = THIS_MODULE; in tps65010_probe()
644 tps->chip.set = tps65010_gpio_set; in tps65010_probe()
645 tps->chip.direction_output = tps65010_output; in tps65010_probe()
648 tps->chip.get = tps65010_gpio_get; in tps65010_probe()
650 tps->chip.base = board->base; in tps65010_probe()
651 tps->chip.ngpio = 7; in tps65010_probe()
652 tps->chip.can_sleep = 1; in tps65010_probe()
654 status = gpiochip_add_data(&tps->chip, tps); in tps65010_probe()
656 dev_err(&client->dev, "can't add gpiochip, err %d\n", in tps65010_probe()
658 else if (board->setup) { in tps65010_probe()
659 status = board->setup(client, board->context); in tps65010_probe()
661 dev_dbg(&client->dev, in tps65010_probe()
663 "setup", client->name, status); in tps65010_probe()
691 /*-------------------------------------------------------------------------*/
694 * 0 mA -- DON'T DRAW (might supply power instead)
695 * 100 mA -- usb unit load (slowest charge rate)
696 * 500 mA -- usb high power (fast battery charge)
703 return -ENODEV; in tps65010_set_vbus_draw()
705 /* assumes non-SMP */ in tps65010_set_vbus_draw()
713 the_tps->vbus = mA; in tps65010_set_vbus_draw()
714 if ((the_tps->chgstatus & TPS_CHG_USB) in tps65010_set_vbus_draw()
716 FLAG_VBUS_CHANGED, &the_tps->flags)) { in tps65010_set_vbus_draw()
718 queue_delayed_work(system_power_efficient_wq, &the_tps->work, in tps65010_set_vbus_draw()
727 /*-------------------------------------------------------------------------*/
738 return -ENODEV; in tps65010_set_gpio_out_value()
740 return -EINVAL; in tps65010_set_gpio_out_value()
742 mutex_lock(&the_tps->lock); in tps65010_set_gpio_out_value()
744 defgpio = i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO); in tps65010_set_gpio_out_value()
752 defgpio |= 1 << (gpio - 1); /* set GPIO low by writing 1 */ in tps65010_set_gpio_out_value()
756 defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */ in tps65010_set_gpio_out_value()
760 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_gpio_out_value()
763 pr_debug("%s: gpio%dout = %s, defgpio 0x%02x\n", DRIVER_NAME, in tps65010_set_gpio_out_value()
765 i2c_smbus_read_byte_data(the_tps->client, TPS_DEFGPIO)); in tps65010_set_gpio_out_value()
767 mutex_unlock(&the_tps->lock); in tps65010_set_gpio_out_value()
772 /*-------------------------------------------------------------------------*/
783 return -ENODEV; in tps65010_set_led()
792 mutex_lock(&the_tps->lock); in tps65010_set_led()
795 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
799 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
818 mutex_unlock(&the_tps->lock); in tps65010_set_led()
819 return -EINVAL; in tps65010_set_led()
822 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_led()
828 mutex_unlock(&the_tps->lock); in tps65010_set_led()
833 i2c_smbus_read_byte_data(the_tps->client, TPS_LED1_ON + offs)); in tps65010_set_led()
835 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_led()
841 mutex_unlock(&the_tps->lock); in tps65010_set_led()
846 i2c_smbus_read_byte_data(the_tps->client, in tps65010_set_led()
849 mutex_unlock(&the_tps->lock); in tps65010_set_led()
855 /*-------------------------------------------------------------------------*/
865 return -ENODEV; in tps65010_set_vib()
867 mutex_lock(&the_tps->lock); in tps65010_set_vib()
869 vdcdc2 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC2); in tps65010_set_vib()
873 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_vib()
878 mutex_unlock(&the_tps->lock); in tps65010_set_vib()
883 /*-------------------------------------------------------------------------*/
893 return -ENODEV; in tps65010_set_low_pwr()
895 mutex_lock(&the_tps->lock); in tps65010_set_low_pwr()
899 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65010_set_low_pwr()
901 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1); in tps65010_set_low_pwr()
913 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_set_low_pwr()
921 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65010_set_low_pwr()
923 mutex_unlock(&the_tps->lock); in tps65010_set_low_pwr()
929 /*-------------------------------------------------------------------------*/
939 return -ENODEV; in tps65010_config_vregs1()
941 mutex_lock(&the_tps->lock); in tps65010_config_vregs1()
944 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1)); in tps65010_config_vregs1()
946 status = i2c_smbus_write_byte_data(the_tps->client, in tps65010_config_vregs1()
954 i2c_smbus_read_byte_data(the_tps->client, TPS_VREGS1)); in tps65010_config_vregs1()
956 mutex_unlock(&the_tps->lock); in tps65010_config_vregs1()
968 return -ENODEV; in tps65010_config_vdcdc2()
970 c = the_tps->client; in tps65010_config_vdcdc2()
971 mutex_lock(&the_tps->lock); in tps65010_config_vdcdc2()
985 mutex_unlock(&the_tps->lock); in tps65010_config_vdcdc2()
990 /*-------------------------------------------------------------------------*/
1003 if (!the_tps || the_tps->por) in tps65013_set_low_pwr()
1004 return -ENODEV; in tps65013_set_low_pwr()
1006 mutex_lock(&the_tps->lock); in tps65013_set_low_pwr()
1011 i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG), in tps65013_set_low_pwr()
1012 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65013_set_low_pwr()
1014 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG); in tps65013_set_low_pwr()
1015 vdcdc1 = i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1); in tps65013_set_low_pwr()
1029 status = i2c_smbus_write_byte_data(the_tps->client, in tps65013_set_low_pwr()
1034 mutex_unlock(&the_tps->lock); in tps65013_set_low_pwr()
1038 chgconfig = i2c_smbus_read_byte_data(the_tps->client, TPS_CHGCONFIG); in tps65013_set_low_pwr()
1039 the_tps->chgconf = chgconfig; in tps65013_set_low_pwr()
1042 status = i2c_smbus_write_byte_data(the_tps->client, in tps65013_set_low_pwr()
1050 i2c_smbus_read_byte_data(the_tps->client, TPS_VDCDC1)); in tps65013_set_low_pwr()
1052 mutex_unlock(&the_tps->lock); in tps65013_set_low_pwr()
1058 /*-------------------------------------------------------------------------*/
1066 * That is, much earlier than on PC-type systems, which don't often use