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