From patchwork Tue Jan 22 02:04:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10774765 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 8E57D746 for ; Tue, 22 Jan 2019 02:04:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D94A2A2A6 for ; Tue, 22 Jan 2019 02:04:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7109F2A2BB; Tue, 22 Jan 2019 02:04:46 +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 E4FF72A2A6 for ; Tue, 22 Jan 2019 02:04:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726663AbfAVCEp (ORCPT ); Mon, 21 Jan 2019 21:04:45 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:39443 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726756AbfAVCEp (ORCPT ); Mon, 21 Jan 2019 21:04:45 -0500 Received: by mail-pg1-f196.google.com with SMTP id w6so10277373pgl.6 for ; Mon, 21 Jan 2019 18:04:44 -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; bh=+emAylfCxXB91cbBPVb9+jou3+Q2IsPc1dpIh7YBHNw=; b=ELvrrYdkS1KN7JJ6CocQLVQXkN2CLFBkT/gNkHZytLdLJ+gEiHL8lK7qhybZisWJQd HCIC9Hu9/MwmuSMyyvHtwah2MJwtw922OgfCoGbbaD/UTE9MDyXyp9oyrv4tXWkwTwpn MpLzIVG1nTBW2Xn3F6jzvppZIRCtk8E8PQjRnyyZXe8lh08G4LrsLt8WVQeqqhlRfRdI aTwrUwxHG0e3mLgJBDRbyen911Vbz423n2kgNE1/cSmfLYFsHjZV+OaEpIhvNfqmv6aN bYffIAKdQOE1GhqGlxN6GqMvg2Nezeka9uyAOVfFcQruiF3yaLf5luPCnaMFBZkpISyr tebg== 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; bh=+emAylfCxXB91cbBPVb9+jou3+Q2IsPc1dpIh7YBHNw=; b=q27sYXlRQDnlodetqRz5VYuHZ/xWth5UgdqKgjckGh8IwV3U+cInE0i9JMy3BGXrbs gX/o691vgaPYu3ColZCumlaAYrwpR0YYhOl8Ecc5nMrvl7xahCBseqnqHXJOzgs2pZM9 8ntSX4Q9efqQDvP5A/E5Doe6k/vsnbySnVZ436OAk36UpaY6PcHJtOtC2+BWOydPJKFW lHwp/WDbfALiP1tMhMpu01DQOsHnmQZ2lu5AnDiMw6aEA5/TzLFqYMTJrbhOKWbet7RW dgP/z8c05oyGvIu5T9pM8WkJBWcYBqp4ZvdA4P61M1cIFvMOZdolQwZTQ8Bn6TSSdrpY pP0Q== X-Gm-Message-State: AJcUukf23UnvO3UGgVFlpjKnVPSw07yKGCTHzk5sjHDaONn9LtB0qvcd L4x8xl5HQELPTXXmsOdZfC1GHPsXTEo= X-Google-Smtp-Source: ALg8bN5QAjDzGiWNn4IuiO87o8INoxCa3IQFatxHmrxNSiWDJclVeSthSqpdEUOQvDysKsnFXIBOOQ== X-Received: by 2002:a63:eb52:: with SMTP id b18mr29514958pgk.213.1548122683923; Mon, 21 Jan 2019 18:04:43 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id n21sm19759404pfg.84.2019.01.21.18.04.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 18:04:43 -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 v2 1/6] iio:bmi160: add SPDX identifiers Date: Mon, 21 Jan 2019 18:04:26 -0800 Message-Id: <20190122020431.5338-1-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 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 Tue Jan 22 02:04:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10774767 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 677D5913 for ; Tue, 22 Jan 2019 02:04:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55A422A2AA for ; Tue, 22 Jan 2019 02:04:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47C092A2A6; Tue, 22 Jan 2019 02:04:49 +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 518AE2A2A6 for ; Tue, 22 Jan 2019 02:04:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726756AbfAVCEr (ORCPT ); Mon, 21 Jan 2019 21:04:47 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:43132 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbfAVCEr (ORCPT ); Mon, 21 Jan 2019 21:04:47 -0500 Received: by mail-pl1-f193.google.com with SMTP id gn14so10642101plb.10 for ; Mon, 21 Jan 2019 18:04: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=R4X2HccFXs6fmY26kbVoQ1Lz2tQsOzlR/hgf7JThecI=; b=t+TM3DvczSBcxN+5XcaGChFYuElmOPH1dymS1X6HyGpYh0q2nIcKzZ1/IDCZo5KejS A2LzBgYJPmcnzzMbKyP2KEiG0CWdO+Lu4JI7oBt4hahaDvp5J5x3JixVHVBdQvH6OH0X iduMlUvG1HeWWNKqNtUtFdlqQ4qOSxcAL7lXRBrhiKrUjrH4CR1GXxzC6xW41VBv/HNS H7Yyz+RyIrcGoeuxAArQIawUkOw6Aq+UlvKkxr477z8mzJ8IxbUMOb6P65RFuzOBFBRd kx/3beX3rfW7idSHyeqN84STjZ27RD3Ptl7kr/ZQewg6lFGf8ZRbT6hM0chmwbQWtqfi S9gw== 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=R4X2HccFXs6fmY26kbVoQ1Lz2tQsOzlR/hgf7JThecI=; b=FqK6V38197QHAGpiVFbDkrwznrRatx+bQT6yzurUM3EdFveu3oxYfgk6s8kxAySmUP bnx0hyO1gEvTaTmAsVLecB8yRIfO2RRWS/6r3d6a7CNZ0gmVdMRmFQwSujEkvT/Xzf87 5WTnCsJ3Xd2D0KO9CI77kWUQ+grGRrKkboHn58yv0Z1/yQe8WEIubW7Ljs7IA27xIHHo V25eGfETTn2bjIN8XoYCAA8DNvBQrIi7QXMR4PyjlojibJfqCTfu5fxMSh/wFzCli+At 47QnnqlaEnYuTxKYZ0j1/vQH2JG6Nnl9xB7qahJsVpTc444pbcXowgdoQfW9kV9a8HLm YyLA== X-Gm-Message-State: AJcUukex094eA5OqUBLOlWWeP2zPEIQ6JZxq9EJXN05pg9Sqefpy99Nm Vu+tz4aSbBG8m0EIu5euCR9+fhRcKi8= X-Google-Smtp-Source: ALg8bN5reWO4R2LCDCWcfDFs6jNbFRwEn9SubjqD0HQ/4RmfzySFAgEGqJZjyMPCF5FosjNrcioHlw== X-Received: by 2002:a17:902:9687:: with SMTP id n7mr11500514plp.94.1548122686053; Mon, 21 Jan 2019 18:04:46 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id n21sm19759404pfg.84.2019.01.21.18.04.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 18:04:45 -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 v2 2/6] iio:bmi160: add drdy interrupt support Date: Mon, 21 Jan 2019 18:04:27 -0800 Message-Id: <20190122020431.5338-2-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190122020431.5338-1-martin@martingkelly.com> References: <20190122020431.5338-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 --- v2: - Drop "BOTH" interrupt setting. - Change to "if (ret)" instead of "if (ret < 0)". - Stylistic changes suggested by Jonathan Cameron. - Fix bogus return check after iio_trigger_get. arch/arm/boot/dts/Makefile | 1 + drivers/iio/imu/bmi160/bmi160.h | 13 +- drivers/iio/imu/bmi160/bmi160_core.c | 294 ++++++++++++++++++++++++++++++++++- drivers/iio/imu/bmi160/bmi160_i2c.c | 3 +- drivers/iio/imu/bmi160/bmi160_spi.c | 2 +- 5 files changed, 303 insertions(+), 10 deletions(-) -- 2.11.0 diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile index b0e966d625b9..df68910fc2c1 100644 --- a/arch/arm/boot/dts/Makefile +++ b/arch/arm/boot/dts/Makefile @@ -701,6 +701,7 @@ dtb-$(CONFIG_SOC_AM33XX) += \ am335x-base0033.dtb \ am335x-bone.dtb \ am335x-boneblack.dtb \ + am335x-boneblack-bmi160-i2c1.dtb \ am335x-boneblack-wireless.dtb \ am335x-boneblue.dtb \ am335x-bonegreen.dtb \ 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..c848fc1bce61 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_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 +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,7 +524,209 @@ 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) + 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; + 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 = 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) + return ret; + + return 0; +} + +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 bool bmi160_parse_irqname(struct device_node *of_node, int irq, + enum bmi160_int_pin *pin) +{ + 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) { + *pin = BMI160_PIN_INT1; + return true; + } + + ret = of_irq_get_byname(of_node, "INT2"); + if (ret == irq) { + *pin = BMI160_PIN_INT2; + return true; + } + + return false; +} + +static int bmi160_config_device_irq(struct iio_dev *indio_dev, + int irq, int irq_type) +{ + int ret; + bool success; + enum bmi160_int_pin int_pin; + bool open_drain; + const char *pin_name; + 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; + } + + success = bmi160_parse_irqname(dev->of_node, irq, &int_pin); + if (!success) { + dev_err(&indio_dev->dev, + "interrupt-names for IRQ %d must be set to either \"INT1\" or \"INT2\"", + irq); + return -EINVAL; + } + + open_drain = of_property_read_bool(dev->of_node, "bmi160,open-drain"); + + ret = bmi160_config_pin(data->regmap, int_pin, open_drain, irq_mask, + BMI160_NORMAL_WRITE_USLEEP); + if (ret) { + switch (int_pin) { + case BMI160_PIN_INT1: + pin_name = "INT1"; + break; + case BMI160_PIN_INT2: + pin_name = "INT2"; + break; + } + dev_err(&indio_dev->dev, "Failed to configure %s IRQ pin", + pin_name); + 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) + return ret; + + ret = bmi160_probe_trigger(indio_dev, irq, irq_type); + if (ret) + return ret; + + return 0; +} + +static int bmi160_chip_init(struct bmi160_data *data, bool use_spi, int irq) { int ret; unsigned int val; @@ -518,7 +749,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi) } 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; } @@ -539,6 +770,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; @@ -548,7 +822,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; @@ -562,7 +836,7 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, dev_set_drvdata(dev, indio_dev); data->regmap = regmap; - ret = bmi160_chip_init(data, use_spi); + ret = bmi160_chip_init(data, use_spi, irq); if (ret < 0) return ret; @@ -585,6 +859,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) + 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[] = { From patchwork Tue Jan 22 02:04:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10774769 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 A3ED71580 for ; Tue, 22 Jan 2019 02:04:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94B2C2A2A6 for ; Tue, 22 Jan 2019 02:04:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88FC32A2AA; Tue, 22 Jan 2019 02:04:49 +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 36EFD2A2BB for ; Tue, 22 Jan 2019 02:04:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726814AbfAVCEs (ORCPT ); Mon, 21 Jan 2019 21:04:48 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36304 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726819AbfAVCEs (ORCPT ); Mon, 21 Jan 2019 21:04:48 -0500 Received: by mail-pg1-f196.google.com with SMTP id n2so10285906pgm.3 for ; Mon, 21 Jan 2019 18:04:48 -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=dwuZqCQsZawaLUa3kw+sSM1yddHKcNSfgi6uyOZEYjU8ISOt/pg5v+yeJ6AQqFbgyO WAcwpuxoQWdSThbiHMYNP+KiiEM8sUjM1Wzt4qap32odHxp2u9QgysaQu/LrTow7ZkOA RrM3qJ2Mt/G9ZidrYNft152bBXz071Otfq6B1HrsOO4eEVgftq35vLEWtX6dJhpuiRAo LDwWG8qGb2DYfQHh8Q5UCCx+3hxqFJGC/NH5IdGzQVMJ2eq9ecZHI/4ya9l7i5AxTHmQ siti7sZmxliRWoFmxBT/tJkXRV41gj03YbiJ9sFENMTI+Rw69r51+w7+dzGkUZn8LCXn i+7w== 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=pnjscpT3YL9SC/b5yfucfCbxBOi4OqWkX91ti7TYF7YtZlxfTZ253ey836NukYV2f1 KGp12aEX5qJZLUFL/jfTg0bqSQeqsQ8GFdPKuzhx9P59fcPMJDEF9zjQ7MOy/4H/UTJj 6MJMHT6WaebBqXiFG+yMi8pRAlh46CfrT393jAIJzhNFvPKN1ZwVx1YH1jhq6hDd7gP5 1YDlSkYWjtZ7w2T15EF1VIOQgRN7pPCz5ou43RSHg2jgse3yblrarKZZ9jHhLlaVPfEQ u0+4TPpH5YQlJiLgufAaGz0v4lArV74GLl3A7ot2g33CQVU6qZMwu+9O4HRcsJSfDrD5 YIow== X-Gm-Message-State: AJcUukdFoRaZYZ1wLcPVf00CBoiNP8iTBXsocfPzvSyedfCgXX3OHf+Z z8ox8d13xiwWu374l1O7d6TojYW/noQ= X-Google-Smtp-Source: ALg8bN7Hp9awGnxLt8iunNVeXUVnGOll4TrqrhDRNOfRqA+lsEb/TvC5MzKsemn3wdAq7I0jcFqLjQ== X-Received: by 2002:a63:a112:: with SMTP id b18mr30401698pgf.440.1548122687498; Mon, 21 Jan 2019 18:04: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 n21sm19759404pfg.84.2019.01.21.18.04.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 18:04:46 -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 v2 3/6] dt-bindings: fix incorrect bmi160 IRQ note Date: Mon, 21 Jan 2019 18:04:28 -0800 Message-Id: <20190122020431.5338-3-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190122020431.5338-1-martin@martingkelly.com> References: <20190122020431.5338-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 Tue Jan 22 02:04:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10774771 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 9A7E3746 for ; Tue, 22 Jan 2019 02:04:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 897A82A2A6 for ; Tue, 22 Jan 2019 02:04:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DE5E2A2BB; Tue, 22 Jan 2019 02:04: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 5D1B82A2A6 for ; Tue, 22 Jan 2019 02:04:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726819AbfAVCEu (ORCPT ); Mon, 21 Jan 2019 21:04:50 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:42157 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726827AbfAVCEt (ORCPT ); Mon, 21 Jan 2019 21:04:49 -0500 Received: by mail-pf1-f194.google.com with SMTP id 64so10943750pfr.9 for ; Mon, 21 Jan 2019 18:04:49 -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=keX0n0PJLRDWTAYQtXV7nGuK12sjngmi9oXCHHIANwFvBuR8ZYJEWeZTh5cxR3V80B CJuQcixiwMqKGyp3dHpgWMBCe2v+MN1LzutvArBvPfcQRJhv3k51v+2Vq9AlFBZIo/eC ZDGoXXhumhLAgGJy20fDvB1vMycyA3uM9QPbsgG003ldk3nQBVs0FOUdHOBX85zkU/FJ wlPAh48dq1EjervCJNDmsefn03b6ne5K3uViNJTzUO1lvZ/MO8Bs6zo05NDowJ84e73S L5hI+3Jw0fRYuY6RJQx1Qj/YJW1qCn2N82Oxm1GlQF0F1y2mYp4vt3TpyXyOHFvRaqP3 jYDA== 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=lbkGHWF1pElO2pD3HfrRdecX8sf8N1X5YuV74n12AKgt2HConCj3FeGc6bcQ5TS67I yvOFsGlUcWntIseED9x0ZwXEMrRxgR+VXekXicl2uGOOx8HXcwzmuiIv3KjnFmzM2cwm y4VG7Q+v+9SxEjA2/py9m9L2KHjqK2npcntTFSYVCUxK4nbtbQosf/IWXRcVe6qTeNux 53vakqBOrtPRU1E26zHqDb8rj6KfGddSKvulXLCAZ/L5JXvBRmc7cVCcgjMfRulRnkQU XoyQz9+FNuilQ0KpAykvvRL4JmiM3P39EcvyuKndeST+3LVfZkNGMY9JBrh0xASfkvyT +ohw== X-Gm-Message-State: AJcUuke8kIwuE9r7/qqZ0bBMRU6ycj0aJa58st3uV0+YCR604R//84vo R3+kKLkBcHQcCrY7gERbsJuEqS31/yM= X-Google-Smtp-Source: ALg8bN4TP9jXNTjg1S5Z0h5Ba8ENVoBPg5SIY72syUxLfJVg+Ssu5TP078poQx1swmn6fxLybOk8vw== X-Received: by 2002:a65:4646:: with SMTP id k6mr25185414pgr.153.1548122688677; Mon, 21 Jan 2019 18:04:48 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id n21sm19759404pfg.84.2019.01.21.18.04.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 18:04:48 -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 v2 4/6] dt-bindings: document open-drain property Date: Mon, 21 Jan 2019 18:04:29 -0800 Message-Id: <20190122020431.5338-4-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190122020431.5338-1-martin@martingkelly.com> References: <20190122020431.5338-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 Tue Jan 22 02:04:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10774773 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 720B7913 for ; Tue, 22 Jan 2019 02:04:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6173A2A2A6 for ; Tue, 22 Jan 2019 02:04:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55F862A2BB; Tue, 22 Jan 2019 02:04:52 +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 017012A2A6 for ; Tue, 22 Jan 2019 02:04:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726881AbfAVCEv (ORCPT ); Mon, 21 Jan 2019 21:04:51 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:35740 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726875AbfAVCEv (ORCPT ); Mon, 21 Jan 2019 21:04:51 -0500 Received: by mail-pf1-f196.google.com with SMTP id z9so10970478pfi.2 for ; Mon, 21 Jan 2019 18:04:50 -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=9zzj010WZSA0DL8/MImmeoLSgz4mP+VjZ9gv0MeoU+w=; b=FwoyFzPEhEtPFTClZPJ13OV5As4/KezduvnhQ3x7h5Pxm6UEIr0Lf5Z4/6vhBIdtsv dJvrhAv08XMPqL6ICpVmfxtIiDPuLi3XUGpesetQZ9INs0tkn24IhZzzHbWfu2JDXZiB OQViCwe+4RkWaZjN5EahkjltOQxBKZbAG2MiR4zJwI7fxKcgf3M5hjS2Rczaf63bLLup /2MmJK+xwUWRYtEWbhYoyz45NfHohTth6tZjYzkr/VSU5xqzzJA/aDsu1rS+kF5m7epu N/WRIcU/+S62att/5ZBupIZ/EqLHP786+EGN3rcIbeLUzCGrU0LREHAga1NlrC0KkFuv oI+A== 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=9zzj010WZSA0DL8/MImmeoLSgz4mP+VjZ9gv0MeoU+w=; b=fvOsb8GBe0E5nFfiubqfNEFgaPc1OSQE+MzY+lBk1j5iwOj0L7g43wfNlXDdf4cSI6 7Inghae3JO5VEqECU29nXsu1qpluY/8MnRLcJnP3wECH1JGU3d+CfcxD57oF3nYd2QSH slHT8WhBcAqKxNQiQ2mjD3QQ50lE2boQIw92Xjej7hz9qOcxAmPQQK6aW7RyIauaq9d9 ndjyIeBfufZt3c/p7Y3DOwB5eXx1TbZaLS1uZtNeq+UrlA7URnlgyIuwY6LN88yJQEzt UhC9C7EgDeqBYR5pWDtjFslT9v4fg4dlEhzZRg4kmW+Cz8iCkScVteRAazlOR/OoFcpK VCiw== X-Gm-Message-State: AJcUukcVeRe+faPd2ylYJlvN61EquPP9JCp+8NmAk96UY3ZCoQ/f88dz h1FnRopUSe+LN8McB3TY9TEtqyThRZ8= X-Google-Smtp-Source: ALg8bN4lDgDhoTiVS67Oa2Aojw4NI+Dy8/9KDcGwoomlJV7jmZ0N6zhh4irdb0uj+gjtL8rh78I/5w== X-Received: by 2002:a62:26c7:: with SMTP id m190mr32277206pfm.79.1548122689923; Mon, 21 Jan 2019 18:04:49 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id n21sm19759404pfg.84.2019.01.21.18.04.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 18:04:49 -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 v2 5/6] iio:bmi160: use iio_pollfunc_store_time Date: Mon, 21 Jan 2019 18:04:30 -0800 Message-Id: <20190122020431.5338-5-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190122020431.5338-1-martin@martingkelly.com> References: <20190122020431.5338-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 --- v2: - Use iio_pollfunc_store_time. drivers/iio/imu/bmi160/bmi160_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c index c848fc1bce61..dca53be066e1 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; @@ -854,7 +853,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 Tue Jan 22 02:04:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 10774775 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 1E627913 for ; Tue, 22 Jan 2019 02:04:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E30A2A2A6 for ; Tue, 22 Jan 2019 02:04:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02C3E2A2BB; Tue, 22 Jan 2019 02:04:53 +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 807D92A2AA for ; Tue, 22 Jan 2019 02:04:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726827AbfAVCEw (ORCPT ); Mon, 21 Jan 2019 21:04:52 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:43213 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726875AbfAVCEw (ORCPT ); Mon, 21 Jan 2019 21:04:52 -0500 Received: by mail-pg1-f193.google.com with SMTP id v28so10272240pgk.10 for ; Mon, 21 Jan 2019 18:04:51 -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=NvPd3WMGgFHrNJUvFjzTxAPvqUZN2CkFtmwIKx5KcvQ=; b=rKjIoGOnpNxouy4yFQhT0BiOwrd7iOLMvhYha0lqxvLzGVlpJrjBMCToLpn3ddAafe 81BQarpgbLKx5sp3PqQqBkzsbUl8AarIo1o3Yu6iRKb3B+kYeTnNnT6fO5iJ8uy+hwtB QPToIjm72enOfI+iTlA/eUI9Tjq/+eUVgT11U+XfmAYDprBofYAubhA+gZOM4y1X83OB NwFj/obaRTvejjYBgcGVHDA7951pvnBAXwUbOJppT1AKsCAlPXmHkAYtdhNrPRBkdN9O VALJy6mgE+WKrNzxBoKENSHfPeF6W33mRmFTBYnva/UFkNDGv5rHvOPwG7+irySHERNf zqCw== 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=NvPd3WMGgFHrNJUvFjzTxAPvqUZN2CkFtmwIKx5KcvQ=; b=hBlsjVDjerfSBzkaszQ8AjEOjf1fg/2uVUZURSW1EXoU9Imz/39Ywvd3PpRDO+IljA Ffg3CYNLu6E6qHM0gCR+h/4LeAwL5+P1zhIVg+saSwt1L07hre6CL6Qg5hTA4Z/nvV1Z WGMEInZyhctlFyxlTfxCqzQ4BxXI+/a18qhRX7hEC2C/yrIzChAAAGDJuOE8N2zJk7C3 B/IYLH4Hh1nM+ADV8ok76nZw0Lzwwqqze5VQ5/mVxwZ5+hzuEvK5RBEB7HMx900PFBSx My134+RNJ5JcW/q6YDiqOVG5WdQ063DMx30BPTt/V2AAZDvXN3OUwyIYALaWHQza3IxE nE3g== X-Gm-Message-State: AJcUukc4nRJBWtTJF4AH6wYsafpsOf8JEhV/BoMPc70Q0FJHPRo6uBg0 uqztcONjhjRb9sD4gxxu0aRoiPK8mRc= X-Google-Smtp-Source: ALg8bN4Z4sp4UjIXFboz8LKlyejd7GtwnX0ENgGoN0rCPG+x9ulUqJRMy9jCa7EFYq3hPUGlfhdxFA== X-Received: by 2002:a63:6103:: with SMTP id v3mr29398559pgb.75.1548122691244; Mon, 21 Jan 2019 18:04:51 -0800 (PST) Received: from cascade.Home (174-21-177-9.tukw.qwest.net. [174.21.177.9]) by smtp.gmail.com with ESMTPSA id n21sm19759404pfg.84.2019.01.21.18.04.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 18:04:50 -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 v2 6/6] iio:bmi160: use if (ret) instead of if (ret < 0) Date: Mon, 21 Jan 2019 18:04:31 -0800 Message-Id: <20190122020431.5338-6-martin@martingkelly.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190122020431.5338-1-martin@martingkelly.com> References: <20190122020431.5338-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 | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c index dca53be066e1..0ec9ded975e2 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; } @@ -732,7 +732,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi, int irq) 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); @@ -743,7 +743,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi, int irq) */ if (use_spi) { ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val); - if (ret < 0) + if (ret) return ret; } @@ -759,11 +759,11 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi, int irq) } 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; @@ -796,7 +796,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); @@ -836,11 +836,11 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, data->regmap = regmap; ret = bmi160_chip_init(data, use_spi, irq); - 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)) @@ -856,7 +856,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; if (irq) { @@ -866,7 +866,7 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap, } ret = devm_iio_device_register(dev, indio_dev); - if (ret < 0) + if (ret) return ret; return 0;