ar71xx: move arch specific files to files-2.6.39
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files-2.6.39 / arch / mips / ar71xx / dev-ar9xxx-wmac.c
1 /*
2 * Atheros AR9XXX SoCs built-in WMAC device support
3 *
4 * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
5 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
6 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7 *
8 * Parts of this file are based on Atheros 2.6.15/2.6.31 BSP
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
13 */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
18 #include <linux/etherdevice.h>
19 #include <linux/platform_device.h>
20 #include <linux/ath9k_platform.h>
21
22 #include <asm/mach-ar71xx/ar71xx.h>
23
24 #include "dev-ar9xxx-wmac.h"
25
26 #define MHZ_25 (25 * 1000 * 1000)
27
28 static struct ath9k_platform_data ar9xxx_wmac_data = {
29 .led_pin = -1,
30 };
31 static char ar9xxx_wmac_mac[6];
32
33 static struct resource ar9xxx_wmac_resources[] = {
34 {
35 /* .start and .end fields are filled dynamically */
36 .flags = IORESOURCE_MEM,
37 }, {
38 .start = AR71XX_CPU_IRQ_IP2,
39 .end = AR71XX_CPU_IRQ_IP2,
40 .flags = IORESOURCE_IRQ,
41 },
42 };
43
44 static struct platform_device ar9xxx_wmac_device = {
45 .name = "ath9k",
46 .id = -1,
47 .resource = ar9xxx_wmac_resources,
48 .num_resources = ARRAY_SIZE(ar9xxx_wmac_resources),
49 .dev = {
50 .platform_data = &ar9xxx_wmac_data,
51 },
52 };
53
54 static void ar913x_wmac_init(void)
55 {
56 ar71xx_device_stop(RESET_MODULE_AMBA2WMAC);
57 mdelay(10);
58
59 ar71xx_device_start(RESET_MODULE_AMBA2WMAC);
60 mdelay(10);
61
62 ar9xxx_wmac_resources[0].start = AR91XX_WMAC_BASE;
63 ar9xxx_wmac_resources[0].end = AR91XX_WMAC_BASE + AR91XX_WMAC_SIZE - 1;
64 }
65
66 static int ar933x_r1_get_wmac_revision(void)
67 {
68 return ar71xx_soc_rev;
69 }
70
71 static int ar933x_wmac_reset(void)
72 {
73 unsigned retries = 0;
74
75 ar71xx_device_stop(AR933X_RESET_WMAC);
76 ar71xx_device_start(AR933X_RESET_WMAC);
77
78 while (1) {
79 u32 bootstrap;
80
81 bootstrap = ar71xx_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
82 if ((bootstrap & AR933X_BOOTSTRAP_EEPBUSY) == 0)
83 return 0;
84
85 if (retries > 20)
86 break;
87
88 udelay(10000);
89 retries++;
90 }
91
92 pr_err("ar93xx: WMAC reset timed out");
93 return -ETIMEDOUT;
94 }
95
96 static void ar933x_wmac_init(void)
97 {
98 ar9xxx_wmac_device.name = "ar933x_wmac";
99 ar9xxx_wmac_resources[0].start = AR933X_WMAC_BASE;
100 ar9xxx_wmac_resources[0].end = AR933X_WMAC_BASE + AR933X_WMAC_SIZE - 1;
101 if (ar71xx_ref_freq == MHZ_25)
102 ar9xxx_wmac_data.is_clk_25mhz = true;
103
104 if (ar71xx_soc_rev == 1)
105 ar9xxx_wmac_data.get_mac_revision = ar933x_r1_get_wmac_revision;
106
107 ar9xxx_wmac_data.external_reset = ar933x_wmac_reset;
108
109 ar933x_wmac_reset();
110 }
111
112 static void ar934x_wmac_init(void)
113 {
114 ar9xxx_wmac_device.name = "ar934x_wmac";
115 ar9xxx_wmac_resources[0].start = AR934X_WMAC_BASE;
116 ar9xxx_wmac_resources[0].end = AR934X_WMAC_BASE + AR934X_WMAC_SIZE - 1;
117 ar9xxx_wmac_resources[1].start = AR934X_IP2_IRQ_WMAC;
118 ar9xxx_wmac_resources[1].start = AR934X_IP2_IRQ_WMAC;
119 if (ar71xx_ref_freq == MHZ_25)
120 ar9xxx_wmac_data.is_clk_25mhz = true;
121 }
122
123 void __init ar9xxx_add_device_wmac(u8 *cal_data, u8 *mac_addr)
124 {
125 switch (ar71xx_soc) {
126 case AR71XX_SOC_AR9130:
127 case AR71XX_SOC_AR9132:
128 ar913x_wmac_init();
129 break;
130
131 case AR71XX_SOC_AR9330:
132 case AR71XX_SOC_AR9331:
133 ar933x_wmac_init();
134 break;
135
136 case AR71XX_SOC_AR9341:
137 case AR71XX_SOC_AR9342:
138 case AR71XX_SOC_AR9344:
139 ar934x_wmac_init();
140 break;
141
142 default:
143 BUG();
144 }
145
146 if (cal_data)
147 memcpy(ar9xxx_wmac_data.eeprom_data, cal_data,
148 sizeof(ar9xxx_wmac_data.eeprom_data));
149
150 if (mac_addr) {
151 memcpy(ar9xxx_wmac_mac, mac_addr, sizeof(ar9xxx_wmac_mac));
152 ar9xxx_wmac_data.macaddr = ar9xxx_wmac_mac;
153 }
154
155 platform_device_register(&ar9xxx_wmac_device);
156 }