1 /* $NetBSD: eeprom.c,v 1.1 2002/03/28 11:54:17 pk 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * eeprom driver. Sun 4 machines use the old-style (a'la Sun 3) EEPROM. 41 * On the 4/100's and 4/200's, this is at a separate obio space. 42 * On the 4/300's and 4/400's, however, it is the cl_nvram[] chunk of 43 * the Mostek chip. Therefore, eeprom_match will only return true on 44 * the 100/200 models, and the eeprom will be attached separately. 45 * On the 300/400 models, the eeprom will be dealt with when the clock 46 * is attached. 47 */ 48 #include "opt_sparc_arch.h" 49 50 #include <sys/param.h> 51 #include <sys/kernel.h> 52 #include <sys/device.h> 53 #include <sys/systm.h> 54 55 #include <machine/bus.h> 56 #include <machine/autoconf.h> 57 #include <machine/eeprom.h> 58 59 #include <dev/clock_subr.h> 60 61 /* Imported from clock.c: */ 62 extern char *eeprom_va; 63 64 static int eeprom_match(struct device *, struct cfdata *, void *); 65 static void eeprom_attach(struct device *, struct device *, void *); 66 67 struct cfattach eeprom_ca = { 68 sizeof(struct device), eeprom_match, eeprom_attach 69 }; 70 71 72 /* We support only one eeprom device */ 73 static int eeprom_attached; 74 75 /* 76 * Sun 4/100, 4/200 EEPROM match routine. 77 */ 78 static int 79 eeprom_match(parent, cf, aux) 80 struct device *parent; 81 struct cfdata *cf; 82 void *aux; 83 { 84 union obio_attach_args *uoba = aux; 85 struct obio4_attach_args *oba; 86 87 if (uoba->uoba_isobio4 == 0) 88 return (0); 89 90 if (eeprom_attached) 91 /* We support only one eeprom device */ 92 return (0); 93 94 /* Only these sun4s have oclock */ 95 if (!CPU_ISSUN4 || 96 (cpuinfo.cpu_type != CPUTYP_4_100 && 97 cpuinfo.cpu_type != CPUTYP_4_200)) 98 return (0); 99 100 /* Make sure there is something there */ 101 oba = &uoba->uoba_oba4; 102 return (bus_space_probe(oba->oba_bustag, oba->oba_paddr, 103 1, /* probe size */ 104 0, /* offset */ 105 0, /* flags */ 106 NULL, NULL)); 107 } 108 109 static void 110 eeprom_attach(parent, self, aux) 111 struct device *parent, *self; 112 void *aux; 113 { 114 #if defined(SUN4) 115 union obio_attach_args *uoba = aux; 116 struct obio4_attach_args *oba = &uoba->uoba_oba4; 117 bus_space_handle_t bh; 118 119 eeprom_attached = 1; 120 printf("\n"); 121 122 if (bus_space_map(oba->oba_bustag, 123 oba->oba_paddr, 124 EEPROM_SIZE, 125 BUS_SPACE_MAP_LINEAR, /* flags */ 126 &bh) != 0) { 127 printf("%s: can't map register\n", self->dv_xname); 128 return; 129 } 130 eeprom_va = (char *)bh; 131 #endif /* SUN4 */ 132 } 133