Lines Matching +full:usb +full:- +full:sdp

1 // SPDX-License-Identifier: GPL-2.0+
3 // max8997_charger.c - Power supply consumer driver for the Maxim 8997/8966
15 #include <linux/mfd/max8997-private.h>
17 #include <linux/devm-helpers.h>
55 struct i2c_client *i2c = charger->iodev->i2c; in max8997_battery_get_property()
61 val->intval = 0; in max8997_battery_get_property()
66 val->intval = POWER_SUPPLY_STATUS_FULL; in max8997_battery_get_property()
68 val->intval = POWER_SUPPLY_STATUS_CHARGING; in max8997_battery_get_property()
70 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in max8997_battery_get_property()
74 val->intval = 0; in max8997_battery_get_property()
79 val->intval = 1; in max8997_battery_get_property()
83 val->intval = 0; in max8997_battery_get_property()
88 val->intval = 1; in max8997_battery_get_property()
92 return -EINVAL; in max8997_battery_get_property()
102 struct extcon_dev *edev = charger->edev; in max8997_battery_extcon_evt_worker()
106 dev_dbg(charger->dev, "USB SDP charger is connected\n"); in max8997_battery_extcon_evt_worker()
109 dev_dbg(charger->dev, "USB DCP charger is connected\n"); in max8997_battery_extcon_evt_worker()
112 dev_dbg(charger->dev, "USB FAST charger is connected\n"); in max8997_battery_extcon_evt_worker()
115 dev_dbg(charger->dev, "USB SLOW charger is connected\n"); in max8997_battery_extcon_evt_worker()
118 dev_dbg(charger->dev, "USB CDP charger is connected\n"); in max8997_battery_extcon_evt_worker()
121 dev_dbg(charger->dev, "USB charger is disconnected\n"); in max8997_battery_extcon_evt_worker()
122 current_limit = -1; in max8997_battery_extcon_evt_worker()
126 int ret = regulator_set_current_limit(charger->reg, current_limit, current_limit); in max8997_battery_extcon_evt_worker()
129 dev_err(charger->dev, "failed to set current limit: %d\n", ret); in max8997_battery_extcon_evt_worker()
132 ret = regulator_enable(charger->reg); in max8997_battery_extcon_evt_worker()
134 dev_err(charger->dev, "failed to enable regulator: %d\n", ret); in max8997_battery_extcon_evt_worker()
136 int ret = regulator_disable(charger->reg); in max8997_battery_extcon_evt_worker()
139 dev_err(charger->dev, "failed to disable regulator: %d\n", ret); in max8997_battery_extcon_evt_worker()
148 schedule_work(&charger->extcon_work); in max8997_battery_extcon_evt()
164 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); in max8997_battery_probe()
165 struct device_node *np = pdev->dev.of_node; in max8997_battery_probe()
166 struct i2c_client *i2c = iodev->i2c; in max8997_battery_probe()
167 struct max8997_platform_data *pdata = iodev->pdata; in max8997_battery_probe()
171 dev_err(&pdev->dev, "No platform data supplied.\n"); in max8997_battery_probe()
172 return -EINVAL; in max8997_battery_probe()
175 if (pdata->eoc_mA) { in max8997_battery_probe()
176 int val = (pdata->eoc_mA - 50) / 10; in max8997_battery_probe()
185 dev_err(&pdev->dev, "Cannot use i2c bus.\n"); in max8997_battery_probe()
189 switch (pdata->timeout) { in max8997_battery_probe()
207 dev_err(&pdev->dev, "incorrect timeout value (%d)\n", in max8997_battery_probe()
208 pdata->timeout); in max8997_battery_probe()
209 return -EINVAL; in max8997_battery_probe()
212 dev_err(&pdev->dev, "Cannot use i2c bus.\n"); in max8997_battery_probe()
216 charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); in max8997_battery_probe()
218 return -ENOMEM; in max8997_battery_probe()
222 charger->dev = &pdev->dev; in max8997_battery_probe()
223 charger->iodev = iodev; in max8997_battery_probe()
227 charger->battery = devm_power_supply_register(&pdev->dev, in max8997_battery_probe()
230 if (IS_ERR(charger->battery)) { in max8997_battery_probe()
231 dev_err(&pdev->dev, "failed: power supply register\n"); in max8997_battery_probe()
232 return PTR_ERR(charger->battery); in max8997_battery_probe()
236 pdev->dev.of_node = iodev->dev->of_node; in max8997_battery_probe()
237 charger->reg = devm_regulator_get_optional(&pdev->dev, "charger"); in max8997_battery_probe()
238 pdev->dev.of_node = np; in max8997_battery_probe()
239 if (IS_ERR(charger->reg)) { in max8997_battery_probe()
240 if (PTR_ERR(charger->reg) == -EPROBE_DEFER) in max8997_battery_probe()
241 return -EPROBE_DEFER; in max8997_battery_probe()
242 dev_info(&pdev->dev, "couldn't get charger regulator\n"); in max8997_battery_probe()
244 charger->edev = extcon_get_extcon_dev("max8997-muic"); in max8997_battery_probe()
245 if (IS_ERR(charger->edev)) { in max8997_battery_probe()
246 dev_err_probe(charger->dev, PTR_ERR(charger->edev), in max8997_battery_probe()
247 "couldn't get extcon device: max8997-muic\n"); in max8997_battery_probe()
248 return PTR_ERR(charger->edev); in max8997_battery_probe()
251 if (!IS_ERR(charger->reg) && !IS_ERR_OR_NULL(charger->edev)) { in max8997_battery_probe()
252 ret = devm_work_autocancel(&pdev->dev, &charger->extcon_work, in max8997_battery_probe()
255 dev_err(&pdev->dev, "failed to add extcon evt stop action: %d\n", ret); in max8997_battery_probe()
258 charger->extcon_nb.notifier_call = max8997_battery_extcon_evt; in max8997_battery_probe()
259 ret = devm_extcon_register_notifier_all(&pdev->dev, charger->edev, in max8997_battery_probe()
260 &charger->extcon_nb); in max8997_battery_probe()
262 dev_err(&pdev->dev, "failed to register extcon notifier\n"); in max8997_battery_probe()
271 { "max8997-battery", 0 },
278 .name = "max8997-battery",