[PATCH] AMD Geode CS5535/5536 GPIO driver

From: Alessandro Zummo
Date: Thu Feb 05 2009 - 10:10:26 EST




A GPIO driver for the AMD Geode CS5535/5536 Companion Devices.

In the release 2 I've addressed all the concerns expressed by the
various subsys maintainers involved.

---
arch/x86/Kconfig | 10 ++++
arch/x86/kernel/geode_32.c | 91 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+)

--- linux-2.6.28.orig/arch/x86/Kconfig 2009-02-03 19:38:43.000000000 +0100
+++ linux-2.6.28/arch/x86/Kconfig 2009-02-03 20:15:25.000000000 +0100
@@ -1911,6 +1911,16 @@ config GEODE_MFGPT_TIMER
MFGPTs have a better resolution and max interval than the
generic PIT, and are suitable for use as high-res timers.

+config GEODE_GPIO
+ bool "Geode GPIO support"
+ depends on MGEODE_LX && !CS5535_GPIO
+ default n
+ help
+ Say yes here to provide support for the 28 GPIO pins on
+ the AMD CS5535 and CS5536 Geode Companion Devices.
+
+ If unsure, say N.
+
config OLPC
bool "One Laptop Per Child support"
default n
--- linux-2.6.28.orig/arch/x86/kernel/geode_32.c 2008-12-25 00:26:37.000000000 +0100
+++ linux-2.6.28/arch/x86/kernel/geode_32.c 2009-02-03 20:22:32.000000000 +0100
@@ -2,6 +2,7 @@
* AMD Geode southbridge support code
* Copyright (C) 2006, Advanced Micro Devices, Inc.
* Copyright (C) 2007, Andres Salomon <dilinger@xxxxxxxxxx>
+ * Copyright (C) 2009, Tower Technologies
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public License
@@ -12,6 +13,8 @@
#include <linux/module.h>
#include <linux/ioport.h>
#include <linux/io.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
#include <asm/msr.h>
#include <asm/geode.h>

@@ -183,6 +186,89 @@ int geode_has_vsa2(void)
}
EXPORT_SYMBOL_GPL(geode_has_vsa2);

+/* GPIO subsystem functions */
+#ifdef CONFIG_GEODE_GPIO
+static void cs5535_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
+{
+ if (value)
+ geode_gpio_set(geode_gpio(offset), GPIO_OUTPUT_VAL);
+ else
+ geode_gpio_clear(geode_gpio(offset), GPIO_OUTPUT_VAL);
+}
+
+static int cs5535_gpio_get(struct gpio_chip *chip, unsigned offset)
+{
+ return geode_gpio_isset(geode_gpio(offset), GPIO_READ_BACK);
+}
+
+static int cs5535_direction_input(struct gpio_chip *chip, unsigned offset)
+{
+ geode_gpio_clear(geode_gpio(offset), GPIO_OUTPUT_ENABLE);
+ geode_gpio_set(geode_gpio(offset), GPIO_INPUT_ENABLE);
+
+ return 0;
+}
+
+static int cs5535_direction_output(struct gpio_chip *chip, unsigned offset,
+ int value)
+{
+ cs5535_gpio_set(chip, offset, value);
+
+ geode_gpio_set(geode_gpio(offset), GPIO_OUTPUT_ENABLE);
+ geode_gpio_clear(geode_gpio(offset), GPIO_INPUT_ENABLE);
+
+ return 0;
+}
+
+static struct gpio_chip cs5535 = {
+ .owner = THIS_MODULE,
+ .label = "cs5535-gpio",
+
+ .base = 0,
+ .ngpio = 28,
+
+ .get = cs5535_gpio_get,
+ .set = cs5535_gpio_set,
+
+ .direction_input = cs5535_direction_input,
+ .direction_output = cs5535_direction_output,
+};
+
+static int __init cs5535_gpio_probe(struct platform_device *pdev)
+{
+ int rc;
+
+ if (!request_region(geode_gpio_base(), LBAR_GPIO_SIZE, "cs5535-gpio")) {
+ dev_err(&pdev->dev, "cannot allocate I/O region at %x\n",
+ geode_gpio_base());
+ return -ENODEV;
+ }
+
+ rc = gpiochip_add(&cs5535);
+ if (rc < 0) {
+ dev_err(&pdev->dev, "cannot add GPIO\n");
+ goto fail_release;
+ }
+
+ dev_info(&pdev->dev, "registered at 0x%x, GPIO base %d\n",
+ geode_gpio_base(), cs5535.base);
+
+ return 0;
+
+fail_release:
+ release_region(geode_gpio_base(), LBAR_GPIO_SIZE);
+
+ return rc;
+}
+
+static struct platform_driver cs5535_gpio_driver = {
+ .driver = {
+ .name = "cs5535-gpio",
+ .owner = THIS_MODULE,
+ },
+};
+#endif
+
static int __init geode_southbridge_init(void)
{
if (!is_geode())
@@ -190,6 +276,11 @@ static int __init geode_southbridge_init

init_lbars();
(void) mfgpt_timer_setup();
+
+#ifdef CONFIG_GEODE_GPIO
+ platform_device_register_simple("cs5535-gpio", 0, NULL, 0);
+ platform_driver_probe(&cs5535_gpio_driver, cs5535_gpio_probe);
+#endif
return 0;
}


--

Best regards,

Alessandro Zummo,
Tower Technologies - Torino, Italy

http://www.towertech.it

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/