From 742821ce5fdf691826154fe72ba0884f71a40982 Mon Sep 17 00:00:00 2001 From: Larry Finger Date: Thu, 11 Feb 2010 12:07:35 -0600 Subject: [PATCH] staging: r8187se: Change to use common eeprom routines in EEPROM_93CX The TODO list includes switching this driver to use the common EEPROM routines in EEPROM_93CX. Signed-off-by: Larry Finger Tested by: Bernhard Schiffner Signed-off-by: Greg Kroah-Hartman --- drivers/staging/rtl8187se/Kconfig | 1 + drivers/staging/rtl8187se/Makefile | 1 - drivers/staging/rtl8187se/TODO | 1 - drivers/staging/rtl8187se/r8180_93cx6.c | 146 ------------------------ drivers/staging/rtl8187se/r8180_93cx6.h | 15 +-- drivers/staging/rtl8187se/r8180_core.c | 68 ++++++++--- 6 files changed, 60 insertions(+), 172 deletions(-) delete mode 100644 drivers/staging/rtl8187se/r8180_93cx6.c diff --git a/drivers/staging/rtl8187se/Kconfig b/drivers/staging/rtl8187se/Kconfig index e24a6f7a0d85..155a78e07405 100644 --- a/drivers/staging/rtl8187se/Kconfig +++ b/drivers/staging/rtl8187se/Kconfig @@ -3,6 +3,7 @@ config R8187SE depends on PCI && WLAN select WIRELESS_EXT select WEXT_PRIV + select EEPROM_93CX6 default N ---help--- If built as a module, it will be called r8187se.ko. diff --git a/drivers/staging/rtl8187se/Makefile b/drivers/staging/rtl8187se/Makefile index b395acf5a38e..e6adf91cdd2c 100644 --- a/drivers/staging/rtl8187se/Makefile +++ b/drivers/staging/rtl8187se/Makefile @@ -18,7 +18,6 @@ EXTRA_CFLAGS += -DENABLE_LPS r8187se-objs := \ r8180_core.o \ - r8180_93cx6.o \ r8180_wx.o \ r8180_rtl8225z2.o \ r8185b_init.o \ diff --git a/drivers/staging/rtl8187se/TODO b/drivers/staging/rtl8187se/TODO index a762e79873e9..704949a9da0d 100644 --- a/drivers/staging/rtl8187se/TODO +++ b/drivers/staging/rtl8187se/TODO @@ -5,7 +5,6 @@ TODO: - switch to use shared "librtl" instead of private ieee80211 stack - switch to use LIB80211 - switch to use MAC80211 -- switch to use EEPROM_93CX6 - use kernel coding style - checkpatch.pl fixes - sparse fixes diff --git a/drivers/staging/rtl8187se/r8180_93cx6.c b/drivers/staging/rtl8187se/r8180_93cx6.c deleted file mode 100644 index 7e4711fb930c..000000000000 --- a/drivers/staging/rtl8187se/r8180_93cx6.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - This files contains card eeprom (93c46 or 93c56) programming routines, - memory is addressed by 16 bits words. - - This is part of rtl8180 OpenSource driver. - Copyright (C) Andrea Merello 2004 - Released under the terms of GPL (General Public Licence) - - Parts of this driver are based on the GPL part of the - official realtek driver. - - Parts of this driver are based on the rtl8180 driver skeleton - from Patric Schenke & Andres Salomon. - - Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver. - - We want to tanks the Authors of those projects and the Ndiswrapper - project Authors. -*/ - -#include "r8180_93cx6.h" - -void eprom_cs(struct net_device *dev, short bit) -{ - if(bit) - write_nic_byte(dev, EPROM_CMD, - (1<epromtype==EPROM_93c56){ - addr_str[7]=addr & 1; - addr_str[6]=addr & (1<<1); - addr_str[5]=addr & (1<<2); - addr_str[4]=addr & (1<<3); - addr_str[3]=addr & (1<<4); - addr_str[2]=addr & (1<<5); - addr_str[1]=addr & (1<<6); - addr_str[0]=addr & (1<<7); - addr_len=8; - }else{ - addr_str[5]=addr & 1; - addr_str[4]=addr & (1<<1); - addr_str[3]=addr & (1<<2); - addr_str[2]=addr & (1<<3); - addr_str[1]=addr & (1<<4); - addr_str[0]=addr & (1<<5); - addr_len=6; - } - eprom_cs(dev, 1); - eprom_ck_cycle(dev); - eprom_send_bits_string(dev, read_cmd, 3); - eprom_send_bits_string(dev, addr_str, addr_len); - - //keep chip pin D to low state while reading. - //I'm unsure if it is necessary, but anyway shouldn't hurt - eprom_w(dev, 0); - - for(i=0;i<16;i++){ - //eeprom needs a clk cycle between writing opcode&adr - //and reading data. (eeprom outs a dummy 0) - eprom_ck_cycle(dev); - ret |= (eprom_r(dev)<<(15-i)); - } - - eprom_cs(dev, 0); - eprom_ck_cycle(dev); - - //disable EPROM programming - write_nic_byte(dev, EPROM_CMD, - (EPROM_CMD_NORMAL< +#include #include "r8180_hw.h" #include "r8180.h" @@ -2642,6 +2643,36 @@ static void rtl8180_link_detect_init(plink_detect_t plink_detect) } //YJ,add,080828,end +static void rtl8187se_eeprom_register_read(struct eeprom_93cx6 *eeprom) +{ + struct net_device *dev = eeprom->data; + u8 reg = read_nic_byte(dev, EPROM_CMD); + + eeprom->reg_data_in = reg & RTL818X_EEPROM_CMD_WRITE; + eeprom->reg_data_out = reg & RTL818X_EEPROM_CMD_READ; + eeprom->reg_data_clock = reg & RTL818X_EEPROM_CMD_CK; + eeprom->reg_chip_select = reg & RTL818X_EEPROM_CMD_CS; +} + +static void rtl8187se_eeprom_register_write(struct eeprom_93cx6 *eeprom) +{ + struct net_device *dev = eeprom->data; + u8 reg = 2 << 6; + + if (eeprom->reg_data_in) + reg |= RTL818X_EEPROM_CMD_WRITE; + if (eeprom->reg_data_out) + reg |= RTL818X_EEPROM_CMD_READ; + if (eeprom->reg_data_clock) + reg |= RTL818X_EEPROM_CMD_CK; + if (eeprom->reg_chip_select) + reg |= RTL818X_EEPROM_CMD_CS; + + write_nic_byte(dev, EPROM_CMD, reg); + read_nic_byte(dev, EPROM_CMD); + udelay(10); +} + short rtl8180_init(struct net_device *dev) { struct r8180_priv *priv = ieee80211_priv(dev); @@ -2650,8 +2681,16 @@ short rtl8180_init(struct net_device *dev) u32 usValue; u16 tmpu16; int i, j; + struct eeprom_93cx6 eeprom; + u16 eeprom_val; - priv->channel_plan = eprom_read(dev, EEPROM_COUNTRY_CODE>>1) & 0xFF; + eeprom.data = dev; + eeprom.register_read = rtl8187se_eeprom_register_read; + eeprom.register_write = rtl8187se_eeprom_register_write; + eeprom.width = PCI_EEPROM_WIDTH_93C46; + + eeprom_93cx6_read(&eeprom, EEPROM_COUNTRY_CODE>>1, &eeprom_val); + priv->channel_plan = eeprom_val & 0xFF; if(priv->channel_plan > COUNTRY_CODE_GLOBAL_DOMAIN){ printk("rtl8180_init:Error channel plan! Set to default.\n"); priv->channel_plan = 0; @@ -2879,7 +2918,8 @@ short rtl8180_init(struct net_device *dev) // just for sync 85 priv->enable_gpio0 = 0; - usValue = eprom_read(dev, EEPROM_SW_REVD_OFFSET); + eeprom_93cx6_read(&eeprom, EEPROM_SW_REVD_OFFSET, &eeprom_val); + usValue = eeprom_val; DMESG("usValue is 0x%x\n",usValue); //3Read AntennaDiversity @@ -2919,27 +2959,23 @@ short rtl8180_init(struct net_device *dev) else priv->epromtype=EPROM_93c46; - dev->dev_addr[0]=eprom_read(dev,MAC_ADR) & 0xff; - dev->dev_addr[1]=(eprom_read(dev,MAC_ADR) & 0xff00)>>8; - dev->dev_addr[2]=eprom_read(dev,MAC_ADR+1) & 0xff; - dev->dev_addr[3]=(eprom_read(dev,MAC_ADR+1) & 0xff00)>>8; - dev->dev_addr[4]=eprom_read(dev,MAC_ADR+2) & 0xff; - dev->dev_addr[5]=(eprom_read(dev,MAC_ADR+2) & 0xff00)>>8; + eeprom_93cx6_multiread(&eeprom, 0x7, (__le16 *) + dev->dev_addr, 3); for(i=1,j=0; i<14; i+=2,j++){ - word = eprom_read(dev,EPROM_TXPW_CH1_2 + j); + eeprom_93cx6_read(&eeprom, EPROM_TXPW_CH1_2 + j, &word); priv->chtxpwr[i]=word & 0xff; priv->chtxpwr[i+1]=(word & 0xff00)>>8; } for (i = 1, j = 0; i < 14; i += 2, j++) { - word = eprom_read(dev, EPROM_TXPW_OFDM_CH1_2 + j); + eeprom_93cx6_read(&eeprom, EPROM_TXPW_OFDM_CH1_2 + j, &word); priv->chtxpwr_ofdm[i] = word & 0xff; priv->chtxpwr_ofdm[i+1] = (word & 0xff00) >> 8; } /* 3Read crystal calibtration and thermal meter indication on 87SE. */ + eeprom_93cx6_read(&eeprom, EEPROM_RSV>>1, &tmpu16); - tmpu16 = eprom_read(dev, EEPROM_RSV >> 1); /* Crystal calibration for Xin and Xout resp. */ priv->XtalCal_Xout = tmpu16 & EEPROM_XTAL_CAL_XOUT_MASK; priv->XtalCal_Xin = (tmpu16 & EEPROM_XTAL_CAL_XIN_MASK) >> 4; @@ -2951,17 +2987,19 @@ short rtl8180_init(struct net_device *dev) if ((tmpu16 & EEPROM_THERMAL_METER_ENABLE) >> 13) priv->bTxPowerTrack = true; - word = eprom_read(dev,EPROM_TXPW_BASE); + eeprom_93cx6_read(&eeprom, EPROM_TXPW_BASE, &word); priv->cck_txpwr_base = word & 0xf; priv->ofdm_txpwr_base = (word>>4) & 0xf; - version = eprom_read(dev,EPROM_VERSION); + eeprom_93cx6_read(&eeprom, EPROM_VERSION, &version); DMESG("EEPROM version %x",version); priv->rcr_csense = 3; - priv->cs_treshold = (eprom_read(dev, ENERGY_TRESHOLD) & 0xff00) >> 8; + eeprom_93cx6_read(&eeprom, ENERGY_TRESHOLD, &eeprom_val); + priv->cs_treshold = (eeprom_val & 0xff00) >> 8; - priv->rf_chip = 0xff & eprom_read(dev, RFCHIPID); + eeprom_93cx6_read(&eeprom, RFCHIPID, &eeprom_val); + priv->rf_chip = 0xff & eeprom_val; priv->rf_chip = RF_ZEBRA4; priv->rf_sleep = rtl8225z4_rf_sleep;