From patchwork Sun Feb 7 15:46:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1A7AC433E0 for ; Sun, 7 Feb 2021 15:49:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 68D7E64E3E for ; Sun, 7 Feb 2021 15:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229510AbhBGPt3 (ORCPT ); Sun, 7 Feb 2021 10:49:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:33700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbhBGPtY (ORCPT ); Sun, 7 Feb 2021 10:49:24 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C2B2B64E40; Sun, 7 Feb 2021 15:48:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712923; bh=pL2q7QCXkVZk9oyCfZKaz51q2nqsfCxTS94/9FlhASY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JSjxLqS6Uco6Tbi4jqdFfBP09gwv06SiV5aYY+Xl57HLJoSsPjUAdSEM3eJM6MoB7 sKKlgxohuUbde1ljaU58qH22KdlVpA5jM+1bXTU4QtGSub5huTaHdd2gs1k6s3iY/T /ZKR5JJf7craYli3+2buipQQUd2iTmXHCJNP03e4aQ+uZxY9QrqduxxrVBglnq2Od6 MEWS170q4eoKyZ+WBIvaYOTLrprL6w2NMUlJ36kIEDjoe0le8zxx5P2h0TOndC4Gfz dtdp6Y8EJq4/npgmuclygBn0Ga4Oy3vnnN4kwkBOPE6S04mTVAvs2PAj/Q2SkjRaCl OYYGLBnb0xlnQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 01/24] staging:iio:cdc:ad7150: use swapped reads for i2c rather than open coding. Date: Sun, 7 Feb 2021 15:46:00 +0000 Message-Id: <20210207154623.433442-2-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Reduces boilerplate and chances of getting the error handling wrong. No functional change. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 48132ab157ef..c3ed88c5e0a5 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -109,18 +109,20 @@ static int ad7150_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: - ret = i2c_smbus_read_word_data(chip->client, - ad7150_addresses[channel][0]); + ret = i2c_smbus_read_word_swapped(chip->client, + ad7150_addresses[channel][0]); if (ret < 0) return ret; - *val = swab16(ret); + *val = ret; + return IIO_VAL_INT; case IIO_CHAN_INFO_AVERAGE_RAW: - ret = i2c_smbus_read_word_data(chip->client, - ad7150_addresses[channel][1]); + ret = i2c_smbus_read_word_swapped(chip->client, + ad7150_addresses[channel][1]); if (ret < 0) return ret; - *val = swab16(ret); + *val = ret; + return IIO_VAL_INT; default: return -EINVAL; @@ -188,9 +190,9 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, /* Note completely different from the adaptive versions */ case IIO_EV_TYPE_THRESH: value = chip->threshold[rising][chan]; - return i2c_smbus_write_word_data(chip->client, - ad7150_addresses[chan][3], - swab16(value)); + return i2c_smbus_write_word_swapped(chip->client, + ad7150_addresses[chan][3], + value); case IIO_EV_TYPE_MAG_ADAPTIVE: sens = chip->mag_sensitivity[rising][chan]; timeout = chip->mag_timeout[rising][chan]; From patchwork Sun Feb 7 15:46:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073077 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B675DC433E6 for ; Sun, 7 Feb 2021 15:49:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 86A2564E4E for ; Sun, 7 Feb 2021 15:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229562AbhBGPt3 (ORCPT ); Sun, 7 Feb 2021 10:49:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:33720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229565AbhBGPt0 (ORCPT ); Sun, 7 Feb 2021 10:49:26 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5389A64E49; Sun, 7 Feb 2021 15:48:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712925; bh=MlcWmmgF9DfgD1RFY/e7DIdyr51yJmbFH38eYtW5hrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nBbT2awqvsS28bis8+3JFbSFP3dxE3KVIwW0iWTCSbUKU3llXXfaF/t+SvbwGGZ3k aEDXcl8S+C48PhQq38wP6255X3508ONrZ55LCvbUsqP8j/ItvV6SKtGENoWC5ZSn0T YwLZWGzo4HnNm0VqBpLAYoXcZnhfRfrcZd6XINkYGY5/gvJE05TmDo1vlLn0iaDOVW XW1KWxrQFXdXOqlBY7Ic+IzfSPYwqsY1FhPFNUpYllrRhTl1LxXbJEF54tOz015fG6 g07lJ+79+Y8bde+6fIzwv/Y7B1/+SnS6rNoKHnvoxya5HLBrOreoNGeN942Et9JBEX ra77HF3wNRc0Q== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 02/24] staging:iio:cdc:ad7150: Remove magnitude adaptive events Date: Sun, 7 Feb 2021 15:46:01 +0000 Message-Id: <20210207154623.433442-3-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron The devices support window detection, but that corresponds to being outside of a range defined by a lower an uppper bound rather than being related to magnitude as such. Hence drop this interface in the interests of making the driver ABI compliant. We may bring back support for the window mode at somepoint in the future but it will be in an ABI compliant fashion. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 56 -------------------------------- 1 file changed, 56 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index c3ed88c5e0a5..4dac4aaec0cf 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -57,14 +57,9 @@ * @threshold: thresholds for simple capacitance value events * @thresh_sensitivity: threshold for simple capacitance offset * from 'average' value. - * @mag_sensitity: threshold for magnitude of capacitance offset from - * from 'average' value. * @thresh_timeout: a timeout, in samples from the moment an * adaptive threshold event occurs to when the average * value jumps to current value. - * @mag_timeout: a timeout, in sample from the moment an - * adaptive magnitude event occurs to when the average - * value jumps to the current value. * @old_state: store state from previous event, allowing confirmation * of new condition. * @conversion_mode: the current conversion mode. @@ -76,9 +71,7 @@ struct ad7150_chip_info { u64 current_event; u16 threshold[2][2]; u8 thresh_sensitivity[2][2]; - u8 mag_sensitivity[2][2]; u8 thresh_timeout[2][2]; - u8 mag_timeout[2][2]; int old_state; char *conversion_mode; struct mutex state_lock; @@ -149,10 +142,6 @@ static int ad7150_read_event_config(struct iio_dev *indio_dev, thrfixed = FIELD_GET(AD7150_CFG_FIX, ret); switch (type) { - case IIO_EV_TYPE_MAG_ADAPTIVE: - if (dir == IIO_EV_DIR_RISING) - return !thrfixed && (threshtype == 0x1); - return !thrfixed && (threshtype == 0x0); case IIO_EV_TYPE_THRESH_ADAPTIVE: if (dir == IIO_EV_DIR_RISING) return !thrfixed && (threshtype == 0x3); @@ -193,10 +182,6 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, return i2c_smbus_write_word_swapped(chip->client, ad7150_addresses[chan][3], value); - case IIO_EV_TYPE_MAG_ADAPTIVE: - sens = chip->mag_sensitivity[rising][chan]; - timeout = chip->mag_timeout[rising][chan]; - break; case IIO_EV_TYPE_THRESH_ADAPTIVE: sens = chip->thresh_sensitivity[rising][chan]; timeout = chip->thresh_timeout[rising][chan]; @@ -240,13 +225,6 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev, cfg = ret & ~((0x03 << 5) | BIT(7)); switch (type) { - case IIO_EV_TYPE_MAG_ADAPTIVE: - adaptive = 1; - if (rising) - thresh_type = 0x1; - else - thresh_type = 0x0; - break; case IIO_EV_TYPE_THRESH_ADAPTIVE: adaptive = 1; if (rising) @@ -294,9 +272,6 @@ static int ad7150_read_event_value(struct iio_dev *indio_dev, /* Complex register sharing going on here */ switch (type) { - case IIO_EV_TYPE_MAG_ADAPTIVE: - *val = chip->mag_sensitivity[rising][chan->channel]; - return IIO_VAL_INT; case IIO_EV_TYPE_THRESH_ADAPTIVE: *val = chip->thresh_sensitivity[rising][chan->channel]; return IIO_VAL_INT; @@ -321,9 +296,6 @@ static int ad7150_write_event_value(struct iio_dev *indio_dev, mutex_lock(&chip->state_lock); switch (type) { - case IIO_EV_TYPE_MAG_ADAPTIVE: - chip->mag_sensitivity[rising][chan->channel] = val; - break; case IIO_EV_TYPE_THRESH_ADAPTIVE: chip->thresh_sensitivity[rising][chan->channel] = val; break; @@ -358,9 +330,6 @@ static ssize_t ad7150_show_timeout(struct device *dev, == IIO_EV_DIR_RISING) ? 1 : 0; switch (IIO_EVENT_CODE_EXTRACT_TYPE(this_attr->address)) { - case IIO_EV_TYPE_MAG_ADAPTIVE: - value = chip->mag_timeout[rising][chan]; - break; case IIO_EV_TYPE_THRESH_ADAPTIVE: value = chip->thresh_timeout[rising][chan]; break; @@ -396,9 +365,6 @@ static ssize_t ad7150_store_timeout(struct device *dev, mutex_lock(&chip->state_lock); switch (type) { - case IIO_EV_TYPE_MAG_ADAPTIVE: - chip->mag_timeout[rising][chan] = data; - break; case IIO_EV_TYPE_THRESH_ADAPTIVE: chip->thresh_timeout[rising][chan] = data; break; @@ -426,10 +392,6 @@ static ssize_t ad7150_store_timeout(struct device *dev, chan, \ IIO_EV_TYPE_##ev_type, \ IIO_EV_DIR_##ev_dir)) -static AD7150_TIMEOUT(0, mag_adaptive, rising, MAG_ADAPTIVE, RISING); -static AD7150_TIMEOUT(0, mag_adaptive, falling, MAG_ADAPTIVE, FALLING); -static AD7150_TIMEOUT(1, mag_adaptive, rising, MAG_ADAPTIVE, RISING); -static AD7150_TIMEOUT(1, mag_adaptive, falling, MAG_ADAPTIVE, FALLING); static AD7150_TIMEOUT(0, thresh_adaptive, rising, THRESH_ADAPTIVE, RISING); static AD7150_TIMEOUT(0, thresh_adaptive, falling, THRESH_ADAPTIVE, FALLING); static AD7150_TIMEOUT(1, thresh_adaptive, rising, THRESH_ADAPTIVE, RISING); @@ -456,16 +418,6 @@ static const struct iio_event_spec ad7150_events[] = { .dir = IIO_EV_DIR_FALLING, .mask_separate = BIT(IIO_EV_INFO_VALUE) | BIT(IIO_EV_INFO_ENABLE), - }, { - .type = IIO_EV_TYPE_MAG_ADAPTIVE, - .dir = IIO_EV_DIR_RISING, - .mask_separate = BIT(IIO_EV_INFO_VALUE) | - BIT(IIO_EV_INFO_ENABLE), - }, { - .type = IIO_EV_TYPE_MAG_ADAPTIVE, - .dir = IIO_EV_DIR_FALLING, - .mask_separate = BIT(IIO_EV_INFO_VALUE) | - BIT(IIO_EV_INFO_ENABLE), }, }; @@ -539,14 +491,6 @@ static irqreturn_t ad7150_event_handler(int irq, void *private) /* Timeouts not currently handled by core */ static struct attribute *ad7150_event_attributes[] = { - &iio_dev_attr_in_capacitance0_mag_adaptive_rising_timeout - .dev_attr.attr, - &iio_dev_attr_in_capacitance0_mag_adaptive_falling_timeout - .dev_attr.attr, - &iio_dev_attr_in_capacitance1_mag_adaptive_rising_timeout - .dev_attr.attr, - &iio_dev_attr_in_capacitance1_mag_adaptive_falling_timeout - .dev_attr.attr, &iio_dev_attr_in_capacitance0_thresh_adaptive_rising_timeout .dev_attr.attr, &iio_dev_attr_in_capacitance0_thresh_adaptive_falling_timeout From patchwork Sun Feb 7 15:46:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBF6CC433E9 for ; Sun, 7 Feb 2021 15:49:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B3A364E49 for ; Sun, 7 Feb 2021 15:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229565AbhBGPta (ORCPT ); Sun, 7 Feb 2021 10:49:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:33728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229581AbhBGPt2 (ORCPT ); Sun, 7 Feb 2021 10:49:28 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DEDBD64E4E; Sun, 7 Feb 2021 15:48:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712927; bh=1egU6Yk0gIai2VfmnJdXpTGAUkrWXeZ9155v8/lJxBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qXw4u1z2Nfc528LYjAwGzY4PqbF4JZ4+LmJfBESO2KKK1PhtTP/2strcDyqYHtbKn TOMtO6/hjM9zaXffQ+JTW82rIsa/gDbJT04V02vMGbLK+mnGGe0cHTGXmFRv0DP4Ew R0ocziM0n2GSxtSCavPSb6bUaFLBWH0+Wfo+WlzgT+lsBfd8XQwBSd57H5n2AELnzz oX+RtGTtT5GiFOOe90vP76CjOD1ERHc1kXetO/dKm8HnwnzdpM6MinTdwZThpPqpIb wyPEiVKhqq+x9RfF0sg0RAX6ocgzTbHzRR31Avz9OprPIOCa5CRUxfxvwcsP+6brsL D5BK6/RstDA+A== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 03/24] staging:iio:cdc:ad7150: Refactor event parameter update Date: Sun, 7 Feb 2021 15:46:02 +0000 Message-Id: <20210207154623.433442-4-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Original code was ordered in a fairly unituitive fashion with the non adaptive threshold handling returning from the switch statement, whilst the adapative path did the actual writes outside the switch. Make it more readable by bringing everything within the switch statement cases and reducing scope of local variables as appropriate. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 4dac4aaec0cf..d6a7bfd94f1c 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -163,9 +163,6 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, enum iio_event_type type, enum iio_event_direction dir) { - int ret; - u16 value; - u8 sens, timeout; struct ad7150_chip_info *chip = iio_priv(indio_dev); int rising = (dir == IIO_EV_DIR_RISING); u64 event_code; @@ -177,26 +174,31 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, switch (type) { /* Note completely different from the adaptive versions */ - case IIO_EV_TYPE_THRESH: - value = chip->threshold[rising][chan]; + case IIO_EV_TYPE_THRESH: { + u16 value = chip->threshold[rising][chan]; return i2c_smbus_write_word_swapped(chip->client, ad7150_addresses[chan][3], value); - case IIO_EV_TYPE_THRESH_ADAPTIVE: + } + case IIO_EV_TYPE_THRESH_ADAPTIVE: { + int ret; + u8 sens, timeout; + sens = chip->thresh_sensitivity[rising][chan]; + ret = i2c_smbus_write_byte_data(chip->client, + ad7150_addresses[chan][4], + sens); + if (ret) + return ret; + timeout = chip->thresh_timeout[rising][chan]; - break; + return i2c_smbus_write_byte_data(chip->client, + ad7150_addresses[chan][5], + timeout); + } default: return -EINVAL; } - ret = i2c_smbus_write_byte_data(chip->client, - ad7150_addresses[chan][4], - sens); - if (ret) - return ret; - return i2c_smbus_write_byte_data(chip->client, - ad7150_addresses[chan][5], - timeout); } static int ad7150_write_event_config(struct iio_dev *indio_dev, From patchwork Sun Feb 7 15:46:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073075 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5E88C43381 for ; Sun, 7 Feb 2021 15:49:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE12564E3E for ; Sun, 7 Feb 2021 15:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229581AbhBGPta (ORCPT ); Sun, 7 Feb 2021 10:49:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:33752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229590AbhBGPt3 (ORCPT ); Sun, 7 Feb 2021 10:49:29 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 742BF64E51; Sun, 7 Feb 2021 15:48:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712928; bh=ySulkE5dW404GovN4NGHULi+9DOHq5F+fmpoYTAxSJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lcnrVa3DxiJXNhMlEGxzt7QNJ4VDJN7JF/zgZiaO6/hoLlZY+rMdz6R9l9XL5ehCC h33UFiMeAgAs8fFm4CgnRl1W6cUTyo+a2WEivA9UoM1WZbFso01zBix4x7jVzvvVoq mGDqiza/4yueDLePL+lX+cyCaRWSiwFKDG6IDU88brxRc7A1NVh6teNLU0tZuBTi50 BR4uDHKuzAXNsqDWUzHJmbkwRSUPS0kF9vRMiSikcSCNCcv5bi+KvgS4Dza5FVBCPO bFmaBkDB8Lsxka41Zwdny34ulN5w3ciUOTX39a3wG+owvAaat89WItA/Z5iVSfjUfh xoN3mIbXcoFlA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 04/24] staging:iio:cdc:ad7150: Timeout register covers both directions so both need updating Date: Sun, 7 Feb 2021 15:46:03 +0000 Message-Id: <20210207154623.433442-5-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron The timeout is treated as one single value, but the datasheet describes it as two 4 bit values, one for each direction of event. As such change the driver to support the separate directions. Also add limit checking to ensure it fits within the 4 bits. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index d6a7bfd94f1c..0dce1b8ce76d 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -49,6 +49,8 @@ /* AD7150 masks */ #define AD7150_THRESHTYPE_MSK GENMASK(6, 5) +#define AD7150_CH_TIMEOUT_RECEDING GENMASK(3, 0) +#define AD7150_CH_TIMEOUT_APPROACHING GENMASK(7, 4) /** * struct ad7150_chip_info - instance specific chip data * @client: i2c client for this device @@ -59,7 +61,9 @@ * from 'average' value. * @thresh_timeout: a timeout, in samples from the moment an * adaptive threshold event occurs to when the average - * value jumps to current value. + * value jumps to current value. Note made up of two fields, + * 3:0 are for timeout receding - applies if below lower threshold + * 7:4 are for timeout approaching - applies if above upper threshold * @old_state: store state from previous event, allowing confirmation * of new condition. * @conversion_mode: the current conversion mode. @@ -191,7 +195,14 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, if (ret) return ret; - timeout = chip->thresh_timeout[rising][chan]; + /* + * Single timeout register contains timeouts for both + * directions. + */ + timeout = FIELD_PREP(AD7150_CH_TIMEOUT_APPROACHING, + chip->thresh_timeout[1][chan]); + timeout |= FIELD_PREP(AD7150_CH_TIMEOUT_RECEDING, + chip->thresh_timeout[0][chan]); return i2c_smbus_write_byte_data(chip->client, ad7150_addresses[chan][5], timeout); @@ -365,6 +376,9 @@ static ssize_t ad7150_store_timeout(struct device *dev, if (ret < 0) return ret; + if (data > GENMASK(3, 0)) + return -EINVAL; + mutex_lock(&chip->state_lock); switch (type) { case IIO_EV_TYPE_THRESH_ADAPTIVE: From patchwork Sun Feb 7 15:46:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073083 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03ADDC433E6 for ; Sun, 7 Feb 2021 15:50:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B958664E3E for ; Sun, 7 Feb 2021 15:50:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbhBGPuL (ORCPT ); Sun, 7 Feb 2021 10:50:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:34022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbhBGPuJ (ORCPT ); Sun, 7 Feb 2021 10:50:09 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0D8B964D9A; Sun, 7 Feb 2021 15:48:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712930; bh=DTCL8xHphxH/c6QWI2fC4+eyHtH3JVQ9LLgh4b8UoWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UjdQ0GyKVWCRxeZxGMmmUrCSKuR+jPyyJ/uge0Zu8zdTPRSvVwBb3VJFOPSlxN571 JALo7RWSIOTlarvTZQTg0oHx4rYhpNSZr+QiNCihtT0PZ2ZnIegcZoKk8wBePzSLC7 YT0/XLlFT34mnSqzTff+JqrmO4KxxTlDUTQqfJHPw8KDsEf9g4wE/1da8TiMBaUm1k Cg6hVdncF6sYqbrPwh37VYpfA7ujiPryjhW41vFj6zmZW+c3cnrJM8KPkpTTiqNv+6 KVmEEbDyVoU9RkzzjUyMzam+UpjGJmoyOQrvqAuf9cVbJSlgX/uSyKQiPhJld1Rduc cXmL5vChXToYw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 05/24] staging:iio:cdc:ad7150: Drop platform data support Date: Sun, 7 Feb 2021 15:46:04 +0000 Message-Id: <20210207154623.433442-6-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron There are no mainline board files using this driver so lets drop the platform_data support in favour of devicetree and similar. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 0dce1b8ce76d..7ad9105e6b46 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -570,20 +570,6 @@ static int ad7150_probe(struct i2c_client *client, return ret; } - if (client->dev.platform_data) { - ret = devm_request_threaded_irq(&client->dev, *(unsigned int *) - client->dev.platform_data, - NULL, - &ad7150_event_handler, - IRQF_TRIGGER_RISING | - IRQF_TRIGGER_FALLING | - IRQF_ONESHOT, - "ad7150_irq2", - indio_dev); - if (ret) - return ret; - } - ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev); if (ret) return ret; From patchwork Sun Feb 7 15:46:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073089 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BB53C433DB for ; Sun, 7 Feb 2021 15:50:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF6C164E3E for ; Sun, 7 Feb 2021 15:50:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229623AbhBGPuN (ORCPT ); Sun, 7 Feb 2021 10:50:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:34024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229590AbhBGPuJ (ORCPT ); Sun, 7 Feb 2021 10:50:09 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9BE3264E4F; Sun, 7 Feb 2021 15:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712931; bh=KJLlKOtM0Yd/Y5jsIx5IECmw7rNVCC2Q6uZxW60aPls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZkL9FZA+arCWzd4rwBkCiyRB/H8Zz5sxHEGqmNxksnKHSjEgPJEdGWF0fNRz3WgJO xGgXbCaXZgyKDHj9QHLSEmQiUEEnP/JY+bdFhO5AzDdEonQva71Xlg4AgjUzWhR5Vq xdDC81HxK1wgY+8CkoWzk/x3tjXS/etPlBLvf4ZlpF0JSy74gkzpvtNUnbVOKN7XQM 5kr2xcL4VRavAu9L/NdavsGMEVmU5DnuAfV5MefcUwiCdCMj/HOpI0/Fi6i12bpcJu KSJvvD2rNkfNLQloHIjUeBjlorNjiiHZoxQOIuVPMBAwbGnnq+iOrcSbVojilUtu+h zygT0hiIpOS6g== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 06/24] staging:iio:cdc:ad7150: Handle variation in chan_spec across device and irq present or not Date: Sun, 7 Feb 2021 15:46:05 +0000 Message-Id: <20210207154623.433442-7-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron The driver supports devices with different numbers of channels and also can function without provision of an IRQ (with reduced features), so this patch handles this cleanly by having multiple chan_spec arrays and iio_info structures to pick between depending on what we have. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 71 ++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 7ad9105e6b46..539beed1a511 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -51,6 +51,12 @@ #define AD7150_CH_TIMEOUT_RECEDING GENMASK(3, 0) #define AD7150_CH_TIMEOUT_APPROACHING GENMASK(7, 4) + +enum { + AD7150, + AD7151, +}; + /** * struct ad7150_chip_info - instance specific chip data * @client: i2c client for this device @@ -447,9 +453,30 @@ static const struct iio_event_spec ad7150_events[] = { .num_event_specs = ARRAY_SIZE(ad7150_events), \ } +#define AD7150_CAPACITANCE_CHAN_NO_IRQ(_chan) { \ + .type = IIO_CAPACITANCE, \ + .indexed = 1, \ + .channel = _chan, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_AVERAGE_RAW), \ + } + static const struct iio_chan_spec ad7150_channels[] = { AD7150_CAPACITANCE_CHAN(0), - AD7150_CAPACITANCE_CHAN(1) + AD7150_CAPACITANCE_CHAN(1), +}; + +static const struct iio_chan_spec ad7150_channels_no_irq[] = { + AD7150_CAPACITANCE_CHAN_NO_IRQ(0), + AD7150_CAPACITANCE_CHAN_NO_IRQ(1), +}; + +static const struct iio_chan_spec ad7151_channels[] = { + AD7150_CAPACITANCE_CHAN(0), +}; + +static const struct iio_chan_spec ad7151_channels_no_irq[] = { + AD7150_CAPACITANCE_CHAN_NO_IRQ(0), }; static irqreturn_t ad7150_event_handler(int irq, void *private) @@ -532,6 +559,10 @@ static const struct iio_info ad7150_info = { .write_event_value = &ad7150_write_event_value, }; +static const struct iio_info ad7150_info_no_irq = { + .read_raw = &ad7150_read_raw, +}; + static int ad7150_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -550,14 +581,24 @@ static int ad7150_probe(struct i2c_client *client, chip->client = client; indio_dev->name = id->name; - indio_dev->channels = ad7150_channels; - indio_dev->num_channels = ARRAY_SIZE(ad7150_channels); - - indio_dev->info = &ad7150_info; indio_dev->modes = INDIO_DIRECT_MODE; if (client->irq) { + indio_dev->info = &ad7150_info; + switch (id->driver_data) { + case AD7150: + indio_dev->channels = ad7150_channels; + indio_dev->num_channels = ARRAY_SIZE(ad7150_channels); + break; + case AD7151: + indio_dev->channels = ad7151_channels; + indio_dev->num_channels = ARRAY_SIZE(ad7151_channels); + break; + default: + return -EINVAL; + } + ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, &ad7150_event_handler, @@ -568,6 +609,20 @@ static int ad7150_probe(struct i2c_client *client, indio_dev); if (ret) return ret; + } else { + indio_dev->info = &ad7150_info_no_irq; + switch (id->driver_data) { + case AD7150: + indio_dev->channels = ad7150_channels_no_irq; + indio_dev->num_channels = ARRAY_SIZE(ad7150_channels_no_irq); + break; + case AD7151: + indio_dev->channels = ad7151_channels_no_irq; + indio_dev->num_channels = ARRAY_SIZE(ad7151_channels_no_irq); + break; + default: + return -EINVAL; + } } ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev); @@ -581,9 +636,9 @@ static int ad7150_probe(struct i2c_client *client, } static const struct i2c_device_id ad7150_id[] = { - { "ad7150", 0 }, - { "ad7151", 0 }, - { "ad7156", 0 }, + { "ad7150", AD7150 }, + { "ad7151", AD7151 }, + { "ad7156", AD7150 }, {} }; From patchwork Sun Feb 7 15:46:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073079 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82497C433DB for ; Sun, 7 Feb 2021 15:50:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44EF664D9A for ; Sun, 7 Feb 2021 15:50:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229615AbhBGPuL (ORCPT ); Sun, 7 Feb 2021 10:50:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:34026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbhBGPuJ (ORCPT ); Sun, 7 Feb 2021 10:50:09 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2AC8F64E52; Sun, 7 Feb 2021 15:48:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712933; bh=AoC8AdZxKBKJlcFns1l5O/bD1szk6uZUqhe8jzPPMTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d/pl44mv/RvAjFykZXKaBA4yrS3VWveD5Yz7/0BFtod9580ktiCWDai9y0datlnSN LYGFMVUL2AEvk8n4Y4dk+Up6NFy5qpC67lsoM98hHbmO7Wp9YyK3vahuZOoMOepjpA AKb5HQSq8hLXHj1P9g8lfL4DQbmRDaHoTk/7+/WnVD0CEbArHodwRLD4O2K9PpvfA/ 7hYfwTxGFgBjKGllqxmYkDQgBzbduUG7lvmQJPcV+zf6N/Wq6EWggJxvFgmqq9XYaX U26cU3dThqU814hzdygOBVQQufgenPqzUG5cMbDfywVaROXiQcaUgKebI7i60QcGxr stc0LCEAI42Fw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 07/24] staging:iio:cdc:ad7150: Simplify event handling by only using rising direction. Date: Sun, 7 Feb 2021 15:46:06 +0000 Message-Id: <20210207154623.433442-8-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron The event line is active high and not maskable within the device. It indicates current state directly. The device supports separate rising and falling thresholds so rather than trying to using each bound to detect in both directions just use IRQF_TRIGGER_RISING. If a user wants to detect the value falling back below the threshold, then set the falling threshold appropriately. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 539beed1a511..34e6afe52f0e 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -603,7 +603,6 @@ static int ad7150_probe(struct i2c_client *client, NULL, &ad7150_event_handler, IRQF_TRIGGER_RISING | - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "ad7150_irq1", indio_dev); From patchwork Sun Feb 7 15:46:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073081 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18E21C433E0 for ; Sun, 7 Feb 2021 15:50:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFB6F64D9A for ; Sun, 7 Feb 2021 15:50:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229651AbhBGPuK (ORCPT ); Sun, 7 Feb 2021 10:50:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:34028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbhBGPuJ (ORCPT ); Sun, 7 Feb 2021 10:50:09 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AFDE864E54; Sun, 7 Feb 2021 15:48:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712934; bh=5ktcO7M+7ub0BD03DVCMXmzuQaOquDyiftN7Rg9aDZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pt0Fq2zeTiOBz2STEhg/BPWQLbYX6w0BGN4xOm84XAND7NJCwm5TkvKLDPY2lrFQB XBn6paMYmyJUdOGXB3KtBuOSaaOT2kaWNJge3GE0Nt/pCBH/9oBRrYPjzBwZy6rO7Y TScl9t3aXY9nAYinoFXs2CjxX/7xkwcGKsbIlTJJmDiDrTrGJANsJ7ni684LqACVpb yO3Ov7utKEPzLp/pHJqc9z9T8HI0OhngWLfxIHP+OsbbgqKehtROY0pIH7pgHggW05 wPf/zCBBooFB+Shw3iil2t+RZhkmiYqPnIEFcjO+alBN8TOqYI1Zvu9uLQ5eB2MXcR y7y4n4hD+MTrA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 08/24] staging:iio:cdc:ad7150: Drop noisy print in probe Date: Sun, 7 Feb 2021 15:46:07 +0000 Message-Id: <20210207154623.433442-9-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Also * drop i2c_set_client_data() as now unused. * white space cleanups Signed-off-by: Jonathan Cameron Reviewed-by: Barry Song --- drivers/staging/iio/cdc/ad7150.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 34e6afe52f0e..8f8e472e3240 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -573,11 +573,9 @@ static int ad7150_probe(struct i2c_client *client, indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); if (!indio_dev) return -ENOMEM; + chip = iio_priv(indio_dev); mutex_init(&chip->state_lock); - /* this is only used for device removal purposes */ - i2c_set_clientdata(client, indio_dev); - chip->client = client; indio_dev->name = id->name; @@ -624,14 +622,7 @@ static int ad7150_probe(struct i2c_client *client, } } - ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev); - if (ret) - return ret; - - dev_info(&client->dev, "%s capacitive sensor registered,irq: %d\n", - id->name, client->irq); - - return 0; + return devm_iio_device_register(indio_dev->dev.parent, indio_dev); } static const struct i2c_device_id ad7150_id[] = { From patchwork Sun Feb 7 15:46:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073085 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17768C433E9 for ; Sun, 7 Feb 2021 15:50:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D9B9164D9A for ; Sun, 7 Feb 2021 15:50:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229596AbhBGPuL (ORCPT ); Sun, 7 Feb 2021 10:50:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:34030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229618AbhBGPuJ (ORCPT ); Sun, 7 Feb 2021 10:50:09 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 404EA64E56; Sun, 7 Feb 2021 15:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712936; bh=SOMyTxKeIeIWFoMLtYk0Cyyi9hMbUmQfLc6M434EXww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CbSut3ZOEgqSpKptg27WCH8Pkn4gPhRExeLOF5U7kQX8ZYZ8zibOjsvSvW413grfo GJWXdOHll+BhM6c7QmQsF6xY5c18MzlLwd01qikxyXvEJL1UR0U2UavJI8WISl2EJn +LwzuGKT4FksfHre9QLEgkwdcAqGYMUiBDc3TEk/2+X4NgErDBo7OVfq+ZusfGbVJd fhBjdddKn7NajWFgj6fEiyo0R2WSERlksIBX8cOi7tL3CQ1j1b8HIUXurOk4a9jZ5C ZPnYwJQnBXG8Av4DRF0VXi7Gp3lMZf7NEFX7zBjK5/wDXMoM6bbJSrwfpm0dJj4rgl euAzOlBbLxMAg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 09/24] staging:iio:cdc:ad7150: Add sampling_frequency support Date: Sun, 7 Feb 2021 15:46:08 +0000 Message-Id: <20210207154623.433442-10-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Device uses a fixed sampling frequency. Let us expose it to userspace. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 8f8e472e3240..54f31aadc92a 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -126,6 +126,10 @@ static int ad7150_read_raw(struct iio_dev *indio_dev, return ret; *val = ret; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SAMP_FREQ: + /* Strangely same for both 1 and 2 chan parts */ + *val = 100; return IIO_VAL_INT; default: return -EINVAL; @@ -449,6 +453,7 @@ static const struct iio_event_spec ad7150_events[] = { .channel = _chan, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_AVERAGE_RAW), \ + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\ .event_spec = ad7150_events, \ .num_event_specs = ARRAY_SIZE(ad7150_events), \ } @@ -459,6 +464,7 @@ static const struct iio_event_spec ad7150_events[] = { .channel = _chan, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_AVERAGE_RAW), \ + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\ } static const struct iio_chan_spec ad7150_channels[] = { From patchwork Sun Feb 7 15:46:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073087 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2FEEC433E0 for ; Sun, 7 Feb 2021 15:50:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7ACFF64E3E for ; Sun, 7 Feb 2021 15:50:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229618AbhBGPuM (ORCPT ); Sun, 7 Feb 2021 10:50:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:34032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229623AbhBGPuJ (ORCPT ); Sun, 7 Feb 2021 10:50:09 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C5BAD64E53; Sun, 7 Feb 2021 15:48:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712938; bh=/MAkf+rmyWrWdd25iKKkrS07W14XZXRkgsf8cbh2gM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JQX3dYiMFYUxCymAGC3vI6Yg6LqdBUtmQd72h3iTiuiFcvjBZG0j3pibYx56DWZkg eU9y7bf+gzZ65SRD8cqc0lV+nbVfzW9G7ZFNW8JNRH7DSnedso2CwguQzCRf+VNavN aaNPo/8JPtHgrE2kWnAjLA/5YBk6XE5dr5yDdPyLjwtL+D2HF5wWK+9q1+XnJJWDnx 3B7oJoW9wdzud9ug3kAij8CeEE/t8Sj9pIdACkJrxp8WX0fSpwlQV02QbIokldHCBD RAObs8dmfTBHZS89CnJbNcsCZ/9mzADWWnzcRXA/WLcMJKPoJzdYH4YjCrrlAFpugv wRTbLQX21ndfA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 10/24] iio:event: Add timeout event info type Date: Sun, 7 Feb 2021 15:46:09 +0000 Message-Id: <20210207154623.433442-11-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron For adaptive threshold events, the current value is compared with a (typically) low pass filtered version of the same signal that slowly tracks large scale changes. However, sometimes a step change can result in a large lag before the low pass filtered version begins to track the signal again. Timeouts can be used to made an instantaneous 'correction'. Documentation of this attribute is added in a later patch. Signed-off-by: Jonathan Cameron --- drivers/iio/industrialio-event.c | 1 + include/linux/iio/types.h | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c index 7e532117ac55..ad01b4d84562 100644 --- a/drivers/iio/industrialio-event.c +++ b/drivers/iio/industrialio-event.c @@ -245,6 +245,7 @@ static const char * const iio_ev_info_text[] = { [IIO_EV_INFO_PERIOD] = "period", [IIO_EV_INFO_HIGH_PASS_FILTER_3DB] = "high_pass_filter_3db", [IIO_EV_INFO_LOW_PASS_FILTER_3DB] = "low_pass_filter_3db", + [IIO_EV_INFO_TIMEOUT] = "timeout", }; static enum iio_event_direction iio_ev_attr_dir(struct iio_dev_attr *attr) diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h index 1e3ed6f55bca..f2e7c96e6e81 100644 --- a/include/linux/iio/types.h +++ b/include/linux/iio/types.h @@ -16,6 +16,7 @@ enum iio_event_info { IIO_EV_INFO_PERIOD, IIO_EV_INFO_HIGH_PASS_FILTER_3DB, IIO_EV_INFO_LOW_PASS_FILTER_3DB, + IIO_EV_INFO_TIMEOUT, }; #define IIO_VAL_INT 1 From patchwork Sun Feb 7 15:46:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073095 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BCD8C433E6 for ; Sun, 7 Feb 2021 15:50:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D25DD64D9A for ; Sun, 7 Feb 2021 15:50:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229631AbhBGPuO (ORCPT ); Sun, 7 Feb 2021 10:50:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:34034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbhBGPuK (ORCPT ); Sun, 7 Feb 2021 10:50:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5A10464E43; Sun, 7 Feb 2021 15:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712939; bh=8yGo+9mnx7F2gVtRoGJV2aljS8VDxMrMfT2/TfOUKe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uOUhFRUW2mugBW3EF0xaNjPRwvSQJ3eEBl9ii1pK7viHhZ/EWD+7+Kb/BhK0xjfqE QD/oEybxRwR0askl5TNroicsfh4B5NSuDIpCQ3xjfgwH36M1dzio78hoZxsD14+kYU We9GH03L6Pu44UtoQnhtqKksyfsoydtMnhHuqESemYZt8A2ML5351+wML+VHPfzooF ZsHu6LN3psuxz0BG51PhuZMNwiu9vXLBAJC/pWCAxtUCJ0Aaq8MNfM6m8oG28o9Wv5 BAOroY2f+fTLaB67RBGxjM/m9Zo+ylrRHx1zk50+yS/rAIl8DxjHr7VFXT4qThUUBH LYoOKCSh3JKAw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 11/24] staging:iio:cdc:ad7150: Change timeout units to seconds and use core support Date: Sun, 7 Feb 2021 15:46:10 +0000 Message-Id: <20210207154623.433442-12-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Now we have core support for timeouts related to adaptive events, let us use it. Note the units of that attribute are seconds, so we also need to scale the cycles value by the period of each sample. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 159 ++++++++++--------------------- 1 file changed, 52 insertions(+), 107 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 54f31aadc92a..f8183c540d5c 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -294,13 +294,22 @@ static int ad7150_read_event_value(struct iio_dev *indio_dev, int rising = (dir == IIO_EV_DIR_RISING); /* Complex register sharing going on here */ - switch (type) { - case IIO_EV_TYPE_THRESH_ADAPTIVE: - *val = chip->thresh_sensitivity[rising][chan->channel]; - return IIO_VAL_INT; - case IIO_EV_TYPE_THRESH: - *val = chip->threshold[rising][chan->channel]; - return IIO_VAL_INT; + switch (info) { + case IIO_EV_INFO_VALUE: + switch (type) { + case IIO_EV_TYPE_THRESH_ADAPTIVE: + *val = chip->thresh_sensitivity[rising][chan->channel]; + return IIO_VAL_INT; + case IIO_EV_TYPE_THRESH: + *val = chip->threshold[rising][chan->channel]; + return IIO_VAL_INT; + default: + return -EINVAL; + } + case IIO_EV_INFO_TIMEOUT: + *val = 0; + *val2 = chip->thresh_timeout[rising][chan->channel] * 10000; + return IIO_VAL_INT_PLUS_MICRO; default: return -EINVAL; } @@ -318,13 +327,36 @@ static int ad7150_write_event_value(struct iio_dev *indio_dev, int rising = (dir == IIO_EV_DIR_RISING); mutex_lock(&chip->state_lock); - switch (type) { - case IIO_EV_TYPE_THRESH_ADAPTIVE: - chip->thresh_sensitivity[rising][chan->channel] = val; + switch (info) { + case IIO_EV_INFO_VALUE: + switch (type) { + case IIO_EV_TYPE_THRESH_ADAPTIVE: + chip->thresh_sensitivity[rising][chan->channel] = val; + break; + case IIO_EV_TYPE_THRESH: + chip->threshold[rising][chan->channel] = val; + break; + default: + ret = -EINVAL; + goto error_ret; + } break; - case IIO_EV_TYPE_THRESH: - chip->threshold[rising][chan->channel] = val; + case IIO_EV_INFO_TIMEOUT: { + /* + * Raw timeout is in cycles of 10 msecs as long as both + * channels are enabled. + * In terms of INT_PLUS_MICRO, that is in units of 10,000 + */ + int timeout = val2 / 10000; + + if (val != 0 || timeout < 0 || timeout > 15 || val2 % 10000) { + ret = -EINVAL; + goto error_ret; + } + + chip->thresh_timeout[rising][chan->channel] = timeout; break; + } default: ret = -EINVAL; goto error_ret; @@ -338,91 +370,6 @@ static int ad7150_write_event_value(struct iio_dev *indio_dev, return ret; } -static ssize_t ad7150_show_timeout(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7150_chip_info *chip = iio_priv(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - u8 value; - - /* use the event code for consistency reasons */ - int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address); - int rising = (IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address) - == IIO_EV_DIR_RISING) ? 1 : 0; - - switch (IIO_EVENT_CODE_EXTRACT_TYPE(this_attr->address)) { - case IIO_EV_TYPE_THRESH_ADAPTIVE: - value = chip->thresh_timeout[rising][chan]; - break; - default: - return -EINVAL; - } - - return sprintf(buf, "%d\n", value); -} - -static ssize_t ad7150_store_timeout(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7150_chip_info *chip = iio_priv(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address); - enum iio_event_direction dir; - enum iio_event_type type; - int rising; - u8 data; - int ret; - - type = IIO_EVENT_CODE_EXTRACT_TYPE(this_attr->address); - dir = IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address); - rising = (dir == IIO_EV_DIR_RISING); - - ret = kstrtou8(buf, 10, &data); - if (ret < 0) - return ret; - - if (data > GENMASK(3, 0)) - return -EINVAL; - - mutex_lock(&chip->state_lock); - switch (type) { - case IIO_EV_TYPE_THRESH_ADAPTIVE: - chip->thresh_timeout[rising][chan] = data; - break; - default: - ret = -EINVAL; - goto error_ret; - } - - ret = ad7150_write_event_params(indio_dev, chan, type, dir); -error_ret: - mutex_unlock(&chip->state_lock); - - if (ret < 0) - return ret; - - return len; -} - -#define AD7150_TIMEOUT(chan, type, dir, ev_type, ev_dir) \ - IIO_DEVICE_ATTR(in_capacitance##chan##_##type##_##dir##_timeout, \ - 0644, \ - &ad7150_show_timeout, \ - &ad7150_store_timeout, \ - IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, \ - chan, \ - IIO_EV_TYPE_##ev_type, \ - IIO_EV_DIR_##ev_dir)) -static AD7150_TIMEOUT(0, thresh_adaptive, rising, THRESH_ADAPTIVE, RISING); -static AD7150_TIMEOUT(0, thresh_adaptive, falling, THRESH_ADAPTIVE, FALLING); -static AD7150_TIMEOUT(1, thresh_adaptive, rising, THRESH_ADAPTIVE, RISING); -static AD7150_TIMEOUT(1, thresh_adaptive, falling, THRESH_ADAPTIVE, FALLING); - static const struct iio_event_spec ad7150_events[] = { { .type = IIO_EV_TYPE_THRESH, @@ -438,12 +385,14 @@ static const struct iio_event_spec ad7150_events[] = { .type = IIO_EV_TYPE_THRESH_ADAPTIVE, .dir = IIO_EV_DIR_RISING, .mask_separate = BIT(IIO_EV_INFO_VALUE) | - BIT(IIO_EV_INFO_ENABLE), + BIT(IIO_EV_INFO_ENABLE) | + BIT(IIO_EV_INFO_TIMEOUT), }, { .type = IIO_EV_TYPE_THRESH_ADAPTIVE, .dir = IIO_EV_DIR_FALLING, .mask_separate = BIT(IIO_EV_INFO_VALUE) | - BIT(IIO_EV_INFO_ENABLE), + BIT(IIO_EV_INFO_ENABLE) | + BIT(IIO_EV_INFO_TIMEOUT), }, }; @@ -538,15 +487,11 @@ static irqreturn_t ad7150_event_handler(int irq, void *private) return IRQ_HANDLED; } -/* Timeouts not currently handled by core */ +static IIO_CONST_ATTR(in_capacitance_thresh_adaptive_timeout_available, + "[0 0.01 0.15]"); + static struct attribute *ad7150_event_attributes[] = { - &iio_dev_attr_in_capacitance0_thresh_adaptive_rising_timeout - .dev_attr.attr, - &iio_dev_attr_in_capacitance0_thresh_adaptive_falling_timeout - .dev_attr.attr, - &iio_dev_attr_in_capacitance1_thresh_adaptive_rising_timeout - .dev_attr.attr, - &iio_dev_attr_in_capacitance1_thresh_adaptive_falling_timeout + &iio_const_attr_in_capacitance_thresh_adaptive_timeout_available .dev_attr.attr, NULL, }; From patchwork Sun Feb 7 15:46:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 388D1C43381 for ; Sun, 7 Feb 2021 15:50:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06C4064D9A for ; Sun, 7 Feb 2021 15:50:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229590AbhBGPuO (ORCPT ); Sun, 7 Feb 2021 10:50:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:34036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbhBGPuK (ORCPT ); Sun, 7 Feb 2021 10:50:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E1CFD64E59; Sun, 7 Feb 2021 15:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712941; bh=qSn+lyfftr8GRCwyiEX0TJ64sGX3S0W2EyyHYgoeCnc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=En6AIbQdYVZjPAGK0G8iTm4OnwKvhE/U7Ri3XKhEdDQkbwppjN37l1fZDmsRJ+4ij JHXqMXDFMME7ZRS9bNvkBg63k2GYZekPxOyym3OLq7VU30nXlwt3FIQwtu6BH/pGRE k7foqIPTn7eODpIx+jYwUqbZvGm1amuKgwPxo9dXIrvaPGyBM2bWGSaijSwaulfIoD JMLWMDvSIFcMRFqJTq2vdNImVAurWkmPztS92npyntl55Ind3Yy3y4a86zLVkhR7kL lHodoSAuxgCTGvaQ3SxK+RzggJGe2Dr//zSWjYy1ZfsSt0yAXrhI4LYfTbaBlopW9y AXwBJQQvpUwtw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 12/24] staging:iio:cdc:ad7150: Rework interrupt handling. Date: Sun, 7 Feb 2021 15:46:11 +0000 Message-Id: <20210207154623.433442-13-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Note this doesn't support everything the chip can do as we ignore window mode for now (in window / out of window). * Given the chip doesn't have any way of disabling the threshold pins, use disable_irq() etc to mask them except when we actually want them enabled (previously events were always enabled). Note there are race conditions, but using the current state from the status register and disabling interrupts across changes in type of event should mean those races result in interrupts, but no events to userspace. * Correctly reflect that there is one threshold line per channel. * Only take notice of rising edge. If anyone wants the other edge then they should set the other threshold (they are available for rising and falling directions). This isn't perfect but it makes it a lot simpler. * If insufficient interrupts are specified in firnware, don't support events. * Adaptive events use the same pos/neg values of thrMD as non adaptive ones. Tested against qemu based emulation. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 258 ++++++++++++++++++------------- 1 file changed, 153 insertions(+), 105 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index f8183c540d5c..24be97456c03 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -60,8 +61,6 @@ enum { /** * struct ad7150_chip_info - instance specific chip data * @client: i2c client for this device - * @current_event: device always has one type of event enabled. - * This element stores the event code of the current one. * @threshold: thresholds for simple capacitance value events * @thresh_sensitivity: threshold for simple capacitance offset * from 'average' value. @@ -70,21 +69,23 @@ enum { * value jumps to current value. Note made up of two fields, * 3:0 are for timeout receding - applies if below lower threshold * 7:4 are for timeout approaching - applies if above upper threshold - * @old_state: store state from previous event, allowing confirmation - * of new condition. - * @conversion_mode: the current conversion mode. * @state_lock: ensure consistent state of this structure wrt the * hardware. + * @interrupts: one or two interrupt numbers depending on device type. + * @int_enabled: is a given interrupt currently enabled. + * @type: threshold type + * @dir: threshold direction */ struct ad7150_chip_info { struct i2c_client *client; - u64 current_event; u16 threshold[2][2]; u8 thresh_sensitivity[2][2]; u8 thresh_timeout[2][2]; - int old_state; - char *conversion_mode; struct mutex state_lock; + int interrupts[2]; + bool int_enabled[2]; + enum iio_event_type type; + enum iio_event_direction dir; }; /* @@ -158,8 +159,8 @@ static int ad7150_read_event_config(struct iio_dev *indio_dev, switch (type) { case IIO_EV_TYPE_THRESH_ADAPTIVE: if (dir == IIO_EV_DIR_RISING) - return !thrfixed && (threshtype == 0x3); - return !thrfixed && (threshtype == 0x2); + return !thrfixed && (threshtype == 0x1); + return !thrfixed && (threshtype == 0x0); case IIO_EV_TYPE_THRESH: if (dir == IIO_EV_DIR_RISING) return thrfixed && (threshtype == 0x1); @@ -179,11 +180,9 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, { struct ad7150_chip_info *chip = iio_priv(indio_dev); int rising = (dir == IIO_EV_DIR_RISING); - u64 event_code; - event_code = IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, chan, type, dir); - - if (event_code != chip->current_event) + /* Only update value live, if parameter is in use */ + if ((type != chip->type) || (dir != chip->dir)) return 0; switch (type) { @@ -231,52 +230,91 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev, int ret; struct ad7150_chip_info *chip = iio_priv(indio_dev); int rising = (dir == IIO_EV_DIR_RISING); - u64 event_code; - - /* Something must always be turned on */ - if (!state) - return -EINVAL; - event_code = IIO_UNMOD_EVENT_CODE(chan->type, chan->channel, type, dir); - if (event_code == chip->current_event) + /* + * There is only a single shared control and no on chip + * interrupt disables for the two interrupt lines. + * So, enabling will switch the events configured to enable + * whatever was most recently requested and if necessary enable_irq() + * the interrupt and any disable will disable_irq() for that + * channels interrupt. + */ + if (!state) { + if ((chip->int_enabled[chan->channel]) && + (type == chip->type) && (dir == chip->dir)) { + disable_irq(chip->interrupts[chan->channel]); + chip->int_enabled[chan->channel] = false; + } return 0; + } + mutex_lock(&chip->state_lock); - ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG); - if (ret < 0) - goto error_ret; + if ((type != chip->type) || (dir != chip->dir)) { - cfg = ret & ~((0x03 << 5) | BIT(7)); + /* + * Need to temporarily disable both interrupts if + * enabled - this is to avoid races around changing + * config and thresholds. + * Note enable/disable_irq() are reference counted so + * no need to check if already enabled. + */ + disable_irq(chip->interrupts[0]); + disable_irq(chip->interrupts[1]); - switch (type) { - case IIO_EV_TYPE_THRESH_ADAPTIVE: - adaptive = 1; - if (rising) - thresh_type = 0x3; - else - thresh_type = 0x2; - break; - case IIO_EV_TYPE_THRESH: - adaptive = 0; - if (rising) - thresh_type = 0x1; - else - thresh_type = 0x0; - break; - default: - ret = -EINVAL; - goto error_ret; - } + ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG); + if (ret < 0) + goto error_ret; - cfg |= (!adaptive << 7) | (thresh_type << 5); + cfg = ret & ~((0x03 << 5) | BIT(7)); - ret = i2c_smbus_write_byte_data(chip->client, AD7150_CFG, cfg); - if (ret < 0) - goto error_ret; + switch (type) { + case IIO_EV_TYPE_THRESH_ADAPTIVE: + adaptive = 1; + if (rising) + thresh_type = 0x1; + else + thresh_type = 0x0; + break; + case IIO_EV_TYPE_THRESH: + adaptive = 0; + if (rising) + thresh_type = 0x1; + else + thresh_type = 0x0; + break; + default: + ret = -EINVAL; + goto error_ret; + } - chip->current_event = event_code; + cfg |= (!adaptive << 7) | (thresh_type << 5); + + ret = i2c_smbus_write_byte_data(chip->client, AD7150_CFG, cfg); + if (ret < 0) + goto error_ret; + + /* + * There is a potential race condition here, but not easy + * to close given we can't disable the interrupt at the + * chip side of things. Rely on the status bit. + */ + chip->type = type; + chip->dir = dir; + + /* update control attributes */ + ret = ad7150_write_event_params(indio_dev, chan->channel, type, + dir); + if (ret) + goto error_ret; + /* reenable any irq's we disabled whilst changing mode */ + enable_irq(chip->interrupts[0]); + enable_irq(chip->interrupts[1]); + } + if (!chip->int_enabled[chan->channel]) { + enable_irq(chip->interrupts[chan->channel]); + chip->int_enabled[chan->channel] = true; + } - /* update control attributes */ - ret = ad7150_write_event_params(indio_dev, chan->channel, type, dir); error_ret: mutex_unlock(&chip->state_lock); @@ -434,59 +472,44 @@ static const struct iio_chan_spec ad7151_channels_no_irq[] = { AD7150_CAPACITANCE_CHAN_NO_IRQ(0), }; -static irqreturn_t ad7150_event_handler(int irq, void *private) +static irqreturn_t __ad7150_event_handler(void *private, u8 status_mask, + int channel) { struct iio_dev *indio_dev = private; struct ad7150_chip_info *chip = iio_priv(indio_dev); - u8 int_status; s64 timestamp = iio_get_time_ns(indio_dev); - int ret; + int int_status; - ret = i2c_smbus_read_byte_data(chip->client, AD7150_STATUS); - if (ret < 0) + int_status = i2c_smbus_read_byte_data(chip->client, AD7150_STATUS); + if (int_status < 0) return IRQ_HANDLED; - int_status = ret; - - if ((int_status & AD7150_STATUS_OUT1) && - !(chip->old_state & AD7150_STATUS_OUT1)) - iio_push_event(indio_dev, - IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, - 0, - IIO_EV_TYPE_THRESH, - IIO_EV_DIR_RISING), - timestamp); - else if ((!(int_status & AD7150_STATUS_OUT1)) && - (chip->old_state & AD7150_STATUS_OUT1)) - iio_push_event(indio_dev, - IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, - 0, - IIO_EV_TYPE_THRESH, - IIO_EV_DIR_FALLING), - timestamp); - - if ((int_status & AD7150_STATUS_OUT2) && - !(chip->old_state & AD7150_STATUS_OUT2)) - iio_push_event(indio_dev, - IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, - 1, - IIO_EV_TYPE_THRESH, - IIO_EV_DIR_RISING), - timestamp); - else if ((!(int_status & AD7150_STATUS_OUT2)) && - (chip->old_state & AD7150_STATUS_OUT2)) - iio_push_event(indio_dev, - IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, - 1, - IIO_EV_TYPE_THRESH, - IIO_EV_DIR_FALLING), - timestamp); - /* store the status to avoid repushing same events */ - chip->old_state = int_status; + /* + * There are race conditions around enabling and disabling that + * could easily land us here with a spurious interrupt. + * Just eat it if so. + */ + if (!(int_status & status_mask)) + return IRQ_HANDLED; + + iio_push_event(indio_dev, + IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, channel, + chip->type, chip->dir), + timestamp); return IRQ_HANDLED; } +static irqreturn_t ad7150_event_handler_ch1(int irq, void *private) +{ + return __ad7150_event_handler(private, AD7150_STATUS_OUT1, 0); +} + +static irqreturn_t ad7150_event_handler_ch2(int irq, void *private) +{ + return __ad7150_event_handler(private, AD7150_STATUS_OUT2, 1); +} + static IIO_CONST_ATTR(in_capacitance_thresh_adaptive_timeout_available, "[0 0.01 0.15]"); @@ -533,12 +556,44 @@ static int ad7150_probe(struct i2c_client *client, indio_dev->modes = INDIO_DIRECT_MODE; - if (client->irq) { + chip->interrupts[0] = fwnode_irq_get(dev_fwnode(&client->dev), 0); + if (chip->interrupts[0] < 0) + return chip->interrupts[0]; + if (id->driver_data == AD7150) { + chip->interrupts[1] = fwnode_irq_get(dev_fwnode(&client->dev), 1); + if (chip->interrupts[1] < 0) + return chip->interrupts[1]; + } + if (chip->interrupts[0] && + (id->driver_data == AD7151 || chip->interrupts[1])) { + irq_set_status_flags(chip->interrupts[0], IRQ_NOAUTOEN); + ret = devm_request_threaded_irq(&client->dev, + chip->interrupts[0], + NULL, + &ad7150_event_handler_ch1, + IRQF_TRIGGER_RISING | + IRQF_ONESHOT, + "ad7150_irq1", + indio_dev); + if (ret) + return ret; + indio_dev->info = &ad7150_info; switch (id->driver_data) { case AD7150: indio_dev->channels = ad7150_channels; indio_dev->num_channels = ARRAY_SIZE(ad7150_channels); + irq_set_status_flags(chip->interrupts[1], IRQ_NOAUTOEN); + ret = devm_request_threaded_irq(&client->dev, + chip->interrupts[1], + NULL, + &ad7150_event_handler_ch2, + IRQF_TRIGGER_RISING | + IRQF_ONESHOT, + "ad7150_irq2", + indio_dev); + if (ret) + return ret; break; case AD7151: indio_dev->channels = ad7151_channels; @@ -548,25 +603,18 @@ static int ad7150_probe(struct i2c_client *client, return -EINVAL; } - ret = devm_request_threaded_irq(&client->dev, client->irq, - NULL, - &ad7150_event_handler, - IRQF_TRIGGER_RISING | - IRQF_ONESHOT, - "ad7150_irq1", - indio_dev); - if (ret) - return ret; } else { indio_dev->info = &ad7150_info_no_irq; switch (id->driver_data) { case AD7150: indio_dev->channels = ad7150_channels_no_irq; - indio_dev->num_channels = ARRAY_SIZE(ad7150_channels_no_irq); + indio_dev->num_channels = + ARRAY_SIZE(ad7150_channels_no_irq); break; case AD7151: indio_dev->channels = ad7151_channels_no_irq; - indio_dev->num_channels = ARRAY_SIZE(ad7151_channels_no_irq); + indio_dev->num_channels = + ARRAY_SIZE(ad7151_channels_no_irq); break; default: return -EINVAL; From patchwork Sun Feb 7 15:46:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48A25C4332B for ; Sun, 7 Feb 2021 15:50:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2438364E3E for ; Sun, 7 Feb 2021 15:50:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229646AbhBGPuP (ORCPT ); Sun, 7 Feb 2021 10:50:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:34038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbhBGPuL (ORCPT ); Sun, 7 Feb 2021 10:50:11 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 75BC764E58; Sun, 7 Feb 2021 15:49:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712942; bh=DHK8ByBIHFZROiTcgedDfpuTsPseAwJQQ5RnqEQR3mQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t/chv+s48Xh5sQn88BgZto/3y1Tw+pxq7GkjTH2GtzyhkjqPH5rynbtvEGnXtD0lJ 2q3QlYrBYJlLGpIlaCdPA2bBZuBk5IdFsbsQ9hj/wbdzLGcntz1oGl4bGWcqdiY4tA QsXpcDIROKXNwC9ULM7/htlSVqYjHm3GX0QY1KTluj7WPMHCH7cnINFeOJZas0lv5Q mmnwEHIJ/mrDQDja/OOuMRIhHBFO8uwOVFI4sItVrj44pvtvmWOjP1y38Y3AIE4cJK 6Y5dUSzrR2s0x1MN1yMbioD5ct/ekWcQXqL4y1s0Gzl+CCPwa77M8P3vNuH8VflEID ncaLQq8KyUdxw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 13/24] staging:iio:cdc:ad7150: More consistent register and field naming Date: Sun, 7 Feb 2021 15:46:12 +0000 Message-Id: <20210207154623.433442-14-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Add _REG postfix to register addresses to avoid confusion with fields. Also add additional field defines and use throughout the driver in place of magic numbers. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 123 +++++++++++++++---------------- 1 file changed, 58 insertions(+), 65 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 24be97456c03..5d4783da7f98 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -21,37 +21,38 @@ * AD7150 registers definition */ -#define AD7150_STATUS 0 -#define AD7150_STATUS_OUT1 BIT(3) -#define AD7150_STATUS_OUT2 BIT(5) -#define AD7150_CH1_DATA_HIGH 1 -#define AD7150_CH2_DATA_HIGH 3 -#define AD7150_CH1_AVG_HIGH 5 -#define AD7150_CH2_AVG_HIGH 7 -#define AD7150_CH1_SENSITIVITY 9 -#define AD7150_CH1_THR_HOLD_H 9 -#define AD7150_CH1_TIMEOUT 10 -#define AD7150_CH1_SETUP 11 -#define AD7150_CH2_SENSITIVITY 12 -#define AD7150_CH2_THR_HOLD_H 12 -#define AD7150_CH2_TIMEOUT 13 -#define AD7150_CH2_SETUP 14 -#define AD7150_CFG 15 -#define AD7150_CFG_FIX BIT(7) -#define AD7150_PD_TIMER 16 -#define AD7150_CH1_CAPDAC 17 -#define AD7150_CH2_CAPDAC 18 -#define AD7150_SN3 19 -#define AD7150_SN2 20 -#define AD7150_SN1 21 -#define AD7150_SN0 22 -#define AD7150_ID 23 - -/* AD7150 masks */ -#define AD7150_THRESHTYPE_MSK GENMASK(6, 5) - -#define AD7150_CH_TIMEOUT_RECEDING GENMASK(3, 0) -#define AD7150_CH_TIMEOUT_APPROACHING GENMASK(7, 4) +#define AD7150_STATUS_REG 0 +#define AD7150_STATUS_OUT1 BIT(3) +#define AD7150_STATUS_OUT2 BIT(5) +#define AD7150_CH1_DATA_HIGH_REG 1 +#define AD7150_CH2_DATA_HIGH_REG 3 +#define AD7150_CH1_AVG_HIGH_REG 5 +#define AD7150_CH2_AVG_HIGH_REG 7 +#define AD7150_CH1_SENSITIVITY_REG 9 +#define AD7150_CH1_THR_HOLD_H_REG 9 +#define AD7150_CH1_TIMEOUT_REG 10 +#define AD7150_CH_TIMEOUT_RECEDING GENMASK(3, 0) +#define AD7150_CH_TIMEOUT_APPROACHING GENMASK(7, 4) +#define AD7150_CH1_SETUP_REG 11 +#define AD7150_CH2_SENSITIVITY_REG 12 +#define AD7150_CH2_THR_HOLD_H_REG 12 +#define AD7150_CH2_TIMEOUT_REG 13 +#define AD7150_CH2_SETUP_REG 14 +#define AD7150_CFG_REG 15 +#define AD7150_CFG_FIX BIT(7) +#define AD7150_CFG_THRESHTYPE_MSK GENMASK(6, 5) +#define AD7150_CFG_TT_NEG 0x0 +#define AD7150_CFG_TT_POS 0x1 +#define AD7150_CFG_TT_IN_WINDOW 0x2 +#define AD7150_CFG_TT_OUT_WINDOW 0x3 +#define AD7150_PD_TIMER_REG 16 +#define AD7150_CH1_CAPDAC_REG 17 +#define AD7150_CH2_CAPDAC_REG 18 +#define AD7150_SN3_REG 19 +#define AD7150_SN2_REG 20 +#define AD7150_SN1_REG 21 +#define AD7150_SN0_REG 22 +#define AD7150_ID_REG 23 enum { AD7150, @@ -93,12 +94,12 @@ struct ad7150_chip_info { */ static const u8 ad7150_addresses[][6] = { - { AD7150_CH1_DATA_HIGH, AD7150_CH1_AVG_HIGH, - AD7150_CH1_SETUP, AD7150_CH1_THR_HOLD_H, - AD7150_CH1_SENSITIVITY, AD7150_CH1_TIMEOUT }, - { AD7150_CH2_DATA_HIGH, AD7150_CH2_AVG_HIGH, - AD7150_CH2_SETUP, AD7150_CH2_THR_HOLD_H, - AD7150_CH2_SENSITIVITY, AD7150_CH2_TIMEOUT }, + { AD7150_CH1_DATA_HIGH_REG, AD7150_CH1_AVG_HIGH_REG, + AD7150_CH1_SETUP_REG, AD7150_CH1_THR_HOLD_H_REG, + AD7150_CH1_SENSITIVITY_REG, AD7150_CH1_TIMEOUT_REG }, + { AD7150_CH2_DATA_HIGH_REG, AD7150_CH2_AVG_HIGH_REG, + AD7150_CH2_SETUP_REG, AD7150_CH2_THR_HOLD_H_REG, + AD7150_CH2_SENSITIVITY_REG, AD7150_CH2_TIMEOUT_REG }, }; static int ad7150_read_raw(struct iio_dev *indio_dev, @@ -147,11 +148,11 @@ static int ad7150_read_event_config(struct iio_dev *indio_dev, bool thrfixed; struct ad7150_chip_info *chip = iio_priv(indio_dev); - ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG); + ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG_REG); if (ret < 0) return ret; - threshtype = FIELD_GET(AD7150_THRESHTYPE_MSK, ret); + threshtype = FIELD_GET(AD7150_CFG_THRESHTYPE_MSK, ret); /*check if threshold mode is fixed or adaptive*/ thrfixed = FIELD_GET(AD7150_CFG_FIX, ret); @@ -159,12 +160,12 @@ static int ad7150_read_event_config(struct iio_dev *indio_dev, switch (type) { case IIO_EV_TYPE_THRESH_ADAPTIVE: if (dir == IIO_EV_DIR_RISING) - return !thrfixed && (threshtype == 0x1); - return !thrfixed && (threshtype == 0x0); + return !thrfixed && (threshtype == AD7150_CFG_TT_POS); + return !thrfixed && (threshtype == AD7150_CFG_TT_NEG); case IIO_EV_TYPE_THRESH: if (dir == IIO_EV_DIR_RISING) - return thrfixed && (threshtype == 0x1); - return thrfixed && (threshtype == 0x0); + return thrfixed && (threshtype == AD7150_CFG_TT_POS); + return thrfixed && (threshtype == AD7150_CFG_TT_NEG); default: break; } @@ -261,35 +262,27 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev, disable_irq(chip->interrupts[0]); disable_irq(chip->interrupts[1]); - ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG); + ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG_REG); if (ret < 0) goto error_ret; - cfg = ret & ~((0x03 << 5) | BIT(7)); + cfg = ret & ~(AD7150_CFG_THRESHTYPE_MSK | AD7150_CFG_FIX); - switch (type) { - case IIO_EV_TYPE_THRESH_ADAPTIVE: + if (type == IIO_EV_TYPE_THRESH_ADAPTIVE) adaptive = 1; - if (rising) - thresh_type = 0x1; - else - thresh_type = 0x0; - break; - case IIO_EV_TYPE_THRESH: + else adaptive = 0; - if (rising) - thresh_type = 0x1; - else - thresh_type = 0x0; - break; - default: - ret = -EINVAL; - goto error_ret; - } - cfg |= (!adaptive << 7) | (thresh_type << 5); + if (rising) + thresh_type = AD7150_CFG_TT_POS; + else + thresh_type = AD7150_CFG_TT_NEG; + + cfg |= FIELD_PREP(AD7150_CFG_FIX, !adaptive) | + FIELD_PREP(AD7150_CFG_THRESHTYPE_MSK, thresh_type); - ret = i2c_smbus_write_byte_data(chip->client, AD7150_CFG, cfg); + ret = i2c_smbus_write_byte_data(chip->client, AD7150_CFG_REG, + cfg); if (ret < 0) goto error_ret; @@ -480,7 +473,7 @@ static irqreturn_t __ad7150_event_handler(void *private, u8 status_mask, s64 timestamp = iio_get_time_ns(indio_dev); int int_status; - int_status = i2c_smbus_read_byte_data(chip->client, AD7150_STATUS); + int_status = i2c_smbus_read_byte_data(chip->client, AD7150_STATUS_REG); if (int_status < 0) return IRQ_HANDLED; From patchwork Sun Feb 7 15:46:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073093 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62912C433E9 for ; Sun, 7 Feb 2021 15:50:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E64B64D9A for ; Sun, 7 Feb 2021 15:50:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbhBGPuO (ORCPT ); Sun, 7 Feb 2021 10:50:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:34040 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbhBGPuK (ORCPT ); Sun, 7 Feb 2021 10:50:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0851464E5C; Sun, 7 Feb 2021 15:49:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712944; bh=ML9ja9AGVGmBbuz2rGGTZBYVZbEJbosGAawvpn9xyxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vxp2kcuUDT7pJ80DXXsAj/mAyS7Ij7TpYEFdNgG9aPuEWmta32XzMWNz6aE0MlUdY PSMlqLSEsj4aszWwCCPavM9DsBKUUuBq49G0Hut2niv9cN+gYyrPP/dz6TuurBV9NU MPDkhS1/scYAj3tHljkIsyYZFUPRwarAl1Q3HsElhP6+Mye+FiVHn7MKz5/M1Df+z/ Bp3GYi2hJvax6MDKdJzwbbehyv5UvcbD6FiWsrB90TEmjX1P8WxpfbzCMuLC+fNh0t ycewFxl0QakgsD0YUnAhbKnWga30cTY++zgw18APSaBCf7NLNEjekofNSh94w107xn szHK6f6K+8Uug== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 14/24] staging:iio:cdc:ad7150: Reorganize headers. Date: Sun, 7 Feb 2021 15:46:13 +0000 Message-Id: <20210207154623.433442-15-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Whilst not important, it's nice to have the general headers in alphabetical order. Signed-off-by: Jonathan Cameron Reviewed-by: Barry Song --- drivers/staging/iio/cdc/ad7150.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 5d4783da7f98..9e88e774752f 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -6,13 +6,13 @@ */ #include -#include #include -#include -#include -#include +#include #include +#include +#include #include +#include #include #include From patchwork Sun Feb 7 15:46:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073099 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 361F9C433DB for ; Sun, 7 Feb 2021 15:50:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08F4E64E3E for ; Sun, 7 Feb 2021 15:50:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229702AbhBGPu1 (ORCPT ); Sun, 7 Feb 2021 10:50:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:34028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbhBGPuZ (ORCPT ); Sun, 7 Feb 2021 10:50:25 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8DBD364E5D; Sun, 7 Feb 2021 15:49:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712945; bh=9bCbymbbviS1pIvSoNX1oyz7bcGvrgD7rv/3Bka0rOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qoKY5QemVUtwtqQAKENhFQBQWzddhuTB+8/xcBPynDdIqAfsxlrK5i0lTbv5o5DyV /Hj+G6fZJc1p2oRD2MwwmadJEhLn7k4dndVX/fspvnVoynZW/+xIc+LhbA5/M3Y+k5 6gHk8lOSNFEa/14PgiFtjSggNim3LZSWeT3L+OTi4/9O/eo3LqQnzQcXIvOC+kp+xM cSDsmBeD9m+BIXHoL3m6RRH+7d81IEg6gy80o70zDyz6yXvL+8GZ7pNTwG085NaXum okQleel8G1QkOa2ViPJbQvt/3b38UtLyjty15LmS0cANVxxKM0Bt1mTXyAvdzba5F2 eR/BJf/9lmyow== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 15/24] staging:iio:cdc:ad7150: Tidy up local variable positioning. Date: Sun, 7 Feb 2021 15:46:14 +0000 Message-Id: <20210207154623.433442-16-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Where there is no other basis on which to order declarations let us prefer reverse xmas tree. Also reduce scope where sensible. Signed-off-by: Jonathan Cameron Reviewed-by: Barry Song --- drivers/staging/iio/cdc/ad7150.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 9e88e774752f..d530b467d1b2 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -108,9 +108,9 @@ static int ad7150_read_raw(struct iio_dev *indio_dev, int *val2, long mask) { - int ret; struct ad7150_chip_info *chip = iio_priv(indio_dev); int channel = chan->channel; + int ret; switch (mask) { case IIO_CHAN_INFO_RAW: @@ -143,10 +143,10 @@ static int ad7150_read_event_config(struct iio_dev *indio_dev, enum iio_event_type type, enum iio_event_direction dir) { - int ret; + struct ad7150_chip_info *chip = iio_priv(indio_dev); u8 threshtype; bool thrfixed; - struct ad7150_chip_info *chip = iio_priv(indio_dev); + int ret; ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG_REG); if (ret < 0) @@ -227,10 +227,8 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev, enum iio_event_type type, enum iio_event_direction dir, int state) { - u8 thresh_type, cfg, adaptive; - int ret; struct ad7150_chip_info *chip = iio_priv(indio_dev); - int rising = (dir == IIO_EV_DIR_RISING); + int ret; /* * There is only a single shared control and no on chip @@ -251,6 +249,8 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev, mutex_lock(&chip->state_lock); if ((type != chip->type) || (dir != chip->dir)) { + int rising = (dir == IIO_EV_DIR_RISING); + u8 thresh_type, cfg, adaptive; /* * Need to temporarily disable both interrupts if @@ -533,9 +533,9 @@ static const struct iio_info ad7150_info_no_irq = { static int ad7150_probe(struct i2c_client *client, const struct i2c_device_id *id) { - int ret; struct ad7150_chip_info *chip; struct iio_dev *indio_dev; + int ret; indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); if (!indio_dev) From patchwork Sun Feb 7 15:46:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073111 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94819C433E0 for ; Sun, 7 Feb 2021 15:50:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6391164D9A for ; Sun, 7 Feb 2021 15:50:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229721AbhBGPuw (ORCPT ); Sun, 7 Feb 2021 10:50:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:34074 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbhBGPuu (ORCPT ); Sun, 7 Feb 2021 10:50:50 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2499864E5E; Sun, 7 Feb 2021 15:49:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712947; bh=aP/uFwsUiSKAzlWUyB9aSxCC8q0vGN79UHRvZmWsRJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ukIPSuNpBG57ioSDB4QJnbImCR/Kc6XgDuIUGrIzJkPAhEj6y3nRPHkdh41FGZDVz FjIpnglxahdRtc0Xo0Y4/rUSlC13PMwWii9MKcHsjlkIVwv8yDdSVLR0nqMDBZX8LU r5FrLd4Z6TTRaLfq2ODQUWHwXdW47rotC5IzAmagJAyFizcgTWU71v2CfJvuGnW2EM x68wfhW7HHti9kHnVyYrV3u+LkxZAagBu+CKE4hSAaip3UcID8DyXmb8Z37Kd+Frph UO0m7xOTxTZ62nPHqblZSBEZMYUHKGV7Nad6JSJJkTna4q5iVkhSyFzuq+b1vcS/Ug 2f7oX8mBP7Z3A== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 16/24] staging:iio:cdc:ad7150: Drop unnecessary block comments. Date: Sun, 7 Feb 2021 15:46:15 +0000 Message-Id: <20210207154623.433442-17-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron These have a habit of not getting updated with driver reorganizations and don't add much info so drop them. Also fix a minor comment syntax issue. Signed-off-by: Jonathan Cameron Reviewed-by: Barry Song --- drivers/staging/iio/cdc/ad7150.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index d530b467d1b2..4c83e6e37c5a 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -17,9 +17,6 @@ #include #include #include -/* - * AD7150 registers definition - */ #define AD7150_STATUS_REG 0 #define AD7150_STATUS_OUT1 BIT(3) @@ -89,10 +86,6 @@ struct ad7150_chip_info { enum iio_event_direction dir; }; -/* - * sysfs nodes - */ - static const u8 ad7150_addresses[][6] = { { AD7150_CH1_DATA_HIGH_REG, AD7150_CH1_AVG_HIGH_REG, AD7150_CH1_SETUP_REG, AD7150_CH1_THR_HOLD_H_REG, @@ -172,8 +165,7 @@ static int ad7150_read_event_config(struct iio_dev *indio_dev, return -EINVAL; } -/* state_lock should be held to ensure consistent state*/ - +/* state_lock should be held to ensure consistent state */ static int ad7150_write_event_params(struct iio_dev *indio_dev, unsigned int chan, enum iio_event_type type, From patchwork Sun Feb 7 15:46:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073101 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3841C433E6 for ; Sun, 7 Feb 2021 15:50:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C05264D9A for ; Sun, 7 Feb 2021 15:50:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229650AbhBGPu3 (ORCPT ); Sun, 7 Feb 2021 10:50:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:34026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbhBGPu0 (ORCPT ); Sun, 7 Feb 2021 10:50:26 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A9A8C64E60; Sun, 7 Feb 2021 15:49:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712948; bh=Jp1GDzXZcYQ/pOlj6E9N5al14Xc2+FKEaMLpmh2SWpU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LfZCXzVsdtJ6gHXisjXkTqvXjVdiEYtxsffkVBZeZ1CppDC6Fey3CASrbdyEk/zPl SfL+peDRIznMCnIoBrK/KwMujY0gH1ehd+kkt3gKMwCOuX48NxcdRr1UtyIEL3NnoQ 96lnliLzaVd6bk+SEWaYxDJBf5HF/7V4f9/SeUv78+saoR6/hSHlEsfX/1xMMYmOuJ O6+tsFbMVAKvfglFtFSJcYJ2NFnU5YugM4e+krpYiEQXl5KRakpQE/o4jQ3fx21fM+ LQtuDe8I58CCgWZXfPxv6MHV5On/FIuIw02rQqep+qmjqVXOk+wuTAdA4UU4yQ53To AkTL39pWjkECg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 17/24] staging:iio:cdc:ad7150: Shift the _raw readings by 4 bits. Date: Sun, 7 Feb 2021 15:46:16 +0000 Message-Id: <20210207154623.433442-18-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Every other register related to raw value on the datasheet is described as correpsonding to the 12MSB of the actual data registers + the bottom 4 bits are 0. So lets treat this as what it actually is, which is a 12 bit value. Note that we will have to be a little careful to compensate for the offset and scale values. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 4c83e6e37c5a..97689625f26c 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -111,7 +111,7 @@ static int ad7150_read_raw(struct iio_dev *indio_dev, ad7150_addresses[channel][0]); if (ret < 0) return ret; - *val = ret; + *val = ret >> 4; return IIO_VAL_INT; case IIO_CHAN_INFO_AVERAGE_RAW: From patchwork Sun Feb 7 15:46:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68943C433E6 for ; Sun, 7 Feb 2021 15:50:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D11764D9A for ; Sun, 7 Feb 2021 15:50:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229715AbhBGPuw (ORCPT ); Sun, 7 Feb 2021 10:50:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:34076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbhBGPuv (ORCPT ); Sun, 7 Feb 2021 10:50:51 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 39EE264E5A; Sun, 7 Feb 2021 15:49:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712950; bh=SoRbZ4bjAi+0oTP5ndExAjb/by4PTKbnns+ox/vRLJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JCmclsbjl8u1ehnlkFxVgDuAui8u9w4X/T5lyv2VL1IEtl5Gd7lY9VLFo8e6Elyt1 YAUeGM9ch3XvJMuMisKOs+akfDebTLnve+lJhQgO931BLJZ8Taht90Xd3vejskZh48 wvk1Yt4WGJZhEEwV/uCbB0BaEyFc1L6o0YWAH3Qu3g5Hao6+Px9SPTZozkq6Ax0uHy 0lzXX1f5Dw/TWneN7VZqfh7NL//fsX5uYMnVipL8WAQAlH2/GkpwZkw6b3O2Ytw2HC VM/JdiHb5Rww6/WGoOetYYaT2XsVCmM+bqwDcPRhPaVST1uu6U+BoZlVUFprHffNCG 9Kvdm9X3qy5bw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 18/24] staging:iio:cdc:ad7150: Add scale and offset to info_mask_shared_by_type Date: Sun, 7 Feb 2021 15:46:17 +0000 Message-Id: <20210207154623.433442-19-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron The datasheet provides these two values on the assumption they are applied to unshift raw value. Hence shift both the offset and scale by 4 to compensate. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 97689625f26c..a2aae370c231 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -121,6 +121,18 @@ static int ad7150_read_raw(struct iio_dev *indio_dev, return ret; *val = ret; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + /* + * Base units for capacitance are nano farads and the value + * calculated from the datasheet formula is in picofarad + * so multiply by 1000 + */ + *val = 1000; + *val2 = 40944 >> 4; /* To match shift in _RAW */ + return IIO_VAL_FRACTIONAL; + case IIO_CHAN_INFO_OFFSET: + *val = -(12288 >> 4); /* To match shift in _RAW */ return IIO_VAL_INT; case IIO_CHAN_INFO_SAMP_FREQ: /* Strangely same for both 1 and 2 chan parts */ @@ -425,6 +437,8 @@ static const struct iio_event_spec ad7150_events[] = { .channel = _chan, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_AVERAGE_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_OFFSET), \ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\ .event_spec = ad7150_events, \ .num_event_specs = ARRAY_SIZE(ad7150_events), \ @@ -436,6 +450,8 @@ static const struct iio_event_spec ad7150_events[] = { .channel = _chan, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_AVERAGE_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_OFFSET), \ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\ } From patchwork Sun Feb 7 15:46:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073105 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9B77C43381 for ; Sun, 7 Feb 2021 15:50:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A967564D9A for ; Sun, 7 Feb 2021 15:50:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229692AbhBGPub (ORCPT ); Sun, 7 Feb 2021 10:50:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:34022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229684AbhBGPu0 (ORCPT ); Sun, 7 Feb 2021 10:50:26 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C280D64E62; Sun, 7 Feb 2021 15:49:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712951; bh=Ky8I7DTWX1mCUv4cS7FiIiJSFZ8MtNwWTdIInWwTju8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WaBoxJtzAGKbpVQIAAhR2qB20ZQfZumqxBzazRd9bcfT5/4+RXfnycNZHr1Kkkjif 0Q1G2i0JGZg/4M5P0IqC9BcpXqK1PsBEd2XVfOYzFb2eR25oiilnEbrD6580moP7Nc rq4OKuH2Is640UP8ILEjQKT1kBd7hr6ryVG9DuOui6v8Kk/fkeIhVToGWzoiUEqygO 3ltakfm4G+S7e5TYY+z65fbljS9oiymnHziiRt2TSzdtxhLXzurcEKDNw81Cs5s8Iu 3L1MGiMsSraaNTdQh263YREZZCLHa0B6K12sjXtj6B6iedUgdOLJpsdVWBHp9tpIbF SvnKu0ltRciCQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 19/24] staging:iio:cdc:ad7150: Really basic regulator support. Date: Sun, 7 Feb 2021 15:46:18 +0000 Message-Id: <20210207154623.433442-20-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Given DT docs will include regulators, lets just turn them on and off with driver probe() and remove(). Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index a2aae370c231..0bc8c7a99883 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -538,11 +539,19 @@ static const struct iio_info ad7150_info_no_irq = { .read_raw = &ad7150_read_raw, }; +static void ad7150_reg_disable(void *data) +{ + struct regulator *reg = data; + + regulator_disable(reg); +} + static int ad7150_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct ad7150_chip_info *chip; struct iio_dev *indio_dev; + struct regulator *reg; int ret; indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); @@ -557,6 +566,18 @@ static int ad7150_probe(struct i2c_client *client, indio_dev->modes = INDIO_DIRECT_MODE; + reg = devm_regulator_get(&client->dev, "vdd"); + if (IS_ERR(reg)) + return PTR_ERR(reg); + + ret = regulator_enable(reg); + if (ret) + return ret; + + ret = devm_add_action_or_reset(&client->dev, ad7150_reg_disable, reg); + if (ret) + return ret; + chip->interrupts[0] = fwnode_irq_get(dev_fwnode(&client->dev), 0); if (chip->interrupts[0] < 0) return chip->interrupts[0]; From patchwork Sun Feb 7 15:46:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073109 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAB6AC433E6 for ; Sun, 7 Feb 2021 15:50:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 811F164E40 for ; Sun, 7 Feb 2021 15:50:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229690AbhBGPuw (ORCPT ); Sun, 7 Feb 2021 10:50:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:34078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229715AbhBGPuv (ORCPT ); Sun, 7 Feb 2021 10:50:51 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 528CE64E63; Sun, 7 Feb 2021 15:49:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712953; bh=M5ZQhHXDEgSCXSYU6eECpPK9SlfIUauk4xahlr/bo5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qbpqzf5aSsVP60VNJYdAl/wewARGbpthqTSzUATUBTzhhj+asUtLv0WltsvWrDD5s RYD3MWcHEyvxPeTfLzZt1TF/JfFcAvq2h9hnkpSxuCaRbp/SvN6jOlwF4C1+bWumRJ W2ZOM80qTXWODIMHMvcmGoK7UVU5IPmi+VWzgWzVf8lqy/RvlbBiA5s8wqXmyqpn/q SWN34KwgIO8od8+ePO+L1qaTyBgAqcU5ECqBe0eQ95t9FqoWr7Ahb9xKKu9g/gDYOo KFZb9CoaPtnT2Oogp6Htm4qmvlHiXkfY4060PasLo4meNqc++AoIhkqzo5RZcnxw6A AWw0edNjzuE5w== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 20/24] staging:iio:cdc:ad7150: Add of_match_table Date: Sun, 7 Feb 2021 15:46:19 +0000 Message-Id: <20210207154623.433442-21-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Rather than using the fallback path in the i2c subsystem and hoping for no clashes across vendors, lets put in an explicit table for matching. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 0bc8c7a99883..33c8a78c076f 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -655,9 +656,16 @@ static const struct i2c_device_id ad7150_id[] = { MODULE_DEVICE_TABLE(i2c, ad7150_id); +static const struct of_device_id ad7150_of_match[] = { + { "adi,ad7150" }, + { "adi,ad7151" }, + { "adi,ad7156" }, + {} +}; static struct i2c_driver ad7150_driver = { .driver = { .name = "ad7150", + .of_match_table = ad7150_of_match, }, .probe = ad7150_probe, .id_table = ad7150_id, From patchwork Sun Feb 7 15:46:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0882C433DB for ; Sun, 7 Feb 2021 15:50:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC0F064D9A for ; Sun, 7 Feb 2021 15:50:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229684AbhBGPub (ORCPT ); Sun, 7 Feb 2021 10:50:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:34030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbhBGPu0 (ORCPT ); Sun, 7 Feb 2021 10:50:26 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D8A2A64E64; Sun, 7 Feb 2021 15:49:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712955; bh=BNvWERF7kZIB0Y4RCSxZOcMeDmUk3d5+ItEOYMBWmnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X/7FzrvrgHwobvr6KC+eQtFYdns4a4VNMsE67SK304yOWKPOmLwnZTBFPLdV86Wbk GlDXQQn4n4Ul9+Hdj4QBfBuF1Yz+9ufUIMU/4wtX4/9agW6DdmUgnzg422CvyIbq6Q 9RDiE9SnyHEeHMdhc7Tt4b0VmvhfQylLpu65SjuqSoNAjeUTY0mNXycRnq6t4gwjdu oJQQERc5h3WfpR8WXrv4lVQMBgXYJPSTC6/8MOA8Tp3kkNLFHhlWIx4uPWObCouJns bBVLGgpp8dPXPSFLzYmZ5rSoZS9Qa0T9ZD6MxkiJCALRTMhijWv5X+DLslwSzqZUqp XlWL9ssYUR3xw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron , Robh+dt@kernel.org, devicetree@vger.kernel.org Subject: [PATCH 21/24] dt-bindings:iio:cdc:adi,ad7150 binding doc Date: Sun, 7 Feb 2021 15:46:20 +0000 Message-Id: <20210207154623.433442-22-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Binding covering the ad7150, ad7151 and ad7156 capacitance to digital convertors. The only difference between these is how many channels they have (1 or 2) Signed-off-by: Jonathan Cameron Cc: Robh+dt@kernel.org Cc: devicetree@vger.kernel.org --- .../bindings/iio/cdc/adi,ad7150.yaml | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/cdc/adi,ad7150.yaml b/Documentation/devicetree/bindings/iio/cdc/adi,ad7150.yaml new file mode 100644 index 000000000000..2155d3f5666c --- /dev/null +++ b/Documentation/devicetree/bindings/iio/cdc/adi,ad7150.yaml @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/cdc/adi,ad7150.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog device AD7150 and similar capacitance to digital convertors. + +maintainers: + - Jonathan Cameron + +properties: + compatible: + enum: + - adi,ad7150 + - adi,ad7151 + - adi,ad7156 + + reg: + maxItems: 1 + + vdd-supply: true + + interrupts: true + +allOf: + - if: + properties: + compatible: + contains: + enum: + - adi,ad7150 + - adi,ad7156 + then: + properties: + interrupts: + minItems: 2 + maxItems: 2 + - if: + properties: + compatible: + contains: + const: adi,ad7151 + then: + properties: + interrupts: + minItems: 1 + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + cdc@48 { + compatible = "adi,ad7150"; + reg = <0x48>; + interrupts = <25 2>, <26 2>; + interrupt-parent = <&gpio>; + }; + }; +... From patchwork Sun Feb 7 15:46:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D730C433E0 for ; Sun, 7 Feb 2021 15:50:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB8AA64E3E for ; Sun, 7 Feb 2021 15:50:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229711AbhBGPux (ORCPT ); Sun, 7 Feb 2021 10:50:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:34080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbhBGPuw (ORCPT ); Sun, 7 Feb 2021 10:50:52 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BC0AE64E61; Sun, 7 Feb 2021 15:49:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712956; bh=QxN68hL0r4dralFNejSlqzW5AefIyMLW6iP4TOtvLOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SA0CDmrnAyVUboSeZeM0y7pIr7q7jyyw99pVmutdZO3rndvX/auHZMDKqYBHNb7g/ QAtj838FQ/ItWBu7BogBA5K/DxM7+kO4x1cHi6ggG3cYfJiUbXCumc1Z4Cr25gr+fO lKgSrpYEFYf/Lruj2gMGvYJTV2Uw9j/cfYP45AFcRleRC+15FmpromyxV7AY+O+kUm styNbUsy2X9bDKcIcJYdMYO7sLzzXLMLGQupfW/fKk/++4Wyj3mJ9OAN40cjv8AdnN I93vzH8wYIRWJtPznXEixkOzBDv7hO35AFEbBN/+1ty+qY7ROipf/F5AXxVgoKiqk6 RGc9ax4CbZh9g== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 22/24] iio:Documentation:ABI Add missing elements as used by the adi,ad7150 Date: Sun, 7 Feb 2021 15:46:21 +0000 Message-Id: <20210207154623.433442-23-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Main additions are around thresh_adaptive. This has been supported by the core of IIO for a long time, but no driver that uses it has previously graduated from staging, hence we are missing Docs. Otherwise, just new entries in existing lists. Signed-off-by: Jonathan Cameron --- Documentation/ABI/testing/sysfs-bus-iio | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio index 35289d47d6cb..e3b9878ea7f9 100644 --- a/Documentation/ABI/testing/sysfs-bus-iio +++ b/Documentation/ABI/testing/sysfs-bus-iio @@ -324,6 +324,7 @@ What: /sys/bus/iio/devices/iio:deviceX/in_humidityrelative_offset What: /sys/bus/iio/devices/iio:deviceX/in_magn_offset What: /sys/bus/iio/devices/iio:deviceX/in_rot_offset What: /sys/bus/iio/devices/iio:deviceX/in_angl_offset +What: /sys/bus/iio/devices/iio:deviceX/in_capacitanceX_offset KernelVersion: 2.6.35 Contact: linux-iio@vger.kernel.org Description: @@ -655,6 +656,8 @@ What: /sys/.../iio:deviceX/events/in_voltageY_thresh_falling_en What: /sys/.../iio:deviceX/events/in_voltageY_thresh_either_en What: /sys/.../iio:deviceX/events/in_tempY_thresh_rising_en What: /sys/.../iio:deviceX/events/in_tempY_thresh_falling_en +What: /sys/.../iio:deviceX/events/in_capacitanceY_thresh_rising_en +What: /sys/.../iio:deviceX/events/in_capacitanceY_thresh_falling_en KernelVersion: 2.6.37 Contact: linux-iio@vger.kernel.org Description: @@ -732,6 +735,32 @@ Description: a given event type is enabled a future point (and not those for whatever event was previously enabled). +What: /sys/.../events/in_capacitanceY_adaptive_thresh_rising_en +What: /sys/.../events/in_capacitanceY_adaptive_thresh_falling_en +KernelVersion: 5.11 +Contact: linux-iio@vger.kernel.org +Descrption: + Adaptive thresholds are similar to normal fixed thresholds + but the value is expressed as an offset from a value which + provides a low frequency approximation of the channel itself. + Thus these detect if a rapid change occurs in the specified + direction which crosses tracking value + offset. + Tracking value calculation is devices specific. + +What: /sys/.../in_capacitanceY_adaptive_thresh_rising_timeout +What: /sys/.../in_capacitanceY_adaptive_thresh_falling_timeout +KernelVersion: 5.11 +Contact: linux-iio@vger.kernel.org +Descrption: + When adaptive thresholds are used, the tracking signal + may adjust too slowly to step changes in the raw signal. + *_timeout (in seconds) specifies a time for which the + difference between the slow tracking signal and the raw + signal is allowed to remain out-of-range before a reset + event occurs in which the tracking signal is made equal + to the raw signal, allowing slow tracking to resume and the + adaptive threshold event detection to function as expected. + What: /sys/.../events/in_accel_thresh_rising_value What: /sys/.../events/in_accel_thresh_falling_value What: /sys/.../events/in_accel_x_raw_thresh_rising_value @@ -772,6 +801,10 @@ What: /sys/.../events/in_proximity0_thresh_falling_value What: /sys/.../events/in_proximity0_thresh_rising_value What: /sys/.../events/in_illuminance_thresh_rising_value What: /sys/.../events/in_illuminance_thresh_falling_value +What: /sys/.../events/in_capacitanceY_thresh_rising_value +What: /sys/.../events/in_capacitanceY_thresh_falling_value +What: /sys/.../events/in_capacitanceY_thresh_adaptive_rising_value +What: /sys/.../events/in_capacitanceY_thresh_falling_rising_value KernelVersion: 2.6.37 Contact: linux-iio@vger.kernel.org Description: From patchwork Sun Feb 7 15:46:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9407AC433DB for ; Sun, 7 Feb 2021 15:50:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6695A64D9A for ; Sun, 7 Feb 2021 15:50:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229703AbhBGPua (ORCPT ); Sun, 7 Feb 2021 10:50:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:34032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229692AbhBGPu0 (ORCPT ); Sun, 7 Feb 2021 10:50:26 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4CC1E64E66; Sun, 7 Feb 2021 15:49:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712958; bh=J1crtzcACihAIjr0lh/NEmAlqbIDCHdm1R8pyw+i0gI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=caReAL5trO+QWVxKE+3bUzMLq3tVuHLRFcWUrKOVu55DpDf87eiM2qhyoMjbUvWn0 3O/GjmevEGRB3ilKV52Vj4S+QxOjQFVwz7IbUQQia3EDihUY3QnG9Z89aQtvlzrTVe 1XRFXay8ysjVd9zhyAfi8EGPuAZvfJ8ivGaaDvAj76smPjR5gJzY7EQ4F3bj/r6zpQ uppImwCB2e4oStBoDpdqRDjnI016go6loFmCX0z9npTpBaEE8I6SK7LWQQxQWe2ZOU 4We+IWxIL7x6SgXTWH2XZtt36eKhbc3hJRvZw5wTMGvq0BMxPB5PB7mlH3fBN4/qM8 nC/cqNRA7lloQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 23/24] staging:iio:cdc:ad7150: Add copyright notice given substantial changes. Date: Sun, 7 Feb 2021 15:46:22 +0000 Message-Id: <20210207154623.433442-24-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron It seems to me that the changes made to get this ready to move out of staging are substantial enough to warant a copyright notice addition. Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 33c8a78c076f..9a6b55021fa7 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -3,6 +3,7 @@ * AD7150 capacitive sensor driver supporting AD7150/1/6 * * Copyright 2010-2011 Analog Devices Inc. + * Copyright 2021 Jonathan Cameron */ #include From patchwork Sun Feb 7 15:46:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12073117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD1D2C433DB for ; Sun, 7 Feb 2021 15:50:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADD9E64E3E for ; Sun, 7 Feb 2021 15:50:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbhBGPux (ORCPT ); Sun, 7 Feb 2021 10:50:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:34084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229720AbhBGPuw (ORCPT ); Sun, 7 Feb 2021 10:50:52 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D2F8564E65; Sun, 7 Feb 2021 15:49:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612712960; bh=scFiQPxMn0cCNmI3U1ZLThe6T0Bz7rFe6CjK29e9cPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SvTGEhphardT7gVKkZkiMQgON2PLQ2dZ/nlRx4UZAF7gKnR9/K/grPtTIxOaQQoBg k5zWwKIOkW6bLOsmLdguP5dYfekITbaiyz6P0o6EHyJM+Zz5v5Bp+gvziVHxtyhg04 cbsiBnJDviJFnh3MQoL7AQ7AXuJGqzqWhbV8HM75oZBfTk+QIeA2k0yHOpvXRKQmc+ 9myPihn3QGu+zQbUyJj21KCZQ5buRFErT5G0V90JPuJs2h8FCIq9+wQyN7XrVz7FYf dFC1sSQ8yYP15KY7K73pOUJi0sDq7xSJxpfWFoxJMSMywqyd8DKsQRNYcG5bQftTLS HJcFXmYVV+j8A== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , song.bao.hua@hisilicon.com, robh+dt@kernel.org, Jonathan Cameron Subject: [PATCH 24/24] iio:cdc:ad7150: Move driver out of staging. Date: Sun, 7 Feb 2021 15:46:23 +0000 Message-Id: <20210207154623.433442-25-jic23@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210207154623.433442-1-jic23@kernel.org> References: <20210207154623.433442-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron This capacitance to digital converter (CDC) driver is compliant with the IIO ABI. Note, not all features supported (e.g. window event modes) but the driver should be in a useful functional state. The cleanup was done against QEMU emulation of the device rather than actual hardware. Whilst this was a bit of an experiment, it made it easy to confirm that the driver remained in a consistent working state through the various refactors. If it worked in the first place, it should still be working after this cleanup. Given some IIO drivers require expensive hardware setups, (not particularly true with this one) the use of QEMU may provide a viable way forward for providing testing during code changes where previously we'd had to rely on sharp eyes and crossed fingers. Note, no explicit MAINTAINERS entry as it will be covered by the generic catch-alls for ADI and IIO drivers which are sufficient. Signed-off-by: Jonathan Cameron Signed-off-by: Jonathan Cameron --- drivers/iio/Kconfig | 1 + drivers/iio/Makefile | 1 + drivers/iio/cdc/Kconfig | 17 +++++++++++++++++ drivers/iio/cdc/Makefile | 6 ++++++ drivers/{staging => }/iio/cdc/ad7150.c | 0 drivers/staging/iio/cdc/Kconfig | 10 ---------- drivers/staging/iio/cdc/Makefile | 3 +-- 7 files changed, 26 insertions(+), 12 deletions(-) diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig index 267553386c71..a5c47300e5a0 100644 --- a/drivers/iio/Kconfig +++ b/drivers/iio/Kconfig @@ -72,6 +72,7 @@ source "drivers/iio/accel/Kconfig" source "drivers/iio/adc/Kconfig" source "drivers/iio/afe/Kconfig" source "drivers/iio/amplifiers/Kconfig" +source "drivers/iio/cdc/Kconfig" source "drivers/iio/chemical/Kconfig" source "drivers/iio/common/Kconfig" source "drivers/iio/dac/Kconfig" diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile index 1712011c0f4a..1cb1434b86b2 100644 --- a/drivers/iio/Makefile +++ b/drivers/iio/Makefile @@ -18,6 +18,7 @@ obj-y += adc/ obj-y += afe/ obj-y += amplifiers/ obj-y += buffer/ +obj-y += cdc/ obj-y += chemical/ obj-y += common/ obj-y += dac/ diff --git a/drivers/iio/cdc/Kconfig b/drivers/iio/cdc/Kconfig new file mode 100644 index 000000000000..5e3319a3ff48 --- /dev/null +++ b/drivers/iio/cdc/Kconfig @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# CDC drivers +# +menu "Capacitance to digital converters" + +config AD7150 + tristate "Analog Devices ad7150/1/6 capacitive sensor driver" + depends on I2C + help + Say yes here to build support for Analog Devices capacitive sensors. + (ad7150, ad7151, ad7156) Provides direct access via sysfs. + + To compile this driver as a module, choose M here: the + module will be called ad7150. + +endmenu diff --git a/drivers/iio/cdc/Makefile b/drivers/iio/cdc/Makefile new file mode 100644 index 000000000000..ee490637b032 --- /dev/null +++ b/drivers/iio/cdc/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for industrial I/O capacitance to digital converter (CDC) drivers +# + +obj-$(CONFIG_AD7150) += ad7150.o diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/iio/cdc/ad7150.c similarity index 100% rename from drivers/staging/iio/cdc/ad7150.c rename to drivers/iio/cdc/ad7150.c diff --git a/drivers/staging/iio/cdc/Kconfig b/drivers/staging/iio/cdc/Kconfig index e0a5ce66a984..a7386bbbcb79 100644 --- a/drivers/staging/iio/cdc/Kconfig +++ b/drivers/staging/iio/cdc/Kconfig @@ -4,16 +4,6 @@ # menu "Capacitance to digital converters" -config AD7150 - tristate "Analog Devices ad7150/1/6 capacitive sensor driver" - depends on I2C - help - Say yes here to build support for Analog Devices capacitive sensors. - (ad7150, ad7151, ad7156) Provides direct access via sysfs. - - To compile this driver as a module, choose M here: the - module will be called ad7150. - config AD7746 tristate "Analog Devices AD7745, AD7746 AD7747 capacitive sensor driver" depends on I2C diff --git a/drivers/staging/iio/cdc/Makefile b/drivers/staging/iio/cdc/Makefile index ab8222579e7e..afb7499a7090 100644 --- a/drivers/staging/iio/cdc/Makefile +++ b/drivers/staging/iio/cdc/Makefile @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # -# Makefile for industrial I/O DAC drivers +# Makefile for industrial I/O CDC drivers # -obj-$(CONFIG_AD7150) += ad7150.o obj-$(CONFIG_AD7746) += ad7746.o