summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-clps711x/devices.c
blob: b6647dec2656c0d23f576d99395b035292f15580 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * Copyright (C) 2012 Alexander Shiyan <shc_work@mail.ru>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 */

#include <common.h>
#include <init.h>
#include <linux/sizes.h>

#include <asm/io.h>
#include <asm/memory.h>

#include <linux/clk.h>

#include <mach/clps711x.h>

static int clps711x_mem_init(void)
{
	ulong memsize = get_ram_size((ulong *)SDRAM0_BASE, SZ_64M);

	arm_add_mem_device("ram0", SDRAM0_BASE, memsize);

	return 0;
}
mem_initcall(clps711x_mem_init);

inline static void _clps711x_setup_memcfg(int bank, u32 addr, u32 val)
{
	u32 tmp = readl(addr);

	tmp &= ~(0xff << (bank * 8));
	tmp |= val << (bank * 8);

	writel(tmp, addr);
}

void clps711x_setup_memcfg(int bank, u32 val)
{
	switch (bank) {
	case 0 ... 3:
		_clps711x_setup_memcfg(bank, MEMCFG1, val);
		break;
	case 4 ... 5:
		_clps711x_setup_memcfg(bank - 4, MEMCFG2, val);
		break;
	}
}

static struct resource uart0_resources[] = {
	DEFINE_RES_MEM(UARTDR1, SZ_128),
};

static struct resource uart1_resources[] = {
	DEFINE_RES_MEM(UARTDR2, SZ_128),
};

void clps711x_add_uart(unsigned int id)
{
	switch (id) {
	case 0:
		clk_add_alias(NULL, "clps711x-uart0", "uart", NULL);
		add_generic_device_res("clps711x-uart", 0, uart0_resources,
				       ARRAY_SIZE(uart0_resources), NULL);
		break;
	case 1:
		clk_add_alias(NULL, "clps711x-uart1", "uart", NULL);
		add_generic_device_res("clps711x-uart", 1, uart1_resources,
				       ARRAY_SIZE(uart1_resources), NULL);
		break;
	}
}

static struct resource gpio0_resources[] = {
	DEFINE_RES_MEM(PADR, SZ_1),
	DEFINE_RES_MEM(PADDR, SZ_1),
};

static struct resource gpio1_resources[] = {
	DEFINE_RES_MEM(PBDR, SZ_1),
	DEFINE_RES_MEM(PBDDR, SZ_1),
};

static struct resource gpio2_resources[] = {
	DEFINE_RES_MEM(PCDR, SZ_1),
	DEFINE_RES_MEM(PCDDR, SZ_1),
};

static struct resource gpio3_resources[] = {
	DEFINE_RES_MEM(PDDR, SZ_1),
	DEFINE_RES_MEM(PDDDR, SZ_1),
};

static struct resource gpio4_resources[] = {
	DEFINE_RES_MEM(PEDR, SZ_1),
	DEFINE_RES_MEM(PEDDR, SZ_1),
};

static __init int clps711x_gpio_init(void)
{
	add_generic_device_res("clps711x-gpio", 0, gpio0_resources,
			       ARRAY_SIZE(gpio0_resources), NULL);
	add_generic_device_res("clps711x-gpio", 1, gpio1_resources,
			       ARRAY_SIZE(gpio1_resources), NULL);
	add_generic_device_res("clps711x-gpio", 2, gpio2_resources,
			       ARRAY_SIZE(gpio2_resources), NULL);
	add_generic_device_res("clps711x-gpio", 3, gpio3_resources,
			       ARRAY_SIZE(gpio3_resources), NULL);
	add_generic_device_res("clps711x-gpio", 4, gpio4_resources,
			       ARRAY_SIZE(gpio4_resources), NULL);

	return 0;
}
coredevice_initcall(clps711x_gpio_init);

static __init int clps711x_syscon_init(void)
{
	/* SYSCON1, SYSFLG1 */
	add_generic_device("syscon", 1, NULL, SYSCON1, SZ_128,
			   IORESOURCE_MEM, NULL);
	/* SYSCON2, SYSFLG2 */
	add_generic_device("syscon", 2, NULL, SYSCON2, SZ_128,
			   IORESOURCE_MEM, NULL);

	return 0;
}
postcore_initcall(clps711x_syscon_init);