From patchwork Sun Mar 19 19:38:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Povilus X-Patchwork-Id: 9632841 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 5CC07601E9 for ; Sun, 19 Mar 2017 19:40:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42CA027FA6 for ; Sun, 19 Mar 2017 19:40:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3425A28306; Sun, 19 Mar 2017 19:40:05 +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 A2A4927FA6 for ; Sun, 19 Mar 2017 19:40:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751643AbdCSTj7 (ORCPT ); Sun, 19 Mar 2017 15:39:59 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:36541 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751972AbdCSTj6 (ORCPT ); Sun, 19 Mar 2017 15:39:58 -0400 Received: by mail-it0-f68.google.com with SMTP id 190so2796469itm.3 for ; Sun, 19 Mar 2017 12:39:03 -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=6B8QoQlCRwuTuEy/SaZ/bZzJBjC0NrfG4ppySVNMhp4=; b=fFPU9iWu9LZwQfWq1hRxBN5xdhHh7rtTIlTZALpBNJ0TBSV/ZJopIQlHBedf1T5nHl Z/pc44crf5OLWBftW7GnE1IW1g5U6cGH1nKFVfFTffInD5/y5fIjkjTj6RxZnuVcsO6X cP2HA8X8Z0ZPdCy8T8czFuOE9HGaskdiabK2mstuva76y++iay81M8YMjJ8amApxfSqX fMCu4gZJDfXYYlwTvjY8pulfvGXnDGpCkI2pAXb12dVYhJhelAXICWQ+S1DOdMzi7kkG kzDmhU69TfvJFJRyykP0Epd5euF1xShTutXh42dj9xyyhW0CgvM52t8gVp2V9YmaC+Nk DDzg== 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=6B8QoQlCRwuTuEy/SaZ/bZzJBjC0NrfG4ppySVNMhp4=; b=gX0/zXkiPw+a7aTISj+4jvVCmZ+OC4K6aGML+qZdfp3VjwaCMqXP2oIjnE6FVuzO3T 2DKK9ZI6lIAjQR7WlgAZleR/cnWBp0waJiFYPXmH4ndJ5aYLVzBIcbPGFdToog0OP09w OHKbWxmAlbua6fpjjI9nFkIoKPkISVz6gGZjK8ISVUKI7DyotKW1y2/hgoG59SpAL82W yFyUVl6mbriKC32rEJtMSci4MOOuNh3hNLhFdw8eeJ4AIBF4vY6pcbB0A6BSTnDjRhwo cZAttwvb9+xIjaMmAfa4UXxA3zgXtxMQ57InjZzSlWf/PTjZ4dJ6FUNMTCIHLUJId5de NhbQ== X-Gm-Message-State: AFeK/H0Y8Dgr16OF2xh8pWX65e9Iy1anN8F/ru6dm2HGD0mVS0j6Zuao7t16DNc7TASn1w== X-Received: by 10.36.80.213 with SMTP id m204mr6526030itb.105.1489952343248; Sun, 19 Mar 2017 12:39:03 -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 p204sm4218445itp.19.2017.03.19.12.39.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Mar 2017 12:39:02 -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 Cc: Sam Povilus Subject: [PATCH v4] hwmon: ads7828 optional parameters from the device tree Date: Sun, 19 Mar 2017 13:38:58 -0600 Message-Id: <20170319193858.24981-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. Because we have made it easy for the user to specify an improper reference voltage, 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 v4: using regulator subsystem for voltage source, renaming differential input property Signed-off-by: Sam Povilus --- .../devicetree/bindings/hwmon/ads7828.txt | 27 ++++++++++++++++++++++ .../devicetree/bindings/i2c/trivial-devices.txt | 2 -- drivers/hwmon/ads7828.c | 23 ++++++++++++++++++ 3 files changed, 50 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..c71b4005e045 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/ads7828.txt @@ -0,0 +1,27 @@ +ads7828 properties + +Required properties: +- compatible: + Should be one of + ti,ads7828 + ti,ads7830 +- reg: I2C address + +Optional properties: + +- ti,differential-input + Set to use the device in differential mode. +- vref + The external reference on the device is set to this regulators output. If it + does not exists the internal reference will be used and output by the ads78xx + on the "external vref" pin. + + Example ADS7828 node: + + ads7828: ads@48 { + comatible = "ti,ads7828"; + reg = <0x48>; + vref = <&vref>; + ti,differential-input; + }; + 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..4f64141b2997 100644 --- a/drivers/hwmon/ads7828.c +++ b/drivers/hwmon/ads7828.c @@ -34,6 +34,7 @@ #include #include #include +#include /* The ADS7828 registers */ #define ADS7828_CMD_SD_SE 0x80 /* Single ended inputs */ @@ -118,9 +119,13 @@ 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; + unsigned int vref_uv = -1; bool diff_input = false; bool ext_vref = false; unsigned int regval; + struct regulator *reg; + data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL); if (!data) @@ -131,11 +136,29 @@ 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, "ti,differential-input", + NULL)) + diff_input = true; + reg = devm_regulator_get_optional(dev, "vref"); + if (!IS_ERR(reg)) { + vref_uv = regulator_get_voltage(reg); + if (vref_uv >= 0) { + vref_mv = DIV_ROUND_CLOSEST(vref_uv, 1000); + ext_vref = true; + } + } } /* 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 reference voltage, it has" + " been clamped to %u mV", + vref_mv); + } /* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */ if (id->driver_data == ads7828) {