devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: James Hogan <james.hogan@imgtec.com>
Cc: linux-kernel@vger.kernel.org,
	Grant Likely <grant.likely@secretlab.ca>,
	Rob Herring <rob.herring@calxeda.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	devicetree-discuss@lists.ozlabs.org,
	Rob Landley <rob@landley.net>,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH 3/8] irq-imgpdc: add ImgTec PDC irqchip driver
Date: Tue, 23 Apr 2013 17:09:51 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LFD.2.02.1304231647400.21884@ionos> (raw)
In-Reply-To: <1366727607-27444-4-git-send-email-james.hogan@imgtec.com>

On Tue, 23 Apr 2013, James Hogan wrote:
> +/**
> + * struct pdc_intc_priv - private pdc interrupt data.
> + * @nr_perips:		Number of peripheral interrupt signals.
> + * @nr_syswakes:	Number of syswake signals.
> + * @perip_irqs:		List of peripheral IRQ numbers handled.
> + * @syswake_irq:	Shared PDC syswake IRQ number.
> + * @domain:		IRQ domain for PDC peripheral and syswake IRQs.
> + * @pdc_base:		Base of PDC registers.
> + * @lock:		Lock to protect the PDC syswake registers.
> + */
> +struct pdc_intc_priv {
> +	unsigned int		nr_perips;
> +	unsigned int		nr_syswakes;
> +	unsigned int		*perip_irqs;
> +	unsigned int		syswake_irq;
> +	struct irq_domain	*domain;
> +	void __iomem		*pdc_base;
> +
> +	spinlock_t		lock;

  raw_spinlock_t please

> +/* Generic IRQ callbacks */
> +
> +#define SYS0_HWIRQ	8
> +
> +static unsigned int hwirq_is_syswake(irq_hw_number_t hw)
> +{
> +	return hw >= SYS0_HWIRQ;
> +}
> +
> +static unsigned int hwirq_to_syswake(irq_hw_number_t hw)
> +{
> +	return hw - SYS0_HWIRQ;
> +}
> +
> +static irq_hw_number_t syswake_to_hwirq(unsigned int syswake)
> +{
> +	return SYS0_HWIRQ + syswake;
> +}
> +
> +static struct pdc_intc_priv *irqd_to_priv(struct irq_data *data)
> +{
> +	return (struct pdc_intc_priv *)data->domain->host_data;
> +}
> +
> +static void perip_irq_mask(struct irq_data *data)
> +{
> +	struct pdc_intc_priv *priv = irqd_to_priv(data);
> +	unsigned int irq_route;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&priv->lock, flags);

This is always called with interrupts disabled.

> +	irq_route = pdc_read(priv, PDC_IRQ_ROUTE);
> +	irq_route &= ~(1 << data->hwirq);

Why not cache the mask value ?

> +	pdc_write(priv, PDC_IRQ_ROUTE, irq_route);

> +	spin_unlock_irqrestore(&priv->lock, flags);
> +}
> +
> +static void perip_irq_unmask(struct irq_data *data)
> +{
> +	struct pdc_intc_priv *priv = irqd_to_priv(data);
> +	unsigned int irq_route;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&priv->lock, flags);
> +	irq_route = pdc_read(priv, PDC_IRQ_ROUTE);
> +	irq_route |= 1 << data->hwirq;
> +	pdc_write(priv, PDC_IRQ_ROUTE, irq_route);

This code is another slightly different copy of stuff which is
available in kernel/irq/generic-chip.c

Can we please stop the code duplication and reuse existing
infrastructure? Don't tell me it does not work for you.  I sent out a
patch yesterday which makes the code suitable for irq domains.

> +static int syswake_irq_set_type(struct irq_data *data, unsigned int flow_type)
> +{
> +	struct pdc_intc_priv *priv = irqd_to_priv(data);
> +	unsigned int syswake = hwirq_to_syswake(data->hwirq);
> +	unsigned int irq_mode;
> +	unsigned int soc_sys_wake_regoff, soc_sys_wake;
> +	unsigned long flags;
> +
> +	/* translate to syswake IRQ mode */
> +	switch (flow_type) {
> +	case IRQ_TYPE_EDGE_BOTH:
> +		irq_mode = PDC_SYS_WAKE_INT_CHANGE;
> +		break;
> +	case IRQ_TYPE_EDGE_RISING:
> +		irq_mode = PDC_SYS_WAKE_INT_UP;
> +		break;
> +	case IRQ_TYPE_EDGE_FALLING:
> +		irq_mode = PDC_SYS_WAKE_INT_DOWN;
> +		break;
> +	case IRQ_TYPE_LEVEL_HIGH:
> +		irq_mode = PDC_SYS_WAKE_INT_HIGH;
> +		break;
> +	case IRQ_TYPE_LEVEL_LOW:
> +		irq_mode = PDC_SYS_WAKE_INT_LOW;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	spin_lock_irqsave(&priv->lock, flags);

All irqchip callbacks are called with interrupts disabled.

> +static void pdc_intc_perip_isr(unsigned int irq, struct irq_desc *desc)
> +{
> +	struct pdc_intc_priv *priv;
> +	unsigned int i, irq_no;
> +
> +	priv = (struct pdc_intc_priv *)irq_desc_get_handler_data(desc);
> +
> +	/* find the peripheral number */
> +	for (i = 0; i < priv->nr_perips; ++i)
> +		if (irq == priv->perip_irqs[i])
> +			goto found;

Whee. Aren't these numbers linear ?

> +	/* should never get here */
> +	return;
> +found:
> +
> +	/* pass on the interrupt */
> +	irq_no = irq_linear_revmap(priv->domain, i);
> +	generic_handle_irq(irq_no);
> +}
> +
> +static void pdc_intc_syswake_isr(unsigned int irq, struct irq_desc *desc)
> +{
> +	struct pdc_intc_priv *priv;
> +	unsigned int syswake, irq_no;
> +	unsigned int status;
> +
> +	priv = (struct pdc_intc_priv *)irq_desc_get_handler_data(desc);
> +
> +	spin_lock(&priv->lock);
> +	status = pdc_read(priv, PDC_IRQ_STATUS);
> +	status &= pdc_read(priv, PDC_IRQ_ENABLE);
> +	spin_unlock(&priv->lock);
> +
> +	status &= (1 << priv->nr_syswakes) - 1;
> +
> +	for (syswake = 0; status; status >>= 1, ++syswake) {
> +		/* Has this sys_wake triggered? */
> +		if (!(status & 1))
> +			continue;
> +
> +		irq_no = irq_linear_revmap(priv->domain,
> +					   syswake_to_hwirq(syswake));
> +		generic_handle_irq(irq_no);
> +	}
> +}
> +


> +static int pdc_intc_probe(struct platform_device *pdev)
> +{
> +	struct pdc_intc_priv *priv;
> +	struct device_node *node = pdev->dev.of_node;
> +	struct resource *res_regs;
> +	unsigned int i;
> +	int irq, ret;
> +	u32 val;
> +
> +	if (!node)
> +		return -ENOENT;
> +
> +	/* Get registers */
> +	res_regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (res_regs == NULL) {
> +		dev_err(&pdev->dev, "cannot find registers resource\n");
> +		return -ENOENT;
> +	}
> +
> +	/* Allocate driver data */
> +	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv) {
> +		dev_err(&pdev->dev, "cannot allocate device data\n");
> +		return -ENOMEM;
> +	}
> +	spin_lock_init(&priv->lock);
> +	platform_set_drvdata(pdev, priv);
> +
> +	/* Ioremap the registers */
> +	priv->pdc_base = devm_ioremap(&pdev->dev, res_regs->start,
> +				      res_regs->end - res_regs->start);
> +	if (!priv->pdc_base)
> +		return -EIO;

Leaks priv.

> +	/* Get number of peripherals */
> +	ret = of_property_read_u32(node, "num-perips", &val);
> +	if (ret) {
> +		dev_err(&pdev->dev, "No num-perips node property found\n");
> +		return -EINVAL;

Leaks priv and mapping

> +	}
> +	if (val > SYS0_HWIRQ) {
> +		dev_err(&pdev->dev, "num-perips (%u) out of range\n", val);
> +		return -EINVAL;

Error handling is optional, right?

> +static int pdc_intc_remove(struct platform_device *pdev)
> +{
> +	struct pdc_intc_priv *priv = platform_get_drvdata(pdev);
> +
> +	irq_domain_remove(priv->domain);

And the rest of the resources is still there?


  reply	other threads:[~2013-04-23 15:09 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-23 14:33 [PATCH 0/8] Add some TZ1090 SoC infrastructure James Hogan
     [not found] ` <1366727607-27444-1-git-send-email-james.hogan-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2013-04-23 14:33   ` [PATCH 1/8] metag: of_platform_populate from arch generic code James Hogan
2013-04-23 14:33   ` [PATCH 8/8] gpio-tz1090pdc: add TZ1090 PDC gpio driver James Hogan
2013-04-23 14:33 ` [PATCH 2/8] metag: minimal TZ1090 (Comet) SoC infrastructure James Hogan
2013-04-23 15:25   ` Arnd Bergmann
2013-04-23 16:06     ` James Hogan
2013-04-24 13:26       ` Catalin Marinas
2013-04-24 14:51         ` James Hogan
2013-04-25 15:21           ` James Hogan
2013-04-23 14:33 ` [PATCH 3/8] irq-imgpdc: add ImgTec PDC irqchip driver James Hogan
2013-04-23 15:09   ` Thomas Gleixner [this message]
2013-04-24  9:14     ` James Hogan
2013-04-24  9:32       ` Thomas Gleixner
2013-04-25 11:25     ` James Hogan
2013-04-23 14:33 ` [PATCH 4/8] metag: tz1090: add <asm/soc-tz1090/gpio.h> James Hogan
2013-04-25 21:52   ` Linus Walleij
2013-04-23 14:33 ` [PATCH 5/8] pinctrl-tz1090: add TZ1090 pinctrl driver James Hogan
2013-04-25 22:39   ` Linus Walleij
2013-04-26 11:54     ` James Hogan
2013-05-03  9:13       ` Linus Walleij
2013-05-03 12:23         ` James Hogan
2013-05-03 13:03           ` Linus Walleij
2013-05-03 15:06             ` James Hogan
     [not found]               ` <5183D262.7000107-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org>
2013-05-14 11:52                 ` Linus Walleij
2013-05-14 12:22                   ` James Hogan
2013-05-15 19:07                     ` Linus Walleij
2013-05-16  9:12                       ` James Hogan
2013-05-17  6:47                         ` Linus Walleij
2013-04-23 14:33 ` [PATCH 6/8] gpio-tz1090: add TZ1090 gpio driver James Hogan
2013-04-25 23:01   ` Linus Walleij
2013-04-26  9:22     ` James Hogan
2013-05-03  8:49       ` Linus Walleij
2013-05-03  9:09         ` James Hogan
2013-05-15 19:09           ` Linus Walleij
2013-04-23 14:33 ` [PATCH 7/8] pinctrl-tz1090-pdc: add TZ1090 PDC pinctrl driver James Hogan

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=alpine.LFD.2.02.1304231647400.21884@ionos \
    --to=tglx@linutronix.de \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@secretlab.ca \
    --cc=james.hogan@imgtec.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    /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).