From patchwork Fri Dec 23 22:12:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Koch X-Patchwork-Id: 9487701 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 D640D62AAE for ; Fri, 23 Dec 2016 22:13:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8C1F204C2 for ; Fri, 23 Dec 2016 22:13:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B307F20564; Fri, 23 Dec 2016 22:13: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.0 required=2.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_SIGNED, RCVD_IN_DNSWL_HI, 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 8E48620564 for ; Fri, 23 Dec 2016 22:13:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758418AbcLWWND (ORCPT ); Fri, 23 Dec 2016 17:13:03 -0500 Received: from argos.tuxed.org ([176.9.87.227]:51061 "EHLO argos.tuxed.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753554AbcLWWNB (ORCPT ); Fri, 23 Dec 2016 17:13:01 -0500 Received: from thor.home.lan (unknown [IPv6:2a02:8071:3183:6700:8080:df34:b3ba:2cd1]) by argos.tuxed.org (Postfix) with ESMTPSA id 847056E381; Fri, 23 Dec 2016 23:12:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alexanderkoch.net; s=default; t=1482531156; bh=CEj1n7iRV82ZSoiWEJaVZkoYdBsHz2Qi/kY9RmXb3Ik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NkZ6eTtYeS3NbYNicfvUo0JfOTxgnf6S2If8l14Pb5vgqE48lZ/Wntw3Ax/b/x/HG yGk7CW0NAnh0pk4ZbDWnaruVAZR50U1M3IAJqJaebutSZiRAsoYXpClHO3hiVbTH0x mY6PJypPP4WVZsJyPRPYl7ErSXv9LqzWWiKndCUU= From: Alexander Koch To: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org Cc: Rob Herring , Mark Rutland , Jean Delvare , Guenter Roeck , Jiri Kosina , Alexander Koch Subject: [RFC PATCH v2 2/4] hwmon: adc128d818: Implement mode selection via dt Date: Fri, 23 Dec 2016 23:12:03 +0100 Message-Id: <20161223221205.8825-3-mail@alexanderkoch.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161223221205.8825-1-mail@alexanderkoch.net> References: <20161223221205.8825-1-mail@alexanderkoch.net> X-Virus-Scanned: clamav-milter 0.99.2 at argos X-Virus-Status: Clean 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 Implement operation mode selection using the optional 'mode' devicetree property (see [1]). The ADC128D818 supports four operation modes differing in the number and type of input readings (see datasheet, sec. 8.4.1), of which mode 0 is the default. We only add handling of the 'mode' property here, the driver still supports nothing else than the default mode 0. [1] Documentation/devicetree/bindings/hwmon/adc128d818.txt Signed-off-by: Alexander Koch --- drivers/hwmon/adc128d818.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/hwmon/adc128d818.c b/drivers/hwmon/adc128d818.c index ad2b47e40345..8667f454ea11 100644 --- a/drivers/hwmon/adc128d818.c +++ b/drivers/hwmon/adc128d818.c @@ -28,6 +28,7 @@ #include #include #include +#include /* Addresses to scan * The chip also supports addresses 0x35..0x37. Don't scan those addresses @@ -63,6 +64,7 @@ struct adc128_data { struct regulator *regulator; int vref; /* Reference voltage in mV */ struct mutex update_lock; + u8 mode; /* Operation mode */ bool valid; /* true if following fields are valid */ unsigned long last_updated; /* In jiffies */ @@ -387,6 +389,15 @@ static int adc128_init_client(struct adc128_data *data) if (err) return err; + /* Set operation mode, if non-default */ + if (data->mode != 0) { + err = i2c_smbus_write_byte_data(client, + ADC128_REG_CONFIG_ADV, + data->mode << 1); + if (err) + return err; + } + /* Start monitoring */ err = i2c_smbus_write_byte_data(client, ADC128_REG_CONFIG, 0x01); if (err) @@ -433,6 +444,19 @@ static int adc128_probe(struct i2c_client *client, data->vref = 2560; /* 2.56V, in mV */ } + /* Operation mode is optional and defaults to mode 0 */ + if (of_property_read_u8(dev->of_node, "mode", &data->mode) == 0) { + /* Currently only mode 0 supported */ + if (data->mode != 0) { + dev_err(dev, "unsupported operation mode %d", + data->mode); + err = -EINVAL; + goto error; + } + } else { + data->mode = 0; + } + data->client = client; i2c_set_clientdata(client, data); mutex_init(&data->update_lock);