Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) // Battery charger driver for TI's tps65217
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) // Copyright (C) 2015 Collabora Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) // Author: Enric Balletbo i Serra <enric.balletbo@collabora.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Battery charger driver for TI's tps65217
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/interrupt.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/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/power_supply.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/mfd/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/mfd/tps65217.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define CHARGER_STATUS_PRESENT	(TPS65217_STATUS_ACPWR | TPS65217_STATUS_USBPWR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define NUM_CHARGER_IRQS	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define POLL_INTERVAL		(HZ * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) struct tps65217_charger {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct tps65217 *tps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct power_supply *psy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	int	online;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int	prev_online;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct task_struct	*poll_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static enum power_supply_property tps65217_charger_props[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	POWER_SUPPLY_PROP_ONLINE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static int tps65217_config_charger(struct tps65217_charger *charger)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	 * tps65217 rev. G, p. 31 (see p. 32 for NTC schematic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	 * The device can be configured to support a 100k NTC (B = 3960) by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	 * setting the the NTC_TYPE bit in register CHGCONFIG1 to 1. However it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	 * is not recommended to do so. In sleep mode, the charger continues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	 * charging the battery, but all register values are reset to default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	 * values. Therefore, the charger would get the wrong temperature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 * information. If 100k NTC setting is required, please contact the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 * factory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	 * ATTENTION, conflicting information, from p. 46
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	 * NTC TYPE (for battery temperature measurement)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	 *   0 – 100k (curve 1, B = 3960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	 *   1 – 10k  (curve 2, B = 3480) (default on reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	ret = tps65217_clear_bits(charger->tps, TPS65217_REG_CHGCONFIG1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				  TPS65217_CHGCONFIG1_NTC_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 				  TPS65217_PROTECT_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		dev_err(charger->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			"failed to set 100k NTC setting: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static int tps65217_enable_charging(struct tps65217_charger *charger)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	/* charger already enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (charger->online)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	dev_dbg(charger->dev, "%s: enable charging\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	ret = tps65217_set_bits(charger->tps, TPS65217_REG_CHGCONFIG1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 				TPS65217_CHGCONFIG1_CHG_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 				TPS65217_CHGCONFIG1_CHG_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 				TPS65217_PROTECT_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		dev_err(charger->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			"%s: Error in writing CHG_EN in reg 0x%x: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			__func__, TPS65217_REG_CHGCONFIG1, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	charger->online = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return 0;
^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) static int tps65217_charger_get_property(struct power_supply *psy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 					 enum power_supply_property psp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 					 union power_supply_propval *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct tps65217_charger *charger = power_supply_get_drvdata(psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (psp == POWER_SUPPLY_PROP_ONLINE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		val->intval = charger->online;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	return -EINVAL;
^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 tps65217_charger_irq(int irq, void *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	int ret, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	struct tps65217_charger *charger = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	charger->prev_online = charger->online;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	ret = tps65217_reg_read(charger->tps, TPS65217_REG_STATUS, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		dev_err(charger->dev, "%s: Error in reading reg 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			__func__, TPS65217_REG_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	dev_dbg(charger->dev, "%s: 0x%x\n", __func__, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	/* check for charger status bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (val & CHARGER_STATUS_PRESENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		ret = tps65217_enable_charging(charger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			dev_err(charger->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 				"failed to enable charger: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		charger->online = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (charger->prev_online != charger->online)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		power_supply_changed(charger->psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	ret = tps65217_reg_read(charger->tps, TPS65217_REG_CHGCONFIG0, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		dev_err(charger->dev, "%s: Error in reading reg 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			__func__, TPS65217_REG_CHGCONFIG0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (val & TPS65217_CHGCONFIG0_ACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		dev_dbg(charger->dev, "%s: charger is charging\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		dev_dbg(charger->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			"%s: charger is NOT charging\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int tps65217_charger_poll_task(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	set_freezable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	while (!kthread_should_stop()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		schedule_timeout_interruptible(POLL_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		try_to_freeze();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		tps65217_charger_irq(-1, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static const struct power_supply_desc tps65217_charger_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	.name			= "tps65217-charger",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	.type			= POWER_SUPPLY_TYPE_MAINS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	.get_property		= tps65217_charger_get_property,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	.properties		= tps65217_charger_props,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	.num_properties		= ARRAY_SIZE(tps65217_charger_props),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static int tps65217_charger_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct tps65217_charger *charger;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct power_supply_config cfg = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct task_struct *poll_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	int irq[NUM_CHARGER_IRQS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (!charger)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	platform_set_drvdata(pdev, charger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	charger->tps = tps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	charger->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	cfg.of_node = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	cfg.drv_data = charger;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	charger->psy = devm_power_supply_register(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 						  &tps65217_charger_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 						  &cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (IS_ERR(charger->psy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		dev_err(&pdev->dev, "failed: power supply register\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		return PTR_ERR(charger->psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	irq[0] = platform_get_irq_byname(pdev, "USB");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	irq[1] = platform_get_irq_byname(pdev, "AC");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	ret = tps65217_config_charger(charger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		dev_err(charger->dev, "charger config failed, err %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	/* Create a polling thread if an interrupt is invalid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (irq[0] < 0 || irq[1] < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		poll_task = kthread_run(tps65217_charger_poll_task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 					charger, "ktps65217charger");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		if (IS_ERR(poll_task)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			ret = PTR_ERR(poll_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			dev_err(charger->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 				"Unable to run kthread err %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		charger->poll_task = poll_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	/* Create IRQ threads for charger interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	for (i = 0; i < NUM_CHARGER_IRQS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		ret = devm_request_threaded_irq(&pdev->dev, irq[i], NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 						tps65217_charger_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 						IRQF_ONESHOT, "tps65217-charger",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 						charger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			dev_err(charger->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				"Unable to register irq %d err %d\n", irq[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 				ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		/* Check current state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		tps65217_charger_irq(-1, charger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static int tps65217_charger_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct tps65217_charger *charger = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (charger->poll_task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		kthread_stop(charger->poll_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static const struct of_device_id tps65217_charger_match_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	{ .compatible = "ti,tps65217-charger", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	{ /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) MODULE_DEVICE_TABLE(of, tps65217_charger_match_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static struct platform_driver tps65217_charger_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	.probe	= tps65217_charger_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	.remove = tps65217_charger_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		.name	= "tps65217-charger",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		.of_match_table = of_match_ptr(tps65217_charger_match_table),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) module_platform_driver(tps65217_charger_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) MODULE_AUTHOR("Enric Balletbo Serra <enric.balletbo@collabora.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) MODULE_DESCRIPTION("TPS65217 battery charger driver");