From patchwork Thu Sep 10 12:32:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishant Malpani X-Patchwork-Id: 11769441 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4605F59D for ; Thu, 10 Sep 2020 21:42:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FC79221F0 for ; Thu, 10 Sep 2020 21:42:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Sa07GR4U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730423AbgIJMi5 (ORCPT ); Thu, 10 Sep 2020 08:38:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730631AbgIJMcz (ORCPT ); Thu, 10 Sep 2020 08:32:55 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A702C061573; Thu, 10 Sep 2020 05:32:25 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id u3so2963929pjr.3; Thu, 10 Sep 2020 05:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lrt2Zo0I7V3qw8iOGxULBlBEn4cKaIZWUdf+NM+cwwI=; b=Sa07GR4U8PmycSTRVlQlKdM9ZT4+Z8sDIuDG5pGA0UmWMhzIYrNyIy5Ma02ToFIy4Q Y1JcBvQRg+UJU0JoCl9JrLYD0swB2PB3hjQ6VAK8PJ5enuCFN5sFVZKDplsJa+eH2aP4 eG20r5s2nfDdnxa1d2f2cvE24NniqAZexkuS3nZ4kUhrA0TS1/KBvmLr4/bkbUQu4kq2 2wulPQhYJ6FJ0idPGZoBPj5jtaUYM0QOm+n/q29ZTWy+c4Fn63FUJpj4Rm3hDPZJ9C+f ppfg6lPzD79bD41NzK9l0qFE7TGrRC3H+FNi4gPSt9JKG+0FiuArqgCgBV2uzHv/f5CG tb4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lrt2Zo0I7V3qw8iOGxULBlBEn4cKaIZWUdf+NM+cwwI=; b=SPJMZmAF+64PwxAYQd+4JFAo08uTflJ81S5oy/K/dCEbiVjCLx7zi0fCiHZwO4qGlE PqVkFk4s2al7FHSGxZGlpXNCA3Nsy/EgCWEaV9DxmpU8tzgfrn65Kr5avrSEI7ry0Nad xdWbt37mpvHefpsiQjA0BHwpfdQPTU4NCg65BXq4wW2XV43tYw1MmwSzUtOEEJ+TWtp7 CgxfRA2rX4v+ApfdJiSP1qSfprfDDIpqdBvVw/bNYDnUlMqumW+1JmETnq/Rj56+iiFD Wxgost3jYOL3+2RZm3fbSxqpHgFtyjf4ixnVkNlR9/XPN/05Juwul2Rn7BPy3Q18M921 YUIg== X-Gm-Message-State: AOAM532fpQL1fpdEgqIE7oIAdkxOqW1JHTh4b31POBi7ICSQhaE5anEy /jrVIhfI78yEp1HO0rcXKvo= X-Google-Smtp-Source: ABdhPJw6I+KooSh37nQCpjRHfmq62ZJbutI5QVxhjghyh1LzLiwJ/p7iAoVHLeB76LrB1BGiX0I3Vg== X-Received: by 2002:a17:902:b10a:: with SMTP id q10mr5354001plr.156.1599741144391; Thu, 10 Sep 2020 05:32:24 -0700 (PDT) Received: from nish-HP-Pavilion ([2409:4072:6218:54d7:9928:e984:12bb:783d]) by smtp.gmail.com with ESMTPSA id f4sm3056475pfa.125.2020.09.10.05.32.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 05:32:23 -0700 (PDT) From: Nishant Malpani To: jic23@kernel.org, robh+dt@kernel.org Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, andy.shevchenko@gmail.com, Nishant Malpani Subject: [PATCH v3 1/3] iio: gyro: adxrs290: Add triggered buffer support Date: Thu, 10 Sep 2020 18:02:15 +0530 Message-Id: <20200910123215.17074-1-nish.malpani25@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Provide a way for continuous data capture by setting up buffer support. The data ready signal exposed at the SYNC pin of the ADXRS290 is exploited as a hardware interrupt which triggers to fill the buffer. Triggered buffer setup was tested with both hardware trigger (DATA_RDY) and software triggers (sysfs-trig & hrtimer). Signed-off-by: Nishant Malpani --- Changes in v3: - issue a separate precursor patch for the devm resource unwinding hook - rename labels in the error-path - use dev_err_probe() (which handles deferred probing) only for calls which request h/w resources Changes in v2: - In adxrs290_set_mode(), move 'if' block outside the locked section - use break statement for error handling instead of goto labels in switch-case blocks - remove outer parentheses when conditional ternary operator is used - use dev_err_probe() saving a few lines of code - re-align 'buffer' variable name in 'struct adxrs290_state' - don't return errors in 'try_reenable' callback - use 'st->spi' inline in 'adxrs290_trigger_handler' - unnecessary to mention default 'shift' (= 0) in iio_chan_spec.scan_type - bring in consistent wrapping of parameters while staying under the advised 80 chars line limit --- drivers/iio/gyro/Kconfig | 2 + drivers/iio/gyro/adxrs290.c | 211 +++++++++++++++++++++++++++++++++--- 2 files changed, 199 insertions(+), 14 deletions(-) diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig index 024a34139875..5824f2edf975 100644 --- a/drivers/iio/gyro/Kconfig +++ b/drivers/iio/gyro/Kconfig @@ -44,6 +44,8 @@ config ADIS16260 config ADXRS290 tristate "Analog Devices ADXRS290 Dual-Axis MEMS Gyroscope SPI driver" depends on SPI + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER help Say yes here to build support for Analog Devices ADXRS290 programmable digital output gyroscope. diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c index 2864eb443957..41b1f995a143 100644 --- a/drivers/iio/gyro/adxrs290.c +++ b/drivers/iio/gyro/adxrs290.c @@ -13,8 +13,12 @@ #include #include +#include #include #include +#include +#include +#include #define ADXRS290_ADI_ID 0xAD #define ADXRS290_MEMS_ID 0x1D @@ -35,7 +39,9 @@ #define ADXRS290_READ BIT(7) #define ADXRS290_TSM BIT(0) #define ADXRS290_MEASUREMENT BIT(1) -#define ADXRS290_SYNC GENMASK(1, 0) +#define ADXRS290_DATA_RDY_OUT BIT(0) +#define ADXRS290_SYNC_MASK GENMASK(1, 0) +#define ADXRS290_SYNC(x) FIELD_PREP(ADXRS290_SYNC_MASK, x) #define ADXRS290_LPF_MASK GENMASK(2, 0) #define ADXRS290_LPF(x) FIELD_PREP(ADXRS290_LPF_MASK, x) #define ADXRS290_HPF_MASK GENMASK(7, 4) @@ -50,6 +56,13 @@ enum adxrs290_mode { ADXRS290_MODE_MEASUREMENT, }; +enum adxrs290_scan_index { + ADXRS290_IDX_X, + ADXRS290_IDX_Y, + ADXRS290_IDX_TEMP, + ADXRS290_IDX_TS, +}; + struct adxrs290_state { struct spi_device *spi; /* Serialize reads and their subsequent processing */ @@ -57,6 +70,12 @@ struct adxrs290_state { enum adxrs290_mode mode; unsigned int lpf_3db_freq_idx; unsigned int hpf_3db_freq_idx; + struct iio_trigger *dready_trig; + /* Ensure correct alignment of timestamp when present */ + struct { + s16 channels[3]; + s64 ts __aligned(8); + } buffer; }; /* @@ -270,24 +289,34 @@ static int adxrs290_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + switch (chan->type) { case IIO_ANGL_VEL: ret = adxrs290_get_rate_data(indio_dev, ADXRS290_READ_REG(chan->address), val); if (ret < 0) - return ret; + break; - return IIO_VAL_INT; + ret = IIO_VAL_INT; + break; case IIO_TEMP: ret = adxrs290_get_temp_data(indio_dev, val); if (ret < 0) - return ret; + break; - return IIO_VAL_INT; + ret = IIO_VAL_INT; + break; default: - return -EINVAL; + ret = -EINVAL; + break; } + + iio_device_release_direct_mode(indio_dev); + return ret; case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_ANGL_VEL: @@ -334,34 +363,52 @@ static int adxrs290_write_raw(struct iio_dev *indio_dev, long mask) { struct adxrs290_state *st = iio_priv(indio_dev); - int lpf_idx, hpf_idx; + int ret, lpf_idx, hpf_idx; + + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; switch (mask) { case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: lpf_idx = adxrs290_find_match(adxrs290_lpf_3db_freq_hz_table, ARRAY_SIZE(adxrs290_lpf_3db_freq_hz_table), val, val2); - if (lpf_idx < 0) - return -EINVAL; + if (lpf_idx < 0) { + ret = -EINVAL; + break; + } + /* caching the updated state of the low-pass filter */ st->lpf_3db_freq_idx = lpf_idx; /* retrieving the current state of the high-pass filter */ hpf_idx = st->hpf_3db_freq_idx; - return adxrs290_set_filter_freq(indio_dev, lpf_idx, hpf_idx); + ret = adxrs290_set_filter_freq(indio_dev, lpf_idx, hpf_idx); + break; + case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: hpf_idx = adxrs290_find_match(adxrs290_hpf_3db_freq_hz_table, ARRAY_SIZE(adxrs290_hpf_3db_freq_hz_table), val, val2); - if (hpf_idx < 0) - return -EINVAL; + if (hpf_idx < 0) { + ret = -EINVAL; + break; + } + /* caching the updated state of the high-pass filter */ st->hpf_3db_freq_idx = hpf_idx; /* retrieving the current state of the low-pass filter */ lpf_idx = st->lpf_3db_freq_idx; - return adxrs290_set_filter_freq(indio_dev, lpf_idx, hpf_idx); + ret = adxrs290_set_filter_freq(indio_dev, lpf_idx, hpf_idx); + break; + + default: + ret = -EINVAL; + break; } - return -EINVAL; + iio_device_release_direct_mode(indio_dev); + return ret; } static int adxrs290_read_avail(struct iio_dev *indio_dev, @@ -389,6 +436,72 @@ static int adxrs290_read_avail(struct iio_dev *indio_dev, } } +static int adxrs290_data_rdy_trigger_set_state(struct iio_trigger *trig, + bool state) +{ + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); + struct adxrs290_state *st = iio_priv(indio_dev); + int ret; + u8 val; + + val = state ? ADXRS290_SYNC(ADXRS290_DATA_RDY_OUT) : 0; + + ret = adxrs290_spi_write_reg(st->spi, ADXRS290_REG_DATA_RDY, val); + if (ret < 0) + dev_err(&st->spi->dev, "failed to start data rdy interrupt\n"); + + return ret; +} + +static int adxrs290_reset_trig(struct iio_trigger *trig) +{ + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); + int val; + + /* + * Data ready interrupt is reset after a read of the data registers. + * Here, we only read the 16b DATAY registers as that marks the end of + * a read of the data registers and initiates a reset for the interrupt + * line. + */ + adxrs290_get_rate_data(indio_dev, + ADXRS290_READ_REG(ADXRS290_REG_DATAY0), &val); + + return 0; +} + +static const struct iio_trigger_ops adxrs290_trigger_ops = { + .set_trigger_state = &adxrs290_data_rdy_trigger_set_state, + .validate_device = &iio_trigger_validate_own_device, + .try_reenable = &adxrs290_reset_trig, +}; + +static irqreturn_t adxrs290_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct adxrs290_state *st = iio_priv(indio_dev); + u8 tx = ADXRS290_READ_REG(ADXRS290_REG_DATAX0); + int ret; + + mutex_lock(&st->lock); + + /* exercise a bulk data capture starting from reg DATAX0... */ + ret = spi_write_then_read(st->spi, &tx, sizeof(tx), st->buffer.channels, + sizeof(st->buffer.channels)); + if (ret < 0) + goto out_unlock_notify; + + iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer, + pf->timestamp); + +out_unlock_notify: + mutex_unlock(&st->lock); + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + #define ADXRS290_ANGL_VEL_CHANNEL(reg, axis) { \ .type = IIO_ANGL_VEL, \ .address = reg, \ @@ -401,6 +514,13 @@ static int adxrs290_read_avail(struct iio_dev *indio_dev, .info_mask_shared_by_type_available = \ BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | \ BIT(IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY), \ + .scan_index = ADXRS290_IDX_##axis, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 16, \ + .storagebits = 16, \ + .endianness = IIO_LE, \ + }, \ } static const struct iio_chan_spec adxrs290_channels[] = { @@ -411,7 +531,20 @@ static const struct iio_chan_spec adxrs290_channels[] = { .address = ADXRS290_REG_TEMP0, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), + .scan_index = ADXRS290_IDX_TEMP, + .scan_type = { + .sign = 's', + .realbits = 12, + .storagebits = 16, + .endianness = IIO_LE, + }, }, + IIO_CHAN_SOFT_TIMESTAMP(ADXRS290_IDX_TS), +}; + +static const unsigned long adxrs290_avail_scan_masks[] = { + BIT(ADXRS290_IDX_X) | BIT(ADXRS290_IDX_Y) | BIT(ADXRS290_IDX_TEMP), + 0 }; static const struct iio_info adxrs290_info = { @@ -420,6 +553,44 @@ static const struct iio_info adxrs290_info = { .read_avail = &adxrs290_read_avail, }; +static int adxrs290_probe_trigger(struct iio_dev *indio_dev) +{ + struct adxrs290_state *st = iio_priv(indio_dev); + int ret; + + if (!st->spi->irq) { + dev_info(&st->spi->dev, "no irq, using polling\n"); + return 0; + } + + st->dready_trig = devm_iio_trigger_alloc(&st->spi->dev, "%s-dev%d", + indio_dev->name, + indio_dev->id); + if (!st->dready_trig) + return -ENOMEM; + + st->dready_trig->dev.parent = &st->spi->dev; + st->dready_trig->ops = &adxrs290_trigger_ops; + iio_trigger_set_drvdata(st->dready_trig, indio_dev); + + ret = devm_request_irq(&st->spi->dev, st->spi->irq, + &iio_trigger_generic_data_rdy_poll, + IRQF_ONESHOT, "adxrs290_irq", st->dready_trig); + if (ret < 0) + return dev_err_probe(&st->spi->dev, ret, + "request irq %d failed\n", st->spi->irq); + + ret = devm_iio_trigger_register(&st->spi->dev, st->dready_trig); + if (ret) { + dev_err(&st->spi->dev, "iio trigger register failed\n"); + return ret; + } + + indio_dev->trig = iio_trigger_get(st->dready_trig); + + return 0; +} + static int adxrs290_probe(struct spi_device *spi) { struct iio_dev *indio_dev; @@ -439,6 +610,7 @@ static int adxrs290_probe(struct spi_device *spi) indio_dev->channels = adxrs290_channels; indio_dev->num_channels = ARRAY_SIZE(adxrs290_channels); indio_dev->info = &adxrs290_info; + indio_dev->available_scan_masks = adxrs290_avail_scan_masks; mutex_init(&st->lock); @@ -478,6 +650,17 @@ static int adxrs290_probe(struct spi_device *spi) st->lpf_3db_freq_idx = val; st->hpf_3db_freq_idx = val2; + ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, + &iio_pollfunc_store_time, + &adxrs290_trigger_handler, NULL); + if (ret < 0) + return dev_err_probe(&spi->dev, ret, + "iio triggered buffer setup failed\n"); + + ret = adxrs290_probe_trigger(indio_dev); + if (ret < 0) + return ret; + return devm_iio_device_register(&spi->dev, indio_dev); } From patchwork Thu Sep 10 12:32:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishant Malpani X-Patchwork-Id: 11767759 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 64A2F92C for ; Thu, 10 Sep 2020 12:39:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4830B21D90 for ; Thu, 10 Sep 2020 12:39:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QQyE+kit" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730544AbgIJMjB (ORCPT ); Thu, 10 Sep 2020 08:39:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730720AbgIJMcz (ORCPT ); Thu, 10 Sep 2020 08:32:55 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4174EC061756; Thu, 10 Sep 2020 05:32:46 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id c196so4684704pfc.0; Thu, 10 Sep 2020 05:32:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mEwZSmSPM9tJPXbfj/hisKYRPYb4G1wKBGhUAXFVXQE=; b=QQyE+kittH/tfmJ8ZNi17jn05QZQZcXwMXVymiKtSy+2DeXb1jiT3escHBvEh6nBkR N88tlDY4zkfS37XNjX8SIuiq73jsc6YnrdrzA0t1dU2T2teWmUc2+DzpOA/8ZAtN5wNs +7b3EL7XVaNrhEX3l6z54aV0/P3PLQGCwEtcf3mdgUZJZ+1IH5g7aOTRY+80M6ykaEjE W9wHsMdf7Ii9vErVU1ctuZ7zBc33XwdDB9NDd93mll4W9W2Ayhlf03qiMEIiA3ilo89s z1wfC/PhdoTHEdGcuufJztn+lVo39fiNHxrCIK+IiuXNLL5FdM1D/saoqSFHIG8oh2Un /K+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mEwZSmSPM9tJPXbfj/hisKYRPYb4G1wKBGhUAXFVXQE=; b=E+cNJO1uin1vPr8ATnylU5fSGCTi9rVpWsAvV5c0GJ60IPMUrS6aVVBBkUNDKDj2MS 7v7x+F9NSAX6kbGgIoqIoeYPEmfiMF3vTIc5g5NSQllqvLejuveHW9IzXXEd2OIXlE+k bzEvsR/Vxc7jkQwEGdl09MlSTdaGKAdZ294SYDTfT+TjveFqRHHj08A0qSLEDwDem0N0 h/rcC7dErP3QG6Ndw/rRgv2WDqYrq++hw82fNashmL6Qd0pNhyPCmT/piJ5LJC7bhAOM 7xMtOYW4HOQIgGS78FKOZZPPy3KnAE/91iYREm1ABQAbM5UijXcCiBy+eo+wntq8VgmJ BrwQ== X-Gm-Message-State: AOAM530nJ5DLYMz4hjhfXh6JpBCCa274icD41BIx29RzvP0kAHy46iRo RRKLYgb/HikTOjzfRdXgVIBHSc1uFfQ= X-Google-Smtp-Source: ABdhPJx4LbkZbNn0hXoKo43LaWN99HPlceHJPG4X2zeKOzevSUZD1WXT6hmjCiUOacSfeY9fy+eduQ== X-Received: by 2002:a63:4d5b:: with SMTP id n27mr4212074pgl.360.1599741162699; Thu, 10 Sep 2020 05:32:42 -0700 (PDT) Received: from nish-HP-Pavilion ([2409:4072:6218:54d7:9928:e984:12bb:783d]) by smtp.gmail.com with ESMTPSA id c1sm5799309pfc.93.2020.09.10.05.32.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 05:32:41 -0700 (PDT) From: Nishant Malpani To: jic23@kernel.org, robh+dt@kernel.org Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, andy.shevchenko@gmail.com, Nishant Malpani Subject: [PATCH v3 2/3] dt-bindings: iio: gyro: adxrs290: Add interrupts support Date: Thu, 10 Sep 2020 18:02:36 +0530 Message-Id: <20200910123236.17141-1-nish.malpani25@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Include 'interrupts' property and provide a suitable example for using a GPIO interrupt line. Signed-off-by: Nishant Malpani --- Changes in v3: - remove gpio.h header since unused Changes in v2: - remove 'interrupts' property from the required properties list - rewrite commit message --- .../devicetree/bindings/iio/gyroscope/adi,adxrs290.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/gyroscope/adi,adxrs290.yaml b/Documentation/devicetree/bindings/iio/gyroscope/adi,adxrs290.yaml index 61adb2c2454b..662ec59ca0af 100644 --- a/Documentation/devicetree/bindings/iio/gyroscope/adi,adxrs290.yaml +++ b/Documentation/devicetree/bindings/iio/gyroscope/adi,adxrs290.yaml @@ -28,6 +28,9 @@ properties: spi-cpha: true + interrupts: + maxItems: 1 + required: - compatible - reg @@ -39,6 +42,7 @@ additionalProperties: false examples: - | + #include spi { #address-cells = <1>; #size-cells = <0>; @@ -48,6 +52,8 @@ examples: spi-max-frequency = <5000000>; spi-cpol; spi-cpha; + interrupt-parent = <&gpio>; + interrupts = <25 IRQ_TYPE_EDGE_RISING>; }; }; ... From patchwork Thu Sep 10 12:32:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishant Malpani X-Patchwork-Id: 11767757 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A118A13B1 for ; Thu, 10 Sep 2020 12:36:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F08B20BED for ; Thu, 10 Sep 2020 12:36:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qG/rKcK2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729935AbgIJMgY (ORCPT ); Thu, 10 Sep 2020 08:36:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730396AbgIJMdB (ORCPT ); Thu, 10 Sep 2020 08:33:01 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFA80C061757; Thu, 10 Sep 2020 05:33:00 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id d16so831768pll.13; Thu, 10 Sep 2020 05:33:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4mAC7AY2dom2okuDhz5TwwH+eN++c0Zg21VAJ30tmZE=; b=qG/rKcK2HhixjeHOwx22cnu5vsq8XLz5RXaPsgu9QDXQi0LEGNYwf6bpkI5tuOVfQT qL94/g9KbH0MlePhTboZv1bJUtR36YPqv+MbGfsqVXmu+Pc7gs527U0DLNOq2WYytdgI P3KsMw7cWHxNhbHzImQRJBSsk2vprNBqSXj/tC3ub/BKPPqhSgOxjhXzbseGFv15Jxlx LmmPekD31CngpQVRV1iRcLrwUXYE9y7kymgY5eNhL5o9G9grrXtPUj6862e9XZd7kBFP u/qtP2vXk/DHK7cOlm6L2z46IB1k2nCopfwArf4KK0oRAfF+B33VAl4wFMWfUYLcT/T9 vtSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4mAC7AY2dom2okuDhz5TwwH+eN++c0Zg21VAJ30tmZE=; b=IvznwsfCnS262FikdhG5KNk+Q6736DELg7yHjNIvE4zJotlmWroF6QF53JeB4qLR+h d1K7oxyXUfRuY/6/MuAVSJy1fzJVYj13fYYJxBK7fnG2YWJHYOWXB5Mwnzyue4u90ty1 dABEar+eU5fKNlx16LWfrlhouCk/LmDGSxkwZtdL7JWnEjiIS5SuD8fcEPDuupaAAPEj 5epe0uvU3YF5j3qKCC6iurzanCOZk/rU4zTwjKvHNEUwlFRACWzzT7+rmAx0NCr+yb2H +rXktMmw4mw8E1p0iTLjvYOXVRersRxN2TfhyeA1DceO2MA9j6DgY3YSY0wcr95A85dG seDA== X-Gm-Message-State: AOAM533YJuH6/eLHFqYsFT8sTBaMRuBnl9VloKNjIcXfSIzz7C7u365g BcYH4P6NIVJpNBuVReDmI14= X-Google-Smtp-Source: ABdhPJxLK5IOkPuZQSvSgkg8AkXwFKqrh/T7qtwK4UBm7gI5yfAXyN4l5FBr5fZALkKhZHOCS02vEg== X-Received: by 2002:a17:902:74c8:: with SMTP id f8mr5383439plt.78.1599741180451; Thu, 10 Sep 2020 05:33:00 -0700 (PDT) Received: from nish-HP-Pavilion ([2409:4072:6218:54d7:9928:e984:12bb:783d]) by smtp.gmail.com with ESMTPSA id j14sm5031485pgf.76.2020.09.10.05.32.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 05:32:59 -0700 (PDT) From: Nishant Malpani To: jic23@kernel.org, robh+dt@kernel.org Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, andy.shevchenko@gmail.com, Nishant Malpani Subject: [PATCH v3 3/3] iio: gyro: adxrs290: Add debugfs register access support Date: Thu, 10 Sep 2020 18:02:49 +0530 Message-Id: <20200910123249.17204-1-nish.malpani25@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Extend support to read/write byte data from/to the device using debugfs iio interface. Signed-off-by: Nishant Malpani --- Changes in v3: - refactor code based on Andy's suggestions No changes in v2 --- drivers/iio/gyro/adxrs290.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c index 41b1f995a143..ca6fc234076e 100644 --- a/drivers/iio/gyro/adxrs290.c +++ b/drivers/iio/gyro/adxrs290.c @@ -436,6 +436,31 @@ static int adxrs290_read_avail(struct iio_dev *indio_dev, } } +static int adxrs290_reg_access_rw(struct spi_device *spi, unsigned int reg, + unsigned int *readval) +{ + int ret; + + ret = spi_w8r8(spi, ADXRS290_READ_REG(reg)); + if (ret < 0) + return ret; + + *readval = ret; + + return 0; +} + +static int adxrs290_reg_access(struct iio_dev *indio_dev, unsigned int reg, + unsigned int writeval, unsigned int *readval) +{ + struct adxrs290_state *st = iio_priv(indio_dev); + + if (readval) + return adxrs290_reg_access_rw(st->spi, reg, readval); + else + return adxrs290_spi_write_reg(st->spi, reg, writeval); +} + static int adxrs290_data_rdy_trigger_set_state(struct iio_trigger *trig, bool state) { @@ -551,6 +576,7 @@ static const struct iio_info adxrs290_info = { .read_raw = &adxrs290_read_raw, .write_raw = &adxrs290_write_raw, .read_avail = &adxrs290_read_avail, + .debugfs_reg_access = &adxrs290_reg_access, }; static int adxrs290_probe_trigger(struct iio_dev *indio_dev)