From patchwork Sun Mar 14 18:14:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12137845 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.2 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,URIBL_BLOCKED,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 47F7AC433E0 for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F013964E77 for ; Sun, 14 Mar 2021 18:18:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230441AbhCNSRk (ORCPT ); Sun, 14 Mar 2021 14:17:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:44878 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232431AbhCNSR0 (ORCPT ); Sun, 14 Mar 2021 14:17:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A0A5964EC3; Sun, 14 Mar 2021 18:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745846; bh=0yy0K9rHUqCqzzRRNcRTpKrZHbakWr9rsVlqqPHzCKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RRVfZpCEkSExo9s7CHl+qNWb2kuNbM6Z4XdwaAWVKv67ONOimaqJLvmcOda2BT+3o yKs9Uzqo3Mijyh0lVVtkqz7h/T2XYD8oZtvz3xB0KffW0L2pt+r4zA4U53MEbFQo9q OeGIP4h+lVdLV2sBLkykWj1iG8ojT2IzroHSwjZpl3dvKK7CbAjoI4BD8BBUAstyvl 9qJ4GuW87ZJ1li1vCdfSDOoz+ODalkSE99dZq9m7niS2nHjX8TSGnMnoaVHWxiI3rF Pj8RyMbyvZq+o41JqgcVPk07P9WgntaMHr00xy1tEgbFjb5tv4ZaK74yArZWlk7AOq p04j9IiBO5phw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 01/24] staging:iio:cdc:ad7150: use swapped reads for i2c rather than open coding. Date: Sun, 14 Mar 2021 18:14:48 +0000 Message-Id: <20210314181511.531414-2-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-2-jic23@kernel.org --- 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 Mar 14 18:14:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12137853 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.2 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,URIBL_BLOCKED,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 88A2CC433E6 for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5949664E77 for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231205AbhCNSRl (ORCPT ); Sun, 14 Mar 2021 14:17:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:44902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232662AbhCNSR3 (ORCPT ); Sun, 14 Mar 2021 14:17:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8564064EC4; Sun, 14 Mar 2021 18:17:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745848; bh=G032iLz19tOMjDWlTQQD9/PvJvSkSm3QEEzF5tJXvh0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dzjZEpGVmMMlCYKyLYA/K3oKhB+3gkEoIuMLFEH8rc6SjE9HUMvhwqXI36PR18raJ EKBR41082qsRkjyWQG5JGroT343Qxqw4uQzfF2XEbF1jo45qWtJWALrPd3vg0S9qpn 19Raac4ii5M2W8qU58341ReitHdI+QRnj9prYIa0RUUIwWJqyJ0PTrqmpBDIHDmYdR tZemH1wKElrjOaQQSSgNmfe75tE0z54DIZizytHE/u3XvC4iU9a6SmYABu9I8Wcbdq PF5eM0Yl77OESbeM3NWrTP3lN0lq6FY3AAx9h+iNDA+eehquTBouu7YKygKoz/s1V2 CeYIX8Uw+AQPg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 02/24] staging:iio:cdc:ad7150: Remove magnitude adaptive events Date: Sun, 14 Mar 2021 18:14:49 +0000 Message-Id: <20210314181511.531414-3-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-3-jic23@kernel.org --- 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 Mar 14 18:14:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12137851 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.2 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,URIBL_BLOCKED,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 9C39CC43381 for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69CD864EE3 for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229870AbhCNSRl (ORCPT ); Sun, 14 Mar 2021 14:17:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:44930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233103AbhCNSRa (ORCPT ); Sun, 14 Mar 2021 14:17:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6BADF64E77; Sun, 14 Mar 2021 18:17:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745849; bh=s5yXVp6LX5eRVmMkKAXkegOWvppVQyqScTFtdObQhAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VE9EFSeqbwgiZFRV0++gTVj9mLlwIa2WNdbM2sv3maJqBL3/Y7zLBMTfimrI6fHUk 00XrIGsdZYiPGfZBToxi8Q5z18Do2IavDd7PCyYHVn1qyQFeFoli4rCtPuEtYycD0v mrtfPZW+RbFRv1LQjacBPzjuhDGpapdJgz7fcmCuaqI645q3Eryu7J4JAvEclDG9uM jJfgvlXo6E2QSxl7pJuakguWXenK70FL8T0dj3M/P6R2Ie3xTXnHPYKz37fNGNUYQf rDOwvz+OpW7xi8fss/AhaPNL0U6fVcGm17macZCHElGSdRFw7nABW1zDzZpMTPrBSq jBasPt98P4ZMQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 03/24] staging:iio:cdc:ad7150: Refactor event parameter update Date: Sun, 14 Mar 2021 18:14:50 +0000 Message-Id: <20210314181511.531414-4-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-4-jic23@kernel.org --- 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 Mar 14 18:14:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12137849 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.2 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,URIBL_BLOCKED,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 72639C433E9 for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4907364EC4 for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232431AbhCNSRm (ORCPT ); Sun, 14 Mar 2021 14:17:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:44952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233369AbhCNSRc (ORCPT ); Sun, 14 Mar 2021 14:17:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4CC7064EC8; Sun, 14 Mar 2021 18:17:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745851; bh=y4/tq/NppJRs+u5Ll0hQtdHLEVm8dJtkbFOpgHffGew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MDwcuwyEwqZnBLiMtPtv3Z2B2unTaISVEtsjbtN3DVWdvS0JSXaqNdVd9Z12Y+hpE oEcTzu1dVO19Bqldr5/Ef+UAsWXciBtgMcQRq0zj4f1rneKIXaijHp6JnsmkBohI2C A5bpbNLSwLCBAcu+5k183jPirlznjp66DuLjYY9nuzZlp8QosY/zh8DqiEqPYnZHFr fyeRrXFmKHk84OWyqiw/X4heRtX05FHm0gnGKqrLaA3k7qs99oDujtDyEPACsDDsp5 A5NkyvQIlRj9Flkq+lhvRBOV5Ds2Phkk9zFEhpfItc7EcxP/Te00zK1TK6KE2nj0Er Q+qIpUyy3N/Qw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 04/24] staging:iio:cdc:ad7150: Timeout register covers both directions so both need updating Date: Sun, 14 Mar 2021 18:14:51 +0000 Message-Id: <20210314181511.531414-5-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-5-jic23@kernel.org --- 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 Mar 14 18:14:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12137855 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.2 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,URIBL_BLOCKED,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 A5AD8C4332D for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 905DA64EE5 for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232662AbhCNSRm (ORCPT ); Sun, 14 Mar 2021 14:17:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:44972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233389AbhCNSRe (ORCPT ); Sun, 14 Mar 2021 14:17:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 309C364EC6; Sun, 14 Mar 2021 18:17:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745853; bh=RGIaw3TXN/jNvvb2wJvRV1c6Q1goNDD036QmSMsTVnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ikXa+YfKCRTUL/eCuJCz8USD6EsdWTT62QQJ8rlq0HvXjOBHWbLMXBGq5gYCx+fTe 4ovRsQvkPiRREYKhcu92hNhGLOBA/R36bMQcJD7o5iHUVvgd+QjQ8vByskwUVeO3bV Uhh+RoSM39oXMHn7coMflCIopRkOxMIpP5NnnOxg0JIONzhT15KQMzYcVWjBP3nPCP BXf6tVB4sa3SBKYyTuQm+yk7kQfFnTyXHGc2CZ4jfrCNWiIhItTmHQq7e+7V9UYvKX Kun9b9XNPXCmmfdvcPiwWHQZYDVA846Bt9GjHZamu5QD+ao09tduyRzRrG32aGMo+1 3mlbByo/UEiKw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 05/24] staging:iio:cdc:ad7150: Drop platform data support Date: Sun, 14 Mar 2021 18:14:52 +0000 Message-Id: <20210314181511.531414-6-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-6-jic23@kernel.org --- 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 Mar 14 18:14:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12137857 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.2 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,URIBL_BLOCKED,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 A49DBC4332B for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 80A8364EC8 for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233103AbhCNSRm (ORCPT ); Sun, 14 Mar 2021 14:17:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:44998 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231809AbhCNSRf (ORCPT ); Sun, 14 Mar 2021 14:17:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 14B8664EE3; Sun, 14 Mar 2021 18:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745855; bh=CYtGui8bZCAKg/0n4fWfZKxTmiojf1wMuLUVEijU/iA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jSUrKQH4QWDrQXYJD8nr2oUi8TnhzEI11UwhxbDRh2zmwtgTAG5vnSjRstIHNWdQd p0fEoilTO6BHiFjDJXLDeFkzwljAv49OoV/JoVhWGhZLJiFZnFx42Ju+wK2KWObRSF YQd1rc8+jn5n2qzHSN+GMbEJXXdFhv7PppI4H/DvU1HUqtoNdF5VEHljkOTG8vePBb HMiAECRj9D05zZT1q+QJ+r/+cjUjVZT93QAu0puavm04wSn9aKn4kF92vUOmCEA2TM FAQnHiErO2fjZy2ZepmnluxGIF3j9H1/mrB67+a8Wuc/Me3f2k+NUig3TwAvlsnxdd ZQlGEhufX9U1g== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 06/24] staging:iio:cdc:ad7150: Handle variation in chan_spec across device and irq present or not Date: Sun, 14 Mar 2021 18:14:53 +0000 Message-Id: <20210314181511.531414-7-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-7-jic23@kernel.org --- 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 Mar 14 18:14:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12137861 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.2 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,URIBL_BLOCKED,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 077B1C43331 for ; Sun, 14 Mar 2021 18:18:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4FDE64E77 for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231809AbhCNSRn (ORCPT ); Sun, 14 Mar 2021 14:17:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:45022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233560AbhCNSRh (ORCPT ); Sun, 14 Mar 2021 14:17:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EABB364EE5; Sun, 14 Mar 2021 18:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745857; bh=w1x4gJMw5apcvIxY6adbF7oo62IwpZuDzsW6SDLQsLo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rgjh61OrMzWMKgcEdIxJfSAWYF67C63UUmWnOkGRDwN9gD9dMhDkt3aioexjMCJRu q71v3qeLNdbUy/YwS3E48Uh+XMG8l6erqxA8Ax0cyuiphx3y5i7GkGt994rjaWHwka epIezxwxab25W7BpHZuDu031Hke6wgb3n8VfL1+BE0zhWWTPxeregp9/4oStmITxsv VLIyI68zcWrNS5JpsJl7x0uJ9K/snpcCwAR8pa3IWBtSERd3XmALc4t9CF5aEFuK8w o66Zrs4LXkIH307EYSAxqUEr+lA8+012LTD0Ge+LuStW/QSCJZdbKTP1H/XAfo9YaU 2r9MiRw628Fbg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 07/24] staging:iio:cdc:ad7150: Simplify event handling by only using rising direction. Date: Sun, 14 Mar 2021 18:14:54 +0000 Message-Id: <20210314181511.531414-8-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-8-jic23@kernel.org --- 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 Mar 14 18:14:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12137859 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.2 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,URIBL_BLOCKED,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 E1AB3C4332E for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A2C6064EC4 for ; Sun, 14 Mar 2021 18:18:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233560AbhCNSRq (ORCPT ); Sun, 14 Mar 2021 14:17:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:45044 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233570AbhCNSRj (ORCPT ); Sun, 14 Mar 2021 14:17:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CF22064EC3; Sun, 14 Mar 2021 18:17:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745859; bh=G/yDof4P/Fe2MUjVSQA6rgTKsHYd9M9l46Jf2hH6wGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RarVtevaI0nf/HEgste2cAnB5wTWei9yPz9FbYDZqKsWM9xnWBrwyk9TEfqg2X9ow oF0to5fb1TduPTig/UqUoAvigyTpk+h147yN1lDzNSLnfYCe+uHrrDibXOuReteGPW s3KoyQOCdB/tSDzO2uP4tsPEhjRuGJS0qv51fR2b8ZoA1vJJru7rJBXhf2MaVzyE12 TU7PSRGorrDCQCcWj2TS88ybtZRIGZgRBZumUWRcskRcsxkHO+G+4V73ONA7kbqA0c KlHizfzQuK+VG87ETVwLXJRxBdILGN8qqs7BMyu9ccy/LQpAR9kX4Lge8iZs2T8Ahk DTq9WGq3SPS/Q== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Barry Song , Alexandru Ardelean Subject: [PATCH v2 08/24] staging:iio:cdc:ad7150: Drop noisy print in probe Date: Sun, 14 Mar 2021 18:14:55 +0000 Message-Id: <20210314181511.531414-9-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-9-jic23@kernel.org --- 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 Mar 14 18:14:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12137863 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.2 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,URIBL_BLOCKED,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 80340C433E0 for ; Sun, 14 Mar 2021 18:18:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D75564EC3 for ; Sun, 14 Mar 2021 18:18:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234074AbhCNSSN (ORCPT ); Sun, 14 Mar 2021 14:18:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:45070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231329AbhCNSRl (ORCPT ); Sun, 14 Mar 2021 14:17:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D830064E31; Sun, 14 Mar 2021 18:17:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745861; bh=aY0zNJMlXtCx+W+ixd9Z4IxiPTaXFT72hRH1gNZmdv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zmuf3MW7BNPvzkMxMsJ+q/K+fP2Rgc19O/s5+bzRqVCRsgVq4RS9MVuSSjYJ/iCIv mp8elK4ZK/s8hAPROWAa965wyATMMpbK8SktOsOXG5nfPg7u689P8iGBsLruyf1PYS 55JhiZzQPGLZSZox4WvxOSfvDx2poZms4lTTdmCSeEG2Wdxe1mAsDvZX9MbnESpVnq nxPfuNNGndH7FXIV4HNnOiqaVz/FpkyUIzIfu7X11qym6I1wgb3a0D2PIT+feb2lDv mYXZYNEtpfl4T1/QbB9O2it7v7hXGQluy9HZ7EWV8mj2UlvhprwGeRuRfbpbleBM3J gKwNMKSNNoCuA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 09/24] staging:iio:cdc:ad7150: Add sampling_frequency support Date: Sun, 14 Mar 2021 18:14:56 +0000 Message-Id: <20210314181511.531414-10-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-10-jic23@kernel.org --- 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 Mar 14 18:14:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12137865 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.2 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,URIBL_BLOCKED,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 929EAC433E6 for ; Sun, 14 Mar 2021 18:18:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6CCF864EE3 for ; Sun, 14 Mar 2021 18:18:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234084AbhCNSSP (ORCPT ); Sun, 14 Mar 2021 14:18:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:45094 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233369AbhCNSRn (ORCPT ); Sun, 14 Mar 2021 14:17:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C431064EC4; Sun, 14 Mar 2021 18:17:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745863; bh=QEaaza3BOatkIZQJ9jfysAynQ6mv9r/zhgtGm6LhEHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=guw/xjtrM2v/oiEad2cm57UtSM0/s0Vt+0otR9+tz/KmwwvOHP22j8MpSYFhKTSVQ ql/faaZQdBePXcxwuAgN/FBNXuvPg4YzzqW0WUGOf4PD7f9U2f68FfTDh1rLOtvz1u khPvAxeF1TJ1t+yrwuEvlUj2DcXsUhjUi35RoqBpuWKHInweX7Y8oDoT6RzZ49UMNN J0YqyCeFjyGDK7LTdVOPQQU7nhhEJ+fbrIMYMrSciGgmMJd46iazKbqStXV4/MFir9 uVcE43AaVPI/gh1xx54+8zyoOQA2JSmhweBzCcMtsVIhOdldoHWEVyQvx992A2WeaV QNVaeG53XrZVg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 10/24] iio:event: Add timeout event info type Date: Sun, 14 Mar 2021 18:14:57 +0000 Message-Id: <20210314181511.531414-11-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-11-jic23@kernel.org --- 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 a30e289fc362..17420682e308 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 5aa7f66d4345..84b3f8175cc6 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 Mar 14 18:14:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12137867 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.2 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,URIBL_BLOCKED,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 B00ECC433E9 for ; Sun, 14 Mar 2021 18:18:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8216964EC8 for ; Sun, 14 Mar 2021 18:18:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231329AbhCNSSN (ORCPT ); Sun, 14 Mar 2021 14:18:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:45124 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233389AbhCNSRq (ORCPT ); Sun, 14 Mar 2021 14:17:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ADA3464EC8; Sun, 14 Mar 2021 18:17:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745865; bh=Zm8XjHk4AwoEtqnPZvQuJ0k7zgJaNr6G+n5KpsPkHq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iTYLFLnD7GSnajcwzqCB94jqRir+BMqV/4WLAdXsX/6nily6JD22n1RUF9NtxcsHD 8DCIuOCRlluepCF9LnkVRco1YZ7eNvz43rcRLfrrTAXSJkB95x1lZyZVMk0oUokFm/ POHGaU7fo9CYc8huYclqiW2lWkdYJ6eDTSSk0miXYah9FxfZEVTpiupp/zDRWN4naJ EFvSXUIhTlkEp+5fgLKOYB+kMncV2gDMvtB31gUQjmW1fZH+sHwi73HsGrwmVVPMqq kK3Fa8oQMJmFeq8Xxh4dBQnhRDVHseSXW2a8X4ridWZOVCOu6JAOkHiOaM4BdBxde/ RIknIT/OfGGkQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 11/24] staging:iio:cdc:ad7150: Change timeout units to seconds and use core support Date: Sun, 14 Mar 2021 18:14:58 +0000 Message-Id: <20210314181511.531414-12-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-12-jic23@kernel.org --- 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 Mar 14 18:14:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12137873 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.2 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,URIBL_BLOCKED,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 3BADCC4332E for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F11B264E77 for ; Sun, 14 Mar 2021 18:18:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233369AbhCNSSR (ORCPT ); Sun, 14 Mar 2021 14:18:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:45140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233570AbhCNSRr (ORCPT ); Sun, 14 Mar 2021 14:17:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9A16A64E77; Sun, 14 Mar 2021 18:17:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745867; bh=JMB1duCPGPbf6nbVrCjPftJ9zq7HKD/995ez5S++nD0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cLXI0iX4aWzdHJsyLUMK4RCU4tJTs6sYU3/HLeMxxPjB5e2XxvvvEZoIPOeRkeN7A ktmSwtz6EsW5JBD6dK7sjAPqa//IWY/9UaEanhT1XxPqKvQINfp7P4YnHEgx1Vu9sH 8dAkIiUGmb8psSa2xR4dyuedO5fPejeH8Iw+G/eoJ6Hv3bFvmbzjJHLxE6UUcaxWhC 1UeoJA8XNYcJHUovGb+M+lcZfYLmPdvkwZGke2lxOmA4kSZtbZqv8V3rOP94N2FiAB /JtDWJpKQ9ahQYPvZ+tirGY6y3LAqn1WePNqUGKGtTxmJE98VwFCWxHxL6a/6QfZF3 2DqYzpBHXlWQA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron Subject: [PATCH v2 12/24] staging:iio:cdc:ad7150: Rework interrupt handling. Date: Sun, 14 Mar 2021 18:14:59 +0000 Message-Id: <20210314181511.531414-13-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Link: https://lore.kernel.org/r/20210207154623.433442-13-jic23@kernel.org Reviewed-by: Alexandru Ardelean --- 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 Mar 14 18:15: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: 12137871 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.2 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,URIBL_BLOCKED,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 CC5E4C4332D for ; Sun, 14 Mar 2021 18:18:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B451A64E77 for ; Sun, 14 Mar 2021 18:18:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233570AbhCNSSR (ORCPT ); Sun, 14 Mar 2021 14:18:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:45156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233756AbhCNSRt (ORCPT ); Sun, 14 Mar 2021 14:17:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 59C0764EC6; Sun, 14 Mar 2021 18:17:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745868; bh=E53hIdKRb8Dd4ROJiBvu6c2aXoH+4ktpcXXI5NAwmZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TBEIcToVsfUasA0cbCakdHup7nNvDXAm1OAlRIm8cJJ/HCtv7W/wmWpBYcKFHWrTQ /GB8zk6/WPJ8iteX7eUv+x67W4396WbB2r55NEmM5R2jstENw4fxl3VnC+pFV7pR+r kTMsl4NztlkZ+VEo6AdgJ83jvDEZGJFeLDVqFzdoajvOE+WbLyZNgyGBIaT5ZfTZQ4 JOIcskTZlvnkUODb9PM8ywdYn/fNSH9iYynYv2bNChygM7K30Po0b4KPDrB+mmg3xl b3HNmtPyRQDc99shOxzycQXK4JOhScsCCiUqxFCF+E12UWkaHPpcGJ4ssYDUH+gLDm ZQu95uB0g6hzQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 13/24] staging:iio:cdc:ad7150: More consistent register and field naming Date: Sun, 14 Mar 2021 18:15:00 +0000 Message-Id: <20210314181511.531414-14-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-14-jic23@kernel.org --- drivers/staging/iio/cdc/ad7150.c | 129 +++++++++++++++---------------- 1 file changed, 61 insertions(+), 68 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 24be97456c03..99125abb889b 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; } @@ -226,7 +227,7 @@ 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; + u8 thresh_type, cfg, fixed; int ret; struct ad7150_chip_info *chip = iio_priv(indio_dev); int rising = (dir == IIO_EV_DIR_RISING); @@ -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: - 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; - } + if (type == IIO_EV_TYPE_THRESH_ADAPTIVE) + fixed = 0; + else + fixed = 1; + + if (rising) + thresh_type = AD7150_CFG_TT_POS; + else + thresh_type = AD7150_CFG_TT_NEG; - cfg |= (!adaptive << 7) | (thresh_type << 5); + cfg |= FIELD_PREP(AD7150_CFG_FIX, fixed) | + 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 Mar 14 18:15: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: 12137869 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.2 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,URIBL_BLOCKED,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 C79EAC43381 for ; Sun, 14 Mar 2021 18:18:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9EB8F64E7A for ; Sun, 14 Mar 2021 18:18:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233756AbhCNSSS (ORCPT ); Sun, 14 Mar 2021 14:18:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:45178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233779AbhCNSRv (ORCPT ); Sun, 14 Mar 2021 14:17:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3F84264EE2; Sun, 14 Mar 2021 18:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745870; bh=+ArNy+2cTID8ZwLSd3Q9f96iGanAixPkEC+0C8TzIL0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k89auVQNk2zL59TU1A39BxDA1jhykPGSpghSDjILaCS+U1FeGG1/VSD+qzOQ9Atlq +VLtTJ0D8fBMAKbatuNN/zBoMDbGgKtbwSWnfBUkPB2gv5xV9raK4Y4fSyfnN2UqUd 54io/2ymed9paK9D6D4uUx8Syy3GURR78KdNAV0LkRcJ6khPaVIpYfBDkVeBZDBgrY P3f+/gKki9j4koLXMQbrrsI51YQJXCUdesvGJQNakcXGkuXGgMh9by5QWM9k+jfbmj Ss5QcDaEYe4kU9552GbQK603Rgl2WArA3b5uEd4xlAW6dbVSEhSa+a5hF2xIKc0RSq jJ7IL8F5Qrr9Q== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Barry Song , Alexandru Ardelean Subject: [PATCH v2 14/24] staging:iio:cdc:ad7150: Reorganize headers. Date: Sun, 14 Mar 2021 18:15:01 +0000 Message-Id: <20210314181511.531414-15-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-15-jic23@kernel.org --- 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 99125abb889b..8131fbb56d37 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 Mar 14 18:15: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: 12137881 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.2 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,URIBL_BLOCKED,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 81781C43333 for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6003264E7A for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234085AbhCNSSS (ORCPT ); Sun, 14 Mar 2021 14:18:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:45198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233332AbhCNSRx (ORCPT ); Sun, 14 Mar 2021 14:17:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4B29E64EE7; Sun, 14 Mar 2021 18:17:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745872; bh=3gNza+00fZBZtTOKVwvC+yOPSmdSdZM9NLOppzvWbmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R9F+kzpEBS9PnLU7GF47YG6HN8P0Vqox/yAatmrL2mQXb5yuIPGTXjS5IS94TvINK AVQitRfa7kJ4E7EVcwOc7HgjaSHDwH5eGsi68ZR/dOZGN8k2KC8shHmI1YBBk4SUgn y3kwN7DWSzdZkOHKoIZRGQtwQIIZ+y5bHmaDWub+3FmWf8K1O3Xy1YGxpfcHbAotkx Vx68xCUgyJKRsrnc7zYvxkyO+rEFftbxwCT5Sm+E6q74GBn91F3xvyI12teZQnhDMa JBnRp+GzHa4ZwoYYAOf36igzC7j+a/gK2K4n1wmFoMnkDo8uk+AOSLBlkMQDNQvExq oaLSPyAnXXNxw== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Barry Song , Alexandru Ardelean Subject: [PATCH v2 15/24] staging:iio:cdc:ad7150: Tidy up local variable positioning. Date: Sun, 14 Mar 2021 18:15:02 +0000 Message-Id: <20210314181511.531414-16-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-16-jic23@kernel.org --- 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 8131fbb56d37..1bfa71d7ca1d 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, fixed; - 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, fixed; /* * 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 Mar 14 18:15: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: 12137875 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.2 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,URIBL_BLOCKED,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 76945C43331 for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 40D4F64EC6 for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233332AbhCNSST (ORCPT ); Sun, 14 Mar 2021 14:18:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:45220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233985AbhCNSRz (ORCPT ); Sun, 14 Mar 2021 14:17:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5822C64EE5; Sun, 14 Mar 2021 18:17:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745875; bh=AA8WgY6NQs/eth2FowL4Scb9ngP3IDGt2y4nrdig4N0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fRS8rTRsSH58HApPMwWbFvoN0RWlWLEIRzl30B6/0gTleUXo8MCdSOWTY/uft0qeE euGoSTP9aYDh7d02m6xd+tDI0/ruOEo4tl+yyBJnncfrxr5o36t0KUnB8iankErXUN 79xkyCfwmTDcQ7mPGhTpzlnYPt6V1tSg4A0OrXWWWPIEg4rXS2v027ymosavPSSHtR feg94g899GGvI1jbrvtBO+TI9EHQq5dfoQBJpNkk+de3vz8l/fVErn6gFG/M9TqPK1 +S0fpe3rpSxXV7u4QC4GseoUl9cvGyX9HKs1ZF+Sub7fiyAltuMiCM6lZhSrSi4daL 5rUCyo420Nvlg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Barry Song , Alexandru Ardelean Subject: [PATCH v2 16/24] staging:iio:cdc:ad7150: Drop unnecessary block comments. Date: Sun, 14 Mar 2021 18:15:03 +0000 Message-Id: <20210314181511.531414-17-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-17-jic23@kernel.org Signed-off-by: Jonathan Cameron --- 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 1bfa71d7ca1d..67af39f80650 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 Mar 14 18:15: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: 12137883 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.2 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,URIBL_BLOCKED,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 532FAC4332B for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D99E64EC3 for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233985AbhCNSST (ORCPT ); Sun, 14 Mar 2021 14:18:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:45238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233995AbhCNSR5 (ORCPT ); Sun, 14 Mar 2021 14:17:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6106164EE3; Sun, 14 Mar 2021 18:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745876; bh=w1XgIupIXsB9J+6Tum2u2vW2nJwexDTG3dvAq+yJGF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HXouJmGSGVWm1mpxokLeLZlYNepMh18msZVOgLf/RvYOxOWsnt8Pz4TF6uZmiVybC JruQZ4Noj5+MZL9GgRDieS5s40i98urbFTmsBeapnv8JXcefuj78SI6OC7AKlK60QD ODnIZZVYduZPAAWXDtZurYJs4ROyJEaS8ngWd73Gq9GQuFjdHkpH6ih2e0d70SS6+P wbvr1vdMMzKL/wTAOhWqgVOGNtaD4Pc61HYAv1t3zNhdCnprMaSOBo2O1jNV31GrXH v4Cf0it3qb838EO7HHTGrvuCExiYi/SIgQD96TdYhtb7ROcAZKytu6rH5NdjkQL0gn UIG3gqnuydT1g== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 17/24] staging:iio:cdc:ad7150: Shift the _raw readings by 4 bits. Date: Sun, 14 Mar 2021 18:15:04 +0000 Message-Id: <20210314181511.531414-18-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-18-jic23@kernel.org --- 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 67af39f80650..1a041396ff9e 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 Mar 14 18:15: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: 12137879 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.2 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,URIBL_BLOCKED,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 B2206C43332 for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8590064E77 for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233995AbhCNSST (ORCPT ); Sun, 14 Mar 2021 14:18:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:45258 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233999AbhCNSR7 (ORCPT ); Sun, 14 Mar 2021 14:17:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 414DB64EC3; Sun, 14 Mar 2021 18:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745878; bh=9vWpsOiQPAIbFpELFCIdERQRoN290obi3D64Or/s1Hw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hEEPsHAO1tAyxD6eY70mPkDBkgJlpDzGyGxc1q3EnnUoNfqpS1jgpUwt+JX/tYFnN a1fyR6tLfnrbFmEuM+9WEVidJef3vk86TTY6zKxTpTYzh3b379bq9UqFAcdWB900tQ +pgts3h+ZpHqAgafBF9rn8h2HXkvZTtoKxlw/DqRqZOLpzJsT1qLsQYB1TuuAMrVgL WpYxZr3gycYJy3jzyBWNP5FR0tpdJ53trc7gja7AFu7GipjU6BBi4lqgehQR08Twqf YJU3m0GArzt7KrazkYNKFa5RKS2nERMEzSJy31ny3905eyCpNEQIK1PuFvejS3P5Vf aUaEBhJ///L4g== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 18/24] staging:iio:cdc:ad7150: Add scale and offset to info_mask_shared_by_type Date: Sun, 14 Mar 2021 18:15:05 +0000 Message-Id: <20210314181511.531414-19-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-19-jic23@kernel.org --- 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 1a041396ff9e..39d70805d2a6 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 Mar 14 18:15: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: 12137877 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.2 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,URIBL_BLOCKED,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 8758CC432C3 for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7057B64EC3 for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233999AbhCNSST (ORCPT ); Sun, 14 Mar 2021 14:18:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:45276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234014AbhCNSSA (ORCPT ); Sun, 14 Mar 2021 14:18:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2371B64E77; Sun, 14 Mar 2021 18:17:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745880; bh=diLHehv8Mv2+cM2498jtDHOuWokJ4UKt+sDnQoVha58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dIDHJxo99rCv9Hm59nw/kdeEoUp8y3s513r6fFtTYZ1AKkY6y3BWLqR1p8CglWWJk foLg3a3StRaul4z/uXqOIIBMXxQp6UDUv+l3IEvkFbGUBvlAdGAJE1Cilxhy3y60q/ IQjM4c589P+WrWBCg9Wv0VZK4VjWoJ7LoFi9I7eSBbGKnAoRcS1itNp3BfxAC9Uwsk SImgxFWhwL/DX1MkD6SdK7CUTA4m1EFmzq+u3yOa0cG8QjcjizBo7mV6dPxwYE21Lj 202Q5M8gHqf9yanesz9fpA5eQs/qbc5KEs4aApSHl1wEz4S5MaRet+0zW4NNrBEbk3 lYYbbQiK8KyKQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 19/24] staging:iio:cdc:ad7150: Really basic regulator support. Date: Sun, 14 Mar 2021 18:15:06 +0000 Message-Id: <20210314181511.531414-20-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-20-jic23@kernel.org --- 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 39d70805d2a6..30abfacda074 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 Mar 14 18:15: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: 12137891 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.2 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,URIBL_BLOCKED,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 D15A2C433E0 for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB11D64EC6 for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234111AbhCNSSU (ORCPT ); Sun, 14 Mar 2021 14:18:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:45298 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234015AbhCNSSC (ORCPT ); Sun, 14 Mar 2021 14:18:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 04A2D64EC4; Sun, 14 Mar 2021 18:18:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745882; bh=99z4MoK2Ks8VbYq0nWMzO2heDTN4y0i1IqoIFe+ejJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DpQmXLJWi/WFreSFzoM1iBoLcBPDdGjR8enBVFKZR8E4sXFe81dbrq0idL8DJ31Bt hWBKPbynAI3ax0eX8uIaUlXUGXQbr4ZdaQGWg8VH11UaF0T9YFJR/hYj2OD8Y+/tzp AYqZ+ATAI9/Ff+du0dZh9LRqoBwFzYpTNIMGHfnEVyQHvfyYGDfOYTu0CrxFLKwKd3 xEuhVTMljeSe5uPwLsKVAIVzLhH0MJEx4y65OgPHVZirqwOiQJSW3AWSwfsAuIGtad GO4kUYWcJYtaM42INFS/OW77jH3+MfYXR/x7Lp/jsbxQYdTuRYfW52IxboYhtTgQvn 6AliW+AmrGdlQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron Subject: [PATCH v2 20/24] staging:iio:cdc:ad7150: Add of_match_table Date: Sun, 14 Mar 2021 18:15:07 +0000 Message-Id: <20210314181511.531414-21-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Link: https://lore.kernel.org/r/20210207154623.433442-21-jic23@kernel.org Reviewed-by: Alexandru Ardelean --- 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 30abfacda074..0afad49bcddc 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 Mar 14 18:15: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: 12137889 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.2 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,URIBL_BLOCKED,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 0B730C43619 for ; Sun, 14 Mar 2021 18:18:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F06CA64E7A for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234046AbhCNSSV (ORCPT ); Sun, 14 Mar 2021 14:18:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:45306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234033AbhCNSSF (ORCPT ); Sun, 14 Mar 2021 14:18:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BBCA964EC6; Sun, 14 Mar 2021 18:18:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745884; bh=3PT22OLX3s76KG/CyNotJU5m2kHns0IWrKbE2893HgQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L6bA6WpR4CBukupf9VcADOP+y6VcLG5NjLfuc6xOdmzvJQhy1Vr2fa9iQxcDuuuef RkDD3P80f5bEDDTDHH8Azaty6msACuhH3wWxsHRoD5n1LLHdD7VV74gwe1AOKhvjZb TMZiIcHKsqYf4mP3ruX9xNXMQELf6Y/GJw/kKa3USHG7FVMa+YgEcZHzsmCNVa1iSZ DHRK2ovjhs+vgfNBFBvOOYY9c6BIIZaGSUe2PW+BRG6Weyror7G+UCqGkgxITHImvr 5YJptVQy9/R0QEOWKUbLtnLZqnmqYURqPX/HC5cUZVDV7w7FtJAHNR6UTUC10ehKhz PeP44cIRfZ/qA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron Subject: [PATCH v2 21/24] iio:Documentation:ABI Add missing elements as used by the adi,ad7150 Date: Sun, 14 Mar 2021 18:15:08 +0000 Message-Id: <20210314181511.531414-22-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Link: https://lore.kernel.org/r/20210207154623.433442-23-jic23@kernel.org Reviewed-by: Alexandru Ardelean --- 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 affd4ce871d7..32d26c118141 100644 --- a/Documentation/ABI/testing/sysfs-bus-iio +++ b/Documentation/ABI/testing/sysfs-bus-iio @@ -371,6 +371,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: @@ -702,6 +703,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: @@ -779,6 +782,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 @@ -819,6 +848,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 Mar 14 18:15: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: 12137887 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.2 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,URIBL_BLOCKED,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 BC5B6C4321A for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9AC1A64EC3 for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234015AbhCNSSU (ORCPT ); Sun, 14 Mar 2021 14:18:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:45324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234046AbhCNSSG (ORCPT ); Sun, 14 Mar 2021 14:18:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7A71B64E31; Sun, 14 Mar 2021 18:18:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745886; bh=tBFFcoLPW9gF6RHgcVOsan/jaW0Ukp1GHSb048G1YEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B4C+8LMN0C5nlup6TVTqVdkqc+J++pHp62Bgz+NXNoi0z5GfIqN06EsWzVyye3eCy 1TmmdJzaBaAt5IaJK/6JfJ1xJLmPhrheQlWTdAHabBzcJxQIGOGGV+9SuI6oQ+Zscs DClhypHiTMyQJMIqTq9lUJBn5k3D/zuL0Mg7/LGPV/o6TMoZZf2vOVhFhftlIzc4yz dVyOpnvpcDp2VrNp2Mn3nAjratH1XNrGKlCby673683IsES/psEhmAcfP66POBzMJC YcMnupWWjP0G1l8OTt5g+QD6aD09o+77SHEKZDOcFn6R7hK4LKoYr/K6yOBTKn3YoA Qaa0Zg5cAEp+g== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 22/24] staging:iio:cdc:ad7150: Add copyright notice given substantial changes. Date: Sun, 14 Mar 2021 18:15:09 +0000 Message-Id: <20210314181511.531414-23-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-24-jic23@kernel.org --- 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 0afad49bcddc..b6d2c02fa39d 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 Mar 14 18:15: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: 12137885 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.2 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,URIBL_BLOCKED,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 F3513C433DB for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAE7864EC3 for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234033AbhCNSSV (ORCPT ); Sun, 14 Mar 2021 14:18:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:45340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234060AbhCNSSI (ORCPT ); Sun, 14 Mar 2021 14:18:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8417164EE2; Sun, 14 Mar 2021 18:18:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745888; bh=ivoStxHayDObgJdCDz7yp1aoi+PiXjUWhK3ZgLGEj70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ovP46vG6dvjKP3OAJEDhFzu5gSeyKUXa74zwQ0z3wrLK6x/ab+aeZ6HdRsP7JTbnS +XHvs6ip0oJL7OxzjBAdi0B4Jk78Nsy4cuQBQxmiff7QRc/iE6YOfjVPCboxpWuYi7 WrsgE3cV246Ve5SM1tQqeYWr/V7IQ/NzS9vgpIUTy8qZm8HPZHS7hPQkFrPzr9HSCm iJrR60t0KyMPiTfyGsD7GicVrzs/HgFmBXq12cOlMuIyuMy+r3K8vZeY7Z7J8PzILG +ygobOURNnvUnEt1Rd+wcSh9lZhRSwbqLgYpLvxd0aNPd1A9f3sEhLxZU4GJa9+LPI x397UEpP2/eVA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , devicetree@vger.kernel.org Subject: [PATCH v2 23/24] dt-bindings:iio:cdc:adi,ad7150 binding doc Date: Sun, 14 Mar 2021 18:15:10 +0000 Message-Id: <20210314181511.531414-24-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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) Whilst it is clearly necessary to provide power to the part, we don't need to know the voltage or anything so if it is always on, there should be no need to have it specified in the binding. Signed-off-by: Jonathan Cameron Cc: Robh+dt@kernel.org Cc: devicetree@vger.kernel.org Link: https://lore.kernel.org/r/20210207154623.433442-22-jic23@kernel.org Reviewed-by: Rob Herring --- .../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 Mar 14 18:15: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: 12137893 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.2 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,URIBL_BLOCKED,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 DD695C43603 for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB10864E7A for ; Sun, 14 Mar 2021 18:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234060AbhCNSSW (ORCPT ); Sun, 14 Mar 2021 14:18:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:45354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234064AbhCNSSK (ORCPT ); Sun, 14 Mar 2021 14:18:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D294664EC3; Sun, 14 Mar 2021 18:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615745890; bh=PhnCXvYhqNkohmltrvxMKK4O9hZWhJEeOwPQwgHk604=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g1bcTz4zBxsUqO2JKcnFKZ8SxFWjhw1pua3rumiuUHTpz5OWs6KXZG3vgTcnV0Ueq K3ujXfGkZYouCBacGxvFLDZaCDQTG+8sWUPoaVtEv9IMh9EYawAfjwX/R5PNLqyoIR 1wfs5k+94J9bxgNCMb62X8ttv9suFf8aAQr720ltiAtVYa1a89147FFOa0LAbcPiVH 4IKLCGZ3kO7gwh0s7Bzzcg7l4dIkvHVvVT7+mv2aqc2HtcC8X98J+KEY+zWkpxyd/B n/u3PstFDnQzGMG4aZCVpVSCs9P9Mke4G7/+D64G1Ij6HG7lDH6yGpWrgNT/ZDUGj/ bPkg9WBomwHww== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Lars-Peter Clausen , Michael Hennerich , Alexandru Ardelean , Robh+dt@kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v2 24/24] iio:cdc:ad7150: Move driver out of staging. Date: Sun, 14 Mar 2021 18:15:11 +0000 Message-Id: <20210314181511.531414-25-jic23@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314181511.531414-1-jic23@kernel.org> References: <20210314181511.531414-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 Reviewed-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210207154623.433442-25-jic23@kernel.org --- drivers/iio/Kconfig | 1 + drivers/iio/Makefile | 1 + drivers/iio/cdc/Kconfig | 17 + drivers/iio/cdc/Makefile | 6 + drivers/iio/cdc/ad7150.c | 678 +++++++++++++++++++++++++++++++ drivers/staging/iio/cdc/Kconfig | 10 - drivers/staging/iio/cdc/Makefile | 3 +- drivers/staging/iio/cdc/ad7150.c | 678 ------------------------------- 8 files changed, 704 insertions(+), 690 deletions(-) diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig index b35e0c33b5e2..2334ad249b46 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 2561325aaa74..65e39bd4f934 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/iio/cdc/ad7150.c b/drivers/iio/cdc/ad7150.c new file mode 100644 index 000000000000..b6d2c02fa39d --- /dev/null +++ b/drivers/iio/cdc/ad7150.c @@ -0,0 +1,678 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * AD7150 capacitive sensor driver supporting AD7150/1/6 + * + * Copyright 2010-2011 Analog Devices Inc. + * Copyright 2021 Jonathan Cameron + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#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, + AD7151, +}; + +/** + * struct ad7150_chip_info - instance specific chip data + * @client: i2c client for this device + * @threshold: thresholds for simple capacitance value events + * @thresh_sensitivity: threshold for simple capacitance offset + * 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. 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 + * @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; + u16 threshold[2][2]; + u8 thresh_sensitivity[2][2]; + u8 thresh_timeout[2][2]; + struct mutex state_lock; + int interrupts[2]; + bool int_enabled[2]; + enum iio_event_type type; + enum iio_event_direction dir; +}; + +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, + 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, + struct iio_chan_spec const *chan, + int *val, + int *val2, + long mask) +{ + struct ad7150_chip_info *chip = iio_priv(indio_dev); + int channel = chan->channel; + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = i2c_smbus_read_word_swapped(chip->client, + ad7150_addresses[channel][0]); + if (ret < 0) + return ret; + *val = ret >> 4; + + return IIO_VAL_INT; + case IIO_CHAN_INFO_AVERAGE_RAW: + ret = i2c_smbus_read_word_swapped(chip->client, + ad7150_addresses[channel][1]); + if (ret < 0) + 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 */ + *val = 100; + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static int ad7150_read_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir) +{ + struct ad7150_chip_info *chip = iio_priv(indio_dev); + u8 threshtype; + bool thrfixed; + int ret; + + ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG_REG); + if (ret < 0) + return ret; + + threshtype = FIELD_GET(AD7150_CFG_THRESHTYPE_MSK, ret); + + /*check if threshold mode is fixed or adaptive*/ + thrfixed = FIELD_GET(AD7150_CFG_FIX, ret); + + switch (type) { + case IIO_EV_TYPE_THRESH_ADAPTIVE: + if (dir == IIO_EV_DIR_RISING) + 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 == AD7150_CFG_TT_POS); + return thrfixed && (threshtype == AD7150_CFG_TT_NEG); + default: + break; + } + return -EINVAL; +} + +/* 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, + enum iio_event_direction dir) +{ + struct ad7150_chip_info *chip = iio_priv(indio_dev); + int rising = (dir == IIO_EV_DIR_RISING); + + /* Only update value live, if parameter is in use */ + if ((type != chip->type) || (dir != chip->dir)) + return 0; + + switch (type) { + /* Note completely different from the adaptive versions */ + 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: { + 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; + + /* + * 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); + } + default: + return -EINVAL; + } +} + +static int ad7150_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, int state) +{ + struct ad7150_chip_info *chip = iio_priv(indio_dev); + int ret; + + /* + * 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); + if ((type != chip->type) || (dir != chip->dir)) { + int rising = (dir == IIO_EV_DIR_RISING); + u8 thresh_type, cfg, fixed; + + /* + * 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]); + + ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG_REG); + if (ret < 0) + goto error_ret; + + cfg = ret & ~(AD7150_CFG_THRESHTYPE_MSK | AD7150_CFG_FIX); + + if (type == IIO_EV_TYPE_THRESH_ADAPTIVE) + fixed = 0; + else + fixed = 1; + + if (rising) + thresh_type = AD7150_CFG_TT_POS; + else + thresh_type = AD7150_CFG_TT_NEG; + + cfg |= FIELD_PREP(AD7150_CFG_FIX, fixed) | + FIELD_PREP(AD7150_CFG_THRESHTYPE_MSK, thresh_type); + + ret = i2c_smbus_write_byte_data(chip->client, AD7150_CFG_REG, + 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; + } + +error_ret: + mutex_unlock(&chip->state_lock); + + return ret; +} + +static int ad7150_read_event_value(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int *val, int *val2) +{ + struct ad7150_chip_info *chip = iio_priv(indio_dev); + int rising = (dir == IIO_EV_DIR_RISING); + + /* Complex register sharing going on here */ + 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; + } +} + +static int ad7150_write_event_value(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int val, int val2) +{ + int ret; + struct ad7150_chip_info *chip = iio_priv(indio_dev); + int rising = (dir == IIO_EV_DIR_RISING); + + mutex_lock(&chip->state_lock); + 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_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; + } + + /* write back if active */ + ret = ad7150_write_event_params(indio_dev, chan->channel, type, dir); + +error_ret: + mutex_unlock(&chip->state_lock); + return ret; +} + +static const struct iio_event_spec ad7150_events[] = { + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_RISING, + .mask_separate = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_ENABLE), + }, { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_FALLING, + .mask_separate = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_ENABLE), + }, { + .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_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_TIMEOUT), + }, +}; + +#define AD7150_CAPACITANCE_CHAN(_chan) { \ + .type = IIO_CAPACITANCE, \ + .indexed = 1, \ + .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), \ + } + +#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), \ + .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),\ + } + +static const struct iio_chan_spec ad7150_channels[] = { + AD7150_CAPACITANCE_CHAN(0), + 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(void *private, u8 status_mask, + int channel) +{ + struct iio_dev *indio_dev = private; + struct ad7150_chip_info *chip = iio_priv(indio_dev); + s64 timestamp = iio_get_time_ns(indio_dev); + int int_status; + + int_status = i2c_smbus_read_byte_data(chip->client, AD7150_STATUS_REG); + if (int_status < 0) + return IRQ_HANDLED; + + /* + * 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]"); + +static struct attribute *ad7150_event_attributes[] = { + &iio_const_attr_in_capacitance_thresh_adaptive_timeout_available + .dev_attr.attr, + NULL, +}; + +static const struct attribute_group ad7150_event_attribute_group = { + .attrs = ad7150_event_attributes, + .name = "events", +}; + +static const struct iio_info ad7150_info = { + .event_attrs = &ad7150_event_attribute_group, + .read_raw = &ad7150_read_raw, + .read_event_config = &ad7150_read_event_config, + .write_event_config = &ad7150_write_event_config, + .read_event_value = &ad7150_read_event_value, + .write_event_value = &ad7150_write_event_value, +}; + +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)); + if (!indio_dev) + return -ENOMEM; + + chip = iio_priv(indio_dev); + mutex_init(&chip->state_lock); + chip->client = client; + + indio_dev->name = id->name; + + 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]; + 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; + indio_dev->num_channels = ARRAY_SIZE(ad7151_channels); + break; + default: + return -EINVAL; + } + + } 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; + } + } + + return devm_iio_device_register(indio_dev->dev.parent, indio_dev); +} + +static const struct i2c_device_id ad7150_id[] = { + { "ad7150", AD7150 }, + { "ad7151", AD7151 }, + { "ad7156", AD7150 }, + {} +}; + +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, +}; +module_i2c_driver(ad7150_driver); + +MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); +MODULE_DESCRIPTION("Analog Devices AD7150/1/6 capacitive sensor driver"); +MODULE_LICENSE("GPL v2"); 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 diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c deleted file mode 100644 index b6d2c02fa39d..000000000000 --- a/drivers/staging/iio/cdc/ad7150.c +++ /dev/null @@ -1,678 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * AD7150 capacitive sensor driver supporting AD7150/1/6 - * - * Copyright 2010-2011 Analog Devices Inc. - * Copyright 2021 Jonathan Cameron - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#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, - AD7151, -}; - -/** - * struct ad7150_chip_info - instance specific chip data - * @client: i2c client for this device - * @threshold: thresholds for simple capacitance value events - * @thresh_sensitivity: threshold for simple capacitance offset - * 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. 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 - * @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; - u16 threshold[2][2]; - u8 thresh_sensitivity[2][2]; - u8 thresh_timeout[2][2]; - struct mutex state_lock; - int interrupts[2]; - bool int_enabled[2]; - enum iio_event_type type; - enum iio_event_direction dir; -}; - -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, - 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, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long mask) -{ - struct ad7150_chip_info *chip = iio_priv(indio_dev); - int channel = chan->channel; - int ret; - - switch (mask) { - case IIO_CHAN_INFO_RAW: - ret = i2c_smbus_read_word_swapped(chip->client, - ad7150_addresses[channel][0]); - if (ret < 0) - return ret; - *val = ret >> 4; - - return IIO_VAL_INT; - case IIO_CHAN_INFO_AVERAGE_RAW: - ret = i2c_smbus_read_word_swapped(chip->client, - ad7150_addresses[channel][1]); - if (ret < 0) - 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 */ - *val = 100; - return IIO_VAL_INT; - default: - return -EINVAL; - } -} - -static int ad7150_read_event_config(struct iio_dev *indio_dev, - const struct iio_chan_spec *chan, - enum iio_event_type type, - enum iio_event_direction dir) -{ - struct ad7150_chip_info *chip = iio_priv(indio_dev); - u8 threshtype; - bool thrfixed; - int ret; - - ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG_REG); - if (ret < 0) - return ret; - - threshtype = FIELD_GET(AD7150_CFG_THRESHTYPE_MSK, ret); - - /*check if threshold mode is fixed or adaptive*/ - thrfixed = FIELD_GET(AD7150_CFG_FIX, ret); - - switch (type) { - case IIO_EV_TYPE_THRESH_ADAPTIVE: - if (dir == IIO_EV_DIR_RISING) - 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 == AD7150_CFG_TT_POS); - return thrfixed && (threshtype == AD7150_CFG_TT_NEG); - default: - break; - } - return -EINVAL; -} - -/* 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, - enum iio_event_direction dir) -{ - struct ad7150_chip_info *chip = iio_priv(indio_dev); - int rising = (dir == IIO_EV_DIR_RISING); - - /* Only update value live, if parameter is in use */ - if ((type != chip->type) || (dir != chip->dir)) - return 0; - - switch (type) { - /* Note completely different from the adaptive versions */ - 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: { - 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; - - /* - * 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); - } - default: - return -EINVAL; - } -} - -static int ad7150_write_event_config(struct iio_dev *indio_dev, - const struct iio_chan_spec *chan, - enum iio_event_type type, - enum iio_event_direction dir, int state) -{ - struct ad7150_chip_info *chip = iio_priv(indio_dev); - int ret; - - /* - * 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); - if ((type != chip->type) || (dir != chip->dir)) { - int rising = (dir == IIO_EV_DIR_RISING); - u8 thresh_type, cfg, fixed; - - /* - * 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]); - - ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG_REG); - if (ret < 0) - goto error_ret; - - cfg = ret & ~(AD7150_CFG_THRESHTYPE_MSK | AD7150_CFG_FIX); - - if (type == IIO_EV_TYPE_THRESH_ADAPTIVE) - fixed = 0; - else - fixed = 1; - - if (rising) - thresh_type = AD7150_CFG_TT_POS; - else - thresh_type = AD7150_CFG_TT_NEG; - - cfg |= FIELD_PREP(AD7150_CFG_FIX, fixed) | - FIELD_PREP(AD7150_CFG_THRESHTYPE_MSK, thresh_type); - - ret = i2c_smbus_write_byte_data(chip->client, AD7150_CFG_REG, - 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; - } - -error_ret: - mutex_unlock(&chip->state_lock); - - return ret; -} - -static int ad7150_read_event_value(struct iio_dev *indio_dev, - const struct iio_chan_spec *chan, - enum iio_event_type type, - enum iio_event_direction dir, - enum iio_event_info info, - int *val, int *val2) -{ - struct ad7150_chip_info *chip = iio_priv(indio_dev); - int rising = (dir == IIO_EV_DIR_RISING); - - /* Complex register sharing going on here */ - 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; - } -} - -static int ad7150_write_event_value(struct iio_dev *indio_dev, - const struct iio_chan_spec *chan, - enum iio_event_type type, - enum iio_event_direction dir, - enum iio_event_info info, - int val, int val2) -{ - int ret; - struct ad7150_chip_info *chip = iio_priv(indio_dev); - int rising = (dir == IIO_EV_DIR_RISING); - - mutex_lock(&chip->state_lock); - 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_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; - } - - /* write back if active */ - ret = ad7150_write_event_params(indio_dev, chan->channel, type, dir); - -error_ret: - mutex_unlock(&chip->state_lock); - return ret; -} - -static const struct iio_event_spec ad7150_events[] = { - { - .type = IIO_EV_TYPE_THRESH, - .dir = IIO_EV_DIR_RISING, - .mask_separate = BIT(IIO_EV_INFO_VALUE) | - BIT(IIO_EV_INFO_ENABLE), - }, { - .type = IIO_EV_TYPE_THRESH, - .dir = IIO_EV_DIR_FALLING, - .mask_separate = BIT(IIO_EV_INFO_VALUE) | - BIT(IIO_EV_INFO_ENABLE), - }, { - .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_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_TIMEOUT), - }, -}; - -#define AD7150_CAPACITANCE_CHAN(_chan) { \ - .type = IIO_CAPACITANCE, \ - .indexed = 1, \ - .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), \ - } - -#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), \ - .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),\ - } - -static const struct iio_chan_spec ad7150_channels[] = { - AD7150_CAPACITANCE_CHAN(0), - 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(void *private, u8 status_mask, - int channel) -{ - struct iio_dev *indio_dev = private; - struct ad7150_chip_info *chip = iio_priv(indio_dev); - s64 timestamp = iio_get_time_ns(indio_dev); - int int_status; - - int_status = i2c_smbus_read_byte_data(chip->client, AD7150_STATUS_REG); - if (int_status < 0) - return IRQ_HANDLED; - - /* - * 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]"); - -static struct attribute *ad7150_event_attributes[] = { - &iio_const_attr_in_capacitance_thresh_adaptive_timeout_available - .dev_attr.attr, - NULL, -}; - -static const struct attribute_group ad7150_event_attribute_group = { - .attrs = ad7150_event_attributes, - .name = "events", -}; - -static const struct iio_info ad7150_info = { - .event_attrs = &ad7150_event_attribute_group, - .read_raw = &ad7150_read_raw, - .read_event_config = &ad7150_read_event_config, - .write_event_config = &ad7150_write_event_config, - .read_event_value = &ad7150_read_event_value, - .write_event_value = &ad7150_write_event_value, -}; - -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)); - if (!indio_dev) - return -ENOMEM; - - chip = iio_priv(indio_dev); - mutex_init(&chip->state_lock); - chip->client = client; - - indio_dev->name = id->name; - - 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]; - 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; - indio_dev->num_channels = ARRAY_SIZE(ad7151_channels); - break; - default: - return -EINVAL; - } - - } 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; - } - } - - return devm_iio_device_register(indio_dev->dev.parent, indio_dev); -} - -static const struct i2c_device_id ad7150_id[] = { - { "ad7150", AD7150 }, - { "ad7151", AD7151 }, - { "ad7156", AD7150 }, - {} -}; - -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, -}; -module_i2c_driver(ad7150_driver); - -MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); -MODULE_DESCRIPTION("Analog Devices AD7150/1/6 capacitive sensor driver"); -MODULE_LICENSE("GPL v2");