From patchwork Sun Mar 12 14:47:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Povilus X-Patchwork-Id: 9619423 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 B2CC760414 for ; Sun, 12 Mar 2017 14:48:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A71DF28495 for ; Sun, 12 Mar 2017 14:48:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B91A2849D; Sun, 12 Mar 2017 14:48:56 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham 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 067DB28495 for ; Sun, 12 Mar 2017 14:48:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934023AbdCLOsz (ORCPT ); Sun, 12 Mar 2017 10:48:55 -0400 Received: from mail-io0-f193.google.com ([209.85.223.193]:35966 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933856AbdCLOsy (ORCPT ); Sun, 12 Mar 2017 10:48:54 -0400 Received: by mail-io0-f193.google.com with SMTP id 68so11149880ioh.3 for ; Sun, 12 Mar 2017 07:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=povil-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=3iaO/OXixL1XBsRosbUWcGAKx3TA8PSb0dC4DX8gNmw=; b=CsPBNeDQ64gmh/AysoM+aMy2+rSjz2mQu2+xbsOFRJrjRyv5M0giVW/rfmOhQGyDYy tdh3+cGeDEQo15DeHp1U9c9bXUzquEowkDI0hbqKLnoQ4flPqWLUifQLqocAQ3UUsUHV 8SJSRAlDtXCdBiCHDaCJdfqK1EuVbc6GpV4rAbawIggXlcP+y4mQIhv11tFfyhlPgHoL VqOyynPMKcUE5cRUgSEXASsghcPyUANzVCayOv3IKZ3qXzbU+7g/OxCfEie7Q26CTL4K uh7DV+PrrmzcLrFamDb7N4cdFl5zslydowDFUCEDFLAGED/1O8QNsx9ymFX0EjjGquRY Veng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3iaO/OXixL1XBsRosbUWcGAKx3TA8PSb0dC4DX8gNmw=; b=NYcZHnu84sFxlwGFmv5VSA3QnQdQwxn2hNJ8S+3Aq2JNWLcoOnsjdeVtF8w0ra8pbZ 6o6E/U2Gyv4g5ayJcqA2iA/4qQmRvpjhhh4Di7sBRZIyuuv3mxXpiSdcj+3TIp8gUjbP BMWJhDpBNTpaT8r26wxMmAAOw/6FhaO6celQz/NbFQ751eXoNNSZBkfGAznOstNsMsIL pmjXli+crUsdwjpSVW1aTB/8uc8MxZswmnKqP4EQnkVIKO+pqXDrPxcJKZHueHWh+FY+ lX4zfJZylXs49dVzgKps/FaESmZgUFFXM6qal3mgXppiRYJaaJZQdvfpDRCXbjREZKJ7 eOPQ== X-Gm-Message-State: AMke39m1QnMt+2gN7zgalZHlPFEscGgu/gTtphyqEORZqp0/593Yolwv3hu69aYfaUWEAQ== X-Received: by 10.107.8.39 with SMTP id 39mr22958360ioi.189.1489330133253; Sun, 12 Mar 2017 07:48:53 -0700 (PDT) Received: from irascible.hsd1.co.comcast.net (c-67-161-204-6.hsd1.co.comcast.net. [67.161.204.6]) by smtp.gmail.com with ESMTPSA id b126sm7035969ioa.55.2017.03.12.07.48.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Mar 2017 07:48:52 -0700 (PDT) From: Sam Povilus To: wsa@the-dreams.de, jdelvare@suse.com, linux@roeck-us.net, linux-hwmon@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: Sam Povilus Subject: [PATCH v3] hwmon: ads7828 optional parameters from the device tree Date: Sun, 12 Mar 2017 08:47:39 -0600 Message-Id: <20170312144739.13276-1-kernel.development@povil.us> X-Mailer: git-send-email 2.11.0 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 Adding the ability for the ads7828 and ads7830 to use the device tree to get their optional parameters, instead of using platform devices. This allows people using custom boards to also use the ads7828 in a non-default manner. Also adding a note to the user if they misconfigure the device's external reference. v2: conforming to coding style v3: changing from "_" to "-" for device tree entries Signed-off-by: Sam Povilus --- Documentation/devicetree/bindings/hwmon/ads7828.txt | 18 ++++++++++++++++++ .../devicetree/bindings/i2c/trivial-devices.txt | 2 -- drivers/hwmon/ads7828.c | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/hwmon/ads7828.txt diff --git a/Documentation/devicetree/bindings/hwmon/ads7828.txt b/Documentation/devicetree/bindings/hwmon/ads7828.txt new file mode 100644 index 000000000000..0d37cd3fd31b --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/ads7828.txt @@ -0,0 +1,18 @@ +ads7828 properties + +Required properties: +- compatible: + Should be one of + ti,ads7828 + ti,ads7830 +- reg: I2C address + +Optional properties: + +- diff-input + Set to use the device in differential mode. +- ext-vref + Set to enable the external voltage reference on the device. +- vref-mv + The external reference on the device is set to this as an unsigned integer in + milivolts. Must use "ext_vref" for this to have any meaning. diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt b/Documentation/devicetree/bindings/i2c/trivial-devices.txt index cdd7b48826c3..87648909f6ce 100644 --- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt +++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt @@ -163,8 +163,6 @@ st,m41t00 Serial real-time clock (RTC) st,m41t62 Serial real-time clock (RTC) with alarm st,m41t80 M41T80 - SERIAL ACCESS RTC WITH ALARMS taos,tsl2550 Ambient Light Sensor with SMBUS/Two Wire Serial Interface -ti,ads7828 8-Channels, 12-bit ADC -ti,ads7830 8-Channels, 8-bit ADC ti,tsc2003 I2C Touch-Screen Controller ti,tmp102 Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface ti,tmp103 Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c index ee396ff167d9..d1f7ba5d7a2b 100644 --- a/drivers/hwmon/ads7828.c +++ b/drivers/hwmon/ads7828.c @@ -118,6 +118,7 @@ static int ads7828_probe(struct i2c_client *client, struct ads7828_data *data; struct device *hwmon_dev; unsigned int vref_mv = ADS7828_INT_VREF_MV; + unsigned int vref_mv_tmp; bool diff_input = false; bool ext_vref = false; unsigned int regval; @@ -131,11 +132,25 @@ static int ads7828_probe(struct i2c_client *client, ext_vref = pdata->ext_vref; if (ext_vref && pdata->vref_mv) vref_mv = pdata->vref_mv; + } else if (dev->of_node) { + if (of_get_property(dev->of_node, "diff-input", NULL)) + diff_input = true; + if (of_get_property(dev->of_node, "ext-vref", NULL)) + ext_vref = true; + if (!of_property_read_u32(dev->of_node, "vref-mv", &vref_mv_tmp) + && ext_vref) + vref_mv = vref_mv_tmp; } /* Bound Vref with min/max values */ + vref_mv_tmp = vref_mv; vref_mv = clamp_val(vref_mv, ADS7828_EXT_VREF_MV_MIN, ADS7828_EXT_VREF_MV_MAX); + if (vref_mv_tmp != vref_mv) { + pr_info("You used and invalid external vref," + " it has been clamped to %u", + vref_mv); + } /* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */ if (id->driver_data == ads7828) {