From patchwork Mon Dec 22 16:27:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 5528011 X-Patchwork-Delegate: eduardo.valentin@ti.com 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 111019F326 for ; Mon, 22 Dec 2014 16:29:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E6372017A for ; Mon, 22 Dec 2014 16:29:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 40BD620108 for ; Mon, 22 Dec 2014 16:29:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932203AbaLVQ3F (ORCPT ); Mon, 22 Dec 2014 11:29:05 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:24487 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932157AbaLVQ27 (ORCPT ); Mon, 22 Dec 2014 11:28:59 -0500 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NGZ00IO2SG9MO40@mailout1.samsung.com>; Tue, 23 Dec 2014 01:28:57 +0900 (KST) X-AuditID: cbfee61b-f79d76d0000024d6-88-549846c907a8 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 48.ED.09430.9C648945; Tue, 23 Dec 2014 01:28:57 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NGZ00H17SEF7V60@mmp1.samsung.com>; Tue, 23 Dec 2014 01:28:57 +0900 (KST) From: Lukasz Majewski To: Eduardo Valentin , Kamil Debski , Jean Delvare , Guenter Roeck Cc: lm-sensors@lm-sensors.org, Linux PM list , "linux-samsung-soc@vger.kernel.org" , devicetree@vger.kernel.org, Lukasz Majewski , Kukjin Kim , linux-kernel@vger.kernel.org, Sylwester Nawrocki , Abhilash Kesavan , Abhilash Kesavan , Lukasz Majewski Subject: [PATCH v2 7/8] hwmon: thermal: Read PWM FAN configuration from device tree Date: Mon, 22 Dec 2014 17:27:47 +0100 Message-id: <1419265668-32283-8-git-send-email-l.majewski@samsung.com> X-Mailer: git-send-email 1.7.10.4 In-reply-to: <1419265668-32283-1-git-send-email-l.majewski@samsung.com> References: <1418897591-18332-1-git-send-email-l.majewski@samsung.com> <1419265668-32283-1-git-send-email-l.majewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKLMWRmVeSWpSXmKPExsVy+t9jAd2TbjNCDJb9ULZ4vGYxk8X8I+dY LeZfucZqsfTuJzaLH68vsFms+atk0bvgKpvFm0fcFm8ebma0uLxrDpvF594jjBYzzu9jsniy 8AyTxZ1pe9ksDr9pZ3Xg99g56y67x4OJu9k81k17y+yx83sDu0ffllWMHptPV3t83iQXwB7F ZZOSmpNZllqkb5fAlXGgeRJrwSLhirkbl7E1MN7g72Lk5JAQMJHoWr+OGcIWk7hwbz1bFyMX h5DAIkaJKw/OskA4XUwSV75NYQepYhPQk/h89ykTSEJEYAajxP6mb+wgDrPAFWaJb6caWUCq hAVCJeYcOwNmswioSny79YARxOYVcJM4dmQtC8Q+RYnuZxOA9nFwcAq4S/x+xQuxrZlR4tSC RuYJjLwLGBlWMYqmFiQXFCel5xrpFSfmFpfmpesl5+duYgQH7jPpHYyrGiwOMQpwMCrx8HKm TQ8RYk0sK67MPcQowcGsJMJ71XJGiBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXFeJfu2ECGB9MSS 1OzU1ILUIpgsEwenVAOjQtaigvc2xw+8tKytff7zXXH/6jSv1iOLv92v3dLfO8lSK0Ftl+2s WfVuC5da7deueedyev0j1mn3jWQkdweJ+148rPf4RPlPtr/xy+0fG1wTcnnGtP7ck+SjptYH P2x+0eYq7VM+RSgk/6zlVTFT5dQJqwUWsfUfa3+Y36Nyj9VATDXRKThdiaU4I9FQi7moOBEA T2O9VVgCAAA= 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 Code for reading PWM FAN configuration data via device tree. Signed-off-by: Lukasz Majewski --- Changes for v2: - Rename pwm_fan_max_states to pwm_fan_cooling_levels - Moving pwm_fan_of_get_cooling_data() call after setting end enabling PWM FAN - pwm_fan_of_get_cooling_data() now can fail - preserving old behaviour - Remove unnecessary dev_err() call --- drivers/hwmon/pwm-fan.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 870e100..8e68308 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -30,7 +30,10 @@ struct pwm_fan_ctx { struct mutex lock; struct pwm_device *pwm; - unsigned char pwm_value; + unsigned int pwm_value; + unsigned int pwm_fan_state; + unsigned int pwm_fan_max_state; + unsigned int *pwm_fan_cooling_levels; }; static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) @@ -100,6 +103,47 @@ static struct attribute *pwm_fan_attrs[] = { ATTRIBUTE_GROUPS(pwm_fan); +int pwm_fan_of_get_cooling_data(struct device *dev, struct pwm_fan_ctx *ctx) +{ + struct device_node *np = dev->of_node; + struct property *pp; + int len, num, i; + + pp = of_find_property(np, "cooling-levels", &len); + if (!pp) { + dev_err(dev, "Property: 'cooling-levels' not found\n"); + return -EINVAL; + } + + if (len == 0) { + dev_err(dev, "Length wrong value!\n"); + return -EINVAL; + } + + ctx->pwm_fan_cooling_levels = devm_kzalloc(dev, len, GFP_KERNEL); + if (!ctx->pwm_fan_cooling_levels) + return -ENOMEM; + + num = len / sizeof(u32); + if (of_property_read_u32_array(np, pp->name, + ctx->pwm_fan_cooling_levels, num)) { + dev_err(dev, "Property: %s cannot be read!\n", pp->name); + return -EINVAL; + } + + for (i = 0; i < num; i++) { + if (ctx->pwm_fan_cooling_levels[i] > MAX_PWM) { + dev_err(dev, "PWM fan state[%d]:%d > %d\n", i, + ctx->pwm_fan_cooling_levels[i], MAX_PWM); + return -EINVAL; + } + } + + ctx->pwm_fan_max_state = num - 1; + + return 0; +} + static int pwm_fan_probe(struct platform_device *pdev) { struct device *hwmon; @@ -145,6 +189,8 @@ static int pwm_fan_probe(struct platform_device *pdev) pwm_disable(ctx->pwm); return PTR_ERR(hwmon); } + + pwm_fan_of_get_cooling_data(&pdev->dev, ctx); return 0; }