John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | Broadcom BCM43xx wireless driver |
| 4 | |
| 5 | Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>, |
| 6 | Stefano Brivio <st3@riseup.net> |
| 7 | Michael Buesch <mbuesch@freenet.de> |
| 8 | Danny van Dyk <kugelfang@gentoo.org> |
| 9 | Andreas Jaggi <andreas.jaggi@waterwave.ch> |
| 10 | |
| 11 | Some parts of the code in this file are derived from the ipw2200 |
| 12 | driver Copyright(c) 2003 - 2004 Intel Corporation. |
| 13 | |
| 14 | This program is free software; you can redistribute it and/or modify |
| 15 | it under the terms of the GNU General Public License as published by |
| 16 | the Free Software Foundation; either version 2 of the License, or |
| 17 | (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, |
| 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | GNU General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program; see the file COPYING. If not, write to |
| 26 | the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, |
| 27 | Boston, MA 02110-1301, USA. |
| 28 | |
| 29 | */ |
| 30 | |
| 31 | #ifndef BCM43xx_MAIN_H_ |
| 32 | #define BCM43xx_MAIN_H_ |
| 33 | |
| 34 | #include "bcm43xx.h" |
| 35 | |
| 36 | #ifdef CONFIG_BCM947XX |
| 37 | #define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0) |
| 38 | |
| 39 | static inline void e_aton(char *str, char *dest) |
| 40 | { |
| 41 | int i = 0; |
| 42 | u16 *d = (u16 *) dest; |
| 43 | |
| 44 | for (;;) { |
| 45 | dest[i++] = (char) simple_strtoul(str, NULL, 16); |
| 46 | str += 2; |
| 47 | if (!*str++ || i == 6) |
| 48 | break; |
| 49 | } |
| 50 | for (i = 0; i < 3; i++) |
| 51 | d[i] = cpu_to_be16(d[i]); |
| 52 | } |
| 53 | #endif |
| 54 | |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 55 | #define P4D_BYT3S(magic, nr_bytes) u8 __p4dding##magic[nr_bytes] |
| 56 | #define P4D_BYTES(line, nr_bytes) P4D_BYT3S(line, nr_bytes) |
| 57 | /* Magic helper macro to pad structures. Ignore those above. It's magic. */ |
| 58 | #define PAD_BYTES(nr_bytes) P4D_BYTES( __LINE__ , (nr_bytes)) |
| 59 | |
| 60 | |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 61 | /* Lightweight function to convert a frequency (in Mhz) to a channel number. */ |
| 62 | static inline |
Michael Buesch | 10d8dd8 | 2006-02-19 22:08:48 +0100 | [diff] [blame] | 63 | u8 bcm43xx_freq_to_channel_a(int freq) |
| 64 | { |
| 65 | return ((freq - 5000) / 5); |
| 66 | } |
| 67 | static inline |
| 68 | u8 bcm43xx_freq_to_channel_bg(int freq) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 69 | { |
| 70 | u8 channel; |
| 71 | |
Michael Buesch | 10d8dd8 | 2006-02-19 22:08:48 +0100 | [diff] [blame] | 72 | if (freq == 2484) |
| 73 | channel = 14; |
| 74 | else |
| 75 | channel = (freq - 2407) / 5; |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 76 | |
| 77 | return channel; |
| 78 | } |
Michael Buesch | 10d8dd8 | 2006-02-19 22:08:48 +0100 | [diff] [blame] | 79 | static inline |
| 80 | u8 bcm43xx_freq_to_channel(struct bcm43xx_private *bcm, |
| 81 | int freq) |
| 82 | { |
Michael Buesch | e9357c0 | 2006-03-13 19:27:34 +0100 | [diff] [blame] | 83 | if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) |
Michael Buesch | 10d8dd8 | 2006-02-19 22:08:48 +0100 | [diff] [blame] | 84 | return bcm43xx_freq_to_channel_a(freq); |
| 85 | return bcm43xx_freq_to_channel_bg(freq); |
| 86 | } |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 87 | |
| 88 | /* Lightweight function to convert a channel number to a frequency (in Mhz). */ |
| 89 | static inline |
Michael Buesch | 10d8dd8 | 2006-02-19 22:08:48 +0100 | [diff] [blame] | 90 | int bcm43xx_channel_to_freq_a(u8 channel) |
| 91 | { |
| 92 | return (5000 + (5 * channel)); |
| 93 | } |
| 94 | static inline |
| 95 | int bcm43xx_channel_to_freq_bg(u8 channel) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 96 | { |
| 97 | int freq; |
| 98 | |
Michael Buesch | 10d8dd8 | 2006-02-19 22:08:48 +0100 | [diff] [blame] | 99 | if (channel == 14) |
| 100 | freq = 2484; |
| 101 | else |
| 102 | freq = 2407 + (5 * channel); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 103 | |
| 104 | return freq; |
| 105 | } |
Michael Buesch | 10d8dd8 | 2006-02-19 22:08:48 +0100 | [diff] [blame] | 106 | static inline |
| 107 | int bcm43xx_channel_to_freq(struct bcm43xx_private *bcm, |
| 108 | u8 channel) |
| 109 | { |
Michael Buesch | e9357c0 | 2006-03-13 19:27:34 +0100 | [diff] [blame] | 110 | if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) |
Michael Buesch | 10d8dd8 | 2006-02-19 22:08:48 +0100 | [diff] [blame] | 111 | return bcm43xx_channel_to_freq_a(channel); |
| 112 | return bcm43xx_channel_to_freq_bg(channel); |
| 113 | } |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 114 | |
| 115 | /* Lightweight function to check if a channel number is valid. |
| 116 | * Note that this does _NOT_ check for geographical restrictions! |
| 117 | */ |
| 118 | static inline |
Michael Buesch | 10d8dd8 | 2006-02-19 22:08:48 +0100 | [diff] [blame] | 119 | int bcm43xx_is_valid_channel_a(u8 channel) |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 120 | { |
Michael Buesch | 869aaab | 2006-05-05 17:23:51 +0200 | [diff] [blame] | 121 | return (channel >= IEEE80211_52GHZ_MIN_CHANNEL |
| 122 | && channel <= IEEE80211_52GHZ_MAX_CHANNEL); |
Michael Buesch | 10d8dd8 | 2006-02-19 22:08:48 +0100 | [diff] [blame] | 123 | } |
| 124 | static inline |
| 125 | int bcm43xx_is_valid_channel_bg(u8 channel) |
| 126 | { |
Michael Buesch | 869aaab | 2006-05-05 17:23:51 +0200 | [diff] [blame] | 127 | return (channel >= IEEE80211_24GHZ_MIN_CHANNEL |
| 128 | && channel <= IEEE80211_24GHZ_MAX_CHANNEL); |
Michael Buesch | 10d8dd8 | 2006-02-19 22:08:48 +0100 | [diff] [blame] | 129 | } |
| 130 | static inline |
| 131 | int bcm43xx_is_valid_channel(struct bcm43xx_private *bcm, |
| 132 | u8 channel) |
| 133 | { |
Michael Buesch | e9357c0 | 2006-03-13 19:27:34 +0100 | [diff] [blame] | 134 | if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) |
Michael Buesch | 10d8dd8 | 2006-02-19 22:08:48 +0100 | [diff] [blame] | 135 | return bcm43xx_is_valid_channel_a(channel); |
| 136 | return bcm43xx_is_valid_channel_bg(channel); |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf); |
| 140 | void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf); |
| 141 | |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 142 | void bcm43xx_set_iwmode(struct bcm43xx_private *bcm, |
| 143 | int iw_mode); |
| 144 | |
| 145 | u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm, |
| 146 | u16 routing, u16 offset); |
| 147 | u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm, |
| 148 | u16 routing, u16 offset); |
| 149 | void bcm43xx_shm_write32(struct bcm43xx_private *bcm, |
| 150 | u16 routing, u16 offset, |
| 151 | u32 value); |
| 152 | void bcm43xx_shm_write16(struct bcm43xx_private *bcm, |
| 153 | u16 routing, u16 offset, |
| 154 | u16 value); |
| 155 | |
| 156 | void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm); |
| 157 | |
| 158 | int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core); |
| 159 | |
| 160 | void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy); |
| 161 | |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 162 | void bcm43xx_mac_suspend(struct bcm43xx_private *bcm); |
| 163 | void bcm43xx_mac_enable(struct bcm43xx_private *bcm); |
| 164 | |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 165 | void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason); |
| 166 | |
Michael Buesch | ea0922b | 2006-02-19 14:09:20 +0100 | [diff] [blame] | 167 | int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom); |
| 168 | int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom); |
| 169 | |
John W. Linville | f222313 | 2006-01-23 16:59:58 -0500 | [diff] [blame] | 170 | #endif /* BCM43xx_MAIN_H_ */ |