Blame view

arch/mips/ar7/platform.c 15.7 KB
7ca5dc145   Florian Fainelli   MIPS: Add support...
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
  /*
   * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
   * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
   *
   * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   */
  
  #include <linux/init.h>
  #include <linux/types.h>
  #include <linux/module.h>
  #include <linux/delay.h>
  #include <linux/dma-mapping.h>
  #include <linux/platform_device.h>
  #include <linux/mtd/physmap.h>
  #include <linux/serial.h>
  #include <linux/serial_8250.h>
  #include <linux/ioport.h>
  #include <linux/io.h>
7ca5dc145   Florian Fainelli   MIPS: Add support...
31
32
33
34
  #include <linux/vlynq.h>
  #include <linux/leds.h>
  #include <linux/string.h>
  #include <linux/etherdevice.h>
1e2c8d830   Florian Fainelli   ar7: add fixed PH...
35
36
  #include <linux/phy.h>
  #include <linux/phy_fixed.h>
5f3c90988   Florian Fainelli   MIPS: AR7: Implem...
37
  #include <linux/gpio.h>
780019ddf   Florian Fainelli   MIPS: AR7: Implem...
38
  #include <linux/clk.h>
7ca5dc145   Florian Fainelli   MIPS: Add support...
39
40
41
42
43
  
  #include <asm/addrspace.h>
  #include <asm/mach-ar7/ar7.h>
  #include <asm/mach-ar7/gpio.h>
  #include <asm/mach-ar7/prom.h>
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
44
45
46
  /*****************************************************************************
   * VLYNQ Bus
   ****************************************************************************/
7ca5dc145   Florian Fainelli   MIPS: Add support...
47
48
49
50
51
  struct plat_vlynq_data {
  	struct plat_vlynq_ops ops;
  	int gpio_bit;
  	int reset_bit;
  };
7ca5dc145   Florian Fainelli   MIPS: Add support...
52
53
  static int vlynq_on(struct vlynq_device *dev)
  {
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
54
  	int ret;
7ca5dc145   Florian Fainelli   MIPS: Add support...
55
  	struct plat_vlynq_data *pdata = dev->dev.platform_data;
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
56
57
  	ret = gpio_request(pdata->gpio_bit, "vlynq");
  	if (ret)
7ca5dc145   Florian Fainelli   MIPS: Add support...
58
59
60
  		goto out;
  
  	ar7_device_reset(pdata->reset_bit);
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
61
62
  	ret = ar7_gpio_disable(pdata->gpio_bit);
  	if (ret)
7ca5dc145   Florian Fainelli   MIPS: Add support...
63
  		goto out_enabled;
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
64
65
  	ret = ar7_gpio_enable(pdata->gpio_bit);
  	if (ret)
7ca5dc145   Florian Fainelli   MIPS: Add support...
66
  		goto out_enabled;
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
67
68
  	ret = gpio_direction_output(pdata->gpio_bit, 0);
  	if (ret)
7ca5dc145   Florian Fainelli   MIPS: Add support...
69
70
71
72
73
  		goto out_gpio_enabled;
  
  	msleep(50);
  
  	gpio_set_value(pdata->gpio_bit, 1);
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
74

7ca5dc145   Florian Fainelli   MIPS: Add support...
75
76
77
78
79
80
81
82
83
84
  	msleep(50);
  
  	return 0;
  
  out_gpio_enabled:
  	ar7_gpio_disable(pdata->gpio_bit);
  out_enabled:
  	ar7_device_disable(pdata->reset_bit);
  	gpio_free(pdata->gpio_bit);
  out:
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
85
  	return ret;
7ca5dc145   Florian Fainelli   MIPS: Add support...
86
87
88
89
90
  }
  
  static void vlynq_off(struct vlynq_device *dev)
  {
  	struct plat_vlynq_data *pdata = dev->dev.platform_data;
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
91

7ca5dc145   Florian Fainelli   MIPS: Add support...
92
93
94
95
  	ar7_gpio_disable(pdata->gpio_bit);
  	gpio_free(pdata->gpio_bit);
  	ar7_device_disable(pdata->reset_bit);
  }
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
96
  static struct resource vlynq_low_res[] = {
7ca5dc145   Florian Fainelli   MIPS: Add support...
97
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
98
99
100
101
  		.name	= "regs",
  		.flags	= IORESOURCE_MEM,
  		.start	= AR7_REGS_VLYNQ0,
  		.end	= AR7_REGS_VLYNQ0 + 0xff,
7ca5dc145   Florian Fainelli   MIPS: Add support...
102
103
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
104
105
106
107
  		.name	= "irq",
  		.flags	= IORESOURCE_IRQ,
  		.start	= 29,
  		.end	= 29,
7ca5dc145   Florian Fainelli   MIPS: Add support...
108
  	},
7ca5dc145   Florian Fainelli   MIPS: Add support...
109
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
110
111
112
113
  		.name	= "mem",
  		.flags	= IORESOURCE_MEM,
  		.start	= 0x04000000,
  		.end	= 0x04ffffff,
7ca5dc145   Florian Fainelli   MIPS: Add support...
114
115
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
116
117
118
119
  		.name	= "devirq",
  		.flags	= IORESOURCE_IRQ,
  		.start	= 80,
  		.end	= 111,
7ca5dc145   Florian Fainelli   MIPS: Add support...
120
121
  	},
  };
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
122
  static struct resource vlynq_high_res[] = {
7ca5dc145   Florian Fainelli   MIPS: Add support...
123
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
124
125
126
127
  		.name	= "regs",
  		.flags	= IORESOURCE_MEM,
  		.start	= AR7_REGS_VLYNQ1,
  		.end	= AR7_REGS_VLYNQ1 + 0xff,
7ca5dc145   Florian Fainelli   MIPS: Add support...
128
129
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
130
131
132
133
  		.name	= "irq",
  		.flags	= IORESOURCE_IRQ,
  		.start	= 33,
  		.end	= 33,
7ca5dc145   Florian Fainelli   MIPS: Add support...
134
135
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
136
137
138
139
  		.name	= "mem",
  		.flags	= IORESOURCE_MEM,
  		.start	= 0x0c000000,
  		.end	= 0x0cffffff,
7ca5dc145   Florian Fainelli   MIPS: Add support...
140
141
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
142
143
144
145
  		.name	= "devirq",
  		.flags	= IORESOURCE_IRQ,
  		.start	= 112,
  		.end	= 143,
7ca5dc145   Florian Fainelli   MIPS: Add support...
146
147
  	},
  };
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
148
149
150
151
  static struct plat_vlynq_data vlynq_low_data = {
  	.ops = {
  		.on	= vlynq_on,
  		.off	= vlynq_off,
7ca5dc145   Florian Fainelli   MIPS: Add support...
152
  	},
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
153
154
155
156
157
158
159
160
  	.reset_bit	= 20,
  	.gpio_bit	= 18,
  };
  
  static struct plat_vlynq_data vlynq_high_data = {
  	.ops = {
  		.on	= vlynq_on,
  		.off	= vlynq_off,
7ca5dc145   Florian Fainelli   MIPS: Add support...
161
  	},
1e3fb3778   Alexander Clouter   MIPS: AR7: Fix ph...
162
  	.reset_bit	= 16,
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
163
164
165
166
167
168
169
170
  	.gpio_bit	= 19,
  };
  
  static struct platform_device vlynq_low = {
  	.id		= 0,
  	.name		= "vlynq",
  	.dev = {
  		.platform_data	= &vlynq_low_data,
7ca5dc145   Florian Fainelli   MIPS: Add support...
171
  	},
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
172
173
174
175
176
177
178
179
180
  	.resource	= vlynq_low_res,
  	.num_resources	= ARRAY_SIZE(vlynq_low_res),
  };
  
  static struct platform_device vlynq_high = {
  	.id		= 1,
  	.name		= "vlynq",
  	.dev = {
  		.platform_data	= &vlynq_high_data,
7ca5dc145   Florian Fainelli   MIPS: Add support...
181
  	},
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
182
183
  	.resource	= vlynq_high_res,
  	.num_resources	= ARRAY_SIZE(vlynq_high_res),
7ca5dc145   Florian Fainelli   MIPS: Add support...
184
  };
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
  /*****************************************************************************
   * Flash
   ****************************************************************************/
  static struct resource physmap_flash_resource = {
  	.name	= "mem",
  	.flags	= IORESOURCE_MEM,
  	.start	= 0x10000000,
  	.end	= 0x107fffff,
  };
  
  static struct physmap_flash_data physmap_flash_data = {
  	.width	= 2,
  };
  
  static struct platform_device physmap_flash = {
  	.name		= "physmap-flash",
  	.dev = {
  		.platform_data	= &physmap_flash_data,
7ca5dc145   Florian Fainelli   MIPS: Add support...
203
  	},
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
204
205
206
207
208
209
210
211
  	.resource	= &physmap_flash_resource,
  	.num_resources	= 1,
  };
  
  /*****************************************************************************
   * Ethernet
   ****************************************************************************/
  static struct resource cpmac_low_res[] = {
7ca5dc145   Florian Fainelli   MIPS: Add support...
212
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
213
214
215
216
  		.name	= "regs",
  		.flags	= IORESOURCE_MEM,
  		.start	= AR7_REGS_MAC0,
  		.end	= AR7_REGS_MAC0 + 0x7ff,
7ca5dc145   Florian Fainelli   MIPS: Add support...
217
218
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
219
220
221
  		.name	= "irq",
  		.flags	= IORESOURCE_IRQ,
  		.start	= 27,
11454100f   Florian Fainelli   MIPS: AR7: Remove...
222
  		.end	= 27,
7ca5dc145   Florian Fainelli   MIPS: Add support...
223
224
  	},
  };
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
225
226
227
228
229
230
231
232
233
234
235
236
237
  static struct resource cpmac_high_res[] = {
  	{
  		.name	= "regs",
  		.flags	= IORESOURCE_MEM,
  		.start	= AR7_REGS_MAC1,
  		.end	= AR7_REGS_MAC1 + 0x7ff,
  	},
  	{
  		.name	= "irq",
  		.flags	= IORESOURCE_IRQ,
  		.start	= 41,
  		.end	= 41,
  	},
7ca5dc145   Florian Fainelli   MIPS: Add support...
238
  };
1e2c8d830   Florian Fainelli   ar7: add fixed PH...
239
  static struct fixed_phy_status fixed_phy_status __initdata = {
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
240
241
242
  	.link		= 1,
  	.speed		= 100,
  	.duplex		= 1,
1e2c8d830   Florian Fainelli   ar7: add fixed PH...
243
  };
7ca5dc145   Florian Fainelli   MIPS: Add support...
244
  static struct plat_cpmac_data cpmac_low_data = {
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
245
246
247
  	.reset_bit	= 17,
  	.power_bit	= 20,
  	.phy_mask	= 0x80000000,
7ca5dc145   Florian Fainelli   MIPS: Add support...
248
249
250
  };
  
  static struct plat_cpmac_data cpmac_high_data = {
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
251
252
253
  	.reset_bit	= 21,
  	.power_bit	= 22,
  	.phy_mask	= 0x7fffffff,
7ca5dc145   Florian Fainelli   MIPS: Add support...
254
  };
8e84c1480   Florian Fainelli   MIPS: AR7: Use DM...
255
  static u64 cpmac_dma_mask = DMA_BIT_MASK(32);
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
256

7ca5dc145   Florian Fainelli   MIPS: Add support...
257
  static struct platform_device cpmac_low = {
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
258
259
  	.id		= 0,
  	.name		= "cpmac",
7ca5dc145   Florian Fainelli   MIPS: Add support...
260
  	.dev = {
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
261
262
263
  		.dma_mask		= &cpmac_dma_mask,
  		.coherent_dma_mask	= DMA_BIT_MASK(32),
  		.platform_data		= &cpmac_low_data,
7ca5dc145   Florian Fainelli   MIPS: Add support...
264
  	},
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
265
266
  	.resource	= cpmac_low_res,
  	.num_resources	= ARRAY_SIZE(cpmac_low_res),
7ca5dc145   Florian Fainelli   MIPS: Add support...
267
268
269
  };
  
  static struct platform_device cpmac_high = {
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
270
271
  	.id		= 1,
  	.name		= "cpmac",
7ca5dc145   Florian Fainelli   MIPS: Add support...
272
  	.dev = {
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
273
274
275
  		.dma_mask		= &cpmac_dma_mask,
  		.coherent_dma_mask	= DMA_BIT_MASK(32),
  		.platform_data		= &cpmac_high_data,
7ca5dc145   Florian Fainelli   MIPS: Add support...
276
  	},
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
277
278
  	.resource	= cpmac_high_res,
  	.num_resources	= ARRAY_SIZE(cpmac_high_res),
7ca5dc145   Florian Fainelli   MIPS: Add support...
279
  };
d16f7093b   Alexander Clouter   MIPS: AR7: rewrit...
280
  static void __init cpmac_get_mac(int instance, unsigned char *dev_addr)
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
281
  {
d16f7093b   Alexander Clouter   MIPS: AR7: rewrit...
282
  	char name[5], *mac;
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
283

4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
284
285
  	sprintf(name, "mac%c", 'a' + instance);
  	mac = prom_getenv(name);
d16f7093b   Alexander Clouter   MIPS: AR7: rewrit...
286
  	if (!mac && instance) {
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
287
288
289
  		sprintf(name, "mac%c", 'a');
  		mac = prom_getenv(name);
  	}
d16f7093b   Alexander Clouter   MIPS: AR7: rewrit...
290
291
292
293
294
295
296
297
298
299
300
301
302
  
  	if (mac) {
  		if (sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
  					&dev_addr[0], &dev_addr[1],
  					&dev_addr[2], &dev_addr[3],
  					&dev_addr[4], &dev_addr[5]) != 6) {
  			pr_warning("cannot parse mac address, "
  					"using random address
  ");
  			random_ether_addr(dev_addr);
  		}
  	} else
  		random_ether_addr(dev_addr);
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
  }
  
  /*****************************************************************************
   * USB
   ****************************************************************************/
  static struct resource usb_res[] = {
  	{
  		.name	= "regs",
  		.flags	= IORESOURCE_MEM,
  		.start	= AR7_REGS_USB,
  		.end	= AR7_REGS_USB + 0xff,
  	},
  	{
  		.name	= "irq",
  		.flags	= IORESOURCE_IRQ,
  		.start	= 32,
  		.end	= 32,
  	},
  	{
  		.name	= "mem",
  		.flags	= IORESOURCE_MEM,
  		.start	= 0x03400000,
632b629c0   Alexander Clouter   MIPS: AR7: Fix US...
325
  		.end	= 0x03401fff,
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
326
  	},
7ca5dc145   Florian Fainelli   MIPS: Add support...
327
  };
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
328
329
330
331
332
  static struct platform_device ar7_udc = {
  	.name		= "ar7_udc",
  	.resource	= usb_res,
  	.num_resources	= ARRAY_SIZE(usb_res),
  };
7ca5dc145   Florian Fainelli   MIPS: Add support...
333

4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
334
335
336
  /*****************************************************************************
   * LEDs
   ****************************************************************************/
7ca5dc145   Florian Fainelli   MIPS: Add support...
337
338
  static struct gpio_led default_leds[] = {
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
339
340
341
  		.name			= "status",
  		.gpio			= 8,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
342
343
  	},
  };
238dd317f   Florian Fainelli   MIPS: AR7: Add su...
344
345
346
347
  static struct gpio_led titan_leds[] = {
  	{ .name = "status", .gpio = 8, .active_low = 1, },
  	{ .name = "wifi", .gpio = 13, .active_low = 1, },
  };
7ca5dc145   Florian Fainelli   MIPS: Add support...
348
349
  static struct gpio_led dsl502t_leds[] = {
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
350
351
352
  		.name			= "status",
  		.gpio			= 9,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
353
354
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
355
356
357
  		.name			= "ethernet",
  		.gpio			= 7,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
358
359
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
360
361
362
  		.name			= "usb",
  		.gpio			= 12,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
363
364
365
366
367
  	},
  };
  
  static struct gpio_led dg834g_leds[] = {
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
368
369
370
  		.name			= "ppp",
  		.gpio			= 6,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
371
372
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
373
374
375
  		.name			= "status",
  		.gpio			= 7,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
376
377
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
378
379
380
  		.name			= "adsl",
  		.gpio			= 8,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
381
382
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
383
384
385
  		.name			= "wifi",
  		.gpio			= 12,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
386
387
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
388
389
390
391
  		.name			= "power",
  		.gpio			= 14,
  		.active_low		= 1,
  		.default_trigger	= "default-on",
7ca5dc145   Florian Fainelli   MIPS: Add support...
392
393
394
395
396
  	},
  };
  
  static struct gpio_led fb_sl_leds[] = {
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
397
398
  		.name			= "1",
  		.gpio			= 7,
7ca5dc145   Florian Fainelli   MIPS: Add support...
399
400
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
401
402
403
  		.name			= "2",
  		.gpio			= 13,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
404
405
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
406
407
408
  		.name			= "3",
  		.gpio			= 10,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
409
410
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
411
412
413
  		.name			= "4",
  		.gpio			= 12,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
414
415
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
416
417
418
  		.name			= "5",
  		.gpio			= 9,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
419
420
421
422
423
  	},
  };
  
  static struct gpio_led fb_fon_leds[] = {
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
424
425
  		.name			= "1",
  		.gpio			= 8,
7ca5dc145   Florian Fainelli   MIPS: Add support...
426
427
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
428
429
430
  		.name			= "2",
  		.gpio			= 3,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
431
432
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
433
434
  		.name			= "3",
  		.gpio			= 5,
7ca5dc145   Florian Fainelli   MIPS: Add support...
435
436
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
437
438
439
  		.name			= "4",
  		.gpio			= 4,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
440
441
  	},
  	{
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
442
443
444
  		.name			= "5",
  		.gpio			= 11,
  		.active_low		= 1,
7ca5dc145   Florian Fainelli   MIPS: Add support...
445
446
  	},
  };
f77138e8d   Florian Fainelli   MIPS: AR7: add LE...
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
  static struct gpio_led gt701_leds[] = {
  	{
  		.name			= "inet:green",
  		.gpio			= 13,
  		.active_low		= 1,
  	},
  	{
  		.name			= "usb",
  		.gpio			= 12,
  		.active_low		= 1,
  	},
  	{
  		.name			= "inet:red",
  		.gpio			= 9,
  		.active_low		= 1,
  	},
  	{
  		.name			= "power:red",
  		.gpio			= 7,
  		.active_low		= 1,
  	},
  	{
  		.name			= "power:green",
  		.gpio			= 8,
  		.active_low		= 1,
  		.default_trigger	= "default-on",
  	},
          {
                  .name                   = "ethernet",
                  .gpio                   = 10,
                  .active_low             = 1,
          },
  };
7ca5dc145   Florian Fainelli   MIPS: Add support...
480
481
482
483
  static struct gpio_led_platform_data ar7_led_data;
  
  static struct platform_device ar7_gpio_leds = {
  	.name = "leds-gpio",
7ca5dc145   Florian Fainelli   MIPS: Add support...
484
485
486
487
  	.dev = {
  		.platform_data = &ar7_led_data,
  	}
  };
7ca5dc145   Florian Fainelli   MIPS: Add support...
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
  static void __init detect_leds(void)
  {
  	char *prid, *usb_prod;
  
  	/* Default LEDs	*/
  	ar7_led_data.num_leds = ARRAY_SIZE(default_leds);
  	ar7_led_data.leds = default_leds;
  
  	/* FIXME: the whole thing is unreliable */
  	prid = prom_getenv("ProductID");
  	usb_prod = prom_getenv("usb_prod");
  
  	/* If we can't get the product id from PROM, use the default LEDs */
  	if (!prid)
  		return;
  
  	if (strstr(prid, "Fritz_Box_FON")) {
  		ar7_led_data.num_leds = ARRAY_SIZE(fb_fon_leds);
  		ar7_led_data.leds = fb_fon_leds;
  	} else if (strstr(prid, "Fritz_Box_")) {
  		ar7_led_data.num_leds = ARRAY_SIZE(fb_sl_leds);
  		ar7_led_data.leds = fb_sl_leds;
  	} else if ((!strcmp(prid, "AR7RD") || !strcmp(prid, "AR7DB"))
  		&& usb_prod != NULL && strstr(usb_prod, "DSL-502T")) {
  		ar7_led_data.num_leds = ARRAY_SIZE(dsl502t_leds);
  		ar7_led_data.leds = dsl502t_leds;
  	} else if (strstr(prid, "DG834")) {
  		ar7_led_data.num_leds = ARRAY_SIZE(dg834g_leds);
  		ar7_led_data.leds = dg834g_leds;
238dd317f   Florian Fainelli   MIPS: AR7: Add su...
517
518
519
  	} else if (strstr(prid, "CYWM") || strstr(prid, "CYWL")) {
  		ar7_led_data.num_leds = ARRAY_SIZE(titan_leds);
  		ar7_led_data.leds = titan_leds;
f77138e8d   Florian Fainelli   MIPS: AR7: add LE...
520
521
522
  	} else if (strstr(prid, "GT701")) {
  		ar7_led_data.num_leds = ARRAY_SIZE(gt701_leds);
  		ar7_led_data.leds = gt701_leds;
7ca5dc145   Florian Fainelli   MIPS: Add support...
523
524
  	}
  }
4d1da8c29   Alexander Clouter   MIPS: AR7: Whites...
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
  /*****************************************************************************
   * Watchdog
   ****************************************************************************/
  static struct resource ar7_wdt_res = {
  	.name		= "regs",
  	.flags		= IORESOURCE_MEM,
  	.start		= -1,	/* Filled at runtime */
  	.end		= -1,	/* Filled at runtime */
  };
  
  static struct platform_device ar7_wdt = {
  	.name		= "ar7_wdt",
  	.resource	= &ar7_wdt_res,
  	.num_resources	= 1,
  };
  
  /*****************************************************************************
   * Init
   ****************************************************************************/
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
544
  static int __init ar7_register_uarts(void)
7ca5dc145   Florian Fainelli   MIPS: Add support...
545
  {
50ca96191   Florian Fainelli   MIPS: AR7: Fix bu...
546
  #ifdef CONFIG_SERIAL_8250
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
547
  	static struct uart_port uart_port __initdata;
780019ddf   Florian Fainelli   MIPS: AR7: Implem...
548
  	struct clk *bus_clk;
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
549
  	int res;
7ca5dc145   Florian Fainelli   MIPS: Add support...
550

7084338eb   Alexander Clouter   MIPS: AR7: Make a...
551
  	memset(&uart_port, 0, sizeof(struct uart_port));
7ca5dc145   Florian Fainelli   MIPS: Add support...
552

780019ddf   Florian Fainelli   MIPS: AR7: Implem...
553
554
  	bus_clk = clk_get(NULL, "bus");
  	if (IS_ERR(bus_clk))
ab75dc02c   Ralf Baechle   MIPS: Fix up inco...
555
  		panic("unable to get bus clk");
780019ddf   Florian Fainelli   MIPS: AR7: Implem...
556

154615d55   Florian Fainelli   MIPS: AR7: Use co...
557
  	uart_port.type		= PORT_AR7;
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
558
559
560
561
562
563
564
565
566
567
  	uart_port.uartclk	= clk_get_rate(bus_clk) / 2;
  	uart_port.iotype	= UPIO_MEM32;
  	uart_port.regshift	= 2;
  
  	uart_port.line		= 0;
  	uart_port.irq		= AR7_IRQ_UART0;
  	uart_port.mapbase	= AR7_REGS_UART0;
  	uart_port.membase	= ioremap(uart_port.mapbase, 256);
  
  	res = early_serial_setup(&uart_port);
7ca5dc145   Florian Fainelli   MIPS: Add support...
568
569
  	if (res)
  		return res;
7ca5dc145   Florian Fainelli   MIPS: Add support...
570
571
  	/* Only TNETD73xx have a second serial port */
  	if (ar7_has_second_uart()) {
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
572
573
574
575
576
577
  		uart_port.line		= 1;
  		uart_port.irq		= AR7_IRQ_UART1;
  		uart_port.mapbase	= UR8_REGS_UART1;
  		uart_port.membase	= ioremap(uart_port.mapbase, 256);
  
  		res = early_serial_setup(&uart_port);
7ca5dc145   Florian Fainelli   MIPS: Add support...
578
579
580
  		if (res)
  			return res;
  	}
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
581
582
583
584
  #endif
  
  	return 0;
  }
238dd317f   Florian Fainelli   MIPS: AR7: Add su...
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
  static void __init titan_fixup_devices(void)
  {
  	/* Set vlynq0 data */
  	vlynq_low_data.reset_bit = 15;
  	vlynq_low_data.gpio_bit = 14;
  
  	/* Set vlynq1 data */
  	vlynq_high_data.reset_bit = 16;
  	vlynq_high_data.gpio_bit = 7;
  
  	/* Set vlynq0 resources */
  	vlynq_low_res[0].start = TITAN_REGS_VLYNQ0;
  	vlynq_low_res[0].end = TITAN_REGS_VLYNQ0 + 0xff;
  	vlynq_low_res[1].start = 33;
  	vlynq_low_res[1].end = 33;
  	vlynq_low_res[2].start = 0x0c000000;
  	vlynq_low_res[2].end = 0x0fffffff;
  	vlynq_low_res[3].start = 80;
  	vlynq_low_res[3].end = 111;
  
  	/* Set vlynq1 resources */
  	vlynq_high_res[0].start = TITAN_REGS_VLYNQ1;
  	vlynq_high_res[0].end = TITAN_REGS_VLYNQ1 + 0xff;
  	vlynq_high_res[1].start = 34;
  	vlynq_high_res[1].end = 34;
  	vlynq_high_res[2].start = 0x40000000;
  	vlynq_high_res[2].end = 0x43ffffff;
  	vlynq_high_res[3].start = 112;
  	vlynq_high_res[3].end = 143;
  
  	/* Set cpmac0 data */
  	cpmac_low_data.phy_mask = 0x40000000;
  
  	/* Set cpmac1 data */
  	cpmac_high_data.phy_mask = 0x80000000;
  
  	/* Set cpmac0 resources */
  	cpmac_low_res[0].start = TITAN_REGS_MAC0;
  	cpmac_low_res[0].end = TITAN_REGS_MAC0 + 0x7ff;
  
  	/* Set cpmac1 resources */
  	cpmac_high_res[0].start = TITAN_REGS_MAC1;
  	cpmac_high_res[0].end = TITAN_REGS_MAC1 + 0x7ff;
  }
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
629
630
631
632
  static int __init ar7_register_devices(void)
  {
  	void __iomem *bootcr;
  	u32 val;
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
633
634
635
636
637
638
  	int res;
  
  	res = ar7_register_uarts();
  	if (res)
  		pr_err("unable to setup uart(s): %d
  ", res);
7ca5dc145   Florian Fainelli   MIPS: Add support...
639
640
  	res = platform_device_register(&physmap_flash);
  	if (res)
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
641
642
  		pr_warning("unable to register physmap-flash: %d
  ", res);
7ca5dc145   Florian Fainelli   MIPS: Add support...
643

238dd317f   Florian Fainelli   MIPS: AR7: Add su...
644
645
  	if (ar7_is_titan())
  		titan_fixup_devices();
7ca5dc145   Florian Fainelli   MIPS: Add support...
646
647
648
  	ar7_device_disable(vlynq_low_data.reset_bit);
  	res = platform_device_register(&vlynq_low);
  	if (res)
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
649
650
  		pr_warning("unable to register vlynq-low: %d
  ", res);
7ca5dc145   Florian Fainelli   MIPS: Add support...
651
652
653
654
655
  
  	if (ar7_has_high_vlynq()) {
  		ar7_device_disable(vlynq_high_data.reset_bit);
  		res = platform_device_register(&vlynq_high);
  		if (res)
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
656
657
  			pr_warning("unable to register vlynq-high: %d
  ", res);
7ca5dc145   Florian Fainelli   MIPS: Add support...
658
659
660
  	}
  
  	if (ar7_has_high_cpmac()) {
727c0075c   Alexander Clouter   MIPS: AR7: Fix ph...
661
  		res = fixed_phy_add(PHY_POLL, cpmac_high.id, &fixed_phy_status);
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
662
663
664
665
666
667
668
669
670
671
672
  		if (!res) {
  			cpmac_get_mac(1, cpmac_high_data.dev_addr);
  
  			res = platform_device_register(&cpmac_high);
  			if (res)
  				pr_warning("unable to register cpmac-high: %d
  ", res);
  		} else
  			pr_warning("unable to add cpmac-high phy: %d
  ", res);
  	} else
7ca5dc145   Florian Fainelli   MIPS: Add support...
673
  		cpmac_low_data.phy_mask = 0xffffffff;
7ca5dc145   Florian Fainelli   MIPS: Add support...
674

1e2c8d830   Florian Fainelli   ar7: add fixed PH...
675
  	res = fixed_phy_add(PHY_POLL, cpmac_low.id, &fixed_phy_status);
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
676
677
678
679
680
681
682
683
684
  	if (!res) {
  		cpmac_get_mac(0, cpmac_low_data.dev_addr);
  		res = platform_device_register(&cpmac_low);
  		if (res)
  			pr_warning("unable to register cpmac-low: %d
  ", res);
  	} else
  		pr_warning("unable to add cpmac-low phy: %d
  ", res);
7ca5dc145   Florian Fainelli   MIPS: Add support...
685
686
687
688
  
  	detect_leds();
  	res = platform_device_register(&ar7_gpio_leds);
  	if (res)
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
689
690
  		pr_warning("unable to register leds: %d
  ", res);
7ca5dc145   Florian Fainelli   MIPS: Add support...
691
692
  
  	res = platform_device_register(&ar7_udc);
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
693
694
695
  	if (res)
  		pr_warning("unable to register usb slave: %d
  ", res);
72838a170   Florian Fainelli   MIPS: AR7: regist...
696
697
  
  	/* Register watchdog only if enabled in hardware */
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
698
699
700
701
  	bootcr = ioremap_nocache(AR7_REGS_DCL, 4);
  	val = readl(bootcr);
  	iounmap(bootcr);
  	if (val & AR7_WDT_HW_ENA) {
9c1b013a3   Florian Fainelli   MIPS: AR7: use ar...
702
  		if (ar7_has_high_vlynq())
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
703
  			ar7_wdt_res.start = UR8_REGS_WDT;
9c1b013a3   Florian Fainelli   MIPS: AR7: use ar...
704
705
  		else
  			ar7_wdt_res.start = AR7_REGS_WDT;
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
706
707
  
  		ar7_wdt_res.end = ar7_wdt_res.start + 0x20;
72838a170   Florian Fainelli   MIPS: AR7: regist...
708
  		res = platform_device_register(&ar7_wdt);
7084338eb   Alexander Clouter   MIPS: AR7: Make a...
709
710
711
712
  		if (res)
  			pr_warning("unable to register watchdog: %d
  ", res);
  	}
d47fbb599   Florian Fainelli   MIPS: AR7: Make b...
713

7084338eb   Alexander Clouter   MIPS: AR7: Make a...
714
  	return 0;
7ca5dc145   Florian Fainelli   MIPS: Add support...
715
  }
142a2ceea   Florian Fainelli   MIPS: AR7: preven...
716
  device_initcall(ar7_register_devices);