linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Denis Turischev <denis-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
To: LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: Samuel Ortiz <sameo-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
	David Brownell
	<dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
	Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 3/3] gpio: add Intel SCH GPIO controller driver
Date: Thu, 11 Feb 2010 12:28:57 +0200	[thread overview]
Message-ID: <4B73DBE9.2030307@compulab.co.il> (raw)
In-Reply-To: <4B73DAEE.5080400-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>

Signed-off-by: Denis Turischev <denis-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>

diff -Nru linux-2.6.33-rc7.orig/drivers/gpio/Kconfig linux-2.6.33-rc7/drivers/gpio/Kconfig
--- linux-2.6.33-rc7.orig/drivers/gpio/Kconfig	2010-02-07 00:17:12.000000000 +0200
+++ linux-2.6.33-rc7/drivers/gpio/Kconfig	2010-02-10 15:15:49.000000000 +0200
@@ -85,6 +85,22 @@
  	help
  	  Say yes here to support the NEC VR4100 series General-purpose I/O Uint

+config GPIO_SCH
+	tristate "Intel SCH GPIO"
+	depends on GPIOLIB
+	select LPC_SCH
+	help
+	  Say yes here to support GPIO interface on Intel Poulsbo SCH.
+	  The Intel SCH contains a total of 14 GPIO pins. Ten GPIOs are
+	  powered by the core power rail and are turned off during sleep
+	  modes (S3 and higher). The remaining four GPIOs are powered by
+	  the Intel SCH suspend power supply. These GPIOs remain
+	  active during S3. The suspend powered GPIOs can be used to wake the
+	  system from the Suspend-to-RAM state.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called sch-gpio.
+
  comment "I2C GPIO expanders:"

  config GPIO_MAX732X
diff -Nru linux-2.6.33-rc7.orig/drivers/gpio/Makefile linux-2.6.33-rc7/drivers/gpio/Makefile
--- linux-2.6.33-rc7.orig/drivers/gpio/Makefile	2010-02-07 00:17:12.000000000 +0200
+++ linux-2.6.33-rc7/drivers/gpio/Makefile	2010-02-10 15:15:49.000000000 +0200
@@ -22,3 +22,4 @@
  obj-$(CONFIG_GPIO_BT8XX)	+= bt8xxgpio.o
  obj-$(CONFIG_GPIO_VR41XX)	+= vr41xx_giu.o
  obj-$(CONFIG_GPIO_WM831X)	+= wm831x-gpio.o
+obj-$(CONFIG_GPIO_SCH)		+= sch_gpio.o
diff -Nru linux-2.6.33-rc7.orig/drivers/gpio/sch_gpio.c linux-2.6.33-rc7/drivers/gpio/sch_gpio.c
--- linux-2.6.33-rc7.orig/drivers/gpio/sch_gpio.c	1970-01-01 02:00:00.000000000 +0200
+++ linux-2.6.33-rc7/drivers/gpio/sch_gpio.c	2010-02-10 15:44:20.000000000 +0200
@@ -0,0 +1,285 @@
+/*
+ *  sch_gpio.c - GPIO interface for Intel Poulsbo SCH
+ *
+ *  Copyright (c) 2010 CompuLab Ltd
+ *  Author: Denis Turischev <denis-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License 2 as published
+ *  by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/errno.h>
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+
+#include <linux/gpio.h>
+
+static DEFINE_SPINLOCK(gpio_lock);
+
+#define CGEN	(0x00)
+#define CGIO	(0x04)
+#define CGLV	(0x08)
+
+#define RGEN	(0x20)
+#define RGIO	(0x24)
+#define RGLV	(0x28)
+
+static unsigned short gpio_ba;
+
+static int sch_gpio_core_direction_in(struct gpio_chip *gc, unsigned  gpio_num)
+{
+	u8 curr_dirs;
+	unsigned short offset, bit;
+
+	spin_lock(&gpio_lock);
+
+	offset = CGIO + gpio_num / 8;
+	bit = gpio_num % 8;
+
+	curr_dirs = inb(gpio_ba + offset);
+
+	if (!(curr_dirs & (1 << bit)))
+		outb(curr_dirs | (1 << bit), gpio_ba + offset);
+
+	spin_unlock(&gpio_lock);
+	return 0;
+}
+
+static int sch_gpio_core_get(struct gpio_chip *gc, unsigned gpio_num)
+{
+	int res;
+	unsigned short offset, bit;
+
+	offset = CGLV + gpio_num / 8;
+	bit = gpio_num % 8;
+
+	res = !!(inb(gpio_ba + offset) & (1 << bit));
+	return res;
+}
+
+static void sch_gpio_core_set(struct gpio_chip *gc, unsigned gpio_num, int val)
+{
+	u8 curr_vals;
+	unsigned short offset, bit;
+
+	spin_lock(&gpio_lock);
+
+	offset = CGLV + gpio_num / 8;
+	bit = gpio_num % 8;
+
+	curr_vals = inb(gpio_ba + offset);
+
+	if (val)
+		outb(curr_vals | (1 << bit), gpio_ba + offset);
+	else
+		outb((curr_vals & ~(1 << bit)), gpio_ba + offset);
+	spin_unlock(&gpio_lock);
+}
+
+static int sch_gpio_core_direction_out(struct gpio_chip *gc,
+					unsigned gpio_num, int val)
+{
+	u8 curr_dirs;
+	unsigned short offset, bit;
+
+	sch_gpio_core_set(gc, gpio_num, val);
+
+	spin_lock(&gpio_lock);
+
+	offset = CGIO + gpio_num / 8;
+	bit = gpio_num % 8;
+
+	curr_dirs = inb(gpio_ba + offset);
+	if (curr_dirs & (1 << bit))
+		outb(curr_dirs & ~(1 << bit), gpio_ba + offset);
+
+	spin_unlock(&gpio_lock);
+	return 0;
+}
+
+static struct gpio_chip sch_gpio_core = {
+	.label			= "sch_gpio_core",
+	.owner			= THIS_MODULE,
+	.direction_input	= sch_gpio_core_direction_in,
+	.get			= sch_gpio_core_get,
+	.direction_output	= sch_gpio_core_direction_out,
+	.set			= sch_gpio_core_set,
+};
+
+static int sch_gpio_resume_direction_in(struct gpio_chip *gc,
+					unsigned gpio_num)
+{
+	u8 curr_dirs;
+
+	spin_lock(&gpio_lock);
+
+	curr_dirs = inb(gpio_ba + RGIO);
+
+	if (!(curr_dirs & (1 << gpio_num)))
+		outb(curr_dirs | (1 << gpio_num) , gpio_ba + RGIO);
+
+	spin_unlock(&gpio_lock);
+	return 0;
+}
+
+static int sch_gpio_resume_get(struct gpio_chip *gc, unsigned gpio_num)
+{
+	return !!(inb(gpio_ba + RGLV) & (1 << gpio_num));
+}
+
+static void sch_gpio_resume_set(struct gpio_chip *gc,
+				unsigned gpio_num, int val)
+{
+	u8 curr_vals;
+
+	spin_lock(&gpio_lock);
+
+	curr_vals = inb(gpio_ba + RGLV);
+
+	if (val)
+		outb(curr_vals | (1 << gpio_num), gpio_ba + RGLV);
+	else
+		outb((curr_vals & ~(1 << gpio_num)), gpio_ba + RGLV);
+
+	spin_unlock(&gpio_lock);
+}
+
+static int sch_gpio_resume_direction_out(struct gpio_chip *gc,
+					unsigned gpio_num, int val)
+{
+	u8 curr_dirs;
+
+	sch_gpio_resume_set(gc, gpio_num, val);
+
+	spin_lock(&gpio_lock);
+
+	curr_dirs = inb(gpio_ba + RGIO);
+	if (curr_dirs & (1 << gpio_num))
+		outb(curr_dirs & ~(1 << gpio_num), gpio_ba + RGIO);
+
+	spin_unlock(&gpio_lock);
+	return 0;
+}
+
+static struct gpio_chip sch_gpio_resume = {
+	.label			= "sch_gpio_resume",
+	.owner			= THIS_MODULE,
+	.direction_input	= sch_gpio_resume_direction_in,
+	.get			= sch_gpio_resume_get,
+	.direction_output	= sch_gpio_resume_direction_out,
+	.set			= sch_gpio_resume_set,
+};
+
+static int __devinit sch_gpio_probe(struct platform_device *pdev)
+{
+	struct resource *res;
+	int err;
+
+	res = platform_get_resource(pdev, IORESOURCE_IO, 0);
+	if (!res)
+		return -EBUSY;
+
+	if (acpi_check_region(res->start, resource_size(res), pdev->name))
+		return -ENODEV;
+
+	if (!request_region(res->start, resource_size(res), pdev->name))
+		return -EBUSY;
+
+	gpio_ba = res->start;
+
+	sch_gpio_core.base = 0;
+	sch_gpio_core.ngpio = 10;
+	sch_gpio_core.dev = &pdev->dev;
+
+	sch_gpio_resume.base = 10;
+	sch_gpio_resume.ngpio = 4;
+	sch_gpio_resume.dev = &pdev->dev;
+
+	err = gpiochip_add(&sch_gpio_core);
+	if (err < 0)
+		goto err_sch_gpio_core;
+
+	err = gpiochip_add(&sch_gpio_resume);
+	if (err < 0)
+		goto err_sch_gpio_resume;
+
+	/*
+	 * GPIO[6:0] enabled by default
+	 * GPIO7 is configured by the CMC as SLPIOVR
+	 * Enable GPIO[9:8] core powered gpios explicitly
+	 */
+	outb(0x3, gpio_ba + CGEN + 1);
+	/*
+	 * SUS_GPIO[2:0] enabled by default
+	 * Enable SUS_GPIO3 resume powered gpio explicitly
+	 */
+	outb(0x8, gpio_ba + RGEN);
+
+	return 0;
+
+err_sch_gpio_resume:
+	gpiochip_remove(&sch_gpio_core);
+
+err_sch_gpio_core:
+	release_region(res->start, resource_size(res));
+	gpio_ba = 0;
+
+	return err;
+}
+
+static int __devexit sch_gpio_remove(struct platform_device *pdev)
+{
+	struct resource *res;
+	if (gpio_ba) {
+		gpiochip_remove(&sch_gpio_core);
+		gpiochip_remove(&sch_gpio_resume);
+
+		res = platform_get_resource(pdev, IORESOURCE_IO, 0);
+
+		release_region(res->start, resource_size(res));
+		gpio_ba = 0;
+	}
+
+	return 0;
+}
+
+static struct platform_driver sch_gpio_driver = {
+	.driver = {
+		.name = "sch_gpio",
+		.owner = THIS_MODULE,
+	},
+	.probe		= sch_gpio_probe,
+	.remove		= __devexit_p(sch_gpio_remove),
+};
+
+static int __init sch_gpio_init(void)
+{
+	return platform_driver_register(&sch_gpio_driver);
+}
+
+static void __exit sch_gpio_exit(void)
+{
+	platform_driver_unregister(&sch_gpio_driver);
+}
+
+module_init(sch_gpio_init);
+module_exit(sch_gpio_exit);
+
+MODULE_AUTHOR("Denis Turischev <denis-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>");
+MODULE_DESCRIPTION("GPIO interface for Intel Poulsbo SCH");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:sch_gpio");

      parent reply	other threads:[~2010-02-11 10:28 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-11 10:24 [PATCH 0/3] Add Intel SCH GPIO driver Denis Turischev
     [not found] ` <4B73DAEE.5080400-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
2010-02-11 10:26   ` [PATCH 1/3] MFD: introduce lpc_sch for Intel SCH LPC bridge Denis Turischev
     [not found]     ` <4B73DB4B.40501-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
2010-02-16 10:08       ` Samuel Ortiz
     [not found]         ` <20100216100809.GA2935-jcdQHdrhKHMdnm+yROfE0A@public.gmane.org>
2010-02-16 13:59           ` Pan, Jacob jun
2010-02-16 15:45             ` Jean Delvare
     [not found]               ` <20100216164523.5a3e13a5-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-02-16 17:19                 ` Pan, Jacob jun
     [not found]                   ` <43F901BD926A4E43B106BF17856F0755A2D58F23-osO9UTpF0UQ8Ug9VwtkbtrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2010-02-16 17:29                     ` Jean Delvare
2010-02-16 19:57       ` David Brownell
     [not found]         ` <201002161157.47196.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2010-02-16 21:49           ` Jean Delvare
     [not found]             ` <20100216224947.5c46ff86-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-02-17 10:03               ` Denis Turischev
     [not found]                 ` <4B7BBEE5.3040104-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
2010-02-17 10:44                   ` Jean Delvare
     [not found]                     ` <20100217114433.6a405bd3-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-02-17 12:35                       ` Mike Rapoport
     [not found]                         ` <4B7BE292.5080700-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
2010-02-17 14:37                           ` Samuel Ortiz
2010-02-18 17:42       ` [PATCH v2 " Denis Turischev
     [not found]         ` <4B7D7C13.20703-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
2010-02-18 17:45           ` Randy Dunlap
     [not found]             ` <4B7D7CD0.7080202-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2010-02-18 18:01               ` [PATCH v3 " Denis Turischev
     [not found]                 ` <4B7D807D.9060105-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
2010-02-18 18:08                   ` Randy Dunlap
2010-02-19 10:30                   ` Samuel Ortiz
2010-02-23  8:26                   ` Jean Delvare
     [not found]                     ` <20100223092636.42b083f0-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-02-23  9:25                       ` Denis Turischev
     [not found]                         ` <4B839F27.2040003-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
2010-02-23  9:41                           ` Samuel Ortiz
2010-02-11 10:28   ` [PATCH 2/3] i2c: convert i2c-isch to platform_device Denis Turischev
2010-02-17 15:42     ` [PATCH v2 " Denis Turischev
     [not found]       ` <4B7C0E5D.3070909-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
2010-02-19 10:33         ` Samuel Ortiz
2010-02-21 12:46         ` [PATCH v3 " Denis Turischev
     [not found]           ` <4B812B42.2090405-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
2010-02-23  7:00             ` Mike Rapoport
     [not found]               ` <4B837D0C.3000708-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
2010-02-23  8:12                 ` Jean Delvare
     [not found]                   ` <20100223091221.086ff17b-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-02-23  8:20                     ` Samuel Ortiz
     [not found]                       ` <20100223082054.GA3550-jcdQHdrhKHMdnm+yROfE0A@public.gmane.org>
2010-02-23  8:24                         ` Jean Delvare
2010-02-28 19:00           ` Samuel Ortiz
     [not found]             ` <20100228190015.GB3589-jcdQHdrhKHMdnm+yROfE0A@public.gmane.org>
2010-03-01 16:59               ` [PATCH v4 " Denis Turischev
     [not found]                 ` <4B8BF28B.1060701-UTxiZqZC01RS1MOuV/RT9w@public.gmane.org>
2010-03-02 10:06                   ` Samuel Ortiz
2010-02-11 10:28   ` Denis Turischev [this message]

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=4B73DBE9.2030307@compulab.co.il \
    --to=denis-utxizqzc01rs1mouv/rt9w@public.gmane.org \
    --cc=dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=sameo-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).