From d2aef0b522ea44cac0114b5eb51cadc6c6179a19 Mon Sep 17 00:00:00 2001 From: xuwei9 Date: Fri, 22 Feb 2019 14:50:53 +0800 Subject: [PATCH] kernel:turbo charger support turbo charger support kernel code Change-Id: Iee02d57987ba73a227007806e2a9a10ff73c5297 Signed-off-by: xuwei9 Reviewed-on: https://gerrit.mot.com/1313086 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Xiangpo Zhao Submit-Approved: Jira Key --- drivers/power/supply/power_supply_sysfs.c | 8 +++++ drivers/power/supply/s2mu00x_battery.c | 37 ++++++++++++++++++++++- include/linux/kobject.h | 2 +- include/linux/power_supply.h | 8 +++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index 4ffa65fe52ee..1fd2e1e23006 100755 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -74,6 +74,10 @@ static const char * const power_supply_scope_text[] = { "Unknown", "System", "Device" }; +static const char * const power_supply_charge_rate_text[] = { + "None","Normal","Weak","Turbo" +}; + static ssize_t power_supply_show_property(struct device *dev, struct device_attribute *attr, char *buf) { @@ -105,6 +109,9 @@ static ssize_t power_supply_show_property(struct device *dev, else if (off == POWER_SUPPLY_PROP_CHARGE_TYPE) return sprintf(buf, "%s\n", power_supply_charge_type_text[value.intval]); + else if (off == POWER_SUPPLY_PROP_CHARGE_RATE) + return sprintf(buf,"%s\n", + power_supply_charge_rate_text[value.intval]); else if (off == POWER_SUPPLY_PROP_HEALTH) return sprintf(buf, "%s\n", power_supply_health_text[value.intval]); @@ -285,6 +292,7 @@ static struct device_attribute power_supply_attrs[] = { POWER_SUPPLY_ATTR(rr_enable), POWER_SUPPLY_ATTR(usbpd_reset), POWER_SUPPLY_ATTR(usbpd_test_read), + POWER_SUPPLY_ATTR(charge_rate), }; static struct attribute * diff --git a/drivers/power/supply/s2mu00x_battery.c b/drivers/power/supply/s2mu00x_battery.c index cad454f87c64..8639991f1c0c 100644 --- a/drivers/power/supply/s2mu00x_battery.c +++ b/drivers/power/supply/s2mu00x_battery.c @@ -89,6 +89,7 @@ static enum power_supply_property s2mu00x_battery_props[] = { POWER_SUPPLY_PROP_TECHNOLOGY, POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, + POWER_SUPPLY_PROP_CHARGE_RATE, }; static enum power_supply_property s2mu00x_power_props[] = { @@ -856,6 +857,28 @@ static void set_bat_status_by_cable(struct s2mu00x_battery_info *battery) #endif } +#define WEAK_CHRG_THRSH 450 +static void get_prop_charge_rate(struct s2mu00x_battery_info *battery) +{ + int prev_chg_rate = battery->charger_rate; + char *charge_rate[] = { + "None", "Normal", "Weak", "Turbo" + }; + + if (!is_usb_present(battery)) { + battery->charger_rate = POWER_SUPPLY_CHARGE_RATE_NONE; + return; + } + + if(battery->cable_type == POWER_SUPPLY_TYPE_HV_MAINS) + battery->charger_rate = POWER_SUPPLY_CHARGE_RATE_TURBO; + else + battery->charger_rate = POWER_SUPPLY_CHARGE_RATE_NORMAL; + + if(prev_chg_rate != battery->charger_rate) + printk(KERN_ERR "%s,charge_rate:%s\n",__func__,charge_rate[battery->charger_rate]); +} + static int s2mu00x_battery_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { @@ -966,6 +989,10 @@ static int s2mu00x_battery_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_SOH: val->intval = battery->soh; break; + case POWER_SUPPLY_PROP_CHARGE_RATE: + get_prop_charge_rate(battery); + val->intval = battery->charger_rate; + break; default: ret = -ENODATA; } @@ -1628,7 +1655,9 @@ end_ifconn_handle: battery->stepchg_state = STEP_NONE; battery->charging_limit_modes = CHARGING_LIMIT_OFF; set_max_allowed_current_ma(battery,battery->stepchg_current_ma); + battery->charger_rate = POWER_SUPPLY_CHARGE_RATE_NONE; } else { + battery->charger_rate = POWER_SUPPLY_CHARGE_RATE_NORMAL; smbchg_stay_awake(battery); cancel_delayed_work(&battery->heartbeat_work); schedule_delayed_work(&battery->heartbeat_work, msecs_to_jiffies(0)); @@ -2727,6 +2756,11 @@ bool is_usb_present(struct s2mu00x_battery_info *chip) case POWER_SUPPLY_TYPE_HV_MAINS: case POWER_SUPPLY_TYPE_PREPARE_TA: case POWER_SUPPLY_TYPE_UNKNOWN: + case POWER_SUPPLY_TYPE_USB_ACA: /* Accessory Charger Adapters */ + case POWER_SUPPLY_TYPE_USB_TYPE_C: /* Type C Port */ + case POWER_SUPPLY_TYPE_USB_PD: /* Power Delivery Port */ + case POWER_SUPPLY_TYPE_USB_PD_DRP: /* PD Dual Role Port */ + case POWER_SUPPLY_TYPE_APPLE_BRICK_ID: /* Apple Charging Method */ present = true; break; default: @@ -2775,7 +2809,7 @@ bool is_dc_present(struct s2mu00x_battery_info *chip) { int type = chip->cable_type; - if (type == POWER_SUPPLY_TYPE_USB_DCP || type == POWER_SUPPLY_TYPE_MAINS) + if (type == POWER_SUPPLY_TYPE_USB_DCP || type == POWER_SUPPLY_TYPE_MAINS || type == POWER_SUPPLY_TYPE_HV_MAINS) return true; else return false; @@ -4424,6 +4458,7 @@ static int s2mu00x_battery_probe(struct platform_device *pdev) battery->is_weak_charger = false; battery->usb_online = -EINVAL; battery->stepchg_state = STEP_NONE; + battery->charger_rate = POWER_SUPPLY_CHARGE_RATE_NONE; rc = device_create_file(battery->dev, &dev_attr_force_demo_mode); if (rc) { diff --git a/include/linux/kobject.h b/include/linux/kobject.h index e232df1d9db2..af4776747c79 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -29,7 +29,7 @@ #include #define UEVENT_HELPER_PATH_LEN 256 -#define UEVENT_NUM_ENVP 32 /* number of env pointers */ +#define UEVENT_NUM_ENVP 64 /* number of env pointers */ #define UEVENT_BUFFER_SIZE 2048 /* buffer for the variables */ #ifdef CONFIG_UEVENT_HELPER diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 3f3f03714201..f086f6ee3539 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -91,6 +91,13 @@ enum { POWER_SUPPLY_SCOPE_DEVICE, }; +enum { + POWER_SUPPLY_CHARGE_RATE_NONE = 0, + POWER_SUPPLY_CHARGE_RATE_NORMAL, + POWER_SUPPLY_CHARGE_RATE_WEAK, + POWER_SUPPLY_CHARGE_RATE_TURBO, +}; + enum power_supply_property { /* Properties of type `int' */ POWER_SUPPLY_PROP_STATUS = 0, @@ -191,6 +198,7 @@ enum power_supply_property { POWER_SUPPLY_PROP_RR_ENABLE, POWER_SUPPLY_PROP_USBPD_RESET, POWER_SUPPLY_PROP_USBPD_TEST_READ, + POWER_SUPPLY_PROP_CHARGE_RATE, }; enum power_supply_type { -- 2.20.1