From patchwork Sun Jan 27 20:39:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10783043 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 7F3576C2 for ; Sun, 27 Jan 2019 20:39:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6FD3F2A92D for ; Sun, 27 Jan 2019 20:39:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62D482A92F; Sun, 27 Jan 2019 20:39:32 +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 0244E2A92D for ; Sun, 27 Jan 2019 20:39:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726867AbfA0Ujb (ORCPT ); Sun, 27 Jan 2019 15:39:31 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:40186 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727095AbfA0Uja (ORCPT ); Sun, 27 Jan 2019 15:39:30 -0500 Received: by mail-pl1-f194.google.com with SMTP id u18so6812261plq.7 for ; Sun, 27 Jan 2019 12:39:30 -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=seTxKBbv6NcYw7C/fWxfSIDXnW8QJGcsoke1fNa+shgYPiMPueYCWIQHhbMV5FzyuX AlJmrasn+/caaslB3Pv4A9I/o1MThhwVZjiV6pqiCegfLxgvA0lhucdBmL3KdZM4dkmY nX1MoVWlrAECC6ay6lKbFiBct3rATFtk6q0wEcGqRBM30dNLZWiTYry1erQZCfXX7Tln yxh+sbNPRR3t5kp6uigS+CTc72uXSy1piZ3uFM+WH3m0m/vEjvHl6BQuKAvKpPhoErU2 gbEanCrIT2s7kDv8uMQqwOrcsLLJWKTVq84LI29EhOnM89koG9+FMTFcHC/xoIA5K5Um 0V+g== 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=rnOwJOb1gHd8FXqw2/GFt4GJxcjjaUEuJ+8pncN2XEz2KRad2kUxcmZtQij/n+M0Gr bDpE/6KFvmDylcewbLZ4971xrlB4PFzPl9VnQVlZyy24LoTFAZ05YbiXi0BEAs5kEdEU 4JrRk1aPaZU4ALXVx3Q0a1jEzBrRgeA7hL6rrTx/RJajAdCnwvhuGwN9wKtT9U9BXScD LKqbDWryteRuopoxpdotimnRH+/l/1nkWJTIO6fYWJf3ZjH506sRqMBjck27FmGgtxDB ehzMo9TnbFDOM9y+ri3pjPvt1Ead4eL49jewiZP7h5v52jeKCAoswVM/7IspwEgBfJnA +PMg== X-Gm-Message-State: AJcUukeS/qCYwuqADcOnZbsTLY5WJ5NQS7V/k34lokzEenWpoOgL7MNM /ia/5JuLJzb+cf3M0gFzoj9TMQtKOxc5Iw== X-Google-Smtp-Source: ALg8bN54JP+563eTAArczYrNxmRCjWwAK5xtno4dxiaRghLB9gQOcbR75WTDAxZiN4GRAyphXbCJwQ== X-Received: by 2002:a17:902:12f:: with SMTP id 44mr19540379plb.74.1548621569745; Sun, 27 Jan 2019 12:39:29 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id a4sm33049912pgv.70.2019.01.27.12.39.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Jan 2019 12:39:29 -0800 (PST) From: Martin Kelly X-Google-Original-From: Martin Kelly , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Daniel Baluta , devicetree@vger.kernel.org, Martin Kelly Subject: [PATCH v3 1/6] iio:bmi160: add SPDX identifiers Date: Sun, 27 Jan 2019 12:39:06 -0800 Message-Id: <20190127203911.8696-2-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190127203911.8696-1-martin@martingkelly.com> References: <20190127203911.8696-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 Sun Jan 27 20:39:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10783045 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 F1BE313B5 for ; Sun, 27 Jan 2019 20:39:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E29522A92D for ; Sun, 27 Jan 2019 20:39:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6E712A92F; Sun, 27 Jan 2019 20:39:34 +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 10D562A92D for ; Sun, 27 Jan 2019 20:39:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727095AbfA0Ujd (ORCPT ); Sun, 27 Jan 2019 15:39:33 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:44548 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727101AbfA0Ujc (ORCPT ); Sun, 27 Jan 2019 15:39:32 -0500 Received: by mail-pl1-f196.google.com with SMTP id e11so6801813plt.11 for ; Sun, 27 Jan 2019 12:39:32 -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=FlyRPLlgUAShz0ebP8RTaMbNSXmKYKB9Wl5iiR3oRNU=; b=cvYn6WZKZDS1hBEhg9zr+SecvfU4vQenbViUm4Jp+aYYHy43tSSG0DcE4Pi9pPparg 66Qgs0WJlxz6h+mamBDQQHFMr3HQWGCYnTuAvi3o6Iq96kq+tBPITs6da5OSNgs9IRub x0rrhruCKhvOYFGJRSqtsbGDzLO0IbpbDhs8+oei8UhpWnhI786Wu+bXJfjc2LFNBdJM nDzxwi4PIb+O1d5VBzMUacW+cJnL3NXzTHRU2LhBVUg/jwry8b4LxRWFqNWbKZmfpbpH mXF9d7RR4MHnbjzuid0hJeoWzjWEDUpF0UTz8XcFLGaHFTlAzftwRWpoyDSfBLyEvEzd jNdQ== 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=FlyRPLlgUAShz0ebP8RTaMbNSXmKYKB9Wl5iiR3oRNU=; b=WX8s2LYlAlo01KbZ0y0/JyDNC0+saZBsl4tBSZByg6Vcfez2nDQ7ax/QO0fz7J7HR8 NSEcHHiS5YIgcBhufvZOClDjPu7srZnzFF38mEP6EbuhSqdHdF5FA5eO8DgcYIfQyWf2 XBwLjn8s8XZGSSKsxZgLD/oH4Nab0g1w/RyYFsZafrQhYlfM9Z/1fOYC6I4XXgX2bR9p izqx2CkW0jwCLm4m3e03fxZtj7b8gEwYk25C5fDexHqt7Z/hZ0/aG5RNSUmSkHsAhiTl zWqdLhXsmheFy0F3mP7z7BZkhcNjkbGc03WqCTIoIZNTPVaZ84+UgpiCnectH0xs+GAh 37gA== X-Gm-Message-State: AJcUukeQhXvcZvGt0JGFHR7/nD7R/wGKFLx/oxh8GohhP9XaOmlmDXeO w6n0phVr0PKb7d6oJb0LNhwGC2wbSqBVeg== X-Google-Smtp-Source: ALg8bN7ET3eoXQ/XR2HRxKvfFQ+UhQwVeYrXhiRtiosl4ipPQqEMnLJu43t0G6mZtGh9dZSw3gSsXw== X-Received: by 2002:a17:902:e290:: with SMTP id cf16mr19643159plb.81.1548621571502; Sun, 27 Jan 2019 12:39:31 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id a4sm33049912pgv.70.2019.01.27.12.39.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Jan 2019 12:39:30 -0800 (PST) From: Martin Kelly X-Google-Original-From: Martin Kelly , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Daniel Baluta , devicetree@vger.kernel.org, Martin Kelly Subject: [PATCH v3 2/6] iio:bmi160: add drdy interrupt support Date: Sun, 27 Jan 2019 12:39:07 -0800 Message-Id: <20190127203911.8696-3-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190127203911.8696-1-martin@martingkelly.com> References: <20190127203911.8696-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/bmi160.h | 11 ++ drivers/iio/imu/bmi160/bmi160_core.c | 270 ++++++++++++++++++++++++++++++++++- 2 files changed, 278 insertions(+), 3 deletions(-) diff --git a/drivers/iio/imu/bmi160/bmi160.h b/drivers/iio/imu/bmi160/bmi160.h index 2351049d930b..621f5309d735 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); +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..70739e3920af 100644 --- a/drivers/iio/imu/bmi160/bmi160_core.c +++ b/drivers/iio/imu/bmi160/bmi160_core.c @@ -3,21 +3,25 @@ * BMI160 - Bosch IMU (accel, gyro plus external magnetometer) * * Copyright (c) 2016, Intel Corporation. + * Copyright (c) 2019, Martin Kelly. * * 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 #include #include #include +#include #include "bmi160.h" @@ -61,8 +65,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_EDGE_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 +133,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,6 +524,186 @@ static const char *bmi160_match_acpi_device(struct device *dev) return dev_name(dev); } +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) + return ret; + + val = (val & ~mask) | bits; + + ret = regmap_write(regmap, reg, val); + if (ret) + 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; + struct device *dev = regmap_get_device(regmap); + u8 int_out_ctrl_shift; + u8 int_latch_mask; + u8 int_map_mask; + u8 int_out_ctrl_mask; + u8 int_out_ctrl_bits; + const char *pin_name; + + 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 = 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) + 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) + 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) { + switch (pin) { + case BMI160_PIN_INT1: + pin_name = "INT1"; + break; + case BMI160_PIN_INT2: + pin_name = "INT2"; + break; + } + dev_err(dev, "Failed to configure %s IRQ pin", pin_name); + } + + return ret; +} + +int bmi160_enable_irq(struct regmap *regmap, bool enable) +{ + unsigned int enable_bit = 0; + + if (enable) + enable_bit = BMI160_DRDY_INT_EN; + + return bmi160_write_conf_reg(regmap, BMI160_REG_INT_EN, + BMI160_DRDY_INT_EN, enable_bit, + BMI160_NORMAL_WRITE_USLEEP); +} +EXPORT_SYMBOL(bmi160_enable_irq); + +static int bmi160_get_irq(struct device_node *of_node, enum bmi160_int_pin *pin) +{ + int irq; + + /* Use INT1 if possible, otherwise falling back to INT2. */ + irq = of_irq_get_byname(of_node, "INT1"); + if (irq > 0) { + *pin = BMI160_PIN_INT1; + return irq; + } + + irq = of_irq_get_byname(of_node, "INT2"); + if (irq > 0) + *pin = BMI160_PIN_INT2; + + return irq; +} + +static int bmi160_config_device_irq(struct iio_dev *indio_dev, int irq_type, + enum bmi160_int_pin pin) +{ + bool open_drain; + u8 irq_mask; + struct bmi160_data *data = iio_priv(indio_dev); + struct device *dev = regmap_get_device(data->regmap); + + /* Level-triggered, active-low is the default if we set all zeroes. */ + if (irq_type == IRQF_TRIGGER_RISING) + irq_mask = BMI160_ACTIVE_HIGH | BMI160_EDGE_TRIGGERED; + else if (irq_type == IRQF_TRIGGER_FALLING) + irq_mask = BMI160_EDGE_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; + } + + open_drain = of_property_read_bool(dev->of_node, "bmi160,open-drain"); + + return bmi160_config_pin(data->regmap, pin, open_drain, irq_mask, + BMI160_NORMAL_WRITE_USLEEP); +} + +static int bmi160_setup_irq(struct iio_dev *indio_dev, int irq, + enum bmi160_int_pin pin) +{ + struct irq_data *desc; + u32 irq_type; + int ret; + + desc = irq_get_irq_data(irq); + if (!desc) { + dev_err(&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_type, pin); + if (ret) + return ret; + + return bmi160_probe_trigger(indio_dev, irq, irq_type); +} + static int bmi160_chip_init(struct bmi160_data *data, bool use_spi) { int ret; @@ -539,6 +748,49 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi) return 0; } +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) + return ret; + + indio_dev->trig = iio_trigger_get(data->trig); + + return 0; +} + static void bmi160_chip_uninit(void *data) { struct bmi160_data *bmi_data = data; @@ -552,6 +804,8 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, { struct iio_dev *indio_dev; struct bmi160_data *data; + int irq; + enum bmi160_int_pin int_pin; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); @@ -585,6 +839,16 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, if (ret < 0) return ret; + irq = bmi160_get_irq(dev->of_node, &int_pin); + if (irq > 0) { + ret = bmi160_setup_irq(indio_dev, irq, int_pin); + if (ret) + dev_err(&indio_dev->dev, "Failed to setup IRQ %d\n", + irq); + } else { + dev_info(&indio_dev->dev, "Not setting up IRQ trigger\n"); + } + ret = devm_iio_device_register(dev, indio_dev); if (ret < 0) return ret; From patchwork Sun Jan 27 20:39:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10783047 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 389396C2 for ; Sun, 27 Jan 2019 20:40:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 290B62A92D for ; Sun, 27 Jan 2019 20:40:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BB012A92F; Sun, 27 Jan 2019 20:40:37 +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 BFFBE2A92D for ; Sun, 27 Jan 2019 20:40:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726893AbfA0Ukg (ORCPT ); Sun, 27 Jan 2019 15:40:36 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:39013 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727031AbfA0Ukf (ORCPT ); Sun, 27 Jan 2019 15:40:35 -0500 Received: by mail-pf1-f196.google.com with SMTP id r136so7051696pfc.6 for ; Sun, 27 Jan 2019 12:40:35 -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=MtAvwxqDbMzJe6Dj4pzPXllkyqtiwXJ9l6TUCGzYocH5Ra+LeuEpX9Cclv57CIp5XL 9sFKnmb144oDZMyclQf5bDsfMnPTychxCB7XFyUTiyLWV5/bChW7Y3OmsvRa90ch68G7 9DkC5rKpfbMRSG1r3E5gmGNb0SxuxjYiD/Wb5qtnm5cZ3Pf5Upn864CnSNpkAHj9hG3G zHOv9ngCMW7fqZRd3PGSpJFeOau4cFiVoRcdw0MBoraG+vY7qxK04HrfnMO0D/C15ieZ 3Z5RKQsHleuczMiTcE1pDSspnigJnA2ZEFYLXnP+ZKj8UErSkZV6AuLLcnmwxMYnfLhg ZhLg== 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=IzSOkrrHasYUDlJkCDmq8zHWtDvaHGcmbWinYCmpWlJ44hvQNL24rcQL9+eSY2xL5U oz/uOeG24qm5bTzrFh2DxyDn9O49HytRHng7ixhSWg905XKUINUHMKHCNFi6zxKKERy8 y7drQNnK8SrjRPJXPwWYAmIE8umESl7Pbz5UoX0iZhliAsg6PEDnqSCSu5131opFbq/w 1+HqMaoteA/19ZEFboxNcTzl+PfY94L9XGRwup738smDPxXW4XOWS3qkrSb0HltaAWkP do3WQAgw5mgrYwJXcMSU8gDzbQcwXnrQTIQjf+pbZArdoJh7rZ6PR2OWrtySxU64RSFz zCKQ== X-Gm-Message-State: AJcUukf+E47Fh0zh1ZGAofHYZcr9ltKXsNsveBLExuCDUBAz8zw8kCph JHQZnPCqDdGcrcAGLRQd2r8KOMO7S4wDHw== X-Google-Smtp-Source: ALg8bN77peA/I73D5k9K6hsf30y2Cpe6oiOEl6L/KOve6XpEOmAlA+D86OVd6B5vEeytahpxXGa9RQ== X-Received: by 2002:a63:4a0a:: with SMTP id x10mr17438771pga.237.1548621634676; Sun, 27 Jan 2019 12:40:34 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id a4sm33049912pgv.70.2019.01.27.12.40.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Jan 2019 12:40:33 -0800 (PST) From: Martin Kelly X-Google-Original-From: Martin Kelly , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Daniel Baluta , devicetree@vger.kernel.org, Martin Kelly Subject: [PATCH v3 3/6] dt-bindings: fix incorrect bmi160 IRQ note Date: Sun, 27 Jan 2019 12:39:08 -0800 Message-Id: <20190127203911.8696-4-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190127203911.8696-1-martin@martingkelly.com> References: <20190127203911.8696-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 Reviewed-by: Rob Herring --- 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 Sun Jan 27 20:39:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10783049 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 3D0DF6C2 for ; Sun, 27 Jan 2019 20:40:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E6422A92D for ; Sun, 27 Jan 2019 20:40:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 226D02A92F; Sun, 27 Jan 2019 20:40:38 +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 B92132A92D for ; Sun, 27 Jan 2019 20:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727159AbfA0Ukh (ORCPT ); Sun, 27 Jan 2019 15:40:37 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:38088 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727158AbfA0Ukh (ORCPT ); Sun, 27 Jan 2019 15:40:37 -0500 Received: by mail-pl1-f196.google.com with SMTP id e5so6815611plb.5 for ; Sun, 27 Jan 2019 12:40:36 -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=A5S4IBP0wL4Wp45lAk4Vx9FHPG78i64RpUvUAmANBbM=; b=s8h8/jKl6W5Mvm24agk7iAbRl6eAcO75QPFbrhHeYYqSa9Wyxiga6lUDjL1/7vjT5K yIOKQ/qTmFfydpubC9EWCJgbeePNwEdmKcmVsekave0ZL5ukoh2Irp30dnE0xw3PWG0s u9cNMQTr3RUjLFjbOnQIVDJT9sZhugv6tdwaSGsUoslkceQqXW8iPss7iK9znduWrlP7 Le3iPJSlI5F6DGuvP4vkwfpfXZ3CVlPxCqAowUHLWxyysL4rjKIR9LF+gwt0Ls9ePej8 uL8KdcTzSQBDixu3sXjwM42UxgLahyCb+ljjcITbuVm+PwGtB1I5+y/OHcU7+WlNar1w rkRA== 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=A5S4IBP0wL4Wp45lAk4Vx9FHPG78i64RpUvUAmANBbM=; b=jceojRYdug+mi5Uv1Yx54OwZ4s1unAdNAF0XGGXf9r/zbzEaBS0OeLAvHd7a059Que 8T3Kad40gHbVvBGMXYGxjT2XaCASsesrkXXbOf2YJDOHLDHUlLrsXbkeQ29uG+w8ZbVZ ovow6ncEDtBOE84Tnc8o47TqJJEZv7z3A8lz1hGQ9HG6fcA788aIXmQThm31R27B5kdE Q4iOS9DaFCxT+0717Fow/b4diAQ9gVesc+NvXKOev+CjVuFZxOcGKlsGh5Ql9XR4TGK5 nptAi4OnVel0HDxgBhDtp5HA6ZoKb9Jq5slIbrTRgOX2QAOgA6oX/0rMCxr4yQO0U0gx ocuw== X-Gm-Message-State: AJcUukcE9xDQsvnFGIIkBNyyCBQpMkINCi6eIMNuAT3Rou7fQUT/LYCw h9KECZ3R+gJ9plsgWj65qY4pBL8hWUMvWQ== X-Google-Smtp-Source: ALg8bN4kiCeI2pkg8OfY++O3ikUidvIMu/2aegWr/IUFSJ4If8vHySsaxQjU3lTTOPPgOChHBCPO+w== X-Received: by 2002:a17:902:59c8:: with SMTP id d8mr19279959plj.116.1548621636158; Sun, 27 Jan 2019 12:40:36 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id a4sm33049912pgv.70.2019.01.27.12.40.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Jan 2019 12:40:35 -0800 (PST) From: Martin Kelly X-Google-Original-From: Martin Kelly , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Daniel Baluta , devicetree@vger.kernel.org, Martin Kelly Subject: [PATCH v3 4/6] dt-bindings: document open-drain property Date: Sun, 27 Jan 2019 12:39:09 -0800 Message-Id: <20190127203911.8696-5-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190127203911.8696-1-martin@martingkelly.com> References: <20190127203911.8696-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 We have added an optional boolean property for configuring a BMI160 interrupt pin as open-drain, as opposed to the default push-pull, so document this. Signed-off-by: Martin Kelly --- Documentation/devicetree/bindings/iio/imu/bmi160.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/imu/bmi160.txt b/Documentation/devicetree/bindings/iio/imu/bmi160.txt index 1aec19997fb5..7eb4b6016404 100644 --- a/Documentation/devicetree/bindings/iio/imu/bmi160.txt +++ b/Documentation/devicetree/bindings/iio/imu/bmi160.txt @@ -12,6 +12,8 @@ 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 +- bmi160,open-drain : set if the specified interrupt pin should be configured as + open drain. If not set, defaults to push-pull. Examples: From patchwork Sun Jan 27 20:39:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10783051 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 38E5A13B5 for ; Sun, 27 Jan 2019 20:40:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 294022A92D for ; Sun, 27 Jan 2019 20:40:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D9BA2A92F; Sun, 27 Jan 2019 20:40:40 +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 C08A32A92D for ; Sun, 27 Jan 2019 20:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727031AbfA0Ukj (ORCPT ); Sun, 27 Jan 2019 15:40:39 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42428 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727133AbfA0Ukj (ORCPT ); Sun, 27 Jan 2019 15:40:39 -0500 Received: by mail-pf1-f196.google.com with SMTP id 64so7039857pfr.9 for ; Sun, 27 Jan 2019 12:40:38 -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=TtrkNJaC1CsUynrxEJE4lhjXyuJShRlDOow8RSN/bhk=; b=XE02BRbmVUUFxt5kerqISSrqG/cacZfPf+1sCRmglqoxOtOiZW1l+8ojkRhx4WTLoa tY7ZbyOasCo2UohNjnhpukco0BBk5RX9JPKuFqzYoo8odXm/AT/m9myYMuF6F5lIHmx5 SWQfqdJD2y4DjWXna+RkcBzyUOv5y6dztBzPlVQ6i7qeaH6B1zJyrRuNDsuOLVc/4Y3T mAb5GPe6KVaEPyRam5LNIVHe4aO7RqdC8akY9g7teKLRErnI6uI6mIydyoEmSD+hNmMp jrBIYoyszEVFYj4u2Atg1tjPdAXujP5TQwiM5oe3IXS3U7bIHkrluIs1/CRk9pgXSLqy G5ow== 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=TtrkNJaC1CsUynrxEJE4lhjXyuJShRlDOow8RSN/bhk=; b=Sg3/5G9uDeXRrrcdosxn3yYOnuvRwx1m5+eDx9puwhNHfGVW8Zbicu+qAxYHm81zT+ ff3ebaVh2yhgAsMhT24j1fIrdLlcuQjW9hGL0gwBN+6qdvt6s8cb1ktTcVNZFjGBi79q 0M6kQClPCBUCkCrfru1A9d6GCdLAHzU9y9H4jCTFVvTgHlfhEyquS1icVKfEAyQ8Q85j VYj08LiPPw6XhBG/iFcVMe5nFJNYGPRKSfRlBDo2Q3ahLgImoQZCHrEXFTx7tmAnMuq2 4HvX29ZhunU/H/ej5nKzF4B2vUXJKuaO85BsK8uRul1NyDfUziaTLv8NAgKIDTyUh+CZ jCHQ== X-Gm-Message-State: AJcUukc9ewwTJIfefp6LC2Qx78puzrCHjHjde1oItAn7XvojNKg6Kd5T yK8BBlIY57euJ2VS6DCu/rArtPntw4Op8g== X-Google-Smtp-Source: AHgI3IaPSyuSlh5b/wt/XWKXoP7d7g7IGZO4Uv3teT4a2EDaszFvH6OQM19bgJDOFj1yFf8Ekt42OA== X-Received: by 2002:a62:5007:: with SMTP id e7mr7084021pfb.92.1548621637642; Sun, 27 Jan 2019 12:40:37 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id a4sm33049912pgv.70.2019.01.27.12.40.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Jan 2019 12:40:37 -0800 (PST) From: Martin Kelly X-Google-Original-From: Martin Kelly , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Daniel Baluta , devicetree@vger.kernel.org, Martin Kelly Subject: [PATCH v3 5/6] iio:bmi160: use iio_pollfunc_store_time Date: Sun, 27 Jan 2019 12:39:10 -0800 Message-Id: <20190127203911.8696-6-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190127203911.8696-1-martin@martingkelly.com> References: <20190127203911.8696-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. Do this by using iio_pollfunc_store_time as other drivers do. Signed-off-by: Martin Kelly --- drivers/iio/imu/bmi160/bmi160_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c index 70739e3920af..de36fe20e023 100644 --- a/drivers/iio/imu/bmi160/bmi160_core.c +++ b/drivers/iio/imu/bmi160/bmi160_core.c @@ -425,8 +425,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, pf->timestamp); done: iio_trigger_notify_done(indio_dev->trig); return IRQ_HANDLED; @@ -834,7 +833,8 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &bmi160_info; - ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL, + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, + iio_pollfunc_store_time, bmi160_trigger_handler, NULL); if (ret < 0) return ret; From patchwork Sun Jan 27 20:39:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10783053 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 62B2313B5 for ; Sun, 27 Jan 2019 20:40:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53FC62A92D for ; Sun, 27 Jan 2019 20:40:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4848D2A930; Sun, 27 Jan 2019 20:40:41 +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 B78192A92E for ; Sun, 27 Jan 2019 20:40:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727172AbfA0Ukk (ORCPT ); Sun, 27 Jan 2019 15:40:40 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37288 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727162AbfA0Ukk (ORCPT ); Sun, 27 Jan 2019 15:40:40 -0500 Received: by mail-pl1-f195.google.com with SMTP id b5so6812029plr.4 for ; Sun, 27 Jan 2019 12:40:39 -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=HG/j4vfMnBaO77CLodtpFhAa3feS3c4GM7XVdmVskHA=; b=jhTNylV1e8XwnNohj8wiwu6DoNXMZ/y4qQDSRjyx/1Z/HMKcmvQnI5PuAZV88kBb5w zmtGzCjUWNGpWBPhfibbYUOPtcpc/ADos5yGSIzKN5b2jxdB659smc/prg0dH0r5XnRb IOVs48EyYeUgsC0uIREtIZY0w00OHssS4oBR/B1qmHcvEMNbgCh2DjCWfiHVIrfDRin6 /EEIBUltK8oUMRJQNulUtjEgii4eMNsFdYw8ZWkz1emWtfIaxXSM1CYn4lr9cH+UqKOW AMoXwgjpHW/bN3QV4IhQnddDGGXzw3LTU4N1I0Zfn/v8kaHE1BQ+5K4DlZXrJHVMefIS CBeQ== 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=HG/j4vfMnBaO77CLodtpFhAa3feS3c4GM7XVdmVskHA=; b=kF23F2gVKOqJz6RzIAW1/oyaoctXZaH21EuLgOTQtob/0h6Nz+EYVOslUoaeziJars vEUfgLggIJ+dj1WeC198BsfZnK+Rx4778U1az9tgngu2zrGYb5zrLC+SwdpL9iu0zhUz MaceEEvo0DkSY2a+wCVdt61mBYRWtfrs4I3nPItqeDS1KRWDThfpFMm7LFoE68l/79mV kHLgSYwvGRRP6QuuMtw7v6kYdrleNMpghjsO9r+IyytcLXjLkcxMcmxLAeCSjRTIyKY2 kXPYRS1aVoMKAPc52qWCThqh8OI+9jX4N6cUe+Ltnlb3GekdGwKohYTSJ25u6ixLxPzQ xQyw== X-Gm-Message-State: AJcUukeUAE4l7cdvMZltgzOTOUJ670zdWXNPgydq3keIIoQxXPRFlQ7F yTvYsViuVe/1REdZsfpmWq2ZDUCV8zUBXg== X-Google-Smtp-Source: ALg8bN76y6v8/Xgkvpgz7+N+4+v9xRk1AL10IXr3gKjlB2YyDHMvHbM21LQmmUUdOrRMmD2BGNSXng== X-Received: by 2002:a17:902:f81:: with SMTP id 1mr18628746plz.174.1548621639097; Sun, 27 Jan 2019 12:40: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 a4sm33049912pgv.70.2019.01.27.12.40.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Jan 2019 12:40:38 -0800 (PST) From: Martin Kelly X-Google-Original-From: Martin Kelly , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Daniel Baluta , devicetree@vger.kernel.org, Martin Kelly Subject: [PATCH v3 6/6] iio:bmi160: use if (ret) instead of if (ret < 0) Date: Sun, 27 Jan 2019 12:39:11 -0800 Message-Id: <20190127203911.8696-7-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190127203911.8696-1-martin@martingkelly.com> References: <20190127203911.8696-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 We are using "if (ret < 0)" in many places in which the function returns 0 on success. Use "if (ret)" instead for better clarity and correctness. Signed-off-by: Martin Kelly --- drivers/iio/imu/bmi160/bmi160_core.c | 40 ++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c index de36fe20e023..6cc11afd395e 100644 --- a/drivers/iio/imu/bmi160/bmi160_core.c +++ b/drivers/iio/imu/bmi160/bmi160_core.c @@ -299,7 +299,7 @@ int bmi160_set_mode(struct bmi160_data *data, enum bmi160_sensor_type t, cmd = bmi160_regs[t].pmu_cmd_suspend; ret = regmap_write(data->regmap, BMI160_REG_CMD, cmd); - if (ret < 0) + if (ret) return ret; usleep_range(bmi160_pmu_time[t], bmi160_pmu_time[t] + 1000); @@ -331,7 +331,7 @@ int bmi160_get_scale(struct bmi160_data *data, enum bmi160_sensor_type t, int i, ret, val; ret = regmap_read(data->regmap, bmi160_regs[t].range, &val); - if (ret < 0) + if (ret) return ret; for (i = 0; i < bmi160_scale_table[t].num; i++) @@ -354,7 +354,7 @@ static int bmi160_get_data(struct bmi160_data *data, int chan_type, reg = bmi160_regs[t].data + (axis - IIO_MOD_X) * sizeof(sample); ret = regmap_bulk_read(data->regmap, reg, &sample, sizeof(sample)); - if (ret < 0) + if (ret) return ret; *val = sign_extend32(le16_to_cpu(sample), 15); @@ -388,7 +388,7 @@ static int bmi160_get_odr(struct bmi160_data *data, enum bmi160_sensor_type t, int i, val, ret; ret = regmap_read(data->regmap, bmi160_regs[t].config, &val); - if (ret < 0) + if (ret) return ret; val &= bmi160_regs[t].config_odr_mask; @@ -420,7 +420,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) indio_dev->masklength) { ret = regmap_bulk_read(data->regmap, base + i * sizeof(sample), &sample, sizeof(sample)); - if (ret < 0) + if (ret) goto done; buf[j++] = sample; } @@ -441,18 +441,18 @@ static int bmi160_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: ret = bmi160_get_data(data, chan->type, chan->channel2, val); - if (ret < 0) + if (ret) return ret; return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: *val = 0; ret = bmi160_get_scale(data, bmi160_to_sensor(chan->type), val2); - return ret < 0 ? ret : IIO_VAL_INT_PLUS_MICRO; + return ret ? ret : IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_SAMP_FREQ: ret = bmi160_get_odr(data, bmi160_to_sensor(chan->type), val, val2); - return ret < 0 ? ret : IIO_VAL_INT_PLUS_MICRO; + return ret ? ret : IIO_VAL_INT_PLUS_MICRO; default: return -EINVAL; } @@ -710,7 +710,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi) struct device *dev = regmap_get_device(data->regmap); ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET); - if (ret < 0) + if (ret) return ret; usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1); @@ -721,12 +721,12 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi) */ if (use_spi) { ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val); - if (ret < 0) + if (ret) return ret; } ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val); - if (ret < 0) { + if (ret) { dev_err(dev, "Error reading chip id\n"); return ret; } @@ -737,11 +737,11 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi) } ret = bmi160_set_mode(data, BMI160_ACCEL, true); - if (ret < 0) + if (ret) return ret; ret = bmi160_set_mode(data, BMI160_GYRO, true); - if (ret < 0) + if (ret) return ret; return 0; @@ -774,7 +774,7 @@ int bmi160_probe_trigger(struct iio_dev *indio_dev, int irq, u32 irq_type) ret = devm_request_irq(&indio_dev->dev, irq, &iio_trigger_generic_data_rdy_poll, irq_type, "bmi160", data->trig); - if (ret < 0) + if (ret) return ret; data->trig->dev.parent = regmap_get_device(data->regmap); @@ -816,11 +816,11 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, data->regmap = regmap; ret = bmi160_chip_init(data, use_spi); - if (ret < 0) + if (ret) return ret; ret = devm_add_action_or_reset(dev, bmi160_chip_uninit, data); - if (ret < 0) + if (ret) return ret; if (!name && ACPI_HANDLE(dev)) @@ -836,7 +836,7 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, ret = devm_iio_triggered_buffer_setup(dev, indio_dev, iio_pollfunc_store_time, bmi160_trigger_handler, NULL); - if (ret < 0) + if (ret) return ret; irq = bmi160_get_irq(dev->of_node, &int_pin); @@ -849,11 +849,7 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, dev_info(&indio_dev->dev, "Not setting up IRQ trigger\n"); } - ret = devm_iio_device_register(dev, indio_dev); - if (ret < 0) - return ret; - - return 0; + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_GPL(bmi160_core_probe);