linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
To: Shreyas Joshi <shreyas.joshi@biamp.com>,
	"lee.jones@linaro.org" <lee.jones@linaro.org>,
	Support Opensource <Support.Opensource@diasemi.com>,
	"shreyasjoshi15@gmail.com" <shreyasjoshi15@gmail.com>,
	Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH V3] mfd: da9062: add support for interrupt polarity defined in device tree
Date: Wed, 12 Feb 2020 12:41:15 +0000	[thread overview]
Message-ID: <AM6PR10MB22633D335FAD6AF40FA344F3801B0@AM6PR10MB2263.EURPRD10.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20200206073126.zf3ahv3b3lafctcn@shreyas_biamp.biamp.com>

On 06 February 2020 07:31, Shreyas Joshi wrote:

> The da9062 interrupt handler cannot necessarily be low active.
> Add a function to configure the interrupt type based on what is defined in the
> device tree. The allowable interrupt type is either low or high level trigger.
> 
> Signed-off-by: Shreyas Joshi <shreyas.joshi@biamp.com>
> ---
>  drivers/mfd/da9062-core.c | 38 +++++++++++++++++++++++++++++++++++---
>  1 file changed, 35 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mfd/da9062-core.c b/drivers/mfd/da9062-core.c
> index 419c73533401..c44a48ba3d05 100644
> --- a/drivers/mfd/da9062-core.c
> +++ b/drivers/mfd/da9062-core.c
> @@ -369,6 +369,32 @@ static int da9062_get_device_type(struct da9062 *chip)
>  	return ret;
>  }
> 
> +static u32 da9062_configure_irq_type(struct da9062 *chip, int irq, u32 *trigger)
> +{
> +	u32 irq_type = 0;
> +	struct irq_data *irq_data = irq_get_irq_data(irq);
> +
> +	if (!irq_data) {
> +		dev_err(chip->dev, "Invalid IRQ: %d\n", irq);
> +		return -EINVAL;
> +	}
> +	*trigger = irqd_get_trigger_type(irq_data);
> +
> +	switch (*trigger) {
> +	case IRQ_TYPE_LEVEL_HIGH:
> +		irq_type = 1;
> +		break;
> +	case IRQ_TYPE_LEVEL_LOW:
> +		irq_type = 0;
> +		break;
> +	default:
> +		dev_warn(chip->dev, "Unsupported IRQ type: %d\n", *trigger);
> +		return -EIO;

Don't think EIO is the correct return code. Think EINVAL is more appropriate.

> +		}

Indentation here for closing bracket isn't right. Make sure you run this through
the checkpatch.pl script.

> +	return regmap_update_bits(chip->regmap, DA9062AA_CONFIG_A,
> +			DA9062AA_IRQ_TYPE_MASK, irq_type);
> +}

This won't work. 'irq_type' needs to be shifted the correct number of bits.
See DA9062AA_IRQ_TYPE_SHIFT.

> +
>  static const struct regmap_range da9061_aa_readable_ranges[] = {
>  	regmap_reg_range(DA9062AA_PAGE_CON, DA9062AA_STATUS_B),
>  	regmap_reg_range(DA9062AA_STATUS_D, DA9062AA_EVENT_C),
> @@ -417,6 +443,7 @@ static const struct regmap_range
> da9061_aa_writeable_ranges[] = {
>  	regmap_reg_range(DA9062AA_VBUCK1_A, DA9062AA_VBUCK4_A),
>  	regmap_reg_range(DA9062AA_VBUCK3_A, DA9062AA_VBUCK3_A),
>  	regmap_reg_range(DA9062AA_VLDO1_A, DA9062AA_VLDO4_A),
> +	regmap_reg_range(DA9062AA_CONFIG_A, DA9062AA_CONFIG_B),
>  	regmap_reg_range(DA9062AA_VBUCK1_B, DA9062AA_VBUCK4_B),
>  	regmap_reg_range(DA9062AA_VBUCK3_B, DA9062AA_VBUCK3_B),
>  	regmap_reg_range(DA9062AA_VLDO1_B, DA9062AA_VLDO4_B),
> @@ -596,6 +623,7 @@ static int da9062_i2c_probe(struct i2c_client *i2c,
>  	const struct regmap_irq_chip *irq_chip;
>  	const struct regmap_config *config;
>  	int cell_num;
> +	u32 trigger_type = 0;
>  	int ret;
> 
>  	chip = devm_kzalloc(&i2c->dev, sizeof(*chip), GFP_KERNEL);
> @@ -654,10 +682,14 @@ static int da9062_i2c_probe(struct i2c_client *i2c,
>  	if (ret)
>  		return ret;
> 
> +	if (da9062_configure_irq_type(chip, i2c->irq, &trigger_type) < 0) {

You're returning error codes from 'da9062_configure_irq_type' so why are you
overriding what's returned with -EINVAL below?

> +		dev_err(chip->dev, "Failed to configure IRQ type\n");
> +		return -EINVAL;
> +	}
> +
>  	ret = regmap_add_irq_chip(chip->regmap, i2c->irq,
> -			IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,
> -			-1, irq_chip,
> -			&chip->regmap_irq);
> +			trigger_type | IRQF_SHARED | IRQF_ONESHOT,
> +			-1, irq_chip, &chip->regmap_irq);
>  	if (ret) {
>  		dev_err(chip->dev, "Failed to request IRQ %d: %d\n",
>  			i2c->irq, ret);
> --
> 2.20.1


      reply	other threads:[~2020-02-12 12:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-06  7:31 [PATCH V3] mfd: da9062: add support for interrupt polarity defined in device tree Shreyas Joshi
2020-02-12 12:41 ` Adam Thomson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM6PR10MB22633D335FAD6AF40FA344F3801B0@AM6PR10MB2263.EURPRD10.PROD.OUTLOOK.COM \
    --to=adam.thomson.opensource@diasemi.com \
    --cc=Support.Opensource@diasemi.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shreyas.joshi@biamp.com \
    --cc=shreyasjoshi15@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).