kernel:turbo charger support
authorxuwei9 <xuwei9@lenovo.com>
Fri, 22 Feb 2019 06:50:53 +0000 (14:50 +0800)
committerlingsen1 <lingsen1@lenovo.com>
Mon, 10 Jun 2019 03:21:11 +0000 (11:21 +0800)
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 78891927a978e3a6ae9165ee3a878a6436ae2cf9..5382d99e281ab94635d01a24a815ce33293ab264 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) {
@@ -104,6 +108,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]);
@@ -284,6 +291,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 7fd6437345bfc4f0eec7f61652188d2d5ce07e8b..eec94750a9becc4b1ca0a1ef14f0976deb6e09ad 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[] = {
@@ -846,6 +847,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)
 {
@@ -956,6 +979,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;
        }
@@ -1618,7 +1645,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));
@@ -2614,6 +2643,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:
@@ -2662,7 +2696,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;
@@ -4313,6 +4347,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 e0a6205caa71ad2fd78853c3eafb2b06e227e58e..c8be15c41babb6a7de2e250e4871931553d844f3 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 300acb6c4245a07f22759b90146e8cd096a82dda..673f77ea7db3f61aeb0261218a4ae8705a1f9644 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 {