1/* zd_rf_rfmd.c: Functions for the RFMD 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 24static const u32 rf2959_table[][2] = { 25 RF_CHANNEL( 1) = { 0x181979, 0x1e6666 }, 26 RF_CHANNEL( 2) = { 0x181989, 0x1e6666 }, 27 RF_CHANNEL( 3) = { 0x181999, 0x1e6666 }, 28 RF_CHANNEL( 4) = { 0x1819a9, 0x1e6666 }, 29 RF_CHANNEL( 5) = { 0x1819b9, 0x1e6666 }, 30 RF_CHANNEL( 6) = { 0x1819c9, 0x1e6666 }, 31 RF_CHANNEL( 7) = { 0x1819d9, 0x1e6666 }, 32 RF_CHANNEL( 8) = { 0x1819e9, 0x1e6666 }, 33 RF_CHANNEL( 9) = { 0x1819f9, 0x1e6666 }, 34 RF_CHANNEL(10) = { 0x181a09, 0x1e6666 }, 35 RF_CHANNEL(11) = { 0x181a19, 0x1e6666 }, 36 RF_CHANNEL(12) = { 0x181a29, 0x1e6666 }, 37 RF_CHANNEL(13) = { 0x181a39, 0x1e6666 }, 38 RF_CHANNEL(14) = { 0x181a60, 0x1c0000 }, 39}; 40 41 42static int rf2959_init_hw(struct zd_rf *rf) 43{ 44 int r; 45 struct zd_chip *chip = zd_rf_to_chip(rf); 46 47 static const struct zd_ioreq16 ioreqs[] = { 48 { CR2, 0x1E }, { CR9, 0x20 }, { CR10, 0x89 }, 49 { CR11, 0x00 }, { CR15, 0xD0 }, { CR17, 0x68 }, 50 { CR19, 0x4a }, { CR20, 0x0c }, { CR21, 0x0E }, 51 { CR23, 0x48 }, 52 /* normal size for cca threshold */ 53 { CR24, 0x14 }, 54 /* { CR24, 0x20 }, */ 55 { CR26, 0x90 }, { CR27, 0x30 }, { CR29, 0x20 }, 56 { CR31, 0xb2 }, { CR32, 0x43 }, { CR33, 0x28 }, 57 { CR38, 0x30 }, { CR34, 0x0f }, { CR35, 0xF0 }, 58 { CR41, 0x2a }, { CR46, 0x7F }, { CR47, 0x1E }, 59 { CR51, 0xc5 }, { CR52, 0xc5 }, { CR53, 0xc5 }, 60 { CR79, 0x58 }, { CR80, 0x30 }, { CR81, 0x30 }, 61 { CR82, 0x00 }, { CR83, 0x24 }, { CR84, 0x04 }, 62 { CR85, 0x00 }, { CR86, 0x10 }, { CR87, 0x2A }, 63 { CR88, 0x10 }, { CR89, 0x24 }, { CR90, 0x18 }, 64 /* { CR91, 0x18 }, */ 65 /* should solve continous CTS frame problems */ 66 { CR91, 0x00 }, 67 { CR92, 0x0a }, { CR93, 0x00 }, { CR94, 0x01 }, 68 { CR95, 0x00 }, { CR96, 0x40 }, { CR97, 0x37 }, 69 { CR98, 0x05 }, { CR99, 0x28 }, { CR100, 0x00 }, 70 { CR101, 0x13 }, { CR102, 0x27 }, { CR103, 0x27 }, 71 { CR104, 0x18 }, { CR105, 0x12 }, 72 /* normal size */ 73 { CR106, 0x1a }, 74 /* { CR106, 0x22 }, */ 75 { CR107, 0x24 }, { CR108, 0x0a }, { CR109, 0x13 }, 76 { CR110, 0x2F }, { CR111, 0x27 }, { CR112, 0x27 }, 77 { CR113, 0x27 }, { CR114, 0x27 }, { CR115, 0x40 }, 78 { CR116, 0x40 }, { CR117, 0xF0 }, { CR118, 0xF0 }, 79 { CR119, 0x16 }, 80 /* no TX continuation */ 81 { CR122, 0x00 }, 82 /* { CR122, 0xff }, */ 83 { CR127, 0x03 }, { CR131, 0x08 }, { CR138, 0x28 }, 84 { CR148, 0x44 }, { CR150, 0x10 }, { CR169, 0xBB }, 85 { CR170, 0xBB }, 86 }; 87 88 static const u32 rv[] = { 89 0x000007, /* REG0(CFG1) */ 90 0x07dd43, /* REG1(IFPLL1) */ 91 0x080959, /* REG2(IFPLL2) */ 92 0x0e6666, 93 0x116a57, /* REG4 */ 94 0x17dd43, /* REG5 */ 95 0x1819f9, /* REG6 */ 96 0x1e6666, 97 0x214554, 98 0x25e7fa, 99 0x27fffa, 100 /* The Zydas driver somehow forgets to set this value. It's 101 * only set for Japan. We are using internal power control 102 * for now. 103 */ 104 0x294128, /* internal power */ 105 /* 0x28252c, */ /* External control TX power */ 106 /* CR31_CCK, CR51_6-36M, CR52_48M, CR53_54M */ 107 0x2c0000, 108 0x300000, 109 0x340000, /* REG13(0xD) */ 110 0x381e0f, /* REG14(0xE) */ 111 /* Bogus, RF2959's data sheet doesn't know register 27, which is 112 * actually referenced here. The commented 0x11 is 17. 113 */ 114 0x6c180f, /* REG27(0x11) */ 115 }; 116 117 r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs)); 118 if (r) 119 return r; 120 121 return zd_rfwritev_locked(chip, rv, ARRAY_SIZE(rv), RF_RV_BITS); 122} 123 124static int rf2959_set_channel(struct zd_rf *rf, u8 channel) 125{ 126 int i, r; 127 const u32 *rv = rf2959_table[channel-1]; 128 struct zd_chip *chip = zd_rf_to_chip(rf); 129 130 for (i = 0; i < 2; i++) { 131 r = zd_rfwrite_locked(chip, rv[i], RF_RV_BITS); 132 if (r) 133 return r; 134 } 135 return 0; 136} 137 138static int rf2959_switch_radio_on(struct zd_rf *rf) 139{ 140 static const struct zd_ioreq16 ioreqs[] = { 141 { CR10, 0x89 }, 142 { CR11, 0x00 }, 143 }; 144 struct zd_chip *chip = zd_rf_to_chip(rf); 145 146 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs)); 147} 148 149static int rf2959_switch_radio_off(struct zd_rf *rf) 150{ 151 static const struct zd_ioreq16 ioreqs[] = { 152 { CR10, 0x15 }, 153 { CR11, 0x81 }, 154 }; 155 struct zd_chip *chip = zd_rf_to_chip(rf); 156 157 return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs)); 158} 159 160int zd_rf_init_rf2959(struct zd_rf *rf) 161{ 162 struct zd_chip *chip = zd_rf_to_chip(rf); 163 164 if (chip->is_zd1211b) { 165 dev_err(zd_chip_dev(chip), 166 "RF2959 is currently not supported for ZD1211B" 167 " devices\n"); 168 return -ENODEV; 169 } 170 rf->init_hw = rf2959_init_hw; 171 rf->set_channel = rf2959_set_channel; 172 rf->switch_radio_on = rf2959_switch_radio_on; 173 rf->switch_radio_off = rf2959_switch_radio_off; 174 return 0; 175} 176