summaryrefslogtreecommitdiffstats
path: root/target/linux/ifxmips/files-2.6.33/arch/mips/ifxmips/ar9/board.c
blob: e4a418b728f0c7b0b1cd4691477a20436b4b2129 (plain)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
/*
 *   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.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 *
 *   Copyright (C) 2007 John Crispin <blogic@openwrt.org>
 */

#include <linux/autoconf.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/mtd/physmap.h>
#include <linux/kernel.h>
#include <linux/reboot.h>
#include <linux/platform_device.h>
#include <linux/leds.h>
#include <linux/etherdevice.h>
#include <linux/reboot.h>
#include <linux/time.h>
#include <linux/io.h>
#include <linux/gpio.h>

#include <asm/bootinfo.h>
#include <asm/irq.h>

#include <ifxmips.h>
#include <ifxmips_irq.h>

#define MAX_BOARD_NAME_LEN		32
#define MAX_IFXMIPS_DEVS		9

#define SYSTEM_DANUBE			"Danube"
#define SYSTEM_DANUBE_CHIPID1	0x00129083
#define SYSTEM_DANUBE_CHIPID2	0x0012B083

#define SYSTEM_TWINPASS			"Twinpass"
#define SYSTEM_TWINPASS_CHIPID	0x0012D083

enum {
	EASY50712,
	EASY4010,
	ARV4519,
	ARV452,
};

extern int ifxmips_pci_external_clock;
extern int ifxmips_pci_req_mask;

static unsigned int chiprev;
static int cmdline_mac;
char board_name[MAX_BOARD_NAME_LEN + 1] = { 0 };

struct ifxmips_board {
	int type;
	char name[32];
	unsigned int system_type;
	struct platform_device **devs;
	struct resource reset_resource;
	struct resource gpiodev_resource;
	struct gpio_led *ifxmips_leds;
	struct gpio_led *gpio_leds;
	int pci_external_clock;
	int pci_req_mask;
	int num_devs;
};

DEFINE_SPINLOCK(ebu_lock);
EXPORT_SYMBOL_GPL(ebu_lock);

extern unsigned char ifxmips_ethaddr[6];
static int ifxmips_brn;

static struct gpio_led_platform_data ifxmips_led_data;

static struct platform_device ifxmips_led = {
	.id = 0,
	.name = "ifxmips_led",
	.dev = {
		.platform_data = (void *) &ifxmips_led_data,
	}
};

static struct platform_device ifxmips_gpio = {
	.id = 0,
	.name = "ifxmips_gpio",
	.num_resources = 1,
};

static struct platform_device ifxmips_mii = {
	.id = 0,
	.name = "ifxmips_mii0",
	.dev = {
		.platform_data = ifxmips_ethaddr,
	}
};

static struct platform_device ifxmips_wdt = {
	.id = 0,
	.name = "ifxmips_wdt",
};

static struct platform_device ifxmips_ebu = {
	.id = 0,
	.name = "ifxmips_ebu",
};

static struct resource ifxmips_mtd_resource = {
	.start  = IFXMIPS_FLASH_START,
	.end    = IFXMIPS_FLASH_START + IFXMIPS_FLASH_MAX - 1,
	.flags  = IORESOURCE_MEM,
};

static struct platform_device ifxmips_mtd = {
	.id = 0,
	.name = "ifxmips_mtd",
	.num_resources  = 1,
	.resource   = &ifxmips_mtd_resource,
};

static struct platform_device ifxmips_gpio_dev = {
	.name     = "GPIODEV",
	.id     = -1,
	.num_resources    =	1,
};

#ifdef CONFIG_LEDS_GPIO
static struct gpio_led arv4519_gpio_leds[] = {
	{ .name = "ifx:green:power", .gpio = 3, .active_low = 1, },
	{ .name = "ifx:red:power", .gpio = 7, .active_low = 1, },
	{ .name = "ifx:green:adsl", .gpio = 4, .active_low = 1, },
	{ .name = "ifx:green:internet", .gpio = 5, .active_low = 1, },
	{ .name = "ifx:red:internet", .gpio = 8, .active_low = 1, },
	{ .name = "ifx:green:wlan", .gpio = 6, .active_low = 1, },
	{ .name = "ifx:green:usbpwr", .gpio = 14, .active_low = 1, },
	{ .name = "ifx:green:usb", .gpio = 19, .active_low = 1, },
};

static struct gpio_led arv452_gpio_leds[] = {
	{ .name = "ifx:blue:power", .gpio = 3, .active_low = 1, },
	{ .name = "ifx:blue:adsl", .gpio = 4, .active_low = 1, },
	{ .name = "ifx:blue:internet", .gpio = 5, .active_low = 1, },
	{ .name = "ifx:red:power", .gpio = 6, .active_low = 1, },
	{ .name = "ifx:yello:wps", .gpio = 7, .active_low = 1, },
	{ .name = "ifx:red:wps", .gpio = 9, .active_low = 1, },
	{ .name = "ifx:blue:voip", .gpio = 32, .active_low = 1, },
	{ .name = "ifx:blue:fxs1", .gpio = 33, .active_low = 1, },
	{ .name = "ifx:blue:fxs2", .gpio = 34, .active_low = 1, },
	{ .name = "ifx:blue:fxo", .gpio = 35, .active_low = 1, },
	{ .name = "ifx:blue:voice", .gpio = 36, .active_low = 1, },
	{ .name = "ifx:blue:usb", .gpio = 37, .active_low = 1, },
	{ .name = "ifx:blue:wlan", .gpio = 38, .active_low = 1, },
	{ .name = "ifx:red:internet", .gpio = 41, .active_low = 1, },
};

static struct gpio_led_platform_data ifxmips_gpio_led_data;

static struct platform_device ifxmips_gpio_leds = {
	.name = "leds-gpio",
	.id = -1,
	.dev = {
		.platform_data = (void *) &ifxmips_gpio_led_data,
	}
};
#endif

static struct resource dwc_usb_res[] = {
	{
		.name = "dwc3884_membase",
		.flags = IORESOURCE_MEM,
		.start = 0x1E101000,
		.end = 0x1E101FFF
	},
	{
		.name = "dwc3884_irq",
		.flags = IORESOURCE_IRQ,
		.start = IFXMIPS_USB_INT,
	}
};

static struct platform_device dwc_usb =
{
	.id = 0,
	.name = "dwc3884-hcd",
	.resource = dwc_usb_res,
	.num_resources = ARRAY_SIZE(dwc_usb_res),
};

struct platform_device *easy50712_devs[] = {
	&ifxmips_led, &ifxmips_gpio, &ifxmips_mii,
	&ifxmips_mtd, &ifxmips_wdt, &ifxmips_gpio_dev, &dwc_usb
};

struct platform_device *easy4010_devs[] = {
	&ifxmips_led, &ifxmips_gpio, &ifxmips_mii,
	&ifxmips_mtd, &ifxmips_wdt, &ifxmips_gpio_dev, &dwc_usb
};

struct platform_device *arv5419_devs[] = {
	&ifxmips_gpio, &ifxmips_mii, &ifxmips_mtd,
	&ifxmips_gpio_dev, &ifxmips_wdt, &dwc_usb,
#ifdef CONFIG_LEDS_GPIO
	&ifxmips_gpio_leds,
#endif
};

struct platform_device *arv452_devs[] = {
	&ifxmips_gpio, &ifxmips_mii, &ifxmips_mtd,
	&ifxmips_gpio_dev, &ifxmips_wdt, &dwc_usb,
	&ifxmips_ebu,
#ifdef CONFIG_LEDS_GPIO
	&ifxmips_gpio_leds,
#endif
};

static struct gpio_led easy50712_leds[] = {
	{ .name = "ifx:green:test0", .gpio = 0,},
	{ .name = "ifx:green:test1", .gpio = 1,},
	{ .name = "ifx:green:test2", .gpio = 2,},
	{ .name = "ifx:green:test3", .gpio = 3,},
};

static struct gpio_led easy4010_leds[] = {
	{ .name = "ifx:green:test0", .gpio = 0,},
	{ .name = "ifx:green:test1", .gpio = 1,},
	{ .name = "ifx:green:test2", .gpio = 2,},
	{ .name = "ifx:green:test3", .gpio = 3,},
};

static struct ifxmips_board boards[] = {
	{
		/* infineon eval kit */
		.type = EASY50712,
		.name = "EASY50712",
		.system_type = SYSTEM_DANUBE_CHIPID1,
		.devs = easy50712_devs,
		.reset_resource = {.name = "reset", .start = 1, .end = 15,},
		.gpiodev_resource = { .name = "gpio",
			.start = (1 << 0) | (1 << 1),
			.end = (1 << 0) | (1 << 1)},
		.ifxmips_leds = easy50712_leds,
	}, {
		/* infineon eval kit */
		.type = EASY4010,
		.name = "EASY4010",
		.system_type = SYSTEM_TWINPASS_CHIPID,
		.devs = easy4010_devs,
		.reset_resource = {.name = "reset", .start = 1, .end = 15},
		.gpiodev_resource = { .name = "gpio",
			.start = (1 << 0) | (1 << 1),
			.end = (1 << 0) | (1 << 1)},
		.ifxmips_leds = easy4010_leds,
	}, {
		/* arcaydian annex-a board used by thompson, airties, ... */
		.type = ARV4519,
		.name = "ARV4519",
		.system_type = SYSTEM_DANUBE_CHIPID2,
		.devs = arv5419_devs,
		.reset_resource = {.name = "reset", .start = 1, .end = 14},
		.pci_external_clock = 1,
#ifdef CONFIG_LEDS_GPIO
		.gpio_leds = arv4519_gpio_leds,
#endif
	}, {
		/* arcaydian annex-b board used by airties, arcor */
		.type = ARV452,
		.name = "ARV452",
		.system_type = SYSTEM_DANUBE_CHIPID2,
		.devs = arv452_devs,
		.reset_resource = {.name = "reset", .start = 1, .end = 14},
		.pci_external_clock = 1,
#ifdef CONFIG_LEDS_GPIO
		.gpio_leds = arv452_gpio_leds,
#endif
	},
};

const char *get_system_type(void)
{
	chiprev = (ifxmips_r32(IFXMIPS_MPS_CHIPID) & 0x0FFFFFFF);

	switch (chiprev) {
	case SYSTEM_DANUBE_CHIPID1:
	case SYSTEM_DANUBE_CHIPID2:
		return SYSTEM_DANUBE;

	case SYSTEM_TWINPASS_CHIPID:
		return SYSTEM_TWINPASS;
	}

	return BOARD_SYSTEM_TYPE;
}

static int __init ifxmips_set_board_type(char *str)
{
	str = strchr(str, '=');
	if (!str)
		goto out;
	str++;
	if (strlen(str) > MAX_BOARD_NAME_LEN)
		goto out;
	strncpy(board_name, str, MAX_BOARD_NAME_LEN);
	printk(KERN_INFO "bootloader told us, that this is a %s board\n",
		board_name);
out:
	return 1;
}
__setup("ifxmips_board", ifxmips_set_board_type);

static int __init ifxmips_set_ethaddr(char *str)
{
#define IS_HEX(x) \
	(((x >= '0' && x <= '9') || (x >= 'a' && x <= 'f') \
		|| (x >= 'A' && x <= 'F')) ? (1) : (0))
	int i;
	str = strchr(str, '=');
	if (!str)
		goto out;
	str++;
	if (strlen(str) != 17)
		goto out;
	for (i = 0; i < 6; i++) {
		if (!IS_HEX(str[3 * i]) || !IS_HEX(str[(3 * i) + 1]))
			goto out;
		if ((i != 5) && (str[(3 * i) + 2] != ':'))
			goto out;
		ifxmips_ethaddr[i] = simple_strtoul(&str[3 * i], NULL, 16);
	}
	if (is_valid_ether_addr(ifxmips_ethaddr))
		cmdline_mac = 1;
out:
	return 1;
}
__setup("ethaddr", ifxmips_set_ethaddr);

int ifxmips_find_brn_block(void)
{
	unsigned char temp[8];
	memcpy_fromio(temp,
		(void *)KSEG1ADDR(IFXMIPS_FLASH_START + 0x800000 - 0x10000), 8);
	if (memcmp(temp, "BRN-BOOT", 8) == 0) {
		if (!cmdline_mac)
			memcpy_fromio(ifxmips_ethaddr,
				(void *)KSEG1ADDR(IFXMIPS_FLASH_START +
					0x800000 - 0x10000 + 0x16), 6);
		if (is_valid_ether_addr(ifxmips_ethaddr))
			cmdline_mac = 1;
		return 1;
	} else {
		return 0;
	}
}

int ifxmips_has_brn_block(void)
{
	return ifxmips_brn;
}
EXPORT_SYMBOL(ifxmips_has_brn_block);

struct ifxmips_board *ifxmips_find_board(void)
{
	int i;
	if (!*board_name)
		return 0;
	for (i = 0; i < ARRAY_SIZE(boards); i++)
		if ((boards[i].system_type == chiprev) &&
		    (!strcmp(boards[i].name, board_name)))
			return &boards[i];
	return 0;
}

int __init ifxmips_init_devices(void)
{
	struct ifxmips_board *board;

	chiprev = (ifxmips_r32(IFXMIPS_MPS_CHIPID) & 0x0FFFFFFF);
	board = ifxmips_find_board();
	ifxmips_brn = ifxmips_find_brn_block();

	if (!cmdline_mac)
		random_ether_addr(ifxmips_ethaddr);

	if (!board) {
		switch (chiprev) {
		case SYSTEM_DANUBE_CHIPID1:
		case SYSTEM_DANUBE_CHIPID2:
		default:
			board = &boards[0];
			break;
		case SYSTEM_TWINPASS_CHIPID:
			board = &boards[1];
			break;
		}
	}

	switch (board->type) {
	case EASY50712:
		board->num_devs = ARRAY_SIZE(easy50712_devs);
		ifxmips_led_data.num_leds = ARRAY_SIZE(easy50712_leds);
		break;
	case EASY4010:
		board->num_devs = ARRAY_SIZE(easy4010_devs);
		ifxmips_led_data.num_leds = ARRAY_SIZE(easy4010_leds);
		break;
	case ARV4519:
		/* set some sane defaults for the gpios */
		gpio_set_value(3, 0);
		gpio_set_value(4, 0);
		gpio_set_value(5, 0);
		gpio_set_value(6, 0);
		gpio_set_value(7, 1);
		gpio_set_value(8, 1);
		gpio_set_value(19, 0);
		board->num_devs = ARRAY_SIZE(arv5419_devs);
#ifdef CONFIG_LEDS_GPIO
		ifxmips_gpio_led_data.num_leds = ARRAY_SIZE(arv4519_gpio_leds);
#endif
		break;
	case ARV452:
		/* set some sane defaults for the gpios */
		board->num_devs = ARRAY_SIZE(arv452_devs);
		ifxmips_w32(0x8001e7ff, IFXMIPS_EBU_BUSCON1);
#ifdef CONFIG_LEDS_GPIO
		ifxmips_gpio_led_data.num_leds = ARRAY_SIZE(arv452_gpio_leds);
#endif
		break;
	}
#ifdef CONFIG_LEDS_GPIO
	ifxmips_gpio_led_data.leds = board->gpio_leds;
#endif
	ifxmips_led_data.leds = board->ifxmips_leds;

	printk(KERN_INFO "%s: adding %d devs\n",
		__func__, board->num_devs);

	ifxmips_gpio.resource = &board->reset_resource;
	ifxmips_gpio_dev.resource = &board->gpiodev_resource;
	if (board->pci_external_clock)
		ifxmips_pci_external_clock = 1;
	if (board->pci_req_mask)
		ifxmips_pci_req_mask = board->pci_req_mask;
	printk(KERN_INFO "using board definition %s\n", board->name);
	return platform_add_devices(board->devs, board->num_devs);
}

arch_initcall(ifxmips_init_devices);