From patchwork Sat Feb 2 21:55:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10794497 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 BF13813B5 for ; Sat, 2 Feb 2019 21:56:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A68232BFE7 for ; Sat, 2 Feb 2019 21:56:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9506B2D4E0; Sat, 2 Feb 2019 21:56:20 +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 159632D496 for ; Sat, 2 Feb 2019 21:56:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726652AbfBBV4T (ORCPT ); Sat, 2 Feb 2019 16:56:19 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:43607 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726660AbfBBV4T (ORCPT ); Sat, 2 Feb 2019 16:56:19 -0500 Received: by mail-pf1-f193.google.com with SMTP id w73so4993233pfk.10 for ; Sat, 02 Feb 2019 13:56:18 -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=MJHYbUaHLWg1+jAFRAZxMlYgv6YmlcXRIvTmErlwgfmHvUe7+HCWIsV4hIOE5PrP1w Cq2xb35nPfhga9wC7ho5hbFoplKzlYeRn8JyBOaM+aZjWIdhxLJcV5sxbgCqhm2/p9RH uKouj5XsPIGSiXlQ+MkTJ42mlKoivrPGFIIgMnrjvEWnEvss0iyc5v+O3t7qEPOuHQx4 eCHz59vmI/wuUxV13J3cewVoJl+FT/q6428CTVONJxCXpg1vFJz96LHVC0ha5H5Q8qAr NPxeVadJiH6h0DoOcwMbY7d9IJjBvcUjk1Px5XvZCYj9L+bQNXaomiF7yJb8vZIQX9CN Kqiw== 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=DeA79Qh0TV9eNLoSfZdg5TLRNRHh9YxT5BvO4BZ+8RQkKbgooeOIpbHQYdIMXzC9w4 of8ivLqp/q4hpjhKJVE7vg/XUWrN63kE6sZhc4A1hDmZXTIQ5ptKcH5ZFMe14WPS5E41 3xnH4QLtrtSOfTplZM/ymfo3oOCNodj1NVXcgrho8bgZlJH3GLzWHABqAZXqAsW2ukjb IFM/0eoZK4rafpk8cR1xArTpLsQkXtBw7OrEH2cs6hNAmian2JmaaMj1zKLD3wSjeszw 2anDQn5i1reLUVgWFpG71EmyQC0n7EyfzfWp09Afeh2K2TACYz0xrlCYFOP3ki81NIpI xgdw== X-Gm-Message-State: AJcUukdtkHCYL3QC6QILUAojpRRoSlijqzSK7QUtTbUBjZ+CmYnt8GvN RN1G/5QvQGN8XtoU6M7mKHG7lEkH0s4= X-Google-Smtp-Source: ALg8bN6AwAKdRe1DZXy8KX9dmt3yNmsr0cF/PaE1v5tIl79iGJ7crg2s62oChR5ff/AITHXLh6QXgg== X-Received: by 2002:a62:6204:: with SMTP id w4mr45404816pfb.5.1549144578164; Sat, 02 Feb 2019 13:56:18 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id z127sm20082025pfb.80.2019.02.02.13.56.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 13:56:17 -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 v4 1/6] iio:bmi160: add SPDX identifiers Date: Sat, 2 Feb 2019 13:55:56 -0800 Message-Id: <20190202215601.20275-2-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190202215601.20275-1-martin@martingkelly.com> References: <20190202215601.20275-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 Sat Feb 2 21:55:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10794501 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 000A6746 for ; Sat, 2 Feb 2019 21:56:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E502B2BFDF for ; Sat, 2 Feb 2019 21:56:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D962A2D496; Sat, 2 Feb 2019 21:56:23 +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 0FCF52BFDF for ; Sat, 2 Feb 2019 21:56:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726660AbfBBV4W (ORCPT ); Sat, 2 Feb 2019 16:56:22 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41974 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726690AbfBBV4V (ORCPT ); Sat, 2 Feb 2019 16:56:21 -0500 Received: by mail-pg1-f195.google.com with SMTP id m1so4600076pgq.8 for ; Sat, 02 Feb 2019 13:56:21 -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=IL3nXPeVJ6brWYu2R/3o65WhAeliANJmDgqCQrv3iK8=; b=A/MjQoiM518UGDq4iWrnkq0vBnjRzO4opW+AEIIMWc/FlFkRPlKXy3oc6qocVUY5NZ +kQuLoXa9l+nT9VbRr7jYV35N6eFEPJugU2HRnm47AARAM0WXR3imfSudZWw6Ywed24K 2ipyP8muA1I6IbXYdcrxF/cMlRuN9FAScdm0T5j7Aeqgl/oJG352OZ/q3/HmG1V+T24Q 8qhZzgLUc/aTjANadZi4dTuEdua18gIAbqrrr4GaxHO8sVwIhSSC49w9M/7MRX7xHzCi E83odv+MHAIDRF3PdKfVpzSsXKgW2sUWxzLclHlJd/NIEEWopoJihEf3Fq+zq3XMnNT5 7zLA== 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=IL3nXPeVJ6brWYu2R/3o65WhAeliANJmDgqCQrv3iK8=; b=lJwrvx+YMa12HDxdMkyfOdVUz1YDa0qjw8n7g6jGM6iEyOVVC63cI6AXVoHCQNKg7U wO1J2K1b1jZw4FLJuuylwj/lqQfypgvtX30eztWPvx/Q/Wdj9x7T01xZY+XPtFb2TM5Q k9KUJps9IRmLbvviNLJZ+yT5AZO798LxM5Nozv5u1McV2r0XZRDY45dTcQiewEqKOz+H d627ATcDLWuoUbuAScTW7VNLwuVSmgNQEwP1Z8jt8Tu5cFn71AjglWzPAOJjm5h+WFzq 4aYIkUCjQx1LTpbXqG4T9S3kpJCchHPUGftKMp/5iRWfR016KLo2Lv2hgWOoQ50gxLU8 3jWA== X-Gm-Message-State: AHQUAuaYxO9mbzhlVAxnXUGcFKDlrBtas8MUPHU+X9I4rV72nYDOGeYz TP7kstVilMxWuY3jwQ48SVOgbaR6W+c= X-Google-Smtp-Source: AHgI3IYbhywS9N8NQjMm7eO7XO2FBAfODMy5E0Sm78kUl9xQ1v7lGRXevO8B2mOG8Ow3WsE0FKHlFg== X-Received: by 2002:a63:b81a:: with SMTP id p26mr4731283pge.433.1549144580108; Sat, 02 Feb 2019 13:56:20 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id z127sm20082025pfb.80.2019.02.02.13.56.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 13:56:19 -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 v4 2/6] iio:bmi160: add drdy interrupt support Date: Sat, 2 Feb 2019 13:55:57 -0800 Message-Id: <20190202215601.20275-3-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190202215601.20275-1-martin@martingkelly.com> References: <20190202215601.20275-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..007f7c532ac4 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 fall 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, "drive-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 Sat Feb 2 21:55:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10794503 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 CBD5F746 for ; Sat, 2 Feb 2019 21:56:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD7962BFDF for ; Sat, 2 Feb 2019 21:56:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B10D72D496; Sat, 2 Feb 2019 21:56:25 +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 5AAE32BFDF for ; Sat, 2 Feb 2019 21:56:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726690AbfBBV4Y (ORCPT ); Sat, 2 Feb 2019 16:56:24 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42276 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726710AbfBBV4Y (ORCPT ); Sat, 2 Feb 2019 16:56:24 -0500 Received: by mail-pf1-f196.google.com with SMTP id 64so4997858pfr.9 for ; Sat, 02 Feb 2019 13:56:23 -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=cCMSBL+YM9QF6GcPueiLjjJAGqiDvbW99utOUVhBYe0=; b=1pCyROAjjHTuV5er7Rw3xGrA8M4vYVgfLCGtQVkPVyN4WU9hedJmNnkZcJl6BZFPjs XEM2/RY6SSZLntxTDjh/JC2thV1Lu9HFk8KbWQDPUYZQS9jbYJJS8QKH48p7NcVKln6T hDh+Y+VcuAQ8ISf6XMRUGWKZJLyhdoYLSSpl3HYQ7L1wQn//12ecIh6DK8kOg5Jj3M3A nWr2QKnqWbslRjY+myT1uEU6WnNU4bJh9c2rJVTXkNG9a8waVF+Hshb2W1EAaYiCZBX6 rClFRSfEK1i6ZrdBELiAAXCuarLQnHcC4w1SlSXn9qrmdWA8qg+lKLfBI3UIDAw9Z1sB Futg== 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=cCMSBL+YM9QF6GcPueiLjjJAGqiDvbW99utOUVhBYe0=; b=TCZB/B/HRULm13jD++Rf3GGu3uzo+unaAAeeHNBFK8KH8uv0A6BcIIMqsxuTNmF9lI X3YW/Gk4w//kNLpLDMD6ZHK1jAbN1QXZ1Lm9pgUlZk6RP+jw4Wd+Q3t30n3K7pblPBMp RBETLP8tXTBXEcenwnEO4BN+/4ra9zrNQbvjhLRnfD5SFSvGIUXzFpgUTLKEsx7y9NQy uTUDNpdx7z21zuaUiBwm9ekpXtmkdKtUVDRwEUYDNt5SYz+vRbIvLDNZ9jDs9XjtiGOg pxc47Zdone3kqDLZHizoDV6hmF8AATEjWcmhfNqSjn3AcACay80nNarBgu3v0j7vnY1K RIhQ== X-Gm-Message-State: AJcUukcodtqqMShOXQRhFf+yHUA+gEv+VFIIcezps+ldtj8IrA7Zk3Ya TiwWrjYQi8A8R/T0eLjHGjPEygWPUZs= X-Google-Smtp-Source: AHgI3IaVUK8TmvVExqVgsBPreVJPgZZ0LAnRIk75Ed9xQRHcexmLvQ2eMcTulsl8f9DvCRQMud2fuA== X-Received: by 2002:a62:9305:: with SMTP id b5mr24046433pfe.10.1549144582754; Sat, 02 Feb 2019 13:56:22 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id z127sm20082025pfb.80.2019.02.02.13.56.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 13:56:21 -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 v4 3/6] dt-bindings: fix incorrect bmi160 IRQ note Date: Sat, 2 Feb 2019 13:55:58 -0800 Message-Id: <20190202215601.20275-4-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190202215601.20275-1-martin@martingkelly.com> References: <20190202215601.20275-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. Reviewed-by: Rob Herring Signed-off-by: Martin Kelly --- Documentation/devicetree/bindings/iio/imu/bmi160.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.11.0 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 Sat Feb 2 21:55:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10794505 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 7198613B5 for ; Sat, 2 Feb 2019 21:56:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 632252BFDF for ; Sat, 2 Feb 2019 21:56:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5755C2D496; Sat, 2 Feb 2019 21:56:27 +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 F19162BFDF for ; Sat, 2 Feb 2019 21:56:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726710AbfBBV40 (ORCPT ); Sat, 2 Feb 2019 16:56:26 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:46637 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726753AbfBBV4Z (ORCPT ); Sat, 2 Feb 2019 16:56:25 -0500 Received: by mail-pg1-f196.google.com with SMTP id w7so4585209pgp.13 for ; Sat, 02 Feb 2019 13:56:25 -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=F8in0vy/Hvy6LyQX0+LUelBgBHeVg6+YK/wgYarwERQ=; b=JQOp6EZ4X0iqxdBXqrL8DgqlNnHeBUHKjSJCDLXG0IhyzqLRESEDjF3lsEEPnvQwqq un1McS8j2YXKYkjHrwQBtKhPIW+CMBJ7qIbhzkyANq2cXFRZ9dz8hzK+QFdSKNZjbsG1 xKLNVnlw1n+NDBCSGc8fWTyF9sw1eIgy+ZArisMXSKg8BcPr7+YPwu3w2o2vL5mA4J2y /sgeipeooskVQ2bajHELPY6QOFREcRL6K8D8yk1q2dkXPSjCHcTcuUr4gSefrzheqph1 L7vqkSOKX1Fmmf0ddsgRDWtCs685VAu9KDDXP/ZDZv1+5GJHycO7MkoV6nGCfwHewMTZ EqSQ== 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=F8in0vy/Hvy6LyQX0+LUelBgBHeVg6+YK/wgYarwERQ=; b=cCa0Sw+XzaEYKlPiKjqCGqeg62qqk++W3m2V48WRGsnaTmdTgc6BYV7MdqrjS7Haco O4WnIp56asCHz2JeRa0uREwR9EWYIYMG65C9A2V5bIO9wx7J1H0mQbVYjuT1nAMURv4H EqcnZlpmfyivObWSX2NT66XaDIX+qFrbMEAydifSc2a5k4WybeUJjfvXQbFx9XmVGEX4 5tWTnrMpnoWTdpOc8Y9al6VeYYPZgFLGQf7wviIxWeB3F7kmqBEQ+QfxWDXlBXcyPrXn 6wThkdDdjjdpDX0tUc9O3Klib3MbSZi6Cu49s/HnCnwXv0JBPKC8XXS2WjvL4TpREF8m 6EhA== X-Gm-Message-State: AHQUAubdLb4V2Sk+QVBRCqozMyBTNVTYR70a8zDjv3uFIAPRBsjOJ8C9 b67SBGE1pp4b1chwFSNXlWV4cEbIvAI= X-Google-Smtp-Source: AHgI3IbxssVlQQednHWm0F3HHqziV+NAMKLSSjropUtV+6x8wXDogk+ahRhLgNIL9Y8n4CWkCMbbVQ== X-Received: by 2002:a63:170c:: with SMTP id x12mr7306442pgl.364.1549144584730; Sat, 02 Feb 2019 13:56:24 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id z127sm20082025pfb.80.2019.02.02.13.56.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 13:56:24 -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 v4 4/6] dt-bindings: document open-drain property Date: Sat, 2 Feb 2019 13:55:59 -0800 Message-Id: <20190202215601.20275-5-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190202215601.20275-1-martin@martingkelly.com> References: <20190202215601.20275-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..900c169de00f 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 + - drive-open-drain : set if the specified interrupt pin should be configured as + open drain. If not set, defaults to push-pull. Examples: From patchwork Sat Feb 2 21:56:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10794507 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 1594A13B5 for ; Sat, 2 Feb 2019 21:56:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0371E2BFDF for ; Sat, 2 Feb 2019 21:56:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBA802D496; Sat, 2 Feb 2019 21:56:28 +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 956D22BFDF for ; Sat, 2 Feb 2019 21:56:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726753AbfBBV41 (ORCPT ); Sat, 2 Feb 2019 16:56:27 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:44853 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726771AbfBBV41 (ORCPT ); Sat, 2 Feb 2019 16:56:27 -0500 Received: by mail-pf1-f195.google.com with SMTP id u6so4990660pfh.11 for ; Sat, 02 Feb 2019 13:56:27 -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=1boX/x+e8zIPyMRDJMyViHJFELThRLCZN0kTeGhnnB8=; b=PpFpUjQ0zrjYqTg53RgiyUDLI574JQwIqJE5RPAgMXa6ya7RELJxzTzqzaaHLieenZ TSiyFWSDJIjAYTEP20XSBYAw/To588n8LxMTOwQvOYMd9yz1uzPOYAtgUHWN75Ti2qPh nDgCYg/chjjplKdKoqmGykzS0BtOy0IE7sS0ksjNFLzPyQEs8crrWvvd03nJ7677tW5k 2O78vflNuu2L/h5laUj9SWmxtaquPBaAzDWmguucDhHhF7BxHpeBF/bfoPV68pEThPsE OZ1ubb/dSkcIi37WHzz2iXffS6gP/kIyo5WekRMYvx9dHj2QIgKSsyzWwWOz0GcX4g68 XwyA== 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=1boX/x+e8zIPyMRDJMyViHJFELThRLCZN0kTeGhnnB8=; b=YsWhhIBhIKFNj9ZieHGh6eKbSwZrul05IFN9M1MiqO735R3dmKrEmxPHczGUxrrg0R EYC4KiL8IrZE438wXzZe83Ynyv+Ml50nqMhzYOtyzyjJ+hCkQc+uddEn+Cbh4utoC7cu iLr48DJuMwgjhS6nTlu1w7NIl8MMifV6Ex7heKgZd95hWBQHTIGYb/emW2daKAZvoW6v QsiLvRaRFTmmTPD0Px9867CxmSSj7CcPFG2Ib7FRiBDBAeaTor0iUMbDVxdP6itsZUMm eXPwtDAYTj0g07xf2x9/JgrjJxaOEydoLcziiAHxmAQ5Fym7gZiPP+279F+1DxuFR2zW xjRg== X-Gm-Message-State: AHQUAuZ4BA0+dvaofa4idQQ1tCq3kl1dsG2g8MsOG+bIww2GMzjh3rJI +TWAZAa16+miJj94Tr0F+hkfc4+bF+o= X-Google-Smtp-Source: AHgI3IYTbwlcdsjvng9l5XoPJWq2doU4juZAeASUxScc5PXGtHFZfc/J5j99GleXCd3J95yPrwe7lg== X-Received: by 2002:a63:b34f:: with SMTP id x15mr7551849pgt.243.1549144586454; Sat, 02 Feb 2019 13:56:26 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id z127sm20082025pfb.80.2019.02.02.13.56.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 13:56:25 -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 v4 5/6] iio:bmi160: use iio_pollfunc_store_time Date: Sat, 2 Feb 2019 13:56:00 -0800 Message-Id: <20190202215601.20275-6-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190202215601.20275-1-martin@martingkelly.com> References: <20190202215601.20275-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 007f7c532ac4..f3c5b86a281e 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 Sat Feb 2 21:56:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10794509 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 C74AF746 for ; Sat, 2 Feb 2019 21:56:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B85532BFDF for ; Sat, 2 Feb 2019 21:56:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9C612D496; Sat, 2 Feb 2019 21:56:30 +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 253112BFDF for ; Sat, 2 Feb 2019 21:56:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726771AbfBBV43 (ORCPT ); Sat, 2 Feb 2019 16:56:29 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43740 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726784AbfBBV43 (ORCPT ); Sat, 2 Feb 2019 16:56:29 -0500 Received: by mail-pl1-f194.google.com with SMTP id gn14so5004762plb.10 for ; Sat, 02 Feb 2019 13:56:29 -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=Tvvv9GlYcmAwl+5pZu2U15t6n8F1a8a+vsfgMpLluds=; b=MCwFf3RL0fODvpFf640WCnJ1qbtDISc6Jpdw/nHlmBs6aPbhq5021rDUjZZGctI/uj Hwgs69O2JbK2Es4XE7mnJvC6gv7CZVywGjL2BPDx+XR2OW856UHFcVnNuwGiHMlgJuu1 j2ugVxxG5wVUK5CK4Tw71DJfXv4Ylq+jN+drYFb3lVF0q3iWUGcYA0bBP2qmoVeWNsN+ o95gtagOvdg8kW8AvJ++5NNfrwlM4E0qgHWclsn4VuGzwoMdtKg/c9S1xFQfzvSr4KeA U4qmMt9jCI3k8K+i22AkJV2+u67zuPh9ki+aU5EZN/Xgd57F2I51WHhz4uW6V3j9O4An gpQw== 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=Tvvv9GlYcmAwl+5pZu2U15t6n8F1a8a+vsfgMpLluds=; b=V9QqHylSrJpcC9qDVaIe6eJI+6CVTb+X2CYR5AJ/kOS96OvhGEBmxMSYndtla8uXbk lVtYS9igDnWbHVcfQ/Jvcmtp/amxNKET5/5SUFYHNmqkd9mN3jLwa3mLsyGUQDSsJS0j AU1YnY1Faw0z+sxSkAluCNRdZPKH+2PZ9XsDbSXo51pfvbUIttN2ZWH1kXG6BULfZsza KoPWhgmey2sUy4yoxlAI4SsoVhd5ijvDWxqFNH2y9iCSuC/jPuA2CfZd609zEKPrwfxA 6jeSmAENEJmZYVH9TVEFBUJkQF7sdwtOBvebUfGYURckQySYOGPWM4VtlqE0JzECZQ8f 8DOQ== X-Gm-Message-State: AJcUukfHdKsajXIA7ATCVkK3+xZYQNIMyjsf8zGxlDFK1JwFa+4OwUbz n40wef0FDQJeqDsXgnQbU/jQ4bnyufw= X-Google-Smtp-Source: ALg8bN4Gy3ytSVtk3g05+Dh5MeDkmVqdloWWfSwGrmjAjB9atbVH/d5bNPcChIcDEwkx+C+oOUFQVA== X-Received: by 2002:a17:902:8607:: with SMTP id f7mr44157059plo.123.1549144588314; Sat, 02 Feb 2019 13:56:28 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id z127sm20082025pfb.80.2019.02.02.13.56.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 13:56:27 -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 v4 6/6] iio:bmi160: use if (ret) instead of if (ret < 0) Date: Sat, 2 Feb 2019 13:56:01 -0800 Message-Id: <20190202215601.20275-7-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190202215601.20275-1-martin@martingkelly.com> References: <20190202215601.20275-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 f3c5b86a281e..6af65d6f1d28 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);