From patchwork Fri Dec 19 02:47:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonghwa Lee X-Patchwork-Id: 5517141 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 59696BEEA8 for ; Fri, 19 Dec 2014 02:48:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6B28D20131 for ; Fri, 19 Dec 2014 02:48:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 802592012D for ; Fri, 19 Dec 2014 02:48:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752070AbaLSCrr (ORCPT ); Thu, 18 Dec 2014 21:47:47 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:14641 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751949AbaLSCrp (ORCPT ); Thu, 18 Dec 2014 21:47:45 -0500 Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NGT00F026FD9330@mailout4.samsung.com>; Fri, 19 Dec 2014 11:47:37 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.115]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id 9E.C1.17016.9C193945; Fri, 19 Dec 2014 11:47:37 +0900 (KST) X-AuditID: cbfee68d-f79296d000004278-cf-549391c96f21 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 76.E2.09430.9C193945; Fri, 19 Dec 2014 11:47:37 +0900 (KST) Received: from localhost.localdomain ([10.252.82.199]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NGT004F46F82Y30@mmp1.samsung.com>; Fri, 19 Dec 2014 11:47:37 +0900 (KST) From: Jonghwa Lee To: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org, anton@enomsg.org, pavel@ucw.cz, myungjoo.ham@samsung.com, cw00.choi@samsung.com, Jonghwa Lee Subject: [PATCH RESEND v2 10/10] power: charger-manager: Support to change polling rate in runtime. Date: Fri, 19 Dec 2014 11:47:30 +0900 Message-id: <1418957250-6542-11-git-send-email-jonghwa3.lee@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1418957250-6542-1-git-send-email-jonghwa3.lee@samsung.com> References: <1418957250-6542-1-git-send-email-jonghwa3.lee@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrELMWRmVeSWpSXmKPExsWyRsSkWPfkxMkhBpO2Glkc3Kppcf3Lc1aL SU/eM1tMXDmZ2aLz7BNmi8u75rBZfO49wmhxu3EFm8XdU0fZLE7vLnHg8pjQ/4nRY+esu+we m1doeWxa1cnm0bdlFaPHitXf2T0+b5ILYI/isklJzcksSy3St0vgyvj1/ShTwRmxim+tK1ga GE8KdTFyckgImEicmnueGcIWk7hwbz1bFyMXh5DAUkaJ/VP/sMIUnZ5wmgkisYhRYu+pDewQ ThuTxI7LX9lAqtgEdCT+77vJDmKLCChIbO59xgpSxCxwhVHi5uL1TCAJYYFUiV137oKNZRFQ lVjwdAlYA6+Ah8SECXOA7uAAWqcgMWeSDUiYEyj89FIT2HwhAXeJE9/esoDMlBDYxy5xeP80 Nog5AhLfJh9igeiVldh0AOodSYmDK26wTGAUXsDIsIpRNLUguaA4Kb3IUK84Mbe4NC9dLzk/ dxMjMCpO/3vWu4Px9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WMN3fMvXhlUauIsqOI++OLHMY+hbsa5C8JV1V+YT5qZd3Jt+ju7j0z Xqxc3fJyDcP+3JkrrRwqa6T+tPNltj4umMH7o8VM7fRU2RPShh8KFX/3nTUw3Ramx1Sw6f+G /V01x+oLlFiKMxINtZiLihMBf95Jys8CAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add 'polling_ms' sysfs node to change charger-manager's monitoring rate in runtime. It can set only bigger than 2 jiffies (for 200 HZ system it is 10 msecs.) as it's allowed for minimum poling rate in previous. It resets poller and re-configure polling rate based on new input if next polling time is far enough. Otherwise, it just waits expiration of timer and new polling rate will affects the next scheduling. Signed-off-by: Jonghwa Lee --- drivers/power/charger-manager.c | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c index 0a0834f..7a007f4 100644 --- a/drivers/power/charger-manager.c +++ b/drivers/power/charger-manager.c @@ -1054,6 +1054,63 @@ static ssize_t charger_externally_control_store(struct device *dev, return count; } +static ssize_t show_polling_ms(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct charger_manager *cm; + ssize_t len; + + list_for_each_entry(cm, &cm_list, entry) + if (cm->charger_psy.dev == dev) + break; + + if (cm->charger_psy.dev != dev) + return -EINVAL; + + len = sprintf(buf, "%d\n", cm->desc->polling_interval_ms); + + return len; +} + +static ssize_t store_polling_ms(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + struct charger_manager *cm; + int polling_ms; + int ret; + + ret = sscanf(buf, "%d", &polling_ms); + if (ret < 0 ) + return -EINVAL; + + if (polling_ms < CM_JIFFIES_SMALL * MSEC_PER_SEC / HZ) + return -EINVAL; + + list_for_each_entry(cm, &cm_list, entry) + if (cm->charger_psy.dev == dev) + break; + + if (cm->charger_psy.dev != dev) + return -ENODEV; + + cm->desc->polling_interval_ms = polling_ms; + + pr_info("Polling interval's changed to %u ms.\n", + cm->desc->polling_interval_ms); + + if (next_polling - jiffies > + msecs_to_jiffies(cm->desc->polling_interval_ms)) { + pr_info("Reset poller now... \n"); + cancel_delayed_work(&cm_monitor_work); + schedule_work(&setup_polling); + } + + return count; +} + +static DEVICE_ATTR(polling_ms, 0644, show_polling_ms, store_polling_ms); + /** * charger_manager_register_sysfs - Register sysfs entry for each charger * @cm: the Charger Manager representing the battery. @@ -1077,6 +1134,11 @@ static int charger_manager_register_sysfs(struct charger_manager *cm) int ret = 0; int i; + /* Create polling_ms sysfs node */ + ret = device_create_file(cm->charger_psy.dev, &dev_attr_polling_ms); + if (ret) + pr_err("Failed to create poling_ms sysfs node (%d)\n", ret); + /* Create sysfs entry to control charger(regulator) */ for (i = 0; i < desc->num_charger_regulators; i++) { charger = &desc->charger_regulators[i];