[adm8668] use the tulip platform driver
[openwrt/svn-archive/archive.git] / target / linux / adm8668 / files / arch / mips / adm8668 / platform.c
1 /*
2 * Infineon/ADMTek 8668 (WildPass) platform devices support
3 *
4 * Copyright (C) 2010 Scott Nicholas <neutronscott@scottn.us>
5 * Copyright (C) 2012 Florian Fainelli <florian@openwrt.org>
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/platform_device.h>
15 #include <linux/platform_data/tulip.h>
16 #include <linux/mtd/physmap.h>
17 #include <linux/mtd/partitions.h>
18 #include <linux/pci.h>
19 #include <linux/slab.h>
20 #include <linux/ioport.h>
21 #include <linux/amba/bus.h>
22 #include <linux/amba/serial.h>
23
24 #include <asm/reboot.h>
25 #include <asm/time.h>
26 #include <asm/addrspace.h>
27 #include <asm/bootinfo.h>
28 #include <asm/io.h>
29 #include <adm8668.h>
30
31 #define ADM8868_UBOOT_ENV 0x20000
32 #define ADM8868_UBOOT_WAN_MAC 0x5ac
33 #define ADM8868_UBOOT_LAN_MAC 0x404
34
35 static void adm8668_uart_set_mctrl(struct amba_device *dev,
36 void __iomem *base,
37 unsigned int mcrtl)
38 {
39 }
40
41 static struct amba_pl010_data adm8668_uart0_data = {
42 .set_mctrl = adm8668_uart_set_mctrl,
43 };
44
45 static struct amba_device adm8668_uart0_device = {
46 .dev = {
47 .init_name = "apb:uart0",
48 .platform_data = &adm8668_uart0_data,
49 },
50 .res = {
51 .start = ADM8668_UART0_BASE,
52 .end = ADM8668_UART0_BASE + 0xF,
53 .flags = IORESOURCE_MEM,
54 },
55 .irq = {
56 INT_LVL_UART0,
57 -1
58 },
59 .periphid = 0x0041010,
60 };
61
62 static struct resource eth0_resources[] = {
63 {
64 .start = ADM8668_LAN_BASE,
65 .end = ADM8668_LAN_BASE + 256,
66 .flags = IORESOURCE_MEM,
67 },
68 {
69 .start = INT_LVL_LAN,
70 .flags = IORESOURCE_IRQ,
71 },
72 };
73
74 static struct tulip_platform_data eth0_pdata = {
75 .chip_id = ADM8668,
76 };
77
78 static struct platform_device adm8668_eth0_device = {
79 .name = "tulip",
80 .id = 0,
81 .resource = eth0_resources,
82 .num_resources = ARRAY_SIZE(eth0_resources),
83 .dev.platform_data = &eth0_pdata,
84 };
85
86 static struct resource eth1_resources[] = {
87 {
88 .start = ADM8668_WAN_BASE,
89 .end = ADM8668_WAN_BASE + 256,
90 .flags = IORESOURCE_MEM,
91 },
92 {
93 .start = INT_LVL_WAN,
94 .flags = IORESOURCE_IRQ,
95 },
96 };
97
98 static struct tulip_platform_data eth1_pdata = {
99 .chip_id = ADM8668,
100 };
101
102 static struct platform_device adm8668_eth1_device = {
103 .name = "tulip",
104 .id = 1,
105 .resource = eth1_resources,
106 .num_resources = ARRAY_SIZE(eth1_resources),
107 .dev.platform_data = &eth1_pdata,
108 };
109
110 static const char *nor_probe_types[] = { "adm8668part", NULL };
111
112 static struct physmap_flash_data nor_flash_data = {
113 .width = 2,
114 .part_probe_types = nor_probe_types,
115 };
116
117 static struct resource nor_resources[] = {
118 {
119 .start = ADM8668_SMEM1_BASE,
120 .end = ADM8668_SMEM1_BASE + 0x800000 - 1,
121 .flags = IORESOURCE_MEM,
122 },
123 };
124
125 static struct platform_device adm8668_nor_device = {
126 .name = "physmap-flash",
127 .id = -1,
128 .resource = nor_resources,
129 .num_resources = ARRAY_SIZE(nor_resources),
130 .dev.platform_data = &nor_flash_data,
131 };
132
133 static struct platform_device *adm8668_devs[] = {
134 &adm8668_eth0_device,
135 &adm8668_eth1_device,
136 &adm8668_nor_device,
137 };
138
139 static void adm8668_fetch_mac(int unit)
140 {
141 u8 *mac;
142 u32 offset;
143 struct tulip_platform_data *pdata;
144
145 switch (unit) {
146 case -1:
147 case 0:
148 offset = ADM8868_UBOOT_LAN_MAC;
149 pdata = &eth0_pdata;
150 break;
151 case 1:
152 offset = ADM8868_UBOOT_WAN_MAC;
153 pdata = &eth1_pdata;
154 break;
155 default:
156 pr_err("unsupported ethernet unit: %d\n", unit);
157 return;
158 }
159
160 mac = (u8 *)(KSEG1ADDR(ADM8668_SMEM1_BASE) + ADM8868_UBOOT_ENV + offset);
161
162 memcpy(pdata->mac, mac, sizeof(pdata->mac));
163 }
164
165
166 int __devinit adm8668_devs_register(void)
167 {
168 int ret;
169
170 ret = amba_device_register(&adm8668_uart0_device, &iomem_resource);
171 if (ret)
172 panic("failed to register AMBA UART");
173
174 adm8668_fetch_mac(0);
175 adm8668_fetch_mac(1);
176
177 return platform_add_devices(adm8668_devs, ARRAY_SIZE(adm8668_devs));
178 }
179 arch_initcall(adm8668_devs_register);