^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2016, Prodys S.L.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This adds support for sbs-charger compilant chips as defined here:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * http://sbs-forum.org/specs/sbc110.pdf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Implemetation based on sbs-battery.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/power_supply.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define SBS_CHARGER_REG_SPEC_INFO 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define SBS_CHARGER_REG_STATUS 0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define SBS_CHARGER_REG_ALARM_WARNING 0x16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define SBS_CHARGER_STATUS_CHARGE_INHIBITED BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define SBS_CHARGER_STATUS_RES_COLD BIT(9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define SBS_CHARGER_STATUS_RES_HOT BIT(10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define SBS_CHARGER_STATUS_BATTERY_PRESENT BIT(14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define SBS_CHARGER_STATUS_AC_PRESENT BIT(15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define SBS_CHARGER_POLL_TIME 500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct sbs_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct power_supply *power_supply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct delayed_work work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) unsigned int last_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static int sbs_get_property(struct power_supply *psy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) enum power_supply_property psp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) union power_supply_propval *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct sbs_info *chip = power_supply_get_drvdata(psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned int reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) reg = chip->last_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) switch (psp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) case POWER_SUPPLY_PROP_PRESENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) val->intval = !!(reg & SBS_CHARGER_STATUS_BATTERY_PRESENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) case POWER_SUPPLY_PROP_ONLINE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) val->intval = !!(reg & SBS_CHARGER_STATUS_AC_PRESENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) case POWER_SUPPLY_PROP_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (!(reg & SBS_CHARGER_STATUS_BATTERY_PRESENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) else if (reg & SBS_CHARGER_STATUS_AC_PRESENT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) !(reg & SBS_CHARGER_STATUS_CHARGE_INHIBITED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) val->intval = POWER_SUPPLY_STATUS_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) case POWER_SUPPLY_PROP_HEALTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (reg & SBS_CHARGER_STATUS_RES_COLD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) val->intval = POWER_SUPPLY_HEALTH_COLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (reg & SBS_CHARGER_STATUS_RES_HOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) val->intval = POWER_SUPPLY_HEALTH_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static int sbs_check_state(struct sbs_info *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) unsigned int reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ret = regmap_read(chip->regmap, SBS_CHARGER_REG_STATUS, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (!ret && reg != chip->last_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) chip->last_state = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) power_supply_changed(chip->power_supply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static void sbs_delayed_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct sbs_info *chip = container_of(work, struct sbs_info, work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) sbs_check_state(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) schedule_delayed_work(&chip->work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) msecs_to_jiffies(SBS_CHARGER_POLL_TIME));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static irqreturn_t sbs_irq_thread(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct sbs_info *chip = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ret = sbs_check_state(chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return ret ? IRQ_HANDLED : IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static enum power_supply_property sbs_properties[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) POWER_SUPPLY_PROP_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) POWER_SUPPLY_PROP_PRESENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) POWER_SUPPLY_PROP_ONLINE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) POWER_SUPPLY_PROP_HEALTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static bool sbs_readable_reg(struct device *dev, unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return reg >= SBS_CHARGER_REG_SPEC_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static bool sbs_volatile_reg(struct device *dev, unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) switch (reg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) case SBS_CHARGER_REG_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static const struct regmap_config sbs_regmap = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .val_bits = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .max_register = SBS_CHARGER_REG_ALARM_WARNING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .readable_reg = sbs_readable_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .volatile_reg = sbs_volatile_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) .val_format_endian = REGMAP_ENDIAN_LITTLE, /* since based on SMBus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static const struct power_supply_desc sbs_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) .name = "sbs-charger",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) .type = POWER_SUPPLY_TYPE_MAINS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) .properties = sbs_properties,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .num_properties = ARRAY_SIZE(sbs_properties),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) .get_property = sbs_get_property,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int sbs_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct power_supply_config psy_cfg = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct sbs_info *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int ret, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) chip = devm_kzalloc(&client->dev, sizeof(struct sbs_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (!chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) chip->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) psy_cfg.of_node = client->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) psy_cfg.drv_data = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) i2c_set_clientdata(client, chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) chip->regmap = devm_regmap_init_i2c(client, &sbs_regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (IS_ERR(chip->regmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return PTR_ERR(chip->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * Before we register, we need to make sure we can actually talk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * to the battery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ret = regmap_read(chip->regmap, SBS_CHARGER_REG_STATUS, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) dev_err(&client->dev, "Failed to get device status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) chip->last_state = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) chip->power_supply = devm_power_supply_register(&client->dev, &sbs_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) &psy_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (IS_ERR(chip->power_supply)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) dev_err(&client->dev, "Failed to register power supply\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return PTR_ERR(chip->power_supply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * The sbs-charger spec doesn't impose the use of an interrupt. So in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * the case it wasn't provided we use polling in order get the charger's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * status.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (client->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) ret = devm_request_threaded_irq(&client->dev, client->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) NULL, sbs_irq_thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) dev_name(&client->dev), chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) dev_err(&client->dev, "Failed to request irq, %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) INIT_DELAYED_WORK(&chip->work, sbs_delayed_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) schedule_delayed_work(&chip->work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) msecs_to_jiffies(SBS_CHARGER_POLL_TIME));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) dev_info(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) "%s: smart charger device registered\n", client->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return 0;
^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 int sbs_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct sbs_info *chip = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) cancel_delayed_work_sync(&chip->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return 0;
^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) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static const struct of_device_id sbs_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) { .compatible = "sbs,sbs-charger" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) MODULE_DEVICE_TABLE(of, sbs_dt_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static const struct i2c_device_id sbs_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) { "sbs-charger", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) MODULE_DEVICE_TABLE(i2c, sbs_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static struct i2c_driver sbs_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .probe = sbs_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .remove = sbs_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) .id_table = sbs_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) .name = "sbs-charger",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .of_match_table = of_match_ptr(sbs_dt_ids),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) module_i2c_driver(sbs_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) MODULE_AUTHOR("Nicolas Saenz Julienne <nicolassaenzj@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) MODULE_DESCRIPTION("SBS smart charger driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) MODULE_LICENSE("GPL v2");