Home | History | Annotate | Line # | Download | only in vsa
leds.c revision 1.3
      1 /*	$NetBSD: leds.c,v 1.3 2003/07/15 02:15:07 lukem Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Gordon W. Ross and der Mouse.
      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  * Functions to flash the LEDs with some pattern.
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: leds.c,v 1.3 2003/07/15 02:15:07 lukem Exp $");
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/device.h>
     49 #include <sys/conf.h>
     50 #include <sys/buf.h>
     51 #include <sys/malloc.h>
     52 #include <sys/proc.h>
     53 
     54 #include <machine/cpu.h>
     55 #include <machine/sid.h>
     56 #include <machine/leds.h>
     57 
     58 #include "opt_cputype.h"
     59 
     60 static volatile u_short *diagreg = 0;
     61 static u_char led_countdown = 0;
     62 static u_char led_px = 0;
     63 
     64 /*
     65  * Initial value is the default pattern set.
     66  */
     67 static struct led_patterns ledpat = {
     68 	16,	/* divisor */
     69 	12,	/* patlen */
     70 	{	/* patterns */
     71 		0x03, 0x06, 0x0c, 0x18,
     72 		0x30, 0x60, 0xc0, 0x60,
     73 		0x30, 0x18, 0x0c, 0x06,
     74 	}
     75 };
     76 
     77 void
     78 ledsattach(int a)
     79 {
     80 	switch (vax_boardtype) {
     81 #if VAX46 || VAXANY
     82 	case VAX_BTYP_46: {
     83 		extern struct vs_cpu *ka46_cpu;
     84 		diagreg = (volatile u_short *)(&ka46_cpu->vc_diagdsp);
     85 		break;
     86 		}
     87 #endif
     88 #if VAX48 || VAXANY
     89 	case VAX_BTYP_48: {
     90 		extern struct vs_cpu *ka48_cpu;
     91 		diagreg = (volatile u_short *)(&ka48_cpu->vc_diagdsp);
     92 		break;
     93 		}
     94 #endif
     95 #if VAX49 || VAXANY
     96 	case VAX_BTYP_49:
     97 		diagreg = (volatile u_short *)vax_map_physmem(0x25800000, 1);
     98 		diagreg += 2;
     99 		break;
    100 #endif
    101 	default:
    102 		return;
    103 	}
    104 
    105 	/* Turn on some lights. */
    106 	leds_intr();
    107 }
    108 
    109 /*
    110  * This is called by the clock interrupt.
    111  */
    112 void
    113 leds_intr()
    114 {
    115 	register u_char i;
    116 
    117 	if (diagreg == 0)
    118 		return;
    119 
    120 	if (led_countdown) {
    121 		led_countdown--;
    122 		return;
    123 	}
    124 
    125 	led_countdown = ledpat.divisor - 1;
    126 	i = led_px;
    127 
    128 	*diagreg = ~ledpat.pat[i];
    129 
    130 	i = i+1;
    131 	if (i == ledpat.patlen)
    132 		i = 0;
    133 	led_px = i;
    134 }
    135 
    136 /*
    137  * This is called by mem.c to handle /dev/leds
    138  */
    139 int
    140 leds_uio(struct uio *uio)
    141 {
    142 	int cnt, error;
    143 	int off;	/* NOT off_t */
    144 	caddr_t va;
    145 
    146 	off = uio->uio_offset;
    147 	if ((off < 0) || (off > sizeof(ledpat)))
    148 		return (EIO);
    149 
    150 	cnt = min(uio->uio_resid, (sizeof(ledpat) - off));
    151 	if (cnt == 0)
    152 		return (0); /* EOF */
    153 
    154 	va = ((char*)(&ledpat)) + off;
    155 	error = uiomove(va, cnt, uio);
    156 
    157 	return (error);
    158 }
    159 
    160