^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Battery and Power Management code for the Sharp SL-6000x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2005 Dirk Opfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2008 Dmitry Baryshkov
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/power_supply.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/wm97xx.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/mach-types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <mach/tosa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static DEFINE_MUTEX(bat_lock); /* protects gpio pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static struct work_struct bat_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct tosa_bat {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct power_supply *psy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) int full_chrg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct mutex work_lock; /* protects data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) bool (*is_present)(struct tosa_bat *bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int gpio_full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) int gpio_charge_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int technology;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int gpio_bat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int adc_bat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int adc_bat_divider;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int bat_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int bat_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int gpio_temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int adc_temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int adc_temp_divider;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static struct tosa_bat tosa_bat_main;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static struct tosa_bat tosa_bat_jacket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static unsigned long tosa_read_bat(struct tosa_bat *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned long value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (bat->gpio_bat < 0 || bat->adc_bat < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) mutex_lock(&bat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) gpio_set_value(bat->gpio_bat, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) msleep(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) value = wm97xx_read_aux_adc(dev_get_drvdata(bat->psy->dev.parent),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) bat->adc_bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) gpio_set_value(bat->gpio_bat, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) mutex_unlock(&bat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) value = value * 1000000 / bat->adc_bat_divider;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static unsigned long tosa_read_temp(struct tosa_bat *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) unsigned long value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (bat->gpio_temp < 0 || bat->adc_temp < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) mutex_lock(&bat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) gpio_set_value(bat->gpio_temp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) msleep(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) value = wm97xx_read_aux_adc(dev_get_drvdata(bat->psy->dev.parent),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) bat->adc_temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) gpio_set_value(bat->gpio_temp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) mutex_unlock(&bat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) value = value * 10000 / bat->adc_temp_divider;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static int tosa_bat_get_property(struct power_supply *psy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) enum power_supply_property psp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) union power_supply_propval *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct tosa_bat *bat = power_supply_get_drvdata(psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (bat->is_present && !bat->is_present(bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) && psp != POWER_SUPPLY_PROP_PRESENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) switch (psp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) case POWER_SUPPLY_PROP_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) val->intval = bat->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) case POWER_SUPPLY_PROP_TECHNOLOGY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) val->intval = bat->technology;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) case POWER_SUPPLY_PROP_VOLTAGE_NOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) val->intval = tosa_read_bat(bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) case POWER_SUPPLY_PROP_VOLTAGE_MAX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (bat->full_chrg == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) val->intval = bat->bat_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) val->intval = bat->full_chrg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) val->intval = bat->bat_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) val->intval = bat->bat_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) case POWER_SUPPLY_PROP_TEMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) val->intval = tosa_read_temp(bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) case POWER_SUPPLY_PROP_PRESENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) val->intval = bat->is_present ? bat->is_present(bat) : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static bool tosa_jacket_bat_is_present(struct tosa_bat *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return gpio_get_value(TOSA_GPIO_JACKET_DETECT) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static void tosa_bat_external_power_changed(struct power_supply *psy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) schedule_work(&bat_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static irqreturn_t tosa_bat_gpio_isr(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) pr_info("tosa_bat_gpio irq\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) schedule_work(&bat_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static void tosa_bat_update(struct tosa_bat *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct power_supply *psy = bat->psy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) mutex_lock(&bat->work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) old = bat->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (bat->is_present && !bat->is_present(bat)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) printk(KERN_NOTICE "%s not present\n", psy->desc->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) bat->status = POWER_SUPPLY_STATUS_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) bat->full_chrg = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) } else if (power_supply_am_i_supplied(psy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (bat->status == POWER_SUPPLY_STATUS_DISCHARGING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) gpio_set_value(bat->gpio_charge_off, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) mdelay(15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (gpio_get_value(bat->gpio_full)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (old == POWER_SUPPLY_STATUS_CHARGING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) bat->full_chrg == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) bat->full_chrg = tosa_read_bat(bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) gpio_set_value(bat->gpio_charge_off, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) bat->status = POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) gpio_set_value(bat->gpio_charge_off, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) bat->status = POWER_SUPPLY_STATUS_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) gpio_set_value(bat->gpio_charge_off, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (old != bat->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) power_supply_changed(psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) mutex_unlock(&bat->work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static void tosa_bat_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) tosa_bat_update(&tosa_bat_main);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) tosa_bat_update(&tosa_bat_jacket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static enum power_supply_property tosa_bat_main_props[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) POWER_SUPPLY_PROP_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) POWER_SUPPLY_PROP_TECHNOLOGY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) POWER_SUPPLY_PROP_VOLTAGE_NOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) POWER_SUPPLY_PROP_VOLTAGE_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) POWER_SUPPLY_PROP_TEMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) POWER_SUPPLY_PROP_PRESENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static enum power_supply_property tosa_bat_bu_props[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) POWER_SUPPLY_PROP_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) POWER_SUPPLY_PROP_TECHNOLOGY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) POWER_SUPPLY_PROP_VOLTAGE_NOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) POWER_SUPPLY_PROP_PRESENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static const struct power_supply_desc tosa_bat_main_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) .name = "main-battery",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) .type = POWER_SUPPLY_TYPE_BATTERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) .properties = tosa_bat_main_props,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) .num_properties = ARRAY_SIZE(tosa_bat_main_props),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) .get_property = tosa_bat_get_property,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) .external_power_changed = tosa_bat_external_power_changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .use_for_apm = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static const struct power_supply_desc tosa_bat_jacket_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) .name = "jacket-battery",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .type = POWER_SUPPLY_TYPE_BATTERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .properties = tosa_bat_main_props,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) .num_properties = ARRAY_SIZE(tosa_bat_main_props),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) .get_property = tosa_bat_get_property,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .external_power_changed = tosa_bat_external_power_changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static const struct power_supply_desc tosa_bat_bu_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) .name = "backup-battery",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .type = POWER_SUPPLY_TYPE_BATTERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .properties = tosa_bat_bu_props,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .num_properties = ARRAY_SIZE(tosa_bat_bu_props),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .get_property = tosa_bat_get_property,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .external_power_changed = tosa_bat_external_power_changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static struct tosa_bat tosa_bat_main = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .status = POWER_SUPPLY_STATUS_DISCHARGING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .full_chrg = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) .psy = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) .gpio_full = TOSA_GPIO_BAT0_CRG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .gpio_charge_off = TOSA_GPIO_CHARGE_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) .gpio_bat = TOSA_GPIO_BAT0_V_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .adc_bat = WM97XX_AUX_ID3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) .adc_bat_divider = 414,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) .bat_max = 4310000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) .bat_min = 1551 * 1000000 / 414,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .gpio_temp = TOSA_GPIO_BAT1_TH_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .adc_temp = WM97XX_AUX_ID2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .adc_temp_divider = 10000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static struct tosa_bat tosa_bat_jacket = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .status = POWER_SUPPLY_STATUS_DISCHARGING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) .full_chrg = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) .psy = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) .is_present = tosa_jacket_bat_is_present,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) .gpio_full = TOSA_GPIO_BAT1_CRG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) .gpio_charge_off = TOSA_GPIO_CHARGE_OFF_JC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) .gpio_bat = TOSA_GPIO_BAT1_V_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) .adc_bat = WM97XX_AUX_ID3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) .adc_bat_divider = 414,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) .bat_max = 4310000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) .bat_min = 1551 * 1000000 / 414,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) .gpio_temp = TOSA_GPIO_BAT0_TH_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) .adc_temp = WM97XX_AUX_ID2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) .adc_temp_divider = 10000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static struct tosa_bat tosa_bat_bu = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .status = POWER_SUPPLY_STATUS_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) .full_chrg = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) .psy = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) .gpio_full = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) .gpio_charge_off = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) .technology = POWER_SUPPLY_TECHNOLOGY_LiMn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) .gpio_bat = TOSA_GPIO_BU_CHRG_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) .adc_bat = WM97XX_AUX_ID4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) .adc_bat_divider = 1266,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) .gpio_temp = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) .adc_temp = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) .adc_temp_divider = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static struct gpio tosa_bat_gpios[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) { TOSA_GPIO_CHARGE_OFF, GPIOF_OUT_INIT_HIGH, "main charge off" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) { TOSA_GPIO_CHARGE_OFF_JC, GPIOF_OUT_INIT_HIGH, "jacket charge off" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) { TOSA_GPIO_BAT_SW_ON, GPIOF_OUT_INIT_LOW, "battery switch" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) { TOSA_GPIO_BAT0_V_ON, GPIOF_OUT_INIT_LOW, "main battery" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) { TOSA_GPIO_BAT1_V_ON, GPIOF_OUT_INIT_LOW, "jacket battery" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) { TOSA_GPIO_BAT1_TH_ON, GPIOF_OUT_INIT_LOW, "main battery temp" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) { TOSA_GPIO_BAT0_TH_ON, GPIOF_OUT_INIT_LOW, "jacket battery temp" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) { TOSA_GPIO_BU_CHRG_ON, GPIOF_OUT_INIT_LOW, "backup battery" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) { TOSA_GPIO_BAT0_CRG, GPIOF_IN, "main battery full" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) { TOSA_GPIO_BAT1_CRG, GPIOF_IN, "jacket battery full" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) { TOSA_GPIO_BAT0_LOW, GPIOF_IN, "main battery low" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) { TOSA_GPIO_BAT1_LOW, GPIOF_IN, "jacket battery low" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) { TOSA_GPIO_JACKET_DETECT, GPIOF_IN, "jacket detect" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static int tosa_bat_suspend(struct platform_device *dev, pm_message_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* flush all pending status updates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) flush_work(&bat_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static int tosa_bat_resume(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /* things may have changed while we were away */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) schedule_work(&bat_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) #define tosa_bat_suspend NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) #define tosa_bat_resume NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static int tosa_bat_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct power_supply_config main_psy_cfg = {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) jacket_psy_cfg = {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) bu_psy_cfg = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (!machine_is_tosa())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) ret = gpio_request_array(tosa_bat_gpios, ARRAY_SIZE(tosa_bat_gpios));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) mutex_init(&tosa_bat_main.work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) mutex_init(&tosa_bat_jacket.work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) INIT_WORK(&bat_work, tosa_bat_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) main_psy_cfg.drv_data = &tosa_bat_main;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) tosa_bat_main.psy = power_supply_register(&dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) &tosa_bat_main_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) &main_psy_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (IS_ERR(tosa_bat_main.psy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) ret = PTR_ERR(tosa_bat_main.psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) goto err_psy_reg_main;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) jacket_psy_cfg.drv_data = &tosa_bat_jacket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) tosa_bat_jacket.psy = power_supply_register(&dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) &tosa_bat_jacket_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) &jacket_psy_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (IS_ERR(tosa_bat_jacket.psy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) ret = PTR_ERR(tosa_bat_jacket.psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) goto err_psy_reg_jacket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) bu_psy_cfg.drv_data = &tosa_bat_bu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) tosa_bat_bu.psy = power_supply_register(&dev->dev, &tosa_bat_bu_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) &bu_psy_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (IS_ERR(tosa_bat_bu.psy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) ret = PTR_ERR(tosa_bat_bu.psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) goto err_psy_reg_bu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) ret = request_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) tosa_bat_gpio_isr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) "main full", &tosa_bat_main);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) goto err_req_main;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) ret = request_irq(gpio_to_irq(TOSA_GPIO_BAT1_CRG),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) tosa_bat_gpio_isr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) "jacket full", &tosa_bat_jacket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) goto err_req_jacket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) ret = request_irq(gpio_to_irq(TOSA_GPIO_JACKET_DETECT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) tosa_bat_gpio_isr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) "jacket detect", &tosa_bat_jacket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) schedule_work(&bat_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) free_irq(gpio_to_irq(TOSA_GPIO_BAT1_CRG), &tosa_bat_jacket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) err_req_jacket:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) free_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG), &tosa_bat_main);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) err_req_main:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) power_supply_unregister(tosa_bat_bu.psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) err_psy_reg_bu:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) power_supply_unregister(tosa_bat_jacket.psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) err_psy_reg_jacket:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) power_supply_unregister(tosa_bat_main.psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) err_psy_reg_main:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) /* see comment in tosa_bat_remove */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) cancel_work_sync(&bat_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) gpio_free_array(tosa_bat_gpios, ARRAY_SIZE(tosa_bat_gpios));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static int tosa_bat_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) free_irq(gpio_to_irq(TOSA_GPIO_JACKET_DETECT), &tosa_bat_jacket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) free_irq(gpio_to_irq(TOSA_GPIO_BAT1_CRG), &tosa_bat_jacket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) free_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG), &tosa_bat_main);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) power_supply_unregister(tosa_bat_bu.psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) power_supply_unregister(tosa_bat_jacket.psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) power_supply_unregister(tosa_bat_main.psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * Now cancel the bat_work. We won't get any more schedules,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) * since all sources (isr and external_power_changed) are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) * unregistered now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) cancel_work_sync(&bat_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) gpio_free_array(tosa_bat_gpios, ARRAY_SIZE(tosa_bat_gpios));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static struct platform_driver tosa_bat_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) .driver.name = "wm97xx-battery",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) .driver.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) .probe = tosa_bat_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) .remove = tosa_bat_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) .suspend = tosa_bat_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) .resume = tosa_bat_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) module_platform_driver(tosa_bat_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) MODULE_AUTHOR("Dmitry Baryshkov");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) MODULE_DESCRIPTION("Tosa battery driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) MODULE_ALIAS("platform:wm97xx-battery");