source: src/router/services/sysinit/devices/wireless.c @ 18257

Last change on this file since 18257 was 18257, checked in by BrainSlayer, 17 months ago

save memory if these devices arent used. so just do not load the drivers if they arent needed

File size: 6.8 KB
Line 
1/*
2 * wireless.c
3 *
4 * Copyright (C) 2009 Sebastian Gottschall <gottschall@dd-wrt.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 *
20 * $Id:
21 *
22 * detects atheros wireless adapters and loads the drivers
23 */
24
25// extern int getath9kdevicecount(void);
26extern void delete_ath9k_devices(char *physical_iface);
27
28static void setWirelessLed(int phynum, int ledpin)
29{
30#ifdef HAVE_MADWIFI_MIMO
31        int triggergpio = ledpin;
32#endif
33#ifdef HAVE_ATH9K
34        char trigger[32];
35        char sysname[32];
36        sprintf(trigger, "phy%dtpt", phynum);
37        if (ledpin < 32) {
38                sprintf(sysname, "generic_%d", ledpin);
39        } else {
40#ifdef HAVE_MADWIFI_MIMO
41                if (ledpin < 48)
42                        triggergpio = ledpin - 32;
43                else
44                        triggergpio = ledpin - 48;
45#endif
46                sprintf(sysname, "wireless_generic_%d", ledpin - 32);
47        }
48        sysprintf("echo %s > /sys/devices/platform/leds-gpio/leds/%s/trigger",
49                  trigger, sysname);
50#else
51#ifdef HAVE_MADWIFI_MIMO
52        if (ledpin >= 32) {
53                if (ledpin < 48)
54                        triggergpio = ledpin - 32;
55                else
56                        triggergpio = ledpin - 48;
57        }
58#endif
59#endif
60#ifdef HAVE_MADWIFI_MIMO
61        sysprintf("echo %d >/proc/sys/dev/wifi%d/ledpin", triggergpio, phynum);
62        sysprintf("echo 1 >/proc/sys/dev/wifi%d/softled", phynum);
63#endif
64}
65
66#define setWirelessLedGeneric(a,b) setWirelessLed(a,b)
67#define setWirelessLedPhy0(b) setWirelessLed(0,b+32)
68#define setWirelessLedPhy1(b) setWirelessLed(1,b+48)
69
70static char *has_device(char *dev)
71{
72        char path[64];
73        static char devstr[32];
74        sprintf(path, "/sys/bus/pci/devices/0000:00:%s/device", dev);
75        FILE *fp = fopen(path, "rb");
76        if (fp) {
77                fscanf(fp, "%s", devstr);
78                fclose(fp);
79                return devstr;
80        }
81
82        return "";
83}
84
85#define AR5416_DEVID_PCI        0x0023
86#define AR5416_DEVID_PCIE       0x0024
87#define AR9160_DEVID_PCI        0x0027
88#define AR9280_DEVID_PCI        0x0029
89#define AR9280_DEVID_PCIE       0x002a
90#define AR9285_DEVID_PCIE       0x002b
91#define AR2427_DEVID_PCIE       0x002c
92#define AR9287_DEVID_PCI        0x002d
93#define AR9287_DEVID_PCIE       0x002e
94#define AR9300_DEVID_PCIE       0x0030
95#define AR9300_DEVID_AR9340     0x0031
96#define AR9300_DEVID_AR9485_PCIE 0x0032
97#define AR9300_DEVID_AR9580     0x0033
98#define AR9300_DEVID_AR9462     0x0034
99#define AR9300_DEVID_AR9330     0x0035
100
101#define AR5416_AR9100_DEVID     0x000b
102
103static void detect_wireless_devices(void)
104{
105        int loadath9k = 1;
106        int loadlegacy = 1;
107#ifdef HAVE_RT61
108        if (!strcmp(has_device("0e.00"), "0x3592"))
109                nvram_set("rtchip", "3062");
110        else
111                nvram_set("rtchip", "2860");
112#endif
113#ifdef HAVE_XSCALE
114        loadath9k = 0;
115        loadlegacy = 0;
116        char path[32];
117        int i = 0;
118        for (i = 0; i < 5; i++) {
119                sprintf(path, "0%d.00", i);
120                if (!strcmp(has_device(path), "0x0023"))
121                        loadath9k = 1;
122                if (!strcmp(has_device(path), "0x0024"))
123                        loadath9k = 1;
124                if (!strcmp(has_device(path), "0x0027"))
125                        loadath9k = 1;
126                if (!strcmp(has_device(path), "0x0029"))
127                        loadath9k = 1;
128                if (!strcmp(has_device(path), "0x002a"))
129                        loadath9k = 1;
130                if (!strcmp(has_device(path), "0x002b"))
131                        loadath9k = 1;
132                if (!strcmp(has_device(path), "0x002c"))
133                        loadath9k = 1;
134                if (!strcmp(has_device(path), "0x002d"))
135                        loadath9k = 1;
136                if (!strcmp(has_device(path), "0x002e"))
137                        loadath9k = 1;
138                if (!strcmp(has_device(path), "0x0030"))
139                        loadath9k = 1;
140                if (!strcmp(has_device(path), "0x0031"))
141                        loadath9k = 1;
142                if (!strcmp(has_device(path), "0x0032"))
143                        loadath9k = 1;
144                if (!strcmp(has_device(path), "0x0034"))
145                        loadath9k = 1;
146                if (!strcmp(has_device(path), "0x0035"))
147                        loadath9k = 1;
148                if (!strcmp(has_device(path), "0x000b"))
149                        loadath9k = 1;
150                if (!strcmp(has_device(path), "0x001b"))
151                        loadlegacy = 1;
152                if (!strcmp(has_device(path), "0x0013"))
153                        loadlegacy = 1;
154                if (!strcmp(has_device(path), "0x0207"))
155                        loadlegacy = 1;
156                if (!strcmp(has_device(path), "0x0007"))
157                        loadlegacy = 1;
158                if (!strcmp(has_device(path), "0xff16"))
159                        loadlegacy = 1;
160                if (!strcmp(has_device(path), "0x0012"))
161                        loadlegacy = 1;
162                if (!strcmp(has_device(path), "0x1014"))
163                        loadlegacy = 1;
164                if (!strcmp(has_device(path), "0x101a"))
165                        loadlegacy = 1;
166                if (!strcmp(has_device(path), "0x0015"))
167                        loadlegacy = 1;
168                if (!strcmp(has_device(path), "0x0016"))
169                        loadlegacy = 1;
170                if (!strcmp(has_device(path), "0x0017"))
171                        loadlegacy = 1;
172                if (!strcmp(has_device(path), "0x0018"))
173                        loadlegacy = 1;
174                if (!strcmp(has_device(path), "0x0019"))
175                        loadlegacy = 1;
176                if (!strcmp(has_device(path), "0x001a"))
177                        loadlegacy = 1;
178                if (!strcmp(has_device(path), "0x001b"))
179                        loadlegacy = 1;
180                if (!strcmp(has_device(path), "0x018a"))
181                        loadlegacy = 1;
182                if (!strcmp(has_device(path), "0x001c"))
183                        loadlegacy = 1;
184                if (!strcmp(has_device(path), "0x001d"))
185                        loadlegacy = 1;
186                if (!strcmp(has_device(path), "0x9013"))
187                        loadlegacy = 1;
188                if (!strcmp(has_device(path), "0xff1a"))
189                        loadlegacy = 1;
190        }
191#endif
192#ifndef HAVE_NOWIFI
193        nvram_default_get("rate_control", "minstrel");
194#ifdef HAVE_MADWIFI
195        if (loadlegacy) {
196                fprintf(stderr, "load ATH 802.11 a/b/g Driver\n");
197                insmod("ath_hal");
198                if (nvram_get("rate_control") != NULL) {
199                        char rate[64];
200
201                        sprintf(rate, "ratectl=%s",
202                                nvram_safe_get("rate_control"));
203                        eval("insmod", "ath_pci", rate);
204                        eval("insmod", "ath_ahb", rate);
205                } else {
206                        insmod("ath_pci");
207                        insmod("ath_ahb");
208                }
209        }
210#ifdef HAVE_ATH9K
211#ifndef HAVE_MADWIFI_MIMO
212        if (1)
213#else
214        if (nvram_match("mimo_driver", "ath9k"))
215#endif
216        {
217                if (loadath9k) {
218                        fprintf(stderr, "load ATH9K 802.11n Driver\n");
219                        // some are just for future use and not (yet) there
220                        insmod("/lib/ath9k/compat.ko");
221                        insmod("/lib/ath9k/compat_firmware_class.ko");
222                        insmod("/lib/ath9k/cfg80211.ko");
223                        insmod("/lib/ath9k/mac80211.ko");
224                        insmod("/lib/ath9k/ath.ko");
225                        insmod("/lib/ath9k/ath9k_hw.ko");
226                        insmod("/lib/ath9k/ath9k_common.ko");
227#ifdef HAVE_WZRG450
228                        system("/sbin/insmod /lib/ath9k/ath9k.ko blink=1");
229#else
230                        insmod("/lib/ath9k/ath9k.ko");
231#endif
232                        delete_ath9k_devices(NULL);
233                }
234        } else {
235#endif
236#ifdef HAVE_MADWIFI_MIMO
237                if (loadath9k) {
238                        fprintf(stderr, "load ATH 802.11n Driver\n");
239                        insmod("/lib/80211n/ath_mimo_hal.ko");
240                        if (nvram_get("rate_control") != NULL) {
241                                char rate[64];
242
243                                sprintf(rate, "ratectl=%s",
244                                        nvram_safe_get("rate_control"));
245                                insmod("/lib/80211n/ath_mimo_pci.ko");
246                                insmod("/lib/80211n/ath_mimo_ahb.ko");
247                        } else {
248                                insmod("/lib/80211n/ath_mimo_pci.ko");
249                                insmod("/lib/80211n/ath_mimo_ahb.ko");
250                        }
251                }
252#endif
253#ifdef HAVE_ATH9K
254        }
255#endif
256#endif
257#endif
258}
Note: See TracBrowser for help on using the repository browser.