From patchwork Thu Jun 30 03:41:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 9206559 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 08BB960757 for ; Thu, 30 Jun 2016 03:42:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E32542866B for ; Thu, 30 Jun 2016 03:42:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D62D828673; Thu, 30 Jun 2016 03:42:30 +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 4B76D2866B for ; Thu, 30 Jun 2016 03:42:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751704AbcF3Dm3 (ORCPT ); Wed, 29 Jun 2016 23:42:29 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:36076 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751486AbcF3Dm2 (ORCPT ); Wed, 29 Jun 2016 23:42:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=References:In-Reply-To:Message-Id:Date:Subject: Cc:To:From; bh=LE7JZXL81oayaD+1Tj3n9GCmlYsN2ib8ay2NlmwDgiw=; b=KjyLy6cKS2VBzm rrWvyYC2Q7GSErLQsMtBEO0LOFgks5hFDR0pHOr+Mk2vEnCsMCEoEmOn/79uF6fm4xfLCOexwkTVv hyPXAMGDNGZXXf5StgLU7NFmDpUMAvh/I3L/QuOevX/JeT7uB6pwzRhDVQKDXUlIIhHgWiafjLFOT CPd774NrsSP6pltV10/Kd9SbLJPvn5DC2D5RBMEvDhhtoC9C7Ahglk/rTa3D/uhXIMH2VnEe7rBnQ KY7QxjEJ+090mhcPLIQg7qDCMzSR4THVxrZzMTpug6UTrw44T15vX9AusGRRhKXSmLmJ2NzykxRHm qx4IyucGqEzMgrX84Wyg==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:51692 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.86_1) (envelope-from ) id 1bISrY-000PuW-NH; Thu, 30 Jun 2016 03:42:01 +0000 From: Guenter Roeck To: Jean Delvare Cc: Nishanth Menon , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck Subject: [PATCH v3 2/3] hwmon: (tmp102) Rework chip configuration Date: Wed, 29 Jun 2016 20:41:58 -0700 Message-Id: <1467258119-14071-2-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1467258119-14071-1-git-send-email-linux@roeck-us.net> References: <1467258119-14071-1-git-send-email-linux@roeck-us.net> X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: 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 So far the chip was forced into polarity 0, even if it was preconfigured differently. Do not touch the polarity when configuring the chip. Also, the configuration register was read beack to check if the configuration 'sticks'. Ultimately, that is similar to checking if the chip is a tmp102 in the first place. Checking if a write into the configuration register was successful is really not the way to do it, and quite risky if the chip is not a tmp102, so drop that check. Instead, verify if the configuration register has unexpected bits set before writing into it. Signed-off-by: Guenter Roeck --- v3: No change v2: No change drivers/hwmon/tmp102.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/hwmon/tmp102.c b/drivers/hwmon/tmp102.c index fd4a4515692a..82a8a29af2e4 100644 --- a/drivers/hwmon/tmp102.c +++ b/drivers/hwmon/tmp102.c @@ -47,6 +47,17 @@ #define TMP102_TLOW_REG 0x02 #define TMP102_THIGH_REG 0x03 +#define TMP102_CONFREG_MASK (TMP102_CONF_SD | TMP102_CONF_TM | \ + TMP102_CONF_POL | TMP102_CONF_F0 | \ + TMP102_CONF_F1 | TMP102_CONF_OS | \ + TMP102_CONF_EM | TMP102_CONF_AL | \ + TMP102_CONF_CR0 | TMP102_CONF_CR1) + +#define TMP102_CONFIG_CLEAR (TMP102_CONF_SD | TMP102_CONF_OS | \ + TMP102_CONF_CR0) +#define TMP102_CONFIG_SET (TMP102_CONF_TM | TMP102_CONF_EM | \ + TMP102_CONF_CR1) + #define CONVERSION_TIME_MS 35 /* in milli-seconds */ struct tmp102 { @@ -167,9 +178,6 @@ static struct attribute *tmp102_attrs[] = { }; ATTRIBUTE_GROUPS(tmp102); -#define TMP102_CONFIG (TMP102_CONF_TM | TMP102_CONF_EM | TMP102_CONF_CR1) -#define TMP102_CONFIG_RD_ONLY (TMP102_CONF_R0 | TMP102_CONF_R1 | TMP102_CONF_AL) - static const struct thermal_zone_of_device_ops tmp102_of_thermal_ops = { .get_temp = tmp102_read_temp, }; @@ -210,26 +218,25 @@ static int tmp102_probe(struct i2c_client *client, dev_err(dev, "error reading config register\n"); return status; } + + if ((status & ~TMP102_CONFREG_MASK) != + (TMP102_CONF_R0 | TMP102_CONF_R1)) { + dev_err(dev, "unexpected config register value\n"); + return -ENODEV; + } + tmp102->config_orig = status; devm_add_action(dev, tmp102_restore_config, tmp102); - status = i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, - TMP102_CONFIG); + status &= ~TMP102_CONFIG_CLEAR; + status |= TMP102_CONFIG_SET; + + status = i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, status); if (status < 0) { dev_err(dev, "error writing config register\n"); return status; } - status = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG); - if (status < 0) { - dev_err(dev, "error reading config register\n"); - return status; - } - status &= ~TMP102_CONFIG_RD_ONLY; - if (status != TMP102_CONFIG) { - dev_err(dev, "config settings did not stick\n"); - return -ENODEV; - } mutex_init(&tmp102->lock);