public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
From: Charulatha V <charu@ti.com>
To: linux-omap@vger.kernel.org
Cc: rnayak@ti.com, paul@pwsan.com, tony@atomide.com,
	Charulatha V <charu@ti.com>
Subject: [PATCH 4/8] OMAP4:GPIO:Add support for early platform gpio device
Date: Wed, 31 Mar 2010 17:53:55 +0530	[thread overview]
Message-ID: <1270038239-1090-5-git-send-email-charu@ti.com> (raw)
In-Reply-To: <1270038239-1090-4-git-send-email-charu@ti.com>

This patch adds support for implementing OMAP4 GPIO as an
early platform device and adds gpio_init specific to OMAP4

This patch adds device structures for each GPIO device in
OMAP4 architecture. These strutures are not created in a
separate *_data.c file because these structures would be
removed once the driver gets adapted to HWMOD way.

Signed-off-by: Charulatha V <charu@ti.com>
---
 arch/arm/mach-omap2/gpio44xx.c          |  350 +++++++++++++++++++++++++++++++
 arch/arm/mach-omap2/include/mach/gpio.h |    3 +-
 2 files changed, 352 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/mach-omap2/gpio44xx.c

diff --git a/arch/arm/mach-omap2/gpio44xx.c b/arch/arm/mach-omap2/gpio44xx.c
new file mode 100644
index 0000000..6133251
--- /dev/null
+++ b/arch/arm/mach-omap2/gpio44xx.c
@@ -0,0 +1,350 @@
+/*
+ * gpio44xx.c - OMAP4-specific gpio code
+ *
+ * Copyright (C) 2010 Texas Instruments, Inc.
+ *
+ * Author:
+ *	Charulatha V <charu@ti.com>
+ *
+ * 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.
+ */
+
+#include <plat/gpio.h>
+
+/*
+ * OMAP4 GPIO reg offsets
+ */
+static struct gpio_reg_offset omap4_gpio_reg = {
+	.data_in	= OMAP4_GPIO_DATAIN,
+	.data_out	= OMAP4_GPIO_DATAOUT,
+	.data_out_set	= OMAP4_GPIO_SETDATAOUT,
+	.data_out_clear	= OMAP4_GPIO_CLEARDATAOUT,
+	.dir_ctrl	= OMAP4_GPIO_OE,
+	.irq_status0	= OMAP4_GPIO_IRQSTATUS0,
+	.irq_status1	= OMAP4_GPIO_IRQSTATUS1,
+	.irq_mask	= OMAP4_GPIO_IRQSTATUSSET0,
+	.irq_set	= OMAP4_GPIO_IRQSTATUSSET0,
+	.irq_clear	= OMAP4_GPIO_IRQSTATUSCLR0,
+	.irq_mask_bits	= 0xffffffff,
+	.irq_inv	= 0,
+	.wkup_enable	= OMAP4_GPIO_IRQWAKEN0,
+	.wkup_clear	= OMAP4_GPIO_IRQWAKEN0,
+	.wkup_set	= OMAP4_GPIO_IRQWAKEN0,
+	.debounce_ena	= OMAP4_GPIO_DEBOUNCENABLE,
+	.debounce_val	= OMAP4_GPIO_DEBOUNCINGTIME,
+	.ctrl		= OMAP4_GPIO_CTRL,
+	.syscfg		= OMAP4_GPIO_SYSCONFIG,
+	.leveldetect0	= OMAP4_GPIO_LEVELDETECT0,
+	.leveldetect1	= OMAP4_GPIO_LEVELDETECT1,
+	.rise_detect	= OMAP4_GPIO_RISINGDETECT,
+	.fall_detect	= OMAP4_GPIO_FALLINGDETECT,
+	.rev_reg	= OMAP4_GPIO_REVISION,
+};
+
+/*
+ * OMAP4 GPIO1 interface data
+ */
+static struct __initdata resource omap4_gpio1_resources[] = {
+	{
+		.start	= OMAP44XX_GPIO1_BASE,
+		.end	= OMAP44XX_GPIO1_BASE + OMAP4_GPIO_AS_LEN - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+	{
+		.start	= OMAP44XX_IRQ_GPIO1,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct __initdata omap_gpio_platform_data omap4_gpio1_config = {
+	.ick_name = "gpio1_ick",
+	.dbck_name = "gpio1_dbck",
+	.virtual_irq_start = IH_GPIO_BASE,
+	.method	= METHOD_GPIO_OMAP2PLUS,
+};
+
+static struct __initdata platform_device omap4_gpio1 = {
+	.name           = "omap-gpio",
+	.id             = 0,
+	.dev            = {
+		.platform_data = &omap4_gpio1_config,
+	},
+	.num_resources = ARRAY_SIZE(omap4_gpio1_resources),
+	.resource = omap4_gpio1_resources,
+};
+
+/*
+ * OMAP4 GPIO2 interface data
+ */
+static struct __initdata resource omap4_gpio2_resources[] = {
+	{
+		.start	= OMAP44XX_GPIO2_BASE,
+		.end	= OMAP44XX_GPIO2_BASE + OMAP4_GPIO_AS_LEN - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+	{
+		.start	= OMAP44XX_IRQ_GPIO2,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct __initdata omap_gpio_platform_data omap4_gpio2_config = {
+	.ick_name = "gpio2_ick",
+	.dbck_name = "gpio2_dbck",
+	.virtual_irq_start = IH_GPIO_BASE + 32,
+	.method	= METHOD_GPIO_OMAP2PLUS,
+};
+
+static struct __initdata platform_device omap4_gpio2 = {
+	.name           = "omap-gpio",
+	.id             = 1,
+	.dev            = {
+		.platform_data = &omap4_gpio2_config,
+	},
+	.num_resources = ARRAY_SIZE(omap4_gpio2_resources),
+	.resource = omap4_gpio2_resources,
+};
+
+/*
+ * OMAP4 GPIO3 interface data
+ */
+static struct __initdata resource omap4_gpio3_resources[] = {
+	{
+		.start	= OMAP44XX_GPIO3_BASE,
+		.end	= OMAP44XX_GPIO3_BASE + OMAP4_GPIO_AS_LEN - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+	{
+		.start	= OMAP44XX_IRQ_GPIO3,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct __initdata omap_gpio_platform_data omap4_gpio3_config = {
+	.ick_name = "gpio3_ick",
+	.dbck_name = "gpio3_dbck",
+	.virtual_irq_start = IH_GPIO_BASE + 64,
+	.method	= METHOD_GPIO_OMAP2PLUS,
+};
+
+static struct __initdata platform_device omap4_gpio3 = {
+	.name           = "omap-gpio",
+	.id             = 2,
+	.dev            = {
+		.platform_data = &omap4_gpio3_config,
+	},
+	.num_resources = ARRAY_SIZE(omap4_gpio3_resources),
+	.resource = omap4_gpio3_resources,
+};
+
+/*
+ * OMAP4 GPIO4 interface data
+ */
+static struct __initdata resource omap4_gpio4_resources[] = {
+	{
+		.start	= OMAP44XX_GPIO4_BASE,
+		.end	= OMAP44XX_GPIO4_BASE + OMAP4_GPIO_AS_LEN - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+	{
+		.start	= OMAP44XX_IRQ_GPIO4,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct __initdata omap_gpio_platform_data omap4_gpio4_config = {
+	.ick_name = "gpio4_ick",
+	.dbck_name = "gpio4_dbck",
+	.virtual_irq_start = IH_GPIO_BASE + 96,
+	.method	= METHOD_GPIO_OMAP2PLUS,
+};
+
+static struct __initdata platform_device omap4_gpio4 = {
+	.name           = "omap-gpio",
+	.id             = 3,
+	.dev            = {
+		.platform_data = &omap4_gpio4_config,
+	},
+	.num_resources = ARRAY_SIZE(omap4_gpio4_resources),
+	.resource = omap4_gpio4_resources,
+};
+
+/*
+ * OMAP4 GPIO5 interface data
+  */
+static struct __initdata resource omap4_gpio5_resources[] = {
+	{
+		.start	= OMAP44XX_GPIO5_BASE,
+		.end	= OMAP44XX_GPIO5_BASE + OMAP4_GPIO_AS_LEN - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+	{
+		.start	= OMAP44XX_IRQ_GPIO5,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct __initdata omap_gpio_platform_data omap4_gpio5_config = {
+	.ick_name = "gpio5_ick",
+	.dbck_name = "gpio5_dbck",
+	.virtual_irq_start = IH_GPIO_BASE + 128,
+	.method	= METHOD_GPIO_OMAP2PLUS,
+};
+
+static struct __initdata platform_device omap4_gpio5 = {
+	.name           = "omap-gpio",
+	.id             = 4,
+	.dev            = {
+		.platform_data = &omap4_gpio5_config,
+	},
+	.num_resources = ARRAY_SIZE(omap4_gpio5_resources),
+	.resource = omap4_gpio5_resources,
+};
+
+/*
+ * OMAP4 GPIO6 interface data
+  */
+static struct __initdata resource omap4_gpio6_resources[] = {
+	{
+		.start	= OMAP44XX_GPIO6_BASE,
+		.end	= OMAP44XX_GPIO6_BASE + OMAP4_GPIO_AS_LEN - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+	{
+		.start	= OMAP44XX_IRQ_GPIO6,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct __initdata omap_gpio_platform_data omap4_gpio6_config = {
+	.ick_name = "gpio6_ick",
+	.dbck_name = "gpio6_dbck",
+	.virtual_irq_start = IH_GPIO_BASE + 160,
+	.method	= METHOD_GPIO_OMAP2PLUS,
+};
+
+static struct __initdata platform_device omap4_gpio6 = {
+	.name           = "omap-gpio",
+	.id             = 5,
+	.dev            = {
+		.platform_data = &omap4_gpio6_config,
+	},
+	.num_resources = ARRAY_SIZE(omap4_gpio6_resources),
+	.resource = omap4_gpio6_resources,
+};
+
+static struct __initdata platform_device * omap4_gpio_early_dev[] = {
+	&omap4_gpio1,
+	&omap4_gpio2,
+	&omap4_gpio3,
+	&omap4_gpio4,
+	&omap4_gpio5,
+	&omap4_gpio6
+};
+
+static struct gpio_bank *omap4_get_gpio_bank(int gpio,
+				struct gpio_bank *gpio_bank)
+{
+	if (cpu_is_omap44xx())
+		return &gpio_bank[gpio >> 5];
+	BUG();
+	return NULL;
+}
+
+static int set_omap4_gpio_triggering(struct gpio_bank *bank, int gpio,
+						int trigger)
+{
+	void __iomem *base = bank->base;
+	u32 gpio_bit = 1 << gpio;
+	u32 val;
+
+	if (!cpu_is_omap44xx())
+		return -EINVAL;
+
+	MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT0, gpio_bit,
+				trigger & IRQ_TYPE_LEVEL_LOW);
+	MOD_REG_BIT(OMAP4_GPIO_LEVELDETECT1, gpio_bit,
+				trigger & IRQ_TYPE_LEVEL_HIGH);
+	MOD_REG_BIT(OMAP4_GPIO_RISINGDETECT, gpio_bit,
+				trigger & IRQ_TYPE_EDGE_RISING);
+	MOD_REG_BIT(OMAP4_GPIO_FALLINGDETECT, gpio_bit,
+				trigger & IRQ_TYPE_EDGE_FALLING);
+	if (likely(!(bank->non_wakeup_gpios & gpio_bit))) {
+		if (trigger != 0)
+			__raw_writel(1 << gpio, bank->base +
+						OMAP4_GPIO_IRQWAKEN0);
+		else {
+			val = __raw_readl(bank->base + OMAP4_GPIO_IRQWAKEN0);
+			__raw_writel(val & (~(1 << gpio)), bank->base +
+						 OMAP4_GPIO_IRQWAKEN0);
+		}
+	} else {
+		if (trigger != 0)
+			bank->enabled_non_wakeup_gpios |= gpio_bit;
+		else
+			bank->enabled_non_wakeup_gpios &= ~gpio_bit;
+	}
+
+	bank->level_mask = __raw_readl(bank->base + OMAP4_GPIO_LEVELDETECT0) |
+				__raw_readl(bank->base +
+						OMAP4_GPIO_LEVELDETECT1);
+
+	return 0;
+}
+
+void __init omap4_gpio_mod_init(struct gpio_bank *bank, int i)
+{
+	static const u32 non_wakeup_gpios[] = {
+		0xe203ffc0, 0x08700040
+	};
+
+	__raw_writel(0xffffffff, bank->base + OMAP4_GPIO_IRQSTATUSCLR0);
+	__raw_writew(0x0015, bank->base + OMAP4_GPIO_SYSCONFIG);
+	__raw_writel(0x00000000, bank->base + OMAP4_GPIO_DEBOUNCENABLE);
+	/* Initialize interface clock ungated, module enabled */
+	__raw_writel(0, bank->base + OMAP4_GPIO_CTRL);
+
+	if (i < ARRAY_SIZE(non_wakeup_gpios))
+		bank->non_wakeup_gpios = non_wakeup_gpios[i];
+}
+
+/*
+ * OMAP4 GPIO function pointers, reg offset pointer and other info
+ */
+static struct omap_gpio_info omap4_gpio_data = {
+	.reg_off		= &omap4_gpio_reg,
+	.index_mask		= 0x1f,
+	.no_of_gpio		= 192,
+	.bank_count		= OMAP4_NR_GPIOS,
+	.bank_bits		= 32,
+	.get_gpio_bank		= omap4_get_gpio_bank,
+	.gpio_mod_init		= omap4_gpio_mod_init,
+	.set_gpio_triggering	= set_omap4_gpio_triggering,
+};
+
+void __init omap4_gpio_init_data(void)
+{
+	gpio_init(&omap4_gpio_data);
+}
+
+int __init omap4_early_init_gpio(struct platform_device ***pdev)
+{
+	*pdev = omap4_gpio_early_dev;
+	return OMAP4_NR_GPIOS;
+}
+
+int __init omap4_gpio_dev_reg(void)
+{
+	if (cpu_is_omap44xx()) {
+		platform_device_register(&omap4_gpio1);
+		platform_device_register(&omap4_gpio2);
+		platform_device_register(&omap4_gpio3);
+		platform_device_register(&omap4_gpio4);
+		platform_device_register(&omap4_gpio5);
+		platform_device_register(&omap4_gpio6);
+	}
+	return 0;
+}
+arch_initcall(omap4_gpio_dev_reg);
diff --git a/arch/arm/mach-omap2/include/mach/gpio.h b/arch/arm/mach-omap2/include/mach/gpio.h
index e822a41..d2d9d17 100644
--- a/arch/arm/mach-omap2/include/mach/gpio.h
+++ b/arch/arm/mach-omap2/include/mach/gpio.h
@@ -89,7 +89,6 @@
 #define OMAP4_GPIO_IRQWAKEN0		0x0044
 #define OMAP4_GPIO_IRQWAKEN1		0x0048
 #define OMAP4_GPIO_SYSSTATUS		0x0114
-#define OMAP4_GPIO_SYSSTATUS		0x0114
 #define OMAP4_GPIO_IRQENABLE1		0x011c
 #define OMAP4_GPIO_WAKE_EN		0x0120
 #define OMAP4_GPIO_IRQSTATUS2		0x0128
@@ -112,6 +111,8 @@
 
 extern void omap2_gpio_init_data(void);
 extern void omap3_gpio_init_data(void);
+extern void omap4_gpio_init_data(void);
 extern int omap2_early_init_gpio(struct platform_device ***pdev);
 extern int omap3_early_init_gpio(struct platform_device ***pdev);
+extern int omap4_early_init_gpio(struct platform_device ***pdev);
 #endif
-- 
1.6.3.3


  reply	other threads:[~2010-03-31 12:19 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-31 12:23 [PATCH 0/8 RFC] OMAP: GPIO: Split OMAP1 and OMAP2PLUS Charulatha V
2010-03-31 12:23 ` [PATCH 1/8] OMAP:GPIO:Move architecture specific macros to specific header Charulatha V
2010-03-31 12:23   ` [PATCH 2/8] OMAP3:GPIO:Add support for early platform gpio device Charulatha V
2010-03-31 12:23     ` [PATCH 3/8] OMAP2:GPIO:Add " Charulatha V
2010-03-31 12:23       ` Charulatha V [this message]
2010-03-31 12:23         ` [PATCH 5/8] OMAP2PLUS:GPIO:Add OMAP2PLUS specific gpio support Charulatha V
2010-03-31 12:23           ` [PATCH 6/8] OMAP1:GPIO:Support for OMAP1 specific gpio Charulatha V
2010-03-31 12:23             ` [PATCH 7/8] OMAP2PLUS:GPIO:Move gpio_init from board files to init_common_hw Charulatha V
2010-03-31 12:23               ` [PATCH 8/8] OMAP:GPIO:Common platform code for all OMAPs Charulatha V
2010-04-01  9:34                 ` Tony Lindgren
2010-04-01  9:32               ` [PATCH 7/8] OMAP2PLUS:GPIO:Move gpio_init from board files to init_common_hw Tony Lindgren
2010-04-01 10:50                 ` Varadarajan, Charulatha
2010-04-06 22:13               ` Kevin Hilman
2010-04-01  9:30           ` [PATCH 5/8] OMAP2PLUS:GPIO:Add OMAP2PLUS specific gpio support Tony Lindgren
2010-04-06 22:08             ` Kevin Hilman
2010-04-01  7:26       ` [PATCH 3/8] OMAP2:GPIO:Add support for early platform gpio device Felipe Balbi
2010-04-01  8:53         ` Varadarajan, Charulatha
2010-04-01  8:58           ` Felipe Balbi
2010-04-01  9:16             ` Varadarajan, Charulatha
2010-04-01  7:23     ` [PATCH 2/8] OMAP3:GPIO:Add " Felipe Balbi
2010-04-01  8:58       ` Varadarajan, Charulatha
2010-04-01  9:12         ` Tony Lindgren
2010-04-01  9:19           ` Varadarajan, Charulatha
2010-04-01  9:13     ` Tony Lindgren
2010-04-01 10:49       ` Varadarajan, Charulatha
2010-04-01  9:31     ` Tony Lindgren
2010-04-01 10:50       ` Varadarajan, Charulatha
2010-04-01  7:17   ` [PATCH 1/8] OMAP:GPIO:Move architecture specific macros to specific header Felipe Balbi
2010-04-01  8:52     ` Varadarajan, Charulatha
2010-04-01  9:00       ` Felipe Balbi
2010-04-01  9:41       ` Tony Lindgren
2010-04-01 10:50         ` Varadarajan, Charulatha
2010-04-06 22:31 ` [PATCH 0/8 RFC] OMAP: GPIO: Split OMAP1 and OMAP2PLUS Kevin Hilman
2010-04-12 12:16   ` Varadarajan, Charulatha
2010-04-19 14:31     ` Kevin Hilman

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=1270038239-1090-5-git-send-email-charu@ti.com \
    --to=charu@ti.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=paul@pwsan.com \
    --cc=rnayak@ti.com \
    --cc=tony@atomide.com \
    /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