public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rohit Vaswani <rvaswani@codeaurora.org>
To: Stanimir Varbanov <svarbanov@mm-sol.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Grant Likely <grant.likely@linaro.org>,
	Rob Herring <rob.herring@calxeda.com>,
	Rob Landley <rob@landley.net>,
	Russell King <linux@arm.linux.org.uk>,
	David Brown <davidb@codeaurora.org>,
	Bryan Huntsman <bryanh@codeaurora.org>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] gpio: msm: Add device tree and irqdomain support for gpio-msm-v2
Date: Wed, 22 May 2013 12:27:24 -0700	[thread overview]
Message-ID: <519D1C1C.4000309@codeaurora.org> (raw)
In-Reply-To: <519C9180.2060408@mm-sol.com>

On 5/22/2013 2:36 AM, Stanimir Varbanov wrote:
> Hi, Rohit
>
> Thanks for the patch!
Thanks for the comments... more below
>
> On 05/21/2013 09:32 PM, Rohit Vaswani wrote:
>> This cleans up the gpio-msm-v2 driver of all the global define usage.
>> The number of gpios are now defined in the device tree. This enables
>> adding irqdomain support as well.
>>
>> Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>
>> ---
> <cut>
>
>>   
>>   static DEFINE_SPINLOCK(tlmm_lock);
>> @@ -168,18 +173,20 @@ static void msm_gpio_free(struct gpio_chip *chip, unsigned offset)
>>   
>>   static int msm_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
>>   {
>> -	return MSM_GPIO_TO_INT(chip->base + offset);
>> +	struct msm_gpio_dev *g_dev = to_msm_gpio_dev(chip);
>> +	struct irq_domain *domain = g_dev->domain;
>> +	return irq_create_mapping(domain, offset);
> IMO here you should use irq_find_mapping() and create irq mapping once
> in .probe. See below comment.
Looking at this more, I  would prefer to get rid of the entire for loop 
and the irq_create_mapping in probe and
just have the irq_create_mapping in msm_gpio_to_irq. This way we are not 
allocating a descriptor for every gpio and only for the ones that call 
the msm_gpio_to_irq.

>
>>   }
>>   
> <cut>
>
>> -static int msm_gpio_probe(struct platform_device *dev)
>> +static struct lock_class_key msm_gpio_lock_class;
>> +
>> +static int msm_gpio_irq_domain_map(struct irq_domain *d, unsigned int irq,
>> +				   irq_hw_number_t hwirq)
>> +{
>> +	irq_set_lockdep_class(irq, &msm_gpio_lock_class);
>> +	irq_set_chip_and_handler(irq, &msm_gpio_irq_chip,
>> +			handle_level_irq);
>> +	set_irq_flags(irq, IRQF_VALID);
>> +
>> +	return 0;
>> +}
>> +
>> +static const struct irq_domain_ops msm_gpio_irq_domain_ops = {
>> +	.xlate = irq_domain_xlate_twocell,
>> +	.map = msm_gpio_irq_domain_map,
>> +};
>> +
>> +static int msm_gpio_irqdomain_init(struct device_node *node, int ngpio)
>>   {
>> -	int i, irq, ret;
>> +	msm_gpio.domain = irq_domain_add_linear(node, ngpio,
>> +			&msm_gpio_irq_domain_ops, &msm_gpio);
>> +	if (!msm_gpio.domain) {
>> +		WARN(1, "Cannot allocate irq_domain\n");
> Are you sure that we want to WARN if no memory? I'd return an error and
> fail the probe if the driver can't works without interrupts.
Done.
>
>> +		return -ENOMEM;
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>> +static int msm_gpio_probe(struct platform_device *pdev)
>> +{
>> +	int i, irq, ret, ngpio;
>> +	struct resource *res;
>> +
>> +	msm_gpio.gpio_chip.label = pdev->name;
>> +	msm_gpio.gpio_chip.dev = &pdev->dev;
>> +	of_property_read_u32(pdev->dev.of_node, "ngpio", &ngpio);
>> +	msm_gpio.gpio_chip.ngpio = ngpio;
>> +
>> +	res = platform_get_resource(&pdev->dev, IORESOURCE_MEM, 0);
>> +	if (!res) {
>> +		dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
>> +		return -EINVAL;
>> +	}
>> +
>> +	msm_tlmm_base = devm_ioremap_resource(pdev->dev, res);
>> +	if (!msm_tlmm_base) {
>> +		dev_err(&pdev->dev, "Couldn't allocate memory for msm tlmm base\n");
>> +		return -ENOMEM;
>> +	}
>> +
>> +	msm_gpio.enabled_irqs = devm_kzalloc(&pdev->dev,
>> +						sizeof(unsigned long) * ngpio,
>> +						GFP_KERNEL);
>> +	msm_gpio.wake_irqs = devm_kzalloc(&pdev->dev,
>> +						sizeof(unsigned long) * ngpio,
>> +						GFP_KERNEL);
>> +	msm_gpio.dual_edge_irqs = devm_kzalloc(&pdev->dev,
>> +						sizeof(unsigned long) * ngpio,
>> +						GFP_KERNEL);
>> +	bitmap_zero(msm_gpio.enabled_irqs, ngpio);
>> +	bitmap_zero(msm_gpio.wake_irqs, ngpio);
>> +	bitmap_zero(msm_gpio.dual_edge_irqs, ngpio);
>>   
>> -	bitmap_zero(msm_gpio.enabled_irqs, NR_GPIO_IRQS);
>> -	bitmap_zero(msm_gpio.wake_irqs, NR_GPIO_IRQS);
>> -	bitmap_zero(msm_gpio.dual_edge_irqs, NR_GPIO_IRQS);
>> -	msm_gpio.gpio_chip.label = dev->name;
>>   	ret = gpiochip_add(&msm_gpio.gpio_chip);
>> -	if (ret < 0)
>> +	if (ret < 0) {
>> +		dev_err(&pdev->dev, "gpiochip_add failed with error %d\n", ret);
>>   		return ret;
>> +	}
>> +
>> +	summary_irq = platform_get_irq(pdev, 0);
>> +	if (summary_irq < 0) {
>> +		dev_err(&pdev->dev, "No Summary irq defined for msmgpio\n");
>> +		return summary_irq;
>> +	}
>> +
>> +	msm_gpio_irqdomain_init(pdev->dev.of_node, msm_gpio.gpio_chip.ngpio);
> Adding irqdomain might fail, could you check the return value. And if
> irqdomain init fail do we need to set up chained handler for summary_irq
> at all?
Done.
>
>>   
>>   	for (i = 0; i < msm_gpio.gpio_chip.ngpio; ++i) {
>>   		irq = msm_gpio_to_irq(&msm_gpio.gpio_chip, i);
> I'd call irq_create_mapping() instead. This way the mapping will be
> created once in .probe and use irq_find_mapping() in gpio_to_irq.
Will get rid of this for loop as mentioned above. Thanks for catching this.

>
>> +		irq_set_lockdep_class(irq, &msm_gpio_lock_class);
>>   		irq_set_chip_and_handler(irq, &msm_gpio_irq_chip,
>>   					 handle_level_irq);
>>   		set_irq_flags(irq, IRQF_VALID);
> These three function calls are not needed anymore because
> irq_create_mapping() will call internally irqdomain .map operation. The
> .map already calls these three functions.
Done.
>
>>   	}
>>   
>> -	irq_set_chained_handler(TLMM_SCSS_SUMMARY_IRQ,
>> -				msm_summary_irq_handler);
>> +	irq_set_chained_handler(summary_irq, msm_summary_irq_handler);
>> +
>>   	return 0;
>>   }
>>   
> - Stan


Thanks,
Rohit Vaswani

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation


  reply	other threads:[~2013-05-22 19:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-21 18:32 [PATCH 0/3] Cleanup MSM_GPIOMUX and add device-tree support for Rohit Vaswani
2013-05-21 18:32 ` [PATCH 1/3] ARM: msm: Remove gpiomux-v2 and re-organize MSM_GPIOMUX configs Rohit Vaswani
2013-05-30 17:53   ` Linus Walleij
2013-05-21 18:32 ` [PATCH 2/3] ARM: msm: Remove unused and unmapped MSM_TLMM_BASE for 8x60 Rohit Vaswani
2013-05-21 18:32 ` [PATCH 3/3] gpio: msm: Add device tree and irqdomain support for gpio-msm-v2 Rohit Vaswani
2013-05-21 21:06   ` Stephen Boyd
2013-05-22 19:29     ` Rohit Vaswani
2013-05-22  9:36   ` Stanimir Varbanov
2013-05-22 19:27     ` Rohit Vaswani [this message]
2013-05-30 17:54 ` [PATCH 0/3] Cleanup MSM_GPIOMUX and add device-tree support for Linus Walleij
  -- strict thread matches above, loose matches on Subject: below --
2013-06-10 22:50 [PATCHv5 0/3] Cleanup MSM_GPIOMUX and add DT support for gpio-msm Rohit Vaswani
2013-06-10 22:50 ` [PATCH 3/3] gpio: msm: Add device tree and irqdomain support for gpio-msm-v2 Rohit Vaswani
2013-06-11 12:45   ` Grant Likely

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=519D1C1C.4000309@codeaurora.org \
    --to=rvaswani@codeaurora.org \
    --cc=bryanh@codeaurora.org \
    --cc=davidb@codeaurora.org \
    --cc=grant.likely@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    --cc=svarbanov@mm-sol.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