Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 1 | /* |
| 2 | This files contains card eeprom (93c46 or 93c56) programming routines, |
| 3 | memory is addressed by 16 bits words. |
| 4 | |
| 5 | This is part of rtl8180 OpenSource driver. |
Andrea Merello | 559a4c3 | 2013-08-26 13:53:30 +0200 | [diff] [blame] | 6 | Copyright (C) Andrea Merello 2004 <andrea.merello@gmail.com> |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 7 | Released under the terms of GPL (General Public Licence) |
| 8 | |
| 9 | Parts of this driver are based on the GPL part of the |
| 10 | official realtek driver. |
| 11 | |
| 12 | Parts of this driver are based on the rtl8180 driver skeleton |
| 13 | from Patric Schenke & Andres Salomon. |
| 14 | |
| 15 | Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver. |
| 16 | |
Justin P. Mattock | ffae305 | 2012-04-30 13:45:41 -0700 | [diff] [blame] | 17 | We want to thank the Authors of those projects and the Ndiswrapper |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 18 | project Authors. |
| 19 | */ |
| 20 | |
| 21 | #include "r8180_93cx6.h" |
| 22 | |
Ana Rey | f6bd19e | 2014-03-13 12:36:37 +0100 | [diff] [blame] | 23 | static void eprom_cs(struct net_device *dev, short bit) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 24 | { |
Xenia Ragiadakou | b3d42bf | 2013-06-06 16:40:51 +0300 | [diff] [blame] | 25 | u8 cmdreg; |
| 26 | |
| 27 | read_nic_byte_E(dev, EPROM_CMD, &cmdreg); |
Xenia Ragiadakou | fcd9f35 | 2013-05-13 20:15:49 +0300 | [diff] [blame] | 28 | if (bit) |
Xenia Ragiadakou | b3d42bf | 2013-06-06 16:40:51 +0300 | [diff] [blame] | 29 | /* enable EPROM */ |
| 30 | write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_CS_BIT); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 31 | else |
Xenia Ragiadakou | b3d42bf | 2013-06-06 16:40:51 +0300 | [diff] [blame] | 32 | /* disable EPROM */ |
| 33 | write_nic_byte_E(dev, EPROM_CMD, cmdreg & ~EPROM_CS_BIT); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 34 | |
| 35 | force_pci_posting(dev); |
| 36 | udelay(EPROM_DELAY); |
| 37 | } |
| 38 | |
| 39 | |
Ana Rey | f6bd19e | 2014-03-13 12:36:37 +0100 | [diff] [blame] | 40 | static void eprom_ck_cycle(struct net_device *dev) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 41 | { |
Xenia Ragiadakou | b3d42bf | 2013-06-06 16:40:51 +0300 | [diff] [blame] | 42 | u8 cmdreg; |
| 43 | |
| 44 | read_nic_byte_E(dev, EPROM_CMD, &cmdreg); |
| 45 | write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_CK_BIT); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 46 | force_pci_posting(dev); |
| 47 | udelay(EPROM_DELAY); |
Xenia Ragiadakou | b3d42bf | 2013-06-06 16:40:51 +0300 | [diff] [blame] | 48 | |
| 49 | read_nic_byte_E(dev, EPROM_CMD, &cmdreg); |
| 50 | write_nic_byte_E(dev, EPROM_CMD, cmdreg & ~EPROM_CK_BIT); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 51 | force_pci_posting(dev); |
| 52 | udelay(EPROM_DELAY); |
| 53 | } |
| 54 | |
| 55 | |
Ana Rey | f6bd19e | 2014-03-13 12:36:37 +0100 | [diff] [blame] | 56 | static void eprom_w(struct net_device *dev,short bit) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 57 | { |
Xenia Ragiadakou | b3d42bf | 2013-06-06 16:40:51 +0300 | [diff] [blame] | 58 | u8 cmdreg; |
| 59 | |
| 60 | read_nic_byte_E(dev, EPROM_CMD, &cmdreg); |
Xenia Ragiadakou | fcd9f35 | 2013-05-13 20:15:49 +0300 | [diff] [blame] | 61 | if (bit) |
Xenia Ragiadakou | b3d42bf | 2013-06-06 16:40:51 +0300 | [diff] [blame] | 62 | write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_W_BIT); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 63 | else |
Xenia Ragiadakou | b3d42bf | 2013-06-06 16:40:51 +0300 | [diff] [blame] | 64 | write_nic_byte_E(dev, EPROM_CMD, cmdreg & ~EPROM_W_BIT); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 65 | |
| 66 | force_pci_posting(dev); |
| 67 | udelay(EPROM_DELAY); |
| 68 | } |
| 69 | |
| 70 | |
Ana Rey | f6bd19e | 2014-03-13 12:36:37 +0100 | [diff] [blame] | 71 | static short eprom_r(struct net_device *dev) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 72 | { |
Xenia Ragiadakou | b3d42bf | 2013-06-06 16:40:51 +0300 | [diff] [blame] | 73 | u8 bit; |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 74 | |
Xenia Ragiadakou | b3d42bf | 2013-06-06 16:40:51 +0300 | [diff] [blame] | 75 | read_nic_byte_E(dev, EPROM_CMD, &bit); |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 76 | udelay(EPROM_DELAY); |
| 77 | |
Xenia Ragiadakou | b3d42bf | 2013-06-06 16:40:51 +0300 | [diff] [blame] | 78 | if (bit & EPROM_R_BIT) |
| 79 | return 1; |
| 80 | |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | |
Ana Rey | f6bd19e | 2014-03-13 12:36:37 +0100 | [diff] [blame] | 85 | static void eprom_send_bits_string(struct net_device *dev, short b[], int len) |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 86 | { |
| 87 | int i; |
| 88 | |
| 89 | for(i=0; i<len; i++){ |
| 90 | eprom_w(dev, b[i]); |
| 91 | eprom_ck_cycle(dev); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | |
| 96 | u32 eprom_read(struct net_device *dev, u32 addr) |
| 97 | { |
| 98 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 99 | short read_cmd[]={1,1,0}; |
| 100 | short addr_str[8]; |
| 101 | int i; |
| 102 | int addr_len; |
| 103 | u32 ret; |
| 104 | |
| 105 | ret=0; |
Sebastian Hahn | fdc64a9 | 2012-12-06 12:23:03 +0100 | [diff] [blame] | 106 | //enable EPROM programming |
Jerry Chuang | 8fc8598 | 2009-11-03 07:17:11 -0200 | [diff] [blame] | 107 | write_nic_byte_E(dev, EPROM_CMD, |
| 108 | (EPROM_CMD_PROGRAM<<EPROM_CMD_OPERATING_MODE_SHIFT)); |
| 109 | force_pci_posting(dev); |
| 110 | udelay(EPROM_DELAY); |
| 111 | |
| 112 | if (priv->epromtype==EPROM_93c56){ |
| 113 | addr_str[7]=addr & 1; |
| 114 | addr_str[6]=addr & (1<<1); |
| 115 | addr_str[5]=addr & (1<<2); |
| 116 | addr_str[4]=addr & (1<<3); |
| 117 | addr_str[3]=addr & (1<<4); |
| 118 | addr_str[2]=addr & (1<<5); |
| 119 | addr_str[1]=addr & (1<<6); |
| 120 | addr_str[0]=addr & (1<<7); |
| 121 | addr_len=8; |
| 122 | }else{ |
| 123 | addr_str[5]=addr & 1; |
| 124 | addr_str[4]=addr & (1<<1); |
| 125 | addr_str[3]=addr & (1<<2); |
| 126 | addr_str[2]=addr & (1<<3); |
| 127 | addr_str[1]=addr & (1<<4); |
| 128 | addr_str[0]=addr & (1<<5); |
| 129 | addr_len=6; |
| 130 | } |
| 131 | eprom_cs(dev, 1); |
| 132 | eprom_ck_cycle(dev); |
| 133 | eprom_send_bits_string(dev, read_cmd, 3); |
| 134 | eprom_send_bits_string(dev, addr_str, addr_len); |
| 135 | |
| 136 | //keep chip pin D to low state while reading. |
| 137 | //I'm unsure if it is necessary, but anyway shouldn't hurt |
| 138 | eprom_w(dev, 0); |
| 139 | |
| 140 | for(i=0;i<16;i++){ |
| 141 | //eeprom needs a clk cycle between writing opcode&adr |
| 142 | //and reading data. (eeprom outs a dummy 0) |
| 143 | eprom_ck_cycle(dev); |
| 144 | ret |= (eprom_r(dev)<<(15-i)); |
| 145 | } |
| 146 | |
| 147 | eprom_cs(dev, 0); |
| 148 | eprom_ck_cycle(dev); |
| 149 | |
| 150 | //disable EPROM programming |
| 151 | write_nic_byte_E(dev, EPROM_CMD, |
| 152 | (EPROM_CMD_NORMAL<<EPROM_CMD_OPERATING_MODE_SHIFT)); |
| 153 | return ret; |
| 154 | } |