Lines Matching +full:jz4740 +full:- +full:battery

1 // SPDX-License-Identifier: GPL-2.0
3 * Battery driver for the Ingenic JZ47xx SoCs
4 * Copyright (c) 2019 Artur Rojek <contact@artur-rojek.eu>
6 * based on drivers/power/supply/jz4740-battery.c
20 struct power_supply *battery; member
29 struct power_supply_battery_info *info = bat->info; in ingenic_battery_get_property()
34 ret = iio_read_channel_processed_scale(bat->channel, in ingenic_battery_get_property()
35 &val->intval, in ingenic_battery_get_property()
37 if (val->intval < info->voltage_min_design_uv) in ingenic_battery_get_property()
38 val->intval = POWER_SUPPLY_HEALTH_DEAD; in ingenic_battery_get_property()
39 else if (val->intval > info->voltage_max_design_uv) in ingenic_battery_get_property()
40 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in ingenic_battery_get_property()
42 val->intval = POWER_SUPPLY_HEALTH_GOOD; in ingenic_battery_get_property()
45 ret = iio_read_channel_processed_scale(bat->channel, in ingenic_battery_get_property()
46 &val->intval, in ingenic_battery_get_property()
50 val->intval = info->voltage_min_design_uv; in ingenic_battery_get_property()
53 val->intval = info->voltage_max_design_uv; in ingenic_battery_get_property()
56 return -EINVAL; in ingenic_battery_get_property()
61 * based on the battery's max voltage.
66 int scale_len, scale_type, best_idx = -1, best_mV, max_raw, i, ret; in ingenic_battery_set_scale()
69 ret = iio_read_max_channel_raw(bat->channel, &max_raw); in ingenic_battery_set_scale()
71 dev_err(bat->dev, "Unable to read max raw channel value\n"); in ingenic_battery_set_scale()
75 ret = iio_read_avail_channel_attribute(bat->channel, &scale_raw, in ingenic_battery_set_scale()
79 dev_err(bat->dev, "Unable to read channel avail scale\n"); in ingenic_battery_set_scale()
83 return -EINVAL; in ingenic_battery_set_scale()
85 max_mV = bat->info->voltage_max_design_uv / 1000; in ingenic_battery_set_scale()
101 dev_err(bat->dev, "Unable to find matching voltage scale\n"); in ingenic_battery_set_scale()
102 return -EINVAL; in ingenic_battery_set_scale()
107 ret = iio_write_channel_attribute(bat->channel, in ingenic_battery_set_scale()
127 struct device *dev = &pdev->dev; in ingenic_battery_probe()
135 return -ENOMEM; in ingenic_battery_probe()
137 bat->dev = dev; in ingenic_battery_probe()
138 bat->channel = devm_iio_channel_get(dev, "battery"); in ingenic_battery_probe()
139 if (IS_ERR(bat->channel)) in ingenic_battery_probe()
140 return PTR_ERR(bat->channel); in ingenic_battery_probe()
142 desc = &bat->desc; in ingenic_battery_probe()
143 desc->name = "jz-battery"; in ingenic_battery_probe()
144 desc->type = POWER_SUPPLY_TYPE_BATTERY; in ingenic_battery_probe()
145 desc->properties = ingenic_battery_properties; in ingenic_battery_probe()
146 desc->num_properties = ARRAY_SIZE(ingenic_battery_properties); in ingenic_battery_probe()
147 desc->get_property = ingenic_battery_get_property; in ingenic_battery_probe()
149 psy_cfg.of_node = dev->of_node; in ingenic_battery_probe()
151 bat->battery = devm_power_supply_register(dev, desc, &psy_cfg); in ingenic_battery_probe()
152 if (IS_ERR(bat->battery)) in ingenic_battery_probe()
153 return dev_err_probe(dev, PTR_ERR(bat->battery), in ingenic_battery_probe()
154 "Unable to register battery\n"); in ingenic_battery_probe()
156 ret = power_supply_get_battery_info(bat->battery, &bat->info); in ingenic_battery_probe()
158 dev_err(dev, "Unable to get battery info: %d\n", ret); in ingenic_battery_probe()
161 if (bat->info->voltage_min_design_uv < 0) { in ingenic_battery_probe()
163 return bat->info->voltage_min_design_uv; in ingenic_battery_probe()
165 if (bat->info->voltage_max_design_uv < 0) { in ingenic_battery_probe()
167 return bat->info->voltage_max_design_uv; in ingenic_battery_probe()
175 { .compatible = "ingenic,jz4740-battery", },
183 .name = "ingenic-battery",
190 MODULE_DESCRIPTION("Battery driver for Ingenic JZ47xx SoCs");
191 MODULE_AUTHOR("Artur Rojek <contact@artur-rojek.eu>");