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

1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for Analog Devices (Linear Technology) LT3651 charger IC.
8 #include <linux/gpio/consumer.h>
19 struct power_supply *charger; member
28 struct power_supply *charger = devid; in lt3651_charger_irq() local
30 power_supply_changed(charger); in lt3651_charger_irq()
48 if (!lt3651_charger->chrg_gpio) { in lt3651_charger_get_property()
49 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in lt3651_charger_get_property()
52 if (gpiod_get_value(lt3651_charger->chrg_gpio)) in lt3651_charger_get_property()
53 val->intval = POWER_SUPPLY_STATUS_CHARGING; in lt3651_charger_get_property()
55 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in lt3651_charger_get_property()
58 val->intval = gpiod_get_value(lt3651_charger->acpr_gpio); in lt3651_charger_get_property()
61 if (!lt3651_charger->fault_gpio) { in lt3651_charger_get_property()
62 val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; in lt3651_charger_get_property()
65 if (!gpiod_get_value(lt3651_charger->fault_gpio)) { in lt3651_charger_get_property()
66 val->intval = POWER_SUPPLY_HEALTH_GOOD; in lt3651_charger_get_property()
73 if (!lt3651_charger->chrg_gpio) { in lt3651_charger_get_property()
74 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in lt3651_charger_get_property()
77 val->intval = gpiod_get_value(lt3651_charger->chrg_gpio) ? in lt3651_charger_get_property()
82 return -EINVAL; in lt3651_charger_get_property()
101 lt3651_charger = devm_kzalloc(&pdev->dev, sizeof(*lt3651_charger), in lt3651_charger_probe()
104 return -ENOMEM; in lt3651_charger_probe()
106 lt3651_charger->acpr_gpio = devm_gpiod_get(&pdev->dev, in lt3651_charger_probe()
108 if (IS_ERR(lt3651_charger->acpr_gpio)) { in lt3651_charger_probe()
109 ret = PTR_ERR(lt3651_charger->acpr_gpio); in lt3651_charger_probe()
110 dev_err(&pdev->dev, "Failed to acquire acpr GPIO: %d\n", ret); in lt3651_charger_probe()
113 lt3651_charger->fault_gpio = devm_gpiod_get_optional(&pdev->dev, in lt3651_charger_probe()
115 if (IS_ERR(lt3651_charger->fault_gpio)) { in lt3651_charger_probe()
116 ret = PTR_ERR(lt3651_charger->fault_gpio); in lt3651_charger_probe()
117 dev_err(&pdev->dev, "Failed to acquire fault GPIO: %d\n", ret); in lt3651_charger_probe()
120 lt3651_charger->chrg_gpio = devm_gpiod_get_optional(&pdev->dev, in lt3651_charger_probe()
122 if (IS_ERR(lt3651_charger->chrg_gpio)) { in lt3651_charger_probe()
123 ret = PTR_ERR(lt3651_charger->chrg_gpio); in lt3651_charger_probe()
124 dev_err(&pdev->dev, "Failed to acquire chrg GPIO: %d\n", ret); in lt3651_charger_probe()
128 charger_desc = &lt3651_charger->charger_desc; in lt3651_charger_probe()
129 charger_desc->name = pdev->dev.of_node->name; in lt3651_charger_probe()
130 charger_desc->type = POWER_SUPPLY_TYPE_MAINS; in lt3651_charger_probe()
131 charger_desc->properties = lt3651_charger_properties; in lt3651_charger_probe()
132 charger_desc->num_properties = ARRAY_SIZE(lt3651_charger_properties); in lt3651_charger_probe()
133 charger_desc->get_property = lt3651_charger_get_property; in lt3651_charger_probe()
134 psy_cfg.of_node = pdev->dev.of_node; in lt3651_charger_probe()
137 lt3651_charger->charger = devm_power_supply_register(&pdev->dev, in lt3651_charger_probe()
139 if (IS_ERR(lt3651_charger->charger)) { in lt3651_charger_probe()
140 ret = PTR_ERR(lt3651_charger->charger); in lt3651_charger_probe()
141 dev_err(&pdev->dev, "Failed to register power supply: %d\n", in lt3651_charger_probe()
147 * Acquire IRQs for the GPIO pins if possible. If the system does not in lt3651_charger_probe()
151 if (lt3651_charger->acpr_gpio) { in lt3651_charger_probe()
152 ret = gpiod_to_irq(lt3651_charger->acpr_gpio); in lt3651_charger_probe()
154 ret = devm_request_any_context_irq(&pdev->dev, ret, in lt3651_charger_probe()
157 dev_name(&pdev->dev), lt3651_charger->charger); in lt3651_charger_probe()
159 dev_warn(&pdev->dev, "Failed to request acpr irq\n"); in lt3651_charger_probe()
161 if (lt3651_charger->fault_gpio) { in lt3651_charger_probe()
162 ret = gpiod_to_irq(lt3651_charger->fault_gpio); in lt3651_charger_probe()
164 ret = devm_request_any_context_irq(&pdev->dev, ret, in lt3651_charger_probe()
167 dev_name(&pdev->dev), lt3651_charger->charger); in lt3651_charger_probe()
169 dev_warn(&pdev->dev, "Failed to request fault irq\n"); in lt3651_charger_probe()
171 if (lt3651_charger->chrg_gpio) { in lt3651_charger_probe()
172 ret = gpiod_to_irq(lt3651_charger->chrg_gpio); in lt3651_charger_probe()
174 ret = devm_request_any_context_irq(&pdev->dev, ret, in lt3651_charger_probe()
177 dev_name(&pdev->dev), lt3651_charger->charger); in lt3651_charger_probe()
179 dev_warn(&pdev->dev, "Failed to request chrg irq\n"); in lt3651_charger_probe()
188 { .compatible = "lltc,ltc3651-charger" }, /* DEPRECATED */
189 { .compatible = "lltc,lt3651-charger" },
197 .name = "lt3651-charger",
205 MODULE_DESCRIPTION("Driver for LT3651 charger");
207 MODULE_ALIAS("platform:lt3651-charger");