All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
To: Russell King <linux@arm.linux.org.uk>,
	Daniel Mack <daniel@zonque.org>,
	Robert Jarzmik <robert.jarzmik@free.fr>,
	Linus Walleij <linus.walleij@linaro.org>,
	Alexandre Courbot <gnurou@gmail.com>,
	Wolfram Sang <wsa@the-dreams.de>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Bryan Wu <cooloney@gmail.com>, Richard Purdie <rpurdie@rpsys.net>,
	Samuel Ortiz <sameo@linux.intel.com>,
	Lee Jones <lee.jones@linaro.org>, Mark Brown <broonie@kernel.org>,
	Jingoo Han <jg1.han@samsung.com>,
	Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Andrea Adami <andrea.adami@gmail.com>
Cc: linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org,
	linux-input@vger.kernel.org, linux-leds@vger.kernel.org,
	linux-spi@vger.kernel.org, linux-fbdev@vger.kernel.org,
	alsa-devel@alsa-project.org
Subject: [PATCH v3 07/17] gpio: port LoCoMo gpio support from old driver
Date: Sun, 17 May 2015 19:27:47 +0300	[thread overview]
Message-ID: <1431880077-26321-8-git-send-email-dbaryshkov@gmail.com> (raw)
In-Reply-To: <1431880077-26321-1-git-send-email-dbaryshkov@gmail.com>

Add gpiolib driver for gpio pins placed on the LoCoMo GA.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/gpio/Kconfig       |  12 ++++
 drivers/gpio/Makefile      |   1 +
 drivers/gpio/gpio-locomo.c | 170 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 183 insertions(+)
 create mode 100644 drivers/gpio/gpio-locomo.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index caefe80..4542684 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -734,6 +734,18 @@ config GPIO_KEMPLD
 	  This driver can also be built as a module. If so, the module will be
 	  called gpio-kempld.
 
+config GPIO_LOCOMO
+	bool "Sharp LoCoMo GPIO support"
+	depends on MFD_LOCOMO
+	help
+	  Select this to support GPIO pins on Sharp LoCoMo Grid Array found
+	  in Sharp Zaurus collie and poodle models.
+
+	  Sat Yes if you have such PDA, say No otherwise.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called gpio-locomo.
+
 config GPIO_LP3943
 	tristate "TI/National Semiconductor LP3943 GPIO expander"
 	depends on MFD_LP3943
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index f71bb97..98655ae 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_GPIO_JANZ_TTL)	+= gpio-janz-ttl.o
 obj-$(CONFIG_GPIO_KEMPLD)	+= gpio-kempld.o
 obj-$(CONFIG_ARCH_KS8695)	+= gpio-ks8695.o
 obj-$(CONFIG_GPIO_INTEL_MID)	+= gpio-intel-mid.o
+obj-$(CONFIG_GPIO_LOCOMO)	+= gpio-locomo.o
 obj-$(CONFIG_GPIO_LOONGSON)	+= gpio-loongson.o
 obj-$(CONFIG_GPIO_LP3943)	+= gpio-lp3943.o
 obj-$(CONFIG_ARCH_LPC32XX)	+= gpio-lpc32xx.o
diff --git a/drivers/gpio/gpio-locomo.c b/drivers/gpio/gpio-locomo.c
new file mode 100644
index 0000000..dd9a1ca
--- /dev/null
+++ b/drivers/gpio/gpio-locomo.c
@@ -0,0 +1,170 @@
+/*
+ * Sharp LoCoMo support for GPIO
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This file contains all generic LoCoMo support.
+ *
+ * All initialization functions provided here are intended to be called
+ * from machine specific code with proper arguments when required.
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/bitops.h>
+#include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/io.h>
+#include <linux/regmap.h>
+#include <linux/mfd/locomo.h>
+
+struct locomo_gpio {
+	struct regmap *regmap;
+
+	struct gpio_chip gpio;
+
+	u16 rising_edge;
+	u16 falling_edge;
+
+	unsigned int save_gpo;
+	unsigned int save_gpe;
+};
+
+static int locomo_gpio_get(struct gpio_chip *chip,
+		unsigned offset)
+{
+	struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio);
+	unsigned int gpl;
+
+	regmap_read(lg->regmap, LOCOMO_GPL, &gpl);
+
+	return gpl & BIT(offset);
+}
+
+static void locomo_gpio_set(struct gpio_chip *chip,
+		unsigned offset, int value)
+{
+	struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio);
+
+	regmap_update_bits(lg->regmap, LOCOMO_GPO,
+			BIT(offset),
+			value ? BIT(offset) : 0);
+}
+
+static int locomo_gpio_direction_input(struct gpio_chip *chip,
+			unsigned offset)
+{
+	struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio);
+
+	regmap_update_bits(lg->regmap, LOCOMO_GPD, BIT(offset), BIT(offset));
+	regmap_update_bits(lg->regmap, LOCOMO_GPE, BIT(offset), BIT(offset));
+
+	return 0;
+}
+
+static int locomo_gpio_direction_output(struct gpio_chip *chip,
+			unsigned offset, int value)
+{
+	struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio);
+
+	regmap_update_bits(lg->regmap, LOCOMO_GPO,
+			BIT(offset),
+			value ? BIT(offset) : 0);
+	regmap_update_bits(lg->regmap, LOCOMO_GPD, BIT(offset), 0);
+	regmap_update_bits(lg->regmap, LOCOMO_GPE, BIT(offset), 0);
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int locomo_gpio_suspend(struct device *dev)
+{
+	struct locomo_gpio *lg = dev_get_drvdata(dev);
+
+	regmap_read(lg->regmap, LOCOMO_GPO, &lg->save_gpo);
+	regmap_write(lg->regmap, LOCOMO_GPO, 0x00);
+	regmap_read(lg->regmap, LOCOMO_GPE, &lg->save_gpe);
+	regmap_write(lg->regmap, LOCOMO_GPE, 0x00);
+
+	return 0;
+}
+
+static int locomo_gpio_resume(struct device *dev)
+{
+	struct locomo_gpio *lg = dev_get_drvdata(dev);
+
+	regmap_write(lg->regmap, LOCOMO_GPO, lg->save_gpo);
+	regmap_write(lg->regmap, LOCOMO_GPE, lg->save_gpe);
+
+	return 0;
+}
+static SIMPLE_DEV_PM_OPS(locomo_gpio_pm,
+		locomo_gpio_suspend, locomo_gpio_resume);
+#define LOCOMO_GPIO_PM	(&locomo_gpio_pm)
+#else
+#define LOCOMO_GPIO_PM	NULL
+#endif
+
+static int locomo_gpio_probe(struct platform_device *pdev)
+{
+	struct locomo_gpio *lg;
+	int ret;
+	struct locomo_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
+
+	lg = devm_kzalloc(&pdev->dev, sizeof(struct locomo_gpio),
+			GFP_KERNEL);
+	if (!lg)
+		return -ENOMEM;
+
+	lg->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!lg->regmap)
+		return -EINVAL;
+
+	platform_set_drvdata(pdev, lg);
+
+	regmap_write(lg->regmap, LOCOMO_GPO, 0x00);
+	regmap_write(lg->regmap, LOCOMO_GPE, 0x00);
+	regmap_write(lg->regmap, LOCOMO_GPD, 0x00);
+	regmap_write(lg->regmap, LOCOMO_GIE, 0x00);
+
+	lg->gpio.base = pdata ? pdata->gpio_base : -1;
+	lg->gpio.label = "locomo-gpio";
+	lg->gpio.ngpio = 16;
+	lg->gpio.set = locomo_gpio_set;
+	lg->gpio.get = locomo_gpio_get;
+	lg->gpio.direction_input = locomo_gpio_direction_input;
+	lg->gpio.direction_output = locomo_gpio_direction_output;
+
+	ret = gpiochip_add(&lg->gpio);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int locomo_gpio_remove(struct platform_device *pdev)
+{
+	struct locomo_gpio *lg = platform_get_drvdata(pdev);
+
+	gpiochip_remove(&lg->gpio);
+
+	return 0;
+}
+
+static struct platform_driver locomo_gpio_driver = {
+	.probe		= locomo_gpio_probe,
+	.remove		= locomo_gpio_remove,
+	.driver		= {
+		.name	= "locomo-gpio",
+		.pm	= LOCOMO_GPIO_PM,
+	},
+};
+module_platform_driver(locomo_gpio_driver);
+
+MODULE_DESCRIPTION("Sharp LoCoMo GPIO driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
+MODULE_ALIAS("platform:locomo-gpio");
-- 
2.1.4


WARNING: multiple messages have this Message-ID (diff)
From: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
To: Russell King <linux@arm.linux.org.uk>,
	Daniel Mack <daniel@zonque.org>,
	Robert Jarzmik <robert.jarzmik@free.fr>,
	Linus Walleij <linus.walleij@linaro.org>,
	Alexandre Courbot <gnurou@gmail.com>,
	Wolfram Sang <wsa@the-dreams.de>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Bryan Wu <cooloney@gmail.com>, Richard Purdie <rpurdie@rpsys.net>,
	Samuel Ortiz <sameo@linux.intel.com>,
	Lee Jones <lee.jones@linaro.org>, Mark Brown <broonie@kernel.org>,
	Jingoo Han <jg1.han@samsung.com>,
	Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Andrea Adami <andrea.adami@gmail.com>
Cc: linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org,
	linux-input@vger.kernel.org, linux-leds@vger.kernel.org,
	linux-spi@vger.kernel.org, linux-fbdev@vger.kernel.org,
	alsa-devel@alsa-project.org
Subject: [PATCH v3 07/17] gpio: port LoCoMo gpio support from old driver
Date: Sun, 17 May 2015 16:27:47 +0000	[thread overview]
Message-ID: <1431880077-26321-8-git-send-email-dbaryshkov@gmail.com> (raw)
In-Reply-To: <1431880077-26321-1-git-send-email-dbaryshkov@gmail.com>

Add gpiolib driver for gpio pins placed on the LoCoMo GA.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/gpio/Kconfig       |  12 ++++
 drivers/gpio/Makefile      |   1 +
 drivers/gpio/gpio-locomo.c | 170 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 183 insertions(+)
 create mode 100644 drivers/gpio/gpio-locomo.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index caefe80..4542684 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -734,6 +734,18 @@ config GPIO_KEMPLD
 	  This driver can also be built as a module. If so, the module will be
 	  called gpio-kempld.
 
+config GPIO_LOCOMO
+	bool "Sharp LoCoMo GPIO support"
+	depends on MFD_LOCOMO
+	help
+	  Select this to support GPIO pins on Sharp LoCoMo Grid Array found
+	  in Sharp Zaurus collie and poodle models.
+
+	  Sat Yes if you have such PDA, say No otherwise.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called gpio-locomo.
+
 config GPIO_LP3943
 	tristate "TI/National Semiconductor LP3943 GPIO expander"
 	depends on MFD_LP3943
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index f71bb97..98655ae 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_GPIO_JANZ_TTL)	+= gpio-janz-ttl.o
 obj-$(CONFIG_GPIO_KEMPLD)	+= gpio-kempld.o
 obj-$(CONFIG_ARCH_KS8695)	+= gpio-ks8695.o
 obj-$(CONFIG_GPIO_INTEL_MID)	+= gpio-intel-mid.o
+obj-$(CONFIG_GPIO_LOCOMO)	+= gpio-locomo.o
 obj-$(CONFIG_GPIO_LOONGSON)	+= gpio-loongson.o
 obj-$(CONFIG_GPIO_LP3943)	+= gpio-lp3943.o
 obj-$(CONFIG_ARCH_LPC32XX)	+= gpio-lpc32xx.o
diff --git a/drivers/gpio/gpio-locomo.c b/drivers/gpio/gpio-locomo.c
new file mode 100644
index 0000000..dd9a1ca
--- /dev/null
+++ b/drivers/gpio/gpio-locomo.c
@@ -0,0 +1,170 @@
+/*
+ * Sharp LoCoMo support for GPIO
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This file contains all generic LoCoMo support.
+ *
+ * All initialization functions provided here are intended to be called
+ * from machine specific code with proper arguments when required.
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/bitops.h>
+#include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/io.h>
+#include <linux/regmap.h>
+#include <linux/mfd/locomo.h>
+
+struct locomo_gpio {
+	struct regmap *regmap;
+
+	struct gpio_chip gpio;
+
+	u16 rising_edge;
+	u16 falling_edge;
+
+	unsigned int save_gpo;
+	unsigned int save_gpe;
+};
+
+static int locomo_gpio_get(struct gpio_chip *chip,
+		unsigned offset)
+{
+	struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio);
+	unsigned int gpl;
+
+	regmap_read(lg->regmap, LOCOMO_GPL, &gpl);
+
+	return gpl & BIT(offset);
+}
+
+static void locomo_gpio_set(struct gpio_chip *chip,
+		unsigned offset, int value)
+{
+	struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio);
+
+	regmap_update_bits(lg->regmap, LOCOMO_GPO,
+			BIT(offset),
+			value ? BIT(offset) : 0);
+}
+
+static int locomo_gpio_direction_input(struct gpio_chip *chip,
+			unsigned offset)
+{
+	struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio);
+
+	regmap_update_bits(lg->regmap, LOCOMO_GPD, BIT(offset), BIT(offset));
+	regmap_update_bits(lg->regmap, LOCOMO_GPE, BIT(offset), BIT(offset));
+
+	return 0;
+}
+
+static int locomo_gpio_direction_output(struct gpio_chip *chip,
+			unsigned offset, int value)
+{
+	struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio);
+
+	regmap_update_bits(lg->regmap, LOCOMO_GPO,
+			BIT(offset),
+			value ? BIT(offset) : 0);
+	regmap_update_bits(lg->regmap, LOCOMO_GPD, BIT(offset), 0);
+	regmap_update_bits(lg->regmap, LOCOMO_GPE, BIT(offset), 0);
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int locomo_gpio_suspend(struct device *dev)
+{
+	struct locomo_gpio *lg = dev_get_drvdata(dev);
+
+	regmap_read(lg->regmap, LOCOMO_GPO, &lg->save_gpo);
+	regmap_write(lg->regmap, LOCOMO_GPO, 0x00);
+	regmap_read(lg->regmap, LOCOMO_GPE, &lg->save_gpe);
+	regmap_write(lg->regmap, LOCOMO_GPE, 0x00);
+
+	return 0;
+}
+
+static int locomo_gpio_resume(struct device *dev)
+{
+	struct locomo_gpio *lg = dev_get_drvdata(dev);
+
+	regmap_write(lg->regmap, LOCOMO_GPO, lg->save_gpo);
+	regmap_write(lg->regmap, LOCOMO_GPE, lg->save_gpe);
+
+	return 0;
+}
+static SIMPLE_DEV_PM_OPS(locomo_gpio_pm,
+		locomo_gpio_suspend, locomo_gpio_resume);
+#define LOCOMO_GPIO_PM	(&locomo_gpio_pm)
+#else
+#define LOCOMO_GPIO_PM	NULL
+#endif
+
+static int locomo_gpio_probe(struct platform_device *pdev)
+{
+	struct locomo_gpio *lg;
+	int ret;
+	struct locomo_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
+
+	lg = devm_kzalloc(&pdev->dev, sizeof(struct locomo_gpio),
+			GFP_KERNEL);
+	if (!lg)
+		return -ENOMEM;
+
+	lg->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!lg->regmap)
+		return -EINVAL;
+
+	platform_set_drvdata(pdev, lg);
+
+	regmap_write(lg->regmap, LOCOMO_GPO, 0x00);
+	regmap_write(lg->regmap, LOCOMO_GPE, 0x00);
+	regmap_write(lg->regmap, LOCOMO_GPD, 0x00);
+	regmap_write(lg->regmap, LOCOMO_GIE, 0x00);
+
+	lg->gpio.base = pdata ? pdata->gpio_base : -1;
+	lg->gpio.label = "locomo-gpio";
+	lg->gpio.ngpio = 16;
+	lg->gpio.set = locomo_gpio_set;
+	lg->gpio.get = locomo_gpio_get;
+	lg->gpio.direction_input = locomo_gpio_direction_input;
+	lg->gpio.direction_output = locomo_gpio_direction_output;
+
+	ret = gpiochip_add(&lg->gpio);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int locomo_gpio_remove(struct platform_device *pdev)
+{
+	struct locomo_gpio *lg = platform_get_drvdata(pdev);
+
+	gpiochip_remove(&lg->gpio);
+
+	return 0;
+}
+
+static struct platform_driver locomo_gpio_driver = {
+	.probe		= locomo_gpio_probe,
+	.remove		= locomo_gpio_remove,
+	.driver		= {
+		.name	= "locomo-gpio",
+		.pm	= LOCOMO_GPIO_PM,
+	},
+};
+module_platform_driver(locomo_gpio_driver);
+
+MODULE_DESCRIPTION("Sharp LoCoMo GPIO driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
+MODULE_ALIAS("platform:locomo-gpio");
-- 
2.1.4


WARNING: multiple messages have this Message-ID (diff)
From: dbaryshkov@gmail.com (Dmitry Eremin-Solenikov)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 07/17] gpio: port LoCoMo gpio support from old driver
Date: Sun, 17 May 2015 19:27:47 +0300	[thread overview]
Message-ID: <1431880077-26321-8-git-send-email-dbaryshkov@gmail.com> (raw)
In-Reply-To: <1431880077-26321-1-git-send-email-dbaryshkov@gmail.com>

Add gpiolib driver for gpio pins placed on the LoCoMo GA.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/gpio/Kconfig       |  12 ++++
 drivers/gpio/Makefile      |   1 +
 drivers/gpio/gpio-locomo.c | 170 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 183 insertions(+)
 create mode 100644 drivers/gpio/gpio-locomo.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index caefe80..4542684 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -734,6 +734,18 @@ config GPIO_KEMPLD
 	  This driver can also be built as a module. If so, the module will be
 	  called gpio-kempld.
 
+config GPIO_LOCOMO
+	bool "Sharp LoCoMo GPIO support"
+	depends on MFD_LOCOMO
+	help
+	  Select this to support GPIO pins on Sharp LoCoMo Grid Array found
+	  in Sharp Zaurus collie and poodle models.
+
+	  Sat Yes if you have such PDA, say No otherwise.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called gpio-locomo.
+
 config GPIO_LP3943
 	tristate "TI/National Semiconductor LP3943 GPIO expander"
 	depends on MFD_LP3943
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index f71bb97..98655ae 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_GPIO_JANZ_TTL)	+= gpio-janz-ttl.o
 obj-$(CONFIG_GPIO_KEMPLD)	+= gpio-kempld.o
 obj-$(CONFIG_ARCH_KS8695)	+= gpio-ks8695.o
 obj-$(CONFIG_GPIO_INTEL_MID)	+= gpio-intel-mid.o
+obj-$(CONFIG_GPIO_LOCOMO)	+= gpio-locomo.o
 obj-$(CONFIG_GPIO_LOONGSON)	+= gpio-loongson.o
 obj-$(CONFIG_GPIO_LP3943)	+= gpio-lp3943.o
 obj-$(CONFIG_ARCH_LPC32XX)	+= gpio-lpc32xx.o
diff --git a/drivers/gpio/gpio-locomo.c b/drivers/gpio/gpio-locomo.c
new file mode 100644
index 0000000..dd9a1ca
--- /dev/null
+++ b/drivers/gpio/gpio-locomo.c
@@ -0,0 +1,170 @@
+/*
+ * Sharp LoCoMo support for GPIO
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This file contains all generic LoCoMo support.
+ *
+ * All initialization functions provided here are intended to be called
+ * from machine specific code with proper arguments when required.
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/bitops.h>
+#include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/io.h>
+#include <linux/regmap.h>
+#include <linux/mfd/locomo.h>
+
+struct locomo_gpio {
+	struct regmap *regmap;
+
+	struct gpio_chip gpio;
+
+	u16 rising_edge;
+	u16 falling_edge;
+
+	unsigned int save_gpo;
+	unsigned int save_gpe;
+};
+
+static int locomo_gpio_get(struct gpio_chip *chip,
+		unsigned offset)
+{
+	struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio);
+	unsigned int gpl;
+
+	regmap_read(lg->regmap, LOCOMO_GPL, &gpl);
+
+	return gpl & BIT(offset);
+}
+
+static void locomo_gpio_set(struct gpio_chip *chip,
+		unsigned offset, int value)
+{
+	struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio);
+
+	regmap_update_bits(lg->regmap, LOCOMO_GPO,
+			BIT(offset),
+			value ? BIT(offset) : 0);
+}
+
+static int locomo_gpio_direction_input(struct gpio_chip *chip,
+			unsigned offset)
+{
+	struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio);
+
+	regmap_update_bits(lg->regmap, LOCOMO_GPD, BIT(offset), BIT(offset));
+	regmap_update_bits(lg->regmap, LOCOMO_GPE, BIT(offset), BIT(offset));
+
+	return 0;
+}
+
+static int locomo_gpio_direction_output(struct gpio_chip *chip,
+			unsigned offset, int value)
+{
+	struct locomo_gpio *lg = container_of(chip, struct locomo_gpio, gpio);
+
+	regmap_update_bits(lg->regmap, LOCOMO_GPO,
+			BIT(offset),
+			value ? BIT(offset) : 0);
+	regmap_update_bits(lg->regmap, LOCOMO_GPD, BIT(offset), 0);
+	regmap_update_bits(lg->regmap, LOCOMO_GPE, BIT(offset), 0);
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int locomo_gpio_suspend(struct device *dev)
+{
+	struct locomo_gpio *lg = dev_get_drvdata(dev);
+
+	regmap_read(lg->regmap, LOCOMO_GPO, &lg->save_gpo);
+	regmap_write(lg->regmap, LOCOMO_GPO, 0x00);
+	regmap_read(lg->regmap, LOCOMO_GPE, &lg->save_gpe);
+	regmap_write(lg->regmap, LOCOMO_GPE, 0x00);
+
+	return 0;
+}
+
+static int locomo_gpio_resume(struct device *dev)
+{
+	struct locomo_gpio *lg = dev_get_drvdata(dev);
+
+	regmap_write(lg->regmap, LOCOMO_GPO, lg->save_gpo);
+	regmap_write(lg->regmap, LOCOMO_GPE, lg->save_gpe);
+
+	return 0;
+}
+static SIMPLE_DEV_PM_OPS(locomo_gpio_pm,
+		locomo_gpio_suspend, locomo_gpio_resume);
+#define LOCOMO_GPIO_PM	(&locomo_gpio_pm)
+#else
+#define LOCOMO_GPIO_PM	NULL
+#endif
+
+static int locomo_gpio_probe(struct platform_device *pdev)
+{
+	struct locomo_gpio *lg;
+	int ret;
+	struct locomo_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
+
+	lg = devm_kzalloc(&pdev->dev, sizeof(struct locomo_gpio),
+			GFP_KERNEL);
+	if (!lg)
+		return -ENOMEM;
+
+	lg->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!lg->regmap)
+		return -EINVAL;
+
+	platform_set_drvdata(pdev, lg);
+
+	regmap_write(lg->regmap, LOCOMO_GPO, 0x00);
+	regmap_write(lg->regmap, LOCOMO_GPE, 0x00);
+	regmap_write(lg->regmap, LOCOMO_GPD, 0x00);
+	regmap_write(lg->regmap, LOCOMO_GIE, 0x00);
+
+	lg->gpio.base = pdata ? pdata->gpio_base : -1;
+	lg->gpio.label = "locomo-gpio";
+	lg->gpio.ngpio = 16;
+	lg->gpio.set = locomo_gpio_set;
+	lg->gpio.get = locomo_gpio_get;
+	lg->gpio.direction_input = locomo_gpio_direction_input;
+	lg->gpio.direction_output = locomo_gpio_direction_output;
+
+	ret = gpiochip_add(&lg->gpio);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int locomo_gpio_remove(struct platform_device *pdev)
+{
+	struct locomo_gpio *lg = platform_get_drvdata(pdev);
+
+	gpiochip_remove(&lg->gpio);
+
+	return 0;
+}
+
+static struct platform_driver locomo_gpio_driver = {
+	.probe		= locomo_gpio_probe,
+	.remove		= locomo_gpio_remove,
+	.driver		= {
+		.name	= "locomo-gpio",
+		.pm	= LOCOMO_GPIO_PM,
+	},
+};
+module_platform_driver(locomo_gpio_driver);
+
+MODULE_DESCRIPTION("Sharp LoCoMo GPIO driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
+MODULE_ALIAS("platform:locomo-gpio");
-- 
2.1.4

  parent reply	other threads:[~2015-05-17 16:27 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-17 16:27 [PATCH v3 00/17] new LoCoMo driver set Dmitry Eremin-Solenikov
2015-05-17 16:27 ` Dmitry Eremin-Solenikov
2015-05-17 16:27 ` Dmitry Eremin-Solenikov
     [not found] ` <1431880077-26321-1-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-05-17 16:27   ` [PATCH v3 01/17] mfd: add new driver for Sharp LoCoMo Dmitry Eremin-Solenikov
2015-05-17 16:27     ` Dmitry Eremin-Solenikov
     [not found]     ` <1431880077-26321-2-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-05-19 10:38       ` Lee Jones
2015-05-19 10:38         ` Lee Jones
2015-05-19 11:21         ` Russell King - ARM Linux
2015-05-19 11:21           ` Russell King - ARM Linux
2015-05-19 11:21           ` Russell King - ARM Linux
2015-05-19 12:33           ` Lee Jones
2015-05-19 12:33             ` Lee Jones
2015-05-19 12:33             ` Lee Jones
2015-05-17 16:27   ` [PATCH v3 04/17] input: make LoCoMo keyboard driver support both poodle and collie Dmitry Eremin-Solenikov
2015-05-17 16:27     ` Dmitry Eremin-Solenikov
2015-05-17 16:27     ` Dmitry Eremin-Solenikov
     [not found]     ` <1431880077-26321-5-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-05-18 16:50       ` Dmitry Torokhov
2015-05-18 16:50         ` Dmitry Torokhov
2015-05-18 16:50         ` Dmitry Torokhov
2015-05-17 16:27   ` [PATCH v3 13/17] ASoC: pxa: poodle: make use of new locomo GPIO interface Dmitry Eremin-Solenikov
2015-05-17 16:27     ` Dmitry Eremin-Solenikov
2015-05-17 16:27     ` Dmitry Eremin-Solenikov
2015-05-17 16:27   ` [PATCH v3 14/17] ARM: pxa: poodle: use new LoCoMo driver Dmitry Eremin-Solenikov
2015-05-17 16:27     ` Dmitry Eremin-Solenikov
2015-05-17 16:27     ` Dmitry Eremin-Solenikov
2015-05-17 16:27   ` [PATCH v3 17/17] ARM: drop old " Dmitry Eremin-Solenikov
2015-05-17 16:27     ` Dmitry Eremin-Solenikov
2015-05-17 16:27 ` [PATCH v3 02/17] leds: port locomo leds driver to new locomo core Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-18  8:37   ` Jacek Anaszewski
2015-05-18  8:37     ` Jacek Anaszewski
2015-05-18  8:37     ` Jacek Anaszewski
2015-05-17 16:27 ` [PATCH v3 03/17] input: convert LoCoMo keyboard driver to use " Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-18 16:50   ` Dmitry Torokhov
2015-05-18 16:50     ` Dmitry Torokhov
2015-05-18 16:50     ` Dmitry Torokhov
2015-05-17 16:27 ` [PATCH v3 05/17] video: backlight: add new locomo backlight driver Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27 ` [PATCH v3 06/17] video: lcd: add LoCoMo LCD driver Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-19  9:36   ` Lee Jones
2015-05-19  9:36     ` Lee Jones
2015-05-19  9:36     ` Lee Jones
2015-05-19  9:45     ` Dmitry Eremin-Solenikov
2015-05-19  9:45       ` Dmitry Eremin-Solenikov
2015-05-19  9:45       ` Dmitry Eremin-Solenikov
2015-05-19 12:34       ` Lee Jones
2015-05-19 12:34         ` Lee Jones
2015-05-19 12:34         ` Lee Jones
2015-05-17 16:27 ` Dmitry Eremin-Solenikov [this message]
2015-05-17 16:27   ` [PATCH v3 07/17] gpio: port LoCoMo gpio support from old driver Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27 ` [PATCH v3 08/17] gpio: locomo: implement per-pin irq handling Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27 ` [PATCH v3 09/17] spi: add locomo SPI driver Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27 ` [PATCH v3 10/17] i2c: add locomo i2c driver Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27 ` [PATCH v3 11/17] ARM: sa1100: make collie use new locomo drivers Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27 ` [PATCH v3 12/17] ARM: sa1100: don't preallocate IRQ space for locomo Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27 ` [PATCH v3 15/17] ARM: pxa: poodle: " Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27 ` [PATCH v3 16/17] video: backlight: drop old locomo bl/lcd driver Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-17 16:27   ` Dmitry Eremin-Solenikov
2015-05-20 12:26 [PATCH v3 06/17] video: lcd: add LoCoMo LCD driver Jingoo Han
2015-05-20 12:26 ` Jingoo Han
2015-05-20 12:26 ` Jingoo Han

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431880077-26321-8-git-send-email-dbaryshkov@gmail.com \
    --to=dbaryshkov@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=andrea.adami@gmail.com \
    --cc=broonie@kernel.org \
    --cc=cooloney@gmail.com \
    --cc=daniel@zonque.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gnurou@gmail.com \
    --cc=jg1.han@samsung.com \
    --cc=lee.jones@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=plagnioj@jcrosoft.com \
    --cc=robert.jarzmik@free.fr \
    --cc=rpurdie@rpsys.net \
    --cc=sameo@linux.intel.com \
    --cc=tomi.valkeinen@ti.com \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.