From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934920Ab1ETO1O (ORCPT ); Fri, 20 May 2011 10:27:14 -0400 Received: from tx2ehsobe003.messaging.microsoft.com ([65.55.88.13]:59157 "EHLO TX2EHSOBE005.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751828Ab1ETO1L (ORCPT ); Fri, 20 May 2011 10:27:11 -0400 X-SpamScore: -9 X-BigFish: VS-9(zz1432N98dKzz1202hzz8275dhz2dh2a8h668h839h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: CIP:70.37.183.190;KIP:(null);UIP:(null);IPVD:NLI;H:mail.freescale.net;RD:none;EFVD:NLI Date: Fri, 20 May 2011 22:31:38 +0800 From: Shawn Guo To: Sascha Hauer CC: Shawn Guo , , , , , , Subject: Re: [PATCH 4/4] gpio: gpio-mxs: add gpio driver for Freescale MXS architecture Message-ID: <20110520143137.GB27551@S2100-06.ap.freescale.net> References: <1305885089-27343-1-git-send-email-shawn.guo@linaro.org> <1305885089-27343-5-git-send-email-shawn.guo@linaro.org> <20110520112455.GB10403@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20110520112455.GB10403@pengutronix.de> User-Agent: Mutt/1.5.21 (2010-09-15) X-OriginatorOrg: freescale.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 20, 2011 at 01:24:55PM +0200, Sascha Hauer wrote: > On Fri, May 20, 2011 at 05:51:29PM +0800, Shawn Guo wrote: > > Add gpio-mxs driver by moving arch/arm/mach-mxs/gpio.c into > > drivers/gpio. > > > > Signed-off-by: Shawn Guo > > --- > > drivers/gpio/Kconfig | 3 + > > drivers/gpio/Makefile | 1 + > > drivers/gpio/gpio-mxs.c | 168 ++++++++++++++++++++++++++++++++++------------- > > 3 files changed, 125 insertions(+), 47 deletions(-) > > > > diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig > > index d3b2953..ccca658 100644 > > --- a/drivers/gpio/Kconfig > > +++ b/drivers/gpio/Kconfig > > @@ -81,6 +81,9 @@ config GPIO_IT8761E > > help > > Say yes here to support GPIO functionality of IT8761E super I/O chip. > > > > +config GPIO_MXS > > + bool > > + > > config GPIO_PL061 > > bool "PrimeCell PL061 GPIO support" > > depends on ARM_AMBA > > diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile > > index becef59..b06a335 100644 > > --- a/drivers/gpio/Makefile > > +++ b/drivers/gpio/Makefile > > @@ -18,6 +18,7 @@ obj-$(CONFIG_GPIO_MAX7301) += max7301.o > > obj-$(CONFIG_GPIO_MAX732X) += max732x.o > > obj-$(CONFIG_GPIO_MC33880) += mc33880.o > > obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o > > +obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o > > obj-$(CONFIG_GPIO_74X164) += 74x164.o > > obj-$(CONFIG_GPIO_PCA953X) += pca953x.o > > obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o > > diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c > > index 6a59bf2..b33b2bc 100644 > > --- a/drivers/gpio/gpio-mxs.c > > +++ b/drivers/gpio/gpio-mxs.c > > @@ -25,14 +25,18 @@ > > #include > > #include > > #include > > -#include > > -#include > > -#include > > - > > -#include "gpio.h" > > - > > -static struct mxs_gpio_port *mxs_gpio_ports; > > -static int gpio_table_size; > > +#include > > +#include > > +#include > > + > > +struct mxs_gpio_port { > > + void __iomem *base; > > + int id; > > + int irq; > > + int irq_high; > > + int virtual_irq_start; > > + struct gpio_chip chip; > > +}; > > > > #define MXS_SET 0x4 > > #define MXS_CLR 0x8 > > @@ -76,20 +80,23 @@ static void set_gpio_irqenable(struct mxs_gpio_port *port, u32 index, > > > > static void mxs_gpio_ack_irq(struct irq_data *d) > > { > > + struct mxs_gpio_port *port = irq_data_get_irq_chip_data(d); > > u32 gpio = irq_to_gpio(d->irq); > > - clear_gpio_irqstatus(&mxs_gpio_ports[gpio / 32], gpio & 0x1f); > > + clear_gpio_irqstatus(port, gpio & 0x1f); > > } > > > > static void mxs_gpio_mask_irq(struct irq_data *d) > > { > > + struct mxs_gpio_port *port = irq_data_get_irq_chip_data(d); > > u32 gpio = irq_to_gpio(d->irq); > > - set_gpio_irqenable(&mxs_gpio_ports[gpio / 32], gpio & 0x1f, 0); > > + set_gpio_irqenable(port, gpio & 0x1f, 0); > > } > > > > static void mxs_gpio_unmask_irq(struct irq_data *d) > > { > > + struct mxs_gpio_port *port = irq_data_get_irq_chip_data(d); > > u32 gpio = irq_to_gpio(d->irq); > > - set_gpio_irqenable(&mxs_gpio_ports[gpio / 32], gpio & 0x1f, 1); > > + set_gpio_irqenable(port, gpio & 0x1f, 1); > > } > > > > static int mxs_gpio_get(struct gpio_chip *chip, unsigned offset); > > @@ -98,7 +105,7 @@ static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type) > > { > > u32 gpio = irq_to_gpio(d->irq); > > u32 pin_mask = 1 << (gpio & 31); > > - struct mxs_gpio_port *port = &mxs_gpio_ports[gpio / 32]; > > + struct mxs_gpio_port *port = irq_data_get_irq_chip_data(d); > > void __iomem *pin_addr; > > int edge; > > > > @@ -142,7 +149,7 @@ static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type) > > static void mxs_gpio_irq_handler(u32 irq, struct irq_desc *desc) > > { > > u32 irq_stat; > > - struct mxs_gpio_port *port = (struct mxs_gpio_port *)irq_get_handler_data(irq); > > + struct mxs_gpio_port *port = irq_get_handler_data(irq); > > u32 gpio_irq_no_base = port->virtual_irq_start; > > > > desc->irq_data.chip->irq_ack(&desc->irq_data); > > @@ -170,7 +177,7 @@ static int mxs_gpio_set_wake_irq(struct irq_data *d, unsigned int enable) > > { > > u32 gpio = irq_to_gpio(d->irq); > > u32 gpio_idx = gpio & 0x1f; > > - struct mxs_gpio_port *port = &mxs_gpio_ports[gpio / 32]; > > + struct mxs_gpio_port *port = irq_data_get_irq_chip_data(d); > > > > if (enable) { > > if (port->irq_high && (gpio_idx >= 16)) > > @@ -251,47 +258,114 @@ static int mxs_gpio_direction_output(struct gpio_chip *chip, > > return 0; > > } > > > > -int __init mxs_gpio_init(struct mxs_gpio_port *port, int cnt) > > +static int __devinit mxs_gpio_probe(struct platform_device *pdev) > > { > > - int i, j; > > + static void __iomem *base; > > + struct mxs_gpio_port *port; > > + struct resource *iores = NULL; > > + int err, i; > > + > > + port = kzalloc(sizeof(struct mxs_gpio_port), GFP_KERNEL); > > + if (!port) > > + return -ENOMEM; > > + > > + port->id = pdev->id; > > + port->virtual_irq_start = MXS_GPIO_IRQ_START + port->id * 32; > > + > > + /* > > + * map memory region only once, as all the gpio ports > > + * share the same one > > + */ > > + if (!base) { > > If the different ports share the same address and can't be seperated I > wonder whether it's better to register only one platform device for all > ports. gpio-u300 is one example that register one platform device for all ports. Comparing to it, the gpio-mxs driver looks simpler and cleaner, and there is no platform data. We may agree that every single port should register its own platform device, if the ports are all independent to each other with their own base address. Then same base address could be special case of different base address, so that we can make driver implementation a little common for both cases. If people think these two cases (sharing ports vs. independent ports) will be sorted into two different patterns, yes, gpio-mxs should go the way that gpio-u300 is going. So please comment, people (Grant? :) > (classic) i.MX has a similar problem where one single interrupt is > shared by all gpio ports. Ok, this could be worked around with another > chained handler which dispatches the single interrupt to each port. > -- Regards, Shawn From mboxrd@z Thu Jan 1 00:00:00 1970 From: shawn.guo@freescale.com (Shawn Guo) Date: Fri, 20 May 2011 22:31:38 +0800 Subject: [PATCH 4/4] gpio: gpio-mxs: add gpio driver for Freescale MXS architecture In-Reply-To: <20110520112455.GB10403@pengutronix.de> References: <1305885089-27343-1-git-send-email-shawn.guo@linaro.org> <1305885089-27343-5-git-send-email-shawn.guo@linaro.org> <20110520112455.GB10403@pengutronix.de> Message-ID: <20110520143137.GB27551@S2100-06.ap.freescale.net> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Fri, May 20, 2011 at 01:24:55PM +0200, Sascha Hauer wrote: > On Fri, May 20, 2011 at 05:51:29PM +0800, Shawn Guo wrote: > > Add gpio-mxs driver by moving arch/arm/mach-mxs/gpio.c into > > drivers/gpio. > > > > Signed-off-by: Shawn Guo > > --- > > drivers/gpio/Kconfig | 3 + > > drivers/gpio/Makefile | 1 + > > drivers/gpio/gpio-mxs.c | 168 ++++++++++++++++++++++++++++++++++------------- > > 3 files changed, 125 insertions(+), 47 deletions(-) > > > > diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig > > index d3b2953..ccca658 100644 > > --- a/drivers/gpio/Kconfig > > +++ b/drivers/gpio/Kconfig > > @@ -81,6 +81,9 @@ config GPIO_IT8761E > > help > > Say yes here to support GPIO functionality of IT8761E super I/O chip. > > > > +config GPIO_MXS > > + bool > > + > > config GPIO_PL061 > > bool "PrimeCell PL061 GPIO support" > > depends on ARM_AMBA > > diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile > > index becef59..b06a335 100644 > > --- a/drivers/gpio/Makefile > > +++ b/drivers/gpio/Makefile > > @@ -18,6 +18,7 @@ obj-$(CONFIG_GPIO_MAX7301) += max7301.o > > obj-$(CONFIG_GPIO_MAX732X) += max732x.o > > obj-$(CONFIG_GPIO_MC33880) += mc33880.o > > obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o > > +obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o > > obj-$(CONFIG_GPIO_74X164) += 74x164.o > > obj-$(CONFIG_GPIO_PCA953X) += pca953x.o > > obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o > > diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c > > index 6a59bf2..b33b2bc 100644 > > --- a/drivers/gpio/gpio-mxs.c > > +++ b/drivers/gpio/gpio-mxs.c > > @@ -25,14 +25,18 @@ > > #include > > #include > > #include > > -#include > > -#include > > -#include > > - > > -#include "gpio.h" > > - > > -static struct mxs_gpio_port *mxs_gpio_ports; > > -static int gpio_table_size; > > +#include > > +#include > > +#include > > + > > +struct mxs_gpio_port { > > + void __iomem *base; > > + int id; > > + int irq; > > + int irq_high; > > + int virtual_irq_start; > > + struct gpio_chip chip; > > +}; > > > > #define MXS_SET 0x4 > > #define MXS_CLR 0x8 > > @@ -76,20 +80,23 @@ static void set_gpio_irqenable(struct mxs_gpio_port *port, u32 index, > > > > static void mxs_gpio_ack_irq(struct irq_data *d) > > { > > + struct mxs_gpio_port *port = irq_data_get_irq_chip_data(d); > > u32 gpio = irq_to_gpio(d->irq); > > - clear_gpio_irqstatus(&mxs_gpio_ports[gpio / 32], gpio & 0x1f); > > + clear_gpio_irqstatus(port, gpio & 0x1f); > > } > > > > static void mxs_gpio_mask_irq(struct irq_data *d) > > { > > + struct mxs_gpio_port *port = irq_data_get_irq_chip_data(d); > > u32 gpio = irq_to_gpio(d->irq); > > - set_gpio_irqenable(&mxs_gpio_ports[gpio / 32], gpio & 0x1f, 0); > > + set_gpio_irqenable(port, gpio & 0x1f, 0); > > } > > > > static void mxs_gpio_unmask_irq(struct irq_data *d) > > { > > + struct mxs_gpio_port *port = irq_data_get_irq_chip_data(d); > > u32 gpio = irq_to_gpio(d->irq); > > - set_gpio_irqenable(&mxs_gpio_ports[gpio / 32], gpio & 0x1f, 1); > > + set_gpio_irqenable(port, gpio & 0x1f, 1); > > } > > > > static int mxs_gpio_get(struct gpio_chip *chip, unsigned offset); > > @@ -98,7 +105,7 @@ static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type) > > { > > u32 gpio = irq_to_gpio(d->irq); > > u32 pin_mask = 1 << (gpio & 31); > > - struct mxs_gpio_port *port = &mxs_gpio_ports[gpio / 32]; > > + struct mxs_gpio_port *port = irq_data_get_irq_chip_data(d); > > void __iomem *pin_addr; > > int edge; > > > > @@ -142,7 +149,7 @@ static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type) > > static void mxs_gpio_irq_handler(u32 irq, struct irq_desc *desc) > > { > > u32 irq_stat; > > - struct mxs_gpio_port *port = (struct mxs_gpio_port *)irq_get_handler_data(irq); > > + struct mxs_gpio_port *port = irq_get_handler_data(irq); > > u32 gpio_irq_no_base = port->virtual_irq_start; > > > > desc->irq_data.chip->irq_ack(&desc->irq_data); > > @@ -170,7 +177,7 @@ static int mxs_gpio_set_wake_irq(struct irq_data *d, unsigned int enable) > > { > > u32 gpio = irq_to_gpio(d->irq); > > u32 gpio_idx = gpio & 0x1f; > > - struct mxs_gpio_port *port = &mxs_gpio_ports[gpio / 32]; > > + struct mxs_gpio_port *port = irq_data_get_irq_chip_data(d); > > > > if (enable) { > > if (port->irq_high && (gpio_idx >= 16)) > > @@ -251,47 +258,114 @@ static int mxs_gpio_direction_output(struct gpio_chip *chip, > > return 0; > > } > > > > -int __init mxs_gpio_init(struct mxs_gpio_port *port, int cnt) > > +static int __devinit mxs_gpio_probe(struct platform_device *pdev) > > { > > - int i, j; > > + static void __iomem *base; > > + struct mxs_gpio_port *port; > > + struct resource *iores = NULL; > > + int err, i; > > + > > + port = kzalloc(sizeof(struct mxs_gpio_port), GFP_KERNEL); > > + if (!port) > > + return -ENOMEM; > > + > > + port->id = pdev->id; > > + port->virtual_irq_start = MXS_GPIO_IRQ_START + port->id * 32; > > + > > + /* > > + * map memory region only once, as all the gpio ports > > + * share the same one > > + */ > > + if (!base) { > > If the different ports share the same address and can't be seperated I > wonder whether it's better to register only one platform device for all > ports. gpio-u300 is one example that register one platform device for all ports. Comparing to it, the gpio-mxs driver looks simpler and cleaner, and there is no platform data. We may agree that every single port should register its own platform device, if the ports are all independent to each other with their own base address. Then same base address could be special case of different base address, so that we can make driver implementation a little common for both cases. If people think these two cases (sharing ports vs. independent ports) will be sorted into two different patterns, yes, gpio-mxs should go the way that gpio-u300 is going. So please comment, people (Grant? :) > (classic) i.MX has a similar problem where one single interrupt is > shared by all gpio ports. Ok, this could be worked around with another > chained handler which dispatches the single interrupt to each port. > -- Regards, Shawn