Lines Matching +full:iio +full:- +full:consumer
1 // SPDX-License-Identifier: GPL-2.0
3 * Generic battery driver using IIO
10 #include <linux/gpio/consumer.h>
18 #include <linux/iio/consumer.h>
19 #include <linux/iio/types.h>
21 #include <linux/devm-helpers.h>
62 schedule_delayed_work(&adc_bat->bat_work, msecs_to_jiffies(0)); in gab_ext_power_changed()
71 * should correspond one-to-one with enum chan_type.
82 if (!adc_bat->charge_finished) in gab_charge_finished()
84 return gpiod_get_value(adc_bat->charge_finished); in gab_charge_finished()
92 ret = iio_read_channel_processed(adc_bat->channel[channel], result); in gab_read_channel()
94 dev_err(&adc_bat->psy->dev, "read channel error: %d\n", ret); in gab_read_channel()
108 val->intval = adc_bat->status; in gab_get_property()
111 return gab_read_channel(adc_bat, GAB_VOLTAGE, &val->intval); in gab_get_property()
113 return gab_read_channel(adc_bat, GAB_CURRENT, &val->intval); in gab_get_property()
115 return gab_read_channel(adc_bat, GAB_POWER, &val->intval); in gab_get_property()
117 return gab_read_channel(adc_bat, GAB_TEMP, &val->intval); in gab_get_property()
119 return -EINVAL; in gab_get_property()
131 status = adc_bat->status; in gab_work()
133 if (!power_supply_am_i_supplied(adc_bat->psy)) in gab_work()
134 adc_bat->status = POWER_SUPPLY_STATUS_DISCHARGING; in gab_work()
136 adc_bat->status = POWER_SUPPLY_STATUS_NOT_CHARGING; in gab_work()
138 adc_bat->status = POWER_SUPPLY_STATUS_CHARGING; in gab_work()
140 if (status != adc_bat->status) in gab_work()
141 power_supply_changed(adc_bat->psy); in gab_work()
148 schedule_delayed_work(&adc_bat->bat_work, in gab_charged()
165 adc_bat = devm_kzalloc(&pdev->dev, sizeof(*adc_bat), GFP_KERNEL); in gab_probe()
167 return -ENOMEM; in gab_probe()
169 psy_cfg.of_node = pdev->dev.of_node; in gab_probe()
171 psy_desc = &adc_bat->psy_desc; in gab_probe()
172 psy_desc->name = dev_name(&pdev->dev); in gab_probe()
175 adc_bat->status = POWER_SUPPLY_STATUS_DISCHARGING; in gab_probe()
176 psy_desc->type = POWER_SUPPLY_TYPE_BATTERY; in gab_probe()
177 psy_desc->get_property = gab_get_property; in gab_probe()
178 psy_desc->external_power_changed = gab_ext_power_changed; in gab_probe()
184 properties = devm_kcalloc(&pdev->dev, in gab_probe()
190 return -ENOMEM; in gab_probe()
195 * getting channel from iio and copying the battery properties in gab_probe()
196 * based on the channel supported by consumer device. in gab_probe()
199 adc_bat->channel[chan] = devm_iio_channel_get(&pdev->dev, gab_chan_name[chan]); in gab_probe()
200 if (IS_ERR(adc_bat->channel[chan])) { in gab_probe()
201 ret = PTR_ERR(adc_bat->channel[chan]); in gab_probe()
202 if (ret != -ENODEV) in gab_probe()
203 return dev_err_probe(&pdev->dev, ret, "Failed to get ADC channel %s\n", gab_chan_name[chan]); in gab_probe()
204 adc_bat->channel[chan] = NULL; in gab_probe()
205 } else if (adc_bat->channel[chan]) { in gab_probe()
221 return dev_err_probe(&pdev->dev, -ENODEV, "Failed to get any ADC channel\n"); in gab_probe()
229 psy_desc->properties = properties; in gab_probe()
230 psy_desc->num_properties = index; in gab_probe()
232 adc_bat->psy = devm_power_supply_register(&pdev->dev, psy_desc, &psy_cfg); in gab_probe()
233 if (IS_ERR(adc_bat->psy)) in gab_probe()
234 …return dev_err_probe(&pdev->dev, PTR_ERR(adc_bat->psy), "Failed to register power-supply device\n"… in gab_probe()
236 ret = devm_delayed_work_autocancel(&pdev->dev, &adc_bat->bat_work, gab_work); in gab_probe()
238 return dev_err_probe(&pdev->dev, ret, "Failed to register delayed work\n"); in gab_probe()
240 adc_bat->charge_finished = devm_gpiod_get_optional(&pdev->dev, "charged", GPIOD_IN); in gab_probe()
241 if (adc_bat->charge_finished) { in gab_probe()
244 irq = gpiod_to_irq(adc_bat->charge_finished); in gab_probe()
245 ret = devm_request_any_context_irq(&pdev->dev, irq, gab_charged, in gab_probe()
249 return dev_err_probe(&pdev->dev, ret, "Failed to register irq\n"); in gab_probe()
255 schedule_delayed_work(&adc_bat->bat_work, in gab_probe()
264 cancel_delayed_work_sync(&adc_bat->bat_work); in gab_suspend()
265 adc_bat->status = POWER_SUPPLY_STATUS_UNKNOWN; in gab_suspend()
274 schedule_delayed_work(&adc_bat->bat_work, in gab_resume()
283 { .compatible = "adc-battery" },
290 .name = "generic-adc-battery",
299 MODULE_DESCRIPTION("generic battery driver using IIO");