1 /* $NetBSD: leds.c,v 1.3 2003/07/15 03:36:12 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 * All other Sun2 machines have an 8-position LED 42 * array in which some pattern is animated. 43 */ 44 45 #include <sys/cdefs.h> 46 __KERNEL_RCSID(0, "$NetBSD: leds.c,v 1.3 2003/07/15 03:36:12 lukem Exp $"); 47 48 #include <sys/param.h> 49 #include <sys/systm.h> 50 #include <sys/device.h> 51 #include <sys/conf.h> 52 #include <sys/buf.h> 53 #include <sys/malloc.h> 54 #include <sys/proc.h> 55 56 #include <machine/autoconf.h> 57 #include <machine/idprom.h> 58 #include <machine/leds.h> 59 60 #include <sun2/sun2/machdep.h> 61 #include <sun2/sun2/control.h> 62 63 static u_char led_countdown = 0; 64 static u_char led_px = 0; 65 66 /* 67 * Initial value is the default pattern set. 68 */ 69 static struct led_patterns ledpat = { 70 8, /* divisor */ 71 8, /* patlen */ 72 { /* patterns */ 73 0x0F, 0x1E, 0x3C, 0x78, 74 0xF0, 0xE1, 0xC3, 0x87, 75 } 76 }; 77 78 /* 79 * This is called early during startup to find the 80 * diag register (LEDs) and turn on the light(s). 81 */ 82 void 83 leds_init() 84 { 85 86 /* Turn on some lights. */ 87 leds_intr(); 88 } 89 90 /* 91 * This is called by the clock interrupt. 92 */ 93 void 94 leds_intr() 95 { 96 u_char i; 97 98 if (led_countdown) { 99 led_countdown--; 100 return; 101 } 102 103 led_countdown = ledpat.divisor - 1; 104 i = led_px; 105 106 set_control_byte(DIAG_REG, ledpat.pat[i]); 107 108 i = i+1; 109 if (i == ledpat.patlen) 110 i = 0; 111 led_px = i; 112 } 113 114 /* 115 * This is called by mem.c to handle /dev/leds 116 */ 117 int 118 leds_uio(struct uio *uio) 119 { 120 int cnt, error; 121 int off; /* NOT off_t */ 122 caddr_t va; 123 124 off = uio->uio_offset; 125 if ((off < 0) || (off > sizeof(ledpat))) 126 return (EIO); 127 128 cnt = min(uio->uio_resid, (sizeof(ledpat) - off)); 129 if (cnt == 0) 130 return (0); /* EOF */ 131 132 va = ((char*)(&ledpat)) + off; 133 error = uiomove(va, cnt, uio); 134 135 return (error); 136 } 137