Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp387643ybg; Tue, 28 Jul 2020 08:28:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPgehLtE0B1LMQIxcrlSQ3K5kLF4i2OUgRTXUeN0CEiLac+Qk1w50tprtMxzccZ03lxABN X-Received: by 2002:a17:907:728a:: with SMTP id dt10mr25270277ejc.150.1595950092817; Tue, 28 Jul 2020 08:28:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595950092; cv=none; d=google.com; s=arc-20160816; b=ac8ATPa2OWVpT21BJs6n+KWwY2eceD5JKx2isaXtPJjTWbRh2mM5HIEtmk6PtNh34E e9bRXL7jWKPUAhLAQsDSw4GL50wQFCC94JEpOxMFqg5UWQ+gPcAVvUObzGV2AdECftmu ywSfIJi028680GP4oiDsDsLfR/v5YkJlfb5D9EpvepTU91XpsudwmUOk2XWmUNxKymnk V06JelZyWlbq6EKcznf2ZpMfTpiV8xKvD+1TivhUjPB48FmpjKB/9CayWdr33zaXsjzY aVOBKXu1DK2X8hPhCz+6Sx5dbI+SRjTGBkGgaigK2hbP9E3l3lAw5wlUszp1tHRGhGYX 6L2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=kZwxRgujYKC1YxyOfF0SCaN3/JeD6fivvOedLcz7eRA=; b=KzgSoNV3l5AHML+m049i7psb5p7Jilg1Ae+1uWQtMGdbxBzbkc2/vkFJi5he+Gzq9S RCIsJa2H2dZsEBtikpLdM1/DCr9Z1Os+q2+XjrcDa4IopPy5FRRtnbJYjqylFspj13Ff MGVElJZee8bHX5AXAUkLqIGJOD8+DLQikdIjdjSUy+nXUufghV1rW3GHiHsmjFQRlWxi eu6nskA/DZZGvNTfIuFGLohwJu8VXyzIlMUIgOOWTa7JiRZHNW37FpLvbzuJXU51MU7R ZsXMdqFPEhgeqIbqBJmNgAWMWE7q4RPYwa/2B08Rn6p32CAA/kHmNEbQltD7/yPDw80+ N3sQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=prodrive-technologies.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si8050778edn.520.2020.07.28.08.27.50; Tue, 28 Jul 2020 08:28:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=prodrive-technologies.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730824AbgG1P0T (ORCPT + 99 others); Tue, 28 Jul 2020 11:26:19 -0400 Received: from mail.prodrive-technologies.com ([212.61.153.67]:59094 "EHLO mail.prodrive-technologies.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730669AbgG1P0T (ORCPT ); Tue, 28 Jul 2020 11:26:19 -0400 X-Greylist: delayed 350 seconds by postgrey-1.27 at vger.kernel.org; Tue, 28 Jul 2020 11:26:17 EDT Received: from mail.prodrive-technologies.com (localhost.localdomain [127.0.0.1]) by localhost (Email Security Appliance) with SMTP id 784D732EBC_F20423AB; Tue, 28 Jul 2020 15:20:26 +0000 (GMT) Received: from mail.prodrive-technologies.com (mdb-dag.prodrive.nl [10.1.1.212]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (Client CN "mail.prodrive-technologies.com", Issuer "GlobalSign RSA OV SSL CA 2018" (verified OK)) by mail.prodrive-technologies.com (Sophos Email Appliance) with ESMTPS id E7900303C1_F20422AF; Tue, 28 Jul 2020 15:20:10 +0000 (GMT) Received: from lnxclnt2222.Prodrive.nl (10.130.5.194) by EXC03.bk.prodrive.nl (10.1.1.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1913.5; Tue, 28 Jul 2020 17:20:10 +0200 From: Roy van Doormaal To: CC: Roy van Doormaal , "Jean Delvare" , Guenter Roeck , open list Subject: [PATCH] hwmon: (adc128d818) Fix advanced configuration register init Date: Tue, 28 Jul 2020 17:18:45 +0200 Message-ID: <20200728151846.231785-1-roy.van.doormaal@prodrive-technologies.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-ClientProxiedBy: EXC03.bk.prodrive.nl (10.1.1.212) To EXC03.bk.prodrive.nl (10.1.1.212) X-SASI-RCODE: 200 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the operation mode is non-zero and an external reference voltage is set, first the operation mode is written to the advanced configuration register, followed by the externel reference enable bit, resetting the configuration mode to 0. To fix this, first compose the value of the advanced configuration register based on the configuration mode and the external reference voltage. The advanced configuration register is then written to the device, if it is different from the default register value (0x0). Signed-off-by: Roy van Doormaal --- drivers/hwmon/adc128d818.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/hwmon/adc128d818.c b/drivers/hwmon/adc128d818.c index f9edec195c35..571d5454c6b2 100644 --- a/drivers/hwmon/adc128d818.c +++ b/drivers/hwmon/adc128d818.c @@ -393,6 +393,7 @@ static int adc128_init_client(struct adc128_data *data) { struct i2c_client *client = data->client; int err; + u8 regval = 0x0; /* * Reset chip to defaults. @@ -403,10 +404,17 @@ static int adc128_init_client(struct adc128_data *data) 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 (data->mode != 0) + regval |= data->mode << 1; + + /* If external vref is selected, configure the chip to use it */ + if (data->regulator) + regval |= 0x01; + + /* Write advanced configuration register */ + if (regval != 0x0) { + err = i2c_smbus_write_byte_data(client, ADC128_REG_CONFIG_ADV, + regval); if (err) return err; } @@ -416,14 +424,6 @@ static int adc128_init_client(struct adc128_data *data) if (err) return err; - /* If external vref is selected, configure the chip to use it */ - if (data->regulator) { - err = i2c_smbus_write_byte_data(client, - ADC128_REG_CONFIG_ADV, 0x01); - if (err) - return err; - } - return 0; } -- 2.20.1