Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp414259imp; Wed, 20 Feb 2019 02:31:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IazwUtcsCNudNTyNRIH2JLMszqQYOsIiQROBC2rjL4MgHPuHIg1DkNthIIBxWC8AAuYiHLM X-Received: by 2002:a17:902:f302:: with SMTP id gb2mr11069608plb.51.1550658661565; Wed, 20 Feb 2019 02:31:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550658661; cv=none; d=google.com; s=arc-20160816; b=H5IaVjBgoLlw86WRJ9T4K8wsdWiOUEzRVv5GpgYiYqGCZMxwCHnySp3A9RQYQE21sd 1zLQDI9ka3smbYHX3kbhx/gJ7G3Lv001VWUBkTGY4He7GcYM3uthnq9N7cyOYe+PovhV U69AWnQs4n2xpZSpY2OFz88OP3li1p2KUEf81R47AtAJcayO/ls6pUHoN3cQrRS5Z+NT mctV3Lpct9E2Et3KiZkZNr4od4GVpZgpuaIlmQbsXl3VZsZZJWgrewpEEoGb8w2K4XY4 Il/B1S6ZGMkvY8LKA7kU7Al8XtA++TvED+RfZoSBao+c7i5aG4BxffW+SCRVTJQhs157 RrMA== 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=CEwEIKMDziE/o8BX0xmEek4nAUUfA3vQCwJ9Dcp0PB0=; b=n0Mw9G6F687QRDzBVVi0M5Tc7i7aq8nemfGwVlWxR3GN6IaZxExJxJxT2dFZF2SwER WcM+1SAM5G8wCJvjfPR2ZXVn5H+DlZWi9wFRStwiWxUAemXvXGfIDS5e7UxxOhj0k81O i/hqE53bX8v3NifVvP+9IjlrNiXjURuSXEeD3CNUM8tNrXss+i4n3QktXY1PJK0z2ym2 9cQP04u8OgXbYhZ9AoLqyV3Kg0jY+qFvXh7aYJ7JEgKADP/Vr+4zf9dn0Ettu//C2jIX Uu0FPfYhfBzx77TVvszXLO4rvNkyVLcXULzxgOsmk0NLBjKxnVyN0of+WCkVAvpr4d+Z WYnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xBzPO2rd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id z2si16814475pgp.429.2019.02.20.02.30.45; Wed, 20 Feb 2019 02:31:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xBzPO2rd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727442AbfBTK3w (ORCPT + 99 others); Wed, 20 Feb 2019 05:29:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:49448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726209AbfBTK3w (ORCPT ); Wed, 20 Feb 2019 05:29:52 -0500 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (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 B1EF02086A; Wed, 20 Feb 2019 10:29:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550658590; bh=ihNkSzqAAFhFcoXkz2WEuxqjMgKZDHQGckxMKV/yXhs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=xBzPO2rd3xpbV4mrMY4Cc3byCCoD/euq+T9Yo5168BniUPbH03RmUwTPQFA0nMRED oKAFM/2J+2G3hJR7xpKfz7Jn5rzbGUbF5GbSuNN381XeHmwAzQFOzQkYbjCF/Lkvz/ aZsLx7y1Bpyu5B07tYjjMax6BLHd56XZx2qkDmBQ= Date: Wed, 20 Feb 2019 10:29:45 +0000 From: Jonathan Cameron To: Stefan Popa Cc: , , , , , , , Subject: Re: [PATCH 2/6] iio: imu: adis16480: Add support for configurable drdy indicator Message-ID: <20190220102945.6af3edc4@archlinux> In-Reply-To: <1550596338-24220-3-git-send-email-stefan.popa@analog.com> References: <1550596338-24220-1-git-send-email-stefan.popa@analog.com> <1550596338-24220-3-git-send-email-stefan.popa@analog.com> X-Mailer: Claws Mail 3.17.3 (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 Tue, 19 Feb 2019 19:12:14 +0200 Stefan Popa wrote: > The FNCTIO_CTRL register provides configuration control for each I/O pin > (DIO1, DIO2, DIO3 and DIO4). > > This patch adds the option to configure each DIOx pin as data ready > indicator with positive or negative polarity by reading the 'interrupts' > and 'interrupt-names' properties from the devicetree. The > 'interrupt-names' property is optional, if it is not specified, then the > factory default DIO2 data ready signal is used. > > Signed-off-by: Stefan Popa Other than follow on from the previous patch change of the default, this looks fine to me. One question inline. Jonathan > --- > drivers/iio/imu/adis16480.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 76 insertions(+) > > diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c > index d222188..38ba0c1 100644 > --- a/drivers/iio/imu/adis16480.c > +++ b/drivers/iio/imu/adis16480.c > @@ -10,6 +10,7 @@ > */ > > #include > +#include > #include > #include > #include > @@ -109,6 +110,10 @@ > #define ADIS16480_FIR_COEF_D(x) ADIS16480_FIR_COEF(0x0B, (x)) > > /* ADIS16480_REG_FNCTIO_CTRL */ > +#define ADIS16480_DRDY_SEL_MSK GENMASK(1, 0) > +#define ADIS16480_DRDY_SEL(x) FIELD_PREP(ADIS16480_DRDY_SEL_MSK, x) > +#define ADIS16480_DRDY_POL_MSK BIT(2) > +#define ADIS16480_DRDY_POL(x) FIELD_PREP(ADIS16480_DRDY_POL_MSK, x) > #define ADIS16480_DRDY_EN_MSK BIT(3) > #define ADIS16480_DRDY_EN(x) FIELD_PREP(ADIS16480_DRDY_EN_MSK, x) > > @@ -121,12 +126,26 @@ struct adis16480_chip_info { > unsigned int accel_max_scale; > }; > > +enum adis16480_int_pin { > + ADIS16480_PIN_DIO1, > + ADIS16480_PIN_DIO2, > + ADIS16480_PIN_DIO3, > + ADIS16480_PIN_DIO4 > +}; > + > struct adis16480 { > const struct adis16480_chip_info *chip_info; > > struct adis adis; > }; > > +static const char * const adis16480_int_pin_names[4] = { > + [ADIS16480_PIN_DIO1] = "DIO1", > + [ADIS16480_PIN_DIO2] = "DIO2", > + [ADIS16480_PIN_DIO3] = "DIO3", > + [ADIS16480_PIN_DIO4] = "DIO4", > +}; > + > #ifdef CONFIG_DEBUG_FS > > static ssize_t adis16480_show_firmware_revision(struct file *file, > @@ -840,6 +859,59 @@ static const struct adis_data adis16480_data = { > .enable_irq = adis16480_enable_irq, > }; > > +static int adis16480_config_irq_pin(struct device_node *of_node, > + struct adis16480 *st) > +{ > + struct irq_data *desc; > + enum adis16480_int_pin pin; > + unsigned int irq_type; > + uint16_t val; > + int i, irq = 0; > + > + desc = irq_get_irq_data(st->adis.spi->irq); > + if (!desc) { > + dev_err(&st->adis.spi->dev, "Could not find IRQ %d\n", irq); > + return -EINVAL; > + } > + > + /* Disable data ready */ > + val = ADIS16480_DRDY_EN(0); Does it default to on after reset? That's a little unusual and nasty. If not, why are you disabling here? > + > + /* > + * Get the interrupt from the devicetre by reading the > + * interrupt-names property. If it is not specified, use > + * the default interrupt on DIO2 pin. > + */ > + pin = ADIS16480_PIN_DIO2; > + for (i = 0; i < ARRAY_SIZE(adis16480_int_pin_names); i++) { > + irq = of_irq_get_byname(of_node, adis16480_int_pin_names[i]); > + if (irq > 0) { > + pin = i; > + break; > + } > + } > + > + val |= ADIS16480_DRDY_SEL(pin); > + > + /* > + * Get the interrupt line behaviour. The data ready polarity can be > + * configured as positive or negative, corresponding to > + * IRQF_TRIGGER_RISING or IRQF_TRIGGER_FALLING respectively. > + */ > + irq_type = irqd_get_trigger_type(desc); > + if (irq_type == IRQF_TRIGGER_RISING) { /* Default */ > + val |= ADIS16480_DRDY_POL(1); > + } else if (irq_type == IRQF_TRIGGER_FALLING) { > + val |= ADIS16480_DRDY_POL(0); > + } else { > + dev_err(&st->adis.spi->dev, > + "Invalid interrupt type 0x%x specified\n", irq_type); > + return -EINVAL; > + } > + /* Write the data ready configuration to the FNCTIO_CTRL register */ > + return adis_write_reg_16(&st->adis, ADIS16480_REG_FNCTIO_CTRL, val); > +} > + > static int adis16480_probe(struct spi_device *spi) > { > const struct spi_device_id *id = spi_get_device_id(spi); > @@ -867,6 +939,10 @@ static int adis16480_probe(struct spi_device *spi) > if (ret) > return ret; > > + ret = adis16480_config_irq_pin(spi->dev.of_node, st); > + if (ret) > + return ret; > + > ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev, NULL); > if (ret) > return ret;