Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jean-Christophe PLAGNIOL-VILLARD | d87c24f | 2008-04-24 07:57:17 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (c) 2007 Nobuhiro Iwamatsu <iwamatsu@nigauri.org> |
Jean-Christophe PLAGNIOL-VILLARD | d87c24f | 2008-04-24 07:57:17 +0200 | [diff] [blame] | 4 | */ |
| 5 | #include <common.h> |
| 6 | #include "ax88796.h" |
| 7 | |
| 8 | /* |
| 9 | * Set 1 bit data |
| 10 | */ |
| 11 | static void ax88796_bitset(u32 bit) |
| 12 | { |
| 13 | /* DATA1 */ |
| 14 | if( bit ) |
| 15 | EEDI_HIGH; |
| 16 | else |
| 17 | EEDI_LOW; |
| 18 | |
| 19 | EECLK_LOW; |
| 20 | udelay(1000); |
| 21 | EECLK_HIGH; |
| 22 | udelay(1000); |
| 23 | EEDI_LOW; |
| 24 | } |
| 25 | |
| 26 | /* |
| 27 | * Get 1 bit data |
| 28 | */ |
| 29 | static u8 ax88796_bitget(void) |
| 30 | { |
| 31 | u8 bit; |
| 32 | |
| 33 | EECLK_LOW; |
| 34 | udelay(1000); |
| 35 | /* DATA */ |
| 36 | bit = EEDO; |
| 37 | EECLK_HIGH; |
| 38 | udelay(1000); |
| 39 | |
| 40 | return bit; |
| 41 | } |
| 42 | |
| 43 | /* |
| 44 | * Send COMMAND to EEPROM |
| 45 | */ |
| 46 | static void ax88796_eep_cmd(u8 cmd) |
| 47 | { |
| 48 | ax88796_bitset(BIT_DUMMY); |
| 49 | switch(cmd){ |
| 50 | case MAC_EEP_READ: |
| 51 | ax88796_bitset(1); |
| 52 | ax88796_bitset(1); |
| 53 | ax88796_bitset(0); |
| 54 | break; |
| 55 | |
| 56 | case MAC_EEP_WRITE: |
| 57 | ax88796_bitset(1); |
| 58 | ax88796_bitset(0); |
| 59 | ax88796_bitset(1); |
| 60 | break; |
| 61 | |
| 62 | case MAC_EEP_ERACE: |
| 63 | ax88796_bitset(1); |
| 64 | ax88796_bitset(1); |
| 65 | ax88796_bitset(1); |
| 66 | break; |
| 67 | |
| 68 | case MAC_EEP_EWEN: |
| 69 | ax88796_bitset(1); |
| 70 | ax88796_bitset(0); |
| 71 | ax88796_bitset(0); |
| 72 | break; |
| 73 | |
| 74 | case MAC_EEP_EWDS: |
| 75 | ax88796_bitset(1); |
| 76 | ax88796_bitset(0); |
| 77 | ax88796_bitset(0); |
| 78 | break; |
| 79 | default: |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | static void ax88796_eep_setaddr(u16 addr) |
| 85 | { |
| 86 | int i ; |
| 87 | |
| 88 | for( i = 7 ; i >= 0 ; i-- ) |
| 89 | ax88796_bitset(addr & (1 << i)); |
| 90 | } |
| 91 | |
| 92 | /* |
| 93 | * Get data from EEPROM |
| 94 | */ |
| 95 | static u16 ax88796_eep_getdata(void) |
| 96 | { |
| 97 | ushort data = 0; |
| 98 | int i; |
| 99 | |
| 100 | ax88796_bitget(); /* DUMMY */ |
| 101 | for( i = 0 ; i < 16 ; i++ ){ |
| 102 | data <<= 1; |
| 103 | data |= ax88796_bitget(); |
| 104 | } |
| 105 | return data; |
| 106 | } |
| 107 | |
| 108 | static void ax88796_mac_read(u8 *buff) |
| 109 | { |
| 110 | int i ; |
| 111 | u16 data; |
| 112 | u16 addr = 0; |
| 113 | |
| 114 | for( i = 0 ; i < 3; i++ ) |
| 115 | { |
| 116 | EECS_HIGH; |
| 117 | EEDI_LOW; |
| 118 | udelay(1000); |
| 119 | /* READ COMMAND */ |
| 120 | ax88796_eep_cmd(MAC_EEP_READ); |
| 121 | /* ADDRESS */ |
| 122 | ax88796_eep_setaddr(addr++); |
| 123 | /* GET DATA */ |
| 124 | data = ax88796_eep_getdata(); |
| 125 | *buff++ = (uchar)(data & 0xff); |
| 126 | *buff++ = (uchar)((data >> 8) & 0xff); |
| 127 | EECLK_LOW; |
| 128 | EEDI_LOW; |
| 129 | EECS_LOW; |
| 130 | } |
| 131 | } |
| 132 | |
Nobuhiro Iwamatsu | f909daa | 2008-09-30 15:02:53 +0900 | [diff] [blame] | 133 | int get_prom(u8* mac_addr, u8* base_addr) |
Jean-Christophe PLAGNIOL-VILLARD | d87c24f | 2008-04-24 07:57:17 +0200 | [diff] [blame] | 134 | { |
| 135 | u8 prom[32]; |
| 136 | int i; |
| 137 | |
| 138 | ax88796_mac_read(prom); |
| 139 | for (i = 0; i < 6; i++){ |
| 140 | mac_addr[i] = prom[i]; |
| 141 | } |
| 142 | return 1; |
| 143 | } |