1 // SPDX-License-Identifier: GPL-2.0
3 * This files contains card eeprom (93c46 or 93c56) programming routines,
4 * memory is addressed by 16 bits words.
6 * This is part of rtl8180 OpenSource driver.
7 * Copyright (C) Andrea Merello 2004 <andrea.merello@gmail.com>
9 * Parts of this driver are based on the GPL part of the
10 * official realtek driver.
12 * Parts of this driver are based on the rtl8180 driver skeleton
13 * from Patric Schenke & Andres Salomon.
15 * Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver.
17 * We want to thank the Authors of those projects and the Ndiswrapper
21 #include "r8180_93cx6.h"
23 static void eprom_cs(struct net_device *dev, short bit)
28 err = read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
33 write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_CS_BIT);
36 write_nic_byte_E(dev, EPROM_CMD, cmdreg & ~EPROM_CS_BIT);
38 force_pci_posting(dev);
42 static void eprom_ck_cycle(struct net_device *dev)
47 err = read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
50 write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_CK_BIT);
51 force_pci_posting(dev);
54 read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
55 write_nic_byte_E(dev, EPROM_CMD, cmdreg & ~EPROM_CK_BIT);
56 force_pci_posting(dev);
60 static void eprom_w(struct net_device *dev, short bit)
65 err = read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
69 write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_W_BIT);
71 write_nic_byte_E(dev, EPROM_CMD, cmdreg & ~EPROM_W_BIT);
73 force_pci_posting(dev);
77 static short eprom_r(struct net_device *dev)
82 err = read_nic_byte_E(dev, EPROM_CMD, &bit);
88 if (bit & EPROM_R_BIT)
94 static void eprom_send_bits_string(struct net_device *dev, short b[], int len)
98 for (i = 0; i < len; i++) {
104 int eprom_read(struct net_device *dev, u32 addr)
106 struct r8192_priv *priv = ieee80211_priv(dev);
107 short read_cmd[] = {1, 1, 0};
115 /* enable EPROM programming */
116 write_nic_byte_E(dev, EPROM_CMD,
117 (EPROM_CMD_PROGRAM << EPROM_CMD_OPERATING_MODE_SHIFT));
118 force_pci_posting(dev);
121 if (priv->epromtype == EPROM_93c56) {
122 addr_str[7] = addr & 1;
123 addr_str[6] = addr & BIT(1);
124 addr_str[5] = addr & BIT(2);
125 addr_str[4] = addr & BIT(3);
126 addr_str[3] = addr & BIT(4);
127 addr_str[2] = addr & BIT(5);
128 addr_str[1] = addr & BIT(6);
129 addr_str[0] = addr & BIT(7);
132 addr_str[5] = addr & 1;
133 addr_str[4] = addr & BIT(1);
134 addr_str[3] = addr & BIT(2);
135 addr_str[2] = addr & BIT(3);
136 addr_str[1] = addr & BIT(4);
137 addr_str[0] = addr & BIT(5);
142 eprom_send_bits_string(dev, read_cmd, 3);
143 eprom_send_bits_string(dev, addr_str, addr_len);
146 * keep chip pin D to low state while reading.
147 * I'm unsure if it is necessary, but anyway shouldn't hurt
151 for (i = 0; i < 16; i++) {
152 /* eeprom needs a clk cycle between writing opcode&adr
153 * and reading data. (eeprom outs a dummy 0)
160 ret |= err << (15 - i);
166 /* disable EPROM programming */
167 write_nic_byte_E(dev, EPROM_CMD,
168 (EPROM_CMD_NORMAL << EPROM_CMD_OPERATING_MODE_SHIFT));