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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * ec battery driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2016 Rockchip Electronics Co., Ltd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Shunqing Chen <csq@rock-chips.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * This program is free software; you can redistribute it and/or modify it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * under the terms and conditions of the GNU General Public License,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * version 2, as published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * This program is distributed in the hope it will be useful, but WITHOUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/module.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) static int dbg_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) module_param_named(dbg_level, dbg_enable, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define DBG(args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		if (dbg_enable) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 			printk(args); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		} \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) struct ec_battery {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct i2c_client	*i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct device		*dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct regmap		*regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct power_supply	*bat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct workqueue_struct	*bat_monitor_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct delayed_work	bat_delay_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	u32			monitor_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	u32			bat_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	u16			status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	int			current_now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	u16			voltage_now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	u16			rem_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	u16			full_charge_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	u16			design_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	int			temperature_now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	int			soc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	bool			is_charge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	bool			dis_charge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	bool			is_ctitical;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	bool			is_battery_low;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	bool			is_battery_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	bool			is_ac_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct gpio_desc	*ec_notify_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) enum bat_mode {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	MODE_BATTARY = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	MODE_VIRTUAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /* virtual params */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define VIRTUAL_CURRENT			1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define VIRTUAL_VOLTAGE			3888
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define VIRTUAL_SOC			66
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define VIRTUAL_PRESET			1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define VIRTUAL_TEMPERATURE		188
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define VIRTUAL_STATUS			POWER_SUPPLY_STATUS_CHARGING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define TIMER_MS_COUNTS			1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define DEFAULT_MONITOR_SEC		5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define EC_GET_VERSION_COMMOND		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #define EC_GET_VERSION_INFO_NUM		(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define EC_GET_BATTERY_INFO_COMMOND	0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define EC_GET_PARAMETER_NUM		(13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #define EC_GET_BATTERY_OTHER_COMMOND	0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #define EC_GET_BATTERYINFO_NUM		(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #define EC_GET_BIT(a, b)	(((a) & (1 << (b))) ? 1 : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) #define EC_DIS_CHARGE(a)	EC_GET_BIT(a, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #define EC_IS_CHARGE(a)		EC_GET_BIT(a, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #define EC_IS_CRITICAL(a)	EC_GET_BIT(a, 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #define EC_IS_BATTERY_LOW(a)	EC_GET_BIT(a, 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #define EC_IS_BATTERY_IN(a)	EC_GET_BIT(a, 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) #define EC_IS_AC_IN(a)		EC_GET_BIT(a, 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static int ec_i2c_read(struct ec_battery *bat, u8 cmd, u8 *dest, u16 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct i2c_client *i2c = bat->i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct i2c_msg msg[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	u8 buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	buf[0] = cmd; /* EC_GET_BATTERY_INFO_COMMOND; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	msg[0].addr = i2c->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	msg[0].flags = i2c->flags & I2C_M_TEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	msg[0].len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	msg[0].buf = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	msg[1].addr = i2c->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	msg[1].flags = i2c->flags & I2C_M_TEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	msg[1].flags |= I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	msg[1].len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	msg[1].buf = dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	ret = i2c_transfer(i2c->adapter, msg, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static void ec_dump_info(struct ec_battery *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	int temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	DBG("==========================================\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	DBG("battery status: %x\n", bat->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	temp = bat->temperature_now / 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	DBG("Temp: %d K (%d C))\n", temp, (temp - 272));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	DBG("current_now: %d ma\n", bat->current_now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	DBG("voltage_now: %d mv\n", bat->voltage_now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	DBG("Charge:    %d %%\n", bat->soc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	DBG("Remaining: %d mAh\n", bat->rem_capacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	DBG("Cap-full:  %d mAh\n", bat->full_charge_capacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	DBG("Design:    %d mAh\n", bat->design_capacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	DBG("==========================================\n");
^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) static int ec_get_battery_info(struct ec_battery *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	u8 buf[13] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	u16 voltage2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	u16 full_charge_capacity_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	u16 design_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	u16 cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	int soc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	ret = ec_i2c_read(bat, EC_GET_BATTERY_INFO_COMMOND, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			  EC_GET_PARAMETER_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if ((EC_GET_PARAMETER_NUM - 1) == buf[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		bat->status = buf[2] << 8 | buf[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		cur = (buf[4] << 8 | buf[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		bat->current_now = cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		if (buf[4] & 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			bat->current_now = (~cur) & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			bat->current_now = -(bat->current_now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		bat->rem_capacity = buf[6] << 8 | buf[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		bat->voltage_now = buf[8] << 8 | buf[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		bat->full_charge_capacity = buf[10] << 8 | buf[9];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		bat->temperature_now = buf[12] << 8 | buf[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		soc = (bat->rem_capacity + bat->full_charge_capacity / 101) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			100 / bat->full_charge_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		if (soc > 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			bat->soc = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		else if (soc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			bat->soc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			bat->soc = soc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		dev_err(bat->dev, "get battery info from 0x07 erro\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	ret = ec_i2c_read(bat, EC_GET_BATTERY_OTHER_COMMOND, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			  EC_GET_BATTERYINFO_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if ((EC_GET_BATTERYINFO_NUM - 1) == buf[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		full_charge_capacity_1 = buf[2] << 8 | buf[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		voltage2 = buf[4] << 8 | buf[3];	/* the same to uppo */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		design_capacity = buf[6] << 8 | buf[5];	/* the same to uppo */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		bat->design_capacity = design_capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	ec_dump_info(bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static int ec_get_current(struct ec_battery *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return bat->current_now * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static int ec_get_voltage(struct ec_battery *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	return bat->voltage_now * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static int is_ec_bat_exist(struct ec_battery *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	int is_exist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	is_exist = EC_IS_BATTERY_IN(bat->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return is_exist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int ec_get_capacity(struct ec_battery *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return bat->soc;
^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) static int ec_get_temperature(struct ec_battery *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	int temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	temp = bat->temperature_now - 2722;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	return temp;
^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) static int ec_bat_chrg_online(struct ec_battery *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	return EC_IS_CHARGE(bat->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int ec_bat_parse_dt(struct ec_battery *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	u32 out_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct device_node *np = bat->dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	bat->bat_mode = MODE_BATTARY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	bat->monitor_sec = DEFAULT_MONITOR_SEC * TIMER_MS_COUNTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	ret = of_property_read_u32(np, "virtual_power", &bat->bat_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		dev_err(bat->dev, "virtual_power missing!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	ret = of_property_read_u32(np, "monitor_sec", &out_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		dev_err(bat->dev, "monitor_sec missing!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		bat->monitor_sec = out_value * TIMER_MS_COUNTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	bat->ec_notify_io =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		devm_gpiod_get_optional(bat->dev, "ec-notify",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 					GPIOD_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (!IS_ERR_OR_NULL(bat->ec_notify_io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		gpiod_direction_output(bat->ec_notify_io, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static int ec_bat_parse_dt(struct ec_battery *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static enum power_supply_property ec_bat_props[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	POWER_SUPPLY_PROP_CURRENT_NOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	POWER_SUPPLY_PROP_PRESENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	POWER_SUPPLY_PROP_HEALTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	POWER_SUPPLY_PROP_CAPACITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	POWER_SUPPLY_PROP_TEMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	POWER_SUPPLY_PROP_STATUS,
^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) static int ec_battery_get_property(struct power_supply *psy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 				   enum power_supply_property psp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 				   union power_supply_propval *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	struct ec_battery *bat = power_supply_get_drvdata(psy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	switch (psp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	case POWER_SUPPLY_PROP_CURRENT_NOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		val->intval = ec_get_current(bat);/*uA*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		if (bat->bat_mode == MODE_VIRTUAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			val->intval = VIRTUAL_CURRENT * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		val->intval = ec_get_voltage(bat);/*uV*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		if (bat->bat_mode == MODE_VIRTUAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			val->intval = VIRTUAL_VOLTAGE * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	case POWER_SUPPLY_PROP_PRESENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		val->intval = is_ec_bat_exist(bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		if (bat->bat_mode == MODE_VIRTUAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			val->intval = VIRTUAL_PRESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	case POWER_SUPPLY_PROP_CAPACITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		val->intval = ec_get_capacity(bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		if (bat->bat_mode == MODE_VIRTUAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			val->intval = VIRTUAL_SOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	case POWER_SUPPLY_PROP_HEALTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		val->intval = POWER_SUPPLY_HEALTH_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	case POWER_SUPPLY_PROP_TEMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		val->intval = ec_get_temperature(bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		if (bat->bat_mode == MODE_VIRTUAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			val->intval = VIRTUAL_TEMPERATURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	case POWER_SUPPLY_PROP_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		if (bat->bat_mode == MODE_VIRTUAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			val->intval = VIRTUAL_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		else if (ec_get_capacity(bat) == 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			val->intval = POWER_SUPPLY_STATUS_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		else if (ec_bat_chrg_online(bat))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			val->intval = POWER_SUPPLY_STATUS_CHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static const struct power_supply_desc ec_bat_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	.name		= "battery",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	.type		= POWER_SUPPLY_TYPE_BATTERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	.properties	= ec_bat_props,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	.num_properties	= ARRAY_SIZE(ec_bat_props),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	.get_property	= ec_battery_get_property,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static int ec_bat_init_power_supply(struct ec_battery *bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	struct power_supply_config psy_cfg = { .drv_data = bat, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	bat->bat = power_supply_register(bat->dev, &ec_bat_desc, &psy_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	if (IS_ERR(bat->bat)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		dev_err(bat->dev, "register bat power supply fail\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		return PTR_ERR(bat->bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static void ec_bat_power_supply_changed(struct ec_battery *ec_bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	bool state_changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	static int old_cap = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	static int old_temperature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	state_changed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	if (ec_get_capacity(ec_bat) != old_cap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		state_changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	else if (ec_get_temperature(ec_bat) != old_temperature)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		state_changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (state_changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		power_supply_changed(ec_bat->bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		old_cap = ec_get_capacity(ec_bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		old_temperature = ec_get_temperature(ec_bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static void ec_battery_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	struct ec_battery *ec_bat =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		container_of(work, struct ec_battery, bat_delay_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	ec_get_battery_info(ec_bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	ec_bat_power_supply_changed(ec_bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	queue_delayed_work(ec_bat->bat_monitor_wq, &ec_bat->bat_delay_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			   msecs_to_jiffies(ec_bat->monitor_sec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static int ec_charger_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 			    const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	struct ec_battery *ec_bat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	ec_bat = devm_kzalloc(&client->dev, sizeof(*ec_bat), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	if (!ec_bat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	ec_bat->dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	ec_bat->i2c = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	i2c_set_clientdata(client, ec_bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	ret = ec_bat_parse_dt(ec_bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		dev_err(ec_bat->dev, "parse dt failed!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	ret = ec_bat_init_power_supply(ec_bat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		dev_err(ec_bat->dev, "init power supply fail!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	ec_bat->bat_monitor_wq =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		alloc_ordered_workqueue("%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 					WQ_MEM_RECLAIM | WQ_FREEZABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 					"ec-bat-monitor-wq");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	INIT_DELAYED_WORK(&ec_bat->bat_delay_work, ec_battery_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	queue_delayed_work(ec_bat->bat_monitor_wq, &ec_bat->bat_delay_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 			   msecs_to_jiffies(TIMER_MS_COUNTS * 5));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static int ec_bat_pm_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	struct ec_battery *ec_bat = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	cancel_delayed_work_sync(&ec_bat->bat_delay_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	if (!IS_ERR_OR_NULL(ec_bat->ec_notify_io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		gpiod_direction_output(ec_bat->ec_notify_io, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static int ec_bat_pm_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	struct ec_battery *ec_bat = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (!IS_ERR_OR_NULL(ec_bat->ec_notify_io))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		gpiod_direction_output(ec_bat->ec_notify_io, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	queue_delayed_work(ec_bat->bat_monitor_wq, &ec_bat->bat_delay_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			   msecs_to_jiffies(TIMER_MS_COUNTS * 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static SIMPLE_DEV_PM_OPS(ec_bat_pm_ops, ec_bat_pm_suspend, ec_bat_pm_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) static const struct i2c_device_id ec_battery_i2c_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	{ "ec_battery" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) MODULE_DEVICE_TABLE(i2c, ec_battery_i2c_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static const struct of_device_id ec_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	{ .compatible = "rockchip,ec-battery" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) MODULE_DEVICE_TABLE(of, ec_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) static const struct of_device_id ec_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static struct i2c_driver ec_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		.name		= "ec_battery",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		.pm		= &ec_bat_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		.of_match_table	= ec_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	.id_table	= ec_battery_i2c_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	.probe		= ec_charger_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) module_i2c_driver(ec_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) MODULE_ALIAS("platform:ec-charger");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) MODULE_AUTHOR("Shunqing Chen<csq@rock-chips.com>");