kernel:turbo charger support
authorxuwei9 <xuwei9@lenovo.com>
Fri, 22 Feb 2019 06:50:53 +0000 (14:50 +0800)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:23:55 +0000 (20:23 +0300)
turbo charger support
kernel code

Change-Id: Iee02d57987ba73a227007806e2a9a10ff73c5297
Signed-off-by: xuwei9 <xuwei9@mt.com>
Reviewed-on: https://gerrit.mot.com/1313086
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Submit-Approved: Jira Key

drivers/power/supply/power_supply_sysfs.c
drivers/power/supply/s2mu00x_battery.c
include/linux/kobject.h
include/linux/power_supply.h

index 4ffa65fe52ee62b89af2353008e580b5b64f12bd..1fd2e1e23006e2bf5f63fb4d27ffe8bc645d4e2f 100755 (executable)
@@ -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 *
index cad454f87c64654317a53b99b888d08cf58f6266..8639991f1c0c29eccc37abf7e3da04c03b7324e3 100644 (file)
@@ -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) {
index e232df1d9db21363e03b03ee7abaf00dd0ebc4d7..af4776747c79e0ab81fed245375cf6579cca06b7 100644 (file)
@@ -29,7 +29,7 @@
 #include <linux/workqueue.h>
 
 #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
index 3f3f03714201787dc15f7b6a035f383845fd4350..f086f6ee35395ac93a02f3bb3eecbecacee08896 100644 (file)
@@ -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 {