1 /* 2 * Copyright (c) 2008 Travis Geiselbrecht 3 * 4 * Use of this source code is governed by a MIT-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/MIT 7 */ 8 #include <sys/types.h> 9 #include <lk/debug.h> 10 #include <lk/trace.h> 11 #include <stdio.h> 12 #include <dev/net/smc91c96.h> 13 #include "smc91c96_p.h" 14 15 #if !defined(SMC91C96_BASE_ADDR) || !defined(SMC91C96_IRQ) 16 #error need to define SMC91C96_BASE_ADDR and SMC91C96_IRQ in project 17 #endif 18 19 static addr_t smc91c96_base = SMC91C96_BASE_ADDR; 20 static uint8_t mac_addr[6]; 21 22 #define SMC_REG16(reg) ((volatile uint16_t *)(smc91c96_base + (reg))) 23 #define SMC_REG8(reg) ((volatile uint8_t *)(smc91c96_base + (reg))) 24 smc_bank(int bank)25static inline void smc_bank(int bank) { 26 *SMC_REG16(SMC_BSR) = bank; 27 } 28 smc91c96_init(void)29void smc91c96_init(void) { 30 int i; 31 32 TRACE; 33 34 // try to detect it 35 if ((*SMC_REG16(SMC_BSR) & 0xff00) != 0x3300) { 36 TRACEF("didn't see smc91c96 chip at 0x%x\n", (unsigned int)smc91c96_base); 37 } 38 39 // read revision 40 smc_bank(3); 41 TRACEF("detected, revision 0x%x\n", *SMC_REG16(SMC_REV)); 42 43 // read in the mac address 44 smc_bank(1); 45 for (i=0; i < 6; i++) { 46 mac_addr[i] = *SMC_REG8(SMC_IAR0 + i); 47 } 48 TRACEF("mac address %02x:%02x:%02x:%02x:%02x:%02x\n", 49 mac_addr[0], mac_addr[1], mac_addr[2], 50 mac_addr[3], mac_addr[4], mac_addr[5]); 51 52 smc_bank(0); 53 } 54 55