📄 rt2400pci.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: rt2400pci Abstract: rt2400pci device specific routines. Supported chipsets: RT2460. *//* * Set enviroment defines for rt2x00.h */#define DRV_NAME "rt2400pci"#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 "rt2400pci.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 rt2400pci_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 rt2400pci_bbp_write(const struct rt2x00_dev *rt2x00dev, const unsigned int word, const u8 value){ u32 reg; /* * Wait until the BBP becomes ready. */ reg = rt2400pci_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 rt2400pci_bbp_read(const struct rt2x00_dev *rt2x00dev, const unsigned int word, u8 *value){ u32 reg; /* * Wait until the BBP becomes ready. */ reg = rt2400pci_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 = rt2400pci_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 rt2400pci_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 rt2400pci_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 rt2400pci_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 rt2400pci_read_csr(const struct rt2x00_dev *rt2x00dev, const unsigned int word, u32 *data){ rt2x00pci_register_read(rt2x00dev, CSR_OFFSET(word), data);}static void rt2400pci_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 rt2400pci_rt2x00debug = { .owner = THIS_MODULE, .csr = { .read = rt2400pci_read_csr, .write = rt2400pci_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 = rt2400pci_bbp_read, .write = rt2400pci_bbp_write, .word_size = sizeof(u8), .word_count = BBP_SIZE / sizeof(u8), }, .rf = { .read = rt2x00_rf_read, .write = rt2400pci_rf_write, .word_size = sizeof(u32), .word_count = RF_SIZE / sizeof(u32), },};#endif /* CONFIG_RT2X00_LIB_DEBUGFS */#ifdef CONFIG_RT2400PCI_RFKILLstatic int rt2400pci_rfkill_poll(struct rt2x00_dev *rt2x00dev){ u32 reg; rt2x00pci_register_read(rt2x00dev, GPIOCSR, ®); return rt2x00_get_field32(reg, GPIOCSR_BIT0);}#else#define rt2400pci_rfkill_poll NULL#endif /* CONFIG_RT2400PCI_RFKILL *//* * Configuration handlers. */static void rt2400pci_config_mac_addr(struct rt2x00_dev *rt2x00dev, __le32 *mac){ rt2x00pci_register_multiwrite(rt2x00dev, CSR3, mac, (2 * sizeof(__le32)));}static void rt2400pci_config_bssid(struct rt2x00_dev *rt2x00dev, __le32 *bssid){ rt2x00pci_register_multiwrite(rt2x00dev, CSR5, bssid, (2 * sizeof(__le32)));}static void rt2400pci_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)); 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 rt2400pci_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 rt2400pci_config_phymode(struct rt2x00_dev *rt2x00dev, const int basic_rate_mask){ rt2x00pci_register_write(rt2x00dev, ARCSR1, basic_rate_mask);}static void rt2400pci_config_channel(struct rt2x00_dev *rt2x00dev, struct rf_channel *rf){ /* * Switch on tuning bits. */ rt2x00_set_field32(&rf->rf1, RF1_TUNER, 1); rt2x00_set_field32(&rf->rf3, RF3_TUNER, 1); rt2400pci_rf_write(rt2x00dev, 1, rf->rf1); rt2400pci_rf_write(rt2x00dev, 2, rf->rf2); rt2400pci_rf_write(rt2x00dev, 3, rf->rf3); /* * RF2420 chipset don't need any additional actions. */ if (rt2x00_rf(&rt2x00dev->chip, RF2420)) return; /* * For the RT2421 chipsets we need to write an invalid * reference clock rate to activate auto_tune. * After that we set the value back to the correct channel. */ rt2400pci_rf_write(rt2x00dev, 1, rf->rf1); rt2400pci_rf_write(rt2x00dev, 2, 0x000c2a32); rt2400pci_rf_write(rt2x00dev, 3, rf->rf3); msleep(1); rt2400pci_rf_write(rt2x00dev, 1, rf->rf1); rt2400pci_rf_write(rt2x00dev, 2, rf->rf2); rt2400pci_rf_write(rt2x00dev, 3, rf->rf3); msleep(1); /* * Switch off tuning bits. */ rt2x00_set_field32(&rf->rf1, RF1_TUNER, 0); rt2x00_set_field32(&rf->rf3, RF3_TUNER, 0); rt2400pci_rf_write(rt2x00dev, 1, rf->rf1); rt2400pci_rf_write(rt2x00dev, 3, rf->rf3); /* * Clear false CRC during channel switch. */ rt2x00pci_register_read(rt2x00dev, CNT0, &rf->rf1);}static void rt2400pci_config_txpower(struct rt2x00_dev *rt2x00dev, int txpower){ rt2400pci_bbp_write(rt2x00dev, 3, TXPOWER_TO_DEV(txpower));}static void rt2400pci_config_antenna(struct rt2x00_dev *rt2x00dev, int antenna_tx, int antenna_rx){ u8 r1; u8 r4; rt2400pci_bbp_read(rt2x00dev, 4, &r4); rt2400pci_bbp_read(rt2x00dev, 1, &r1); /* * Configure the TX antenna. */ switch (antenna_tx) { case ANTENNA_SW_DIVERSITY: case ANTENNA_HW_DIVERSITY: rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 1); break; case ANTENNA_A: rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -