From patchwork Wed Aug 10 14:19:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Looijmans X-Patchwork-Id: 657770 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3s8fK70j9Sz9sxb for ; Thu, 11 Aug 2016 04:08:26 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750786AbcHJSIB (ORCPT ); Wed, 10 Aug 2016 14:08:01 -0400 Received: from atl4mhfb03.myregisteredsite.com ([209.17.115.119]:35576 "EHLO atl4mhfb03.myregisteredsite.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932793AbcHJSH7 (ORCPT ); Wed, 10 Aug 2016 14:07:59 -0400 X-Greylist: delayed 419 seconds by postgrey-1.27 at vger.kernel.org; Wed, 10 Aug 2016 14:07:59 EDT Received: from atl4mhob19.myregisteredsite.com (atl4mhob19.myregisteredsite.com [209.17.115.112]) by atl4mhfb03.myregisteredsite.com (8.14.4/8.14.4) with ESMTP id u7AEJv2Q025241 for ; Wed, 10 Aug 2016 10:19:57 -0400 Received: from mailpod.hostingplatform.com ([10.30.71.204]) by atl4mhob19.myregisteredsite.com (8.14.4/8.14.4) with ESMTP id u7AEJro4026319 for ; Wed, 10 Aug 2016 10:19:53 -0400 Received: (qmail 23910 invoked by uid 0); 10 Aug 2016 14:19:53 -0000 X-TCPREMOTEIP: 37.74.225.130 X-Authenticated-UID: mike@milosoftware.com Received: from unknown (HELO mikebuntu.TOPIC.LOCAL) (mike@milosoftware.com@37.74.225.130) by 0 with ESMTPA; 10 Aug 2016 14:19:53 -0000 From: Mike Looijmans To: lm-sensors@lm-sensors.org, devicetree@vger.kernel.org Cc: linux@roeck-us.net, linux-kernel@vger.kernel.org, Mike Looijmans Subject: [PATCH v3] hwmon/max6650.c: Add devicetree support Date: Wed, 10 Aug 2016 16:19:47 +0200 Message-Id: <1470838787-8273-1-git-send-email-mike.looijmans@topic.nl> X-Mailer: git-send-email 1.9.1 References: <1470727827-15907-1-git-send-email-mike.looijmans@topic.nl> <20160809163727.GC9105@roeck-us.net> In-Reply-To: <20160809163727.GC9105@roeck-us.net> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Parse devicetree parameters for voltage and prescaler setting. This allows using multiple max6550 devices with varying settings, and also makes it possible to instantiate and configure the device using devicetree. Signed-off-by: Mike Looijmans --- v3: Resubmit because mailing lists bounced Fix style errors as reported by checkpatch.pl Fix bug in DT parsing of fan-prescale v2: Add devicetree binding documentation Code changes as suggested by Guenter Reduce log info, output only a single line .../devicetree/bindings/hwmon/max6650.txt | 20 ++++++++++++++++ drivers/hwmon/max6650.c | 28 +++++++++++++--------- 2 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 Documentation/devicetree/bindings/hwmon/max6650.txt diff --git a/Documentation/devicetree/bindings/hwmon/max6650.txt b/Documentation/devicetree/bindings/hwmon/max6650.txt new file mode 100644 index 0000000..89d87c6 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/max6650.txt @@ -0,0 +1,20 @@ +Bindings for MAX6651 and MAX6650 I2C fan controllers + +Required properties: +- compatible : One of "max6650" or "max6651" +- reg : I2C address + +Optional properties: +- fan-voltage : The supply voltage of the fan. Valid values are 5 and 12. + Default is to use the chip's current setting. +- fan-prescale : Pre-scaling value as per datasheet. Valid are 1, 2, 4, 8, 16. + Default is to use the chip's current setting. + + +Example: + fan-max6650: max6650@1b { + reg = <0x1b>; + compatible = "max6650"; + fan-voltage = <12>; + fan-prescale = <4>; + }; diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c index 162a520..56a6c87 100644 --- a/drivers/hwmon/max6650.c +++ b/drivers/hwmon/max6650.c @@ -41,14 +41,14 @@ #include /* - * Insmod parameters + * Insmod parameters (for backward compatibility) */ /* fan_voltage: 5=5V fan, 12=12V fan, 0=don't change */ static int fan_voltage; /* prescaler: Possible values are 1, 2, 4, 8, 16 or 0 for don't change */ static int prescaler; -/* clock: The clock frequency of the chip the driver should assume */ +/* clock: The clock frequency of the chip (max6651 can be clocked externally) */ static int clock = 254000; module_param(fan_voltage, int, S_IRUGO); @@ -566,6 +566,15 @@ static int max6650_init_client(struct max6650_data *data, struct device *dev = &client->dev; int config; int err = -EIO; + u32 voltage; + u32 prescale; + + if (of_property_read_u32(client->dev.of_node, "fan-voltage", + &voltage)) + voltage = fan_voltage; + if (of_property_read_u32(client->dev.of_node, "fan-prescale", + &prescale)) + prescale = prescaler; config = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG); @@ -574,7 +583,7 @@ static int max6650_init_client(struct max6650_data *data, return err; } - switch (fan_voltage) { + switch (voltage) { case 0: break; case 5: @@ -584,14 +593,10 @@ static int max6650_init_client(struct max6650_data *data, config |= MAX6650_CFG_V12; break; default: - dev_err(dev, "illegal value for fan_voltage (%d)\n", - fan_voltage); + dev_err(dev, "illegal value for fan_voltage (%d)\n", voltage); } - dev_info(dev, "Fan voltage is set to %dV.\n", - (config & MAX6650_CFG_V12) ? 12 : 5); - - switch (prescaler) { + switch (prescale) { case 0: break; case 1: @@ -614,10 +619,11 @@ static int max6650_init_client(struct max6650_data *data, | MAX6650_CFG_PRESCALER_16; break; default: - dev_err(dev, "illegal value for prescaler (%d)\n", prescaler); + dev_err(dev, "illegal value for prescaler (%d)\n", prescale); } - dev_info(dev, "Prescaler is set to %d.\n", + dev_info(dev, "Fan voltage: %dV, prescaler: %d.\n", + (config & MAX6650_CFG_V12) ? 12 : 5, 1 << (config & MAX6650_CFG_PRESCALER_MASK)); /*