Lines Matching +full:sbs +full:- +full:battery

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * This adds support for sbs-charger compilant chips as defined here:
6 * http://sbs-forum.org/specs/sbc110.pdf
8 * Implemetation based on sbs-battery.c
21 #include <linux/devm-helpers.h>
50 reg = chip->last_state; in sbs_get_property()
54 val->intval = !!(reg & SBS_CHARGER_STATUS_BATTERY_PRESENT); in sbs_get_property()
58 val->intval = !!(reg & SBS_CHARGER_STATUS_AC_PRESENT); in sbs_get_property()
62 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in sbs_get_property()
65 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in sbs_get_property()
68 val->intval = POWER_SUPPLY_STATUS_CHARGING; in sbs_get_property()
70 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in sbs_get_property()
76 val->intval = POWER_SUPPLY_HEALTH_COLD; in sbs_get_property()
78 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; in sbs_get_property()
80 val->intval = POWER_SUPPLY_HEALTH_GOOD; in sbs_get_property()
85 return -EINVAL; in sbs_get_property()
96 ret = regmap_read(chip->regmap, SBS_CHARGER_REG_STATUS, &reg); in sbs_check_state()
97 if (!ret && reg != chip->last_state) { in sbs_check_state()
98 chip->last_state = reg; in sbs_check_state()
99 power_supply_changed(chip->power_supply); in sbs_check_state()
112 schedule_delayed_work(&chip->work, in sbs_delayed_work()
158 .name = "sbs-charger",
171 chip = devm_kzalloc(&client->dev, sizeof(struct sbs_info), GFP_KERNEL); in sbs_probe()
173 return -ENOMEM; in sbs_probe()
175 chip->client = client; in sbs_probe()
176 psy_cfg.of_node = client->dev.of_node; in sbs_probe()
181 chip->regmap = devm_regmap_init_i2c(client, &sbs_regmap); in sbs_probe()
182 if (IS_ERR(chip->regmap)) in sbs_probe()
183 return PTR_ERR(chip->regmap); in sbs_probe()
187 * to the battery. in sbs_probe()
189 ret = regmap_read(chip->regmap, SBS_CHARGER_REG_STATUS, &val); in sbs_probe()
191 return dev_err_probe(&client->dev, ret, "Failed to get device status\n"); in sbs_probe()
192 chip->last_state = val; in sbs_probe()
194 chip->power_supply = devm_power_supply_register(&client->dev, &sbs_desc, &psy_cfg); in sbs_probe()
195 if (IS_ERR(chip->power_supply)) in sbs_probe()
196 return dev_err_probe(&client->dev, PTR_ERR(chip->power_supply), in sbs_probe()
200 * The sbs-charger spec doesn't impose the use of an interrupt. So in in sbs_probe()
204 if (client->irq) { in sbs_probe()
205 ret = devm_request_threaded_irq(&client->dev, client->irq, in sbs_probe()
208 dev_name(&client->dev), chip); in sbs_probe()
210 return dev_err_probe(&client->dev, ret, "Failed to request irq\n"); in sbs_probe()
212 ret = devm_delayed_work_autocancel(&client->dev, &chip->work, in sbs_probe()
215 return dev_err_probe(&client->dev, ret, in sbs_probe()
218 schedule_delayed_work(&chip->work, in sbs_probe()
222 dev_info(&client->dev, in sbs_probe()
223 "%s: smart charger device registered\n", client->name); in sbs_probe()
230 { .compatible = "sbs,sbs-charger" },
237 { "sbs-charger" },
246 .name = "sbs-charger",
253 MODULE_DESCRIPTION("SBS smart charger driver");