xref: /netbsd/sys/arch/sparc/sparc/eeprom.c (revision 6550d01e)
1 /*	$NetBSD: eeprom.c,v 1.7 2008/04/28 20:23:36 martin Exp $ */
2 
3 /*-
4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Paul Kranenburg.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * eeprom driver. Sun 4 machines use the old-style (a'la Sun 3) EEPROM.
34  * On the 4/100's and 4/200's, this is at a separate obio space.
35  * On the 4/300's and 4/400's, however, it is the cl_nvram[] chunk of
36  * the Mostek chip.  Therefore, eeprom_match will only return true on
37  * the 100/200 models, and the eeprom will be attached separately.
38  * On the 300/400 models, the eeprom will be dealt with when the clock
39  * is attached.
40  */
41 
42 #include <sys/cdefs.h>
43 __KERNEL_RCSID(0, "$NetBSD: eeprom.c,v 1.7 2008/04/28 20:23:36 martin Exp $");
44 
45 #include "opt_sparc_arch.h"
46 
47 #include <sys/param.h>
48 #include <sys/kernel.h>
49 #include <sys/device.h>
50 #include <sys/systm.h>
51 
52 #include <machine/bus.h>
53 #include <machine/autoconf.h>
54 #include <machine/eeprom.h>
55 
56 #include <dev/clock_subr.h>
57 
58 /* Imported from clock.c: */
59 extern char	*eeprom_va;
60 
61 static int	eeprom_match(struct device *, struct cfdata *, void *);
62 static void	eeprom_attach(struct device *, struct device *, void *);
63 
64 CFATTACH_DECL(eeprom, sizeof(struct device),
65     eeprom_match, eeprom_attach, NULL, NULL);
66 
67 /* We support only one eeprom device */
68 static int eeprom_attached;
69 
70 /*
71  * Sun 4/100, 4/200 EEPROM match routine.
72  */
73 static int
74 eeprom_match(struct device *parent, struct cfdata *cf, void *aux)
75 {
76 	union obio_attach_args *uoba = aux;
77 	struct obio4_attach_args *oba;
78 
79 	if (uoba->uoba_isobio4 == 0)
80 		return (0);
81 
82 	if (eeprom_attached)
83 		/* We support only one eeprom device */
84 		return (0);
85 
86 	/* Only these sun4s have oclock */
87 	if (!CPU_ISSUN4 ||
88 	    (cpuinfo.cpu_type != CPUTYP_4_100 &&
89 	     cpuinfo.cpu_type != CPUTYP_4_200))
90 		return (0);
91 
92 	/* Make sure there is something there */
93 	oba = &uoba->uoba_oba4;
94 	return (bus_space_probe(oba->oba_bustag, oba->oba_paddr,
95 				1,	/* probe size */
96 				0,	/* offset */
97 				0,	/* flags */
98 				NULL, NULL));
99 }
100 
101 static void
102 eeprom_attach(struct device *parent, struct device *self, void *aux)
103 {
104 #if defined(SUN4)
105 	union obio_attach_args *uoba = aux;
106 	struct obio4_attach_args *oba = &uoba->uoba_oba4;
107 	bus_space_handle_t bh;
108 
109 	eeprom_attached = 1;
110 	printf("\n");
111 
112 	if (bus_space_map(oba->oba_bustag,
113 			  oba->oba_paddr,
114 			  EEPROM_SIZE,
115 			  BUS_SPACE_MAP_LINEAR,	/* flags */
116 			  &bh) != 0) {
117 		printf("%s: can't map register\n", self->dv_xname);
118 		return;
119 	}
120 	eeprom_va = (char *)bh;
121 #endif /* SUN4 */
122 }
123