From patchwork Fri Jul 22 16:10:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 9243823 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 ABC67602F0 for ; Fri, 22 Jul 2016 16:11:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D0F620747 for ; Fri, 22 Jul 2016 16:11:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91AF727F9A; Fri, 22 Jul 2016 16:11:12 +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.8 required=2.0 tests=BAYES_00,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 1E7DE20747 for ; Fri, 22 Jul 2016 16:11:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751271AbcGVQLL (ORCPT ); Fri, 22 Jul 2016 12:11:11 -0400 Received: from ssl.serverraum.org ([213.133.101.245]:36289 "EHLO ssl.serverraum.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751244AbcGVQLL (ORCPT ); Fri, 22 Jul 2016 12:11:11 -0400 Received: from mwalle01.kse.adk.loc (unknown [194.25.174.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id CC47E22361; Fri, 22 Jul 2016 18:11:04 +0200 (CEST) Authentication-Results: ssl.serverraum.org; dmarc=none header.from=walle.cc DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1469203865; bh=btYbr6jTn1lhN47GGm6WQqhazttT0Mgw0SvQWom57Ec=; h=From:To:Cc:Subject:Date:From; b=qK8N/coNBpT82wrqqKhkxC42cku6gG4K8Epc8oLmOYro6jPMz+7UHVXIP08qpAcaB YIZyhwpH3P+vG1tnRDJRynw5zIp21dCYVYzfaQn4bIjtyumljM4Tc3IJED2InpL32o EK8fLJHsDBBp4Ay+QuRMxbZzOUBvljl+Df0FAH4c= From: Michael Walle To: linux-hwmon@vger.kernel.org Cc: Guenter Roeck , Jean Delvare , linux-kernel@vger.kernel.org, Michael Walle Subject: [PATCH 1/2] hwmon: adt7411: set sane values for CFG1 and CFG3 Date: Fri, 22 Jul 2016 18:10:54 +0200 Message-Id: <1469203855-18094-1-git-send-email-michael@walle.cc> X-Mailer: git-send-email 2.1.4 X-Virus-Scanned: clamav-milter 0.99.2 at web 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 According to the datasheet we have to set some bits as 0 and others as 1. Make sure we do this for CFG1 and CFG3. Signed-off-by: Michael Walle --- drivers/hwmon/adt7411.c | 53 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c index a7f8869..410405b 100644 --- a/drivers/hwmon/adt7411.c +++ b/drivers/hwmon/adt7411.c @@ -30,6 +30,7 @@ #define ADT7411_REG_CFG1 0x18 #define ADT7411_CFG1_START_MONITOR (1 << 0) +#define ADT7411_CFG1_RESERVED_BIT1 (1 << 1) #define ADT7411_CFG1_RESERVED_BIT3 (1 << 3) #define ADT7411_REG_CFG2 0x19 @@ -37,6 +38,9 @@ #define ADT7411_REG_CFG3 0x1a #define ADT7411_CFG3_ADC_CLK_225 (1 << 0) +#define ADT7411_CFG3_RESERVED_BIT1 (1 << 1) +#define ADT7411_CFG3_RESERVED_BIT2 (1 << 2) +#define ADT7411_CFG3_RESERVED_BIT3 (1 << 3) #define ADT7411_CFG3_REF_VDD (1 << 4) #define ADT7411_REG_DEVICE_ID 0x4d @@ -280,6 +284,50 @@ static int adt7411_detect(struct i2c_client *client, return 0; } +static int adt7411_init_device(struct adt7411_data *data) +{ + int ret; + u8 val; + + mutex_lock(&data->device_lock); + + ret = i2c_smbus_read_byte_data(data->client, ADT7411_REG_CFG3); + if (ret < 0) + goto exit_unlock; + + /* + * We must only write zero to bit 1 and bit 2 and only one to bit 3 + * according to the datasheet. + */ + val = ret; + val &= ~(ADT7411_CFG3_RESERVED_BIT1 | ADT7411_CFG3_RESERVED_BIT2); + val |= ADT7411_CFG3_RESERVED_BIT3; + + ret = i2c_smbus_write_byte_data(data->client, ADT7411_REG_CFG3, val); + if (ret < 0) + goto exit_unlock; + + ret = i2c_smbus_read_byte_data(data->client, ADT7411_REG_CFG1); + if (ret < 0) + goto exit_unlock; + + /* + * We must only write zero to bit 1 and only one to bit 3 according to + * the datasheet. + */ + val = ret; + val &= ~ADT7411_CFG1_RESERVED_BIT1; + val |= ADT7411_CFG1_RESERVED_BIT3; + + /* enable monitoring */ + val |= ADT7411_CFG1_START_MONITOR; + + ret = i2c_smbus_write_byte_data(data->client, ADT7411_REG_CFG1, val); + exit_unlock: + mutex_unlock(&data->device_lock); + return ret; +} + static int adt7411_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -297,10 +345,7 @@ static int adt7411_probe(struct i2c_client *client, mutex_init(&data->device_lock); mutex_init(&data->update_lock); - /* According to the datasheet, we must only write 1 to bit 3 */ - ret = adt7411_modify_bit(client, ADT7411_REG_CFG1, - ADT7411_CFG1_RESERVED_BIT3 - | ADT7411_CFG1_START_MONITOR, 1); + ret = adt7411_init_device(data); if (ret < 0) return ret;