Home | History | Annotate | Line # | Download | only in sparc
      1 /*	$NetBSD: eeprom.c,v 1.10 2021/01/24 07:36:54 mrg 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.10 2021/01/24 07:36:54 mrg 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 <sys/bus.h>
     53 #include <machine/autoconf.h>
     54 #include <machine/eeprom.h>
     55 
     56 #include <dev/clock_subr.h>
     57 
     58 static int	eeprom_match(device_t, cfdata_t, void *);
     59 static void	eeprom_attach(device_t, device_t, void *);
     60 
     61 CFATTACH_DECL_NEW(eeprom, 0,
     62     eeprom_match, eeprom_attach, NULL, NULL);
     63 
     64 /* We support only one eeprom device */
     65 static int eeprom_attached;
     66 
     67 /*
     68  * Sun 4/100, 4/200 EEPROM match routine.
     69  */
     70 static int
     71 eeprom_match(device_t parent, cfdata_t cf, void *aux)
     72 {
     73 	union obio_attach_args *uoba = aux;
     74 	struct obio4_attach_args *oba;
     75 
     76 	if (uoba->uoba_isobio4 == 0)
     77 		return (0);
     78 
     79 	if (eeprom_attached)
     80 		/* We support only one eeprom device */
     81 		return (0);
     82 
     83 	/* Only these sun4s have oclock */
     84 	if (!CPU_ISSUN4 ||
     85 	    (cpuinfo.cpu_type != CPUTYP_4_100 &&
     86 	     cpuinfo.cpu_type != CPUTYP_4_200))
     87 		return (0);
     88 
     89 	/* Make sure there is something there */
     90 	oba = &uoba->uoba_oba4;
     91 	return (bus_space_probe(oba->oba_bustag, oba->oba_paddr,
     92 				1,	/* probe size */
     93 				0,	/* offset */
     94 				0,	/* flags */
     95 				NULL, NULL));
     96 }
     97 
     98 static void
     99 eeprom_attach(device_t parent, device_t self, void *aux)
    100 {
    101 #if defined(SUN4)
    102 	union obio_attach_args *uoba = aux;
    103 	struct obio4_attach_args *oba = &uoba->uoba_oba4;
    104 	bus_space_handle_t bh;
    105 
    106 	eeprom_attached = 1;
    107 	printf("\n");
    108 
    109 	if (bus_space_map(oba->oba_bustag,
    110 			  oba->oba_paddr,
    111 			  EEPROM_SIZE,
    112 			  BUS_SPACE_MAP_LINEAR,	/* flags */
    113 			  &bh) != 0) {
    114 		printf("%s: can't map register\n",
    115 			device_xname(self));
    116 		return;
    117 	}
    118 	eeprom_va = (char *)bh;
    119 #endif /* SUN4 */
    120 }
    121