Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 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 | |
| 29 | #if !defined(SMC91C96_BASE_ADDR) || !defined(SMC91C96_IRQ) |
| 30 | #error need to define SMC91C96_BASE_ADDR and SMC91C96_IRQ in project |
| 31 | #endif |
| 32 | |
| 33 | static addr_t smc91c96_base = SMC91C96_BASE_ADDR; |
| 34 | static uint8_t mac_addr[6]; |
| 35 | |
| 36 | #define SMC_REG16(reg) ((volatile uint16_t *)(smc91c96_base + (reg))) |
| 37 | #define SMC_REG8(reg) ((volatile uint8_t *)(smc91c96_base + (reg))) |
| 38 | |
| 39 | static inline void smc_bank(int bank) |
| 40 | { |
| 41 | *SMC_REG16(SMC_BSR) = bank; |
| 42 | } |
| 43 | |
| 44 | void smc91c96_init(void) |
| 45 | { |
| 46 | int i; |
| 47 | |
| 48 | TRACE; |
| 49 | |
| 50 | // try to detect it |
| 51 | if ((*SMC_REG16(SMC_BSR) & 0xff00) != 0x3300) { |
| 52 | TRACEF("didn't see smc91c96 chip at 0x%x\n", (unsigned int)smc91c96_base); |
| 53 | } |
| 54 | |
| 55 | // read revision |
| 56 | smc_bank(3); |
| 57 | TRACEF("detected, revision 0x%x\n", *SMC_REG16(SMC_REV)); |
| 58 | |
| 59 | // read in the mac address |
| 60 | smc_bank(1); |
| 61 | for (i=0; i < 6; i++) { |
| 62 | mac_addr[i] = *SMC_REG8(SMC_IAR0 + i); |
| 63 | } |
| 64 | TRACEF("mac address %02x:%02x:%02x:%02x:%02x:%02x\n", |
| 65 | mac_addr[0], mac_addr[1], mac_addr[2], |
| 66 | mac_addr[3], mac_addr[4], mac_addr[5]); |
| 67 | |
| 68 | smc_bank(0); |
| 69 | } |
| 70 | |