1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
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