Subversion Repositories svnkaklik

Rev

Rev 409 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 409 Rev 410
1
/*
1
/*
2
 * Board-specific setup code for the ATNGW100 Network Gateway
2
 * Board-specific setup code for the ATNGW100 Network Gateway
3
 *
3
 *
4
 * Copyright (C) 2005-2006 Atmel Corporation
4
 * Copyright (C) 2005-2006 Atmel Corporation
5
 *
5
 *
6
 * This program is free software; you can redistribute it and/or modify
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License version 2 as
7
 * it under the terms of the GNU General Public License version 2 as
8
 * published by the Free Software Foundation.
8
 * published by the Free Software Foundation.
9
 */
9
 */
10
#include <linux/clk.h>
10
#include <linux/clk.h>
11
#include <linux/etherdevice.h>
11
#include <linux/etherdevice.h>
12
#include <linux/i2c-gpio.h>
12
#include <linux/i2c-gpio.h>
13
#include <linux/init.h>
13
#include <linux/init.h>
14
#include <linux/linkage.h>
14
#include <linux/linkage.h>
15
#include <linux/platform_device.h>
15
#include <linux/platform_device.h>
16
#include <linux/types.h>
16
#include <linux/types.h>
17
#include <linux/leds.h>
17
#include <linux/leds.h>
18
#include <linux/spi/spi.h>
18
#include <linux/spi/spi.h>
19
 
19
 
20
#include <asm/io.h>
20
#include <asm/io.h>
21
#include <asm/setup.h>
21
#include <asm/setup.h>
22
 
22
 
23
#include <asm/arch/at32ap7000.h>
23
#include <asm/arch/at32ap7000.h>
24
#include <asm/arch/board.h>
24
#include <asm/arch/board.h>
25
#include <asm/arch/init.h>
25
#include <asm/arch/init.h>
26
#include <asm/arch/portmux.h>
26
#include <asm/arch/portmux.h>
27
 
27
 
28
/* Initialized by bootloader-specific startup code. */
28
/* Initialized by bootloader-specific startup code. */
29
struct tag *bootloader_tags __initdata;
29
struct tag *bootloader_tags __initdata;
30
 
30
 
31
struct eth_addr {
31
struct eth_addr {
32
	u8 addr[6];
32
	u8 addr[6];
33
};
33
};
34
static struct eth_addr __initdata hw_addr[2];
34
static struct eth_addr __initdata hw_addr[2];
35
static struct eth_platform_data __initdata eth_data[2];
35
static struct eth_platform_data __initdata eth_data[2];
36
 
36
 
37
static struct spi_board_info spi0_board_info[] __initdata = {
37
static struct spi_board_info spi0_board_info[] __initdata = {
38
	{
38
	{
39
		.modalias	= "mtd_dataflash",
39
		.modalias	= "mtd_dataflash",
40
		.max_speed_hz	= 10000000,
40
		.max_speed_hz	= 10000000,
41
		.chip_select	= 0,
41
		.chip_select	= 0,
42
	},
42
	},
43
};
43
};
44
 
44
 
45
static struct mci_platform_data __initdata mci0_data = {
45
static struct mci_platform_data __initdata mci0_data = {
46
	.detect_pin	= GPIO_PIN_PC(25),
46
	.detect_pin	= GPIO_PIN_PC(25),
47
	.wp_pin		= GPIO_PIN_PE(0),
47
	.wp_pin		= GPIO_PIN_PE(0),
48
};
48
};
49
 
49
 
50
/*
50
/*
51
 * The next two functions should go away as the boot loader is
51
 * The next two functions should go away as the boot loader is
52
 * supposed to initialize the macb address registers with a valid
52
 * supposed to initialize the macb address registers with a valid
53
 * ethernet address. But we need to keep it around for a while until
53
 * ethernet address. But we need to keep it around for a while until
54
 * we can be reasonably sure the boot loader does this.
54
 * we can be reasonably sure the boot loader does this.
55
 *
55
 *
56
 * The phy_id is ignored as the driver will probe for it.
56
 * The phy_id is ignored as the driver will probe for it.
57
 */
57
 */
58
static int __init parse_tag_ethernet(struct tag *tag)
58
static int __init parse_tag_ethernet(struct tag *tag)
59
{
59
{
60
	int i;
60
	int i;
61
 
61
 
62
	i = tag->u.ethernet.mac_index;
62
	i = tag->u.ethernet.mac_index;
63
	if (i < ARRAY_SIZE(hw_addr))
63
	if (i < ARRAY_SIZE(hw_addr))
64
		memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
64
		memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
65
		       sizeof(hw_addr[i].addr));
65
		       sizeof(hw_addr[i].addr));
66
 
66
 
67
	return 0;
67
	return 0;
68
}
68
}
69
__tagtable(ATAG_ETHERNET, parse_tag_ethernet);
69
__tagtable(ATAG_ETHERNET, parse_tag_ethernet);
70
 
70
 
71
static void __init set_hw_addr(struct platform_device *pdev)
71
static void __init set_hw_addr(struct platform_device *pdev)
72
{
72
{
73
	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
73
	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
74
	const u8 *addr;
74
	const u8 *addr;
75
	void __iomem *regs;
75
	void __iomem *regs;
76
	struct clk *pclk;
76
	struct clk *pclk;
77
 
77
 
78
	if (!res)
78
	if (!res)
79
		return;
79
		return;
80
	if (pdev->id >= ARRAY_SIZE(hw_addr))
80
	if (pdev->id >= ARRAY_SIZE(hw_addr))
81
		return;
81
		return;
82
 
82
 
83
	addr = hw_addr[pdev->id].addr;
83
	addr = hw_addr[pdev->id].addr;
84
	if (!is_valid_ether_addr(addr))
84
	if (!is_valid_ether_addr(addr))
85
		return;
85
		return;
86
 
86
 
87
	/*
87
	/*
88
	 * Since this is board-specific code, we'll cheat and use the
88
	 * Since this is board-specific code, we'll cheat and use the
89
	 * physical address directly as we happen to know that it's
89
	 * physical address directly as we happen to know that it's
90
	 * the same as the virtual address.
90
	 * the same as the virtual address.
91
	 */
91
	 */
92
	regs = (void __iomem __force *)res->start;
92
	regs = (void __iomem __force *)res->start;
93
	pclk = clk_get(&pdev->dev, "pclk");
93
	pclk = clk_get(&pdev->dev, "pclk");
94
	if (!pclk)
94
	if (!pclk)
95
		return;
95
		return;
96
 
96
 
97
	clk_enable(pclk);
97
	clk_enable(pclk);
98
	__raw_writel((addr[3] << 24) | (addr[2] << 16)
98
	__raw_writel((addr[3] << 24) | (addr[2] << 16)
99
		     | (addr[1] << 8) | addr[0], regs + 0x98);
99
		     | (addr[1] << 8) | addr[0], regs + 0x98);
100
	__raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
100
	__raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
101
	clk_disable(pclk);
101
	clk_disable(pclk);
102
	clk_put(pclk);
102
	clk_put(pclk);
103
}
103
}
104
 
104
 
105
void __init setup_board(void)
105
void __init setup_board(void)
106
{
106
{
107
	at32_map_usart(1, 0);	/* USART 1: /dev/ttyS0, DB9 */
107
	at32_map_usart(1, 0);	/* USART 1: /dev/ttyS0, DB9 */
108
	at32_map_usart(3, 1);	/* USART 3: /dev/ttyS1      */
108
	at32_map_usart(3, 1);	/* USART 3: /dev/ttyS1      */
109
	at32_setup_serial_console(0);
109
	at32_setup_serial_console(0);
110
}
110
}
111
 
111
 
112
static const struct gpio_led ngw_leds[] = {
112
static const struct gpio_led ngw_leds[] = {
113
	{ .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
113
	{ .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
114
		.default_trigger = "heartbeat",
114
		.default_trigger = "heartbeat",
115
	},
115
	},
116
	{ .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
116
	{ .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
117
	{ .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
117
	{ .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
118
};
118
};
119
 
119
 
120
static const struct gpio_led_platform_data ngw_led_data = {
120
static const struct gpio_led_platform_data ngw_led_data = {
121
	.num_leds =	ARRAY_SIZE(ngw_leds),
121
	.num_leds =	ARRAY_SIZE(ngw_leds),
122
	.leds =		(void *) ngw_leds,
122
	.leds =		(void *) ngw_leds,
123
};
123
};
124
 
124
 
125
static struct platform_device ngw_gpio_leds = {
125
static struct platform_device ngw_gpio_leds = {
126
	.name =		"leds-gpio",
126
	.name =		"leds-gpio",
127
	.id =		-1,
127
	.id =		-1,
128
	.dev = {
128
	.dev = {
129
		.platform_data = (void *) &ngw_led_data,
129
		.platform_data = (void *) &ngw_led_data,
130
	}
130
	}
131
};
131
};
132
 
132
 
133
#ifdef CONFIG_BOARD_ATNGW100_I2C_GPIO
133
#ifdef CONFIG_BOARD_ATNGW100_I2C_GPIO
134
static struct i2c_gpio_platform_data i2c_gpio_data = {
134
static struct i2c_gpio_platform_data i2c_gpio_data = {
135
	.sda_pin	= GPIO_PIN_PA(6),
135
	.sda_pin	= GPIO_PIN_PA(6),
136
	.scl_pin	= GPIO_PIN_PA(7),
136
	.scl_pin	= GPIO_PIN_PA(7),
137
};
137
};
138
 
138
 
139
static struct platform_device i2c_gpio_device = {
139
static struct platform_device i2c_gpio_device = {
140
	.name		= "i2c-gpio",
140
	.name		= "i2c-gpio",
141
	.id		= 0,
141
	.id		= 0,
142
	.dev		= {
142
	.dev		= {
143
		.platform_data	= &i2c_gpio_data,
143
		.platform_data	= &i2c_gpio_data,
144
	},
144
	},
145
};
145
};
146
#endif
146
#endif
147
 
147
 
148
static int __init atngw100_init(void)
148
static int __init atngw100_init(void)
149
{
149
{
150
	unsigned	i;
150
	unsigned	i;
151
 
151
 
152
	/*
152
	/*
153
	 * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
153
	 * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
154
	 * reserve any pins for it.
154
	 * reserve any pins for it.
155
	 */
155
	 */
156
 
156
 
157
	at32_add_system_devices();
157
	at32_add_system_devices();
158
 
158
 
159
	at32_add_device_usart(0);
159
	at32_add_device_usart(0);
160
	at32_add_device_usart(1);
160
	at32_add_device_usart(1);
161
 
161
 
162
	set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
162
	set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
163
	set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
163
	set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
164
 
164
 
165
	at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
165
	at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
166
	at32_add_device_mci(0, &mci0_data);
166
	at32_add_device_mci(0, &mci0_data);
167
	at32_add_device_usba(0, NULL);
167
	at32_add_device_usba(0, NULL);
168
 
168
 
169
	for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
169
	for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
170
		at32_select_gpio(ngw_leds[i].gpio,
170
		at32_select_gpio(ngw_leds[i].gpio,
171
				AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
171
				AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
172
	}
172
	}
173
	platform_device_register(&ngw_gpio_leds);
173
	platform_device_register(&ngw_gpio_leds);
174
 
174
 
175
#ifdef CONFIG_BOARD_ATNGW100_I2C_GPIO
175
#ifdef CONFIG_BOARD_ATNGW100_I2C_GPIO
176
	at32_select_gpio(i2c_gpio_data.sda_pin, 0);
176
	at32_select_gpio(i2c_gpio_data.sda_pin, 0);
177
	at32_select_gpio(i2c_gpio_data.scl_pin, 0);
177
	at32_select_gpio(i2c_gpio_data.scl_pin, 0);
178
	platform_device_register(&i2c_gpio_device);
178
	platform_device_register(&i2c_gpio_device);
179
#else
179
#else
180
	at32_add_device_twi(0);
180
	at32_add_device_twi(0);
181
#endif
181
#endif
182
	at32_add_device_ac97c (0);
182
	at32_add_device_ac97c (0);
183
 
183
 
184
	return 0;
184
	return 0;
185
}
185
}
186
postcore_initcall(atngw100_init);
186
postcore_initcall(atngw100_init);