Skip to contentSkip to conversation

Add Generic GPIO driver

RFC In review Alexander Shiyan 2 participants 7 messages Feb 15, 2013 – Feb 19, 2013 GPIO

lore
Share & tools
lore
#0 lore raw

RFC 1/1 Add Generic GPIO driver

This patch adds generic memory-mapped GPIO controller support. Code taken from Linux Kernel and adopted for barebox.

---
 drivers/gpio/Kconfig            |  10 +
 drivers/gpio/Makefile           |   5 +-
 drivers/gpio/gpio-generic.c     | 427 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpio/gpio.c             |   5 +
 include/gpio.h                  |   2 +
 include/linux/basic_mmio_gpio.h |  68 +++++++
 6 files changed, 515 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpio/gpio-generic.c
 create mode 100644 include/linux/basic_mmio_gpio.h
drivers/gpio/Kconfig +10 -0
index 89be684..565f5bd 100644
@@ -6,10 +6,20 @@ if GPIOLIB
 
 menu "GPIO"
 
+config GPIO_GENERIC
+	def_bool y
+
 config GPIO_BCM2835
 	bool "GPIO support for BCM2835"
 	depends on ARCH_BCM2835
 
+config GPIO_GENERIC_PLATFORM
+	bool "Generic memory-mapped GPIO controller support"
+	select GPIO_GENERIC
+	help
+	  Say yes here to support basic platform memory-mapped
+	  GPIO controllers
+
 config GPIO_PL061
 	bool "PrimeCell PL061 GPIO support"
 	depends on ARM_AMBA
drivers/gpio/Makefile +3 -2
index 993ab89..1ef345c 100644
@@ -1,4 +1,5 @@
-obj-$(CONFIG_GPIOLIB) += gpio.o
+obj-$(CONFIG_GPIOLIB)		+= gpio.o
 obj-$(CONFIG_GPIO_BCM2835)	+= gpio-bcm2835.o
+obj-$(CONFIG_GPIO_GENERIC)	+= gpio-generic.o
 obj-$(CONFIG_GPIO_PL061)	+= gpio-pl061.o
-obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o
+obj-$(CONFIG_GPIO_STMPE)	+= gpio-stmpe.o
drivers/gpio/gpio-generic.c new file +427 -0

427 lines not on this page · raw message

drivers/gpio/gpio.c +5 -0
index d37f5a0..6d29224 100644
@@ -189,6 +189,11 @@ int gpiochip_add(struct gpio_chip *chip)
 	return 0;
 }
 
+void gpiochip_remove(struct gpio_chip *chip)
+{
+	list_del(&chip->list);
+}
+
 int gpio_get_num(struct device_d *dev, int gpio)
 {
 	struct gpio_chip *chip;
include/gpio.h +2 -0
index eedb980..6d8336b 100644
@@ -2,6 +2,7 @@
 #define __GPIO_H
 
 #include <asm/gpio.h>
+#include <linux/list.h>
 
 #ifndef CONFIG_GPIOLIB
 static inline int gpio_request(unsigned gpio, const char *label)
@@ -40,6 +41,7 @@ struct gpio_chip {
 };
 
 int gpiochip_add(struct gpio_chip *chip);
+void gpiochip_remove(struct gpio_chip *chip);
 
 int gpio_get_num(struct device_d *dev, int gpio);
 
include/linux/basic_mmio_gpio.h new file +68 -0

68 lines not on this page · raw message

Signature · 7 lines
1.7.12.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

Hi Alexander,

Quoted 2 lines · Alexander Shiyan

This patch adds generic memory-mapped GPIO controller support. Code taken from Linux Kernel and adopted for barebox.

I'm fine with this if you add a user for it. I wonder though if it's worth it to have this driver for barebox. If I have a driver in the kernel that already uses it, then this makes it simple to copy it, but should I have to write a new gpio driver, I'm unsure if it's simpler to write a new gpio driver or to register with the generic gpio driver.

drivers/gpio/Kconfig if GPIOLIB · line 11

Quoted 11 lines
drivers/gpio/Kconfig +3 -0
index 89be684..565f5bd 100644
@@ -6,10 +6,20 @@ if GPIOLIB
 
 menu "GPIO"
 
+config GPIO_GENERIC
+	def_bool y
+

Please do not unconditionally enable this for all configs.

Sascha

Signature · 9 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 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw
Quoted 10 lines · Alexander Shiyan
Quoted 2 lines

This patch adds generic memory-mapped GPIO controller support. Code taken from Linux Kernel and adopted for barebox.

I'm fine with this if you add a user for it. I wonder though if it's worth it to have this driver for barebox. If I have a driver in the kernel that already uses it, then this makes it simple to copy it, but should I have to write a new gpio driver, I'm unsure if it's simpler to write a new gpio driver or to register with the generic gpio driver.

Here's an example that I'm checking:

/*
* Copyright (C) 2013 Alexander Shiyan <[email protected]> *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. */

#include <init.h>
#include <common.h>
#include <malloc.h>

#include <linux/basic_mmio_gpio.h>

static int clps711x_gpio_probe(struct device_d *dev)

{
	int err;
	void __iomem *dat, *dir, *dir_inv;
	struct bgpio_chip *bgc;
	struct bgpio_pdata *pdata = dev->platform_data;

	if (!pdata)
		return -ENODATA;

	dat = dev_request_mem_region_by_name(dev, "dat");
	dir = dev_request_mem_region_by_name(dev, "dir");
	dir_inv = dev_request_mem_region_by_name(dev, "dir_inv");
	if (!dat || (!dir && !dir_inv))
		return -EINVAL;

	bgc = xzalloc(sizeof(struct bgpio_chip));
	if (!bgc)
		return -ENOMEM;

	err = bgpio_init(bgc, dev, 1, dat, NULL, NULL, dir, dir_inv, 0);
	if (err) {
		free(bgc);
		return err;
	}

	bgc->gc.base = pdata->base;
	bgc->gc.ngpio = pdata->ngpio;

	return gpiochip_add(&bgc->gc);
}
static struct driver_d clps711x_gpio_driver = {
	.name	= "clps711x-gpio",
	.probe	= clps711x_gpio_probe,
};

static __init int clps711x_gpio_register(void)

{
	return platform_driver_register(&clps711x_gpio_driver);
}

coredevice_initcall(clps711x_gpio_register);

---
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#3 lore raw
Quoted 4 lines · Alexander Shiyan
Quoted 4 lines · Alexander Shiyan
Quoted 2 lines

This patch adds generic memory-mapped GPIO controller support. Code taken from Linux Kernel and adopted for barebox.

Quoted 8 lines
Quoted 6 lines

I'm fine with this if you add a user for it. I wonder though if it's worth it to have this driver for barebox. If I have a driver in the kernel that already uses it, then this makes it simple to copy it, but should I have to write a new gpio driver, I'm unsure if it's simpler to write a new gpio driver or to register with the generic gpio driver.

Here's an example that I'm checking:

Ok, this indeed looks nice and short. You convinced me ;)

As said, I'm fine with the generic gpio driver if you add the below as first user.

Sascha

Quoted 60 lines

/*
* Copyright (C) 2013 Alexander Shiyan <[email protected]> *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. */

#include <init.h>
#include <common.h>
#include <malloc.h>

#include <linux/basic_mmio_gpio.h>

static int clps711x_gpio_probe(struct device_d *dev)

{
	int err;
	void __iomem *dat, *dir, *dir_inv;
	struct bgpio_chip *bgc;
	struct bgpio_pdata *pdata = dev->platform_data;

	if (!pdata)
		return -ENODATA;

	dat = dev_request_mem_region_by_name(dev, "dat");
	dir = dev_request_mem_region_by_name(dev, "dir");
	dir_inv = dev_request_mem_region_by_name(dev, "dir_inv");
	if (!dat || (!dir && !dir_inv))
		return -EINVAL;

	bgc = xzalloc(sizeof(struct bgpio_chip));
	if (!bgc)
		return -ENOMEM;

	err = bgpio_init(bgc, dev, 1, dat, NULL, NULL, dir, dir_inv, 0);
	if (err) {
		free(bgc);
		return err;
	}

	bgc->gc.base = pdata->base;
	bgc->gc.ngpio = pdata->ngpio;

	return gpiochip_add(&bgc->gc);
}
static struct driver_d clps711x_gpio_driver = {
	.name	= "clps711x-gpio",
	.probe	= clps711x_gpio_probe,
};

static __init int clps711x_gpio_register(void)

{
	return platform_driver_register(&clps711x_gpio_driver);
}

coredevice_initcall(clps711x_gpio_register);

---

Signature · 9 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 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw
Quoted 12 lines · Alexander Shiyan
Quoted 11 lines
Quoted 10 lines · Alexander Shiyan
Quoted 2 lines

This patch adds generic memory-mapped GPIO controller support. Code taken from Linux Kernel and adopted for barebox.

I'm fine with this if you add a user for it. I wonder though if it's worth it to have this driver for barebox. If I have a driver in the kernel that already uses it, then this makes it simple to copy it, but should I have to write a new gpio driver, I'm unsure if it's simpler to write a new gpio driver or to register with the generic gpio driver.

Quoted 6 lines
Quoted 1 line

Here's an example that I'm checking:

Ok, this indeed looks nice and short. You convinced me ;)

As said, I'm fine with the generic gpio driver if you add the below as first user.

I still beg to consider patch for generic GPIO separately.
Then I will send you two completely different versions of the implementation GPIO for CLPS711X for consideration.

...

Quoted 9 lines
Quoted 9 lines

/*
* Copyright (C) 2013 Alexander Shiyan <[email protected]> *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. */

Quoted 5 lines
Quoted 5 lines

#include <init.h>
#include <common.h>
#include <malloc.h>

#include <linux/basic_mmio_gpio.h>

...

---
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#5 lore raw
Quoted 14 lines · Alexander Shiyan
Quoted 14 lines · Alexander Shiyan
Quoted 12 lines
Quoted 10 lines · Alexander Shiyan
Quoted 2 lines

This patch adds generic memory-mapped GPIO controller support. Code taken from Linux Kernel and adopted for barebox.

I'm fine with this if you add a user for it. I wonder though if it's worth it to have this driver for barebox. If I have a driver in the kernel that already uses it, then this makes it simple to copy it, but should I have to write a new gpio driver, I'm unsure if it's simpler to write a new gpio driver or to register with the generic gpio driver.

Here's an example that I'm checking:

Quoted 8 lines
Quoted 4 lines

Ok, this indeed looks nice and short. You convinced me ;)

As said, I'm fine with the generic gpio driver if you add the below as first user.

I still beg to consider patch for generic GPIO separately.
Then I will send you two completely different versions of the implementation GPIO for CLPS711X for consideration.

I don't know if I'm misunderstanding you. Of course the generic GPIO driver and the CLPS711x driver should be two separate patches, but both should come in the same series. I just want to wait applying the generic driver until we have a user (and thus compile coverage).

Sascha

Signature · 9 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 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

...

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 11 lines
Quoted 9 lines
Quoted 2 lines

This patch adds generic memory-mapped GPIO controller support. Code taken from Linux Kernel and adopted for barebox.

I'm fine with this if you add a user for it. I wonder though if it's worth it to have this driver for barebox. If I have a driver in the kernel that already uses it, then this makes it simple to copy it, but should I have to write a new gpio driver, I'm unsure if it's simpler to write a new gpio driver or to register with the generic gpio driver.

Here's an example that I'm checking:

Ok, this indeed looks nice and short. You convinced me ;)

As said, I'm fine with the generic gpio driver if you add the below as first user.

Quoted 8 lines
Quoted 3 lines

I still beg to consider patch for generic GPIO separately.
Then I will send you two completely different versions of the implementation GPIO for CLPS711X for consideration.

I don't know if I'm misunderstanding you. Of course the generic GPIO driver and the CLPS711x driver should be two separate patches, but both should come in the same series. I just want to wait applying the generic driver until we have a user (and thus compile coverage).

No, no, no. I say that I have two different implementations of gpio-clps711x, both is based on generic-gpio but I cannot choose between these :)

---
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox