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_sbus.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 <sparc64/sbus/sbusvar.h>
77
78 #include "clock_if.h"
79
80 static int eeprom_sbus_probe(device_t);
81 static int eeprom_sbus_attach(device_t);
82
83 static device_method_t eeprom_sbus_methods[] = {
84 /* Device interface */
85 DEVMETHOD(device_probe, eeprom_sbus_probe),
86 DEVMETHOD(device_attach, eeprom_sbus_attach),
87
88 /* clock interface */
89 DEVMETHOD(clock_gettime, mk48txx_gettime),
90 DEVMETHOD(clock_settime, mk48txx_settime),
91
92 { 0, 0 }
93 };
94
95 static driver_t eeprom_sbus_driver = {
96 "eeprom",
97 eeprom_sbus_methods,
98 0,
99 };
100
101 DRIVER_MODULE(eeprom, sbus, eeprom_sbus_driver, eeprom_devclass, 0, 0);
102
103
104 static int
105 eeprom_sbus_probe(device_t dev)
106 {
107
108 if (strcmp("eeprom", sbus_get_name(dev)) == 0) {
109 device_set_desc(dev, "SBus EEPROM/clock");
110 return (0);
111 }
112 return (ENXIO);
113 }
114
115 /*
116 * Attach a clock (really `eeprom') to the sbus.
117 *
118 * This is mapped read-only on NetBSD for safety, but this is not possible
119 * with the current FreeBSD bus code.
120 *
121 * the MK48T02 is 2K. the MK48T08 is 8K, and the MK48T59 is supposed to be
122 * identical to it.
123 */
124 static int
125 eeprom_sbus_attach(device_t dev)
126 {
127 struct resource *res;
128 int rid, error;
129
130 rid = 0;
131 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0UL, ~0UL, 1,
132 RF_ACTIVE);
133 if (res == NULL) {
134 device_printf(dev, "could not allocate resources\n");
135 return (ENXIO);
136 }
137 error = eeprom_attach(dev, sbus_get_node(dev), rman_get_bustag(res),
138 rman_get_bushandle(res));
139 return (error);
140 }
Cache object: b786648d90bd3d026d779da8e6172351
|