summaryrefslogtreecommitdiffstats
path: root/target/linux/adm8668/files/arch/mips/adm8668/platform.c
blob: dc0fd91a338228a18918762cbd2989028698ebf7 (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
/*
 * Infineon/ADMTek 8668 (WildPass) platform devices support
 *
 * Copyright (C) 2010 Scott Nicholas <neutronscott@scottn.us>
 * Copyright (C) 2012 Florian Fainelli <florian@openwrt.org>
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/platform_data/tulip.h>
#include <linux/mtd/physmap.h>
#include <linux/mtd/partitions.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/ioport.h>
#include <linux/amba/bus.h>
#include <linux/amba/serial.h>

#include <asm/reboot.h>
#include <asm/time.h>
#include <asm/addrspace.h>
#include <asm/bootinfo.h>
#include <asm/io.h>
#include <adm8668.h>

#define ADM8868_UBOOT_ENV		0x20000
#define ADM8868_UBOOT_WAN_MAC		0x5ac
#define ADM8868_UBOOT_LAN_MAC		0x404

static void adm8668_uart_set_mctrl(struct amba_device *dev,
					void __iomem *base,
					unsigned int mcrtl)
{
}

static struct amba_pl010_data adm8668_uart0_data = {
	.set_mctrl = adm8668_uart_set_mctrl,
};

static struct amba_device adm8668_uart0_device = {
	.dev = {
		.init_name	= "apb:uart0",
		.platform_data	= &adm8668_uart0_data,
	},
	.res = {
		.start		= ADM8668_UART0_BASE,
		.end		= ADM8668_UART0_BASE + 0xF,
		.flags		= IORESOURCE_MEM,
	},
	.irq = {
		INT_LVL_UART0,
		-1
	},
	.periphid = 0x0041010,
};

static struct resource eth0_resources[] = {
	{
		.start		= ADM8668_LAN_BASE,
		.end		= ADM8668_LAN_BASE + 256,
		.flags		= IORESOURCE_MEM,
	},
	{
		.start		= INT_LVL_LAN,
		.flags		= IORESOURCE_IRQ,
	},
};

static struct tulip_platform_data eth0_pdata = {
	.chip_id	= ADM8668,
};

static struct platform_device adm8668_eth0_device = {
	.name		= "tulip",
	.id		= 0,
	.resource	= eth0_resources,
	.num_resources	= ARRAY_SIZE(eth0_resources),
	.dev.platform_data = &eth0_pdata,
};

static struct resource eth1_resources[] = {
	{
		.start		= ADM8668_WAN_BASE,
		.end		= ADM8668_WAN_BASE + 256,
		.flags		= IORESOURCE_MEM,
	},
	{
		.start		= INT_LVL_WAN,
		.flags		= IORESOURCE_IRQ,
	},
};

static struct tulip_platform_data eth1_pdata = {
	.chip_id	= ADM8668,
};

static struct platform_device adm8668_eth1_device = {
	.name		= "tulip",
	.id		= 1,
	.resource	= eth1_resources,
	.num_resources	= ARRAY_SIZE(eth1_resources),
	.dev.platform_data = &eth1_pdata,
};

static const char *nor_probe_types[] = { "adm8668part", NULL };

static struct physmap_flash_data nor_flash_data = {
	.width			= 2,
	.part_probe_types	= nor_probe_types,
};

static struct resource nor_resources[] = {
	{
		.start	= ADM8668_SMEM1_BASE,
		.end	= ADM8668_SMEM1_BASE + 0x800000 - 1,
		.flags	= IORESOURCE_MEM,
	},
};

static struct platform_device adm8668_nor_device = {
	.name		= "physmap-flash",
	.id		= -1,
	.resource	= nor_resources,
	.num_resources	= ARRAY_SIZE(nor_resources),
	.dev.platform_data = &nor_flash_data,
};

static struct platform_device *adm8668_devs[] = {
	&adm8668_eth0_device,
	&adm8668_eth1_device,
	&adm8668_nor_device,
};

static void adm8668_fetch_mac(int unit)
{
	u8 *mac;
	u32 offset;
	struct tulip_platform_data *pdata;

	switch (unit) {
	case -1:
	case 0:
		offset = ADM8868_UBOOT_LAN_MAC;
		pdata = &eth0_pdata;
		break;
	case 1:
		offset = ADM8868_UBOOT_WAN_MAC;
		pdata = &eth1_pdata;
		break;
	default:
		pr_err("unsupported ethernet unit: %d\n", unit);
		return;
	}

	mac = (u8 *)(KSEG1ADDR(ADM8668_SMEM1_BASE) + ADM8868_UBOOT_ENV + offset);

	memcpy(pdata->mac, mac, sizeof(pdata->mac));
}


int __devinit adm8668_devs_register(void)
{
	int ret;

	ret = amba_device_register(&adm8668_uart0_device, &iomem_resource);
	if (ret)
		panic("failed to register AMBA UART");

	adm8668_fetch_mac(0);
	adm8668_fetch_mac(1);

	return platform_add_devices(adm8668_devs, ARRAY_SIZE(adm8668_devs));
}
arch_initcall(adm8668_devs_register);