📄 rt2500pci.c
字号:
/* Copyright (C) 2004 - 2007 rt2x00 SourceForge Project <http://rt2x00.serialmonkey.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//* Module: rt2500pci Abstract: rt2500pci device specific routines. Supported chipsets: RT2560. *//* * Set enviroment defines for rt2x00.h */#define DRV_NAME "rt2500pci"#include <linux/delay.h>#include <linux/etherdevice.h>#include <linux/init.h>#include <linux/kernel.h>#include <linux/module.h>#include <linux/pci.h>#include <linux/eeprom_93cx6.h>#include "rt2x00.h"#include "rt2x00pci.h"#include "rt2500pci.h"/* * Register access. * All access to the CSR registers will go through the methods * rt2x00pci_register_read and rt2x00pci_register_write. * BBP and RF register require indirect register access, * and use the CSR registers BBPCSR and RFCSR to achieve this. * These indirect registers work with busy bits, * and we will try maximal REGISTER_BUSY_COUNT times to access * the register while taking a REGISTER_BUSY_DELAY us delay * between each attampt. When the busy bit is still set at that time, * the access attempt is considered to have failed, * and we will print an error. */static u32 rt2500pci_bbp_check(const struct rt2x00_dev *rt2x00dev){ u32 reg; unsigned int i; for (i = 0; i < REGISTER_BUSY_COUNT; i++) { rt2x00pci_register_read(rt2x00dev, BBPCSR, ®); if (!rt2x00_get_field32(reg, BBPCSR_BUSY)) break; udelay(REGISTER_BUSY_DELAY); } return reg;}static void rt2500pci_bbp_write(const struct rt2x00_dev *rt2x00dev, const unsigned int word, const u8 value){ u32 reg; /* * Wait until the BBP becomes ready. */ reg = rt2500pci_bbp_check(rt2x00dev); if (rt2x00_get_field32(reg, BBPCSR_BUSY)) { ERROR(rt2x00dev, "BBPCSR register busy. Write failed.\n"); return; } /* * Write the data into the BBP. */ reg = 0; rt2x00_set_field32(®, BBPCSR_VALUE, value); rt2x00_set_field32(®, BBPCSR_REGNUM, word); rt2x00_set_field32(®, BBPCSR_BUSY, 1); rt2x00_set_field32(®, BBPCSR_WRITE_CONTROL, 1); rt2x00pci_register_write(rt2x00dev, BBPCSR, reg);}static void rt2500pci_bbp_read(const struct rt2x00_dev *rt2x00dev, const unsigned int word, u8 *value){ u32 reg; /* * Wait until the BBP becomes ready. */ reg = rt2500pci_bbp_check(rt2x00dev); if (rt2x00_get_field32(reg, BBPCSR_BUSY)) { ERROR(rt2x00dev, "BBPCSR register busy. Read failed.\n"); return; } /* * Write the request into the BBP. */ reg = 0; rt2x00_set_field32(®, BBPCSR_REGNUM, word); rt2x00_set_field32(®, BBPCSR_BUSY, 1); rt2x00_set_field32(®, BBPCSR_WRITE_CONTROL, 0); rt2x00pci_register_write(rt2x00dev, BBPCSR, reg); /* * Wait until the BBP becomes ready. */ reg = rt2500pci_bbp_check(rt2x00dev); if (rt2x00_get_field32(reg, BBPCSR_BUSY)) { ERROR(rt2x00dev, "BBPCSR register busy. Read failed.\n"); *value = 0xff; return; } *value = rt2x00_get_field32(reg, BBPCSR_VALUE);}static void rt2500pci_rf_write(const struct rt2x00_dev *rt2x00dev, const unsigned int word, const u32 value){ u32 reg; unsigned int i; if (!word) return; for (i = 0; i < REGISTER_BUSY_COUNT; i++) { rt2x00pci_register_read(rt2x00dev, RFCSR, ®); if (!rt2x00_get_field32(reg, RFCSR_BUSY)) goto rf_write; udelay(REGISTER_BUSY_DELAY); } ERROR(rt2x00dev, "RFCSR register busy. Write failed.\n"); return;rf_write: reg = 0; rt2x00_set_field32(®, RFCSR_VALUE, value); rt2x00_set_field32(®, RFCSR_NUMBER_OF_BITS, 20); rt2x00_set_field32(®, RFCSR_IF_SELECT, 0); rt2x00_set_field32(®, RFCSR_BUSY, 1); rt2x00pci_register_write(rt2x00dev, RFCSR, reg); rt2x00_rf_write(rt2x00dev, word, value);}static void rt2500pci_eepromregister_read(struct eeprom_93cx6 *eeprom){ struct rt2x00_dev *rt2x00dev = eeprom->data; u32 reg; rt2x00pci_register_read(rt2x00dev, CSR21, ®); eeprom->reg_data_in = !!rt2x00_get_field32(reg, CSR21_EEPROM_DATA_IN); eeprom->reg_data_out = !!rt2x00_get_field32(reg, CSR21_EEPROM_DATA_OUT); eeprom->reg_data_clock = !!rt2x00_get_field32(reg, CSR21_EEPROM_DATA_CLOCK); eeprom->reg_chip_select = !!rt2x00_get_field32(reg, CSR21_EEPROM_CHIP_SELECT);}static void rt2500pci_eepromregister_write(struct eeprom_93cx6 *eeprom){ struct rt2x00_dev *rt2x00dev = eeprom->data; u32 reg = 0; rt2x00_set_field32(®, CSR21_EEPROM_DATA_IN, !!eeprom->reg_data_in); rt2x00_set_field32(®, CSR21_EEPROM_DATA_OUT, !!eeprom->reg_data_out); rt2x00_set_field32(®, CSR21_EEPROM_DATA_CLOCK, !!eeprom->reg_data_clock); rt2x00_set_field32(®, CSR21_EEPROM_CHIP_SELECT, !!eeprom->reg_chip_select); rt2x00pci_register_write(rt2x00dev, CSR21, reg);}#ifdef CONFIG_RT2X00_LIB_DEBUGFS#define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u32)) )static void rt2500pci_read_csr(const struct rt2x00_dev *rt2x00dev, const unsigned int word, u32 *data){ rt2x00pci_register_read(rt2x00dev, CSR_OFFSET(word), data);}static void rt2500pci_write_csr(const struct rt2x00_dev *rt2x00dev, const unsigned int word, u32 data){ rt2x00pci_register_write(rt2x00dev, CSR_OFFSET(word), data);}static const struct rt2x00debug rt2500pci_rt2x00debug = { .owner = THIS_MODULE, .csr = { .read = rt2500pci_read_csr, .write = rt2500pci_write_csr, .word_size = sizeof(u32), .word_count = CSR_REG_SIZE / sizeof(u32), }, .eeprom = { .read = rt2x00_eeprom_read, .write = rt2x00_eeprom_write, .word_size = sizeof(u16), .word_count = EEPROM_SIZE / sizeof(u16), }, .bbp = { .read = rt2500pci_bbp_read, .write = rt2500pci_bbp_write, .word_size = sizeof(u8), .word_count = BBP_SIZE / sizeof(u8), }, .rf = { .read = rt2x00_rf_read, .write = rt2500pci_rf_write, .word_size = sizeof(u32), .word_count = RF_SIZE / sizeof(u32), },};#endif /* CONFIG_RT2X00_LIB_DEBUGFS */#ifdef CONFIG_RT2500PCI_RFKILLstatic int rt2500pci_rfkill_poll(struct rt2x00_dev *rt2x00dev){ u32 reg; rt2x00pci_register_read(rt2x00dev, GPIOCSR, ®); return rt2x00_get_field32(reg, GPIOCSR_BIT0);}#else#define rt2500pci_rfkill_poll NULL#endif /* CONFIG_RT2500PCI_RFKILL *//* * Configuration handlers. */static void rt2500pci_config_mac_addr(struct rt2x00_dev *rt2x00dev, __le32 *mac){ rt2x00pci_register_multiwrite(rt2x00dev, CSR3, mac, (2 * sizeof(__le32)));}static void rt2500pci_config_bssid(struct rt2x00_dev *rt2x00dev, __le32 *bssid){ rt2x00pci_register_multiwrite(rt2x00dev, CSR5, bssid, (2 * sizeof(__le32)));}static void rt2500pci_config_type(struct rt2x00_dev *rt2x00dev, const int type, const int tsf_sync){ u32 reg; rt2x00pci_register_write(rt2x00dev, CSR14, 0); /* * Enable beacon config */ rt2x00pci_register_read(rt2x00dev, BCNCSR1, ®); rt2x00_set_field32(®, BCNCSR1_PRELOAD, PREAMBLE + get_duration(IEEE80211_HEADER, 20)); rt2x00_set_field32(®, BCNCSR1_BEACON_CWMIN, rt2x00lib_get_ring(rt2x00dev, IEEE80211_TX_QUEUE_BEACON) ->tx_params.cw_min); rt2x00pci_register_write(rt2x00dev, BCNCSR1, reg); /* * Enable synchronisation. */ rt2x00pci_register_read(rt2x00dev, CSR14, ®); rt2x00_set_field32(®, CSR14_TSF_COUNT, 1); rt2x00_set_field32(®, CSR14_TBCN, 1); rt2x00_set_field32(®, CSR14_BEACON_GEN, 0); rt2x00_set_field32(®, CSR14_TSF_SYNC, tsf_sync); rt2x00pci_register_write(rt2x00dev, CSR14, reg);}static void rt2500pci_config_preamble(struct rt2x00_dev *rt2x00dev, const int short_preamble, const int ack_timeout, const int ack_consume_time){ int preamble_mask; u32 reg; /* * When short preamble is enabled, we should set bit 0x08 */ preamble_mask = short_preamble << 3; rt2x00pci_register_read(rt2x00dev, TXCSR1, ®); rt2x00_set_field32(®, TXCSR1_ACK_TIMEOUT, ack_timeout); rt2x00_set_field32(®, TXCSR1_ACK_CONSUME_TIME, ack_consume_time); rt2x00pci_register_write(rt2x00dev, TXCSR1, reg); rt2x00pci_register_read(rt2x00dev, ARCSR2, ®); rt2x00_set_field32(®, ARCSR2_SIGNAL, 0x00 | preamble_mask); rt2x00_set_field32(®, ARCSR2_SERVICE, 0x04); rt2x00_set_field32(®, ARCSR2_LENGTH, get_duration(ACK_SIZE, 10)); rt2x00pci_register_write(rt2x00dev, ARCSR2, reg); rt2x00pci_register_read(rt2x00dev, ARCSR3, ®); rt2x00_set_field32(®, ARCSR3_SIGNAL, 0x01 | preamble_mask); rt2x00_set_field32(®, ARCSR3_SERVICE, 0x04); rt2x00_set_field32(®, ARCSR2_LENGTH, get_duration(ACK_SIZE, 20)); rt2x00pci_register_write(rt2x00dev, ARCSR3, reg); rt2x00pci_register_read(rt2x00dev, ARCSR4, ®); rt2x00_set_field32(®, ARCSR4_SIGNAL, 0x02 | preamble_mask); rt2x00_set_field32(®, ARCSR4_SERVICE, 0x04); rt2x00_set_field32(®, ARCSR2_LENGTH, get_duration(ACK_SIZE, 55)); rt2x00pci_register_write(rt2x00dev, ARCSR4, reg); rt2x00pci_register_read(rt2x00dev, ARCSR5, ®); rt2x00_set_field32(®, ARCSR5_SIGNAL, 0x03 | preamble_mask); rt2x00_set_field32(®, ARCSR5_SERVICE, 0x84); rt2x00_set_field32(®, ARCSR2_LENGTH, get_duration(ACK_SIZE, 110)); rt2x00pci_register_write(rt2x00dev, ARCSR5, reg);}static void rt2500pci_config_phymode(struct rt2x00_dev *rt2x00dev, const int basic_rate_mask){ rt2x00pci_register_write(rt2x00dev, ARCSR1, basic_rate_mask);}static void rt2500pci_config_channel(struct rt2x00_dev *rt2x00dev, struct rf_channel *rf, const int txpower){ u8 r70; /* * Set TXpower. */ rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower)); /* * Switch on tuning bits. * For RT2523 devices we do not need to update the R1 register. */ if (!rt2x00_rf(&rt2x00dev->chip, RF2523)) rt2x00_set_field32(&rf->rf1, RF1_TUNER, 1); rt2x00_set_field32(&rf->rf3, RF3_TUNER, 1); /* * For RT2525 we should first set the channel to half band higher. */ if (rt2x00_rf(&rt2x00dev->chip, RF2525)) { static const u32 vals[] = { 0x00080cbe, 0x00080d02, 0x00080d06, 0x00080d0a, 0x00080d0e, 0x00080d12, 0x00080d16, 0x00080d1a, 0x00080d1e, 0x00080d22, 0x00080d26, 0x00080d2a, 0x00080d2e, 0x00080d3a }; rt2500pci_rf_write(rt2x00dev, 1, rf->rf1); rt2500pci_rf_write(rt2x00dev, 2, vals[rf->channel - 1]); rt2500pci_rf_write(rt2x00dev, 3, rf->rf3); if (rf->rf4) rt2500pci_rf_write(rt2x00dev, 4, rf->rf4); } rt2500pci_rf_write(rt2x00dev, 1, rf->rf1); rt2500pci_rf_write(rt2x00dev, 2, rf->rf2); rt2500pci_rf_write(rt2x00dev, 3, rf->rf3); if (rf->rf4) rt2500pci_rf_write(rt2x00dev, 4, rf->rf4); /* * Channel 14 requires the Japan filter bit to be set. */ r70 = 0x46; rt2x00_set_field8(&r70, BBP_R70_JAPAN_FILTER, rf->channel == 14); rt2500pci_bbp_write(rt2x00dev, 70, r70); msleep(1); /* * Switch off tuning bits. * For RT2523 devices we do not need to update the R1 register. */ if (!rt2x00_rf(&rt2x00dev->chip, RF2523)) { rt2x00_set_field32(&rf->rf1, RF1_TUNER, 0); rt2500pci_rf_write(rt2x00dev, 1, rf->rf1); } rt2x00_set_field32(&rf->rf3, RF3_TUNER, 0); rt2500pci_rf_write(rt2x00dev, 3, rf->rf3); /* * Clear false CRC during channel switch. */ rt2x00pci_register_read(rt2x00dev, CNT0, &rf->rf1);}static void rt2500pci_config_txpower(struct rt2x00_dev *rt2x00dev, const int txpower){ u32 rf3; rt2x00_rf_read(rt2x00dev, 3, &rf3); rt2x00_set_field32(&rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower)); rt2500pci_rf_write(rt2x00dev, 3, rf3);}static void rt2500pci_config_antenna(struct rt2x00_dev *rt2x00dev, const int antenna_tx, const int antenna_rx){ u32 reg; u8 r14; u8 r2; rt2x00pci_register_read(rt2x00dev, BBPCSR1, ®); rt2500pci_bbp_read(rt2x00dev, 14, &r14); rt2500pci_bbp_read(rt2x00dev, 2, &r2); /* * Configure the TX antenna. */ switch (antenna_tx) { case ANTENNA_SW_DIVERSITY: case ANTENNA_HW_DIVERSITY: rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2); rt2x00_set_field32(®, BBPCSR1_CCK, 2); rt2x00_set_field32(®, BBPCSR1_OFDM, 2); break; case ANTENNA_A: rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 0); rt2x00_set_field32(®, BBPCSR1_CCK, 0); rt2x00_set_field32(®, BBPCSR1_OFDM, 0); break; case ANTENNA_B: rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2); rt2x00_set_field32(®, BBPCSR1_CCK, 2); rt2x00_set_field32(®, BBPCSR1_OFDM, 2); break; } /* * Configure the RX antenna. */ switch (antenna_rx) { case ANTENNA_SW_DIVERSITY: case ANTENNA_HW_DIVERSITY: rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2); break; case ANTENNA_A: rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 0); break; case ANTENNA_B: rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2); break; } /* * RT2525E and RT5222 need to flip TX I/Q */ if (rt2x00_rf(&rt2x00dev->chip, RF2525E) || rt2x00_rf(&rt2x00dev->chip, RF5222)) { rt2x00_set_field8(&r2, BBP_R2_TX_IQ_FLIP, 1); rt2x00_set_field32(®, BBPCSR1_CCK_FLIP, 1); rt2x00_set_field32(®, BBPCSR1_OFDM_FLIP, 1); /* * RT2525E does not need RX I/Q Flip. */ if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) rt2x00_set_field8(&r14, BBP_R14_RX_IQ_FLIP, 0); } else { rt2x00_set_field32(®, BBPCSR1_CCK_FLIP, 0); rt2x00_set_field32(®, BBPCSR1_OFDM_FLIP, 0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -