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