From patchwork Thu Mar 30 03:46:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Povilus X-Patchwork-Id: 9652905 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 AA762602C8 for ; Thu, 30 Mar 2017 03:46:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B21A27B2F for ; Thu, 30 Mar 2017 03:46:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F6E1280B0; Thu, 30 Mar 2017 03:46:52 +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 870EB27C0B for ; Thu, 30 Mar 2017 03:46:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932685AbdC3Dqu (ORCPT ); Wed, 29 Mar 2017 23:46:50 -0400 Received: from mail-it0-f67.google.com ([209.85.214.67]:36343 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932196AbdC3Dqt (ORCPT ); Wed, 29 Mar 2017 23:46:49 -0400 Received: by mail-it0-f67.google.com with SMTP id 190so11897934itm.3 for ; Wed, 29 Mar 2017 20:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=povil.us; s=google; h=from:to:cc:subject:date:message-id; bh=PSKstPZBnsnKRw7nYvgYUA2xBBdfYdryMUFuPI5qz3M=; b=wp96XPXvIw9ukD+sME/cU/V9FRfu6AFpFyG1wG+tMKHQlqM4v66YY0Mdo4Z80Axwvs HnaTSyr3okCmwIhmAz6tzln+vFZgI/wLgMBT6Tx3WmRK0ozi5T3MMtv8T0TfzaMYEThE 9qiH/f2x++Omtd35lctV2AK5mSxC4j8LEYHPcF5eQOrwATV+MCjsFjC+neUkkv8RV8/D aAequPRjPJmkyfnY9g/ANpQMGqTKvnY6Du+iG75jYzoIgedp+8gdPhXvMZs16rYCcAcz +t4Vv5JM/0vs+YeqPfFBLqRDLWi759wSaQbqMRLpvX18rWKHjAyWD7nDcwwDvRA5oKyU +s3A== 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=PSKstPZBnsnKRw7nYvgYUA2xBBdfYdryMUFuPI5qz3M=; b=drX7RV7PASxhXurlGqTaFoIUTtV823Vr+WBYp2XQBzKeZA0tnQimVxOdVyoms2e37K YK9Re67WA077wSaXV76lGaPbdPVwuhRisnP46EH4c8y41jF8zpgkMrV4wfwyTsVg29iF skmFrQgbVWEJtKAb7FDVYAdn2IGbths0769C/A/5Iai7NRpCRfiCDP1+jaQAoi+yPDm2 xPDc1XH4CZMaszMF85tRu9bbvT2yWurIMXhP2yJSKKDcCh2H1Xt1sZN2L9E6yCygL8e8 jPlN2X9hKoPRV53m1wyRigT7mOjO52Q2BDM5dwYBxTlC6wyMWtuUZwwaEnpi/EBvHZ4R wpCA== X-Gm-Message-State: AFeK/H2jqqIwZIE/gMdJrJ5wxC8ELfiHh5f5L+LXejJJjSIGaAJ6fS10DqvH1JguLhEfgA== X-Received: by 10.36.17.210 with SMTP id 201mr2205780itf.84.1490845608193; Wed, 29 Mar 2017 20:46:48 -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 b132sm778343iob.6.2017.03.29.20.46.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Mar 2017 20:46:47 -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 v6] hwmon: ads7828 optional parameters from the device tree Date: Wed, 29 Mar 2017 21:46:37 -0600 Message-Id: <20170330034637.29708-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. v2: conforming to coding style v3: changing from "_" to "-" for device tree entries v4: using regulator subsystem for voltage source, renaming differential input property v5: checking for invalid vref values sooner and returning error if they are bad, not warning user. v6: optimization per Guenter Roeck Signed-off-by: Sam Povilus --- .../devicetree/bindings/hwmon/ads7828.txt | 26 ++++++++++++++++++++++ drivers/hwmon/ads7828.c | 15 +++++++++++++ 2 files changed, 41 insertions(+) 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..a1251b19079d --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/ads7828.txt @@ -0,0 +1,26 @@ +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-supply = <&vref>; + ti,differential-input; + }; + diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c index ee396ff167d9..88330a233b1d 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,11 @@ 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_uv; 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,6 +134,18 @@ 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) { + diff_input = of_property_read_bool(dev->of_node, + "ti,differential-input"); + reg = devm_regulator_get_optional(dev, "vref"); + if (!IS_ERR(reg)) { + vref_uv = regulator_get_voltage(reg); + vref_mv = DIV_ROUND_CLOSEST(vref_uv, 1000); + if (vref_mv < ADS7828_EXT_VREF_MV_MIN || + vref_mv > ADS7828_EXT_VREF_MV_MAX) + return -EINVAL; + ext_vref = true; + } } /* Bound Vref with min/max values */