From patchwork Thu May 14 23:04:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Bakker X-Patchwork-Id: 11550119 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF73C59D for ; Thu, 14 May 2020 23:05:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A78C020727 for ; Thu, 14 May 2020 23:05:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729029AbgENXFJ (ORCPT ); Thu, 14 May 2020 19:05:09 -0400 Received: from mail-mw2nam12olkn2084.outbound.protection.outlook.com ([40.92.23.84]:28621 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728602AbgENXFJ (ORCPT ); Thu, 14 May 2020 19:05:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DO0cFOQofIEESAc5fRVOhz9srlEMKK7fB8+sWxF9dG1U0GKfmsu7PBcQ5s5ktFZtC9dd0KxHS4W4PbpLIIUK9NB1ygTgq7LyfXf+B1calMyMpg6Lq+mCBn28qURHNpRmOlr7C/bxom4QQq9WS+SO2nycVL4vtLd97FMxr3bAtVSXCaJCELJFsPH8IYbgRn9z1YwBwf/oP6wxu9QJKRZbtvBQIUzmGtTMdcRz3JztsUBVihP9vYAb6rajxpLP6D/LQnGM3Fo7FezqWKK5amiiWtYoULSBvUk9TQY7/Shr5ECU729553FyTbEMigo67qcrncazAyYxzC+ss7aV3HTGjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gUCcqPZF46q0Hh6KXEjruQjzv4fka78JltJ4rJy8xpM=; b=Y1pr3MzfYnZhlNksrKmMtW7HzPr0LuHoRGww63ohv5Zab8JtLOnsuIF4Nalk+INIRYTK7A+kUlRiZTklWWK3f1sizZIgAePz4S+LEwORuq7RsJdNGUkHZnGImjQpugvxHDqQGKsfwPelOFfVeQpNGywwenKItBog24fsvU6n4oo2iJ9CZgwd/u8hxmGDcyhxbTxbeVmkkCey6+05BTmm8oo+MmZ/WCvZVH1T+A0Xgu5LOwgNRrpqduKUT+IYkzFf4RavlUD4Vn4HPp9L0PNIeo1NJFcn5rXu7BcxuFKRIvlbPIPbaG8TKAgtaxjutmC0PA4dF7alv1JvStg2+6+CVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=live.ca; dmarc=pass action=none header.from=live.ca; dkim=pass header.d=live.ca; arc=none Received: from MW2NAM12FT003.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::42) by MW2NAM12HT256.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::347) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.11; Thu, 14 May 2020 23:05:05 +0000 Received: from BN6PR04MB0660.namprd04.prod.outlook.com (2a01:111:e400:fc65::44) by MW2NAM12FT003.mail.protection.outlook.com (2a01:111:e400:fc65::70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11 via Frontend Transport; Thu, 14 May 2020 23:05:05 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:96457069B7C8ECE2B32989EFB7E1F5D4DADFFD3A441ED28AA851DA2F7CED0FB9;UpperCasedChecksum:0278B8E250466512A3B55EE2741B6A3930D3A4C203E92490CD07E1149D2789B6;SizeAsReceived:7954;Count:50 Received: from BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc]) by BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc%6]) with mapi id 15.20.3000.022; Thu, 14 May 2020 23:05:05 +0000 From: Jonathan Bakker To: sre@kernel.org, krzk@kernel.org, jonghwa3.lee@samsung.com, tglx@linutronix.de, kstewart@linuxfoundation.org, baolin.wang7@gmail.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , Jonathan Bakker Subject: [PATCH 01/10] power: supply: charger-manager: Swap private uevent for power_supply_changed Date: Thu, 14 May 2020 16:04:26 -0700 Message-ID: X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514230435.11798-1-xc-racer2@live.ca> References: <20200514230435.11798-1-xc-racer2@live.ca> X-ClientProxiedBy: MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) To BN6PR04MB0660.namprd04.prod.outlook.com (2603:10b6:404:d9::21) X-Microsoft-Original-Message-ID: <20200514230435.11798-2-xc-racer2@live.ca> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jon-hp-6570b.telus (2001:569:fb68:9c00:8067:f823:1e15:7520) by MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26 via Frontend Transport; Thu, 14 May 2020 23:05:04 +0000 X-Mailer: git-send-email 2.20.1 X-Microsoft-Original-Message-ID: <20200514230435.11798-2-xc-racer2@live.ca> X-TMN: [mPWESInzjCLz92pIXHfqiXC1ByhNVvhz3CPcz0+OaSZ94j1MlwaNEzaqt3PaUjLe] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: eeb8004d-7710-4412-fe06-08d7f85b3d5d X-MS-TrafficTypeDiagnostic: MW2NAM12HT256: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d3TyidNTycMoHuwCqjQxwoUlVk2ivaMpaJzGqs2P6nFiNhFuCQKYYqQ9K4Ie/z0U7IqDPaDQCVhCJMCvG52QjnN2JmsPJnJfRgfoU0SJ8YVFXULdXOK6BUvEk+4iBYExmTh518nD2XlNuQvEW9daEo2dliB0FRJPAGPa+b9Eepq6PkWmww0uoLnlAIxW2ZFGTXT8ETEwKEjxDQB6nsoUhg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR04MB0660.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: wx8almPHaP0Jq9rE26RA5ylTygMxvedEN8J0H/QT6rQSDzit4sgCmBQpP11nrP1ft9QxWtXWtZD1E0oHbJJgxrPw5gIebSDSXsfPmgupvQKHfJYUwoeVT003jGDRy1bjyDY0bti+upFkQ8lbvID57LRNJEQzTieLQMATNJJGzVOeVBWbJR5A71QScbMa7jV5tcmf270E1c224CmmYZXiSQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: eeb8004d-7710-4412-fe06-08d7f85b3d5d X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 23:05:05.5715 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM12HT256 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Jonghwa Lee Whenever the battery status is changed, charger manager triggers a uevent through a private interface. Modify it to use power_supply_changed() since it belongs to the power supply subsystem. Signed-off-by: Jonghwa Lee Signed-off-by: Krzysztof Kozlowski Signed-off-by: Jonathan Bakker --- drivers/power/supply/charger-manager.c | 91 ++++---------------------- 1 file changed, 11 insertions(+), 80 deletions(-) diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c index a21e1a2673f8..330185b960a5 100644 --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -33,18 +33,6 @@ #define CM_DEFAULT_RECHARGE_TEMP_DIFF 50 #define CM_DEFAULT_CHARGE_TEMP_MAX 500 -static const char * const default_event_names[] = { - [CM_EVENT_UNKNOWN] = "Unknown", - [CM_EVENT_BATT_FULL] = "Battery Full", - [CM_EVENT_BATT_IN] = "Battery Inserted", - [CM_EVENT_BATT_OUT] = "Battery Pulled Out", - [CM_EVENT_BATT_OVERHEAT] = "Battery Overheat", - [CM_EVENT_BATT_COLD] = "Battery Cold", - [CM_EVENT_EXT_PWR_IN_OUT] = "External Power Attach/Detach", - [CM_EVENT_CHG_START_STOP] = "Charging Start/Stop", - [CM_EVENT_OTHERS] = "Other battery events" -}; - /* * Regard CM_JIFFIES_SMALL jiffies is small enough to ignore for * delayed works so that we can run delayed works with CM_JIFFIES_SMALL @@ -61,8 +49,6 @@ static const char * const default_event_names[] = { */ #define CM_RTC_SMALL (2) -#define UEVENT_BUF_SIZE 32 - static LIST_HEAD(cm_list); static DEFINE_MUTEX(cm_list_mtx); @@ -446,61 +432,6 @@ static int try_charger_restart(struct charger_manager *cm) return try_charger_enable(cm, true); } -/** - * uevent_notify - Let users know something has changed. - * @cm: the Charger Manager representing the battery. - * @event: the event string. - * - * If @event is null, it implies that uevent_notify is called - * by resume function. When called in the resume function, cm_suspended - * should be already reset to false in order to let uevent_notify - * notify the recent event during the suspend to users. While - * suspended, uevent_notify does not notify users, but tracks - * events so that uevent_notify can notify users later after resumed. - */ -static void uevent_notify(struct charger_manager *cm, const char *event) -{ - static char env_str[UEVENT_BUF_SIZE + 1] = ""; - static char env_str_save[UEVENT_BUF_SIZE + 1] = ""; - - if (cm_suspended) { - /* Nothing in suspended-event buffer */ - if (env_str_save[0] == 0) { - if (!strncmp(env_str, event, UEVENT_BUF_SIZE)) - return; /* status not changed */ - strncpy(env_str_save, event, UEVENT_BUF_SIZE); - return; - } - - if (!strncmp(env_str_save, event, UEVENT_BUF_SIZE)) - return; /* Duplicated. */ - strncpy(env_str_save, event, UEVENT_BUF_SIZE); - return; - } - - if (event == NULL) { - /* No messages pending */ - if (!env_str_save[0]) - return; - - strncpy(env_str, env_str_save, UEVENT_BUF_SIZE); - kobject_uevent(&cm->dev->kobj, KOBJ_CHANGE); - env_str_save[0] = 0; - - return; - } - - /* status not changed */ - if (!strncmp(env_str, event, UEVENT_BUF_SIZE)) - return; - - /* save the status and notify the update */ - strncpy(env_str, event, UEVENT_BUF_SIZE); - kobject_uevent(&cm->dev->kobj, KOBJ_CHANGE); - - dev_info(cm->dev, "%s\n", event); -} - /** * fullbatt_vchk - Check voltage drop some times after "FULL" event. * @work: the work_struct appointing the function @@ -538,7 +469,7 @@ static void fullbatt_vchk(struct work_struct *work) if (diff > desc->fullbatt_vchkdrop_uV) { try_charger_restart(cm); - uevent_notify(cm, "Recharging"); + power_supply_changed(cm->charger_psy); } } @@ -569,7 +500,7 @@ static int check_charging_duration(struct charger_manager *cm) if (duration > desc->charging_max_duration_ms) { dev_info(cm->dev, "Charging duration exceed %ums\n", desc->charging_max_duration_ms); - uevent_notify(cm, "Discharging"); + power_supply_changed(cm->charger_psy); try_charger_enable(cm, false); ret = true; } @@ -580,7 +511,7 @@ static int check_charging_duration(struct charger_manager *cm) is_ext_pwr_online(cm)) { dev_info(cm->dev, "Discharging duration exceed %ums\n", desc->discharging_max_duration_ms); - uevent_notify(cm, "Recharging"); + power_supply_changed(cm->charger_psy); try_charger_enable(cm, true); ret = true; } @@ -688,7 +619,7 @@ static bool _cm_monitor(struct charger_manager *cm) if (temp_alrt) { cm->emergency_stop = temp_alrt; if (!try_charger_enable(cm, false)) - uevent_notify(cm, default_event_names[temp_alrt]); + power_supply_changed(cm->charger_psy); /* * Check whole charging duration and discharging duration @@ -713,7 +644,7 @@ static bool _cm_monitor(struct charger_manager *cm) } else if (!cm->emergency_stop && is_full_charged(cm) && cm->charger_enabled) { dev_info(cm->dev, "EVENT_HANDLE: Battery Fully Charged\n"); - uevent_notify(cm, default_event_names[CM_EVENT_BATT_FULL]); + power_supply_changed(cm->charger_psy); try_charger_enable(cm, false); @@ -722,7 +653,7 @@ static bool _cm_monitor(struct charger_manager *cm) cm->emergency_stop = 0; if (is_ext_pwr_online(cm)) { if (!try_charger_enable(cm, true)) - uevent_notify(cm, "CHARGING"); + power_supply_changed(cm->charger_psy); } } @@ -843,7 +774,7 @@ static void fullbatt_handler(struct charger_manager *cm) out: dev_info(cm->dev, "EVENT_HANDLE: Battery Fully Charged\n"); - uevent_notify(cm, default_event_names[CM_EVENT_BATT_FULL]); + power_supply_changed(cm->charger_psy); } /** @@ -857,9 +788,9 @@ static void battout_handler(struct charger_manager *cm) if (!is_batt_present(cm)) { dev_emerg(cm->dev, "Battery Pulled Out!\n"); - uevent_notify(cm, default_event_names[CM_EVENT_BATT_OUT]); + power_supply_changed(cm->charger_psy); } else { - uevent_notify(cm, "Battery Reinserted?"); + power_supply_changed(cm->charger_psy); } } @@ -876,7 +807,7 @@ static void misc_event_handler(struct charger_manager *cm, if (is_polling_required(cm) && cm->desc->polling_interval_ms) schedule_work(&setup_polling); - uevent_notify(cm, default_event_names[type]); + power_supply_changed(cm->charger_psy); } static int charger_get_property(struct power_supply *psy, @@ -2044,7 +1975,7 @@ void cm_notify_event(struct power_supply *psy, enum cm_event_types type, break; case CM_EVENT_UNKNOWN: case CM_EVENT_OTHERS: - uevent_notify(cm, msg ? msg : default_event_names[type]); + power_supply_changed(cm->charger_psy); break; default: dev_err(cm->dev, "%s: type not specified\n", __func__); From patchwork Thu May 14 23:04:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Bakker X-Patchwork-Id: 11550137 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BFBBF14E3 for ; Thu, 14 May 2020 23:05:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7850204EA for ; Thu, 14 May 2020 23:05:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728863AbgENXFj (ORCPT ); Thu, 14 May 2020 19:05:39 -0400 Received: from mail-bn8nam12olkn2108.outbound.protection.outlook.com ([40.92.21.108]:20142 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728508AbgENXFL (ORCPT ); Thu, 14 May 2020 19:05:11 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n+oD2qsV3IsjlI2vZ66rpKeZ7LBWeLwjDqPGsKoOo7ZhKEo53M+FMxK2ywa0cNChWzISLEVUf/A+cXKkBU081aRVG6xBxoNMa2W0DUX9CSe6VXHnV3KancyCrKYjN/8VByzAGOZDpJpnzRXglqhdj4UqoqcCFOLeIAZ+J+DZLMM+US6iEFOQJiI+srMPx4FNBdEYju4Fqzs6rb8EOY4KaWmkPnaZ7oON2iOo5bLUOWCGO0iu92PHa4Y2NMwcYNQCrJQX8fWhXa0QQHqAvFbqENfUnwO1aOBOe4t9zsJw3msIt1V4RrKAAlHv+oNkqWuABUo3h3vDzwjbeUywYBVYaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lyjKg82RDXOCg9HNE8hwuthY+JJZ6CRJdrgIFzS+iNo=; b=RbnFLpQZeIDa1Q1Ov+j3FgFtvu2MLKK/YThLyRGh/4QS4IaRtOcM3GfJciBQ2DJSszt+mXXM5P0zUSNXnEQLXQxBNCEG1NO7/FiY5zekj2Mt0cvv6/FfdKNwUPUPPtwgafRaNW9eie8vlKdbcWiRQqeT6sw6EHojR5rtUzkyz51cm9E3DwbFnmpMBbxRWsjtssZ7eNqP58NhE/BXw9mm/GJzXeAmv03eIbU+r57IhbkhtwX6ieTMPuYoNoAxeQC5MJE8FAOBD5z6gAQwwYs5UKRNkFsHsQIn92BOLBkYMFtbwIArybwI6GQy4WvxOwNgGQDEX+3K2VfuflzUhHTI0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=live.ca; dmarc=pass action=none header.from=live.ca; dkim=pass header.d=live.ca; arc=none Received: from MW2NAM12FT003.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::48) by MW2NAM12HT165.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::320) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.11; Thu, 14 May 2020 23:05:07 +0000 Received: from BN6PR04MB0660.namprd04.prod.outlook.com (2a01:111:e400:fc65::44) by MW2NAM12FT003.mail.protection.outlook.com (2a01:111:e400:fc65::70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11 via Frontend Transport; Thu, 14 May 2020 23:05:07 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:2016BDC7D35C5A6C359D7E9001B4EDC8631378461CFA9E445D7FF99FCAA2B433;UpperCasedChecksum:6018D499545EF9CA234DD02394934E579641570A08EE1F3EA4A34A0726C73216;SizeAsReceived:7957;Count:50 Received: from BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc]) by BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc%6]) with mapi id 15.20.3000.022; Thu, 14 May 2020 23:05:07 +0000 From: Jonathan Bakker To: sre@kernel.org, krzk@kernel.org, jonghwa3.lee@samsung.com, tglx@linutronix.de, kstewart@linuxfoundation.org, baolin.wang7@gmail.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , Jonathan Bakker Subject: [PATCH 02/10] power: supply: charger-manager: Remove cm_notify_event function Date: Thu, 14 May 2020 16:04:27 -0700 Message-ID: X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514230435.11798-1-xc-racer2@live.ca> References: <20200514230435.11798-1-xc-racer2@live.ca> X-ClientProxiedBy: MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) To BN6PR04MB0660.namprd04.prod.outlook.com (2603:10b6:404:d9::21) X-Microsoft-Original-Message-ID: <20200514230435.11798-3-xc-racer2@live.ca> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jon-hp-6570b.telus (2001:569:fb68:9c00:8067:f823:1e15:7520) by MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26 via Frontend Transport; Thu, 14 May 2020 23:05:05 +0000 X-Mailer: git-send-email 2.20.1 X-Microsoft-Original-Message-ID: <20200514230435.11798-3-xc-racer2@live.ca> X-TMN: [xV0L5Z9tMl1BQBrVnn0IYO2sSh5535YaB7QpL7I3vEApBrFNhWEMqDXDGOUhWZo1] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 91cd1ee8-1f5e-4fb2-2468-08d7f85b3e71 X-MS-TrafficTypeDiagnostic: MW2NAM12HT165: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U/8jDoMB5T4IH3FjWgOgHjkbRzf2TWk6hDoXQ+7oghldWYXs3sYbVYS8/jvo9h70ezrUk4TCqRd+utC3/51P+eJrNyu8aW+lgq6GpB2i7Y0JiKrPVf4rmlmJXJNp0tJiw/W+qzRdPU8tY8mX7W3Ukae7lddrLBN9bdHYitzr/KELzdfhl1UBP+I5Gqkl3kJrVPdf5CZL+5BKhQdeMSm07Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR04MB0660.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: vNj+264zHEsFFjpQ7zvYkxF83FqUXm76HPVebLT5vPxfNlp46U8biAIrvnH7NqryeBl15DMwQLhShcv6KIbDUq9E87fSTueqFLmMFyp/QKwWIGkcXez3iFMPwtn+/DjAFJho1/N93iwPR1npNKUF/SukHa+FWLFGSJz1VWhNgMoe4WuPLnlwszSoIUXQvhjBP8RomHInIFKAk3KRAWyImw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91cd1ee8-1f5e-4fb2-2468-08d7f85b3e71 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 23:05:07.3087 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM12HT165 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Jonghwa Lee cm_notify_event() was introduced to get an event associated with the battery status externally (ie in board files), but no one ever used it. Moreover it makes charger manager driver more complicated. Drop the function and all data related to it to simplify the driver. Signed-off-by: Jonghwa Lee Signed-off-by: Krzysztof Kozlowski Signed-off-by: Jonathan Bakker --- drivers/power/supply/charger-manager.c | 183 ++----------------------- include/linux/power/charger-manager.h | 33 +---- 2 files changed, 16 insertions(+), 200 deletions(-) diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c index 330185b960a5..413f291fda5f 100644 --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -434,25 +434,18 @@ static int try_charger_restart(struct charger_manager *cm) /** * fullbatt_vchk - Check voltage drop some times after "FULL" event. - * @work: the work_struct appointing the function * - * If a user has designated "fullbatt_vchkdrop_ms/uV" values with + * If a user has designated "fullbatt_vchkdrop_uV" values with * charger_desc, Charger Manager checks voltage drop after the battery * "FULL" event. It checks whether the voltage has dropped more than * fullbatt_vchkdrop_uV by calling this function after fullbatt_vchkrop_ms. */ -static void fullbatt_vchk(struct work_struct *work) +static void fullbatt_vchk(struct charger_manager *cm) { - struct delayed_work *dwork = to_delayed_work(work); - struct charger_manager *cm = container_of(dwork, - struct charger_manager, fullbatt_vchk_work); struct charger_desc *desc = cm->desc; int batt_uV, err, diff; - /* remove the appointment for fullbatt_vchk */ - cm->fullbatt_vchk_jiffies_at = 0; - - if (!desc->fullbatt_vchkdrop_uV || !desc->fullbatt_vchkdrop_ms) + if (!desc->fullbatt_vchkdrop_uV) return; err = get_batt_uV(cm, &batt_uV); @@ -588,9 +581,11 @@ static int cm_check_thermal_status(struct charger_manager *cm) } if (temp > upper_limit) - ret = CM_EVENT_BATT_OVERHEAT; + ret = CM_BATT_OVERHEAT; else if (temp < lower_limit) - ret = CM_EVENT_BATT_COLD; + ret = CM_BATT_COLD; + else + ret = CM_BATT_OK; return ret; } @@ -635,7 +630,7 @@ static bool _cm_monitor(struct charger_manager *cm) */ } else if (!cm->emergency_stop && is_ext_pwr_online(cm) && !cm->charger_enabled) { - fullbatt_vchk(&cm->fullbatt_vchk_work.work); + fullbatt_vchk(cm); /* * Check whether fully charged state to protect overcharge @@ -648,7 +643,7 @@ static bool _cm_monitor(struct charger_manager *cm) try_charger_enable(cm, false); - fullbatt_vchk(&cm->fullbatt_vchk_work.work); + fullbatt_vchk(cm); } else { cm->emergency_stop = 0; if (is_ext_pwr_online(cm)) { @@ -750,66 +745,6 @@ static void cm_monitor_poller(struct work_struct *work) schedule_work(&setup_polling); } -/** - * fullbatt_handler - Event handler for CM_EVENT_BATT_FULL - * @cm: the Charger Manager representing the battery. - */ -static void fullbatt_handler(struct charger_manager *cm) -{ - struct charger_desc *desc = cm->desc; - - if (!desc->fullbatt_vchkdrop_uV || !desc->fullbatt_vchkdrop_ms) - goto out; - - if (cm_suspended) - device_set_wakeup_capable(cm->dev, true); - - mod_delayed_work(cm_wq, &cm->fullbatt_vchk_work, - msecs_to_jiffies(desc->fullbatt_vchkdrop_ms)); - cm->fullbatt_vchk_jiffies_at = jiffies + msecs_to_jiffies( - desc->fullbatt_vchkdrop_ms); - - if (cm->fullbatt_vchk_jiffies_at == 0) - cm->fullbatt_vchk_jiffies_at = 1; - -out: - dev_info(cm->dev, "EVENT_HANDLE: Battery Fully Charged\n"); - power_supply_changed(cm->charger_psy); -} - -/** - * battout_handler - Event handler for CM_EVENT_BATT_OUT - * @cm: the Charger Manager representing the battery. - */ -static void battout_handler(struct charger_manager *cm) -{ - if (cm_suspended) - device_set_wakeup_capable(cm->dev, true); - - if (!is_batt_present(cm)) { - dev_emerg(cm->dev, "Battery Pulled Out!\n"); - power_supply_changed(cm->charger_psy); - } else { - power_supply_changed(cm->charger_psy); - } -} - -/** - * misc_event_handler - Handler for other events - * @cm: the Charger Manager representing the battery. - * @type: the Charger Manager representing the battery. - */ -static void misc_event_handler(struct charger_manager *cm, - enum cm_event_types type) -{ - if (cm_suspended) - device_set_wakeup_capable(cm->dev, true); - - if (is_polling_required(cm) && cm->desc->polling_interval_ms) - schedule_work(&setup_polling); - power_supply_changed(cm->charger_psy); -} - static int charger_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -1000,21 +935,6 @@ static bool cm_setup_timer(void) mutex_lock(&cm_list_mtx); list_for_each_entry(cm, &cm_list, entry) { - unsigned int fbchk_ms = 0; - - /* fullbatt_vchk is required. setup timer for that */ - if (cm->fullbatt_vchk_jiffies_at) { - fbchk_ms = jiffies_to_msecs(cm->fullbatt_vchk_jiffies_at - - jiffies); - if (time_is_before_eq_jiffies( - cm->fullbatt_vchk_jiffies_at) || - msecs_to_jiffies(fbchk_ms) < CM_JIFFIES_SMALL) { - fullbatt_vchk(&cm->fullbatt_vchk_work.work); - fbchk_ms = 0; - } - } - CM_MIN_VALID(wakeup_ms, fbchk_ms); - /* Skip if polling is not required for this CM */ if (!is_polling_required(cm) && !cm->emergency_stop) continue; @@ -1422,8 +1342,6 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev) of_property_read_u32(np, "cm-poll-interval", &desc->polling_interval_ms); - of_property_read_u32(np, "cm-fullbatt-vchkdrop-ms", - &desc->fullbatt_vchkdrop_ms); of_property_read_u32(np, "cm-fullbatt-vchkdrop-volt", &desc->fullbatt_vchkdrop_uV); of_property_read_u32(np, "cm-fullbatt-voltage", &desc->fullbatt_uV); @@ -1583,9 +1501,8 @@ static int charger_manager_probe(struct platform_device *pdev) if (desc->fullbatt_uV == 0) { dev_info(&pdev->dev, "Ignoring full-battery voltage threshold as it is not supplied\n"); } - if (!desc->fullbatt_vchkdrop_ms || !desc->fullbatt_vchkdrop_uV) { + if (!desc->fullbatt_vchkdrop_uV) { dev_info(&pdev->dev, "Disabling full-battery voltage drop checking mechanism as it is not supplied\n"); - desc->fullbatt_vchkdrop_ms = 0; desc->fullbatt_vchkdrop_uV = 0; } if (desc->fullbatt_soc == 0) { @@ -1689,8 +1606,6 @@ static int charger_manager_probe(struct platform_device *pdev) } power_supply_put(fuel_gauge); - INIT_DELAYED_WORK(&cm->fullbatt_vchk_work, fullbatt_vchk); - /* Register sysfs entry for charger(regulator) */ ret = charger_manager_prepare_sysfs(cm); if (ret < 0) { @@ -1830,8 +1745,6 @@ static bool cm_need_to_awake(void) static int cm_suspend_prepare(struct device *dev) { - struct charger_manager *cm = dev_get_drvdata(dev); - if (cm_need_to_awake()) return -EBUSY; @@ -1843,7 +1756,6 @@ static int cm_suspend_prepare(struct device *dev) if (cm_timer_set) { cancel_work_sync(&setup_polling); cancel_delayed_work_sync(&cm_monitor_work); - cancel_delayed_work(&cm->fullbatt_vchk_work); } return 0; @@ -1868,31 +1780,6 @@ static void cm_suspend_complete(struct device *dev) _cm_monitor(cm); - /* Re-enqueue delayed work (fullbatt_vchk_work) */ - if (cm->fullbatt_vchk_jiffies_at) { - unsigned long delay = 0; - unsigned long now = jiffies + CM_JIFFIES_SMALL; - - if (time_after_eq(now, cm->fullbatt_vchk_jiffies_at)) { - delay = (unsigned long)((long)now - - (long)(cm->fullbatt_vchk_jiffies_at)); - delay = jiffies_to_msecs(delay); - } else { - delay = 0; - } - - /* - * Account for cm_suspend_duration_ms with assuming that - * timer stops in suspend. - */ - if (delay > cm_suspend_duration_ms) - delay -= cm_suspend_duration_ms; - else - delay = 0; - - queue_delayed_work(cm_wq, &cm->fullbatt_vchk_work, - msecs_to_jiffies(delay)); - } device_set_wakeup_capable(cm->dev, false); } @@ -1934,56 +1821,6 @@ static void __exit charger_manager_cleanup(void) } module_exit(charger_manager_cleanup); -/** - * cm_notify_event - charger driver notify Charger Manager of charger event - * @psy: pointer to instance of charger's power_supply - * @type: type of charger event - * @msg: optional message passed to uevent_notify function - */ -void cm_notify_event(struct power_supply *psy, enum cm_event_types type, - char *msg) -{ - struct charger_manager *cm; - bool found_power_supply = false; - - if (psy == NULL) - return; - - mutex_lock(&cm_list_mtx); - list_for_each_entry(cm, &cm_list, entry) { - if (match_string(cm->desc->psy_charger_stat, -1, - psy->desc->name) >= 0) { - found_power_supply = true; - break; - } - } - mutex_unlock(&cm_list_mtx); - - if (!found_power_supply) - return; - - switch (type) { - case CM_EVENT_BATT_FULL: - fullbatt_handler(cm); - break; - case CM_EVENT_BATT_OUT: - battout_handler(cm); - break; - case CM_EVENT_BATT_IN: - case CM_EVENT_EXT_PWR_IN_OUT ... CM_EVENT_CHG_START_STOP: - misc_event_handler(cm, type); - break; - case CM_EVENT_UNKNOWN: - case CM_EVENT_OTHERS: - power_supply_changed(cm->charger_psy); - break; - default: - dev_err(cm->dev, "%s: type not specified\n", __func__); - break; - } -} -EXPORT_SYMBOL_GPL(cm_notify_event); - MODULE_AUTHOR("MyungJoo Ham "); MODULE_DESCRIPTION("Charger Manager"); MODULE_LICENSE("GPL"); diff --git a/include/linux/power/charger-manager.h b/include/linux/power/charger-manager.h index ae94dcebd936..3a98837684e3 100644 --- a/include/linux/power/charger-manager.h +++ b/include/linux/power/charger-manager.h @@ -31,16 +31,10 @@ enum polling_modes { CM_POLL_CHARGING_ONLY, }; -enum cm_event_types { - CM_EVENT_UNKNOWN = 0, - CM_EVENT_BATT_FULL, - CM_EVENT_BATT_IN, - CM_EVENT_BATT_OUT, - CM_EVENT_BATT_OVERHEAT, - CM_EVENT_BATT_COLD, - CM_EVENT_EXT_PWR_IN_OUT, - CM_EVENT_CHG_START_STOP, - CM_EVENT_OTHERS, +enum cm_batt_temp { + CM_BATT_OK = 0, + CM_BATT_OVERHEAT, + CM_BATT_COLD, }; /** @@ -131,11 +125,10 @@ struct charger_regulator { * @psy_name: the name of power-supply-class for charger manager * @polling_mode: * Determine which polling mode will be used - * @fullbatt_vchkdrop_ms: * @fullbatt_vchkdrop_uV: * Check voltage drop after the battery is fully charged. - * If it has dropped more than fullbatt_vchkdrop_uV after - * fullbatt_vchkdrop_ms, CM will restart charging. + * If it has dropped more than fullbatt_vchkdrop_uV + * CM will restart charging. * @fullbatt_uV: voltage in microvolt * If VBATT >= fullbatt_uV, it is assumed to be full. * @fullbatt_soc: state of Charge in % @@ -172,7 +165,6 @@ struct charger_desc { enum polling_modes polling_mode; unsigned int polling_interval_ms; - unsigned int fullbatt_vchkdrop_ms; unsigned int fullbatt_vchkdrop_uV; unsigned int fullbatt_uV; unsigned int fullbatt_soc; @@ -211,9 +203,6 @@ struct charger_desc { * @charger_stat: array of power_supply for chargers * @tzd_batt : thermal zone device for battery * @charger_enabled: the state of charger - * @fullbatt_vchk_jiffies_at: - * jiffies at the time full battery check will occur. - * @fullbatt_vchk_work: work queue for full battery check * @emergency_stop: * When setting true, stop charging * @psy_name_buf: the name of power-supply-class for charger manager @@ -235,9 +224,6 @@ struct charger_manager { #endif bool charger_enabled; - unsigned long fullbatt_vchk_jiffies_at; - struct delayed_work fullbatt_vchk_work; - int emergency_stop; char psy_name_buf[PSY_NAME_MAX + 1]; @@ -248,11 +234,4 @@ struct charger_manager { u64 charging_end_time; }; -#if IS_ENABLED(CONFIG_CHARGER_MANAGER) -extern void cm_notify_event(struct power_supply *psy, - enum cm_event_types type, char *msg); -#else -static inline void cm_notify_event(struct power_supply *psy, - enum cm_event_types type, char *msg) { } -#endif #endif /* _CHARGER_MANAGER_H */ From patchwork Thu May 14 23:04:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Bakker X-Patchwork-Id: 11550121 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD0C3912 for ; Thu, 14 May 2020 23:05:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA3AC20748 for ; Thu, 14 May 2020 23:05:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729054AbgENXFL (ORCPT ); Thu, 14 May 2020 19:05:11 -0400 Received: from mail-mw2nam12olkn2106.outbound.protection.outlook.com ([40.92.23.106]:25648 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729030AbgENXFK (ORCPT ); Thu, 14 May 2020 19:05:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aLVLYC9nvW8X8/JMbhT6M1UnikqLvDY6Lb/fR474DHDEffIdrZa/J/tuQXIKvnABI328ZuxtDryUGqMUJDzmGr55rNNQX7AUTgZns3L0ngdgFOYTbblUl9+0u1Bp7pzobOUQOVyb1anO1EDUxKuciSoD2p8fsZ2xGc6gAsIlw3u/6RiA2rFnaVllrf/k64+rfO5e5s2emAz7fKNReI8Nm2CcHEbblszv9LYsy7+64l3gWjtIPD0cFMR+1I2jqkHX9Ljoe5uLkFB2ZQEd5s7mKgXG+Xfpd94vxVZrgx4LDDxICo8SySrke35mHqS+0PJcosjgUAJ41w2WFOHUiC59qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QLomBpgXv/TDUtX34CbzmZ3HlSD3S1fzXXzPwtYsxso=; b=HOFuGOVDECtZtLX5cAAnj314JCyAfo3a78mNEYlti1u6uNonMjqlxRAzKFsXqSH0MfgpJ4DfwZ/ua5AHxuHT+1jiIOpcadCc7QHLzvyf3KOcriCp3skyGFoaKeW76bpzBkT1vD4sGvOuG8L608wQoKy7iZuSNfSIxV5hKaDmFBDnNIp4sN4zlTkKUscd3OqkImIsbYeJzk0M+CXkidmqx7dUyRsEy1KZ2gnzRyFvTLfoc0rOwW+AEXIexh3Rba6U3iRfdh4woGftWDLH7YDXR3/5b5Aut5I8XTrzJKengJlG4dMIQ3fuMcf8eeaAuOheGS/bVmsgrU4nZkxeGq70ZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=live.ca; dmarc=pass action=none header.from=live.ca; dkim=pass header.d=live.ca; arc=none Received: from MW2NAM12FT003.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::40) by MW2NAM12HT204.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11; Thu, 14 May 2020 23:05:09 +0000 Received: from BN6PR04MB0660.namprd04.prod.outlook.com (2a01:111:e400:fc65::44) by MW2NAM12FT003.mail.protection.outlook.com (2a01:111:e400:fc65::70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11 via Frontend Transport; Thu, 14 May 2020 23:05:09 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:64CBFC3109C95C9FCBD57A6799AA931C810E773B695283F3A3641466A59781AC;UpperCasedChecksum:17975E63A85A75CD90A3DDC234C1FBC63FC781E611BF75CB3B850DE16DE0F16E;SizeAsReceived:7865;Count:50 Received: from BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc]) by BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc%6]) with mapi id 15.20.3000.022; Thu, 14 May 2020 23:05:08 +0000 From: Jonathan Bakker To: sre@kernel.org, krzk@kernel.org, jonghwa3.lee@samsung.com, tglx@linutronix.de, kstewart@linuxfoundation.org, baolin.wang7@gmail.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Bakker Subject: [PATCH 03/10] power: supply: charger-manager: Always use POWER_SUPPLY_PROP_TEMP Date: Thu, 14 May 2020 16:04:28 -0700 Message-ID: X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514230435.11798-1-xc-racer2@live.ca> References: <20200514230435.11798-1-xc-racer2@live.ca> X-ClientProxiedBy: MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) To BN6PR04MB0660.namprd04.prod.outlook.com (2603:10b6:404:d9::21) X-Microsoft-Original-Message-ID: <20200514230435.11798-4-xc-racer2@live.ca> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jon-hp-6570b.telus (2001:569:fb68:9c00:8067:f823:1e15:7520) by MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26 via Frontend Transport; Thu, 14 May 2020 23:05:07 +0000 X-Mailer: git-send-email 2.20.1 X-Microsoft-Original-Message-ID: <20200514230435.11798-4-xc-racer2@live.ca> X-TMN: [yDx9y3RCGQmBAsPKlcjBN6IkC4h43GEhmkQKsM/wuvmI7hcTOrSOrrQj5QjGHG5+] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: d49610f8-b4d8-4617-06bc-08d7f85b3f5c X-MS-TrafficTypeDiagnostic: MW2NAM12HT204: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2A6/MF1kAHsYuwQs/+VUj94zUE9CLuXQTeyuocBo6UCsYw0GxPcKq9ELw4y+HD0w44xUc6YnjPE5X0P9tO63J1sHhtCWC+BwXcEqYAWB89yHpMtlTDMvvuYFPWpn0tXL7xfemoClYIJDMi2QjlIEnrPTHt3wPsD5qWARa9Rh+3SotU9/z4RcREmVfbMwxi1+cRmVDIoP9IZANED/NOb4hg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR04MB0660.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: aJ1pJZ5qNMvJfvKEVhwsdzUUBrdMYSPBGK1DWKQBi5IuyHgueMALySGQ3I32i2hJDnXrw7dIkqAXHRWx2SsWXrLgxPP/fPpdKRcJd2X5f2YB1yUD2Jeow+gQElc8MxonZ7jGDWSdC6Cafcea8fZtqbQpM6rO10TgnWls79b2jxLaA/kQmTQ2nn2pElHDRxvTiJr9MbIVWlokQrgvbcCw8A== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d49610f8-b4d8-4617-06bc-08d7f85b3f5c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 23:05:08.9060 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM12HT204 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We were using POWER_SUPPLY_PROP_TEMP if the temperature was coming via the fuel gauge and POWER_SUPPLY_PROP_TEMP_AMBIENT if it was coming via the thermal framework. Since they're mutually exclusive in the driver and we don't know if the thermal framework is ambient or not, unify them both to use POWER_SUPPLY_PROP_TEMP. Signed-off-by: Jonathan Bakker --- drivers/power/supply/charger-manager.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c index 413f291fda5f..6a5ae1d0ef92 100644 --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -791,7 +791,6 @@ static int charger_get_property(struct power_supply *psy, POWER_SUPPLY_PROP_CURRENT_NOW, val); break; case POWER_SUPPLY_PROP_TEMP: - case POWER_SUPPLY_PROP_TEMP_AMBIENT: return cm_get_battery_temperature(cm, &val->intval); case POWER_SUPPLY_PROP_CAPACITY: if (!is_batt_present(cm)) { @@ -899,8 +898,7 @@ static enum power_supply_property default_charger_props[] = { * Optional properties are: * POWER_SUPPLY_PROP_CHARGE_NOW, * POWER_SUPPLY_PROP_CURRENT_NOW, - * POWER_SUPPLY_PROP_TEMP, and - * POWER_SUPPLY_PROP_TEMP_AMBIENT, + * POWER_SUPPLY_PROP_TEMP, */ }; @@ -1298,7 +1296,7 @@ static int cm_init_thermal_data(struct charger_manager *cm, /* Use external thermometer */ cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] = - POWER_SUPPLY_PROP_TEMP_AMBIENT; + POWER_SUPPLY_PROP_TEMP; cm->charger_psy_desc.num_properties++; cm->desc->measure_battery_temp = true; ret = 0; From patchwork Thu May 14 23:04:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Bakker X-Patchwork-Id: 11550123 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 367DC912 for ; Thu, 14 May 2020 23:05:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22093206D8 for ; Thu, 14 May 2020 23:05:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729085AbgENXFN (ORCPT ); Thu, 14 May 2020 19:05:13 -0400 Received: from mail-mw2nam12olkn2088.outbound.protection.outlook.com ([40.92.23.88]:20065 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729057AbgENXFM (ORCPT ); Thu, 14 May 2020 19:05:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bcfxD/lOGLTaRbGcyTw1aITMBWJyl8WT2b/aGvtv5QnCjfBdNPMTtUzk4Ilb3Fhcj2/j+lpLnKGLdpmtXFO8XdRueUxog2pRMNf1P9CgScUq1CIWBnX79xY+oCzlWrWHTWxW6FeqclwQbZRt3+h7oUJTjTd+Hj5iioED8QPTyECJi3X7Pq4pgOunqorMBoVVgcLKxk9lKxc/qPau0Cs9XWY8TUeJrak9r8XBGVXYtESEm+oD5oTXY/1LDJ0rTUkZaB8zxTVvm1lx4oEU4amqvkwSLzecRr2AgUge9tdIUrvyQAs92dqCcJivbqmO1cth06yDknJc6UkTnQtKeoLubg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8OffufdBNdxoO5LBkJSaKGrBgbpE2ZCwE5ssP6HjtlE=; b=j2kCWhy65eKP2vPJ1/8fcUP260p2FUw/58y0VE/VUmPDxojH3yB8rxVRlPdQMpA61X7TzBp8+vSdPT+H19pZQFBNBNolse8YavXVQ+xNj1aws0EC29K5uAnC3J0Lx2kOSC0+H1c4VboRgxAHnebLm3USka8PNaErKMD+raccHRHJcT6aewE1c3xNlh9dkDPwfhyjvT+kWaBLNKgzF5kGTlliaAlH85JA+nxIla2o+RKc9KPsWbbi65dIv9pHwVu8cs4SUJbNE3Sv2EC3SvjDt25hq5oYQ50ql5Ovd2E3ueWFTyrykD47mIGiqWBmMrGrL1fcAZ3MzH7jjXGpSkO7bQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=live.ca; dmarc=pass action=none header.from=live.ca; dkim=pass header.d=live.ca; arc=none Received: from MW2NAM12FT003.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::4d) by MW2NAM12HT035.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11; Thu, 14 May 2020 23:05:10 +0000 Received: from BN6PR04MB0660.namprd04.prod.outlook.com (2a01:111:e400:fc65::44) by MW2NAM12FT003.mail.protection.outlook.com (2a01:111:e400:fc65::70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11 via Frontend Transport; Thu, 14 May 2020 23:05:10 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:E8855A4EEBA158DCE1388606AFE8029E026DBD8F77496260270EF58ACF993A0A;UpperCasedChecksum:078FA253B621B01367A20960D3B92B4EFCD542541F80AC619F2BA83EAE804E2C;SizeAsReceived:7958;Count:50 Received: from BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc]) by BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc%6]) with mapi id 15.20.3000.022; Thu, 14 May 2020 23:05:10 +0000 From: Jonathan Bakker To: sre@kernel.org, krzk@kernel.org, jonghwa3.lee@samsung.com, tglx@linutronix.de, kstewart@linuxfoundation.org, baolin.wang7@gmail.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , Jonathan Bakker Subject: [PATCH 04/10] power: supply: charger-manager: Correct usage of CHARGE_NOW/FULL Date: Thu, 14 May 2020 16:04:29 -0700 Message-ID: X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514230435.11798-1-xc-racer2@live.ca> References: <20200514230435.11798-1-xc-racer2@live.ca> X-ClientProxiedBy: MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) To BN6PR04MB0660.namprd04.prod.outlook.com (2603:10b6:404:d9::21) X-Microsoft-Original-Message-ID: <20200514230435.11798-5-xc-racer2@live.ca> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jon-hp-6570b.telus (2001:569:fb68:9c00:8067:f823:1e15:7520) by MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26 via Frontend Transport; Thu, 14 May 2020 23:05:09 +0000 X-Mailer: git-send-email 2.20.1 X-Microsoft-Original-Message-ID: <20200514230435.11798-5-xc-racer2@live.ca> X-TMN: [eynva0AuKMosR+KJZSVdTMPwqJEOBoLjVwGN3J8i66dDb+qFmSKFJ9xK5nCSIx7J] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 2ea06532-6b08-4e0a-f8d2-08d7f85b4074 X-MS-TrafficTypeDiagnostic: MW2NAM12HT035: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8MmEi1S8UgvawJHsBXbVTQBuQzF8bNaM2TkYmUnci8DVAiTsEhZmvskTkATC/us2B74Q/iXKkP6Ogx45EHpK9145KGEpnGXVDhyXhfXv0pLgJxt2ECZhv6+Hb9+CpBn4yuoWnimkJ7ApAUhPbzURvjCzrO5rlesucA9ACq/18krnG+nrnm2QNIqMWpZALdbPG47P3aiJmhgE6ZTc8TguSA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR04MB0660.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: r5r3NRGMvAL0HX/31WoCDl31CiGM7WiIiKNuz0rHPO69vddRAoZb89NLGvmCfNLvU50lBUzDZCxEhaqj2HPq/T4e3oGQoHFZ7luJUTcMxgVmimhNA55UWGkdvHB6GTDHJAtf7yi8GDOXH75LYJQK0i1GU9VHx0mEKYOKib1FUnKaPaM6lDEbkEScgmTSe24OGZTTs08i93U7E6duCyfLKQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2ea06532-6b08-4e0a-f8d2-08d7f85b4074 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 23:05:10.7362 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM12HT035 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Jonghwa Lee The POWER_SUPPLY_CHARGE_NOW/FULL property reflects battery's charges in uAh unit, but charger-manager has been used it wrongly as a status field. Signed-off-by: Jonghwa Lee Signed-off-by: Krzysztof Kozlowski Signed-off-by: Jonathan Bakker --- drivers/power/supply/charger-manager.c | 40 ++++++++------------------ 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c index 6a5ae1d0ef92..80d1699c938a 100644 --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -846,35 +846,13 @@ static int charger_get_property(struct power_supply *psy, val->intval = 0; break; case POWER_SUPPLY_PROP_CHARGE_FULL: - if (is_full_charged(cm)) - val->intval = 1; - else - val->intval = 0; - ret = 0; - break; case POWER_SUPPLY_PROP_CHARGE_NOW: - if (is_charging(cm)) { - fuel_gauge = power_supply_get_by_name( - cm->desc->psy_fuel_gauge); - if (!fuel_gauge) { - ret = -ENODEV; - break; - } - - ret = power_supply_get_property(fuel_gauge, - POWER_SUPPLY_PROP_CHARGE_NOW, - val); - if (ret) { - val->intval = 1; - ret = 0; - } else { - /* If CHARGE_NOW is supplied, use it */ - val->intval = (val->intval > 0) ? - val->intval : 1; - } - } else { - val->intval = 0; + fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge); + if (!fuel_gauge) { + ret = -ENODEV; + break; } + ret = power_supply_get_property(fuel_gauge, psp, val); break; default: return -EINVAL; @@ -893,9 +871,9 @@ static enum power_supply_property default_charger_props[] = { POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_CAPACITY, POWER_SUPPLY_PROP_ONLINE, - POWER_SUPPLY_PROP_CHARGE_FULL, /* * Optional properties are: + * POWER_SUPPLY_PROP_CHARGE_FULL, * POWER_SUPPLY_PROP_CHARGE_NOW, * POWER_SUPPLY_PROP_CURRENT_NOW, * POWER_SUPPLY_PROP_TEMP, @@ -1583,6 +1561,12 @@ static int charger_manager_probe(struct platform_device *pdev) desc->psy_fuel_gauge); return -ENODEV; } + if (!power_supply_get_property(fuel_gauge, + POWER_SUPPLY_PROP_CHARGE_FULL, &val)) { + cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] = + POWER_SUPPLY_PROP_CHARGE_FULL; + cm->charger_psy_desc.num_properties++; + } if (!power_supply_get_property(fuel_gauge, POWER_SUPPLY_PROP_CHARGE_NOW, &val)) { cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] = From patchwork Thu May 14 23:04:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Bakker X-Patchwork-Id: 11550135 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1ADF714F7 for ; Thu, 14 May 2020 23:05:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B6C7204EA for ; Thu, 14 May 2020 23:05:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729101AbgENXFR (ORCPT ); Thu, 14 May 2020 19:05:17 -0400 Received: from mail-bn8nam12olkn2054.outbound.protection.outlook.com ([40.92.21.54]:33120 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729089AbgENXFQ (ORCPT ); Thu, 14 May 2020 19:05:16 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jo5KZty/6gstHOjihVNK848jIxJMpRRl3Ka/k4iX6SPIog1/Z/ZEWpNNq+RwsO7ISLtTaM4f7ENMJOa14TJLhrL7Dk1vBUJto0Uj57kcUz510nh6ysNboGIykeuAXYbwugnomgXya+r7tkPQDjHrLUUd7vBeLQmCWsedOo7deOxCjmpAU2N355hWgpU5Q93gh+ZyCV88P+SdGLdrWtpB6y16pBK5r6VCgXLBi6v88NmLmgDvZ61SLYHsDD8ZRYk+sG9P2KqBEuby1kBpHHcp2/YnPqdA1vHCKgFDD510L0wjXKYiuThac98nhDoEjf7hnsQLX3fnVGlC54+iZRPvCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0/ojXOnyhyTbuZiHTpPWJRaeNoPwnXBkbesBz+CUR+s=; b=aivYGt5FnOSnbbjYzSV3dag1LR4ViqfWh56OQ9I66pJi+VY4BFhWfnkRqRqus+YdO4MW4MeDXGRLF1TfOxdmeH4CzsvOKAIb72C7tEBl1bzLPNIBuZ+Jo5LmrLoSOz4ASowORAp7Q8dBh6nIJjHy9X7EJwvhjTmnm1NWwaAxG8VLMDYV22ut0ouYURi7uJvRTSqAXhguVNOb6xWIfqj6fIvq4ZVOCmZA7YXQgaWyjLnHIyKf376b2fuj1qP0StNQoTlZOIwL6jTPWdITQR5X2ahmxWjQSnZ8dwPIj7s6lKJyvZuHUdA0iIuIwq6pdPiZHkef5UYVY7loMVj6XpKmyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=live.ca; dmarc=pass action=none header.from=live.ca; dkim=pass header.d=live.ca; arc=none Received: from MW2NAM12FT003.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::49) by MW2NAM12HT003.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11; Thu, 14 May 2020 23:05:12 +0000 Received: from BN6PR04MB0660.namprd04.prod.outlook.com (2a01:111:e400:fc65::44) by MW2NAM12FT003.mail.protection.outlook.com (2a01:111:e400:fc65::70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11 via Frontend Transport; Thu, 14 May 2020 23:05:12 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:46D2674C3E3ACD975D3F292E58B620A0DFF44ACFE61B0D6D3E7BFFFBB5F1250C;UpperCasedChecksum:CC5D7174DD7BE7353E7D8A0DFDD4DF185588120DBCAF1662CB3119E7018BCC9C;SizeAsReceived:7952;Count:50 Received: from BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc]) by BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc%6]) with mapi id 15.20.3000.022; Thu, 14 May 2020 23:05:12 +0000 From: Jonathan Bakker To: sre@kernel.org, krzk@kernel.org, jonghwa3.lee@samsung.com, tglx@linutronix.de, kstewart@linuxfoundation.org, baolin.wang7@gmail.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , Jonathan Bakker Subject: [PATCH 05/10] power: supply: charger-manager: Collect all power_supply_changed() calls Date: Thu, 14 May 2020 16:04:30 -0700 Message-ID: X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514230435.11798-1-xc-racer2@live.ca> References: <20200514230435.11798-1-xc-racer2@live.ca> X-ClientProxiedBy: MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) To BN6PR04MB0660.namprd04.prod.outlook.com (2603:10b6:404:d9::21) X-Microsoft-Original-Message-ID: <20200514230435.11798-6-xc-racer2@live.ca> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jon-hp-6570b.telus (2001:569:fb68:9c00:8067:f823:1e15:7520) by MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26 via Frontend Transport; Thu, 14 May 2020 23:05:11 +0000 X-Mailer: git-send-email 2.20.1 X-Microsoft-Original-Message-ID: <20200514230435.11798-6-xc-racer2@live.ca> X-TMN: [a2GnsS8BAg4aEnisxadQPAzfNz981r4B+n1d7Cac3tGaRxO8nVYlJAX2Ymkl2WGn] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: d7e296ba-7962-4981-9451-08d7f85b4188 X-MS-TrafficTypeDiagnostic: MW2NAM12HT003: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yA9ltyohT4tcbduNjZHwR0KrKwhx6KeUb1hbM28N7/I1KohAukyHmxXSmc+D99u6YS4Ar7WtkD0LJmv6zaXjSItai2gUjgKxNf4tF1Lb1HYqAwXpYb1Y3VMt5jfJJtpxL7UkI8lNcr+jF/mSMa0zMi8MNwnDeHeKjqCxKmznMoKQmT++flyITU5APhBtBgLdv3v/eKJOu+47SWxcITSh2Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR04MB0660.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: KVTmawHR+GpGWX62638HNetTw/tjxWPAuiFavgD/1Sy3YVktgI3fivD7u4aQasC6vYPIcxJ0en33x2jpy+DIoeuQY6BE3ktfDmNBUvjSZKWN6jkBbMOpultHHDQZkSHudbpz9qd9gORqFVMJqYE6ZIJq5+UAQTgjT5hhTbKDflavXY8KlFMtpbOMqKv3dlTP8sRtEzeAJvE67tungfTtkg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d7e296ba-7962-4981-9451-08d7f85b4188 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 23:05:12.5035 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM12HT003 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Jonghwa Lee Current charger-manager calls power_supply_changed() whenever charging status is changed. Remove the separated power_supply_changed() calls and let it be called at end of try_charger_enable() function which is called to set charging/discharging. Signed-off-by: Jonghwa Lee Signed-off-by: Krzysztof Kozlowski Signed-off-by: Jonathan Bakker --- drivers/power/supply/charger-manager.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c index 80d1699c938a..b2daab480eb3 100644 --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -406,8 +406,10 @@ static int try_charger_enable(struct charger_manager *cm, bool enable) } } - if (!err) + if (!err) { cm->charger_enabled = enable; + power_supply_changed(cm->charger_psy); + } return err; } @@ -460,10 +462,8 @@ static void fullbatt_vchk(struct charger_manager *cm) dev_info(cm->dev, "VBATT dropped %duV after full-batt\n", diff); - if (diff > desc->fullbatt_vchkdrop_uV) { + if (diff > desc->fullbatt_vchkdrop_uV) try_charger_restart(cm); - power_supply_changed(cm->charger_psy); - } } /** @@ -493,7 +493,6 @@ static int check_charging_duration(struct charger_manager *cm) if (duration > desc->charging_max_duration_ms) { dev_info(cm->dev, "Charging duration exceed %ums\n", desc->charging_max_duration_ms); - power_supply_changed(cm->charger_psy); try_charger_enable(cm, false); ret = true; } @@ -504,7 +503,6 @@ static int check_charging_duration(struct charger_manager *cm) is_ext_pwr_online(cm)) { dev_info(cm->dev, "Discharging duration exceed %ums\n", desc->discharging_max_duration_ms); - power_supply_changed(cm->charger_psy); try_charger_enable(cm, true); ret = true; } @@ -613,8 +611,7 @@ static bool _cm_monitor(struct charger_manager *cm) */ if (temp_alrt) { cm->emergency_stop = temp_alrt; - if (!try_charger_enable(cm, false)) - power_supply_changed(cm->charger_psy); + try_charger_enable(cm, false); /* * Check whole charging duration and discharging duration @@ -639,16 +636,13 @@ static bool _cm_monitor(struct charger_manager *cm) } else if (!cm->emergency_stop && is_full_charged(cm) && cm->charger_enabled) { dev_info(cm->dev, "EVENT_HANDLE: Battery Fully Charged\n"); - power_supply_changed(cm->charger_psy); - try_charger_enable(cm, false); fullbatt_vchk(cm); } else { cm->emergency_stop = 0; if (is_ext_pwr_online(cm)) { - if (!try_charger_enable(cm, true)) - power_supply_changed(cm->charger_psy); + try_charger_enable(cm, true); } } From patchwork Thu May 14 23:04:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Bakker X-Patchwork-Id: 11550133 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 05252139A for ; Thu, 14 May 2020 23:05:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7EC82065F for ; Thu, 14 May 2020 23:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729125AbgENXFU (ORCPT ); Thu, 14 May 2020 19:05:20 -0400 Received: from mail-mw2nam12olkn2105.outbound.protection.outlook.com ([40.92.23.105]:50784 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729057AbgENXFR (ORCPT ); Thu, 14 May 2020 19:05:17 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZY/CjIXNxvW2K0W0VUBLOCjMHyII0PP+40VJW3JroG8v3Yg3Q6yy+eeyEtZtVcyOphr16VvhTp5MwxZdvteg/zYbcQlBCcHlgsbSWfG3Yvertm4/g4nhw7K3aEWEKEhuVan1IK/gk4MBQ3e+fXxyOOlKazsIgMRgk5JccYzai5pEc8UyQjbbWMgF3bncdIgl5tYFnYIet0pGIQxEqtHGxS0mIWjigfjwBpjEtBHtF/n4oiXbxopQN1k9LJ25kufp/gihfoirBIgfa3+SOKOC5lD8uQF+2J3gZQLvswSOoTzlG0c+wdsforAtNrBxh5x20ndo5LdM2E5tNB+VC5kF/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mRhZL1bZkietTQ0o2ZfyTfRCGzEekdpIMS2F/8N8EX8=; b=Kk7/uCKX6UXuR2Yilfpk0aFlk3I0uO2aNvRjptM4oNwG8MxiB2zO7FB3HwIFxvDK2ByfFQQEMk14z8SiHEuTennlGw7zwuV3GHt3lpHR5tHdgEuNgpkGvSH12hcfOIYzyb0RDau3DoBawZtxNc7Lk4iRbE9p69ZbQNN0TyIPNvqx2PMRrjy5CKtEDzUYSSzMJQz9p+suT29BxN4DMByqMd6+BFFCfgzfUXaTzP6YOw6smy1iRerazySbUcV057LDHUzT2BMa4ZOSZ3NlYLF+SanwjjIwrMBoMHYezLPQmfvnoz6Uoka0wtCGZRu9bu1oYuZLb5B61W8RnMJJPgfj4g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=live.ca; dmarc=pass action=none header.from=live.ca; dkim=pass header.d=live.ca; arc=none Received: from MW2NAM12FT003.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::43) by MW2NAM12HT105.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11; Thu, 14 May 2020 23:05:14 +0000 Received: from BN6PR04MB0660.namprd04.prod.outlook.com (2a01:111:e400:fc65::44) by MW2NAM12FT003.mail.protection.outlook.com (2a01:111:e400:fc65::70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11 via Frontend Transport; Thu, 14 May 2020 23:05:14 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:9935C6736AFA23F056AE7BE382B566E572D625F1F2009748A3E144141AD3F898;UpperCasedChecksum:6D0E67D090ED02E3B819CFF61B9DE0BFA133034D6629F592DE6D8A2998A2665A;SizeAsReceived:7953;Count:50 Received: from BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc]) by BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc%6]) with mapi id 15.20.3000.022; Thu, 14 May 2020 23:05:14 +0000 From: Jonathan Bakker To: sre@kernel.org, krzk@kernel.org, jonghwa3.lee@samsung.com, tglx@linutronix.de, kstewart@linuxfoundation.org, baolin.wang7@gmail.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , Jonathan Bakker Subject: [PATCH 06/10] power: supply: charger-manager: Make decisions focussed on battery status Date: Thu, 14 May 2020 16:04:31 -0700 Message-ID: X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514230435.11798-1-xc-racer2@live.ca> References: <20200514230435.11798-1-xc-racer2@live.ca> X-ClientProxiedBy: MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) To BN6PR04MB0660.namprd04.prod.outlook.com (2603:10b6:404:d9::21) X-Microsoft-Original-Message-ID: <20200514230435.11798-7-xc-racer2@live.ca> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jon-hp-6570b.telus (2001:569:fb68:9c00:8067:f823:1e15:7520) by MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26 via Frontend Transport; Thu, 14 May 2020 23:05:12 +0000 X-Mailer: git-send-email 2.20.1 X-Microsoft-Original-Message-ID: <20200514230435.11798-7-xc-racer2@live.ca> X-TMN: [9qETSCHe94zv59gnv8EhDc5vAYzACONT9vzKhW+2B8HzcwZUXmP/dNYbmyL8Knl7] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 348835cb-4566-4a9e-5220-08d7f85b42a7 X-MS-TrafficTypeDiagnostic: MW2NAM12HT105: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: B47m44DcrTLgpPgD8y5gA2vXyaRgX0TxHIFdsBYca7mv89W6FN8UBnZ68hanxRb92N79Jiu4QM5AGF4BtUZCHPTubXAxtyhE6aRQvwaDxcLBsJf0aTKt3Uvl+4uDWT4AKceiqEG/YJ+O7JJnXla5jj99NCU6fXvCjvmPcip9dkrLsfvl7VBlB2cyXPL9+L7JhinkWbynpB5RmeQm1AQMdA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR04MB0660.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: b4xoJh5i7pZ2HjqlWbOYC+8CQ5mJ++5QCm3c5Ez68fLu/id/8u/3MUksYDpHEVu8J1o4MYr+Ebl84Q2ZErjeOHXlCb8UxQbOyC3CGFvQ32VMd429tmd4J0fUQK8xtUr243vALsXjTbNhVAsRzqj9e2zs/d6EQqail1njUg8Vtp/uPvxZlFj9boPj31/Hebt6A3XKRBkSGOCiagVEdzpVDQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 348835cb-4566-4a9e-5220-08d7f85b42a7 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 23:05:14.4057 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM12HT105 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Jonghwa Lee cm_monitor(), where charging management starts, checks various charging condition sequentially to decide next charging operation. However, as it follows sequential process, cascaded if statements, it does some jobs which have already done in the previous stage. This results in a delay in decision making. Moreover, starting point of charging is spread all around which makes maintain code and debugging difficult. Both of the problems mentioned above become clean if it manages battery charging focusing on battery status not following sequential condition checking. Now, cm_monitor() moves battery state diagram and does the optimal operation for current state. As a result, it reduces whole monitoring time almost in half. Signed-off-by: Jonghwa Lee Signed-off-by: Krzysztof Kozlowski Signed-off-by: Jonathan Bakker --- drivers/power/supply/charger-manager.c | 181 +++++++++---------------- include/linux/power/charger-manager.h | 3 + 2 files changed, 64 insertions(+), 120 deletions(-) diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c index b2daab480eb3..9e4a7d368b08 100644 --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -271,6 +271,19 @@ static bool is_full_charged(struct charger_manager *cm) if (!fuel_gauge) return false; + /* Full, if it's over the fullbatt voltage */ + if (desc->fullbatt_uV > 0) { + ret = get_batt_uV(cm, &uV); + if (!ret) { + /* Battery is already full, checks voltage drop. */ + if (cm->battery_status == POWER_SUPPLY_STATUS_FULL + && desc->fullbatt_vchkdrop_uV) + uV += desc->fullbatt_vchkdrop_uV; + if (uV >= desc->fullbatt_uV) + return true; + } + } + if (desc->fullbatt_full_capacity > 0) { val.intval = 0; @@ -283,15 +296,6 @@ static bool is_full_charged(struct charger_manager *cm) } } - /* Full, if it's over the fullbatt voltage */ - if (desc->fullbatt_uV > 0) { - ret = get_batt_uV(cm, &uV); - if (!ret && uV >= desc->fullbatt_uV) { - is_full = true; - goto out; - } - } - /* Full, if the capacity is more than fullbatt_soc */ if (desc->fullbatt_soc > 0) { val.intval = 0; @@ -406,66 +410,12 @@ static int try_charger_enable(struct charger_manager *cm, bool enable) } } - if (!err) { + if (!err) cm->charger_enabled = enable; - power_supply_changed(cm->charger_psy); - } return err; } -/** - * try_charger_restart - Restart charging. - * @cm: the Charger Manager representing the battery. - * - * Restart charging by turning off and on the charger. - */ -static int try_charger_restart(struct charger_manager *cm) -{ - int err; - - if (cm->emergency_stop) - return -EAGAIN; - - err = try_charger_enable(cm, false); - if (err) - return err; - - return try_charger_enable(cm, true); -} - -/** - * fullbatt_vchk - Check voltage drop some times after "FULL" event. - * - * If a user has designated "fullbatt_vchkdrop_uV" values with - * charger_desc, Charger Manager checks voltage drop after the battery - * "FULL" event. It checks whether the voltage has dropped more than - * fullbatt_vchkdrop_uV by calling this function after fullbatt_vchkrop_ms. - */ -static void fullbatt_vchk(struct charger_manager *cm) -{ - struct charger_desc *desc = cm->desc; - int batt_uV, err, diff; - - if (!desc->fullbatt_vchkdrop_uV) - return; - - err = get_batt_uV(cm, &batt_uV); - if (err) { - dev_err(cm->dev, "%s: get_batt_uV error(%d)\n", __func__, err); - return; - } - - diff = desc->fullbatt_uV - batt_uV; - if (diff < 0) - return; - - dev_info(cm->dev, "VBATT dropped %duV after full-batt\n", diff); - - if (diff > desc->fullbatt_vchkdrop_uV) - try_charger_restart(cm); -} - /** * check_charging_duration - Monitor charging/discharging duration * @cm: the Charger Manager representing the battery. @@ -493,17 +443,14 @@ static int check_charging_duration(struct charger_manager *cm) if (duration > desc->charging_max_duration_ms) { dev_info(cm->dev, "Charging duration exceed %ums\n", desc->charging_max_duration_ms); - try_charger_enable(cm, false); ret = true; } - } else if (is_ext_pwr_online(cm) && !cm->charger_enabled) { + } else if (cm->battery_status == POWER_SUPPLY_STATUS_NOT_CHARGING) { duration = curr - cm->charging_end_time; - if (duration > desc->discharging_max_duration_ms && - is_ext_pwr_online(cm)) { + if (duration > desc->charging_max_duration_ms) { dev_info(cm->dev, "Discharging duration exceed %ums\n", desc->discharging_max_duration_ms); - try_charger_enable(cm, true); ret = true; } } @@ -585,9 +532,46 @@ static int cm_check_thermal_status(struct charger_manager *cm) else ret = CM_BATT_OK; + cm->emergency_stop = ret; + return ret; } +/** + * cm_get_target_status - Check current status and get next target status. + * @cm: the Charger Manager representing the battery. + */ +static int cm_get_target_status(struct charger_manager *cm) +{ + if (!is_ext_pwr_online(cm)) + return POWER_SUPPLY_STATUS_DISCHARGING; + + if (cm_check_thermal_status(cm)) { + /* Check if discharging duration exeeds limit. */ + if (check_charging_duration(cm)) + goto charging_ok; + return POWER_SUPPLY_STATUS_NOT_CHARGING; + } + + switch (cm->battery_status) { + case POWER_SUPPLY_STATUS_CHARGING: + /* Check if charging duration exeeds limit. */ + if (check_charging_duration(cm)) + return POWER_SUPPLY_STATUS_FULL; + fallthrough; + case POWER_SUPPLY_STATUS_FULL: + if (is_full_charged(cm)) + return POWER_SUPPLY_STATUS_FULL; + fallthrough; + default: + break; + } + +charging_ok: + /* Charging is allowed. */ + return POWER_SUPPLY_STATUS_CHARGING; +} + /** * _cm_monitor - Monitor the temperature and return true for exceptions. * @cm: the Charger Manager representing the battery. @@ -597,56 +581,18 @@ static int cm_check_thermal_status(struct charger_manager *cm) */ static bool _cm_monitor(struct charger_manager *cm) { - int temp_alrt; + int target; - temp_alrt = cm_check_thermal_status(cm); + target = cm_get_target_status(cm); - /* It has been stopped already */ - if (temp_alrt && cm->emergency_stop) - return false; - - /* - * Check temperature whether overheat or cold. - * If temperature is out of range normal state, stop charging. - */ - if (temp_alrt) { - cm->emergency_stop = temp_alrt; - try_charger_enable(cm, false); - - /* - * Check whole charging duration and discharging duration - * after full-batt. - */ - } else if (!cm->emergency_stop && check_charging_duration(cm)) { - dev_dbg(cm->dev, - "Charging/Discharging duration is out of range\n"); - /* - * Check dropped voltage of battery. If battery voltage is more - * dropped than fullbatt_vchkdrop_uV after fully charged state, - * charger-manager have to recharge battery. - */ - } else if (!cm->emergency_stop && is_ext_pwr_online(cm) && - !cm->charger_enabled) { - fullbatt_vchk(cm); + try_charger_enable(cm, (target == POWER_SUPPLY_STATUS_CHARGING)); - /* - * Check whether fully charged state to protect overcharge - * if charger-manager is charging for battery. - */ - } else if (!cm->emergency_stop && is_full_charged(cm) && - cm->charger_enabled) { - dev_info(cm->dev, "EVENT_HANDLE: Battery Fully Charged\n"); - try_charger_enable(cm, false); - - fullbatt_vchk(cm); - } else { - cm->emergency_stop = 0; - if (is_ext_pwr_online(cm)) { - try_charger_enable(cm, true); - } + if (cm->battery_status != target) { + cm->battery_status = target; + power_supply_changed(cm->charger_psy); } - return true; + return (cm->battery_status == POWER_SUPPLY_STATUS_NOT_CHARGING); } /** @@ -751,12 +697,7 @@ static int charger_get_property(struct power_supply *psy, switch (psp) { case POWER_SUPPLY_PROP_STATUS: - if (is_charging(cm)) - val->intval = POWER_SUPPLY_STATUS_CHARGING; - else if (is_ext_pwr_online(cm)) - val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; - else - val->intval = POWER_SUPPLY_STATUS_DISCHARGING; + val->intval = cm->battery_status; break; case POWER_SUPPLY_PROP_HEALTH: if (cm->emergency_stop > 0) diff --git a/include/linux/power/charger-manager.h b/include/linux/power/charger-manager.h index 3a98837684e3..c127dbe31e49 100644 --- a/include/linux/power/charger-manager.h +++ b/include/linux/power/charger-manager.h @@ -213,6 +213,7 @@ struct charger_desc { * saved status of battery before entering suspend-to-RAM * @charging_start_time: saved start time of enabling charging * @charging_end_time: saved end time of disabling charging + * @battery_status: Current battery status */ struct charger_manager { struct list_head entry; @@ -232,6 +233,8 @@ struct charger_manager { u64 charging_start_time; u64 charging_end_time; + + int battery_status; }; #endif /* _CHARGER_MANAGER_H */ From patchwork Thu May 14 23:04:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Bakker X-Patchwork-Id: 11550131 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C4838139A for ; Thu, 14 May 2020 23:05:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B4A132065F for ; Thu, 14 May 2020 23:05:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729133AbgENXFU (ORCPT ); Thu, 14 May 2020 19:05:20 -0400 Received: from mail-mw2nam12olkn2037.outbound.protection.outlook.com ([40.92.23.37]:4257 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729097AbgENXFR (ORCPT ); Thu, 14 May 2020 19:05:17 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h4MpOj4au/avLdApsNguau3ugkyL6Mlye71dySCybN5CcM7di9jv6YWthIe/uJ24IvqJOJYFVq4MHPnJwavQgMwXyaD9tLt4SeG87Q0bbppm1k3W+OPLAzu6ni56yJAi/HRsWN7rX4HhR559Cb9ZhRn8YYOBU+WM3oY28kBpMvWPWGtA2W5K0sKhoVtVSu/oyfwMn2KtYUp6IYHp2k95p5Z9YIbNSzftwtElwRHVcCsbBlT7DO2jcLVZ+L2cNVbvuSDDbxFCdWCYMGY50kYUN6JBD9b0XJekSrTQJkdtO4Zsu0605AA8u/AdojBEvdZgWDgTiIqnmLWLvLu/F++UEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=45eF6F9wzmrdPsALF3gGVxx5rQQ0x4YDjUHCdPPTock=; b=FIHt9haHy6aPwoL/cMXDcw2r4UkFDXivGzO8BodjERohUMR9Snp2dAePpqjuopM6ECUZwwSo/hR975EJ0wwjunyiwR908HpKsDxE7hEzOjdsm6MGYwdQ1WsyexX54RB3ewh5s7XJPKO4FkHmS21Zt2vmN9hnPypdYls3NcqUT5Z/Z9K9gF5ADBZmeIW2mAGI0aV7b+TxALyeafAtH66FN6YbAOtmD7Ug0u2Z+dcbRhQWcyRDD5NLxr7QCmBhZ/ADoo/kn7wff7dfva9zOc108FWC5d0AxMgxvhAXtNCG5t+Xrst/D8K8A3yXAZm1Hb3pthlJRD1IE1mZOvTxDAIrgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=live.ca; dmarc=pass action=none header.from=live.ca; dkim=pass header.d=live.ca; arc=none Received: from MW2NAM12FT003.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::4b) by MW2NAM12HT059.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11; Thu, 14 May 2020 23:05:16 +0000 Received: from BN6PR04MB0660.namprd04.prod.outlook.com (2a01:111:e400:fc65::44) by MW2NAM12FT003.mail.protection.outlook.com (2a01:111:e400:fc65::70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11 via Frontend Transport; Thu, 14 May 2020 23:05:16 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:59C9CA188537F6D8ACB66AA95174C9996E8EC3B61AF5541208BCF15FD54490A6;UpperCasedChecksum:3A0E72812C5B62A88117DAA944A2C93A79071114E0CC5730143DC55CAA5C8860;SizeAsReceived:7953;Count:50 Received: from BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc]) by BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc%6]) with mapi id 15.20.3000.022; Thu, 14 May 2020 23:05:16 +0000 From: Jonathan Bakker To: sre@kernel.org, krzk@kernel.org, jonghwa3.lee@samsung.com, tglx@linutronix.de, kstewart@linuxfoundation.org, baolin.wang7@gmail.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , Jonathan Bakker Subject: [PATCH 07/10] power: supply: charger-manager: Don't start charging in cable nofitication Date: Thu, 14 May 2020 16:04:32 -0700 Message-ID: X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514230435.11798-1-xc-racer2@live.ca> References: <20200514230435.11798-1-xc-racer2@live.ca> X-ClientProxiedBy: MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) To BN6PR04MB0660.namprd04.prod.outlook.com (2603:10b6:404:d9::21) X-Microsoft-Original-Message-ID: <20200514230435.11798-8-xc-racer2@live.ca> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jon-hp-6570b.telus (2001:569:fb68:9c00:8067:f823:1e15:7520) by MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26 via Frontend Transport; Thu, 14 May 2020 23:05:14 +0000 X-Mailer: git-send-email 2.20.1 X-Microsoft-Original-Message-ID: <20200514230435.11798-8-xc-racer2@live.ca> X-TMN: [aNGJO5wpZ50jdg5D+islHvQLmbJJGmWldJiA9HVPAayVA/DH3rynnFz9hUR9HbLo] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 1473ed6f-4026-4dd1-4529-08d7f85b43a5 X-MS-TrafficTypeDiagnostic: MW2NAM12HT059: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FWi6i5AovQqQtbxC7fpKBzF8VcHW/WZl++i3bc2BDETI+ZXxvVOQ4nrynnntAJiS8ze3JnuaEmhOG4hsp9FhvMWzkxWm2jxd/kraG+f06NkhSHotEW7oVIguth9i6J96fZTcbuVaFVUDDErwOCsAS9hhjACNtbLVQbZ0gak318+gOEyHJZg85zCNoExQSPJD77EhXw5BQboaI335/dTEzA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR04MB0660.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: NyTR2HioZWucfyXU/6P6Gp3E23roTCaDZJ7s0hzWWivoeUsRTrgvNxGxSnalwsol1K9+xpEH0aZxtLE/84AojOL+YaKD3ZJxWFifwY54xvDNVWsNUqlDt/EfkpaQqzPUcY0TIhfRv9zdNVurQXcHZtk8I3pcnIG9Nd5U5N59HiNEkC/TJA6Igip8YxGRI+EeeUPKhbqMH+slJBjnxmwiqQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1473ed6f-4026-4dd1-4529-08d7f85b43a5 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 23:05:16.1049 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM12HT059 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Jonghwa Lee Prevents direct charging control in cable notification and only set the input current limit according to cable type. Leave the enabling of charing to cm_monitor() where charging management proceeds. We may lose a few ms to enable charging compared to before, but it's more important that charging is enabled always in safe context. Signed-off-by: Jonghwa Lee Signed-off-by: Krzysztof Kozlowski Signed-off-by: Jonathan Bakker --- drivers/power/supply/charger-manager.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c index 9e4a7d368b08..27064a46a365 100644 --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -907,7 +907,8 @@ static void charger_extcon_work(struct work_struct *work) cable->min_uA, cable->max_uA); } - try_charger_enable(cable->cm, cable->attached); + cancel_delayed_work(&cm_monitor_work); + queue_delayed_work(cm_wq, &cm_monitor_work, 0); } /** @@ -930,15 +931,6 @@ static int charger_extcon_notifier(struct notifier_block *self, */ cable->attached = event; - /* - * Setup monitoring to check battery state - * when charger cable is attached. - */ - if (cable->attached && is_polling_required(cable->cm)) { - cancel_work_sync(&setup_polling); - schedule_work(&setup_polling); - } - /* * Setup work for controlling charger(regulator) * according to charger cable. From patchwork Thu May 14 23:04:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Bakker X-Patchwork-Id: 11550129 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 30CF214E3 for ; Thu, 14 May 2020 23:05:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D405204EA for ; Thu, 14 May 2020 23:05:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729144AbgENXFV (ORCPT ); Thu, 14 May 2020 19:05:21 -0400 Received: from mail-mw2nam12olkn2048.outbound.protection.outlook.com ([40.92.23.48]:48353 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729089AbgENXFU (ORCPT ); Thu, 14 May 2020 19:05:20 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=juQ1uv2PQI4oVeb3gR7UDjtU+bFKGd3Q4nSeUchXdd0froQzwMQ12DpNcqXyI94btSbdTMgQiBYFdoyJT7cCGPM+R+m/EAR5copLBmWUniHTygj7wXpf7aQZLjDiJ/bJxtSIujSVUOsDhMMNQJ+lyD5bFbASa0q3vXHmgD4HxduIU3aFsJSmgxQVvxI8O6A+lCN0Fz5HmLQJNxh8HtL1CxCO3xw10+6Gi9UHIV966j2ooev64zgUCmYGOX6Wn5+ZtAPzFj6b0ErtdktJGmf7Pie959KOFYkRgT22WDFRZb34oSGq2bbi4dlCYGvVtuTStHEGMQQq9ZujPb7UQpta/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4Awkr2HpBhIcbXNIc+x+8pzhsNau8D04HOqebPXK4AQ=; b=B2nxgdU0PPYAcG8kxLNqWLcrCJWVLIKtCzpLp7//l3ynEGSvJ5y5XOYZkol5CjT2D/bWFmeuiPUnFANLIS+0vYcUteQGr0TxhBQjxJqtYDd62U+9gHUNiLhYNxSGTnYbOKr67OgGiQxAEXSU4yy1yfgfHmfPS6SFWUIA6NcA8Hx1/Lvng9G7cSN+CjnOqQ8NjWW0tIi+RBX+WUbVDXG4hrclQa+8Y8sJDpRIXuv7JCDBRQTbHRbim1RZA8Gu7D33xjDMOgXHux/XnMvTjxadUV9YQyTl3+/HF9+UIpadTEPhp5RYAnG7KlVcYTpWuanLIAG2YPvJSGQIl/99aoGLiQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=live.ca; dmarc=pass action=none header.from=live.ca; dkim=pass header.d=live.ca; arc=none Received: from MW2NAM12FT003.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::47) by MW2NAM12HT137.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::308) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11; Thu, 14 May 2020 23:05:17 +0000 Received: from BN6PR04MB0660.namprd04.prod.outlook.com (2a01:111:e400:fc65::44) by MW2NAM12FT003.mail.protection.outlook.com (2a01:111:e400:fc65::70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11 via Frontend Transport; Thu, 14 May 2020 23:05:17 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:DA49E0BF4D44EDE16ED6CB8CF973445A05031789189D1DC617FF0DF5C394CCD6;UpperCasedChecksum:DB43982AC0D3BA7F762B9A5240929384587D5BA91CA2D7E9E9DD9B8CAFB75C9E;SizeAsReceived:7846;Count:50 Received: from BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc]) by BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc%6]) with mapi id 15.20.3000.022; Thu, 14 May 2020 23:05:17 +0000 From: Jonathan Bakker To: sre@kernel.org, krzk@kernel.org, jonghwa3.lee@samsung.com, tglx@linutronix.de, kstewart@linuxfoundation.org, baolin.wang7@gmail.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Bakker Subject: [PATCH 08/10] power: supply: charger-manager: Update extcon functions Date: Thu, 14 May 2020 16:04:33 -0700 Message-ID: X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514230435.11798-1-xc-racer2@live.ca> References: <20200514230435.11798-1-xc-racer2@live.ca> X-ClientProxiedBy: MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) To BN6PR04MB0660.namprd04.prod.outlook.com (2603:10b6:404:d9::21) X-Microsoft-Original-Message-ID: <20200514230435.11798-9-xc-racer2@live.ca> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jon-hp-6570b.telus (2001:569:fb68:9c00:8067:f823:1e15:7520) by MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26 via Frontend Transport; Thu, 14 May 2020 23:05:16 +0000 X-Mailer: git-send-email 2.20.1 X-Microsoft-Original-Message-ID: <20200514230435.11798-9-xc-racer2@live.ca> X-TMN: [AcyfIgyKaFETI0utMZ2iLLGcFuqS6vCeNAZkAEPkpunVOy+2tlxhWt5qcagr9rVu] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 74d3d40f-9c30-47aa-3c8d-08d7f85b44a1 X-MS-TrafficTypeDiagnostic: MW2NAM12HT137: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w8P9hABOmelYHAoQi/+SKxUr+eOeeG32b5Sf1M477CajGAlyId7HMW4X92xnaQfjSNw3wpPSSDBM/OHKECCtXPwJrUeKcphgrcy7p8e/YNYAldjsf7MkPiFjHkRWsCKxa8lWc2kLMrgXz/R/5PEf9X8i9HFgV1v+dq0TAeK0kxQGRx07NhWQtRmttZIwBdhsxkLtIuT2Uw2IAMvV/6aOew== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR04MB0660.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: sE0ZLSkAGq6PQiYLwIrACHzwkDqTagDcnuYORuwftGmFopS9lBY8vJ9k3pB20PG0ay6zCxXox6LpqScYCsakYPg6rgl9vNEtrapxXUzq7myirmnVno+lSKKa/xBMB8/sE8QrrNzZlo4wh9MN9mIqJyblwGNDsJS8iD+9NU7OqywH0E8HGME7EOSwRk0YWlqEIAnixBixEswVYwJDJRYe4g== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74d3d40f-9c30-47aa-3c8d-08d7f85b44a1 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 23:05:17.7312 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM12HT137 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In commit 830ae442202e ("extcon: Remove the deprecated extcon functions") the function extcon_register_interest became a no-op returning an error, leading to non-functional behaviour in charger-manager. Additionally, a translation table is needed between the text representation of the extcon cable names and their IDs is needed. In order to retain DT compatibility, TA and CHARGE-DOWNSTREAM are added as they were present up until commit 11eecf910bd8 ("extcon: Modify the id and name of external connector") Signed-off-by: Jonathan Bakker --- drivers/power/supply/charger-manager.c | 82 +++++++++++++++++++------- include/linux/power/charger-manager.h | 5 +- 2 files changed, 63 insertions(+), 24 deletions(-) diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c index 27064a46a365..4ad3dd754abf 100644 --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -26,6 +26,29 @@ #include #include +static struct { + const char *name; + u64 extcon_type; +} extcon_mapping[] = { + /* Current textual representations */ + { "USB", EXTCON_USB }, + { "USB-HOST", EXTCON_USB_HOST }, + { "SDP", EXTCON_CHG_USB_SDP }, + { "DCP", EXTCON_CHG_USB_DCP }, + { "CDP", EXTCON_CHG_USB_CDP }, + { "ACA", EXTCON_CHG_USB_ACA }, + { "FAST-CHARGER", EXTCON_CHG_USB_FAST }, + { "SLOW-CHARGER", EXTCON_CHG_USB_SLOW }, + { "WPT", EXTCON_CHG_WPT }, + { "PD", EXTCON_CHG_USB_PD }, + { "DOCK", EXTCON_DOCK }, + { "JIG", EXTCON_JIG }, + { "MECHANICAL", EXTCON_MECHANICAL }, + /* Deprecated textual representations */ + { "TA", EXTCON_CHG_USB_SDP }, + { "CHARGE-DOWNSTREAM", EXTCON_CHG_USB_CDP }, +}; + /* * Default temperature threshold for charging. * Every temperature units are in tenth of centigrade. @@ -950,7 +973,8 @@ static int charger_extcon_notifier(struct notifier_block *self, static int charger_extcon_init(struct charger_manager *cm, struct charger_cable *cable) { - int ret; + int ret, i; + u64 extcon_type = EXTCON_NONE; /* * Charger manager use Extcon framework to identify @@ -959,14 +983,39 @@ static int charger_extcon_init(struct charger_manager *cm, */ INIT_WORK(&cable->wq, charger_extcon_work); cable->nb.notifier_call = charger_extcon_notifier; - ret = extcon_register_interest(&cable->extcon_dev, - cable->extcon_name, cable->name, &cable->nb); + + cable->extcon_dev = extcon_get_extcon_dev(cable->extcon_name); + if (IS_ERR_OR_NULL(cable->extcon_dev)) { + pr_err("Cannot find extcon_dev for %s (cable: %s)\n", + cable->extcon_name, cable->name); + if (cable->extcon_dev == NULL) + return -EPROBE_DEFER; + else + return PTR_ERR(cable->extcon_dev); + } + + for (i = 0; i < ARRAY_SIZE(extcon_mapping); i++) { + if (!strcmp(cable->name, extcon_mapping[i].name)) { + extcon_type = extcon_mapping[i].extcon_type; + break; + } + } + if (extcon_type == EXTCON_NONE) { + pr_err("Cannot find cable for type %s", cable->name); + return -EINVAL; + } + + cable->extcon_type = extcon_type; + + ret = devm_extcon_register_notifier(cm->dev, cable->extcon_dev, + cable->extcon_type, &cable->nb); if (ret < 0) { - pr_info("Cannot register extcon_dev for %s(cable: %s)\n", + pr_err("Cannot register extcon_dev for %s (cable: %s)\n", cable->extcon_name, cable->name); + return ret; } - return ret; + return 0; } /** @@ -983,6 +1032,7 @@ static int charger_manager_register_extcon(struct charger_manager *cm) { struct charger_desc *desc = cm->desc; struct charger_regulator *charger; + unsigned long event; int ret; int i; int j; @@ -1010,6 +1060,11 @@ static int charger_manager_register_extcon(struct charger_manager *cm) } cable->charger = charger; cable->cm = cm; + + event = extcon_get_state(cable->extcon_dev, + cable->extcon_type); + charger_extcon_notifier(&cable->nb, + event, NULL); } } @@ -1370,7 +1425,6 @@ static int charger_manager_probe(struct platform_device *pdev) struct charger_desc *desc = cm_get_drv_data(pdev); struct charger_manager *cm; int ret, i = 0; - int j = 0; union power_supply_propval val; struct power_supply *fuel_gauge; struct power_supply_config psy_cfg = {}; @@ -1568,12 +1622,6 @@ static int charger_manager_probe(struct platform_device *pdev) struct charger_regulator *charger; charger = &desc->charger_regulators[i]; - for (j = 0; j < charger->num_cables; j++) { - struct charger_cable *cable = &charger->cables[j]; - /* Remove notifier block if only edev exists */ - if (cable->extcon_dev.edev) - extcon_unregister_interest(&cable->extcon_dev); - } regulator_put(desc->charger_regulators[i].consumer); } @@ -1588,7 +1636,6 @@ static int charger_manager_remove(struct platform_device *pdev) struct charger_manager *cm = platform_get_drvdata(pdev); struct charger_desc *desc = cm->desc; int i = 0; - int j = 0; /* Remove from the list */ mutex_lock(&cm_list_mtx); @@ -1598,15 +1645,6 @@ static int charger_manager_remove(struct platform_device *pdev) cancel_work_sync(&setup_polling); cancel_delayed_work_sync(&cm_monitor_work); - for (i = 0 ; i < desc->num_charger_regulators ; i++) { - struct charger_regulator *charger - = &desc->charger_regulators[i]; - for (j = 0 ; j < charger->num_cables ; j++) { - struct charger_cable *cable = &charger->cables[j]; - extcon_unregister_interest(&cable->extcon_dev); - } - } - for (i = 0 ; i < desc->num_charger_regulators ; i++) regulator_put(desc->charger_regulators[i].consumer); diff --git a/include/linux/power/charger-manager.h b/include/linux/power/charger-manager.h index c127dbe31e49..45e228b353ea 100644 --- a/include/linux/power/charger-manager.h +++ b/include/linux/power/charger-manager.h @@ -40,7 +40,7 @@ enum cm_batt_temp { /** * struct charger_cable * @extcon_name: the name of extcon device. - * @name: the name of charger cable(external connector). + * @name: the name of the cable connector * @extcon_dev: the extcon device. * @wq: the workqueue to control charger according to the state of * charger cable. If charger cable is attached, enable charger. @@ -56,9 +56,10 @@ enum cm_batt_temp { struct charger_cable { const char *extcon_name; const char *name; + struct extcon_dev *extcon_dev; + u64 extcon_type; /* The charger-manager use Extcon framework */ - struct extcon_specific_cable_nb extcon_dev; struct work_struct wq; struct notifier_block nb; From patchwork Thu May 14 23:04:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Bakker X-Patchwork-Id: 11550125 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 858A814B7 for ; Thu, 14 May 2020 23:05:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76F7B20758 for ; Thu, 14 May 2020 23:05:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729194AbgENXF1 (ORCPT ); Thu, 14 May 2020 19:05:27 -0400 Received: from mail-dm6nam12olkn2018.outbound.protection.outlook.com ([40.92.22.18]:32128 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729145AbgENXFW (ORCPT ); Thu, 14 May 2020 19:05:22 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KMKeYpli/g4HaT9v/UVXn11AlAzmxZeapvStl6V8lOwxuHjenUeGtSWmPPoLBfA558hlqV3Wiak0rbEHpWHN2k0l6e+UY3AyRQv5e9V9xOy+aWNQknaWRt1KPbsQaIfxxtxE+WJD3qIOQxoBGnPTag78zabKedc/77G+FyTPKRhOJjZQvHU5gopNjEcAQvw1Ll0okpgTsuVtWx6bnUjnW5+/EzuN4zErN6rBv0V4HHTrx3Y0cmoHvGhsUdzqNRvJUbaFsOJJhKNO21JothfDLyzK8JiZyUxHz4uJbnbebcj3yk6nIDK7wyJ/m1gG030UwUOqM5iP09FiXDsaIW0I/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=frjjLVPAF4ZuhXoCL/krqbQKU4CEv1ZHlJsmkJDyOAk=; b=kKfzxz8P1rXJRos3keXShy/VxanDUR1UUvtwOTVP4Cn1rAr40BeHrdktfOVA4aLGBwEUBXF8nT+3PLClJ1ku0V2qYjdoKzpBPvH89qLkHl/p3IGUDPA2MAaslfsSDYsh487s1QM/xJo+8/GN7npBxMpNOr6iHM9dSTFncHdYqqVJ22w7azqA3uboKS4IIu6WvuW1e45V4Ja4DGiVrwPBNimlR9hByIy7N4PmgAPqa4peFYoyZ5ZQIBHp31JLC3hS2Cg8f0UfO/8k+B98D7iVdDlZYLeTSQmRcHV05/TX01e7OPmJaShyxBCKPDFwi3MbIPt3dkqPsp5aC2YBC0Wdgw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=live.ca; dmarc=pass action=none header.from=live.ca; dkim=pass header.d=live.ca; arc=none Received: from MW2NAM12FT003.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::41) by MW2NAM12HT132.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::484) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.11; Thu, 14 May 2020 23:05:19 +0000 Received: from BN6PR04MB0660.namprd04.prod.outlook.com (2a01:111:e400:fc65::44) by MW2NAM12FT003.mail.protection.outlook.com (2a01:111:e400:fc65::70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11 via Frontend Transport; Thu, 14 May 2020 23:05:19 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:74862B13F85791B1DEA666493F20868B73C6CDBCF68E78AB8A00B9EAED5B6DC7;UpperCasedChecksum:00EE86BF9418EED3CF25276A5E25B1D90AA9C5C451A54C98D07631ABF8140D81;SizeAsReceived:7869;Count:50 Received: from BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc]) by BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc%6]) with mapi id 15.20.3000.022; Thu, 14 May 2020 23:05:19 +0000 From: Jonathan Bakker To: sre@kernel.org, krzk@kernel.org, jonghwa3.lee@samsung.com, tglx@linutronix.de, kstewart@linuxfoundation.org, baolin.wang7@gmail.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Bakker Subject: [PATCH 09/10] power: supply: charger-manager: Count cm-chargers property directly Date: Thu, 14 May 2020 16:04:34 -0700 Message-ID: X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514230435.11798-1-xc-racer2@live.ca> References: <20200514230435.11798-1-xc-racer2@live.ca> X-ClientProxiedBy: MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) To BN6PR04MB0660.namprd04.prod.outlook.com (2603:10b6:404:d9::21) X-Microsoft-Original-Message-ID: <20200514230435.11798-10-xc-racer2@live.ca> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jon-hp-6570b.telus (2001:569:fb68:9c00:8067:f823:1e15:7520) by MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26 via Frontend Transport; Thu, 14 May 2020 23:05:17 +0000 X-Mailer: git-send-email 2.20.1 X-Microsoft-Original-Message-ID: <20200514230435.11798-10-xc-racer2@live.ca> X-TMN: [EpCpjepnmk2cjalAvX2YBosdIDPdzGZTlvQoEZxd5csTAj9x2S6pPEJtc8Ppjy9u] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: ece23963-be24-4f3a-9782-08d7f85b45a5 X-MS-TrafficTypeDiagnostic: MW2NAM12HT132: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +LYQwITxRiGsdQAQeQwKhOVcATtt6FfqJhh95tPGiyKITaMFb04krSNQERKHKtLJ9PRXNui69KEd2Ftrhdc83bwP3FDQJyNhCHP3jkriAWGuUl3FQ2KT4s43alM5+WEqp8A49Zs/H3PndiNKd7ibqt7mGPkmjt8kja+RirliWXlrD+ItsbB7CAk0+rQ/IeN2GxLPTFmjFaSuzVOCqKKd3A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR04MB0660.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: ticopCGDOfT5aqgJnzaVJu9MdZIa1+ST7R79Red8Ufk/fzzemgWI246Gn9c2AARx6PNBhbGVyMcyU4NcuKMvaXrSts3CSq5jq8bOKNbml4qutB8Yb+Ay+4U5h/969HsWitg+l40zZ5Y9p426vlHTu77vPSrIxzPAqfasqlRZ1sMLTiajHfeZ63GAtDHemSrQYvhFan+m6HVCc5wBiTAVcg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ece23963-be24-4f3a-9782-08d7f85b45a5 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 23:05:19.6494 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM12HT132 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Rather than having a cm-chargers and a separate cm-num-chargers property, simply count the entries in cm-chargers. Signed-off-by: Jonathan Bakker --- drivers/power/supply/charger-manager.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c index 4ad3dd754abf..f0ef8a10891c 100644 --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -1311,8 +1311,8 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev) desc->battery_present = battery_stat; /* chargers */ - of_property_read_u32(np, "cm-num-chargers", &num_chgs); - if (num_chgs) { + num_chgs = of_property_count_strings(np, "cm-chargers"); + if (num_chgs > 0) { int i; /* Allocate empty bin at the tail of array */ From patchwork Thu May 14 23:04:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Bakker X-Patchwork-Id: 11550127 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3B29139A for ; Thu, 14 May 2020 23:05:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A13CC207C3 for ; Thu, 14 May 2020 23:05:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729089AbgENXF0 (ORCPT ); Thu, 14 May 2020 19:05:26 -0400 Received: from mail-bn8nam12olkn2108.outbound.protection.outlook.com ([40.92.21.108]:52132 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729164AbgENXFY (ORCPT ); Thu, 14 May 2020 19:05:24 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FzXng47NL8FcgWy1gQ9W7tlLb3tw/GA9M48/LyWy6VGTt/xv16NIagwvxz3UF/K18avxwezAYlRHNO6TvmIEBwrq2iT0rlsnLo3pRCQAfYBixnf0rGDnsQ5A4vytKoZf0JoiUsSYQjwR5Za6F1MsmnTXoNFe+nFcoGKrXI4PdVLwQe6w5ULB0wSYduZgoD8GZB+vlwhBeo2dmDh/3843ujcKZEpOM8DLowEpPZLMkXSRiEqNUtbt1Kn1PqkKxtvJ82kEAkpFcYvArwL/xzQW1U718h0euoS7c2jNXHvg9WevnjpBCVNBFoViu93shkzqJEL6GxOQVncnXzi8C2CcPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qe8FbzbVdPyeGBc4pRx8iEkk18QIkWBbq67esAEoc/U=; b=fHFSnkBDByckvhL9LeCRU2pxEb61ffTNjPbUbvq6gAomLFEMV5WYtGPOFkBuatqoyIY+G3qfarluH3yT1wSouIwP7p+K9CtZLWZKpVIYDvXFIiHmqirqQcYh8nkFVP6ynb7FD5RsSpqdYacnS60byTD3e8zN5SCZyQdBKqpuMxE4QezHyhGWX73n78cKHAVONQuLykJWS2V0gvQaAW/dxRtNyZhlfEHdVuAekeG4fsIPEmJWxh/nmomoE8YiDNU9U82qxTZoC5tsquB6f9qtxThtIKuizFbvq1IIe30yylAwtWGU5NLikbQLePLI1bfhZGU3KDm8RavKPiuX38C+Yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=live.ca; dmarc=pass action=none header.from=live.ca; dkim=pass header.d=live.ca; arc=none Received: from MW2NAM12FT003.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::44) by MW2NAM12HT209.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::472) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.11; Thu, 14 May 2020 23:05:21 +0000 Received: from BN6PR04MB0660.namprd04.prod.outlook.com (2a01:111:e400:fc65::44) by MW2NAM12FT003.mail.protection.outlook.com (2a01:111:e400:fc65::70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11 via Frontend Transport; Thu, 14 May 2020 23:05:21 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:8FE46E5D22477DA16827A93781B410B0D8719A47343C2F81C8D0CD8B7CC14DCE;UpperCasedChecksum:DE063B2EF7B2E3193A6A4BF53F51B43C4F701699C70C528B78C3F7B85453DA6E;SizeAsReceived:7862;Count:50 Received: from BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc]) by BN6PR04MB0660.namprd04.prod.outlook.com ([fe80::ad10:4127:4bc8:76fc%6]) with mapi id 15.20.3000.022; Thu, 14 May 2020 23:05:21 +0000 From: Jonathan Bakker To: sre@kernel.org, krzk@kernel.org, jonghwa3.lee@samsung.com, tglx@linutronix.de, kstewart@linuxfoundation.org, baolin.wang7@gmail.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Bakker Subject: [PATCH 10/10] dt-bindings: power: supply: Cleanup charger-manager bindings Date: Thu, 14 May 2020 16:04:35 -0700 Message-ID: X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200514230435.11798-1-xc-racer2@live.ca> References: <20200514230435.11798-1-xc-racer2@live.ca> X-ClientProxiedBy: MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) To BN6PR04MB0660.namprd04.prod.outlook.com (2603:10b6:404:d9::21) X-Microsoft-Original-Message-ID: <20200514230435.11798-11-xc-racer2@live.ca> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jon-hp-6570b.telus (2001:569:fb68:9c00:8067:f823:1e15:7520) by MWHPR22CA0040.namprd22.prod.outlook.com (2603:10b6:300:69::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26 via Frontend Transport; Thu, 14 May 2020 23:05:19 +0000 X-Mailer: git-send-email 2.20.1 X-Microsoft-Original-Message-ID: <20200514230435.11798-11-xc-racer2@live.ca> X-TMN: [MWEiQQrJbor6Eb/d0JZR+Ax6cMEWlvDwFRLGKClVWSx7rfMDU/Cel/S3miHFtqaz] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 58a531cf-2e75-4aba-7847-08d7f85b46bd X-MS-TrafficTypeDiagnostic: MW2NAM12HT209: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8jhOcp/k0IL0FyU8mDfcfHrTPPl3dPoIJYAQ5VkiRpV3OC2VH1D6O0woOX52ZYBcLOTAmgPpMZy24Y+gyfq7U6t+p2eJAyLw5Pc9zX86mE2pw/5FuFYcNVaPpMn5QjPrvZdhv0kb/9w+LTXQFtxPBOjeQbXjvrUTpZMYAGpDPOHIhQX9TEPxI6nQdoZCTj1ji8OSESUt9BysMA1LYCJs5g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR04MB0660.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: gk7JFDJ7j+wwMIWEXjrZr+7d9Lf32O521nshvEFRBDrIt+D2ZM0BIqjRDw53VUAUG1DmnDqq3no/S6pYoQUxkEGaXDDZ595vYHPVhEkS4dfusxCS7zXYNV/SnWTyN8eqGk80MZ0K1zrmnmTXjcN4LLugE+mMvcs81NpMOygs1B8Q83XXG321rGdIuYZr/YjVaM1XE96Wfq3GkeD0wSGfyA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 58a531cf-2e75-4aba-7847-08d7f85b46bd X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2020 23:05:21.5046 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM12HT209 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The bindings for charger-manager were very unclear and didn't specify allowable values in many cases. Clean these up to show what each value does and make sure all properties are documented here rather than using wildcards. Signed-off-by: Jonathan Bakker Acked-by: Rob Herring --- .../bindings/power/supply/charger-manager.txt | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Documentation/devicetree/bindings/power/supply/charger-manager.txt b/Documentation/devicetree/bindings/power/supply/charger-manager.txt index ec4fe9de3137..b5ae9061b7a0 100644 --- a/Documentation/devicetree/bindings/power/supply/charger-manager.txt +++ b/Documentation/devicetree/bindings/power/supply/charger-manager.txt @@ -3,24 +3,32 @@ charger-manager bindings Required properties : - compatible : "charger-manager" - - <>-supply : for regulator consumer - - cm-num-chargers : number of chargers + - <>-supply : for regulator consumer, named according to cm-regulator-name - cm-chargers : name of chargers - cm-fuel-gauge : name of battery fuel gauge - subnode : - cm-regulator-name : name of charger regulator - subnode : - - cm-cable-name : name of charger cable + - cm-cable-name : name of charger cable - one of USB, USB-HOST, + SDP, DCP, CDP, ACA, FAST-CHARGER, SLOW-CHARGER, WPT, + PD, DOCK, JIG, or MECHANICAL - cm-cable-extcon : name of extcon dev (optional) - cm-cable-min : minimum current of cable (optional) - cm-cable-max : maximum current of cable Optional properties : - cm-name : charger manager's name (default : "battery") - - cm-poll-mode : polling mode (enum polling_modes) - - cm-poll-interval : polling interval - - cm-battery-stat : battery status (enum data_source) - - cm-fullbatt-* : data for full battery checking + - cm-poll-mode : polling mode - 0 for disabled, 1 for always, 2 for when + external power is connected, or 3 for when charging. If not present, + then polling is disabled + - cm-poll-interval : polling interval (in ms) + - cm-battery-stat : battery status - 0 for battery always present, 1 for no + battery, 2 to check presence via fuel gauge, or 3 to check presence + via charger + - cm-fullbatt-vchkdrop-volt : voltage drop (in uV) before restarting charging + - cm-fullbatt-voltage : voltage (in uV) of full battery + - cm-fullbatt-soc : state of charge to consider as full battery + - cm-fullbatt-capacity : capcity (in uAh) to consider as full battery - cm-thermal-zone : name of external thermometer's thermal zone - cm-battery-* : threshold battery temperature for charging -cold : critical cold temperature of battery for charging @@ -29,6 +37,10 @@ Optional properties : -temp-diff : temperature difference to allow recharging - cm-dis/charging-max = limits of charging duration +Deprecated properties: + - cm-num-chargers + - cm-fullbatt-vchkdrop-ms + Example : charger-manager@0 { compatible = "charger-manager"; @@ -39,13 +51,11 @@ Example : cm-poll-mode = <1>; cm-poll-interval = <30000>; - cm-fullbatt-vchkdrop-ms = <30000>; cm-fullbatt-vchkdrop-volt = <150000>; cm-fullbatt-soc = <100>; cm-battery-stat = <3>; - cm-num-chargers = <3>; cm-chargers = "charger0", "charger1", "charger2"; cm-fuel-gauge = "fuelgauge0"; @@ -71,7 +81,7 @@ Example : cm-cable-max = <500000>; }; cable@1 { - cm-cable-name = "TA"; + cm-cable-name = "SDP"; cm-cable-extcon = "extcon-dev.0"; cm-cable-min = <650000>; cm-cable-max = <675000>;