From patchwork Thu Oct 30 12:43:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonghwa Lee X-Patchwork-Id: 5197301 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1B5FD9F318 for ; Thu, 30 Oct 2014 12:44:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 44A5E20172 for ; Thu, 30 Oct 2014 12:44:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4002F2015D for ; Thu, 30 Oct 2014 12:44:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759998AbaJ3Mnh (ORCPT ); Thu, 30 Oct 2014 08:43:37 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:23881 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759976AbaJ3Mne (ORCPT ); Thu, 30 Oct 2014 08:43:34 -0400 Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NE900EUOCOAR590@mailout1.samsung.com>; Thu, 30 Oct 2014 21:43:23 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.113]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id C6.1B.11124.A6232545; Thu, 30 Oct 2014 21:43:22 +0900 (KST) X-AuditID: cbfee68e-f79b46d000002b74-16-5452326a2a25 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 3F.24.09430.A6232545; Thu, 30 Oct 2014 21:43:22 +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 <0NE900852CO56T50@mmp1.samsung.com>; Thu, 30 Oct 2014 21:43:22 +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 10/10] power: charger-manager: Support to change polling rate in runtime. Date: Thu, 30 Oct 2014 21:43:16 +0900 Message-id: <1414672996-28355-11-git-send-email-jonghwa3.lee@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1414672996-28355-1-git-send-email-jonghwa3.lee@samsung.com> References: <1414672996-28355-1-git-send-email-jonghwa3.lee@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrELMWRmVeSWpSXmKPExsWyRsSkUDfLKCjE4NJ0M4uDWzUtrn95zmox 6cl7ZouJKyczW3SefcJscXnXHDaLz71HGC1uN65gs7h76iibxendJQ5cHhP6PzF67Jx1l91j 8wotj02rOtk8+rasYvRYsfo7u8fnTXIB7FFcNimpOZllqUX6dglcGb++H2UqOCNW8a11BUsD 40mhLkZODgkBE4nLux6wQthiEhfurWfrYuTiEBJYyihx5ccXZpiivuP7oRKLGCVWPXnNDuG0 MUncaVrBDlLFJqAj8X/fTTBbREBBYnPvM1aQImaBK4wSNxevZwJJCAtES0xbfwbMZhFQlVi4 fy+YzSvgKTH9zUIgmwNonYLEnEk2IGFOoPCmKzNZQGwhAQ+JB7u6wBZLCOxil/h0bwIjxBwB iW+TD7FA9MpKbDoAdbWkxMEVN1gmMAovYGRYxSiaWpBcUJyUXmSkV5yYW1yal66XnJ+7iREY Faf/PevbwXjzgPUhRgEORiUeXo0T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VX3zwIWH2I68n22DuRZquWndWy/qJX9F3iTebc aV2JP5bvrdTgqZK081znIsekF/lK63fqr9X11+t/JbNzGCj+6I8NZrvrnhv+y81yg9Q9G+f9 pWFZSizFGYmGWsxFxYkAkYziG88CAAA= 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=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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];