1 /* Copyright (C) 2009 - 2010 Ivo van Doorn <IvDoorn@gmail.com> 2 * Copyright (C) 2009 Alban Browaeys <prahal@yahoo.com> 3 * Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org> 4 * Copyright (C) 2009 Luis Correia <luis.f.correia@gmail.com> 5 * Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de> 6 * Copyright (C) 2009 Mark Asselstine <asselsm@gmail.com> 7 * Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com> 8 * Copyright (C) 2009 Bart Zolnierkiewicz <bzolnier@gmail.com> 9 * <http://rt2x00.serialmonkey.com> 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, see <http://www.gnu.org/licenses/>. 23 */ 24 25 /* Module: rt2800soc 26 * Abstract: rt2800 WiSoC specific routines. 27 */ 28 29 #include <linux/etherdevice.h> 30 #include <linux/init.h> 31 #include <linux/kernel.h> 32 #include <linux/module.h> 33 #include <linux/platform_device.h> 34 35 #include "rt2x00.h" 36 #include "rt2x00mmio.h" 37 #include "rt2x00soc.h" 38 #include "rt2800.h" 39 #include "rt2800lib.h" 40 #include "rt2800mmio.h" 41 42 /* Allow hardware encryption to be disabled. */ 43 static bool modparam_nohwcrypt; 44 module_param_named(nohwcrypt, modparam_nohwcrypt, bool, 0444); 45 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption."); 46 47 static bool rt2800soc_hwcrypt_disabled(struct rt2x00_dev *rt2x00dev) 48 { 49 return modparam_nohwcrypt; 50 } 51 52 static void rt2800soc_disable_radio(struct rt2x00_dev *rt2x00dev) 53 { 54 u32 reg; 55 56 rt2800_disable_radio(rt2x00dev); 57 rt2x00mmio_register_write(rt2x00dev, PWR_PIN_CFG, 0); 58 59 reg = 0; 60 if (rt2x00_rt(rt2x00dev, RT3883)) 61 rt2x00_set_field32(®, TX_PIN_CFG_RFTR_EN, 1); 62 63 rt2x00mmio_register_write(rt2x00dev, TX_PIN_CFG, reg); 64 } 65 66 static int rt2800soc_set_device_state(struct rt2x00_dev *rt2x00dev, 67 enum dev_state state) 68 { 69 int retval = 0; 70 71 switch (state) { 72 case STATE_RADIO_ON: 73 retval = rt2800mmio_enable_radio(rt2x00dev); 74 break; 75 76 case STATE_RADIO_OFF: 77 rt2800soc_disable_radio(rt2x00dev); 78 break; 79 80 case STATE_RADIO_IRQ_ON: 81 case STATE_RADIO_IRQ_OFF: 82 rt2800mmio_toggle_irq(rt2x00dev, state); 83 break; 84 85 case STATE_DEEP_SLEEP: 86 case STATE_SLEEP: 87 case STATE_STANDBY: 88 case STATE_AWAKE: 89 /* These states are not supported, but don't report an error */ 90 retval = 0; 91 break; 92 93 default: 94 retval = -ENOTSUPP; 95 break; 96 } 97 98 if (unlikely(retval)) 99 rt2x00_err(rt2x00dev, "Device failed to enter state %d (%d)\n", 100 state, retval); 101 102 return retval; 103 } 104 105 static int rt2800soc_read_eeprom(struct rt2x00_dev *rt2x00dev) 106 { 107 void __iomem *base_addr = ioremap(0x1F040000, EEPROM_SIZE); 108 109 if (!base_addr) 110 return -ENOMEM; 111 112 memcpy_fromio(rt2x00dev->eeprom, base_addr, EEPROM_SIZE); 113 114 iounmap(base_addr); 115 return 0; 116 } 117 118 /* Firmware functions */ 119 static char *rt2800soc_get_firmware_name(struct rt2x00_dev *rt2x00dev) 120 { 121 WARN_ON_ONCE(1); 122 return NULL; 123 } 124 125 static int rt2800soc_load_firmware(struct rt2x00_dev *rt2x00dev, 126 const u8 *data, const size_t len) 127 { 128 WARN_ON_ONCE(1); 129 return 0; 130 } 131 132 static int rt2800soc_check_firmware(struct rt2x00_dev *rt2x00dev, 133 const u8 *data, const size_t len) 134 { 135 WARN_ON_ONCE(1); 136 return 0; 137 } 138 139 static int rt2800soc_write_firmware(struct rt2x00_dev *rt2x00dev, 140 const u8 *data, const size_t len) 141 { 142 WARN_ON_ONCE(1); 143 return 0; 144 } 145 146 static const struct ieee80211_ops rt2800soc_mac80211_ops = { 147 .tx = rt2x00mac_tx, 148 .start = rt2x00mac_start, 149 .stop = rt2x00mac_stop, 150 .add_interface = rt2x00mac_add_interface, 151 .remove_interface = rt2x00mac_remove_interface, 152 .config = rt2x00mac_config, 153 .configure_filter = rt2x00mac_configure_filter, 154 .set_key = rt2x00mac_set_key, 155 .sw_scan_start = rt2x00mac_sw_scan_start, 156 .sw_scan_complete = rt2x00mac_sw_scan_complete, 157 .get_stats = rt2x00mac_get_stats, 158 .get_key_seq = rt2800_get_key_seq, 159 .set_rts_threshold = rt2800_set_rts_threshold, 160 .sta_add = rt2800_sta_add, 161 .sta_remove = rt2800_sta_remove, 162 .bss_info_changed = rt2x00mac_bss_info_changed, 163 .conf_tx = rt2800_conf_tx, 164 .get_tsf = rt2800_get_tsf, 165 .rfkill_poll = rt2x00mac_rfkill_poll, 166 .ampdu_action = rt2800_ampdu_action, 167 .flush = rt2x00mac_flush, 168 .get_survey = rt2800_get_survey, 169 .get_ringparam = rt2x00mac_get_ringparam, 170 .tx_frames_pending = rt2x00mac_tx_frames_pending, 171 }; 172 173 static const struct rt2800_ops rt2800soc_rt2800_ops = { 174 .register_read = rt2x00mmio_register_read, 175 .register_read_lock = rt2x00mmio_register_read, /* same for SoCs */ 176 .register_write = rt2x00mmio_register_write, 177 .register_write_lock = rt2x00mmio_register_write, /* same for SoCs */ 178 .register_multiread = rt2x00mmio_register_multiread, 179 .register_multiwrite = rt2x00mmio_register_multiwrite, 180 .regbusy_read = rt2x00mmio_regbusy_read, 181 .read_eeprom = rt2800soc_read_eeprom, 182 .hwcrypt_disabled = rt2800soc_hwcrypt_disabled, 183 .drv_write_firmware = rt2800soc_write_firmware, 184 .drv_init_registers = rt2800mmio_init_registers, 185 .drv_get_txwi = rt2800mmio_get_txwi, 186 }; 187 188 static const struct rt2x00lib_ops rt2800soc_rt2x00_ops = { 189 .irq_handler = rt2800mmio_interrupt, 190 .txstatus_tasklet = rt2800mmio_txstatus_tasklet, 191 .pretbtt_tasklet = rt2800mmio_pretbtt_tasklet, 192 .tbtt_tasklet = rt2800mmio_tbtt_tasklet, 193 .rxdone_tasklet = rt2800mmio_rxdone_tasklet, 194 .autowake_tasklet = rt2800mmio_autowake_tasklet, 195 .probe_hw = rt2800mmio_probe_hw, 196 .get_firmware_name = rt2800soc_get_firmware_name, 197 .check_firmware = rt2800soc_check_firmware, 198 .load_firmware = rt2800soc_load_firmware, 199 .initialize = rt2x00mmio_initialize, 200 .uninitialize = rt2x00mmio_uninitialize, 201 .get_entry_state = rt2800mmio_get_entry_state, 202 .clear_entry = rt2800mmio_clear_entry, 203 .set_device_state = rt2800soc_set_device_state, 204 .rfkill_poll = rt2800_rfkill_poll, 205 .link_stats = rt2800_link_stats, 206 .reset_tuner = rt2800_reset_tuner, 207 .link_tuner = rt2800_link_tuner, 208 .gain_calibration = rt2800_gain_calibration, 209 .vco_calibration = rt2800_vco_calibration, 210 .start_queue = rt2800mmio_start_queue, 211 .kick_queue = rt2800mmio_kick_queue, 212 .stop_queue = rt2800mmio_stop_queue, 213 .flush_queue = rt2800mmio_flush_queue, 214 .write_tx_desc = rt2800mmio_write_tx_desc, 215 .write_tx_data = rt2800_write_tx_data, 216 .write_beacon = rt2800_write_beacon, 217 .clear_beacon = rt2800_clear_beacon, 218 .fill_rxdone = rt2800mmio_fill_rxdone, 219 .config_shared_key = rt2800_config_shared_key, 220 .config_pairwise_key = rt2800_config_pairwise_key, 221 .config_filter = rt2800_config_filter, 222 .config_intf = rt2800_config_intf, 223 .config_erp = rt2800_config_erp, 224 .config_ant = rt2800_config_ant, 225 .config = rt2800_config, 226 }; 227 228 static const struct rt2x00_ops rt2800soc_ops = { 229 .name = KBUILD_MODNAME, 230 .drv_data_size = sizeof(struct rt2800_drv_data), 231 .max_ap_intf = 8, 232 .eeprom_size = EEPROM_SIZE, 233 .rf_size = RF_SIZE, 234 .tx_queues = NUM_TX_QUEUES, 235 .queue_init = rt2800mmio_queue_init, 236 .lib = &rt2800soc_rt2x00_ops, 237 .drv = &rt2800soc_rt2800_ops, 238 .hw = &rt2800soc_mac80211_ops, 239 #ifdef CONFIG_RT2X00_LIB_DEBUGFS 240 .debugfs = &rt2800_rt2x00debug, 241 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 242 }; 243 244 static int rt2800soc_probe(struct platform_device *pdev) 245 { 246 return rt2x00soc_probe(pdev, &rt2800soc_ops); 247 } 248 249 static struct platform_driver rt2800soc_driver = { 250 .driver = { 251 .name = "rt2800_wmac", 252 .mod_name = KBUILD_MODNAME, 253 }, 254 .probe = rt2800soc_probe, 255 .remove = rt2x00soc_remove, 256 .suspend = rt2x00soc_suspend, 257 .resume = rt2x00soc_resume, 258 }; 259 260 module_platform_driver(rt2800soc_driver); 261 262 MODULE_AUTHOR(DRV_PROJECT); 263 MODULE_VERSION(DRV_VERSION); 264 MODULE_DESCRIPTION("Ralink WiSoC Wireless LAN driver."); 265 MODULE_LICENSE("GPL"); 266