adds gpiodev support to ifxmips
[openwrt/openwrt.git] / target / linux / ifxmips / files / arch / mips / ifxmips / board.c
1 /*
2 * arch/mips/ifxmips/board.c
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
19 *
20 */
21
22 #include <linux/autoconf.h>
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/types.h>
26 #include <linux/string.h>
27 #include <linux/mtd/physmap.h>
28 #include <linux/kernel.h>
29 #include <linux/reboot.h>
30 #include <linux/platform_device.h>
31 #include <asm/bootinfo.h>
32 #include <asm/reboot.h>
33 #include <asm/time.h>
34 #include <asm/irq.h>
35 #include <asm/io.h>
36 #include <asm/ifxmips/ifxmips.h>
37
38 #define MAX_IFXMIPS_DEVS 6
39
40 #define BOARD_DANUBE "Danube"
41 #define BOARD_DANUBE_CHIPID 0x10129083
42
43 #define BOARD_TWINPASS "Twinpass"
44 #define BOARD_TWINPASS_CHIPID 0x3012D083
45
46 #define BOARD_DANUBE "Danube"
47
48 static unsigned int chiprev;
49
50 static struct platform_device *ifxmips_devs[MAX_IFXMIPS_DEVS];
51
52 static struct platform_device ifxmips_led[] =
53 {
54 {
55 .id = 0,
56 .name = "ifxmips_led",
57 },
58 };
59
60 static struct platform_device ifxmips_gpio[] =
61 {
62 {
63 .id = 0,
64 .name = "ifxmips_gpio",
65 },
66 };
67
68 static struct platform_device ifxmips_mii[] =
69 {
70 {
71 .id = 0,
72 .name = "ifxmips_mii0",
73 },
74 };
75
76 static struct physmap_flash_data ifxmips_mtd_data = {
77 .width = 2,
78 };
79
80 static struct resource ifxmips_mtd_resource = {
81 .start = IFXMIPS_FLASH_START,
82 .end = IFXMIPS_FLASH_START + IFXMIPS_FLASH_MAX - 1,
83 .flags = IORESOURCE_MEM,
84 };
85
86 static struct platform_device ifxmips_mtd[] =
87 {
88 {
89 .id = 0,
90 .name = "ifxmips_mtd",
91 .dev = {
92 .platform_data = &ifxmips_mtd_data,
93 },
94 .num_resources = 1,
95 .resource = &ifxmips_mtd_resource,
96 },
97 };
98
99 #ifdef CONFIG_GPIO_DEVICE
100 static struct resource ifxmips_gpio_dev_resources[] = {
101 {
102 .name = "gpio",
103 .flags = 0,
104 .start = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 12),
105 .end = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 12),
106 },
107 };
108
109 static struct platform_device ifxmips_gpio_dev[] = {
110 {
111 .name = "GPIODEV",
112 .id = -1,
113 .num_resources = ARRAY_SIZE(ifxmips_gpio_dev_resources),
114 .resource = ifxmips_gpio_dev_resources,
115 }
116 };
117 #endif
118
119 const char*
120 get_system_type (void)
121 {
122 chiprev = ifxmips_r32(IFXMIPS_MPS_CHIPID);
123 switch(chiprev)
124 {
125 case BOARD_DANUBE_CHIPID:
126 return BOARD_DANUBE;
127
128 case BOARD_TWINPASS_CHIPID:
129 return BOARD_TWINPASS;
130 }
131
132 return BOARD_SYSTEM_TYPE;
133 }
134
135 int __init ifxmips_init_devices(void)
136 {
137 /*
138 * This is where we detect what chip we are running on
139 * Currently we support 3 chips
140 * 1.) Danube
141 * 2.) Twinpass (Danube without dsl phy)
142 */
143
144 int dev = 0;
145
146 /* the following devices are generic for all targets */
147 ifxmips_devs[dev++] = ifxmips_led;
148 ifxmips_devs[dev++] = ifxmips_gpio;
149 ifxmips_devs[dev++] = ifxmips_mii;
150 ifxmips_devs[dev++] = ifxmips_mtd;
151 #ifdef CONFIG_GPIO_DEVICE
152 ifxmips_devs[dev++] = ifxmips_gpio_dev;
153 #endif
154 return platform_add_devices(ifxmips_devs, dev);
155 }
156
157 arch_initcall(ifxmips_init_devices);