]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sparc64/sparc64/eeprom.c
Remove bt(4) driver
[FreeBSD/FreeBSD.git] / sys / sparc64 / sparc64 / eeprom.c
1 /*-
2  * SPDX-License-Identifier: BSD-4-Clause
3  *
4  * Copyright (c) 1992, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  * Copyright (c) 1994 Gordon W. Ross
7  * Copyright (c) 1993 Adam Glass
8  * Copyright (c) 1996 Paul Kranenburg
9  * Copyright (c) 1996
10  *      The President and Fellows of Harvard College. All rights reserved.
11  *
12  * This software was developed by the Computer Systems Engineering group
13  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
14  * contributed to Berkeley.
15  *
16  * All advertising materials mentioning features or use of this software
17  * must display the following acknowledgement:
18  *      This product includes software developed by Harvard University.
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 Paul Kranenburg.
32  *      This product includes software developed by Harvard University.
33  * 4. Neither the name of the University nor the names of its contributors
34  *    may be used to endorse or promote products derived from this software
35  *    without specific prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
38  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
41  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  *
49  *      from: @(#)clock.c       8.1 (Berkeley) 6/11/93
50  *      from: NetBSD: clock.c,v 1.41 2001/07/24 19:29:25 eeh Exp
51  */
52
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
55
56 /*
57  * clock (eeprom) attaches at EBus, FireHose or SBus
58  */
59
60 #include <sys/param.h>
61 #include <sys/systm.h>
62 #include <sys/bus.h>
63 #include <sys/eventhandler.h>
64 #include <sys/kernel.h>
65 #include <sys/lock.h>
66 #include <sys/module.h>
67 #include <sys/mutex.h>
68 #include <sys/resource.h>
69
70 #include <dev/ofw/ofw_bus.h>
71
72 #include <machine/bus.h>
73 #include <machine/resource.h>
74 #include <machine/ver.h>
75
76 #include <sys/rman.h>
77
78 #include <dev/mk48txx/mk48txxvar.h>
79
80 #include "clock_if.h"
81
82 static devclass_t eeprom_devclass;
83
84 static device_probe_t eeprom_probe;
85 static device_attach_t eeprom_attach;
86
87 static device_method_t eeprom_methods[] = {
88         /* Device interface */
89         DEVMETHOD(device_probe,         eeprom_probe),
90         DEVMETHOD(device_attach,        eeprom_attach),
91
92         /* clock interface */
93         DEVMETHOD(clock_gettime,        mk48txx_gettime),
94         DEVMETHOD(clock_settime,        mk48txx_settime),
95
96         DEVMETHOD_END
97 };
98
99 static driver_t eeprom_driver = {
100         "eeprom",
101         eeprom_methods,
102         sizeof(struct mk48txx_softc),
103 };
104
105 DRIVER_MODULE(eeprom, ebus, eeprom_driver, eeprom_devclass, 0, 0);
106 DRIVER_MODULE(eeprom, fhc, eeprom_driver, eeprom_devclass, 0, 0);
107 DRIVER_MODULE(eeprom, sbus, eeprom_driver, eeprom_devclass, 0, 0);
108
109 static int
110 eeprom_probe(device_t dev)
111 {
112         const char *name;
113
114         name = ofw_bus_get_name(dev);
115         if (strcmp(name, "eeprom") == 0 ||
116             strcmp(name, "FJSV,eeprom") == 0) {
117                 device_set_desc(dev, "EEPROM/clock");
118                 return (0);
119         }
120         return (ENXIO);
121 }
122
123 static int
124 eeprom_attach(device_t dev)
125 {
126         struct mk48txx_softc *sc;
127         struct timespec ts;
128         int error, rid;
129
130         sc = device_get_softc(dev);
131
132         mtx_init(&sc->sc_mtx, "eeprom_mtx", NULL, MTX_DEF);
133
134         rid = 0;
135         sc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
136             RF_ACTIVE);
137         if (sc->sc_res == NULL) {
138                 device_printf(dev, "cannot allocate resources\n");
139                 error = ENXIO;
140                 goto fail_mtx;
141         }
142
143         if ((sc->sc_model = ofw_bus_get_model(dev)) == NULL) {
144                 device_printf(dev, "cannot determine model\n");
145                 error = ENXIO;
146                 goto fail_res;
147         }
148
149         /* Our TOD clock year 0 is 1968. */
150         sc->sc_year0 = 1968;
151         /* Use default register read/write functions. */
152         sc->sc_flag = 0;
153         /*
154          * Generally, if the `eeprom' node has a `watchdog-enable' property
155          * this indicates that the watchdog part of the MK48T59 is usable,
156          * i.e. its RST pin is connected to the WDR input of the CPUs or
157          * something. The `eeprom' nodes of E250, E450 and the clock board
158          * variant in Exx00 have such properties. For E250 and E450 the
159          * watchdog just works, for Exx00 the delivery of the reset signal
160          * apparently has to be additionally enabled elsewhere...
161          * The OFW environment variable `watchdog-reboot?' is ignored for
162          * these watchdogs as they always trigger a system reset when they
163          * time out and can't be made to issue a break to the boot monitor
164          * instead.
165          */
166         if (OF_getproplen(ofw_bus_get_node(dev), "watchdog-enable") != -1 &&
167             (strcmp(sparc64_model, "SUNW,Ultra-250") == 0 ||
168             strcmp(sparc64_model, "SUNW,Ultra-4") == 0))
169                 sc->sc_flag |= MK48TXX_WDOG_REGISTER | MK48TXX_WDOG_ENABLE_WDS;
170         if ((error = mk48txx_attach(dev)) != 0) {
171                 device_printf(dev, "cannot attach time of day clock\n");
172                 goto fail_res;
173         }
174
175         if (bootverbose) {
176                 if (mk48txx_gettime(dev, &ts) != 0)
177                         device_printf(dev, "invalid time");
178                 else
179                         device_printf(dev, "current time: %ld.%09ld\n",
180                             (long)ts.tv_sec, ts.tv_nsec);
181         }
182
183         return (0);
184
185  fail_res:
186         bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->sc_res);
187  fail_mtx:
188         mtx_destroy(&sc->sc_mtx);
189
190         return (error);
191 }