Lines Matching +full:bat +full:- +full:present

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Battery and Power Management code for the Sharp SL-5x00
21 #include <asm/mach-types.h>
35 bool (*is_present)(struct collie_bat *bat);
54 static unsigned long collie_read_bat(struct collie_bat *bat) in collie_read_bat() argument
58 if (!bat->gpio_bat || bat->adc_bat < 0) in collie_read_bat()
61 gpiod_set_value(bat->gpio_bat, 1); in collie_read_bat()
64 value = ucb1x00_adc_read(ucb, bat->adc_bat, UCB_SYNC); in collie_read_bat()
66 gpiod_set_value(bat->gpio_bat, 0); in collie_read_bat()
68 value = value * 1000000 / bat->adc_bat_divider; in collie_read_bat()
73 static unsigned long collie_read_temp(struct collie_bat *bat) in collie_read_temp() argument
76 if (!bat->gpio_temp || bat->adc_temp < 0) in collie_read_temp()
80 gpiod_set_value(bat->gpio_temp, 1); in collie_read_temp()
83 value = ucb1x00_adc_read(ucb, bat->adc_temp, UCB_SYNC); in collie_read_temp()
85 gpiod_set_value(bat->gpio_temp, 0); in collie_read_temp()
88 value = value * 10000 / bat->adc_temp_divider; in collie_read_temp()
98 struct collie_bat *bat = power_supply_get_drvdata(psy); in collie_bat_get_property() local
100 if (bat->is_present && !bat->is_present(bat) in collie_bat_get_property()
102 return -ENODEV; in collie_bat_get_property()
107 val->intval = bat->status; in collie_bat_get_property()
110 val->intval = bat->technology; in collie_bat_get_property()
113 val->intval = collie_read_bat(bat); in collie_bat_get_property()
116 if (bat->full_chrg == -1) in collie_bat_get_property()
117 val->intval = bat->bat_max; in collie_bat_get_property()
119 val->intval = bat->full_chrg; in collie_bat_get_property()
122 val->intval = bat->bat_max; in collie_bat_get_property()
125 val->intval = bat->bat_min; in collie_bat_get_property()
128 val->intval = collie_read_temp(bat); in collie_bat_get_property()
131 val->intval = bat->is_present ? bat->is_present(bat) : 1; in collie_bat_get_property()
134 ret = -EINVAL; in collie_bat_get_property()
152 static void collie_bat_update(struct collie_bat *bat) in collie_bat_update() argument
155 struct power_supply *psy = bat->psy; in collie_bat_update()
157 mutex_lock(&bat->work_lock); in collie_bat_update()
159 old = bat->status; in collie_bat_update()
161 if (bat->is_present && !bat->is_present(bat)) { in collie_bat_update()
162 printk(KERN_NOTICE "%s not present\n", psy->desc->name); in collie_bat_update()
163 bat->status = POWER_SUPPLY_STATUS_UNKNOWN; in collie_bat_update()
164 bat->full_chrg = -1; in collie_bat_update()
166 if (bat->status == POWER_SUPPLY_STATUS_DISCHARGING) { in collie_bat_update()
167 gpiod_set_value(bat->gpio_charge_on, 1); in collie_bat_update()
171 if (gpiod_get_value(bat->gpio_full)) { in collie_bat_update()
173 bat->full_chrg == -1) in collie_bat_update()
174 bat->full_chrg = collie_read_bat(bat); in collie_bat_update()
176 gpiod_set_value(bat->gpio_charge_on, 0); in collie_bat_update()
177 bat->status = POWER_SUPPLY_STATUS_FULL; in collie_bat_update()
179 gpiod_set_value(bat->gpio_charge_on, 1); in collie_bat_update()
180 bat->status = POWER_SUPPLY_STATUS_CHARGING; in collie_bat_update()
183 gpiod_set_value(bat->gpio_charge_on, 0); in collie_bat_update()
184 bat->status = POWER_SUPPLY_STATUS_DISCHARGING; in collie_bat_update()
187 if (old != bat->status) in collie_bat_update()
190 mutex_unlock(&bat->work_lock); in collie_bat_update()
221 .name = "main-battery",
232 .full_chrg = -1,
252 .name = "backup-battery",
262 .full_chrg = -1,
277 .adc_temp = -1,
278 .adc_temp_divider = -1,
292 if (device_may_wakeup(&dev->ucb->dev) && in collie_bat_suspend()
319 struct gpio_chip *gc = &dev->ucb->gpio; in collie_bat_probe()
322 return -ENODEV; in collie_bat_probe()
324 ucb = dev->ucb; in collie_bat_probe()
327 collie_bat_main.gpio_full = gpiod_get(&dev->ucb->dev, in collie_bat_probe()
333 collie_mbat_low = gpiod_get(&dev->ucb->dev, in collie_bat_probe()
341 collie_bat_main.gpio_charge_on = gpiod_get(&dev->ucb->dev, in collie_bat_probe()
390 collie_bat_main.psy = power_supply_register(&dev->ucb->dev, in collie_bat_probe()
399 collie_bat_bu.psy = power_supply_register(&dev->ucb->dev, in collie_bat_probe()
414 device_init_wakeup(&ucb->dev, 1); in collie_bat_probe()