9
0
Fork 0

ARM i.MX: switch to gpiolib support

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
This commit is contained in:
Sascha Hauer 2012-09-03 10:18:09 +02:00
parent 2f8fe26382
commit b395e8bfb0
13 changed files with 126 additions and 145 deletions

View File

@ -32,6 +32,7 @@ config ARCH_EP93XX
config ARCH_IMX config ARCH_IMX
bool "Freescale iMX-based" bool "Freescale iMX-based"
select GENERIC_GPIO select GENERIC_GPIO
select GPIOLIB
config ARCH_MXS config ARCH_MXS
bool "Freescale i.MX23/28 (mxs) based" bool "Freescale i.MX23/28 (mxs) based"

View File

@ -27,7 +27,8 @@
#include <errno.h> #include <errno.h>
#include <io.h> #include <io.h>
#include <mach/imx-regs.h> #include <mach/imx-regs.h>
#include <mach/gpio.h> #include <gpio.h>
#include <init.h>
#if defined CONFIG_ARCH_IMX1 || defined CONFIG_ARCH_IMX21 || defined CONFIG_ARCH_IMX27 #if defined CONFIG_ARCH_IMX1 || defined CONFIG_ARCH_IMX21 || defined CONFIG_ARCH_IMX27
#define GPIO_DR 0x1c #define GPIO_DR 0x1c
@ -48,21 +49,15 @@
#define GPIO_ISR 0x18 #define GPIO_ISR 0x18
#endif #endif
extern void __iomem *imx_gpio_base[]; struct imx_gpio_chip {
extern int imx_gpio_count; void __iomem *base;
struct gpio_chip chip;
};
static void __iomem *gpio_get_base(unsigned gpio) static void imx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
{ {
if (gpio >= imx_gpio_count) struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
return NULL; void __iomem *base = imxgpio->base;
return imx_gpio_base[gpio / 32];
}
void gpio_set_value(unsigned gpio, int value)
{
void __iomem *base = gpio_get_base(gpio);
int shift = gpio % 32;
u32 val; u32 val;
if (!base) if (!base)
@ -71,59 +66,88 @@ void gpio_set_value(unsigned gpio, int value)
val = readl(base + GPIO_DR); val = readl(base + GPIO_DR);
if (value) if (value)
val |= 1 << shift; val |= 1 << gpio;
else else
val &= ~(1 << shift); val &= ~(1 << gpio);
writel(val, base + GPIO_DR); writel(val, base + GPIO_DR);
} }
int gpio_direction_input(unsigned gpio) static int imx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
{ {
void __iomem *base = gpio_get_base(gpio); struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
int shift = gpio % 32; void __iomem *base = imxgpio->base;
u32 val; u32 val;
if (!base) if (!base)
return -EINVAL; return -EINVAL;
val = readl(base + GPIO_GDIR); val = readl(base + GPIO_GDIR);
val &= ~(1 << shift); val &= ~(1 << gpio);
writel(val, base + GPIO_GDIR); writel(val, base + GPIO_GDIR);
return 0; return 0;
} }
int gpio_direction_output(unsigned gpio, int value) static int imx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
{ {
void __iomem *base = gpio_get_base(gpio); struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
int shift = gpio % 32; void __iomem *base = imxgpio->base;
u32 val; u32 val;
if (!base) gpio_set_value(gpio + chip->base, value);
return -EINVAL;
gpio_set_value(gpio, value);
val = readl(base + GPIO_GDIR); val = readl(base + GPIO_GDIR);
val |= 1 << shift; val |= 1 << gpio;
writel(val, base + GPIO_GDIR); writel(val, base + GPIO_GDIR);
return 0; return 0;
} }
int gpio_get_value(unsigned gpio) static int imx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
{ {
void __iomem *base = gpio_get_base(gpio); struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
int shift = gpio % 32; void __iomem *base = imxgpio->base;
u32 val; u32 val;
if (!base)
return -EINVAL;
val = readl(base + GPIO_PSR); val = readl(base + GPIO_PSR);
return val & (1 << shift) ? 1 : 0; return val & (1 << gpio) ? 1 : 0;
} }
static struct gpio_ops imx_gpio_ops = {
.direction_input = imx_gpio_direction_input,
.direction_output = imx_gpio_direction_output,
.get = imx_gpio_get_value,
.set = imx_gpio_set_value,
};
static int imx_gpio_probe(struct device_d *dev)
{
struct imx_gpio_chip *imxgpio;
imxgpio = xzalloc(sizeof(*imxgpio));
imxgpio->base = dev_request_mem_region(dev, 0);
imxgpio->chip.ops = &imx_gpio_ops;
imxgpio->chip.base = -1;
imxgpio->chip.ngpio = 32;
imxgpio->chip.dev = dev;
gpiochip_add(&imxgpio->chip);
dev_info(dev, "probed gpiochip%d with base %d\n", dev->id, imxgpio->chip.base);
return 0;
}
static struct driver_d imx_gpio_driver = {
.name = "imx-gpio",
.probe = imx_gpio_probe,
};
static int imx_gpio_add(void)
{
register_driver(&imx_gpio_driver);
return 0;
}
coredevice_initcall(imx_gpio_add);

View File

@ -1,4 +0,0 @@
extern void *imx_gpio_base[];
extern int imx_gpio_count;

View File

@ -16,16 +16,15 @@
*/ */
#include <common.h> #include <common.h>
#include <init.h>
#include "gpio.h" static int imx1_init(void)
{
void *imx_gpio_base[] = { add_generic_device("imx-gpio", 0, NULL, 0x0021c000, 0x100, IORESOURCE_MEM, NULL);
(void *)0x0021c000, add_generic_device("imx-gpio", 1, NULL, 0x0021c100, 0x100, IORESOURCE_MEM, NULL);
(void *)0x0021c100, add_generic_device("imx-gpio", 2, NULL, 0x0021c200, 0x100, IORESOURCE_MEM, NULL);
(void *)0x0021c200, add_generic_device("imx-gpio", 3, NULL, 0x0021c300, 0x100, IORESOURCE_MEM, NULL);
(void *)0x0021c300,
};
int imx_gpio_count = ARRAY_SIZE(imx_gpio_base) * 32;
return 0;
}
coredevice_initcall(imx1_init);

View File

@ -18,8 +18,6 @@
#include <common.h> #include <common.h>
#include <mach/imx-regs.h> #include <mach/imx-regs.h>
#include "gpio.h"
int imx_silicon_revision(void) int imx_silicon_revision(void)
{ {
// Known values: // Known values:
@ -28,14 +26,15 @@ int imx_silicon_revision(void)
return CID; return CID;
} }
void *imx_gpio_base[] = { static int imx21_init(void)
(void *)0x10015000, {
(void *)0x10015100, add_generic_device("imx-gpio", 0, NULL, 0x10015000, 0x100, IORESOURCE_MEM, NULL);
(void *)0x10015200, add_generic_device("imx-gpio", 1, NULL, 0x10015100, 0x100, IORESOURCE_MEM, NULL);
(void *)0x10015300, add_generic_device("imx-gpio", 2, NULL, 0x10015200, 0x100, IORESOURCE_MEM, NULL);
(void *)0x10015400, add_generic_device("imx-gpio", 3, NULL, 0x10015300, 0x100, IORESOURCE_MEM, NULL);
(void *)0x10015500, add_generic_device("imx-gpio", 4, NULL, 0x10015400, 0x100, IORESOURCE_MEM, NULL);
}; add_generic_device("imx-gpio", 5, NULL, 0x10015500, 0x100, IORESOURCE_MEM, NULL);
int imx_gpio_count = ARRAY_SIZE(imx_gpio_base) * 32;
return 0;
}
coredevice_initcall(imx21_init);

View File

@ -22,17 +22,6 @@
#include <io.h> #include <io.h>
#include <sizes.h> #include <sizes.h>
#include "gpio.h"
void *imx_gpio_base[] = {
(void *)0x53fcc000,
(void *)0x53fd0000,
(void *)0x53fa4000,
(void *)0x53f9c000,
};
int imx_gpio_count = ARRAY_SIZE(imx_gpio_base) * 32;
u64 imx_uid(void) u64 imx_uid(void)
{ {
u64 uid = 0; u64 uid = 0;
@ -59,6 +48,10 @@ static int imx25_init(void)
add_generic_device("imx_iim", 0, NULL, IMX_IIM_BASE, SZ_4K, add_generic_device("imx_iim", 0, NULL, IMX_IIM_BASE, SZ_4K,
IORESOURCE_MEM, &imx25_iim_pdata); IORESOURCE_MEM, &imx25_iim_pdata);
add_generic_device("imx-gpio", 0, NULL, 0x53fcc000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, 0x53fd0000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, 0x53fa4000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 3, NULL, 0x53f9c000, 0x1000, IORESOURCE_MEM, NULL);
return 0; return 0;
} }
coredevice_initcall(imx25_init); coredevice_initcall(imx25_init);

View File

@ -21,24 +21,11 @@
#include <init.h> #include <init.h>
#include <io.h> #include <io.h>
#include "gpio.h"
int imx_silicon_revision(void) int imx_silicon_revision(void)
{ {
return CID >> 28; return CID >> 28;
} }
void *imx_gpio_base[] = {
(void *)0x10015000,
(void *)0x10015100,
(void *)0x10015200,
(void *)0x10015300,
(void *)0x10015400,
(void *)0x10015500,
};
int imx_gpio_count = ARRAY_SIZE(imx_gpio_base) * 32;
/* /*
* Initialize MAX on i.MX27. necessary to give the DMA engine * Initialize MAX on i.MX27. necessary to give the DMA engine
* higher priority to the memory than the CPU. Needed for proper * higher priority to the memory than the CPU. Needed for proper
@ -86,6 +73,12 @@ static int imx27_init(void)
imx27_init_max(); imx27_init_max();
add_generic_device("imx-gpio", 0, NULL, 0x10015000, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, 0x10015100, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, 0x10015200, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 3, NULL, 0x10015300, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 4, NULL, 0x10015400, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 5, NULL, 0x10015500, 0x100, IORESOURCE_MEM, NULL);
return 0; return 0;
} }
coredevice_initcall(imx27_init); coredevice_initcall(imx27_init);

View File

@ -20,21 +20,15 @@
#include <sizes.h> #include <sizes.h>
#include <mach/imx-regs.h> #include <mach/imx-regs.h>
#include "gpio.h"
void *imx_gpio_base[] = {
(void *)0x53fcc000,
(void *)0x53fd0000,
(void *)0x53fa4000,
};
int imx_gpio_count = ARRAY_SIZE(imx_gpio_base) * 32;
static int imx31_init(void) static int imx31_init(void)
{ {
add_generic_device("imx_iim", 0, NULL, IMX_IIM_BASE, SZ_4K, add_generic_device("imx_iim", 0, NULL, IMX_IIM_BASE, SZ_4K,
IORESOURCE_MEM, NULL); IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 0, NULL, 0x53fcc000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, 0x53fd0000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, 0x53fa4000, 0x1000, IORESOURCE_MEM, NULL);
return 0; return 0;
} }
coredevice_initcall(imx31_init); coredevice_initcall(imx31_init);

View File

@ -23,16 +23,6 @@
#include <mach/iim.h> #include <mach/iim.h>
#include <mach/generic.h> #include <mach/generic.h>
#include "gpio.h"
void *imx_gpio_base[] = {
(void *)0x53fcc000,
(void *)0x53fd0000,
(void *)0x53fa4000,
};
int imx_gpio_count = ARRAY_SIZE(imx_gpio_base) * 32;
int imx_silicon_revision() int imx_silicon_revision()
{ {
uint32_t reg; uint32_t reg;
@ -66,6 +56,10 @@ static int imx35_init(void)
add_generic_device("imx_iim", 0, NULL, IMX_IIM_BASE, SZ_4K, add_generic_device("imx_iim", 0, NULL, IMX_IIM_BASE, SZ_4K,
IORESOURCE_MEM, NULL); IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 0, NULL, 0x53fcc000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, 0x53fd0000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, 0x53fa4000, 0x1000, IORESOURCE_MEM, NULL);
return 0; return 0;
} }
coredevice_initcall(imx35_init); coredevice_initcall(imx35_init);

View File

@ -24,17 +24,6 @@
#include <mach/imx-regs.h> #include <mach/imx-regs.h>
#include <mach/clock-imx51_53.h> #include <mach/clock-imx51_53.h>
#include "gpio.h"
void *imx_gpio_base[] = {
(void *)MX51_GPIO1_BASE_ADDR,
(void *)MX51_GPIO2_BASE_ADDR,
(void *)MX51_GPIO3_BASE_ADDR,
(void *)MX51_GPIO4_BASE_ADDR,
};
int imx_gpio_count = ARRAY_SIZE(imx_gpio_base) * 32;
#define SI_REV 0x48 #define SI_REV 0x48
static u32 mx51_silicon_revision; static u32 mx51_silicon_revision;
@ -89,6 +78,11 @@ static int imx51_init(void)
add_generic_device("imx_iim", 0, NULL, MX51_IIM_BASE_ADDR, SZ_4K, add_generic_device("imx_iim", 0, NULL, MX51_IIM_BASE_ADDR, SZ_4K,
IORESOURCE_MEM, NULL); IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 0, NULL, 0x73f84000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, 0x73f88000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, 0x73f8c000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 3, NULL, 0x73f90000, 0x1000, IORESOURCE_MEM, NULL);
return 0; return 0;
} }
coredevice_initcall(imx51_init); coredevice_initcall(imx51_init);

View File

@ -24,20 +24,6 @@
#include <mach/imx-regs.h> #include <mach/imx-regs.h>
#include <mach/clock-imx51_53.h> #include <mach/clock-imx51_53.h>
#include "gpio.h"
void *imx_gpio_base[] = {
(void *)MX53_GPIO1_BASE_ADDR,
(void *)MX53_GPIO2_BASE_ADDR,
(void *)MX53_GPIO3_BASE_ADDR,
(void *)MX53_GPIO4_BASE_ADDR,
(void *)MX53_GPIO5_BASE_ADDR,
(void *)MX53_GPIO6_BASE_ADDR,
(void *)MX53_GPIO7_BASE_ADDR,
};
int imx_gpio_count = ARRAY_SIZE(imx_gpio_base) * 32;
#define SI_REV 0x48 #define SI_REV 0x48
static u32 mx53_silicon_revision; static u32 mx53_silicon_revision;
@ -88,6 +74,13 @@ static int imx53_init(void)
add_generic_device("imx_iim", 0, NULL, MX53_IIM_BASE_ADDR, SZ_4K, add_generic_device("imx_iim", 0, NULL, MX53_IIM_BASE_ADDR, SZ_4K,
IORESOURCE_MEM, NULL); IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 0, NULL, MX53_GPIO1_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, MX53_GPIO2_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, MX53_GPIO3_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 3, NULL, MX53_GPIO4_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 4, NULL, MX53_GPIO5_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 5, NULL, MX53_GPIO6_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 6, NULL, MX53_GPIO7_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
return 0; return 0;
} }
coredevice_initcall(imx53_init); coredevice_initcall(imx53_init);

View File

@ -21,20 +21,6 @@
#include <sizes.h> #include <sizes.h>
#include <mach/imx6-regs.h> #include <mach/imx6-regs.h>
#include "gpio.h"
void *imx_gpio_base[] = {
(void *)MX6_GPIO1_BASE_ADDR,
(void *)MX6_GPIO2_BASE_ADDR,
(void *)MX6_GPIO3_BASE_ADDR,
(void *)MX6_GPIO4_BASE_ADDR,
(void *)MX6_GPIO5_BASE_ADDR,
(void *)MX6_GPIO6_BASE_ADDR,
(void *)MX6_GPIO7_BASE_ADDR,
};
int imx_gpio_count = ARRAY_SIZE(imx_gpio_base) * 32;
void imx6_init_lowlevel(void) void imx6_init_lowlevel(void)
{ {
void __iomem *aips1 = (void *)MX6_AIPS1_ON_BASE_ADDR; void __iomem *aips1 = (void *)MX6_AIPS1_ON_BASE_ADDR;
@ -69,3 +55,17 @@ void imx6_init_lowlevel(void)
writel(0xffffffff, 0x020c407c); writel(0xffffffff, 0x020c407c);
writel(0xffffffff, 0x020c4080); writel(0xffffffff, 0x020c4080);
} }
static int imx6_init(void)
{
add_generic_device("imx-gpio", 0, NULL, MX6_GPIO1_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, MX6_GPIO2_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, MX6_GPIO3_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 3, NULL, MX6_GPIO4_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 4, NULL, MX6_GPIO5_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 5, NULL, MX6_GPIO6_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 6, NULL, MX6_GPIO7_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
return 0;
}
coredevice_initcall(imx6_init);

View File

@ -18,5 +18,6 @@ source "drivers/input/Kconfig"
source "drivers/watchdog/Kconfig" source "drivers/watchdog/Kconfig"
source "drivers/pwm/Kconfig" source "drivers/pwm/Kconfig"
source "drivers/dma/Kconfig" source "drivers/dma/Kconfig"
source "drivers/gpio/Kconfig"
endmenu endmenu