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