1 /******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
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.
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
15 * The full GNU General Public License is included in this distribution in the
16 * file called LICENSE.
18 * Contact Information:
19 * wlanfae <wlanfae@realtek.com>
20 ******************************************************************************/
22 #include "rtl_eeprom.h"
24 static void _rtl92e_gpio_write_bit(struct net_device *dev, int no, bool val)
26 u8 reg = rtl92e_readb(dev, EPROM_CMD);
33 rtl92e_writeb(dev, EPROM_CMD, reg);
37 static bool _rtl92e_gpio_get_bit(struct net_device *dev, int no)
39 u8 reg = rtl92e_readb(dev, EPROM_CMD);
41 return (reg >> no) & 0x1;
44 static void _rtl92e_eeprom_ck_cycle(struct net_device *dev)
46 _rtl92e_gpio_write_bit(dev, EPROM_CK_BIT, 1);
47 _rtl92e_gpio_write_bit(dev, EPROM_CK_BIT, 0);
50 static u16 _rtl92e_eeprom_xfer(struct net_device *dev, u16 data, int tx_len)
55 _rtl92e_gpio_write_bit(dev, EPROM_CS_BIT, 1);
56 _rtl92e_eeprom_ck_cycle(dev);
59 _rtl92e_gpio_write_bit(dev, EPROM_W_BIT,
60 (data >> tx_len) & 0x1);
61 _rtl92e_eeprom_ck_cycle(dev);
64 _rtl92e_gpio_write_bit(dev, EPROM_W_BIT, 0);
67 _rtl92e_eeprom_ck_cycle(dev);
68 ret |= _rtl92e_gpio_get_bit(dev, EPROM_R_BIT) << rx_len;
71 _rtl92e_gpio_write_bit(dev, EPROM_CS_BIT, 0);
72 _rtl92e_eeprom_ck_cycle(dev);
77 u32 rtl92e_eeprom_read(struct net_device *dev, u32 addr)
79 struct r8192_priv *priv = rtllib_priv(dev);
82 rtl92e_writeb(dev, EPROM_CMD,
83 (EPROM_CMD_PROGRAM << EPROM_CMD_OPERATING_MODE_SHIFT));
86 /* EEPROM is configured as x16 */
87 if (priv->epromtype == EEPROM_93C56)
88 ret = _rtl92e_eeprom_xfer(dev, (addr & 0xFF) | (0x6 << 8), 11);
90 ret = _rtl92e_eeprom_xfer(dev, (addr & 0x3F) | (0x6 << 6), 9);
92 rtl92e_writeb(dev, EPROM_CMD,
93 (EPROM_CMD_NORMAL<<EPROM_CMD_OPERATING_MODE_SHIFT));