Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1298187imu; Tue, 11 Dec 2018 16:57:45 -0800 (PST) X-Google-Smtp-Source: AFSGD/VGrJcBHDHj66bctitwlaPHTc3Yolzcc+kHXl/IHsUQs3rnGDWYlbMXvCX9w2A2mscy2TMw X-Received: by 2002:a63:344e:: with SMTP id b75mr15906496pga.184.1544576265254; Tue, 11 Dec 2018 16:57:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544576265; cv=none; d=google.com; s=arc-20160816; b=abKHfrLCxPWHzQ0lcenxdNgJsgSlL1bAu7ZTQeSqcsf6Mt0XEs5lqckNNcIDrLKvOX PpAU7YK/wTku1zbP7L46hoUxA3ogjY+UvW5X9YZowr7F9vzMJ7EnPeFfWvBxyRDJnfEq C8AZXbxpMyK50M4rC4JY98AREkKqzJJ2Fji4TwS8H6fFm31yFqO8rtv8zhZWo8+0+VsM D3B+QkodP1egoQBUC8NGZKAFb9aw0DEsv7quViXUVT1w+eI2LWPfMMs9dJaIcplU4HE/ k0qd1w04aA3rgayWwkRCaFpqX0pKDZz8vkr5uPlio4aA7/gC/jQ0ZSGXjP2PPFqnYaEU YhKw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=R4U3PNF7JZZPKLCYh0Oave/Y3+d9jjju4/OWSW4r6jQ=; b=RsHyP0bVo5zjA42ETDsjtHLx8wjfI13MauB3P65jajEY6hZoU8IocCaooRvAiiT9HO lRoJyT6eYq7sRmerSofvRCtLBKBUcelBA9DBRDDm5MBTSC6S3Crquwx8rjfsOwPuFR2w PGGVBgsYxx1P5acEX9NLAJP4IwwUDEBfKs5yqVtcY2ZNe2QOhcmhp6tmhIfyVY5Rc2g5 AOiQ4Wad3nnzcgkEBjUWpFalPOOUKn2+4nBH6hB5Rjw3IpsYIDYg4LrWcOwnmlhSjk7H N7WCSxcYyURwfrPCDKNuasbhXV6SUWBD5s8d5BH7TjHTRQZiYi9YLLFNmeGZVoiSoRDe OHHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aIwD8A2K; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3si12386866pga.297.2018.12.11.16.57.30; Tue, 11 Dec 2018 16:57:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aIwD8A2K; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726436AbeLLA4N (ORCPT + 99 others); Tue, 11 Dec 2018 19:56:13 -0500 Received: from mail-it1-f195.google.com ([209.85.166.195]:50655 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726378AbeLLAzx (ORCPT ); Tue, 11 Dec 2018 19:55:53 -0500 Received: by mail-it1-f195.google.com with SMTP id z7so6616520iti.0; Tue, 11 Dec 2018 16:55:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R4U3PNF7JZZPKLCYh0Oave/Y3+d9jjju4/OWSW4r6jQ=; b=aIwD8A2Kcld+gp/b1xdxZy0FZTjXcslHyF694uIJTlbT1P229Bu50T2bSZdHcNMErF 40uRUYksS7Rts3ar07s0MWKjBHP8fruipwTOb/mBJu/oy6LYc4GhJgtToKerFTNexbQp kdMEBbqVkezlX1Q8JoGS9ov9EXp3OYeve9zm7arlwVjwVhoQ8NL0yqrpMuFbQFMHtnE/ fSVt6eXVVQubH1oTTfgioWfUvTQSI4NHLY441d4jJyKWXm/owPT6U2W4BWFqM1GyLImU mGVrGpejKGkCKaVX3anWqZkqGeDpdttmKG/Kv1RWFXjRwIpg+Sv9pqAwXbkeYMrZZ3SM oqIg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=R4U3PNF7JZZPKLCYh0Oave/Y3+d9jjju4/OWSW4r6jQ=; b=hXATk9QP1IWkt+D9O+t04VW6pDYaGz+V+wTd7GUo+0lgYTPaccH1AD9NruM83iNmXk JQGzTVf/EJZl3sc6syrHByf+ja8pJmMvt0tE2+sWlpziBCVk+I3gZN7OCdC6W4dPG5RN SGBo9ThjyuEcjhwvmVQTm+Em4/PPEiDqmIMO4rqe0i/COaoZSuKaCRDBcYAk5BZGHiB2 PhakmGEdtjZJgQ818fEj0fT8tr8EJkiymAnTHlrQ3YYIv36t0VFU39iT9BhyYhTexvnv J/rhxnyoUkIomXk4DD+ZFWuKZxNmW7PDpsd7HPjBp0AlWShaOZalZBkyC3mUnG1xyJAj aryw== X-Gm-Message-State: AA+aEWbIHPFitpA3VhCbt8WEB319h736BonMfPa/rsd+h8bzZPHmGSbf 7/AocIR5yy3rcscyldrYb3E= X-Received: by 2002:a24:4709:: with SMTP id t9mr4551515itb.47.1544576152796; Tue, 11 Dec 2018 16:55:52 -0800 (PST) Received: from r2700x.localdomain (c-75-70-96-103.hsd1.co.comcast.net. [75.70.96.103]) by smtp.gmail.com with ESMTPSA id l186sm1952445itl.22.2018.12.11.16.55.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 16:55:52 -0800 (PST) From: Jeremy Fertic To: Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , Hartmut Knaack , Peter Meerwald-Stadler , Greg Kroah-Hartman , linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Jeremy Fertic Subject: [PATCH 10/11] staging: iio: adt7316: change interpretation of write to dac update mode Date: Tue, 11 Dec 2018 17:55:02 -0700 Message-Id: <20181212005503.28054-11-jeremyfertic@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181212005503.28054-1-jeremyfertic@gmail.com> References: <20181212005503.28054-1-jeremyfertic@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Based on the output of adt7316_show_all_DAC_update_modes() and adt7316_show_DAC_update_mode(), adt7316_store_DAC_update_mode() should expect the user to enter an integer input from 0 to 3. The user input is currently expected to account for the actual bit positions in the register. For example, choosing option 3 would require a write of 0x30 (actually 48 since it expects base 10). To address this inconsistency, create a shift macro to be used in the valid input check as well as the calculation for the register write. Signed-off-by: Jeremy Fertic --- I'm not sure if this patch is appropriate since it's making a user visible change. I've included it since the driver is still in staging. drivers/staging/iio/addac/adt7316.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c index bca599d8c51c..58b462ad0c83 100644 --- a/drivers/staging/iio/addac/adt7316.c +++ b/drivers/staging/iio/addac/adt7316.c @@ -129,6 +129,7 @@ */ #define ADT7316_DA_2VREF_CH_MASK 0xF #define ADT7316_DA_EN_MODE_MASK 0x30 +#define ADT7316_DA_EN_MODE_SHIFT 4 #define ADT7316_DA_EN_MODE_SINGLE 0x00 #define ADT7316_DA_EN_MODE_AB_CD 0x10 #define ADT7316_DA_EN_MODE_ABCD 0x20 @@ -879,11 +880,11 @@ static ssize_t adt7316_store_DAC_update_mode(struct device *dev, return -EPERM; ret = kstrtou8(buf, 10, &data); - if (ret || data > ADT7316_DA_EN_MODE_MASK) + if (ret || data > (ADT7316_DA_EN_MODE_MASK >> ADT7316_DA_EN_MODE_SHIFT)) return -EINVAL; dac_config = chip->dac_config & (~ADT7316_DA_EN_MODE_MASK); - dac_config |= data; + dac_config |= data << ADT7316_DA_EN_MODE_SHIFT; ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config); if (ret) -- 2.19.1