diff mbox

[v3] GPIO: Add support for GPIO on CLPS711X-target platform

Message ID 1349106153-27371-1-git-send-email-shc_work@mail.ru (mailing list archive)
State New, archived
Headers show

Commit Message

Alexander Shiyan Oct. 1, 2012, 3:42 p.m. UTC
The CLPS711X CPUs provide some GPIOs for use in the system. This
driver provides support for these via gpiolib. Due to platform
limitations, driver does not support interrupts, only inputs and
outputs.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 arch/arm/Kconfig                           |    1 +
 arch/arm/mach-clps711x/include/mach/gpio.h |   27 +++++
 drivers/gpio/Kconfig                       |    4 +
 drivers/gpio/Makefile                      |    1 +
 drivers/gpio/gpio-clps711x.c               |  152 ++++++++++++++++++++++++++++
 5 files changed, 185 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-clps711x/include/mach/gpio.h
 create mode 100644 drivers/gpio/gpio-clps711x.c

Comments

Russell King - ARM Linux Oct. 5, 2012, 9:02 a.m. UTC | #1
On Mon, Oct 01, 2012 at 07:42:33PM +0400, Alexander Shiyan wrote:
> The CLPS711X CPUs provide some GPIOs for use in the system. This
> driver provides support for these via gpiolib. Due to platform
> limitations, driver does not support interrupts, only inputs and
> outputs.
> 
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> ---
>  arch/arm/Kconfig                           |    1 +
>  arch/arm/mach-clps711x/include/mach/gpio.h |   27 +++++
>  drivers/gpio/Kconfig                       |    4 +
>  drivers/gpio/Makefile                      |    1 +
>  drivers/gpio/gpio-clps711x.c               |  152 ++++++++++++++++++++++++++++
>  5 files changed, 185 insertions(+), 0 deletions(-)
>  create mode 100644 arch/arm/mach-clps711x/include/mach/gpio.h
>  create mode 100644 drivers/gpio/gpio-clps711x.c
> 
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index 2f88d8d..e73bf9d 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -384,6 +384,7 @@ config ARCH_CLPS711X
>  	bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
>  	select CPU_ARM720T
>  	select ARCH_USES_GETTIMEOFFSET
> +	select ARCH_REQUIRE_GPIOLIB
>  	select NEED_MACH_MEMORY_H
>  	help
>  	  Support for Cirrus Logic 711x/721x/731x based boards.
> diff --git a/arch/arm/mach-clps711x/include/mach/gpio.h b/arch/arm/mach-clps711x/include/mach/gpio.h
> new file mode 100644
> index 0000000..cbcc985
> --- /dev/null
> +++ b/arch/arm/mach-clps711x/include/mach/gpio.h
> @@ -0,0 +1,27 @@
> +/*
> + *  This file contains the CLPS711X GPIO definitions.
> + *
> + *  Copyright (C) 2012 Alexander Shiyan <shc_work@mail.ru>
> + *
> + * 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.
> + */
> +
> +/* Simple helper for convert port & pin to GPIO number */
> +#define CLPS711X_GPIO(port, bit)	((port) * 8 + (bit))
> +
> +/* Temporaty definitions for GPIO-ports */
> +/* Will be removed after remove clps_read(write) macros */
> +#include <mach/hardware.h>
> +#define _PADR	(CLPS711X_VIRT_BASE + PADR)
> +#define _PBDR	(CLPS711X_VIRT_BASE + PBDR)
> +#define _PCDR	(CLPS711X_VIRT_BASE + PCDR)
> +#define _PDDR	(CLPS711X_VIRT_BASE + PDDR)
> +#define _PADDR	(CLPS711X_VIRT_BASE + PADDR)
> +#define _PBDDR	(CLPS711X_VIRT_BASE + PBDDR)
> +#define _PCDDR	(CLPS711X_VIRT_BASE + PCDDR)
> +#define _PDDDR	(CLPS711X_VIRT_BASE + PDDDR)
> +#define _PEDR	(CLPS711X_VIRT_BASE + PEDR)
> +#define _PEDDR	(CLPS711X_VIRT_BASE + PEDDR)

Why can't this file (or the bulk of it) live in drivers/gpio ?
Alexander Shiyan Oct. 7, 2012, 9:53 a.m. UTC | #2
On Fri, 5 Oct 2012 10:02:04 +0100
Russell King - ARM Linux <linux@arm.linux.org.uk> wrote:

> On Mon, Oct 01, 2012 at 07:42:33PM +0400, Alexander Shiyan wrote:
> > The CLPS711X CPUs provide some GPIOs for use in the system. This
> > driver provides support for these via gpiolib. Due to platform
> > limitations, driver does not support interrupts, only inputs and
> > outputs.
...
> > +++ b/arch/arm/mach-clps711x/include/mach/gpio.h
> > @@ -0,0 +1,27 @@
> > +/*
> > + *  This file contains the CLPS711X GPIO definitions.
> > + *
> > + *  Copyright (C) 2012 Alexander Shiyan <shc_work@mail.ru>
> > + *
> > + * 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.
> > + */
> > +
> > +/* Simple helper for convert port & pin to GPIO number */
> > +#define CLPS711X_GPIO(port, bit)	((port) * 8 + (bit))
> > +
> > +/* Temporaty definitions for GPIO-ports */
> > +/* Will be removed after remove clps_read(write) macros */
> > +#include <mach/hardware.h>
> > +#define _PADR	(CLPS711X_VIRT_BASE + PADR)
> > +#define _PBDR	(CLPS711X_VIRT_BASE + PBDR)
> > +#define _PCDR	(CLPS711X_VIRT_BASE + PCDR)
> > +#define _PDDR	(CLPS711X_VIRT_BASE + PDDR)
> > +#define _PADDR	(CLPS711X_VIRT_BASE + PADDR)
> > +#define _PBDDR	(CLPS711X_VIRT_BASE + PBDDR)
> > +#define _PCDDR	(CLPS711X_VIRT_BASE + PCDDR)
> > +#define _PDDDR	(CLPS711X_VIRT_BASE + PDDDR)
> > +#define _PEDR	(CLPS711X_VIRT_BASE + PEDR)
> > +#define _PEDDR	(CLPS711X_VIRT_BASE + PEDDR)
> 
> Why can't this file (or the bulk of it) live in drivers/gpio ?
We should have access for macros in gpio.h from board support files
and other drivers. From drivers/gpio it not possible.
If you ask about port definitions, as I say before, it will be
removed later after rework on platform hardware definitions.
Russell King - ARM Linux Oct. 7, 2012, 10:28 a.m. UTC | #3
On Sun, Oct 07, 2012 at 01:53:34PM +0400, Alexander Shiyan wrote:
> On Fri, 5 Oct 2012 10:02:04 +0100
> Russell King - ARM Linux <linux@arm.linux.org.uk> wrote:
> 
> > On Mon, Oct 01, 2012 at 07:42:33PM +0400, Alexander Shiyan wrote:
> > > The CLPS711X CPUs provide some GPIOs for use in the system. This
> > > driver provides support for these via gpiolib. Due to platform
> > > limitations, driver does not support interrupts, only inputs and
> > > outputs.
> ...
> > > +++ b/arch/arm/mach-clps711x/include/mach/gpio.h
> > > @@ -0,0 +1,27 @@
> > > +/*
> > > + *  This file contains the CLPS711X GPIO definitions.
> > > + *
> > > + *  Copyright (C) 2012 Alexander Shiyan <shc_work@mail.ru>
> > > + *
> > > + * 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.
> > > + */
> > > +
> > > +/* Simple helper for convert port & pin to GPIO number */
> > > +#define CLPS711X_GPIO(port, bit)	((port) * 8 + (bit))
> > > +
> > > +/* Temporaty definitions for GPIO-ports */
> > > +/* Will be removed after remove clps_read(write) macros */
> > > +#include <mach/hardware.h>
> > > +#define _PADR	(CLPS711X_VIRT_BASE + PADR)
> > > +#define _PBDR	(CLPS711X_VIRT_BASE + PBDR)
> > > +#define _PCDR	(CLPS711X_VIRT_BASE + PCDR)
> > > +#define _PDDR	(CLPS711X_VIRT_BASE + PDDR)
> > > +#define _PADDR	(CLPS711X_VIRT_BASE + PADDR)
> > > +#define _PBDDR	(CLPS711X_VIRT_BASE + PBDDR)
> > > +#define _PCDDR	(CLPS711X_VIRT_BASE + PCDDR)
> > > +#define _PDDDR	(CLPS711X_VIRT_BASE + PDDDR)
> > > +#define _PEDR	(CLPS711X_VIRT_BASE + PEDR)
> > > +#define _PEDDR	(CLPS711X_VIRT_BASE + PEDDR)
> > 
> > Why can't this file (or the bulk of it) live in drivers/gpio ?
> We should have access for macros in gpio.h from board support files
> and other drivers. From drivers/gpio it not possible.
> If you ask about port definitions, as I say before, it will be
> removed later after rework on platform hardware definitions.

No other drivers should be directly accessing the GPIO registers -
doing so is likely a bug because of the inherent lack of locking,
which will cause race conditions.

All accesses to GPIOs should be done via gpiolib, even from board
support files.
Alexander Shiyan Oct. 7, 2012, 3:12 p.m. UTC | #4
On Sun, 7 Oct 2012 11:28:03 +0100
Russell King - ARM Linux <linux@arm.linux.org.uk> wrote:

> > ...
> > > > +++ b/arch/arm/mach-clps711x/include/mach/gpio.h
> > > > @@ -0,0 +1,27 @@
> > > > +/*
> > > > + *  This file contains the CLPS711X GPIO definitions.
> > > > + *
> > > > + *  Copyright (C) 2012 Alexander Shiyan <shc_work@mail.ru>
> > > > + *
> > > > + * 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.
> > > > + */
> > > > +
> > > > +/* Simple helper for convert port & pin to GPIO number */
> > > > +#define CLPS711X_GPIO(port, bit)	((port) * 8 + (bit))
> > > > +
> > > > +/* Temporaty definitions for GPIO-ports */
> > > > +/* Will be removed after remove clps_read(write) macros */
> > > > +#include <mach/hardware.h>
> > > > +#define _PADR	(CLPS711X_VIRT_BASE + PADR)
> > > > +#define _PBDR	(CLPS711X_VIRT_BASE + PBDR)
> > > > +#define _PCDR	(CLPS711X_VIRT_BASE + PCDR)
> > > > +#define _PDDR	(CLPS711X_VIRT_BASE + PDDR)
> > > > +#define _PADDR	(CLPS711X_VIRT_BASE + PADDR)
> > > > +#define _PBDDR	(CLPS711X_VIRT_BASE + PBDDR)
> > > > +#define _PCDDR	(CLPS711X_VIRT_BASE + PCDDR)
> > > > +#define _PDDDR	(CLPS711X_VIRT_BASE + PDDDR)
> > > > +#define _PEDR	(CLPS711X_VIRT_BASE + PEDR)
> > > > +#define _PEDDR	(CLPS711X_VIRT_BASE + PEDDR)
> > > 
> > > Why can't this file (or the bulk of it) live in drivers/gpio ?
> > We should have access for macros in gpio.h from board support files
> > and other drivers. From drivers/gpio it not possible.
> > If you ask about port definitions, as I say before, it will be
> > removed later after rework on platform hardware definitions.
> 
> No other drivers should be directly accessing the GPIO registers -
> doing so is likely a bug because of the inherent lack of locking,
> which will cause race conditions.
> 
> All accesses to GPIOs should be done via gpiolib, even from board
> support files.

Yes, and I am say only about macro that calculate GPIO-number from
port number and bit position. Access to this is a helpful for understand
source code.
Russell King - ARM Linux Oct. 7, 2012, 3:20 p.m. UTC | #5
On Sun, Oct 07, 2012 at 07:12:27PM +0400, Alexander Shiyan wrote:
> On Sun, 7 Oct 2012 11:28:03 +0100
> Russell King - ARM Linux <linux@arm.linux.org.uk> wrote:
> 
> > > ...
> > > > > +++ b/arch/arm/mach-clps711x/include/mach/gpio.h
> > > > > @@ -0,0 +1,27 @@
> > > > > +/*
> > > > > + *  This file contains the CLPS711X GPIO definitions.
> > > > > + *
> > > > > + *  Copyright (C) 2012 Alexander Shiyan <shc_work@mail.ru>
> > > > > + *
> > > > > + * 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.
> > > > > + */
> > > > > +
> > > > > +/* Simple helper for convert port & pin to GPIO number */
> > > > > +#define CLPS711X_GPIO(port, bit)	((port) * 8 + (bit))
> > > > > +
> > > > > +/* Temporaty definitions for GPIO-ports */
> > > > > +/* Will be removed after remove clps_read(write) macros */
> > > > > +#include <mach/hardware.h>
> > > > > +#define _PADR	(CLPS711X_VIRT_BASE + PADR)
> > > > > +#define _PBDR	(CLPS711X_VIRT_BASE + PBDR)
> > > > > +#define _PCDR	(CLPS711X_VIRT_BASE + PCDR)
> > > > > +#define _PDDR	(CLPS711X_VIRT_BASE + PDDR)
> > > > > +#define _PADDR	(CLPS711X_VIRT_BASE + PADDR)
> > > > > +#define _PBDDR	(CLPS711X_VIRT_BASE + PBDDR)
> > > > > +#define _PCDDR	(CLPS711X_VIRT_BASE + PCDDR)
> > > > > +#define _PDDDR	(CLPS711X_VIRT_BASE + PDDDR)
> > > > > +#define _PEDR	(CLPS711X_VIRT_BASE + PEDR)
> > > > > +#define _PEDDR	(CLPS711X_VIRT_BASE + PEDDR)
> > > > 
> > > > Why can't this file (or the bulk of it) live in drivers/gpio ?
> > > We should have access for macros in gpio.h from board support files
> > > and other drivers. From drivers/gpio it not possible.
> > > If you ask about port definitions, as I say before, it will be
> > > removed later after rework on platform hardware definitions.
> > 
> > No other drivers should be directly accessing the GPIO registers -
> > doing so is likely a bug because of the inherent lack of locking,
> > which will cause race conditions.
> > 
> > All accesses to GPIOs should be done via gpiolib, even from board
> > support files.
> 
> Yes, and I am say only about macro that calculate GPIO-number from
> port number and bit position. Access to this is a helpful for understand
> source code.

Sorry, I don't think you're understanding.

Why can't you put:

#define _PADR        (CLPS711X_VIRT_BASE + PADR)

and the other macros inside drivers/gpio/gpio-clps711x.c ?  This should
be the _only_ file which uses them.
Linus Walleij Oct. 9, 2012, 11:45 a.m. UTC | #6
On Mon, Oct 1, 2012 at 5:42 PM, Alexander Shiyan <shc_work@mail.ru> wrote:

> The CLPS711X CPUs provide some GPIOs for use in the system. This
> driver provides support for these via gpiolib. Due to platform
> limitations, driver does not support interrupts, only inputs and
> outputs.
>
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>

I agree with Russell's comment that all register access macros need
to be pushed down to drivers/gpio/gpio-clps711x.c.

Preferably they should also be replaced by register #defines
and ioremap:ed accesses but I'm not going to be pushy about
that since the driver certainly looks way better after this than
before, so it can be fixed up later.

Yours,
Linus Walleij
diff mbox

Patch

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 2f88d8d..e73bf9d 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -384,6 +384,7 @@  config ARCH_CLPS711X
 	bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
 	select CPU_ARM720T
 	select ARCH_USES_GETTIMEOFFSET
+	select ARCH_REQUIRE_GPIOLIB
 	select NEED_MACH_MEMORY_H
 	help
 	  Support for Cirrus Logic 711x/721x/731x based boards.
diff --git a/arch/arm/mach-clps711x/include/mach/gpio.h b/arch/arm/mach-clps711x/include/mach/gpio.h
new file mode 100644
index 0000000..cbcc985
--- /dev/null
+++ b/arch/arm/mach-clps711x/include/mach/gpio.h
@@ -0,0 +1,27 @@ 
+/*
+ *  This file contains the CLPS711X GPIO definitions.
+ *
+ *  Copyright (C) 2012 Alexander Shiyan <shc_work@mail.ru>
+ *
+ * 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.
+ */
+
+/* Simple helper for convert port & pin to GPIO number */
+#define CLPS711X_GPIO(port, bit)	((port) * 8 + (bit))
+
+/* Temporaty definitions for GPIO-ports */
+/* Will be removed after remove clps_read(write) macros */
+#include <mach/hardware.h>
+#define _PADR	(CLPS711X_VIRT_BASE + PADR)
+#define _PBDR	(CLPS711X_VIRT_BASE + PBDR)
+#define _PCDR	(CLPS711X_VIRT_BASE + PCDR)
+#define _PDDR	(CLPS711X_VIRT_BASE + PDDR)
+#define _PADDR	(CLPS711X_VIRT_BASE + PADDR)
+#define _PBDDR	(CLPS711X_VIRT_BASE + PBDDR)
+#define _PCDDR	(CLPS711X_VIRT_BASE + PCDDR)
+#define _PDDDR	(CLPS711X_VIRT_BASE + PDDDR)
+#define _PEDR	(CLPS711X_VIRT_BASE + PEDR)
+#define _PEDDR	(CLPS711X_VIRT_BASE + PEDDR)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index ba7926f5..636eda6 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -91,6 +91,10 @@  config GPIO_MAX730X
 
 comment "Memory mapped GPIO drivers:"
 
+config GPIO_CLPS711X
+	def_bool y
+	depends on ARCH_CLPS711X
+
 config GPIO_GENERIC_PLATFORM
 	tristate "Generic memory-mapped GPIO controller support (MMIO platform device)"
 	select GPIO_GENERIC
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 153cace..6a41f79 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -15,6 +15,7 @@  obj-$(CONFIG_GPIO_ADP5588)	+= gpio-adp5588.o
 obj-$(CONFIG_GPIO_AMD8111)	+= gpio-amd8111.o
 obj-$(CONFIG_GPIO_ARIZONA)	+= gpio-arizona.o
 obj-$(CONFIG_GPIO_BT8XX)	+= gpio-bt8xx.o
+obj-$(CONFIG_GPIO_CLPS711X)	+= gpio-clps711x.o
 obj-$(CONFIG_GPIO_CS5535)	+= gpio-cs5535.o
 obj-$(CONFIG_GPIO_DA9052)	+= gpio-da9052.o
 obj-$(CONFIG_ARCH_DAVINCI)	+= gpio-davinci.o
diff --git a/drivers/gpio/gpio-clps711x.c b/drivers/gpio/gpio-clps711x.c
new file mode 100644
index 0000000..c2576f9
--- /dev/null
+++ b/drivers/gpio/gpio-clps711x.c
@@ -0,0 +1,152 @@ 
+/*
+ *  CLPS711X GPIO driver
+ *
+ *  Copyright (C) 2012 Alexander Shiyan <shc_work@mail.ru>
+ *
+ * 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 <linux/io.h>
+#include <linux/slab.h>
+#include <linux/gpio.h>
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <linux/platform_device.h>
+
+#define CLPS711X_GPIO_PORTS	5
+#define CLPS711X_GPIO_NAME	"gpio-clps711x"
+
+struct clps711x_gpio {
+	struct gpio_chip	chip[CLPS711X_GPIO_PORTS];
+	spinlock_t		lock;
+};
+
+static const void __iomem *clps711x_ports[] = {
+	_PADR, _PBDR, _PCDR, _PDDR, _PEDR,
+};
+
+static const void __iomem *clps711x_pdirs[] = {
+	_PADDR, _PBDDR, _PCDDR, _PDDDR, _PEDDR,
+};
+
+#define clps711x_port(x)	clps711x_ports[x->base / 8]
+#define clps711x_pdir(x)	clps711x_pdirs[x->base / 8]
+
+static int gpio_clps711x_get(struct gpio_chip *chip, unsigned offset)
+{
+	return !!readb(clps711x_port(chip)) & (1 << offset);
+}
+
+static void gpio_clps711x_set(struct gpio_chip *chip, unsigned offset,
+			      int value)
+{
+	int tmp;
+	unsigned long flags;
+	struct clps711x_gpio *gpio = dev_get_drvdata(chip->dev);
+
+	spin_lock_irqsave(&gpio->lock, flags);
+	tmp = readb(clps711x_port(chip)) & ~(1 << offset);
+	if (value)
+		tmp |= 1 << offset;
+	writeb(tmp, clps711x_port(chip));
+	spin_unlock_irqrestore(&gpio->lock, flags);
+}
+
+static int gpio_clps711x_direction_in(struct gpio_chip *chip, unsigned offset)
+{
+	int tmp;
+	unsigned long flags;
+	struct clps711x_gpio *gpio = dev_get_drvdata(chip->dev);
+
+	spin_lock_irqsave(&gpio->lock, flags);
+	tmp = readb(clps711x_pdir(chip)) & ~(1 << offset);
+	writeb(tmp, clps711x_pdir(chip));
+	spin_unlock_irqrestore(&gpio->lock, flags);
+
+	return 0;
+}
+
+static int gpio_clps711x_direction_out(struct gpio_chip *chip, unsigned offset,
+				       int value)
+{
+	int tmp;
+	unsigned long flags;
+	struct clps711x_gpio *gpio = dev_get_drvdata(chip->dev);
+
+	spin_lock_irqsave(&gpio->lock, flags);
+	tmp = readb(clps711x_pdir(chip)) | (1 << offset);
+	writeb(tmp, clps711x_pdir(chip));
+	tmp = readb(clps711x_port(chip)) & ~(1 << offset);
+	if (value)
+		tmp |= 1 << offset;
+	writeb(tmp, clps711x_port(chip));
+	spin_unlock_irqrestore(&gpio->lock, flags);
+
+	return 0;
+}
+
+struct clps711x_gpio_port {
+	char	*name;
+	int	nr;
+};
+
+static const struct clps711x_gpio_port clps711x_gpio_ports[] __initconst = {
+	{ "PORTA", 8, },
+	{ "PORTB", 8, },
+	{ "PORTC", 8, },
+	{ "PORTD", 8, },
+	{ "PORTE", 3, },
+};
+
+static int __init gpio_clps711x_init(void)
+{
+	int i;
+	struct platform_device *pdev;
+	struct clps711x_gpio *gpio;
+
+	pdev = platform_device_alloc(CLPS711X_GPIO_NAME, 0);
+	if (!pdev) {
+		pr_err("Cannot create platform device: %s\n",
+		       CLPS711X_GPIO_NAME);
+		return -ENOMEM;
+	}
+
+	platform_device_add(pdev);
+
+	gpio = kzalloc(sizeof(struct clps711x_gpio), GFP_KERNEL);
+	if (!gpio) {
+		dev_err(&pdev->dev, "GPIO allocating memory error\n");
+		platform_device_del(pdev);
+		platform_device_put(pdev);
+		return -ENOMEM;
+	}
+
+	platform_set_drvdata(pdev, gpio);
+
+	spin_lock_init(&gpio->lock);
+
+	for (i = 0; i < CLPS711X_GPIO_PORTS; i++) {
+		gpio->chip[i].owner		= THIS_MODULE;
+		gpio->chip[i].dev		= &pdev->dev;
+		gpio->chip[i].label		= clps711x_gpio_ports[i].name;
+		gpio->chip[i].base		= i * 8;
+		gpio->chip[i].ngpio		= clps711x_gpio_ports[i].nr;
+		gpio->chip[i].direction_input	= gpio_clps711x_direction_in;
+		gpio->chip[i].get		= gpio_clps711x_get;
+		gpio->chip[i].direction_output	= gpio_clps711x_direction_out;
+		gpio->chip[i].set		= gpio_clps711x_set;
+		gpiochip_add(&gpio->chip[i]);
+	}
+
+	dev_info(&pdev->dev, "GPIO driver initialized\n");
+
+	return 0;
+}
+arch_initcall(gpio_clps711x_init);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
+MODULE_DESCRIPTION("CLPS711X GPIO driver");