smc91c96.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2008 Travis Geiselbrecht
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <sys/types.h>
  24. #include <debug.h>
  25. #include <printf.h>
  26. #include <dev/net/smc91c96.h>
  27. #include "smc91c96_p.h"
  28. #if !defined(SMC91C96_BASE_ADDR) || !defined(SMC91C96_IRQ)
  29. #error need to define SMC91C96_BASE_ADDR and SMC91C96_IRQ in project
  30. #endif
  31. static addr_t smc91c96_base = SMC91C96_BASE_ADDR;
  32. static uint8_t mac_addr[6];
  33. #define SMC_REG16(reg) ((volatile uint16_t *)(smc91c96_base + (reg)))
  34. #define SMC_REG8(reg) ((volatile uint8_t *)(smc91c96_base + (reg)))
  35. static inline void smc_bank(int bank)
  36. {
  37. *SMC_REG16(SMC_BSR) = bank;
  38. }
  39. void smc91c96_init(void)
  40. {
  41. int i;
  42. TRACE;
  43. // try to detect it
  44. if ((*SMC_REG16(SMC_BSR) & 0xff00) != 0x3300) {
  45. TRACEF("didn't see smc91c96 chip at 0x%x\n", (unsigned int)smc91c96_base);
  46. }
  47. // read revision
  48. smc_bank(3);
  49. TRACEF("detected, revision 0x%x\n", *SMC_REG16(SMC_REV));
  50. // read in the mac address
  51. smc_bank(1);
  52. for (i=0; i < 6; i++) {
  53. mac_addr[i] = *SMC_REG8(SMC_IAR0 + i);
  54. }
  55. TRACEF("mac address %02x:%02x:%02x:%02x:%02x:%02x\n",
  56. mac_addr[0], mac_addr[1], mac_addr[2],
  57. mac_addr[3], mac_addr[4], mac_addr[5]);
  58. smc_bank(0);
  59. }