ax88796.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * (c) 2007 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <common.h>
  19. #include "ax88796.h"
  20. /*
  21. * Set 1 bit data
  22. */
  23. static void ax88796_bitset(u32 bit)
  24. {
  25. /* DATA1 */
  26. if( bit )
  27. EEDI_HIGH;
  28. else
  29. EEDI_LOW;
  30. EECLK_LOW;
  31. udelay(1000);
  32. EECLK_HIGH;
  33. udelay(1000);
  34. EEDI_LOW;
  35. }
  36. /*
  37. * Get 1 bit data
  38. */
  39. static u8 ax88796_bitget(void)
  40. {
  41. u8 bit;
  42. EECLK_LOW;
  43. udelay(1000);
  44. /* DATA */
  45. bit = EEDO;
  46. EECLK_HIGH;
  47. udelay(1000);
  48. return bit;
  49. }
  50. /*
  51. * Send COMMAND to EEPROM
  52. */
  53. static void ax88796_eep_cmd(u8 cmd)
  54. {
  55. ax88796_bitset(BIT_DUMMY);
  56. switch(cmd){
  57. case MAC_EEP_READ:
  58. ax88796_bitset(1);
  59. ax88796_bitset(1);
  60. ax88796_bitset(0);
  61. break;
  62. case MAC_EEP_WRITE:
  63. ax88796_bitset(1);
  64. ax88796_bitset(0);
  65. ax88796_bitset(1);
  66. break;
  67. case MAC_EEP_ERACE:
  68. ax88796_bitset(1);
  69. ax88796_bitset(1);
  70. ax88796_bitset(1);
  71. break;
  72. case MAC_EEP_EWEN:
  73. ax88796_bitset(1);
  74. ax88796_bitset(0);
  75. ax88796_bitset(0);
  76. break;
  77. case MAC_EEP_EWDS:
  78. ax88796_bitset(1);
  79. ax88796_bitset(0);
  80. ax88796_bitset(0);
  81. break;
  82. default:
  83. break;
  84. }
  85. }
  86. static void ax88796_eep_setaddr(u16 addr)
  87. {
  88. int i ;
  89. for( i = 7 ; i >= 0 ; i-- )
  90. ax88796_bitset(addr & (1 << i));
  91. }
  92. /*
  93. * Get data from EEPROM
  94. */
  95. static u16 ax88796_eep_getdata(void)
  96. {
  97. ushort data = 0;
  98. int i;
  99. ax88796_bitget(); /* DUMMY */
  100. for( i = 0 ; i < 16 ; i++ ){
  101. data <<= 1;
  102. data |= ax88796_bitget();
  103. }
  104. return data;
  105. }
  106. static void ax88796_mac_read(u8 *buff)
  107. {
  108. int i ;
  109. u16 data;
  110. u16 addr = 0;
  111. for( i = 0 ; i < 3; i++ )
  112. {
  113. EECS_HIGH;
  114. EEDI_LOW;
  115. udelay(1000);
  116. /* READ COMMAND */
  117. ax88796_eep_cmd(MAC_EEP_READ);
  118. /* ADDRESS */
  119. ax88796_eep_setaddr(addr++);
  120. /* GET DATA */
  121. data = ax88796_eep_getdata();
  122. *buff++ = (uchar)(data & 0xff);
  123. *buff++ = (uchar)((data >> 8) & 0xff);
  124. EECLK_LOW;
  125. EEDI_LOW;
  126. EECS_LOW;
  127. }
  128. }
  129. int get_prom(u8* mac_addr)
  130. {
  131. u8 prom[32];
  132. int i;
  133. ax88796_mac_read(prom);
  134. for (i = 0; i < 6; i++){
  135. mac_addr[i] = prom[i];
  136. }
  137. return 1;
  138. }