From patchwork Mon Jan 14 03:56:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10761635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C664F6C5 for ; Mon, 14 Jan 2019 03:56:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF44F28A20 for ; Mon, 14 Jan 2019 03:56:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0EC628A48; Mon, 14 Jan 2019 03:56:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA9D428A20 for ; Mon, 14 Jan 2019 03:56:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726721AbfAND4l (ORCPT ); Sun, 13 Jan 2019 22:56:41 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:45707 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbfAND4k (ORCPT ); Sun, 13 Jan 2019 22:56:40 -0500 Received: by mail-pl1-f194.google.com with SMTP id a14so9490162plm.12 for ; Sun, 13 Jan 2019 19:56:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martingkelly-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+emAylfCxXB91cbBPVb9+jou3+Q2IsPc1dpIh7YBHNw=; b=nEbsLnS1DqY5CS1LxhtrxmD14ZyiXipQY3uKH/QZTX5o7NVAbb+MhS6gIAtVSYEWY1 X/LBBwJyPE+WBlfbpTUuUuGZ1xWLpv/Lu8L6E5g6m6bBgNZK7Edzekwjjml8O0dnOKIr 9oUR/Uux3XgaR1s+dsLCSVK7seowGNRQrp1ClOgv+tCQ76nJAdLXpDYE1E0BXuGLskNu A/Kd7YIAp1baZi6S4FsNTlPFvQZUcy8TTgtYU9KaU8E2DX9bwSXLbdp0MdFPE925scQm d/T0uWIdpkIhXPdX3DqEaDDb0J0TvvAm1TLKvp99JAnSAkq0x7xTZ2JKXosKvZpsfIhk LnlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+emAylfCxXB91cbBPVb9+jou3+Q2IsPc1dpIh7YBHNw=; b=YuodDPd2MBvO1SyaJbi0IAezZbAU4RDaU5QzxO8GffW9Kc/koI0WKDNKwHv/ZlNJo+ I+h4U7UAojOPXLGE4R5GL876sSnAa09mJVnn1dtgyC0X2uMydahwlkoDMi5P/Iv3rsDI fqxX/9PrWzHhTIHUUHhd8HREhWDLBypRE6a1+B0gHgpP1JWoSZs3cJw5WbVk3ASdNHRZ nRQY86NYJhlJ6JNgjx4utMzTVQj5+XpqayiHRYZyPH3ZLem2GMfn/m0NE1UeDYRdrwOq xsC4s3oz76LgAT+EpzuEvr70L4HbnJVcI8URRssPSQTirkWIkjwhDipA+zfeNFJSOdIv 7FlA== X-Gm-Message-State: AJcUukdSQaWYy2qHb3nHeO7VWCKCv1f+NoofhrAa3afiwiMiwg3eQTLl ykCLW4DjQLkvVm4KeQeVYVdsZ6t0+/k= X-Google-Smtp-Source: ALg8bN6w211JPg25hulx9VoNrG175EXFCOsR80bK+RhCR6b3VWzkenHqhhf2Yhpv8YlgosHIr4YJTw== X-Received: by 2002:a17:902:8d95:: with SMTP id v21mr23863417plo.162.1547438199790; Sun, 13 Jan 2019 19:56:39 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id l70sm93582741pgd.20.2019.01.13.19.56.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Jan 2019 19:56:39 -0800 (PST) From: Martin Kelly X-Google-Original-From: Martin Kelly , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Martin Kelly Subject: [PATCH 1/5] iio:bmi160: add SPDX identifiers Date: Sun, 13 Jan 2019 19:56:17 -0800 Message-Id: <20190114035621.5252-2-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190114035621.5252-1-martin@martingkelly.com> References: <20190114035621.5252-1-martin@martingkelly.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Kelly Add SPDX identifiers (GPL 2) for the BMI160 driver. bmi160.h had an identifier, but the other files did not. Signed-off-by: Martin Kelly --- drivers/iio/imu/bmi160/bmi160_core.c | 5 +---- drivers/iio/imu/bmi160/bmi160_i2c.c | 5 +---- drivers/iio/imu/bmi160/bmi160_spi.c | 4 +--- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c index b10330b0f93f..ce61026d84c3 100644 --- a/drivers/iio/imu/bmi160/bmi160_core.c +++ b/drivers/iio/imu/bmi160/bmi160_core.c @@ -1,12 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0 /* * BMI160 - Bosch IMU (accel, gyro plus external magnetometer) * * Copyright (c) 2016, Intel Corporation. * - * This file is subject to the terms and conditions of version 2 of - * the GNU General Public License. See the file COPYING in the main - * directory of this archive for more details. - * * IIO core driver for BMI160, with support for I2C/SPI busses * * TODO: magnetometer, interrupts, hardware FIFO diff --git a/drivers/iio/imu/bmi160/bmi160_i2c.c b/drivers/iio/imu/bmi160/bmi160_i2c.c index 5b1f7e6af651..e36f5e82d400 100644 --- a/drivers/iio/imu/bmi160/bmi160_i2c.c +++ b/drivers/iio/imu/bmi160/bmi160_i2c.c @@ -1,12 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0 /* * BMI160 - Bosch IMU, I2C bits * * Copyright (c) 2016, Intel Corporation. * - * This file is subject to the terms and conditions of version 2 of - * the GNU General Public License. See the file COPYING in the main - * directory of this archive for more details. - * * 7-bit I2C slave address is: * - 0x68 if SDO is pulled to GND * - 0x69 if SDO is pulled to VDDIO diff --git a/drivers/iio/imu/bmi160/bmi160_spi.c b/drivers/iio/imu/bmi160/bmi160_spi.c index e521ad14eeac..c19e3df35559 100644 --- a/drivers/iio/imu/bmi160/bmi160_spi.c +++ b/drivers/iio/imu/bmi160/bmi160_spi.c @@ -1,11 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0 /* * BMI160 - Bosch IMU, SPI bits * * Copyright (c) 2016, Intel Corporation. * - * This file is subject to the terms and conditions of version 2 of - * the GNU General Public License. See the file COPYING in the main - * directory of this archive for more details. */ #include #include From patchwork Mon Jan 14 03:56:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10761641 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8EC0714E5 for ; Mon, 14 Jan 2019 03:56:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E75228A20 for ; Mon, 14 Jan 2019 03:56:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7257D28A37; Mon, 14 Jan 2019 03:56:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB1C528A22 for ; Mon, 14 Jan 2019 03:56:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726723AbfAND4o (ORCPT ); Sun, 13 Jan 2019 22:56:44 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:45287 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbfAND4o (ORCPT ); Sun, 13 Jan 2019 22:56:44 -0500 Received: by mail-pf1-f194.google.com with SMTP id g62so9682661pfd.12 for ; Sun, 13 Jan 2019 19:56:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martingkelly-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=epvT2po3KSgWtqacDVe+UBB3Xy1nc9APf41E0KARoF0=; b=kxmnGyHZ03zz3lINDE6bYqn4oWwzm2BztPySCcajeZHwuAJdKr4TtrYHz1o/DBm+yg /35M+uYvlbK7yvRAYAlCXMTxdzANzTJFqbW7W8uPWBGuSo+SjQv9190rJeAkCl48q21N UPmLzg+6vPtZBdwOSU1gMXsJCK3btRy9qOADPyqdCAz9AcKbKP7BgUPg//TuK2HJApyp PQ+Lh6vS2BWbABHXI+Qu/b3CsigkTZp91G6p/nyUJ536o4qByy67HWzBlPYniKWz8m81 iw56L/s53az2pNBoo8AVIecF/+VugazRmG6FKe6aaNqbozMxZLG+SEZoPYFdKPf3jtD1 LK6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=epvT2po3KSgWtqacDVe+UBB3Xy1nc9APf41E0KARoF0=; b=I1PsKgBnY24ENlYHGSWIbk8jInaFoVIN9K+xrHH9ZJkjfYZKjhPJDcWigjx3X1Tnp2 /1Ria1b9OxZP+KTR8TXMVxyY4H955ih/A+Nkmp0o0ELxxqUWSwAnliIxggtU6ohGUQGG Stie8rJYO7cVVBWBhXAuma14RiNWrRZe5Ra7+3klAJvyFhd6vArvOUL9jK/Z6DVx8/gp xnRUW/iz1LC8wtkvGdQX3r5/r0nmRcRK1zOHU5nBwR8VFz4MdYgVEqRjTUsbLXp5E6nP vN+Tgj6qTPTM+0A/N30EEJbgxq/n5N1wQJkxwcUYjjN9prvwUySkuq5ohYab2z+GpVeo ZNmA== X-Gm-Message-State: AJcUukeHF9bvptTTRtUJeOuQxgTNux8e3ganeZKRmmLkVNnMHDIZEABe kEf8lnEDHb0DfQ0j2s0UqGiqd5xVDCE= X-Google-Smtp-Source: ALg8bN7Ez70KISCkmTSvfV2GmjF9zsFCA9ABGjNWdq7P7bNmiS4CyAGXcrabNRuBLEVq8u4z+/v66A== X-Received: by 2002:a62:c583:: with SMTP id j125mr23984250pfg.37.1547438202654; Sun, 13 Jan 2019 19:56:42 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id l70sm93582741pgd.20.2019.01.13.19.56.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Jan 2019 19:56:42 -0800 (PST) From: Martin Kelly X-Google-Original-From: Martin Kelly , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Martin Kelly Subject: [PATCH 2/5] iio:bmi160: add drdy interrupt support Date: Sun, 13 Jan 2019 19:56:18 -0800 Message-Id: <20190114035621.5252-3-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190114035621.5252-1-martin@martingkelly.com> References: <20190114035621.5252-1-martin@martingkelly.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Kelly Add interrupt support for the data ready signal on the BMI160, which fires an interrupt whenever new accelerometer/gyroscope data is ready to read. Signed-off-by: Martin Kelly --- drivers/iio/imu/bmi160/Makefile | 1 + drivers/iio/imu/bmi160/bmi160.h | 13 +- drivers/iio/imu/bmi160/bmi160_core.c | 271 +++++++++++++++++++++++++++++++- drivers/iio/imu/bmi160/bmi160_i2c.c | 3 +- drivers/iio/imu/bmi160/bmi160_spi.c | 2 +- drivers/iio/imu/bmi160/bmi160_trigger.c | 60 +++++++ 6 files changed, 341 insertions(+), 9 deletions(-) create mode 100644 drivers/iio/imu/bmi160/bmi160_trigger.c diff --git a/drivers/iio/imu/bmi160/Makefile b/drivers/iio/imu/bmi160/Makefile index 10365e493ae2..19e1720c6fe9 100644 --- a/drivers/iio/imu/bmi160/Makefile +++ b/drivers/iio/imu/bmi160/Makefile @@ -2,5 +2,6 @@ # Makefile for Bosch BMI160 IMU # obj-$(CONFIG_BMI160) += bmi160_core.o +obj-$(CONFIG_BMI160) += bmi160_trigger.o obj-$(CONFIG_BMI160_I2C) += bmi160_i2c.o obj-$(CONFIG_BMI160_SPI) += bmi160_spi.o diff --git a/drivers/iio/imu/bmi160/bmi160.h b/drivers/iio/imu/bmi160/bmi160.h index 2351049d930b..0c5e67e0d35b 100644 --- a/drivers/iio/imu/bmi160/bmi160.h +++ b/drivers/iio/imu/bmi160/bmi160.h @@ -2,9 +2,20 @@ #ifndef BMI160_H_ #define BMI160_H_ +#include + +struct bmi160_data { + struct regmap *regmap; + struct iio_trigger *trig; +}; + extern const struct regmap_config bmi160_regmap_config; int bmi160_core_probe(struct device *dev, struct regmap *regmap, - const char *name, bool use_spi); + const char *name, bool use_spi, int irq); + +int bmi160_enable_irq(struct regmap *regmap, bool enable); + +int bmi160_probe_trigger(struct iio_dev *indio_dev, int irq, u32 irq_type); #endif /* BMI160_H_ */ diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c index ce61026d84c3..e119965e64a3 100644 --- a/drivers/iio/imu/bmi160/bmi160_core.c +++ b/drivers/iio/imu/bmi160/bmi160_core.c @@ -6,12 +6,14 @@ * * IIO core driver for BMI160, with support for I2C/SPI busses * - * TODO: magnetometer, interrupts, hardware FIFO + * TODO: magnetometer, hardware FIFO */ #include #include #include #include +#include +#include #include #include @@ -61,8 +63,32 @@ #define BMI160_CMD_GYRO_PM_FAST_STARTUP 0x17 #define BMI160_CMD_SOFTRESET 0xB6 +#define BMI160_REG_INT_EN 0x51 +#define BMI160_DRDY_INT_EN BIT(4) + +#define BMI160_REG_INT_OUT_CTRL 0x53 +#define BMI160_INT_OUT_CTRL_MASK 0x0f +#define BMI160_INT1_OUT_CTRL_SHIFT 0 +#define BMI160_INT2_OUT_CTRL_SHIFT 4 +#define BMI160_LEVEL_TRIGGERED BIT(0) +#define BMI160_ACTIVE_HIGH BIT(1) +#define BMI160_OPEN_DRAIN BIT(2) +#define BMI160_OUTPUT_EN BIT(3) + +#define BMI160_REG_INT_LATCH 0x54 +#define BMI160_INT1_LATCH_MASK BIT(4) +#define BMI160_INT2_LATCH_MASK BIT(5) + +/* INT1 and INT2 are in the opposite order as in INT_OUT_CTRL! */ +#define BMI160_REG_INT_MAP 0x56 +#define BMI160_INT1_MAP_DRDY_EN 0x80 +#define BMI160_INT2_MAP_DRDY_EN 0x08 + #define BMI160_REG_DUMMY 0x7F +#define BMI160_NORMAL_WRITE_USLEEP 2 +#define BMI160_SUSPENDED_WRITE_USLEEP 450 + #define BMI160_ACCEL_PMU_MIN_USLEEP 3800 #define BMI160_GYRO_PMU_MIN_USLEEP 80000 #define BMI160_SOFTRESET_USLEEP 1000 @@ -105,8 +131,9 @@ enum bmi160_sensor_type { BMI160_NUM_SENSORS /* must be last */ }; -struct bmi160_data { - struct regmap *regmap; +enum bmi160_int_pin { + BMI160_PIN_INT1, + BMI160_PIN_INT2 }; const struct regmap_config bmi160_regmap_config = { @@ -495,7 +522,232 @@ static const char *bmi160_match_acpi_device(struct device *dev) return dev_name(dev); } -static int bmi160_chip_init(struct bmi160_data *data, bool use_spi) +static int bmi160_write_conf_reg(struct regmap *regmap, unsigned int reg, + unsigned int mask, unsigned int bits, + unsigned int write_usleep) +{ + int ret; + unsigned int val; + + ret = regmap_read(regmap, reg, &val); + if (ret < 0) + return ret; + + val = (val & ~mask) | bits; + + ret = regmap_write(regmap, reg, val); + if (ret < 0) + return ret; + + /* + * We need to wait after writing before we can write again. See the + * datasheet, page 93. + */ + usleep_range(write_usleep, write_usleep + 1000); + + return 0; +} + +static int bmi160_config_pin(struct regmap *regmap, enum bmi160_int_pin pin, + bool open_drain, u8 irq_mask, + unsigned long write_usleep) +{ + int ret; + u8 int_out_ctrl_shift; + u8 int_latch_mask; + u8 int_map_mask; + u8 int_out_ctrl_mask; + u8 int_out_ctrl_bits; + + switch (pin) { + case BMI160_PIN_INT1: + int_out_ctrl_shift = BMI160_INT1_OUT_CTRL_SHIFT; + int_latch_mask = BMI160_INT1_LATCH_MASK; + int_map_mask = BMI160_INT1_MAP_DRDY_EN; + break; + case BMI160_PIN_INT2: + int_out_ctrl_shift = BMI160_INT2_OUT_CTRL_SHIFT; + int_latch_mask = BMI160_INT2_LATCH_MASK; + int_map_mask = BMI160_INT2_MAP_DRDY_EN; + break; + } + int_out_ctrl_mask = BMI160_INT_OUT_CTRL_MASK << int_out_ctrl_shift; + + /* + * Enable the requested pin with the right settings: + * - Push-pull/open-drain + * - Active low/high + * - Edge/level triggered + */ + int_out_ctrl_bits = 0; + int_out_ctrl_bits |= BMI160_OUTPUT_EN; + if (open_drain) + /* Default is push-pull. */ + int_out_ctrl_bits |= BMI160_OPEN_DRAIN; + int_out_ctrl_bits |= irq_mask; + int_out_ctrl_bits <<= int_out_ctrl_shift; + + ret = bmi160_write_conf_reg(regmap, BMI160_REG_INT_OUT_CTRL, + int_out_ctrl_mask, int_out_ctrl_bits, + write_usleep); + if (ret < 0) + return ret; + + /* Set the pin to input mode with no latching. */ + ret = bmi160_write_conf_reg(regmap, BMI160_REG_INT_LATCH, + int_latch_mask, int_latch_mask, + write_usleep); + if (ret < 0) + return ret; + + /* Map interrupts to the requested pin. */ + ret = bmi160_write_conf_reg(regmap, BMI160_REG_INT_MAP, + int_map_mask, int_map_mask, + write_usleep); + if (ret < 0) + return ret; + + return 0; +} + +int bmi160_enable_irq(struct regmap *regmap, bool enable) +{ + int ret; + unsigned int enable_bit; + + if (enable) + enable_bit = BMI160_DRDY_INT_EN; + else + enable_bit = 0; + + ret = bmi160_write_conf_reg(regmap, BMI160_REG_INT_EN, + BMI160_DRDY_INT_EN, enable_bit, + BMI160_NORMAL_WRITE_USLEEP); + + return ret; +} +EXPORT_SYMBOL(bmi160_enable_irq); + +static void bmi160_parse_irqname(struct device_node *of_node, int irq, + bool *int1_enabled, bool *int2_enabled) +{ + int ret; + + /* of_irq_get_byname returns the IRQ number if the entry is found. */ + ret = of_irq_get_byname(of_node, "INT1"); + if (ret == irq) { + *int1_enabled = true; + *int2_enabled = false; + return; + } + + ret = of_irq_get_byname(of_node, "INT2"); + if (ret == irq) { + *int1_enabled = false; + *int2_enabled = true; + return; + } + + ret = of_irq_get_byname(of_node, "BOTH"); + if (ret == irq) { + *int1_enabled = true; + *int2_enabled = true; + return; + } + + /* No interrupt name entries found. */ + *int1_enabled = false; + *int2_enabled = false; +} + +static int bmi160_config_device_irq(struct iio_dev *indio_dev, + int irq, int irq_type) +{ + int ret; + bool int1_enabled; + bool int1_open_drain; + bool int2_enabled; + bool int2_open_drain; + u8 irq_mask; + struct bmi160_data *data = iio_priv(indio_dev); + struct device *dev = regmap_get_device(data->regmap); + + /* Edge-triggered, active-low is the default if we set all zeroes. */ + if (irq_type == IRQF_TRIGGER_RISING) + irq_mask = BMI160_ACTIVE_HIGH | BMI160_LEVEL_TRIGGERED; + else if (irq_type == IRQF_TRIGGER_FALLING) + irq_mask = BMI160_LEVEL_TRIGGERED; + else if (irq_type == IRQF_TRIGGER_HIGH) + irq_mask = BMI160_ACTIVE_HIGH; + else if (irq_type == IRQF_TRIGGER_LOW) + irq_mask = 0; + else { + dev_err(&indio_dev->dev, + "Invalid interrupt type 0x%x specified\n", irq_type); + return -EINVAL; + } + + bmi160_parse_irqname(dev->of_node, irq, &int1_enabled, &int2_enabled); + + if (!int1_enabled && !int2_enabled) { + dev_err(&indio_dev->dev, "IRQ specified but not routed anywhere. bmi160,int1-enabled or bmi160,int2-enabled must be set."); + return -EINVAL; + } + + int1_open_drain = of_property_read_bool(dev->of_node, + "bmi160,int1-open-drain"); + int2_open_drain = of_property_read_bool(dev->of_node, + "bmi160,int2-open-drain"); + + if (int1_enabled) { + ret = bmi160_config_pin(data->regmap, BMI160_PIN_INT1, + int1_open_drain, irq_mask, + BMI160_NORMAL_WRITE_USLEEP); + if (ret < 0) { + dev_err(&indio_dev->dev, "Failed to configure INT1 IRQ pin"); + return ret; + } + } + + if (int2_enabled) { + ret = bmi160_config_pin(data->regmap, BMI160_PIN_INT2, + int2_open_drain, irq_mask, + BMI160_NORMAL_WRITE_USLEEP); + if (ret < 0) { + dev_err(&indio_dev->dev, "Failed to configure INT2 IRQ pin"); + return ret; + } + } + + return 0; +} + +static int bmi160_setup_irq(struct iio_dev *indio_dev, int irq) +{ + struct irq_data *desc; + u32 irq_type; + int ret; + + desc = irq_get_irq_data(irq); + if (!desc) { + dev_warn(&indio_dev->dev, "Could not find IRQ %d\n", irq); + return -EINVAL; + } + + irq_type = irqd_get_trigger_type(desc); + + ret = bmi160_config_device_irq(indio_dev, irq, irq_type); + if (ret < 0) + return ret; + + ret = bmi160_probe_trigger(indio_dev, irq, irq_type); + if (ret < 0) + return ret; + + return 0; +} + +static int bmi160_chip_init(struct bmi160_data *data, bool use_spi, int irq) { int ret; unsigned int val; @@ -548,7 +800,7 @@ static void bmi160_chip_uninit(void *data) } int bmi160_core_probe(struct device *dev, struct regmap *regmap, - const char *name, bool use_spi) + const char *name, bool use_spi, int irq) { struct iio_dev *indio_dev; struct bmi160_data *data; @@ -561,8 +813,9 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, data = iio_priv(indio_dev); dev_set_drvdata(dev, indio_dev); data->regmap = regmap; + data->trig = NULL; - ret = bmi160_chip_init(data, use_spi); + ret = bmi160_chip_init(data, use_spi, irq); if (ret < 0) return ret; @@ -585,6 +838,12 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, if (ret < 0) return ret; + if (irq) { + ret = bmi160_setup_irq(indio_dev, irq); + if (ret < 0) + return ret; + } + ret = devm_iio_device_register(dev, indio_dev); if (ret < 0) return ret; diff --git a/drivers/iio/imu/bmi160/bmi160_i2c.c b/drivers/iio/imu/bmi160/bmi160_i2c.c index e36f5e82d400..98467d73c887 100644 --- a/drivers/iio/imu/bmi160/bmi160_i2c.c +++ b/drivers/iio/imu/bmi160/bmi160_i2c.c @@ -32,7 +32,8 @@ static int bmi160_i2c_probe(struct i2c_client *client, if (id) name = id->name; - return bmi160_core_probe(&client->dev, regmap, name, false); + return bmi160_core_probe(&client->dev, regmap, + name, false, client->irq); } static const struct i2c_device_id bmi160_i2c_id[] = { diff --git a/drivers/iio/imu/bmi160/bmi160_spi.c b/drivers/iio/imu/bmi160/bmi160_spi.c index c19e3df35559..23e323518873 100644 --- a/drivers/iio/imu/bmi160/bmi160_spi.c +++ b/drivers/iio/imu/bmi160/bmi160_spi.c @@ -24,7 +24,7 @@ static int bmi160_spi_probe(struct spi_device *spi) (int)PTR_ERR(regmap)); return PTR_ERR(regmap); } - return bmi160_core_probe(&spi->dev, regmap, id->name, true); + return bmi160_core_probe(&spi->dev, regmap, id->name, true, spi->irq); } static const struct spi_device_id bmi160_spi_id[] = { diff --git a/drivers/iio/imu/bmi160/bmi160_trigger.c b/drivers/iio/imu/bmi160/bmi160_trigger.c new file mode 100644 index 000000000000..96e254eb2f19 --- /dev/null +++ b/drivers/iio/imu/bmi160/bmi160_trigger.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * BMI160 - Bosch IMU, trigger/IRQ bits + * + * Copyright (c) 2019, Martin Kelly. + */ + +#include +#include + +#include +#include + +#include "bmi160.h" + +static int bmi160_data_rdy_trigger_set_state(struct iio_trigger *trig, + bool enable) +{ + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); + struct bmi160_data *data = iio_priv(indio_dev); + + return bmi160_enable_irq(data->regmap, enable); +} + +static const struct iio_trigger_ops bmi160_trigger_ops = { + .set_trigger_state = &bmi160_data_rdy_trigger_set_state, +}; + +int bmi160_probe_trigger(struct iio_dev *indio_dev, int irq, u32 irq_type) +{ + struct bmi160_data *data = iio_priv(indio_dev); + int ret; + + data->trig = devm_iio_trigger_alloc(&indio_dev->dev, "%s-dev%d", + indio_dev->name, indio_dev->id); + + if (data->trig == NULL) + return -ENOMEM; + + ret = devm_request_irq(&indio_dev->dev, irq, + &iio_trigger_generic_data_rdy_poll, + irq_type, "bmi160", data->trig); + if (ret < 0) + return ret; + + data->trig->dev.parent = regmap_get_device(data->regmap); + data->trig->ops = &bmi160_trigger_ops; + iio_trigger_set_drvdata(data->trig, indio_dev); + + ret = devm_iio_trigger_register(&indio_dev->dev, data->trig); + if (ret < 0) + return ret; + + indio_dev->trig = iio_trigger_get(data->trig); + if (ret < 0) + return ret; + + return 0; +} +EXPORT_SYMBOL_GPL(bmi160_probe_trigger); From patchwork Mon Jan 14 03:56:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10761637 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E14F13BF for ; Mon, 14 Jan 2019 03:56:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0054428A20 for ; Mon, 14 Jan 2019 03:56:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8E9A28A48; Mon, 14 Jan 2019 03:56:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 016C828A37 for ; Mon, 14 Jan 2019 03:56:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726724AbfAND4p (ORCPT ); Sun, 13 Jan 2019 22:56:45 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:37906 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbfAND4p (ORCPT ); Sun, 13 Jan 2019 22:56:45 -0500 Received: by mail-pg1-f196.google.com with SMTP id g189so8882482pgc.5 for ; Sun, 13 Jan 2019 19:56:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martingkelly-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AoooTCmjZ5+hUnrheSFS4kgpOtp0NBQrzyp55jolc5Q=; b=0TesgYfdb+J/wkWGX744GE7lmPS8/X/WRxph6pHxTpuOaT6UAzGTQ3HmgFDtVjKWYa qIxOO/yh5yBEEey+ulMMFzqcjWfnrU2n1wXUzSGHxb9yHZDW8rG8+goGTqU7aoiv94xa OkTV9KUTt/W2HVadNrV47ltU/IDRSFxek+o2iXPLHKUHQQpjjoBB07y5DYWl/kZdODeZ n9tgZgR7kpyaK0aLDI+JCCyh2ix38rSZu2Wupu/BM1d4N7Z0XXIR9xufwGrVll6x8ef+ Wl5MzY2E2TkC7/LXUZ8ffRtBVPRwaRb8saTOaeqHhOmIAGPPiRNacTv99IcIoaE5cCbd FWig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AoooTCmjZ5+hUnrheSFS4kgpOtp0NBQrzyp55jolc5Q=; b=s3EnLMaGLfwLmhCQn5lEq9q9MeNXat2tqfPclHdxXAdtfQrDwrWsRbKfrhld1mgAz+ UktGU7Rgc3b+NfxnehqWBES8G6B2PTPlo+tRunO8m2Uyyl1kXA50A5zc2VZguZOjbaOp eUpFUaXwepEbQo5VUiUYEUgEu5uW06IKjM8B92DLTEKpPF+j/bKg0J8iqAtxww1DPNZq L/vndTij6YHGwU4EhPyG6jRlCm5aZkHX1aCyUsBe+5GCY/TmedSjVkEWOK0ZdeRrA1RO pj4Ot88jru4PRGq28amPSZYoHULoeVAQzWOnQVHpVPpsVYs9SajWaq8bE172fosBg3jm LYQQ== X-Gm-Message-State: AJcUukdYz0OOPCnnEwqQnmv1aMGRI04JZyD4eXMlYRO4BmNMh4Nb0ktI Y57BBzGdrd68ixfZ7/eaCPakLtzwetU= X-Google-Smtp-Source: ALg8bN4wMBMc5Jbofa5emp9WSuTFjxR+qsbrzQbUGbhRWLPkVPyg8s/VbEFBL4N4Lv2AdkJj20LxdA== X-Received: by 2002:a62:870e:: with SMTP id i14mr24312425pfe.41.1547438204242; Sun, 13 Jan 2019 19:56:44 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id l70sm93582741pgd.20.2019.01.13.19.56.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Jan 2019 19:56:43 -0800 (PST) From: Martin Kelly X-Google-Original-From: Martin Kelly , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Martin Kelly Subject: [PATCH 3/5] dt-bindings: fix incorrect bmi160 IRQ note Date: Sun, 13 Jan 2019 19:56:19 -0800 Message-Id: <20190114035621.5252-4-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190114035621.5252-1-martin@martingkelly.com> References: <20190114035621.5252-1-martin@martingkelly.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Kelly The bmi160 bindings say that the BMI160 requires level-triggered, active-low interrupts, but it actually supports all interrupt types, so fix the note to reflect that. Signed-off-by: Martin Kelly --- Documentation/devicetree/bindings/iio/imu/bmi160.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/imu/bmi160.txt b/Documentation/devicetree/bindings/iio/imu/bmi160.txt index 0c1c105fb503..1aec19997fb5 100644 --- a/Documentation/devicetree/bindings/iio/imu/bmi160.txt +++ b/Documentation/devicetree/bindings/iio/imu/bmi160.txt @@ -9,7 +9,7 @@ Required properties: - spi-max-frequency : set maximum clock frequency (only for SPI) Optional properties: - - interrupts : interrupt mapping for IRQ, must be IRQ_TYPE_LEVEL_LOW + - interrupts : interrupt mapping for IRQ - interrupt-names : set to "INT1" if INT1 pin should be used as interrupt input, set to "INT2" if INT2 pin should be used instead @@ -20,7 +20,7 @@ bmi160@68 { reg = <0x68>; interrupt-parent = <&gpio4>; - interrupts = <12 IRQ_TYPE_LEVEL_LOW>; + interrupts = <12 IRQ_TYPE_EDGE_RISING>; interrupt-names = "INT1"; }; From patchwork Mon Jan 14 03:56:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10761645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B38F13BF for ; Mon, 14 Jan 2019 03:56:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C7B9289CD for ; Mon, 14 Jan 2019 03:56:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 010A128A20; Mon, 14 Jan 2019 03:56:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 235DA28A3A for ; Mon, 14 Jan 2019 03:56:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726728AbfAND4r (ORCPT ); Sun, 13 Jan 2019 22:56:47 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:36828 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbfAND4q (ORCPT ); Sun, 13 Jan 2019 22:56:46 -0500 Received: by mail-pl1-f195.google.com with SMTP id g9so9500424plo.3 for ; Sun, 13 Jan 2019 19:56:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martingkelly-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jgtsCNC4lKMzHun3rXVG2z7hRy3IkPEkIrYF5GtUHHI=; b=yvqvJ9pzBeGiZieEYLEon0kn/HP1XhLGUcyHcGm0cHw9sZAPzkUhLIHRY5rnbx5PUI xnlr8DcE5Sz6wl6aOGS2FdjM1Uxk8vecSfp2uLz/2jvI8apbkYZUe0ZfmDOnEp0ZygyW xfqVxsgpNhzNSAKwmE2u9hHGO5bMOQKy9rloNYUg1VQpHfwVrdU/Jq8PW4eB1OzbXxdM 5fhspjsVJQk7j1j+uPC0hga93ZBQibaQQCL2+fg7fSdAes8bKQX4KO4sSia9plkax8Zx zjcd1TaDa+lWAADzMZ7LKiQikAWnsnLQYv/BWUT5mYqT3dDvwQV48XkDU/xtG64oIQPA EXSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jgtsCNC4lKMzHun3rXVG2z7hRy3IkPEkIrYF5GtUHHI=; b=qudMNDkvFeoYaFqc5TZKHVCprjHa2RGMEo0gG2u7L5w1B9SKOWmA4h2pA6aGOrqNp/ QcWlTGQ96cyLSatcVGbmD8RmjshL+TB8z85h0RCfjnplcL0GsdEHt4VGDUjImoSASGAH skEPTtZF5yfxrVM9HIgs4N65xgpsbw1y/d9372iuEC7H6r3ddXzAEiz3yYrmz0Igdwxn Sh/a+pFkveEaUqKaBxg4H+D3DTqZicdfUwTVcO6JJDP73F7jpt3JNSbs3SHd9VXjhouf LaRv5J5YGfz2svW1CcyzVpA0d4JjewKyPyGhU8tR3bMIxyBiPbCkrmMcERcFd/EChlHV lUxg== X-Gm-Message-State: AJcUukdaczlWYLCOICNHWSeHPQVSQaAPWvHNUyhTz/Ibl0LQxGXAMJtp /dRMJiWGJIWYyo1LNECCppszQ186PqI= X-Google-Smtp-Source: ALg8bN4ZWDlg6q6bM5OSxEnrsYKPoAbemcpIidCt7TQ5FvOpsj4cqHmO2yndJz//DlTKmmkyQdl6kg== X-Received: by 2002:a17:902:6946:: with SMTP id k6mr24311473plt.101.1547438205790; Sun, 13 Jan 2019 19:56:45 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id l70sm93582741pgd.20.2019.01.13.19.56.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Jan 2019 19:56:45 -0800 (PST) From: Martin Kelly X-Google-Original-From: Martin Kelly , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Martin Kelly Subject: [PATCH 4/5] dt-bindings:bmi160: add "BOTH" int pin type Date: Sun, 13 Jan 2019 19:56:20 -0800 Message-Id: <20190114035621.5252-5-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190114035621.5252-1-martin@martingkelly.com> References: <20190114035621.5252-1-martin@martingkelly.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Kelly The bindings currently allow for interrupts routing to INT1 or INT2, but the hardware allows for routing to both, so add "BOTH" as an int pin entry. Signed-off-by: Martin Kelly --- Documentation/devicetree/bindings/iio/imu/bmi160.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iio/imu/bmi160.txt b/Documentation/devicetree/bindings/iio/imu/bmi160.txt index 1aec19997fb5..a56d377dabf3 100644 --- a/Documentation/devicetree/bindings/iio/imu/bmi160.txt +++ b/Documentation/devicetree/bindings/iio/imu/bmi160.txt @@ -11,7 +11,8 @@ Required properties: Optional properties: - interrupts : interrupt mapping for IRQ - interrupt-names : set to "INT1" if INT1 pin should be used as interrupt - input, set to "INT2" if INT2 pin should be used instead + input, set to "INT2" if INT2 pin should be used instead, set to "BOTH" if + both should be used. Examples: @@ -33,3 +34,13 @@ bmi160@0 { interrupts = <12 IRQ_TYPE_LEVEL_LOW>; interrupt-names = "INT2"; }; + +bmi160@0 { + compatible = "bosch,bmi160"; + reg = <0>; + spi-max-frequency = <10000000>; + + interrupt-parent = <&gpio2>; + interrupts = <12 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "BOTH"; +}; From patchwork Mon Jan 14 03:56:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10761639 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2FA6A1823 for ; Mon, 14 Jan 2019 03:56:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 225BB28A20 for ; Mon, 14 Jan 2019 03:56:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16E5628A37; Mon, 14 Jan 2019 03:56:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43D0228A3B for ; Mon, 14 Jan 2019 03:56:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726730AbfAND4s (ORCPT ); Sun, 13 Jan 2019 22:56:48 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37394 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbfAND4s (ORCPT ); Sun, 13 Jan 2019 22:56:48 -0500 Received: by mail-pl1-f195.google.com with SMTP id b5so9502592plr.4 for ; Sun, 13 Jan 2019 19:56:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martingkelly-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sY6D3nJrPNk6hjxFulqaRdI0rgmo/bhPApL6m8Dg1pQ=; b=LnkpAssKZnPgRh5pQnixanacbQ2eHfRVM2AOqjqf1Pj4B76zZyEwh+NpG7GbO1NBwq Cqf3+0nGlKdxv0G2aDFd4Alkt2YskCBalQB+Q3yx3mQx6I0Z6CebKZpBveDMla+Rfmw7 JU8eiC9WRlKEVzOTPbI4CMJHFg2xQKHj71hEJHArtGBfPQxhIotoZopVgTuOhOwN2rLz AqBvigI3C7/gk+6CbbLeE/gKilVsQFk4IausPzfBTW4ukfd2w2WIog1pk5eU3VV7umyX ixxl97TarZGwWzweB032Cyg2ZW0nwwxuTTvC/znIYvyizmfYzF0PWtcZVzmGqdS814Zb NZWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sY6D3nJrPNk6hjxFulqaRdI0rgmo/bhPApL6m8Dg1pQ=; b=CiGsriPx5Ze4wB2l4cqFjpSl7NS7l+TgVtRCc9lA0XqBdAkCU4ir0GrPiFvnA9XGxS iAJ9NGB4fjrMFVFaRxjBRNOHL7r+Xjfr13O5jSG8gRON2cMSutePSqoIQCg2LqtTcdk0 vp3sHptB+HtZc/gLkIcavUcop6ARfiInF0BbRCIfs+9ff3RzSiYd2BIRkW3OjYStCnJu fOrlumlAXfPXl70NkiNocRSYK03Hn/EKgAfZbT7cYj3xz5F3ybuYkLCSh67j4swr15mJ NdK119LAtb5clDMAWvheAzZ+e55S52y+yXYpcrlY/8ej+Ng05Ub8mscKXnvaGSmx+kgF PpuA== X-Gm-Message-State: AJcUukdj56DjqmOytG4dDQWZgCwEXmZL4q7kTEYgrmvP0l92VS30E806 WwQu5ADSFivCG0I1U/G+7jC89aQGKXQ= X-Google-Smtp-Source: ALg8bN7dJBzxjN6JXMy/UpRgq0ZSTNFIKHCAF9TzA91WqCdm+9MEJBysNMQVLH7eDLbher13kCxoKw== X-Received: by 2002:a17:902:a03:: with SMTP id 3mr23997924plo.112.1547438207232; Sun, 13 Jan 2019 19:56:47 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id l70sm93582741pgd.20.2019.01.13.19.56.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Jan 2019 19:56:46 -0800 (PST) From: Martin Kelly X-Google-Original-From: Martin Kelly , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Martin Kelly Subject: [PATCH 5/5] iio:bmi160:snap timestamp closer to event Date: Sun, 13 Jan 2019 19:56:21 -0800 Message-Id: <20190114035621.5252-6-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190114035621.5252-1-martin@martingkelly.com> References: <20190114035621.5252-1-martin@martingkelly.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Kelly Currently, we snap the timestamp after reading from the buffer and processing the event. When the IIO poll function is triggered by an interrupt, we can get a slightly more accurate timestamp by snapping it prior to reading the data, since the data was already generated prior to entering the trigger handler. This is not going to make a huge difference, but we might as well improve slightly. Signed-off-by: Martin Kelly --- drivers/iio/imu/bmi160/bmi160_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c index e119965e64a3..4b4456af0971 100644 --- a/drivers/iio/imu/bmi160/bmi160_core.c +++ b/drivers/iio/imu/bmi160/bmi160_core.c @@ -408,6 +408,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; + s64 ts = iio_get_time_ns(indio_dev); struct bmi160_data *data = iio_priv(indio_dev); __le16 buf[16]; /* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */ @@ -423,8 +424,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) buf[j++] = sample; } - iio_push_to_buffers_with_timestamp(indio_dev, buf, - iio_get_time_ns(indio_dev)); + iio_push_to_buffers_with_timestamp(indio_dev, buf, ts); done: iio_trigger_notify_done(indio_dev->trig); return IRQ_HANDLED;