From patchwork Thu Mar 30 23:01:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 9655281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 732786034C for ; Thu, 30 Mar 2017 23:01:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C8C524B44 for ; Thu, 30 Mar 2017 23:01:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50B7926E49; Thu, 30 Mar 2017 23:01:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB47C285EA for ; Thu, 30 Mar 2017 23:01:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932294AbdC3XBp (ORCPT ); Thu, 30 Mar 2017 19:01:45 -0400 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:60567 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934122AbdC3XBn (ORCPT ); Thu, 30 Mar 2017 19:01:43 -0400 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 58190886D6; Fri, 31 Mar 2017 12:01:40 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail; t=1490914900; bh=+P8gDUVXTWA3LRhy8099KnHyiIiydlHRsR0dzpVKEQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pdryK6rUAvJtgwkRnkDmInrprNlp/OSnIGzo4A1NMfBdLQhQC7yHtwC+lz5KdPaa2 avQ+7b6lby/Fj0aDvuv6fHUiGh7OdDRx4TNpVI7/HjE+qAHdI/pWtI8i59Bq3wXHXq K3caDpCZCG3LQytWQtEqjFjFHOOTiQg1Zl6ud2CU= Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7, 5, 7, 9061) id ; Fri, 31 Mar 2017 12:01:38 +1300 Received: from chrisp-dl.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by smtp (Postfix) with ESMTP id EF39A13F0FC; Fri, 31 Mar 2017 12:01:39 +1300 (NZDT) Received: by chrisp-dl.atlnz.lc (Postfix, from userid 1030) id EE7CE1E1D76; Fri, 31 Mar 2017 12:01:39 +1300 (NZDT) From: Chris Packham To: linux-hwmon@vger.kernel.org, linux@roeck-us.net Cc: Mahoda Ratnayaka , Chris Packham , Jean Delvare , linux-kernel@vger.kernel.org Subject: [PATCH v5 2/2] lm87: Allow channel data to be set from dts file Date: Fri, 31 Mar 2017 12:01:00 +1300 Message-Id: <20170330230100.989-3-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.11.0.24.ge6920cf In-Reply-To: <20170330230100.989-1-chris.packham@alliedtelesis.co.nz> References: <20170330230100.989-1-chris.packham@alliedtelesis.co.nz> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mahoda Ratnayaka Currently there is no method for setting the channel value from the DTS file. When, the driver uses a dts file to initialize the driver platform_data is not set. As a result channel variable may not be set correctly. Without the channel variable set correctly, some of the sensors will not be initialized correctly. For example temp3 sensor sysfs entries. This implements the schema agreed with the device tree binding document. Signed-off-by: Mahoda Ratnayaka Tested-by: Chris Packham Signed-off-by: Chris Packham --- - Changes since v1: Removed unncessary variables channel and np. Update the code as per review comments. - Changes since v2 (note v3 and v4 skipped): Use of_property_read_bool for flag properties (has-foo) Use regulator API and vcc-supply property to select 5V/3V3 scaling. drivers/hwmon/lm87.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c index e06faf9d3f0f..04a7a1ddb030 100644 --- a/drivers/hwmon/lm87.c +++ b/drivers/hwmon/lm87.c @@ -66,6 +66,7 @@ #include #include #include +#include /* * Addresses to scan @@ -855,8 +856,26 @@ static int lm87_init_client(struct i2c_client *client) { struct lm87_data *data = i2c_get_clientdata(client); int rc; - - if (dev_get_platdata(&client->dev)) { + struct device_node *of_node = client->dev.of_node; + u8 val = 0; + struct regulator *vcc = NULL; + + if (of_node) { + if (of_property_read_bool(of_node, "has-temp3")) + val |= CHAN_TEMP3; + if (of_property_read_bool(of_node, "has-in6")) + val |= CHAN_NO_FAN(0); + if (of_property_read_bool(of_node, "has-in7")) + val |= CHAN_NO_FAN(1); + vcc = devm_regulator_get_optional(&client->dev, "vcc"); + if (!IS_ERR(vcc)) { + if (regulator_get_voltage(vcc) == 5000000) + val |= CHAN_VCC_5V; + } + data->channel = val; + lm87_write_value(client, + LM87_REG_CHANNEL_MODE, data->channel); + } else if (dev_get_platdata(&client->dev)) { data->channel = *(u8 *)dev_get_platdata(&client->dev); lm87_write_value(client, LM87_REG_CHANNEL_MODE, data->channel);