Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1995379ybm; Sun, 31 May 2020 05:21:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyv2uy37aMgQ3Eyju410lteSyz6BZV2UfmO2hhPmjCtGooYQzb76jYAduAGWYIv64eWInQS X-Received: by 2002:a05:6402:1d82:: with SMTP id dk2mr15080989edb.75.1590927665278; Sun, 31 May 2020 05:21:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590927665; cv=none; d=google.com; s=arc-20160816; b=lO/ekL9oFJv7nc+/ZVOkGDF+cuRxGTt7n5yx9cevBtXGhRR5SPhpzwctaejZYha5Fm QRgggpro6jodEfMSnEHvB5fA+sw7wCQm2qUyP94hxHhj2DvjNfL4W9bCajb7z9Thb/3I D7lRnnbPan95jYDyuDUV5Tp5YJvetdDcSwRi75PN4Dnq9Dv1LbLzu6eVcSHneLYtqQuf FUX6USmS8qlquwHa67FvRjaHPkrQ8BewmnJVWQbTJsEqbHPLV0RAK7fvHo/MvS/xIafo /Z7UvX2oqKZzgc5kMIENdNKpDXMvSkcf1ki6EJfnXptUWOE2Ig9FfOh04rPqwBqItvnn /e3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=P7EhZffO5m7XoyshgEIN4sKJ0Hq9qkZnHmMr5fKUSWU=; b=SfS6esKWrayiHP4fxWLFmtmVY3CxMLxiPmpWl8XVAzySU/Bei2LGvrTcaD0N69mYWC 0Sx8NRY0NMEMQhLM388qEsj4Nn/SjHRvR942o8VwBu2UQiskfwd5hp2pl4FcD+HzBlZs KxYVXdUjK2SVcep9OB2rGY/dhwGs/krSXZIdGVjXan0BLZ9UCV69gKkWql0aauQUibEp tzll4v7d/iPtO+fSme8OhWU9N2Uxjgb06cN2okOtMqBKkafs0449x3ligWlGXPrJoBI/ Qxe7oaT8UK2IJ8zd6l4RQwUGY7EEsZm2ux9Jb2nPbKSiiZNmezxCIavBwwWi5KAlp+Nw H1mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2ajgG3bS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si9004224ejh.293.2020.05.31.05.20.42; Sun, 31 May 2020 05:21:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2ajgG3bS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728941AbgEaMQR (ORCPT + 99 others); Sun, 31 May 2020 08:16:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:44256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725898AbgEaMQR (ORCPT ); Sun, 31 May 2020 08:16:17 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 35E98206F1; Sun, 31 May 2020 12:16:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590927376; bh=J6x4b1+MubT5rZbsJ2uqsOH9lZsuOHOocKwqIBws2Rg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=2ajgG3bSz03K1Hs33T7dsZdTWN8bAYzqPMckH1k/eqGixqH1WGEU5S0J4F0LDc9lx SJW1mkxMM5VYC79G0LlDtWflkAJKPonxI8BnkDCZU94SQ6RAwr89Hjvh7xoCNaw1k4 e3ooc9erBqj81p34kmV7M3+vxjZaXYk4DsOe5+tU= Date: Sun, 31 May 2020 13:16:12 +0100 From: Jonathan Cameron To: Jean-Baptiste Maneyrol Cc: robh+dt@kernel.org, robh@kernel.org, mchehab+huawei@kernel.org, davem@davemloft.net, gregkh@linuxfoundation.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 08/12] iio: imu: inv_icm42600: add device interrupt Message-ID: <20200531131612.027433a5@archlinux> In-Reply-To: <20200527185711.21331-9-jmaneyrol@invensense.com> References: <20200527185711.21331-1-jmaneyrol@invensense.com> <20200527185711.21331-9-jmaneyrol@invensense.com> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 27 May 2020 20:57:07 +0200 Jean-Baptiste Maneyrol wrote: > Add INT1 interrupt support. Support interrupt edge and level, > active high or low. Push-pull or open-drain configurations. > > Interrupt will be used to read data from the FIFO. > > Signed-off-by: Jean-Baptiste Maneyrol Some nitpicks inline - all cases where a blank line would slightly help readability. J > --- > drivers/iio/imu/inv_icm42600/inv_icm42600.h | 2 +- > .../iio/imu/inv_icm42600/inv_icm42600_core.c | 96 ++++++++++++++++++- > .../iio/imu/inv_icm42600/inv_icm42600_i2c.c | 3 +- > .../iio/imu/inv_icm42600/inv_icm42600_spi.c | 3 +- > 4 files changed, 100 insertions(+), 4 deletions(-) > > diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600.h b/drivers/iio/imu/inv_icm42600/inv_icm42600.h > index c534acae0308..43749f56426c 100644 > --- a/drivers/iio/imu/inv_icm42600/inv_icm42600.h > +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600.h > @@ -372,7 +372,7 @@ int inv_icm42600_set_temp_conf(struct inv_icm42600_state *st, bool enable, > int inv_icm42600_debugfs_reg(struct iio_dev *indio_dev, unsigned int reg, > unsigned int writeval, unsigned int *readval); > > -int inv_icm42600_core_probe(struct regmap *regmap, int chip, > +int inv_icm42600_core_probe(struct regmap *regmap, int chip, int irq, > inv_icm42600_bus_setup bus_setup); > > int inv_icm42600_gyro_init(struct inv_icm42600_state *st); > diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c > index e7f7835aca9b..246c1eb52231 100644 > --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c > +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c > @@ -9,8 +9,11 @@ > #include > #include > #include > +#include > +#include > #include > #include > +#include > #include > #include > > @@ -409,6 +412,79 @@ static int inv_icm42600_setup(struct inv_icm42600_state *st, > return inv_icm42600_set_conf(st, hw->conf); > } > > +static irqreturn_t inv_icm42600_irq_handler(int irq, void *_data) > +{ > + struct inv_icm42600_state *st = _data; > + struct device *dev = regmap_get_device(st->map); > + unsigned int status; > + int ret; > + > + mutex_lock(&st->lock); > + > + ret = regmap_read(st->map, INV_ICM42600_REG_INT_STATUS, &status); > + if (ret) > + goto out_unlock; > + > + /* FIFO full */ > + if (status & INV_ICM42600_INT_STATUS_FIFO_FULL) > + dev_warn(dev, "FIFO full data lost!\n"); > + > +out_unlock: > + mutex_unlock(&st->lock); > + return IRQ_HANDLED; > +} > + > +/** > + * inv_icm42600_irq_init() - initialize int pin and interrupt handler > + * @st: driver internal state > + * @irq: irq number > + * @irq_type: irq trigger type > + * @open_drain: true if irq is open drain, false for push-pull > + * > + * Returns 0 on success, a negative error code otherwise. > + */ > +static int inv_icm42600_irq_init(struct inv_icm42600_state *st, int irq, > + int irq_type, bool open_drain) > +{ > + struct device *dev = regmap_get_device(st->map); > + unsigned int val; > + int ret; > + > + /* configure INT1 interrupt: default is active low on edge */ > + switch (irq_type) { > + case IRQF_TRIGGER_RISING: > + case IRQF_TRIGGER_HIGH: > + val = INV_ICM42600_INT_CONFIG_INT1_ACTIVE_HIGH; > + break; > + default: > + val = INV_ICM42600_INT_CONFIG_INT1_ACTIVE_LOW; > + break; > + } blank line here > + switch (irq_type) { > + case IRQF_TRIGGER_LOW: > + case IRQF_TRIGGER_HIGH: > + val |= INV_ICM42600_INT_CONFIG_INT1_LATCHED; > + break; > + default: > + break; > + } blank line here. > + if (!open_drain) > + val |= INV_ICM42600_INT_CONFIG_INT1_PUSH_PULL; blank line here > + ret = regmap_write(st->map, INV_ICM42600_REG_INT_CONFIG, val); > + if (ret) > + return ret; > + > + /* Deassert async reset for proper INT pin operation (cf datasheet) */ > + ret = regmap_update_bits(st->map, INV_ICM42600_REG_INT_CONFIG1, > + INV_ICM42600_INT_CONFIG1_ASYNC_RESET, 0); > + if (ret) > + return ret; > + > + return devm_request_threaded_irq(dev, irq, NULL, > + inv_icm42600_irq_handler, irq_type, > + "inv_icm42600", st); > +} > + > static int inv_icm42600_enable_regulator_vddio(struct inv_icm42600_state *st) > { > int ret; > @@ -453,11 +529,14 @@ static void inv_icm42600_disable_pm(void *_data) > pm_runtime_disable(dev); > } > > -int inv_icm42600_core_probe(struct regmap *regmap, int chip, > +int inv_icm42600_core_probe(struct regmap *regmap, int chip, int irq, > inv_icm42600_bus_setup bus_setup) > { > struct device *dev = regmap_get_device(regmap); > struct inv_icm42600_state *st; > + struct irq_data *irq_desc; > + int irq_type; > + bool open_drain; > int ret; > > if (chip < 0 || chip >= INV_CHIP_NB) { > @@ -465,6 +544,17 @@ int inv_icm42600_core_probe(struct regmap *regmap, int chip, > return -ENODEV; > } > > + /* get irq properties, set trigger falling by default */ > + irq_desc = irq_get_irq_data(irq); > + if (!irq_desc) { > + dev_err(dev, "could not find IRQ %d\n", irq); > + return -EINVAL; > + } nitpick: Blank line here > + irq_type = irqd_get_trigger_type(irq_desc); > + if (!irq_type) > + irq_type = IRQF_TRIGGER_FALLING; blank line here. > + open_drain = device_property_read_bool(dev, "drive-open-drain"); > + > st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); > if (!st) > return -ENOMEM; > @@ -518,6 +608,10 @@ int inv_icm42600_core_probe(struct regmap *regmap, int chip, > if (ret) > return ret; > > + ret = inv_icm42600_irq_init(st, irq, irq_type, open_drain); > + if (ret) > + return ret; > + > /* setup runtime power management */ > ret = pm_runtime_set_active(dev); > if (ret) > diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_i2c.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_i2c.c > index 4789cead23b3..85b1934cec60 100644 > --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_i2c.c > +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_i2c.c > @@ -64,7 +64,8 @@ static int inv_icm42600_probe(struct i2c_client *client) > if (IS_ERR(regmap)) > return PTR_ERR(regmap); > > - return inv_icm42600_core_probe(regmap, chip, inv_icm42600_i2c_bus_setup); > + return inv_icm42600_core_probe(regmap, chip, client->irq, > + inv_icm42600_i2c_bus_setup); > } > > static const struct of_device_id inv_icm42600_of_matches[] = { > diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_spi.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_spi.c > index a9c5e2fdbe2a..323789697a08 100644 > --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_spi.c > +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_spi.c > @@ -63,7 +63,8 @@ static int inv_icm42600_probe(struct spi_device *spi) > if (IS_ERR(regmap)) > return PTR_ERR(regmap); > > - return inv_icm42600_core_probe(regmap, chip, inv_icm42600_spi_bus_setup); > + return inv_icm42600_core_probe(regmap, chip, spi->irq, > + inv_icm42600_spi_bus_setup); > } > > static const struct of_device_id inv_icm42600_of_matches[] = {