Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 056c78d3 authored by Linus Walleij's avatar Linus Walleij
Browse files

ARM: nomadik: register GPIOs dynamically



Register the NHK8815 GPIO devices dynamically like the Ux500 does
it.

Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent f8f5701b
Loading
Loading
Loading
Loading
+47 −67
Original line number Original line Diff line number Diff line
@@ -35,86 +35,66 @@
#include "clock.h"
#include "clock.h"
#include "cpu-8815.h"
#include "cpu-8815.h"


#define __MEM_4K_RESOURCE(x) \
static AMBA_APB_DEVICE(cpu8815_amba_rng, "rng", 0, NOMADIK_RNG_BASE, { }, NULL);
	.res = {.start = (x), .end = (x) + SZ_4K - 1, .flags = IORESOURCE_MEM}

/* The 8815 has 4 GPIO blocks, let's register them immediately */


#define GPIO_RESOURCE(block)						\
static struct amba_device *amba_devs[] __initdata = {
	{								\
	&cpu8815_amba_rng_device
		.start	= NOMADIK_GPIO##block##_BASE,			\
};
		.end	= NOMADIK_GPIO##block##_BASE + SZ_4K - 1,	\
		.flags	= IORESOURCE_MEM,				\
	},								\
	{								\
		.start	= IRQ_GPIO##block,				\
		.end	= IRQ_GPIO##block,				\
		.flags	= IORESOURCE_IRQ,				\
	}


#define GPIO_DEVICE(block)						\
/* The 8815 has 4 GPIO blocks, let's register them immediately */
	{								\
static resource_size_t __initdata cpu8815_gpio_base[] = {
		.name 		= "gpio",				\
	NOMADIK_GPIO0_BASE,
		.id		= block,				\
	NOMADIK_GPIO1_BASE,
		.num_resources 	= 2,					\
	NOMADIK_GPIO2_BASE,
		.resource	= &cpu8815_gpio_resources[block * 2],	\
	NOMADIK_GPIO3_BASE,
		.dev = {						\
};
			.platform_data = &cpu8815_gpio[block],		\
		},							\
	}


static struct nmk_gpio_platform_data cpu8815_gpio[] = {
static struct platform_device *
cpu8815_add_gpio(int id, resource_size_t addr, int irq,
		 struct nmk_gpio_platform_data *pdata)
{
{
		.name = "GPIO-0-31",
	struct resource resources[] = {
		.first_gpio = 0,
		{
		.first_irq = NOMADIK_GPIO_TO_IRQ(0),
			.start	= addr,
	}, {
			.end	= addr + 127,
		.name = "GPIO-32-63",
			.flags	= IORESOURCE_MEM,
		.first_gpio = 32,
		},
		.first_irq = NOMADIK_GPIO_TO_IRQ(32),
		{
	}, {
			.start	= irq,
		.name = "GPIO-64-95",
			.end	= irq,
		.first_gpio = 64,
			.flags	= IORESOURCE_IRQ,
		.first_irq = NOMADIK_GPIO_TO_IRQ(64),
	}, {
		.name = "GPIO-96-127", /* 124..127 not routed to pin */
		.first_gpio = 96,
		.first_irq = NOMADIK_GPIO_TO_IRQ(96),
		}
		}
	};
	};


static struct resource cpu8815_gpio_resources[] = {
	return platform_device_register_resndata(NULL, "gpio", id,
	GPIO_RESOURCE(0),
				resources, ARRAY_SIZE(resources),
	GPIO_RESOURCE(1),
				pdata, sizeof(*pdata));
	GPIO_RESOURCE(2),
}
	GPIO_RESOURCE(3),
};

static struct platform_device cpu8815_platform_gpio[] = {
	GPIO_DEVICE(0),
	GPIO_DEVICE(1),
	GPIO_DEVICE(2),
	GPIO_DEVICE(3),
};


static AMBA_APB_DEVICE(cpu8815_amba_rng, "rng", 0, NOMADIK_RNG_BASE, { }, NULL);
void cpu8815_add_gpios(resource_size_t *base, int num, int irq,
		       struct nmk_gpio_platform_data *pdata)
{
	int first = 0;
	int i;


static struct platform_device *platform_devs[] __initdata = {
	for (i = 0; i < num; i++, first += 32, irq++) {
	cpu8815_platform_gpio + 0,
		pdata->first_gpio = first;
	cpu8815_platform_gpio + 1,
		pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first);
	cpu8815_platform_gpio + 2,
		pdata->num_gpio = 32;
	cpu8815_platform_gpio + 3,
};


static struct amba_device *amba_devs[] __initdata = {
		cpu8815_add_gpio(i, base[i], irq, pdata);
	&cpu8815_amba_rng_device
	}
};
}


static int __init cpu8815_init(void)
static int __init cpu8815_init(void)
{
{
	int i;
	int i;
	struct nmk_gpio_platform_data pdata = {
		/* No custom data yet */
	};


	platform_add_devices(platform_devs, ARRAY_SIZE(platform_devs));
	cpu8815_add_gpios(cpu8815_gpio_base, ARRAY_SIZE(cpu8815_gpio_base),
			  IRQ_GPIO0, &pdata);
	for (i = 0; i < ARRAY_SIZE(amba_devs); i++)
	for (i = 0; i < ARRAY_SIZE(amba_devs); i++)
		amba_device_register(amba_devs[i], &iomem_resource);
		amba_device_register(amba_devs[i], &iomem_resource);
	return 0;
	return 0;