Lines Matching +full:gpio +full:- +full:charger

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Power supply driver for the Active-semi ACT8945A PMIC
16 #include <linux/gpio/consumer.h>
19 static const char *act8945a_charger_manufacturer = "Active-semi";
22 * ACT8945A Charger Register Map
209 static int act8945a_get_capacity_level(struct act8945a_charger *charger,
214 int lbo_level = gpiod_get_value(charger->lbo_gpio);
268 * Riset(K) = 2336 * (1V/Ichg(mA)) - 0.205
276 static int act8945a_get_current_max(struct act8945a_charger *charger,
282 int chgin_level = gpiod_get_value(charger->chglev_gpio);
346 struct act8945a_charger *charger = power_supply_get_drvdata(psy);
347 struct regmap *regmap = charger->regmap;
352 ret = act8945a_get_charger_state(regmap, &val->intval);
355 ret = act8945a_get_charge_type(regmap, &val->intval);
358 val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
361 ret = act8945a_get_battery_health(regmap, &val->intval);
364 ret = act8945a_get_capacity_level(charger,
365 regmap, &val->intval);
368 ret = act8945a_get_current_max(charger,
369 regmap, &val->intval);
372 val->strval = act8945a_charger_model;
375 val->strval = act8945a_charger_manufacturer;
378 return -EINVAL;
384 static int act8945a_enable_interrupt(struct act8945a_charger *charger)
386 struct regmap *regmap = charger->regmap;
407 static unsigned int act8945a_set_supply_type(struct act8945a_charger *charger,
413 ret = regmap_read(charger->regmap, ACT8945A_APCH_STATUS, &status);
417 ret = regmap_read(charger->regmap, ACT8945A_APCH_STATE, &state);
435 struct act8945a_charger *charger =
438 act8945a_set_supply_type(charger, &charger->desc.type);
440 power_supply_changed(charger->psy);
445 struct act8945a_charger *charger = dev_id;
447 if (charger->init_done)
448 schedule_work(&charger->work);
458 struct act8945a_charger *charger)
460 struct device_node *np = dev->of_node;
461 struct regmap *regmap = charger->regmap;
472 dev_err(dev, "no charger of node\n");
473 return -EINVAL;
485 charger->lbo_gpio = devm_gpiod_get_optional(dev, "active-semi,lbo",
487 if (IS_ERR(charger->lbo_gpio)) {
488 err = PTR_ERR(charger->lbo_gpio);
489 dev_err(dev, "unable to claim gpio \"lbo\": %d\n", err);
493 ret = devm_request_irq(dev, gpiod_to_irq(charger->lbo_gpio),
496 "act8945a_lbo_detect", charger);
498 dev_info(dev, "failed to request gpio \"lbo\" IRQ\n");
500 charger->chglev_gpio = devm_gpiod_get_optional(dev,
501 "active-semi,chglev",
503 if (IS_ERR(charger->chglev_gpio)) {
504 err = PTR_ERR(charger->chglev_gpio);
505 dev_err(dev, "unable to claim gpio \"chglev\": %d\n", err);
510 "active-semi,input-voltage-threshold-microvolt",
515 "active-semi,precondition-timeout",
519 if (of_property_read_u32(np, "active-semi,total-timeout",
576 struct act8945a_charger *charger;
580 charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
581 if (!charger)
582 return -ENOMEM;
584 charger->regmap = dev_get_regmap(pdev->dev.parent, NULL);
585 if (!charger->regmap) {
586 dev_err(&pdev->dev, "Parent did not provide regmap\n");
587 return -EINVAL;
590 ret = act8945a_charger_config(&pdev->dev, charger);
594 irq = of_irq_get(pdev->dev.of_node, 0);
596 dev_err(&pdev->dev, "failed to find IRQ number\n");
597 return irq ?: -ENXIO;
600 ret = devm_request_irq(&pdev->dev, irq, act8945a_status_changed,
602 charger);
604 dev_err(&pdev->dev, "failed to request nIRQ pin IRQ\n");
608 charger->desc.name = "act8945a-charger";
609 charger->desc.get_property = act8945a_charger_get_property;
610 charger->desc.properties = act8945a_charger_props;
611 charger->desc.num_properties = ARRAY_SIZE(act8945a_charger_props);
613 ret = act8945a_set_supply_type(charger, &charger->desc.type);
615 return -EINVAL;
617 psy_cfg.fwnode = dev_fwnode(&pdev->dev);
618 psy_cfg.drv_data = charger;
620 charger->psy = devm_power_supply_register(&pdev->dev,
621 &charger->desc,
623 if (IS_ERR(charger->psy)) {
624 dev_err(&pdev->dev, "failed to register power supply\n");
625 return PTR_ERR(charger->psy);
628 platform_set_drvdata(pdev, charger);
630 INIT_WORK(&charger->work, act8945a_work);
632 ret = act8945a_enable_interrupt(charger);
634 return -EIO;
636 charger->init_done = true;
643 struct act8945a_charger *charger = platform_get_drvdata(pdev);
645 charger->init_done = false;
646 cancel_work_sync(&charger->work);
651 .name = "act8945a-charger",
658 MODULE_DESCRIPTION("Active-semi ACT8945A ActivePath charger driver");