From patchwork Wed Apr 28 08:22:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Nyekjaer X-Patchwork-Id: 428707 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=-15.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,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 7016AC43460 for ; Wed, 28 Apr 2021 08:22:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3ABF06141E for ; Wed, 28 Apr 2021 08:22:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237063AbhD1IXK (ORCPT ); Wed, 28 Apr 2021 04:23:10 -0400 Received: from first.geanix.com ([116.203.34.67]:54892 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237049AbhD1IXK (ORCPT ); Wed, 28 Apr 2021 04:23:10 -0400 Received: from zen.. (unknown [185.17.218.86]) by first.geanix.com (Postfix) with ESMTPSA id C9DA4466247; Wed, 28 Apr 2021 08:22:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1619598144; bh=yxyUaE3usL1VvpfSS4eG3SS+uBcOJ5IHRl4PETO1cVY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ACXZz79MoaN8kOKBmLyC+p41voTeX8aBpKJoNtx/QWZYUPAZch4iwZtrTGgtyoyqP ZPgVG9O4VkqASuZROIRrqw8YxD5ai7nxSVGQ7E/qvQjf5XhDVQAV0KZM8HFQegYyh8 ur5IU1MooyF7K/fNPtd2FFjhMBAsnUDByWUJYPsSk4NvzyUJU0/d6B9Xr3sHQpuy6K Qcm7flchn5BrrunzVfpV+iUZLaMohvLG2gONph0qBlt16dtenH7TuNfpUtbVGLknpX 6wJtNZ6iECfLY7KiCCFz6hc7gDg7qF/XYpIMHcVe4e7tkO8vspAhSREY1BFTyAdTJT X9UFaAuz2EJvQ== From: Sean Nyekjaer To: jic23@kernel.org, linux-iio@vger.kernel.org, andy.shevchenko@gmail.com, lars@metafoo.de, Nuno.Sa@analog.com, robh+dt@kernel.org, devicetree@vger.kernel.org Cc: Sean Nyekjaer Subject: [RFC PATCH 2/4] iio: accel: fxls8962af: add interrupt support Date: Wed, 28 Apr 2021 10:22:01 +0200 Message-Id: <20210428082203.3587022-2-sean@geanix.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210428082203.3587022-1-sean@geanix.com> References: <20210428082203.3587022-1-sean@geanix.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Preparation commit for the next that adds hw buffered sampling Signed-off-by: Sean Nyekjaer --- This series depends on "iio: accel: add support for FXLS8962AF/FXLS8964AF accelerometers" drivers/iio/accel/fxls8962af-core.c | 116 ++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/drivers/iio/accel/fxls8962af-core.c b/drivers/iio/accel/fxls8962af-core.c index b47d81bebf43..848f3d68f5d4 100644 --- a/drivers/iio/accel/fxls8962af-core.c +++ b/drivers/iio/accel/fxls8962af-core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,10 @@ #define FXLS8962AF_SC3_WAKE_ODR_PREP(x) FIELD_PREP(FXLS8962AF_SC3_WAKE_ODR_MASK, x) #define FXLS8962AF_SC3_WAKE_ODR_GET(x) FIELD_GET(FXLS8962AF_SC3_WAKE_ODR_MASK, x) #define FXLS8962AF_SENS_CONFIG4 0x18 +#define FXLS8962AF_SC4_INT_PP_OD_MASK BIT(1) +#define FXLS8962AF_SC4_INT_PP_OD_PREP(x) FIELD_PREP(FXLS8962AF_SC4_INT_PP_OD_MASK, x) +#define FXLS8962AF_SC4_INT_POL_MASK BIT(0) +#define FXLS8962AF_SC4_INT_POL_PREP(x) FIELD_PREP(FXLS8962AF_SC4_INT_POL_MASK, x) #define FXLS8962AF_SENS_CONFIG5 0x19 #define FXLS8962AF_WAKE_IDLE_LSB 0x1b @@ -62,6 +67,9 @@ #define FXLS8962AF_INT_EN 0x20 #define FXLS8962AF_INT_PIN_SEL 0x21 +#define FXLS8962AF_INT_PIN_SEL_MASK GENMASK(7, 0) +#define FXLS8962AF_INT_PIN_SEL_INT1 0x00 +#define FXLS8962AF_INT_PIN_SEL_INT2 GENMASK(7, 0) #define FXLS8962AF_OFF_X 0x22 #define FXLS8962AF_OFF_Y 0x23 @@ -142,6 +150,11 @@ enum { fxls8962af_idx_ts, }; +enum fxls8962af_int_pin { + FXLS8962AF_PIN_INT1, + FXLS8962AF_PIN_INT2, +}; + static int fxls8962af_drdy(struct fxls8962af_data *data) { struct device *dev = regmap_get_device(data->regmap); @@ -559,6 +572,20 @@ static int fxls8962af_reset(struct fxls8962af_data *data) return ret; } +static irqreturn_t fxls8962af_interrupt(int irq, void *p) +{ + struct iio_dev *indio_dev = p; + struct fxls8962af_data *data = iio_priv(indio_dev); + unsigned int reg; + int ret; + + ret = regmap_read(data->regmap, FXLS8962AF_INT_STATUS, ®); + if (ret < 0) + return IRQ_NONE; + + return IRQ_NONE; +} + static void fxls8962af_regulator_disable(void *data_ptr) { struct fxls8962af_data *data = data_ptr; @@ -578,6 +605,89 @@ static void fxls8962af_pm_disable(void *dev_ptr) fxls8962af_standby(iio_priv(indio_dev)); } +static void fxls8962af_get_irq(struct device_node *of_node, enum fxls8962af_int_pin *pin) +{ + int irq; + + irq = of_irq_get_byname(of_node, "INT2"); + if (irq > 0) { + *pin = FXLS8962AF_PIN_INT2; + return; + } + + *pin = FXLS8962AF_PIN_INT1; +} + +static int fxls8962af_irq_setup(struct iio_dev *indio_dev, int irq) +{ + struct fxls8962af_data *data = iio_priv(indio_dev); + struct device *dev = regmap_get_device(data->regmap); + unsigned long irq_type; + bool irq_active_high; + enum fxls8962af_int_pin int_pin; + u8 int_pin_sel; + int ret; + + fxls8962af_get_irq(dev->of_node, &int_pin); + switch (int_pin) { + case FXLS8962AF_PIN_INT1: + int_pin_sel = FXLS8962AF_INT_PIN_SEL_INT1; + break; + case FXLS8962AF_PIN_INT2: + int_pin_sel = FXLS8962AF_INT_PIN_SEL_INT2; + break; + default: + dev_err(dev, "unsupported int pin selected\n"); + return -EINVAL; + } + + ret = regmap_update_bits(data->regmap, FXLS8962AF_INT_PIN_SEL, + FXLS8962AF_INT_PIN_SEL_MASK, + int_pin_sel); + if (ret) + return ret; + + irq_type = irqd_get_trigger_type(irq_get_irq_data(irq)); + + switch (irq_type) { + case IRQF_TRIGGER_HIGH: + case IRQF_TRIGGER_RISING: + irq_active_high = true; + break; + case IRQF_TRIGGER_LOW: + case IRQF_TRIGGER_FALLING: + irq_active_high = false; + break; + default: + dev_info(dev, "mode %lx unsupported\n", irq_type); + return -EINVAL; + } + + ret = regmap_update_bits(data->regmap, FXLS8962AF_SENS_CONFIG4, + FXLS8962AF_SC4_INT_POL_MASK, + FXLS8962AF_SC4_INT_POL_PREP(irq_active_high)); + if (ret < 0) + return ret; + + if (device_property_read_bool(dev, "drive-open-drain")) { + ret = regmap_update_bits(data->regmap, FXLS8962AF_SENS_CONFIG4, + FXLS8962AF_SC4_INT_PP_OD_MASK, + FXLS8962AF_SC4_INT_PP_OD_PREP(1)); + if (ret < 0) + return ret; + + irq_type |= IRQF_SHARED; + } + + ret = devm_request_threaded_irq(dev, + irq, + NULL, fxls8962af_interrupt, + irq_type | IRQF_ONESHOT, + indio_dev->name, indio_dev); + + return ret; +} + int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq) { struct fxls8962af_data *data; @@ -637,6 +747,12 @@ int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq) if (ret < 0) return ret; + if (irq) { + ret = fxls8962af_irq_setup(indio_dev, irq); + if (ret < 0) + return ret; + } + ret = pm_runtime_set_active(dev); if (ret < 0) return ret; From patchwork Wed Apr 28 08:22:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Nyekjaer X-Patchwork-Id: 428706 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44FC1C43462 for ; Wed, 28 Apr 2021 08:22:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 095CE6141F for ; Wed, 28 Apr 2021 08:22:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237162AbhD1IXN (ORCPT ); Wed, 28 Apr 2021 04:23:13 -0400 Received: from first.geanix.com ([116.203.34.67]:54930 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237049AbhD1IXN (ORCPT ); Wed, 28 Apr 2021 04:23:13 -0400 Received: from zen.. (unknown [185.17.218.86]) by first.geanix.com (Postfix) with ESMTPSA id 65CE946624B; Wed, 28 Apr 2021 08:22:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1619598146; bh=hOssXQoLqitONDdAWpjsYfSVVVTOP07FajOYAZWHqFU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fsWcUK+m4N4DZ4m/XI9yVqs92xfHiiWNlSgDezEFZeNu5MHWpDg3LRCQCTLwxS7A9 HG65NA9YE+iS3JbLSXeAsTvSqrEnMH8+tvyay+yJ9yUHcC+LMsfaHrwRo6Xnz8hDnK tktBzeTJu0Nw37N83RehoQP7ZYzmOk7r++83FdNxEUheBBTYKOr7jHoYUXGRg+x7sq CPHWq/zM59dzVeeCqmXG/zMG/2DwjLIACMUmRYfArOvZxqlnT1G550Jnz3qHiQgLDh gmt2kMk50pU4YL0eWbnH3GHLA08d70pNGg1XRvoHpak50B5/xyIrz910lolVgJr2qT YBjQ4s8emvAJw== From: Sean Nyekjaer To: jic23@kernel.org, linux-iio@vger.kernel.org, andy.shevchenko@gmail.com, lars@metafoo.de, Nuno.Sa@analog.com, robh+dt@kernel.org, devicetree@vger.kernel.org Cc: Sean Nyekjaer Subject: [RFC PATCH 4/4] iio: accel: fxls8962af: fix errata bug E3 - I2C burst reads Date: Wed, 28 Apr 2021 10:22:03 +0200 Message-Id: <20210428082203.3587022-4-sean@geanix.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210428082203.3587022-1-sean@geanix.com> References: <20210428082203.3587022-1-sean@geanix.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org When flushing the hw fifo there is a bug in the I2C that prevents burst reads of more than one sample pair. Signed-off-by: Sean Nyekjaer --- This series depends on "iio: accel: add support for FXLS8962AF/FXLS8964AF accelerometers" drivers/iio/accel/fxls8962af-core.c | 27 +++++++++++++++++++++++---- drivers/iio/accel/fxls8962af-i2c.c | 2 +- drivers/iio/accel/fxls8962af-spi.c | 2 +- drivers/iio/accel/fxls8962af.h | 2 +- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/drivers/iio/accel/fxls8962af-core.c b/drivers/iio/accel/fxls8962af-core.c index 2bd5c6d76b63..fad9e756d313 100644 --- a/drivers/iio/accel/fxls8962af-core.c +++ b/drivers/iio/accel/fxls8962af-core.c @@ -149,6 +149,7 @@ struct fxls8962af_data { __le16 channels[3]; s64 ts __aligned(8); } scan; + bool i2c_device; int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */ struct iio_mount_matrix orientation; }; @@ -684,11 +685,27 @@ static int fxls8962af_fifo_transfer(struct fxls8962af_data *data, { struct device *dev = regmap_get_device(data->regmap); int sample_length = 3 * 2; - int ret; + int ret, i; int total_length = samples * sample_length; - ret = regmap_raw_read(data->regmap, FXLS8962AF_BUF_X_LSB, buffer, - total_length); + if (data->i2c_device) { + /* Due to errata bug: + * E3: FIFO burst read operation error using I2C interface + * We have to avoid burst reads on I2C.. + */ + for (i = 0; i < samples; i++) { + ret = regmap_raw_read(data->regmap, FXLS8962AF_BUF_X_LSB, + &buffer[i * sample_length], + sample_length); + if (ret < 0) + goto out; + } + } else { + ret = regmap_raw_read(data->regmap, FXLS8962AF_BUF_X_LSB, buffer, + total_length); + } + + out: if (ret < 0) dev_err(dev, "Error transferring data from fifo: %d\n", ret); @@ -899,7 +916,8 @@ static int fxls8962af_irq_setup(struct iio_dev *indio_dev, int irq) return ret; } -int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq) +int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq, + bool i2c_device) { struct fxls8962af_data *data; struct iio_dev *indio_dev; @@ -913,6 +931,7 @@ int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq) data = iio_priv(indio_dev); dev_set_drvdata(dev, indio_dev); data->regmap = regmap; + data->i2c_device = i2c_device; ret = iio_read_mount_matrix(dev, "mount-matrix", &data->orientation); if (ret) diff --git a/drivers/iio/accel/fxls8962af-i2c.c b/drivers/iio/accel/fxls8962af-i2c.c index cba12160a714..03bd7ef285d0 100644 --- a/drivers/iio/accel/fxls8962af-i2c.c +++ b/drivers/iio/accel/fxls8962af-i2c.c @@ -24,7 +24,7 @@ static int fxls8962af_probe(struct i2c_client *client) return PTR_ERR(regmap); } - return fxls8962af_core_probe(&client->dev, regmap, client->irq); + return fxls8962af_core_probe(&client->dev, regmap, client->irq, true); } static const struct i2c_device_id fxls8962af_id[] = { diff --git a/drivers/iio/accel/fxls8962af-spi.c b/drivers/iio/accel/fxls8962af-spi.c index cb971b76d135..77186220f6dc 100644 --- a/drivers/iio/accel/fxls8962af-spi.c +++ b/drivers/iio/accel/fxls8962af-spi.c @@ -24,7 +24,7 @@ static int fxls8962af_probe(struct spi_device *spi) return PTR_ERR(regmap); } - return fxls8962af_core_probe(&spi->dev, regmap, spi->irq); + return fxls8962af_core_probe(&spi->dev, regmap, spi->irq, false); } static const struct of_device_id fxls8962af_spi_of_match[] = { diff --git a/drivers/iio/accel/fxls8962af.h b/drivers/iio/accel/fxls8962af.h index b67572c3ef06..e428163926b7 100644 --- a/drivers/iio/accel/fxls8962af.h +++ b/drivers/iio/accel/fxls8962af.h @@ -13,7 +13,7 @@ enum { fxls8964af, }; -int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq); +int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq, bool i2c_device); int fxls8962af_core_remove(struct device *dev); extern const struct dev_pm_ops fxls8962af_pm_ops;