1 /*
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1994 Gordon W. Ross
5 * Copyright (c) 1993 Adam Glass
6 * Copyright (c) 1996 Paul Kranenburg
7 * Copyright (c) 1996
8 * The President and Fellows of Harvard College. All rights reserved.
9 *
10 * This software was developed by the Computer Systems Engineering group
11 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
12 * contributed to Berkeley.
13 *
14 * All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Harvard University.
17 * This product includes software developed by the University of
18 * California, Lawrence Berkeley Laboratory.
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * 1. Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
29 * 3. All advertising materials mentioning features or use of this software
30 * must display the following acknowledgement:
31 * This product includes software developed by the University of
32 * California, Berkeley and its contributors.
33 * This product includes software developed by Paul Kranenburg.
34 * This product includes software developed by Harvard University.
35 * 4. Neither the name of the University nor the names of its contributors
36 * may be used to endorse or promote products derived from this software
37 * without specific prior written permission.
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
40 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
45 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
48 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 * SUCH DAMAGE.
50 *
51 * from: @(#)clock.c 8.1 (Berkeley) 6/11/93
52 * from: NetBSD: clock.c,v 1.41 2001/07/24 19:29:25 eeh Exp
53 *
54 * $FreeBSD: releng/5.2/sys/sparc64/sparc64/eeprom.c 119352 2003-08-23 05:56:58Z marcel $
55 */
56
57 #include <sys/param.h>
58 #include <sys/systm.h>
59 #include <sys/bus.h>
60 #include <sys/kernel.h>
61 #include <sys/malloc.h>
62 #include <sys/resource.h>
63
64 #include <machine/bus.h>
65 #include <machine/idprom.h>
66 #include <machine/resource.h>
67
68 #include <sys/rman.h>
69
70 #include <dev/ofw/openfirm.h>
71
72 #include <machine/eeprom.h>
73
74 #include <dev/mk48txx/mk48txxreg.h>
75
76 #include "clock_if.h"
77
78 devclass_t eeprom_devclass;
79
80
81 #define IDPROM_OFFSET (8 * 1024 - 40) /* XXX - get nvram size from driver */
82
83 int
84 eeprom_attach(device_t dev, phandle_t node, bus_space_tag_t bt,
85 bus_space_handle_t bh)
86 {
87 struct timespec ts;
88 struct idprom *idp;
89 char *model;
90 int error, i;
91 u_int32_t h;
92
93 if (OF_getprop_alloc(node, "model", 1, (void **)&model) == -1)
94 panic("eeprom_attach: no model property");
95
96 /* Our TOD clock year 0 is 1968 */
97 if ((error = mk48txx_attach(dev, bt, bh, model, 1968)) != 0) {
98 device_printf(dev, "Can't attach %s tod clock", model);
99 free(model, M_OFWPROP);
100 return (error);
101 }
102 /* XXX: register clock device */
103
104 /* Get the host ID from the prom. */
105 idp = (struct idprom *)((u_long)bh + IDPROM_OFFSET);
106 h = bus_space_read_1(bt, bh, IDPROM_OFFSET +
107 offsetof(struct idprom, id_machine)) << 24;
108 for (i = 0; i < 3; i++) {
109 h |= bus_space_read_1(bt, bh, IDPROM_OFFSET +
110 offsetof(struct idprom, id_hostid[i])) << ((2 - i) * 8);
111 }
112 /* XXX: register host id */
113 device_printf(dev, "hostid %x\n", (u_int)h);
114 if (bootverbose) {
115 mk48txx_gettime(dev, &ts);
116 device_printf(dev, "current time: %ld.%09ld\n", (long)ts.tv_sec,
117 ts.tv_nsec);
118 }
119
120 return (0);
121 }
122
Cache object: 7e6f9c1aced18941923d6a4f7300f423
|