From patchwork Sun Mar 12 03:22:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Povilus X-Patchwork-Id: 737775 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vgmXg5rV4z9s7H for ; Sun, 12 Mar 2017 14:22:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=povil-us.20150623.gappssmtp.com header.i=@povil-us.20150623.gappssmtp.com header.b="AhoFXgVB"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755591AbdCLDW6 (ORCPT ); Sat, 11 Mar 2017 22:22:58 -0500 Received: from mail-it0-f68.google.com ([209.85.214.68]:36195 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755644AbdCLDW5 (ORCPT ); Sat, 11 Mar 2017 22:22:57 -0500 Received: by mail-it0-f68.google.com with SMTP id w185so3077015ita.3 for ; Sat, 11 Mar 2017 19:22:56 -0800 (PST) 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=BKqjVCoIsno+cOaHx/UUC0HG8/LlBWuL0+jbqKri97o=; b=AhoFXgVBRxp3rSJlmGZlUxSI2SVhZHKzgwZolOntlxENMd8VRyeitqoIR/2Ml8w7A9 r4yx5w5e5mK9i7yjQMHDKOPC2rx1YoG8kldWayHmIvOQ054s/Hx+hI2w+FVbt2RmlQ4C BQNqD4sZ6bGEtB7SQt3vva5IVKgblntT+ofcBx0CSOz1OKC2MMYmdyVepNe/aUvRTWEQ NB4rZaBeYCGdYzhVK7U6Ea8GbBK3SFWg/2EeeT4TZCY/LaDzBya9RRvo4zv528TiajiX FYtewjSggpmsGzk35e0taoVkbGqufHbhCO97BFHvqhLhcnG8MlkM0o5QSduE0crsMozJ XXwA== 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=BKqjVCoIsno+cOaHx/UUC0HG8/LlBWuL0+jbqKri97o=; b=TAB/UPPCo1GbEHRq0sCkWjLHttjerszIDgkom2nQi3UA1SNHkwrpk4+hc1Mk+5mLu+ xXWtePH4wbIwE68yQY/+7Km5ZtSf2Eq41UPi1DLmUFABx/+OKL1tViERMJ57SFgj/qj+ Ho668Zym29Px9bpbxGWnr+ZbIi6RuYVrdImuAM6vBN0BFO8OquP8FQSrUXXDTMU47QY8 t7KSEyjojFBD/gahS/U/JAd4Cnx8MdG1e7FbmuNQ3kJnMIEFiFxTCi3IhQDOp1uRXpZ0 ub4fTdQCKPnrtiVhi+nHp7KF50xgbypsluAi2WvoxjTiuEbVkfGXAC7sDF+/3SO/uBAw 3gaA== X-Gm-Message-State: AFeK/H0MJLw3Th4wcQUDNR/BTt1DnGqENNhGHa4s6j8OvV3WQbcljSH1egAu/RkqLrqsNg== X-Received: by 10.36.14.77 with SMTP id 74mr5170866ite.115.1489288976237; Sat, 11 Mar 2017 19:22:56 -0800 (PST) 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 e62sm6523788ioj.2.2017.03.11.19.22.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Mar 2017 19:22:55 -0800 (PST) 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 Cc: Sam Povilus Subject: [PATCH] Adding the ability for the ads7828 and ads7830 to use the device tree to get thier optional parameters, instead of using platform devices. This allows people using custom boards to also use the ads7828 in a non-default manner. Date: Sat, 11 Mar 2017 20:22:52 -0700 Message-Id: <20170312032252.10656-1-kernel.development@povil.us> X-Mailer: git-send-email 2.11.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Also adding a note to the user if they misconfigure the device's external reference. Signed-off-by: Sam Povilus --- Documentation/devicetree/bindings/hwmon/ads7828.txt | 18 ++++++++++++++++++ .../devicetree/bindings/i2c/trivial-devices.txt | 2 -- drivers/hwmon/ads7828.c | 21 +++++++++++++++++++++ 3 files changed, 39 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..7cd786585b51 --- /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..1a6a91f3701f 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,31 @@ 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) {