linux/drivers/staging/rtl8192e/rtl8192e/rtl_eeprom.c
<<
>>
Prefs
   1/******************************************************************************
   2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
   3 *
   4 * Based on the r8180 driver, which is:
   5 * Copyright 2004-2005 Andrea Merello <andrea.merello@gmail.com>, et al.
   6 * This program is free software; you can redistribute it and/or modify it
   7 * under the terms of version 2 of the GNU General Public License as
   8 * published by the Free Software Foundation.
   9 *
  10 * This program is distributed in the hope that it will be useful, but WITHOUT
  11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  13 * more details.
  14 *
  15 * You should have received a copy of the GNU General Public License along with
  16 * this program; if not, write to the Free Software Foundation, Inc.,
  17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  18 *
  19 * The full GNU General Public License is included in this distribution in the
  20 * file called LICENSE.
  21 *
  22 * Contact Information:
  23 * wlanfae <wlanfae@realtek.com>
  24******************************************************************************/
  25#include "rtl_core.h"
  26#include "rtl_eeprom.h"
  27
  28static void _rtl92e_gpio_write_bit(struct net_device *dev, int no, bool val)
  29{
  30        u8 reg = rtl92e_readb(dev, EPROM_CMD);
  31
  32        if (val)
  33                reg |= 1 << no;
  34        else
  35                reg &= ~(1 << no);
  36
  37        rtl92e_writeb(dev, EPROM_CMD, reg);
  38        udelay(EPROM_DELAY);
  39}
  40
  41static bool _rtl92e_gpio_get_bit(struct net_device *dev, int no)
  42{
  43        u8 reg = rtl92e_readb(dev, EPROM_CMD);
  44
  45        return (reg >> no) & 0x1;
  46}
  47
  48static void _rtl92e_eeprom_ck_cycle(struct net_device *dev)
  49{
  50        _rtl92e_gpio_write_bit(dev, EPROM_CK_BIT, 1);
  51        _rtl92e_gpio_write_bit(dev, EPROM_CK_BIT, 0);
  52}
  53
  54static u16 _rtl92e_eeprom_xfer(struct net_device *dev, u16 data, int tx_len)
  55{
  56        u16 ret = 0;
  57        int rx_len = 16;
  58
  59        _rtl92e_gpio_write_bit(dev, EPROM_CS_BIT, 1);
  60        _rtl92e_eeprom_ck_cycle(dev);
  61
  62        while (tx_len--) {
  63                _rtl92e_gpio_write_bit(dev, EPROM_W_BIT,
  64                                       (data >> tx_len) & 0x1);
  65                _rtl92e_eeprom_ck_cycle(dev);
  66        }
  67
  68        _rtl92e_gpio_write_bit(dev, EPROM_W_BIT, 0);
  69
  70        while (rx_len--) {
  71                _rtl92e_eeprom_ck_cycle(dev);
  72                ret |= _rtl92e_gpio_get_bit(dev, EPROM_R_BIT) << rx_len;
  73        }
  74
  75        _rtl92e_gpio_write_bit(dev, EPROM_CS_BIT, 0);
  76        _rtl92e_eeprom_ck_cycle(dev);
  77
  78        return ret;
  79}
  80
  81u32 rtl92e_eeprom_read(struct net_device *dev, u32 addr)
  82{
  83        struct r8192_priv *priv = rtllib_priv(dev);
  84        u32 ret = 0;
  85
  86        rtl92e_writeb(dev, EPROM_CMD,
  87                      (EPROM_CMD_PROGRAM << EPROM_CMD_OPERATING_MODE_SHIFT));
  88        udelay(EPROM_DELAY);
  89
  90        /* EEPROM is configured as x16 */
  91        if (priv->epromtype == EEPROM_93C56)
  92                ret = _rtl92e_eeprom_xfer(dev, (addr & 0xFF) | (0x6 << 8), 11);
  93        else
  94                ret = _rtl92e_eeprom_xfer(dev, (addr & 0x3F) | (0x6 << 6), 9);
  95
  96        rtl92e_writeb(dev, EPROM_CMD,
  97                      (EPROM_CMD_NORMAL<<EPROM_CMD_OPERATING_MODE_SHIFT));
  98        return ret;
  99}
 100