Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752352AbaLSIzn (ORCPT ); Fri, 19 Dec 2014 03:55:43 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:20572 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752156AbaLSIzi (ORCPT ); Fri, 19 Dec 2014 03:55:38 -0500 X-AuditID: cbfee691-f79b86d000004a5a-67-5493e804257a 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 V3 11/11] power: charger-manager: Support to change polling rate in runtime. Date: Fri, 19 Dec 2014 17:55:23 +0900 Message-id: <1418979323-7188-12-git-send-email-jonghwa3.lee@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1418979323-7188-1-git-send-email-jonghwa3.lee@samsung.com> References: <1418979323-7188-1-git-send-email-jonghwa3.lee@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrALMWRmVeSWpSXmKPExsWyRsSkQJflxeQQg0U7hCwObtW0uP7lOavF pCfvmS0mrpzMbNF59gmzxeVdc9gsPvceYbS43biCzeLuqaNsFqd3lzhweUzo/8TosXPWXXaP zSu0PDat6mTz6NuyitFjxerv7B6fN8kFsEdx2aSk5mSWpRbp2yVwZfS/+89UcFas4tCb10wN jKeEuhg5OCQETCQu3BftYuQEMsUkLtxbz9bFyMUhJLCUUeLXgwmsMDX3/4lBxKczSlxYfhuq qI1J4vODT+wg3WwCOhL/990Es0UEFCQ29z5jBSliFrjCKHFz8XomkISwQJzEsR3vwIpYBFQl 9h3fxQZi8wp4SNx9NY8NYpuCxJxJNiBhTqDwn5NbwFqFBNwlGrd8ZweZKSGwi11i5ZMpjBBz BCS+TT7EAtErK7HpADPEN5ISB1fcYJ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OTS1ILYLpY+LglGpg1NBo/jJlZ9Sm8u1HfJbEnInckF/tFf71 tZ+anwuLXN/9E28tE07lbVXgnOvc/sdaZF7okuunF3rcr9GZdm5/8M+yzIfHplbYqCpP+3nb XPSz0J3ne553b/x0dUOT1AE7oYTdD57wKDQszjVuLqszar9yJ/2yr4DAjcCKq39UbuYYnxY0 vWAuoMRSnJFoqMVcVJwIAGe1NtXOAgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 f5787bc..a8cabf09 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]; -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/