From patchwork Sun Dec 23 04:57:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Fertic X-Patchwork-Id: 10741555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 399B413A4 for ; Sun, 23 Dec 2018 04:58:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCFF22018E for ; Sun, 23 Dec 2018 04:58:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD12920602; Sun, 23 Dec 2018 04:58:42 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 9751728A73 for ; Sun, 23 Dec 2018 04:58:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725793AbeLWE6Y (ORCPT ); Sat, 22 Dec 2018 23:58:24 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:39436 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725267AbeLWE6X (ORCPT ); Sat, 22 Dec 2018 23:58:23 -0500 Received: by mail-it1-f196.google.com with SMTP id a6so11936428itl.4; Sat, 22 Dec 2018 20:58:23 -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=BJl9JvtqFLFxHkxk96iUyl94VYQgxphAIRNyaBqFMK8=; b=F+eGxTGyi9pFc+XPnyWe37XRKfKBjZ8DZcz/oQXbL+mvtW4LyywBn2nCjiU6wq+7cC 2Xz51Y1aW2H73+ey3lvrFX4CfEtuT4SJKmnWptxU0Xi0vtFVB0KFY/n9pqkqCpEAk4RY lgC1iRYlIL+zjZShfMTvWR3br2h3coeO5orJ7zECSlLkySAkIlLgwvu7ANJWo0U9NLsO veFTUwglelhIy+z1B2L0StgWJ2ePYcSG5VGyHuqBQyGRrEkgh4nYzcbmVd4ArOtRD7PK 1qw47i+l6Pj/80NzdbUc43Zu2BuPXDd4YlW+vZWGCQb6fW7bmBDmuYantkFxSoSg7eoL 5IaQ== 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=BJl9JvtqFLFxHkxk96iUyl94VYQgxphAIRNyaBqFMK8=; b=ZvqdxqEQW8N9TMXUi0IhcfH/sbxV24nVVITbrGKGXwo6pcJ0bw0Yb0yMa6rCKksku5 e6b4HCvMR+2jyr0pXHEkpEY315ZQqfVNNAqgIcMbbvuUDN3V9wSyxTYw71wIP/XCqxvZ GZKt4ye5BhCEZyoDZiTXz23cTfjqD+pTtMAwaM1Y4XkDncfh5ZY7L9vTn8btggCqk14h 6vIbxfF5wcjh2grlpRJGTl8Vde0zOQG6FDyu+1DAaVzdsUyxVwcss+ss2iuBE4CQ+Yfe dbkDLEkth7+hSmzDySpkuArPQxaymm99mIxSh7HHRRrrSEQMJj9+CKa8yZywxq/nNIPF Vn7A== X-Gm-Message-State: AA+aEWYgGKEedhhQ0/m318Fqxg6MijqtCMuHjEStfW5astgcjysLUYKe 2kOK+Ov34FJxTVQ87pb3idU= X-Google-Smtp-Source: AFSGD/WhRN+X/4F1xgy3h+4+bGM8wDiZrVZpw06JUYMTAzTRB2kjeJHl2e6sTuhKhi23A+bmSj2Fnw== X-Received: by 2002:a02:8244:: with SMTP id q4mr5615297jag.43.1545541102709; Sat, 22 Dec 2018 20:58:22 -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 15sm8435378itv.11.2018.12.22.20.58.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Dec 2018 20:58:22 -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 v2 1/4] staging: iio: adt7316: fix dac_bits assignment Date: Sat, 22 Dec 2018 21:57:40 -0700 Message-Id: <20181223045743.10716-2-jeremyfertic@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181223045743.10716-1-jeremyfertic@gmail.com> References: <20181223045743.10716-1-jeremyfertic@gmail.com> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The value of dac_bits is used in adt7316_show_DAC() and adt7316_store_DAC(), and it should be either 8, 10, or 12 bits depending on the device in use. The driver currently only assigns a value to dac_bits in adt7316_store_da_high_resolution(). The purpose of the dac high resolution option is not to change dac resolution for normal operation. Instead, it is specific to an optional feature where one or two of the four dacs can be set to output voltage proportional to temperature. If the user chooses to set dac a and/or dac b to output voltage proportional to temperature, the da_high_resolution attribute can optionally be enabled to use 10 bit resolution rather than the default 8 bits. This is only available on the 10 and 12 bit dac devices. If the user attempts to read or write dacs a or b under these settings, the driver's current behaviour is to return an error. Dacs c and d continue to operate normally under these conditions. With the above in mind, remove the dac_bits assignments from this function since the value of dac_bits as used in the driver is not dependent on this dac high resolution option. Since the dac_bits assignments discussed above are currently the only ones in this driver, the default value of dac_bits is 0. This results in incorrect calculations when the dacs are read or written in adt7316_show_DAC() and adt7316_store_DAC(). To correct this, assign a value to dac_bits in adt7316_probe() to ensure correct operation as soon as the device is registered and available to userspace. Fixes: 35f6b6b86ede ("staging: iio: new ADT7316/7/8 and ADT7516/7/9 driver") Signed-off-by: Jeremy Fertic --- drivers/staging/iio/addac/adt7316.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c index 9db49aa186bb..e17c1cb12c94 100644 --- a/drivers/staging/iio/addac/adt7316.c +++ b/drivers/staging/iio/addac/adt7316.c @@ -652,17 +652,10 @@ static ssize_t adt7316_store_da_high_resolution(struct device *dev, u8 config3; int ret; - chip->dac_bits = 8; - - if (buf[0] == '1') { + if (buf[0] == '1') config3 = chip->config3 | ADT7316_DA_HIGH_RESOLUTION; - if (chip->id == ID_ADT7316 || chip->id == ID_ADT7516) - chip->dac_bits = 12; - else if (chip->id == ID_ADT7317 || chip->id == ID_ADT7517) - chip->dac_bits = 10; - } else { + else config3 = chip->config3 & (~ADT7316_DA_HIGH_RESOLUTION); - } ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3); if (ret) @@ -2145,6 +2138,13 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus, else return -ENODEV; + if (chip->id == ID_ADT7316 || chip->id == ID_ADT7516) + chip->dac_bits = 12; + else if (chip->id == ID_ADT7317 || chip->id == ID_ADT7517) + chip->dac_bits = 10; + else + chip->dac_bits = 8; + chip->ldac_pin = devm_gpiod_get_optional(dev, "adi,ldac", GPIOD_OUT_LOW); if (IS_ERR(chip->ldac_pin)) { ret = PTR_ERR(chip->ldac_pin); From patchwork Sun Dec 23 04:57:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Fertic X-Patchwork-Id: 10741557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3DCBA17D5 for ; Sun, 23 Dec 2018 04:58:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFEB922AFC for ; Sun, 23 Dec 2018 04:58:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3B3420881; Sun, 23 Dec 2018 04:58:42 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 B7FFE28A74 for ; Sun, 23 Dec 2018 04:58:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726671AbeLWE63 (ORCPT ); Sat, 22 Dec 2018 23:58:29 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:34724 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725267AbeLWE62 (ORCPT ); Sat, 22 Dec 2018 23:58:28 -0500 Received: by mail-io1-f67.google.com with SMTP id l22so38445ioh.1; Sat, 22 Dec 2018 20:58:28 -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=8yZFL/zwD25f09AodsHo5P6etccInIazFV7uoFevqFM=; b=mFs+FMUqu3q9ekZtjSITBt0goNkoTX8vuMp1uOHkd0Q6AIHs0UeMBB+NLdSQXOtWyc kn9okEWP+2ksHpqyj4cVm9kfIVmIJioHZ9EVMLGS0uSO3WjXFw43tkwUASLe32OHpNxV Dhj3Q1FySbdbcPCllvrfFdLEUfmm866Fp2pmuuXqhMlgRqrz3dKCWAyGKF0ig/kPpwDY y0XP1UqxzJgij4b+Bnmckjj28yiWYXiYEPU9Zl7WAWVIXqa/fp8sXwjLcmxusEMLk0wo +1ruNSbdCzR56CEJGMrKbaJiNNH7u92W9XOyZOnawrv8OLsqKnHGaGWK2sjuwQQWy/SP 8iOw== 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=8yZFL/zwD25f09AodsHo5P6etccInIazFV7uoFevqFM=; b=LLdoZ2OL1m8fRTAITYTyh02EWMIZtODxW7PQvdy9VtvsHY6GpOtw7RDcHRlRmjQP6E ubo1fMKPc44B3lD96PITUZNT4Bpq/WZL96UV1YSQpbl8LMvBQwQsgxZhiWmItzluuOE2 JrK2cal9emHERdWwSVwB9G/42mrSOiSPbLEsR75bPY1tvFuxgzAv+maZorr5SvBbKu8a UYT+fNEqUkDp5ITWayk1g9hCjeLa4eOW0lCSOgLUNm0ve2wyjJIjlFKzRV+8OaXhr9oL u0EE89K9k3g+yks1fgI3OtkSoqVE7jZCVOJQdUxfJK6GxLF5H3EJnrhD50G23jODEb0n VGZg== X-Gm-Message-State: AJcUukdC5w9bqDNxQpYETg39sajLufTvmJ1Zm57L6uWvgmdbMWOfBIhA y31rUbE+lZhKH8KZGDRr4So= X-Google-Smtp-Source: ALg8bN6pundBV1jxOaEmM9wHtK7VuCT4zTimcFX5rEF0sVnMVdEb0Zl0z1/RUYrMcPk1S7fIG3T9BQ== X-Received: by 2002:a6b:e919:: with SMTP id u25mr6013502iof.132.1545541108043; Sat, 22 Dec 2018 20:58:28 -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 15sm8435378itv.11.2018.12.22.20.58.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Dec 2018 20:58:27 -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 v2 2/4] staging: iio: adt7316: fix handling of dac high resolution option Date: Sat, 22 Dec 2018 21:57:41 -0700 Message-Id: <20181223045743.10716-3-jeremyfertic@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181223045743.10716-1-jeremyfertic@gmail.com> References: <20181223045743.10716-1-jeremyfertic@gmail.com> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The adt7316/7 and adt7516/7 have the option to output voltage proportional to temperature on dac a and/or dac b. The default dac resolution in this mode is 8 bits with the dac high resolution option enabling 10 bits. None of these settings affect dacs c and d. Remove the "1 (12 bits)" output from the show function since that is not an option for this mode. Return "1 (10 bits)" if the device is one of the above mentioned chips and the dac high resolution mode is enabled. In the store function, the driver currently allows the user to write to the ADT7316_DA_HIGH_RESOLUTION bit regardless of the device in use. Add a check to return an error in the case of an adt7318 or adt7519. Remove the else statement that clears the ADT7316_DA_HIGH_RESOLUTION bit. Instead, clear it before conditionally enabling it, depending on user input. This matches the typical pattern in the driver when an attribute is a boolean. Fixes: 35f6b6b86ede ("staging: iio: new ADT7316/7/8 and ADT7516/7/9 driver") Signed-off-by: Jeremy Fertic --- drivers/staging/iio/addac/adt7316.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c index e17c1cb12c94..80cc3420036b 100644 --- a/drivers/staging/iio/addac/adt7316.c +++ b/drivers/staging/iio/addac/adt7316.c @@ -633,9 +633,7 @@ static ssize_t adt7316_show_da_high_resolution(struct device *dev, struct adt7316_chip_info *chip = iio_priv(dev_info); if (chip->config3 & ADT7316_DA_HIGH_RESOLUTION) { - if (chip->id == ID_ADT7316 || chip->id == ID_ADT7516) - return sprintf(buf, "1 (12 bits)\n"); - if (chip->id == ID_ADT7317 || chip->id == ID_ADT7517) + if (chip->id != ID_ADT7318 && chip->id != ID_ADT7519) return sprintf(buf, "1 (10 bits)\n"); } @@ -652,10 +650,12 @@ static ssize_t adt7316_store_da_high_resolution(struct device *dev, u8 config3; int ret; + if (chip->id == ID_ADT7318 || chip->id == ID_ADT7519) + return -EPERM; + + config3 = chip->config3 & (~ADT7316_DA_HIGH_RESOLUTION); if (buf[0] == '1') - config3 = chip->config3 | ADT7316_DA_HIGH_RESOLUTION; - else - config3 = chip->config3 & (~ADT7316_DA_HIGH_RESOLUTION); + config3 |= ADT7316_DA_HIGH_RESOLUTION; ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3); if (ret) From patchwork Sun Dec 23 04:57:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Fertic X-Patchwork-Id: 10741559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 411F517FB for ; Sun, 23 Dec 2018 04:58:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 067DD21FAD for ; Sun, 23 Dec 2018 04:58:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE45F2522B; Sun, 23 Dec 2018 04:58:42 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 E215C28A75 for ; Sun, 23 Dec 2018 04:58:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725851AbeLWE6e (ORCPT ); Sat, 22 Dec 2018 23:58:34 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:40273 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726773AbeLWE6d (ORCPT ); Sat, 22 Dec 2018 23:58:33 -0500 Received: by mail-io1-f67.google.com with SMTP id a11so4375794ioq.7; Sat, 22 Dec 2018 20:58:32 -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=QObNkapVO/i8shFczuk2z27Jj/GGsaFAwRKXUgysxBo=; b=N8/q6CH6zKitObX3LEBwNAVUb/BA3iShzDJM+kbxSZm5S7zpuwqa9wcsTAfssIFQ/X EO4cuqBdC8MnazvUd668j3a6oL/cKq0rYJW+pY92iLNi/nS+EI2Jd0WcnKOyLgc3Wmwt fvBI8Zs3uPHBNPsxqLJrJEaFwR/NxcH6T9R+FW6S5YNGHhF5wSNb6zi8okfaK/hwsNHs Hp4H4B9mtZpmpCK2/KZPj59ctKIZk7wv0A7ICSc2Oa0xcQNaTs0cavPTTZZnFyblBjUJ Xe4PFshyIXoiMtJZp/h6rbO4qQN0IVr8oYW5m5UozXxY6PTg081wGFwXjz1zjFs0+bu2 Os1A== 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=QObNkapVO/i8shFczuk2z27Jj/GGsaFAwRKXUgysxBo=; b=Q1V/inqjGB+tFFO2FydBBdFpckpo+n4T3WBMZ8VY5p7LP1RsEaOYwR2RHBzxNwtJHU dppELaKx96CLrpMgjsUwjVEkYUsv0vUDm7l8bP+oXNU7jVHR0yIv9VrA9adcCHBz4ksO sksG19OWvjNxrNynT2x9qjI+YHe3xnvvU+EX4yyMnEFycBAx3UAz8jG3e+6RAl6BRtJQ qyVerWPOruehFRR2Nr3L7vP2Ejmwhiy7UfNdi6N6s84/FurG4F8KrjGaCxpu53scyiqF wqhJv0kluaXxw4AZPySNtSjCBnVyoEXuFVLoZ7bxa7+2Ldxu/eiPA+Z3iP8dH0L7lL2h WsCQ== X-Gm-Message-State: AJcUukdc01KithhihOKpr4RMEeN4QEsKi3HKfZ7hUyPreUvXKyxt9Izd Hu1ZpllZX3zqmWYPO90WERo= X-Google-Smtp-Source: ALg8bN6aeCdERqkvq54GDfTOD8A3q2ws72cWC6MG+sA/NghGC448PTlzuNGEUChJpgC9+3e692gnkQ== X-Received: by 2002:a5e:8b46:: with SMTP id z6mr5628833iom.7.1545541111980; Sat, 22 Dec 2018 20:58:31 -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 15sm8435378itv.11.2018.12.22.20.58.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Dec 2018 20:58:31 -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 v2 3/4] staging: iio: adt7316: fix the dac read calculation Date: Sat, 22 Dec 2018 21:57:42 -0700 Message-Id: <20181223045743.10716-4-jeremyfertic@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181223045743.10716-1-jeremyfertic@gmail.com> References: <20181223045743.10716-1-jeremyfertic@gmail.com> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The calculation of the current dac value is using the wrong bits of the dac lsb register. Create two macros to shift the lsb register value into lsb position, depending on whether the dac is 10 or 12 bit. Initialize data to 0 so, with an 8 bit dac, the msb register value can be bitwise ORed with data. Fixes: 35f6b6b86ede ("staging: iio: new ADT7316/7/8 and ADT7516/7/9 driver") Signed-off-by: Jeremy Fertic --- drivers/staging/iio/addac/adt7316.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c index 80cc3420036b..d7f3d68e525b 100644 --- a/drivers/staging/iio/addac/adt7316.c +++ b/drivers/staging/iio/addac/adt7316.c @@ -47,6 +47,8 @@ #define ADT7516_MSB_AIN3 0xA #define ADT7516_MSB_AIN4 0xB #define ADT7316_DA_DATA_BASE 0x10 +#define ADT7316_DA_10_BIT_LSB_SHIFT 6 +#define ADT7316_DA_12_BIT_LSB_SHIFT 4 #define ADT7316_DA_MSB_DATA_REGS 4 #define ADT7316_LSB_DAC_A 0x10 #define ADT7316_MSB_DAC_A 0x11 @@ -1392,7 +1394,7 @@ static IIO_DEVICE_ATTR(ex_analog_temp_offset, 0644, static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip, int channel, char *buf) { - u16 data; + u16 data = 0; u8 msb, lsb, offset; int ret; @@ -1417,7 +1419,11 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip, if (ret) return -EIO; - data = (msb << offset) + (lsb & ((1 << offset) - 1)); + if (chip->dac_bits == 12) + data = lsb >> ADT7316_DA_12_BIT_LSB_SHIFT; + else if (chip->dac_bits == 10) + data = lsb >> ADT7316_DA_10_BIT_LSB_SHIFT; + data |= msb << offset; return sprintf(buf, "%d\n", data); } From patchwork Sun Dec 23 04:57:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Fertic X-Patchwork-Id: 10741561 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3FA8F13AD for ; Sun, 23 Dec 2018 04:58:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DE9D2842D for ; Sun, 23 Dec 2018 04:58:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2158D2843B; Sun, 23 Dec 2018 04:58:48 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 C36662842D for ; Sun, 23 Dec 2018 04:58:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726382AbeLWE6k (ORCPT ); Sat, 22 Dec 2018 23:58:40 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:40276 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725888AbeLWE6i (ORCPT ); Sat, 22 Dec 2018 23:58:38 -0500 Received: by mail-io1-f67.google.com with SMTP id a11so4375853ioq.7; Sat, 22 Dec 2018 20:58:37 -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=hbV2rZQ67LuJPX6YUHnnKWTvJhORDui2wg3k/8TbKxY=; b=uM7vIrg1kODY4nh5lBOZezgmmNgNRj5OFh4MwhlaAbQO8BkMwZ9vzPt8j+SrKUmV/R wcc71DW91AgCH8rgOnKi1JF8TwLYWNr8diqzXJuaTBlzJ2Bupba0ZG3yR6spWDJDc6jT x/CYcp4Dkk5VJWcPtkNLI84H+ei2079kxjdyzy+r6DjbYZG6XuoHn+xh8jLGlaxva538 Kzg9njR8cCcwtlstCSrZs5Od6oo8VCyZT91555y1HgFjZS6nbZvHgTDMkGDwn+1dP/d3 udQzIji5/byY4epJdumAyaQTgwAp3M8hSONvvErls5aTKxBeggBTz61ioydKt8RAWja7 73ug== 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=hbV2rZQ67LuJPX6YUHnnKWTvJhORDui2wg3k/8TbKxY=; b=BkdGUksqAgHeLzTed/qY9M8H3q3GsPFOBNqam0sE3D2HQDPC2v4neCUVfcT7g5mOZn QKGfWHf+VN1fiO82mPwfzlDv3avy1wiS298PqKvUmJaoZ6gL6M8Ky/0ZYFiprj5a/1Ei obElyyFPIQxE2J6Tlokw6M7rHDXOk7hGnwFXS6WBbOJHhGCL0c+ULCjFqpqL9Yxh6zpI d7wPtMGsOIWhivFU1zO9jFgAnAt6QLrbRF/N6qs1GJb5qmJEdEEdBkOv8+1f/01iM91G 6/qBLokf/ccewwQ3nZ3adJLb/ieGhMiuz5RwgByh3cg92w3hoyiIiqMzeUgFzxUeResc HXRw== X-Gm-Message-State: AJcUukdWHSCoCR8pixncb5P1k2WdGcTj5ZSGvzAUdWu3KHxZh2qLHoQV /NJSxAR/iHGqjEIRGlikcik= X-Google-Smtp-Source: ALg8bN5h5xy3arU6MQX/ghft3R+OOPcP+oPq+P2C/OygtNGjtaH5V8SZSx3T5m8o777D4wj6a87xkg== X-Received: by 2002:a5e:c914:: with SMTP id z20mr5747178iol.72.1545541116919; Sat, 22 Dec 2018 20:58:36 -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 15sm8435378itv.11.2018.12.22.20.58.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Dec 2018 20:58:36 -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 v2 4/4] staging: iio: adt7316: fix the dac write calculation Date: Sat, 22 Dec 2018 21:57:43 -0700 Message-Id: <20181223045743.10716-5-jeremyfertic@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181223045743.10716-1-jeremyfertic@gmail.com> References: <20181223045743.10716-1-jeremyfertic@gmail.com> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The lsb calculation is not masking the correct bits from the user input. Subtract 1 from (1 << offset) to correctly set up the mask to be applied to user input. The lsb register stores its value starting at the bit 7 position. adt7316_store_DAC() currently assumes the value is at the other end of the register. Shift the lsb value before storing it in a new variable lsb_reg, and write this variable to the lsb register. Fixes: 35f6b6b86ede ("staging: iio: new ADT7316/7/8 and ADT7516/7/9 driver") Signed-off-by: Jeremy Fertic --- drivers/staging/iio/addac/adt7316.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c index d7f3d68e525b..6f7891b567b9 100644 --- a/drivers/staging/iio/addac/adt7316.c +++ b/drivers/staging/iio/addac/adt7316.c @@ -1431,7 +1431,7 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip, static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip, int channel, const char *buf, size_t len) { - u8 msb, lsb, offset; + u8 msb, lsb, lsb_reg, offset; u16 data; int ret; @@ -1449,9 +1449,13 @@ static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip, return -EINVAL; if (chip->dac_bits > 8) { - lsb = data & (1 << offset); + lsb = data & ((1 << offset) - 1); + if (chip->dac_bits == 12) + lsb_reg = lsb << ADT7316_DA_12_BIT_LSB_SHIFT; + else + lsb_reg = lsb << ADT7316_DA_10_BIT_LSB_SHIFT; ret = chip->bus.write(chip->bus.client, - ADT7316_DA_DATA_BASE + channel * 2, lsb); + ADT7316_DA_DATA_BASE + channel * 2, lsb_reg); if (ret) return -EIO; }