Lines Matching +full:battery +full:- +full:detect +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Battery and Power Management code for the Sharp SL-6000x
17 #include <asm/mach-types.h>
54 if (!bat->gpiod_bat || bat->adc_bat < 0) in tosa_read_bat()
58 gpiod_set_value(bat->gpiod_bat, 1); in tosa_read_bat()
60 value = wm97xx_read_aux_adc(dev_get_drvdata(bat->psy->dev.parent), in tosa_read_bat()
61 bat->adc_bat); in tosa_read_bat()
62 gpiod_set_value(bat->gpiod_bat, 0); in tosa_read_bat()
65 value = value * 1000000 / bat->adc_bat_divider; in tosa_read_bat()
74 if (!bat->gpiod_temp || bat->adc_temp < 0) in tosa_read_temp()
78 gpiod_set_value(bat->gpiod_temp, 1); in tosa_read_temp()
80 value = wm97xx_read_aux_adc(dev_get_drvdata(bat->psy->dev.parent), in tosa_read_temp()
81 bat->adc_temp); in tosa_read_temp()
82 gpiod_set_value(bat->gpiod_temp, 0); in tosa_read_temp()
85 value = value * 10000 / bat->adc_temp_divider; in tosa_read_temp()
97 if (bat->is_present && !bat->is_present(bat) in tosa_bat_get_property()
99 return -ENODEV; in tosa_bat_get_property()
104 val->intval = bat->status; in tosa_bat_get_property()
107 val->intval = bat->technology; in tosa_bat_get_property()
110 val->intval = tosa_read_bat(bat); in tosa_bat_get_property()
113 if (bat->full_chrg == -1) in tosa_bat_get_property()
114 val->intval = bat->bat_max; in tosa_bat_get_property()
116 val->intval = bat->full_chrg; in tosa_bat_get_property()
119 val->intval = bat->bat_max; in tosa_bat_get_property()
122 val->intval = bat->bat_min; in tosa_bat_get_property()
125 val->intval = tosa_read_temp(bat); in tosa_bat_get_property()
128 val->intval = bat->is_present ? bat->is_present(bat) : 1; in tosa_bat_get_property()
131 ret = -EINVAL; in tosa_bat_get_property()
157 struct power_supply *psy = bat->psy; in tosa_bat_update()
159 mutex_lock(&bat->work_lock); in tosa_bat_update()
161 old = bat->status; in tosa_bat_update()
163 if (bat->is_present && !bat->is_present(bat)) { in tosa_bat_update()
164 printk(KERN_NOTICE "%s not present\n", psy->desc->name); in tosa_bat_update()
165 bat->status = POWER_SUPPLY_STATUS_UNKNOWN; in tosa_bat_update()
166 bat->full_chrg = -1; in tosa_bat_update()
168 if (bat->status == POWER_SUPPLY_STATUS_DISCHARGING) { in tosa_bat_update()
169 gpiod_set_value(bat->gpiod_charge_off, 0); in tosa_bat_update()
173 if (gpiod_get_value(bat->gpiod_full)) { in tosa_bat_update()
175 bat->full_chrg == -1) in tosa_bat_update()
176 bat->full_chrg = tosa_read_bat(bat); in tosa_bat_update()
178 gpiod_set_value(bat->gpiod_charge_off, 1); in tosa_bat_update()
179 bat->status = POWER_SUPPLY_STATUS_FULL; in tosa_bat_update()
181 gpiod_set_value(bat->gpiod_charge_off, 0); in tosa_bat_update()
182 bat->status = POWER_SUPPLY_STATUS_CHARGING; in tosa_bat_update()
185 gpiod_set_value(bat->gpiod_charge_off, 1); in tosa_bat_update()
186 bat->status = POWER_SUPPLY_STATUS_DISCHARGING; in tosa_bat_update()
189 if (old != bat->status) in tosa_bat_update()
192 mutex_unlock(&bat->work_lock); in tosa_bat_update()
222 .name = "main-battery",
232 .name = "jacket-battery",
241 .name = "backup-battery",
251 .full_chrg = -1,
272 .full_chrg = -1,
294 .full_chrg = -1,
307 .adc_temp = -1,
308 .adc_temp_divider = -1,
336 struct device *dev = &pdev->dev; in tosa_bat_probe()
340 return -ENODEV; in tosa_bat_probe()
342 /* Main charging control GPIOs */ in tosa_bat_probe()
352 /* Per-battery output check (routes battery voltage to ADC) */ in tosa_bat_probe()
353 tosa_bat_main.gpiod_bat = devm_gpiod_get(dev, "main battery", GPIOD_OUT_LOW); in tosa_bat_probe()
356 "no main battery GPIO\n"); in tosa_bat_probe()
357 tosa_bat_jacket.gpiod_bat = devm_gpiod_get(dev, "jacket battery", GPIOD_OUT_LOW); in tosa_bat_probe()
360 "no jacket battery GPIO\n"); in tosa_bat_probe()
361 tosa_bat_bu.gpiod_bat = devm_gpiod_get(dev, "backup battery", GPIOD_OUT_LOW); in tosa_bat_probe()
364 "no backup battery GPIO\n"); in tosa_bat_probe()
366 /* Battery full detect GPIOs (using PXA SoC GPIOs) */ in tosa_bat_probe()
367 tosa_bat_main.gpiod_full = devm_gpiod_get(dev, "main battery full", GPIOD_IN); in tosa_bat_probe()
370 "no main battery full GPIO\n"); in tosa_bat_probe()
371 tosa_bat_jacket.gpiod_full = devm_gpiod_get(dev, "jacket battery full", GPIOD_IN); in tosa_bat_probe()
374 "no jacket battery full GPIO\n"); in tosa_bat_probe()
376 /* Battery temperature GPIOs (routes thermistor voltage to ADC) */ in tosa_bat_probe()
377 tosa_bat_main.gpiod_temp = devm_gpiod_get(dev, "main battery temp", GPIOD_OUT_LOW); in tosa_bat_probe()
380 "no main battery temp GPIO\n"); in tosa_bat_probe()
381 tosa_bat_jacket.gpiod_temp = devm_gpiod_get(dev, "jacket battery temp", GPIOD_OUT_LOW); in tosa_bat_probe()
384 "no jacket battery temp GPIO\n"); in tosa_bat_probe()
386 /* Jacket detect GPIO */ in tosa_bat_probe()
387 jacket_detect = devm_gpiod_get(dev, "jacket detect", GPIOD_IN); in tosa_bat_probe()
390 "no jacket detect GPIO\n"); in tosa_bat_probe()
392 /* Battery low indication GPIOs (not used, we just request them) */ in tosa_bat_probe()
393 dummy = devm_gpiod_get(dev, "main battery low", GPIOD_IN); in tosa_bat_probe()
396 "no main battery low GPIO\n"); in tosa_bat_probe()
397 dummy = devm_gpiod_get(dev, "jacket battery low", GPIOD_IN); in tosa_bat_probe()
400 "no jacket battery low GPIO\n"); in tosa_bat_probe()
402 /* Battery switch GPIO (not used just requested) */ in tosa_bat_probe()
403 dummy = devm_gpiod_get(dev, "battery switch", GPIOD_OUT_LOW); in tosa_bat_probe()
406 "no battery switch GPIO\n"); in tosa_bat_probe()
456 "jacket detect", &tosa_bat_jacket); in tosa_bat_probe()
499 .driver.name = "wm97xx-battery",
511 MODULE_DESCRIPTION("Tosa battery driver");
512 MODULE_ALIAS("platform:wm97xx-battery");