Daniel Drake | ec62bd9 | 2006-08-12 17:59:46 +0100 | [diff] [blame^] | 1 | /* zd_rf_al7230b.c: Functions for the AL7230B RF controller |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
| 19 | |
| 20 | #include "zd_rf.h" |
| 21 | #include "zd_usb.h" |
| 22 | #include "zd_chip.h" |
| 23 | |
| 24 | static const u32 chan_rv[][2] = { |
| 25 | RF_CHANNEL( 1) = { 0x09ec00, 0x8cccc8 }, |
| 26 | RF_CHANNEL( 2) = { 0x09ec00, 0x8cccd8 }, |
| 27 | RF_CHANNEL( 3) = { 0x09ec00, 0x8cccc0 }, |
| 28 | RF_CHANNEL( 4) = { 0x09ec00, 0x8cccd0 }, |
| 29 | RF_CHANNEL( 5) = { 0x05ec00, 0x8cccc8 }, |
| 30 | RF_CHANNEL( 6) = { 0x05ec00, 0x8cccd8 }, |
| 31 | RF_CHANNEL( 7) = { 0x05ec00, 0x8cccc0 }, |
| 32 | RF_CHANNEL( 8) = { 0x05ec00, 0x8cccd0 }, |
| 33 | RF_CHANNEL( 9) = { 0x0dec00, 0x8cccc8 }, |
| 34 | RF_CHANNEL(10) = { 0x0dec00, 0x8cccd8 }, |
| 35 | RF_CHANNEL(11) = { 0x0dec00, 0x8cccc0 }, |
| 36 | RF_CHANNEL(12) = { 0x0dec00, 0x8cccd0 }, |
| 37 | RF_CHANNEL(13) = { 0x03ec00, 0x8cccc8 }, |
| 38 | RF_CHANNEL(14) = { 0x03ec00, 0x866660 }, |
| 39 | }; |
| 40 | |
| 41 | static const u32 std_rv[] = { |
| 42 | 0x4ff821, |
| 43 | 0xc5fbfc, |
| 44 | 0x21ebfe, |
| 45 | 0xafd401, /* freq shift 0xaad401 */ |
| 46 | 0x6cf56a, |
| 47 | 0xe04073, |
| 48 | 0x193d76, |
| 49 | 0x9dd844, |
| 50 | 0x500007, |
| 51 | 0xd8c010, |
| 52 | }; |
| 53 | |
| 54 | static int al7230b_init_hw(struct zd_rf *rf) |
| 55 | { |
| 56 | int i, r; |
| 57 | struct zd_chip *chip = zd_rf_to_chip(rf); |
| 58 | |
| 59 | /* All of these writes are identical to AL2230 unless otherwise |
| 60 | * specified */ |
| 61 | static const struct zd_ioreq16 ioreqs_1[] = { |
| 62 | /* This one is 7230-specific, and happens before the rest */ |
| 63 | { CR240, 0x57 }, |
| 64 | { }, |
| 65 | |
| 66 | { CR15, 0x20 }, { CR23, 0x40 }, { CR24, 0x20 }, |
| 67 | { CR26, 0x11 }, { CR28, 0x3e }, { CR29, 0x00 }, |
| 68 | { CR44, 0x33 }, |
| 69 | /* This value is different for 7230 (was: 0x2a) */ |
| 70 | { CR106, 0x22 }, |
| 71 | { CR107, 0x1a }, { CR109, 0x09 }, { CR110, 0x27 }, |
| 72 | { CR111, 0x2b }, { CR112, 0x2b }, { CR119, 0x0a }, |
| 73 | /* This happened further down in AL2230, |
| 74 | * and the value changed (was: 0xe0) */ |
| 75 | { CR122, 0xfc }, |
| 76 | { CR10, 0x89 }, |
| 77 | /* for newest (3rd cut) AL2300 */ |
| 78 | { CR17, 0x28 }, |
| 79 | { CR26, 0x93 }, { CR34, 0x30 }, |
| 80 | /* for newest (3rd cut) AL2300 */ |
| 81 | { CR35, 0x3e }, |
| 82 | { CR41, 0x24 }, { CR44, 0x32 }, |
| 83 | /* for newest (3rd cut) AL2300 */ |
| 84 | { CR46, 0x96 }, |
| 85 | { CR47, 0x1e }, { CR79, 0x58 }, { CR80, 0x30 }, |
| 86 | { CR81, 0x30 }, { CR87, 0x0a }, { CR89, 0x04 }, |
| 87 | { CR92, 0x0a }, { CR99, 0x28 }, |
| 88 | /* This value is different for 7230 (was: 0x00) */ |
| 89 | { CR100, 0x02 }, |
| 90 | { CR101, 0x13 }, { CR102, 0x27 }, |
| 91 | /* This value is different for 7230 (was: 0x24) */ |
| 92 | { CR106, 0x22 }, |
| 93 | /* This value is different for 7230 (was: 0x2a) */ |
| 94 | { CR107, 0x3f }, |
| 95 | { CR109, 0x09 }, |
| 96 | /* This value is different for 7230 (was: 0x13) */ |
| 97 | { CR110, 0x1f }, |
| 98 | { CR111, 0x1f }, { CR112, 0x1f }, { CR113, 0x27 }, |
| 99 | { CR114, 0x27 }, |
| 100 | /* for newest (3rd cut) AL2300 */ |
| 101 | { CR115, 0x24 }, |
| 102 | /* This value is different for 7230 (was: 0x24) */ |
| 103 | { CR116, 0x3f }, |
| 104 | /* This value is different for 7230 (was: 0xf4) */ |
| 105 | { CR117, 0xfa }, |
| 106 | { CR118, 0xfc }, { CR119, 0x10 }, { CR120, 0x4f }, |
| 107 | { CR121, 0x77 }, { CR137, 0x88 }, |
| 108 | /* This one is 7230-specific */ |
| 109 | { CR138, 0xa8 }, |
| 110 | /* This value is different for 7230 (was: 0xff) */ |
| 111 | { CR252, 0x34 }, |
| 112 | /* This value is different for 7230 (was: 0xff) */ |
| 113 | { CR253, 0x34 }, |
| 114 | |
| 115 | /* PLL_OFF */ |
| 116 | { CR251, 0x2f }, |
| 117 | }; |
| 118 | |
| 119 | static const struct zd_ioreq16 ioreqs_2[] = { |
| 120 | /* PLL_ON */ |
| 121 | { CR251, 0x3f }, |
| 122 | { CR128, 0x14 }, { CR129, 0x12 }, { CR130, 0x10 }, |
| 123 | { CR38, 0x38 }, { CR136, 0xdf }, |
| 124 | }; |
| 125 | |
| 126 | r = zd_iowrite16a_locked(chip, ioreqs_1, ARRAY_SIZE(ioreqs_1)); |
| 127 | if (r) |
| 128 | return r; |
| 129 | |
| 130 | r = zd_rfwrite_cr_locked(chip, 0x09ec04); |
| 131 | if (r) |
| 132 | return r; |
| 133 | r = zd_rfwrite_cr_locked(chip, 0x8cccc8); |
| 134 | if (r) |
| 135 | return r; |
| 136 | |
| 137 | for (i = 0; i < ARRAY_SIZE(std_rv); i++) { |
| 138 | r = zd_rfwrite_cr_locked(chip, std_rv[i]); |
| 139 | if (r) |
| 140 | return r; |
| 141 | } |
| 142 | |
| 143 | r = zd_rfwrite_cr_locked(chip, 0x3c9000); |
| 144 | if (r) |
| 145 | return r; |
| 146 | r = zd_rfwrite_cr_locked(chip, 0xbfffff); |
| 147 | if (r) |
| 148 | return r; |
| 149 | r = zd_rfwrite_cr_locked(chip, 0x700000); |
| 150 | if (r) |
| 151 | return r; |
| 152 | r = zd_rfwrite_cr_locked(chip, 0xf15d58); |
| 153 | if (r) |
| 154 | return r; |
| 155 | |
| 156 | r = zd_iowrite16a_locked(chip, ioreqs_2, ARRAY_SIZE(ioreqs_2)); |
| 157 | if (r) |
| 158 | return r; |
| 159 | |
| 160 | r = zd_rfwrite_cr_locked(chip, 0xf15d59); |
| 161 | if (r) |
| 162 | return r; |
| 163 | r = zd_rfwrite_cr_locked(chip, 0xf15d5c); |
| 164 | if (r) |
| 165 | return r; |
| 166 | r = zd_rfwrite_cr_locked(chip, 0xf15d58); |
| 167 | if (r) |
| 168 | return r; |
| 169 | |
| 170 | r = zd_iowrite16_locked(chip, 0x06, CR203); |
| 171 | if (r) |
| 172 | return r; |
| 173 | r = zd_iowrite16_locked(chip, 0x80, CR240); |
| 174 | if (r) |
| 175 | return r; |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static int al7230b_set_channel(struct zd_rf *rf, u8 channel) |
| 181 | { |
| 182 | int i, r; |
| 183 | const u32 *rv = chan_rv[channel-1]; |
| 184 | struct zd_chip *chip = zd_rf_to_chip(rf); |
| 185 | |
| 186 | struct zd_ioreq16 ioreqs_1[] = { |
| 187 | { CR128, 0x14 }, { CR129, 0x12 }, { CR130, 0x10 }, |
| 188 | { CR38, 0x38 }, { CR136, 0xdf }, |
| 189 | }; |
| 190 | |
| 191 | struct zd_ioreq16 ioreqs_2[] = { |
| 192 | /* PLL_ON */ |
| 193 | { CR251, 0x3f }, |
| 194 | { CR203, 0x06 }, { CR240, 0x08 }, |
| 195 | }; |
| 196 | |
| 197 | r = zd_iowrite16_locked(chip, 0x57, CR240); |
| 198 | if (r) |
| 199 | return r; |
| 200 | |
| 201 | /* PLL_OFF */ |
| 202 | r = zd_iowrite16_locked(chip, 0x2f, CR251); |
| 203 | if (r) |
| 204 | return r; |
| 205 | |
| 206 | for (i = 0; i < ARRAY_SIZE(std_rv); i++) { |
| 207 | r = zd_rfwrite_cr_locked(chip, std_rv[i]); |
| 208 | if (r) |
| 209 | return r; |
| 210 | } |
| 211 | |
| 212 | r = zd_rfwrite_cr_locked(chip, 0x3c9000); |
| 213 | if (r) |
| 214 | return r; |
| 215 | r = zd_rfwrite_cr_locked(chip, 0xf15d58); |
| 216 | if (r) |
| 217 | return r; |
| 218 | |
| 219 | r = zd_iowrite16a_locked(chip, ioreqs_1, ARRAY_SIZE(ioreqs_1)); |
| 220 | if (r) |
| 221 | return r; |
| 222 | |
| 223 | for (i = 0; i < 2; i++) { |
| 224 | r = zd_rfwrite_cr_locked(chip, rv[i]); |
| 225 | if (r) |
| 226 | return r; |
| 227 | } |
| 228 | |
| 229 | r = zd_rfwrite_cr_locked(chip, 0x3c9000); |
| 230 | if (r) |
| 231 | return r; |
| 232 | |
| 233 | return zd_iowrite16a_locked(chip, ioreqs_2, ARRAY_SIZE(ioreqs_2)); |
| 234 | } |
| 235 | |
| 236 | static int al7230b_switch_radio_on(struct zd_rf *rf) |
| 237 | { |
| 238 | struct zd_chip *chip = zd_rf_to_chip(rf); |
| 239 | static const struct zd_ioreq16 ioreqs[] = { |
| 240 | { CR11, 0x00 }, |
| 241 | { CR251, 0x3f }, |
| 242 | }; |
| 243 | |
| 244 | return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs)); |
| 245 | } |
| 246 | |
| 247 | static int al7230b_switch_radio_off(struct zd_rf *rf) |
| 248 | { |
| 249 | struct zd_chip *chip = zd_rf_to_chip(rf); |
| 250 | static const struct zd_ioreq16 ioreqs[] = { |
| 251 | { CR11, 0x04 }, |
| 252 | { CR251, 0x2f }, |
| 253 | }; |
| 254 | |
| 255 | return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs)); |
| 256 | } |
| 257 | |
| 258 | int zd_rf_init_al7230b(struct zd_rf *rf) |
| 259 | { |
| 260 | struct zd_chip *chip = zd_rf_to_chip(rf); |
| 261 | |
| 262 | if (chip->is_zd1211b) { |
| 263 | dev_err(zd_chip_dev(chip), "AL7230B is currently not " |
| 264 | "supported for ZD1211B devices\n"); |
| 265 | return -ENODEV; |
| 266 | } |
| 267 | |
| 268 | rf->init_hw = al7230b_init_hw; |
| 269 | rf->set_channel = al7230b_set_channel; |
| 270 | rf->switch_radio_on = al7230b_switch_radio_on; |
| 271 | rf->switch_radio_off = al7230b_switch_radio_off; |
| 272 | rf->patch_6m_band_edge = 1; |
| 273 | return 0; |
| 274 | } |