From patchwork Thu Mar 5 11:20:24 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Henk Stegeman X-Patchwork-Id: 24095 X-Patchwork-Delegate: grant.likely@secretlab.ca Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 6ACECDDFB0 for ; Thu, 5 Mar 2009 22:21:04 +1100 (EST) X-Original-To: linuxppc-dev@ozlabs.org Delivered-To: linuxppc-dev@ozlabs.org X-Greylist: delayed 317 seconds by postgrey-1.31 at ozlabs; Thu, 05 Mar 2009 22:20:26 EST Received: from mail-gx0-f174.google.com (mail-gx0-f174.google.com [209.85.217.174]) by ozlabs.org (Postfix) with ESMTP id EBD95DDDB6 for ; Thu, 5 Mar 2009 22:20:26 +1100 (EST) Received: by gxk22 with SMTP id 22so1514444gxk.9 for ; Thu, 05 Mar 2009 03:20:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=2tbd1yKknezN7xaQPXpuOtFSorsZg1Ktwip4YeaQK08=; b=XwezpZAWi8Jspr8S2M/OgCi5DMhyAzuntGTZR3dH/ACeiFD5ie0F/Zht2jZVLW20VG Qkeb7UkvgAFJxM51g2bQvj9ayNveeCvc0E0v15dpSjUZVHwuv+PuJVqAq69Nh0GpxwRS FZKtvY6ZiBetXafjs6KNKtblasU5qAFkNCEJc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=o3uAq+3XerX06RImesA4iXJTKP+gjLO8yRbzFXWVHlnmFG4XiGFAihmtY5NnEzVFsB 5VCikYal9uPs+53U2UwT1NSMNdWfYT8hVChDJRl1m+h9UtV6TcRCbJqF+quOtHuduRVU ozNlB3sg6odVcghBfzMnfJ1EG9vvoAuKQaf3Q= MIME-Version: 1.0 Received: by 10.220.72.140 with SMTP id m12mr293593vcj.7.1236252024780; Thu, 05 Mar 2009 03:20:24 -0800 (PST) In-Reply-To: References: Date: Thu, 5 Mar 2009 12:20:24 +0100 Message-ID: Subject: Re: support IRQ from GPIO trough OF and GPIOLIB From: Henk Stegeman To: linuxppc-dev@ozlabs.org X-BeenThere: linuxppc-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org I forgot to include my changes in arch/powerpc/include/asm/gpio.h: On Thu, Mar 5, 2009 at 12:15 PM, Henk Stegeman wrote: > Hello, > > I have an SPI device that sends an IRQ to the CPU (MPC5200) via GPIO (GPT6): > > gpt6: timer@660 {       // General Purpose Timer GPT6 in GPIO mode for > SMC4000IO sample irq. >        compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio"; >        cell-index = <6>; >        reg = <0x660 0x10>; >        interrupts = <1 15 0>; >        interrupt-parent = <&mpc5200_pic>; >        gpio-controller; >        #gpio-cells = <2>; > }; > > spi@f00 { >        #address-cells = <1>; >        #size-cells = <0>; >        compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi"; >        reg = <0xf00 0x20>; >        interrupts = <2 13 0 2 14 0>; >        interrupt-parent = <&mpc5200_pic>; >        gpios = <&gpt4 0 0>; > >        io-controller@0 { >                compatible = "microkey,smc4000io"; >                linux,modalias = "of_smc4000io"; >                spi-max-frequency = <1000000>; >                spi-cpha; >                reg = <0>; >                // gpios: first is IRQ to cpu >                gpios = <&gpt6 0 0>; >                word-delay-us = <0>; >        }; > }; > > I've got it working for a mm_gpio, but it's probably not the right > approach, I have the following questions to get to the right solution: > - Should gpiolib's gpio_to_irq function indeed return the IRQ that was > specified at the GPIO by the DTS (interrupts = <1 15 0>)? >  The effect is that if the IRQ is not specified in the DTS the > gpio_to_irq returns NO_IRQ. >  (On the MPC5200 the IRQ is fixed for GPT6, so instead the cell-index > could also be used to return a gpio's IRQ) > - If a GPIO controller supports several GPIOs but one IRQ, is it > defined what gpio_to_irq should return? > - Is it okay for gpio_to_irq to return NO_IRQ?  (returned by > irq_of_parse_and_map) if irq is not defined? > > > Henk. > > diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c > index 6eea601..81927d7 100644 > --- a/drivers/of/gpio.c > +++ b/drivers/of/gpio.c > @@ -150,6 +150,17 @@ int of_gpio_simple_xlate(struct of_gpio_chip > *of_gc, struct device_node *np, >  } >  EXPORT_SYMBOL(of_gpio_simple_xlate); > > +static int of_mm_gpio_to_irq(struct gpio_chip *gc, unsigned int gpio) > +{ > +       struct of_mm_gpio_chip *mm_gc; > +       struct of_gpio_chip *of_gc; > + > +       of_gc = container_of(gc, struct of_gpio_chip, gc); > +       mm_gc = container_of(of_gc, struct of_mm_gpio_chip, of_gc); > +       return mm_gc->irq; > + > +} > + >  /** >  * of_mm_gpiochip_add - Add memory mapped GPIO chip (bank) >  * @np:                device node of the GPIO chip > @@ -188,6 +199,9 @@ int of_mm_gpiochip_add(struct device_node *np, > >        gc->base = -1; > > +       mm_gc->irq = irq_of_parse_and_map(np, 0); > +       gc->to_irq = of_mm_gpio_to_irq; > + >        if (!of_gc->xlate) >                of_gc->xlate = of_gpio_simple_xlate; > > diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h > index fc2472c..17fe9ed 100644 > --- a/include/linux/of_gpio.h > +++ b/include/linux/of_gpio.h > @@ -54,6 +54,7 @@ struct of_mm_gpio_chip { >        struct of_gpio_chip of_gc; >        void (*save_regs)(struct of_mm_gpio_chip *mm_gc); >        void __iomem *regs; > +       int irq; >  }; > >  static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc) > diff --git a/arch/powerpc/include/asm/gpio.h b/arch/powerpc/include/asm/gpio.h index ea04632..38762ed 100644 --- a/arch/powerpc/include/asm/gpio.h +++ b/arch/powerpc/include/asm/gpio.h @@ -38,12 +38,9 @@ static inline int gpio_cansleep(unsigned int gpio) return __gpio_cansleep(gpio); } -/* - * Not implemented, yet. - */ static inline int gpio_to_irq(unsigned int gpio) { - return -ENOSYS; + return __gpio_to_irq(gpio); } static inline int irq_to_gpio(unsigned int irq)