Skip to contentSkip to conversation

gpio/mxs: save the unnecessary function mxs_gpio_to_irq

PATCH New Shawn Guo 4 participants 6 messages Jun 6, 2011

Subsystems (4)
lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

PATCH 1/2 gpio/mxs: save the unnecessary function mxs_gpio_to_irq

The irq number can be easily calculated from the sum of MXS_GPIO_IRQ_START and gpio number. The patch directly defines gpio_to_irq for it and removes mxs_gpio_to_irq to simplify the the driver.

---
 arch/arm/mach-mxs/include/mach/gpio.h |    2 +-
 drivers/gpio/gpio-mxs.c               |    9 ---------
 2 files changed, 1 insertions(+), 10 deletions(-)
arch/arm/mach-mxs/include/mach/gpio.h +1 -1
index 828cccc..18017c5 100644
@@ -28,8 +28,8 @@
 #define gpio_get_value		__gpio_get_value
 #define gpio_set_value		__gpio_set_value
 #define gpio_cansleep		__gpio_cansleep
-#define gpio_to_irq		__gpio_to_irq
 
 #define irq_to_gpio(irq)	((irq) - MXS_GPIO_IRQ_START)
+#define gpio_to_irq(gpio)	(MXS_GPIO_IRQ_START + (gpio))
 
 #endif /* __MACH_MXS_GPIO_H__ */
drivers/gpio/gpio-mxs.c +0 -9
index a287614..d01f046 100644
@@ -236,14 +236,6 @@ static void mxs_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 		writel(1 << offset, pin_addr + MXS_CLR);
 }
 
-static int mxs_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
-{
-	struct mxs_gpio_port *port =
-		container_of(chip, struct mxs_gpio_port, chip);
-
-	return port->virtual_irq_start + offset;
-}
-
 static int mxs_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
 {
 	mxs_set_gpio_direction(chip, offset, 0);
@@ -327,7 +319,6 @@ static int __devinit mxs_gpio_probe(struct platform_device *pdev)
 	port->chip.direction_output = mxs_gpio_direction_output;
 	port->chip.get = mxs_gpio_get;
 	port->chip.set = mxs_gpio_set;
-	port->chip.to_irq = mxs_gpio_to_irq;
 	port->chip.base = port->id * 32;
 	port->chip.ngpio = 32;
 
Signature · 1 line
1.7.4.1
author
#1 lore raw

PATCH 2/2 gpio/mxs: convert gpio-mxs to use basic_mmio_gpio library

The gpio-mxs controller complies with basic_mmio_gpio library. This patch converts the driver to use the library.

---
 drivers/gpio/Kconfig    |    1 +
 drivers/gpio/gpio-mxs.c |   73 +++++++++--------------------------------------
 2 files changed, 15 insertions(+), 59 deletions(-)
drivers/gpio/Kconfig +1 -0
index daaef0f..0b858e5 100644
@@ -96,6 +96,7 @@ config GPIO_EXYNOS4
 config GPIO_MXS
 	def_bool y
 	depends on ARCH_MXS
+	select GPIO_BASIC_MMIO_CORE
 
 config GPIO_PLAT_SAMSUNG
 	bool "Samsung SoCs GPIO library support"
drivers/gpio/gpio-mxs.c +14 -59

108 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 2/2 gpio/mxs: convert gpio-mxs to use basic_mmio_gpio library

Quoted 4 lines · Shawn Guo

The gpio-mxs controller complies with basic_mmio_gpio library. This patch converts the driver to use the library.

Given that patch 1 was nacked, I'm assuming I should ignore this patch?

g.

Quoted 137 lines
---
 drivers/gpio/Kconfig    |    1 +
 drivers/gpio/gpio-mxs.c |   73 +++++++++--------------------------------------
 2 files changed, 15 insertions(+), 59 deletions(-)
drivers/gpio/Kconfig +1 -0
index daaef0f..0b858e5 100644
@@ -96,6 +96,7 @@ config GPIO_EXYNOS4
 config GPIO_MXS
 	def_bool y
 	depends on ARCH_MXS
+	select GPIO_BASIC_MMIO_CORE
 
 config GPIO_PLAT_SAMSUNG
 	bool "Samsung SoCs GPIO library support"
drivers/gpio/gpio-mxs.c +14 -59
index d01f046..9897641 100644
@@ -27,6 +27,7 @@
 #include <linux/gpio.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
+#include <linux/basic_mmio_gpio.h>
 #include <mach/mxs.h>
 
 #define MXS_SET		0x4
@@ -54,7 +55,7 @@ struct mxs_gpio_port {
 	int irq;
 	int irq_high;
 	int virtual_irq_start;
-	struct gpio_chip chip;
+	struct bgpio_chip bgc;
 };
 
 /* Note: This driver assumes 32 GPIOs are handled in one register */
@@ -99,8 +100,6 @@ static void mxs_gpio_unmask_irq(struct irq_data *d)
 	set_gpio_irqenable(port, gpio & 0x1f, 1);
 }
 
-static int mxs_gpio_get(struct gpio_chip *chip, unsigned offset);
-
 static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type)
 {
 	u32 gpio = irq_to_gpio(d->irq);
@@ -203,53 +202,6 @@ static struct irq_chip gpio_irq_chip = {
 	.irq_set_wake = mxs_gpio_set_wake_irq,
 };
 
-static void mxs_set_gpio_direction(struct gpio_chip *chip, unsigned offset,
-				int dir)
-{
-	struct mxs_gpio_port *port =
-		container_of(chip, struct mxs_gpio_port, chip);
-	void __iomem *pin_addr = port->base + PINCTRL_DOE(port->id);
-
-	if (dir)
-		writel(1 << offset, pin_addr + MXS_SET);
-	else
-		writel(1 << offset, pin_addr + MXS_CLR);
-}
-
-static int mxs_gpio_get(struct gpio_chip *chip, unsigned offset)
-{
-	struct mxs_gpio_port *port =
-		container_of(chip, struct mxs_gpio_port, chip);
-
-	return (readl(port->base + PINCTRL_DIN(port->id)) >> offset) & 1;
-}
-
-static void mxs_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
-{
-	struct mxs_gpio_port *port =
-		container_of(chip, struct mxs_gpio_port, chip);
-	void __iomem *pin_addr = port->base + PINCTRL_DOUT(port->id);
-
-	if (value)
-		writel(1 << offset, pin_addr + MXS_SET);
-	else
-		writel(1 << offset, pin_addr + MXS_CLR);
-}
-
-static int mxs_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
-{
-	mxs_set_gpio_direction(chip, offset, 0);
-	return 0;
-}
-
-static int mxs_gpio_direction_output(struct gpio_chip *chip,
-				     unsigned offset, int value)
-{
-	mxs_gpio_set(chip, offset, value);
-	mxs_set_gpio_direction(chip, offset, 1);
-	return 0;
-}
-
 static int __devinit mxs_gpio_probe(struct platform_device *pdev)
 {
 	static void __iomem *base;
@@ -314,20 +266,23 @@ static int __devinit mxs_gpio_probe(struct platform_device *pdev)
 	irq_set_chained_handler(port->irq, mxs_gpio_irq_handler);
 	irq_set_handler_data(port->irq, port);
 
-	/* register gpio chip */
-	port->chip.direction_input = mxs_gpio_direction_input;
-	port->chip.direction_output = mxs_gpio_direction_output;
-	port->chip.get = mxs_gpio_get;
-	port->chip.set = mxs_gpio_set;
-	port->chip.base = port->id * 32;
-	port->chip.ngpio = 32;
-
-	err = gpiochip_add(&port->chip);
+	err = bgpio_init(&port->bgc, &pdev->dev, 4,
+			 port->base + PINCTRL_DIN(port->id),
+			 port->base + PINCTRL_DOUT(port->id), NULL,
+			 port->base + PINCTRL_DOE(port->id), NULL, false);
 	if (err)
 		goto out_iounmap;
 
+	port->bgc.gc.base = port->id * 32;
+
+	err = gpiochip_add(&port->bgc.gc);
+	if (err)
+		goto out_bgpio_remove;
+
 	return 0;
 
+out_bgpio_remove:
+	bgpio_remove(&port->bgc);
 out_iounmap:
 	if (iores)
 		iounmap(port->base);
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH 2/2 gpio/mxs: convert gpio-mxs to use basic_mmio_gpio library

Quoted 8 lines · Grant Likely
Quoted 4 lines · Shawn Guo

The gpio-mxs controller complies with basic_mmio_gpio library. This patch converts the driver to use the library.

Given that patch 1 was nacked, I'm assuming I should ignore this patch?

Yes. I will send a v2 of this patch.

Signature · 2 lines
Regards,
Shawn
maintainer NAK
#4 lore raw

PATCH 1/2 gpio/mxs: save the unnecessary function mxs_gpio_to_irq

In reply to Shawn Guo

Hi Shawn,

Quoted 16 lines · Shawn Guo

The irq number can be easily calculated from the sum of MXS_GPIO_IRQ_START and gpio number. The patch directly defines gpio_to_irq for it and removes mxs_gpio_to_irq to simplify the the driver.

---
 arch/arm/mach-mxs/include/mach/gpio.h |    2 +-
 drivers/gpio/gpio-mxs.c               |    9 ---------
 2 files changed, 1 insertions(+), 10 deletions(-)
arch/arm/mach-mxs/include/mach/gpio.h +0 -0
index 828cccc..18017c5 100644

arch/arm/mach-mxs/include/mach/gpio.h line 33

Quoted 7 lines
arch/arm/mach-mxs/include/mach/gpio.h +1 -1
@@ -28,8 +28,8 @@
 #define gpio_get_value		__gpio_get_value
 #define gpio_set_value		__gpio_set_value
 #define gpio_cansleep		__gpio_cansleep
-#define gpio_to_irq		__gpio_to_irq
 
 #define irq_to_gpio(irq)	((irq) - MXS_GPIO_IRQ_START)
+#define gpio_to_irq(gpio)	(MXS_GPIO_IRQ_START + (gpio))

NACK

This is no good idea. __gpio_to_irq also works correctly for i2c gpio expanders and the like whereas your patch limits the gio_to_irq usage to internal gpios. Better to keep it like it is.

Sascha

Quoted 38 lines
arch/arm/mach-mxs/include/mach/gpio.h +0 -0
 #endif /* __MACH_MXS_GPIO_H__ */
drivers/gpio/gpio-mxs.c +0 -9
index a287614..d01f046 100644
@@ -236,14 +236,6 @@ static void mxs_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 		writel(1 << offset, pin_addr + MXS_CLR);
 }
 
-static int mxs_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
-{
-	struct mxs_gpio_port *port =
-		container_of(chip, struct mxs_gpio_port, chip);
-
-	return port->virtual_irq_start + offset;
-}
-
 static int mxs_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
 {
 	mxs_set_gpio_direction(chip, offset, 0);
@@ -327,7 +319,6 @@ static int __devinit mxs_gpio_probe(struct platform_device *pdev)
 	port->chip.direction_output = mxs_gpio_direction_output;
 	port->chip.get = mxs_gpio_get;
 	port->chip.set = mxs_gpio_set;
-	port->chip.to_irq = mxs_gpio_to_irq;
 	port->chip.base = port->id * 32;
 	port->chip.ngpio = 32;
 
Signature · 7 lines
1.7.4.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#5 lore raw

PATCH 1/2 gpio/mxs: save the unnecessary function mxs_gpio_to_irq

Quoted 24 lines · Sascha Hauer

Hi Shawn,

Quoted 21 lines · Shawn Guo

The irq number can be easily calculated from the sum of MXS_GPIO_IRQ_START and gpio number. The patch directly defines gpio_to_irq for it and removes mxs_gpio_to_irq to simplify the the driver.

---
 arch/arm/mach-mxs/include/mach/gpio.h |    2 +-
 drivers/gpio/gpio-mxs.c               |    9 ---------
 2 files changed, 1 insertions(+), 10 deletions(-)
arch/arm/mach-mxs/include/mach/gpio.h +0 -1
index 828cccc..18017c5 100644
@@ -28,8 +28,8 @@
 #define gpio_get_value		__gpio_get_value
 #define gpio_set_value		__gpio_set_value
 #define gpio_cansleep		__gpio_cansleep
-#define gpio_to_irq		__gpio_to_irq
 
Quoted 9 lines

arch/arm/mach-mxs/include/mach/gpio.h line 33

Quoted 2 lines
arch/arm/mach-mxs/include/mach/gpio.h +1 -0
 #define irq_to_gpio(irq)	((irq) - MXS_GPIO_IRQ_START)
+#define gpio_to_irq(gpio)	(MXS_GPIO_IRQ_START + (gpio))

NACK

This is no good idea. __gpio_to_irq also works correctly for i2c gpio expanders and the like whereas your patch limits the gio_to_irq usage to internal gpios. Better to keep it like it is.

What I was trying to do is moving gpio-mxs one step closer to gpio-mxc. I thought what gpio-mxc is doing should have been proved fine by a wider users/platforms. But you are telling this is one step backward. Then I will drop the patch.

Signature · 2 lines
Regards,
Shawn