Home | History | Annotate | Line # | Download | only in vsa
      1  1.11   thorpej /*	$NetBSD: leds.c,v 1.11 2023/12/20 15:34:46 thorpej Exp $	*/
      2   1.1     ragge 
      3   1.1     ragge /*-
      4   1.1     ragge  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5   1.1     ragge  * All rights reserved.
      6   1.1     ragge  *
      7   1.1     ragge  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1     ragge  * by Gordon W. Ross and der Mouse.
      9   1.1     ragge  *
     10   1.1     ragge  * Redistribution and use in source and binary forms, with or without
     11   1.1     ragge  * modification, are permitted provided that the following conditions
     12   1.1     ragge  * are met:
     13   1.1     ragge  * 1. Redistributions of source code must retain the above copyright
     14   1.1     ragge  *    notice, this list of conditions and the following disclaimer.
     15   1.1     ragge  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1     ragge  *    notice, this list of conditions and the following disclaimer in the
     17   1.1     ragge  *    documentation and/or other materials provided with the distribution.
     18   1.1     ragge  *
     19   1.1     ragge  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1     ragge  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1     ragge  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1     ragge  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1     ragge  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1     ragge  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1     ragge  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1     ragge  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1     ragge  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1     ragge  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1     ragge  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1     ragge  */
     31   1.1     ragge 
     32   1.1     ragge /*
     33   1.1     ragge  * Functions to flash the LEDs with some pattern.
     34   1.1     ragge  */
     35   1.3     lukem 
     36   1.3     lukem #include <sys/cdefs.h>
     37  1.11   thorpej __KERNEL_RCSID(0, "$NetBSD: leds.c,v 1.11 2023/12/20 15:34:46 thorpej Exp $");
     38   1.1     ragge 
     39   1.1     ragge #include <sys/param.h>
     40   1.1     ragge #include <sys/systm.h>
     41   1.9      matt #include <sys/cpu.h>
     42   1.9      matt #include <sys/conf.h>
     43   1.1     ragge #include <sys/device.h>
     44   1.1     ragge #include <sys/proc.h>
     45   1.1     ragge 
     46   1.1     ragge #include <machine/sid.h>
     47   1.1     ragge #include <machine/leds.h>
     48   1.1     ragge 
     49   1.1     ragge #include "opt_cputype.h"
     50   1.1     ragge 
     51   1.1     ragge static volatile u_short *diagreg = 0;
     52   1.1     ragge static u_char led_countdown = 0;
     53   1.1     ragge static u_char led_px = 0;
     54   1.1     ragge 
     55   1.1     ragge /*
     56   1.1     ragge  * Initial value is the default pattern set.
     57   1.1     ragge  */
     58   1.8     jklos struct led_patterns ledpat = {
     59   1.1     ragge 	16,	/* divisor */
     60   1.1     ragge 	12,	/* patlen */
     61   1.1     ragge 	{	/* patterns */
     62   1.1     ragge 		0x03, 0x06, 0x0c, 0x18,
     63   1.1     ragge 		0x30, 0x60, 0xc0, 0x60,
     64   1.1     ragge 		0x30, 0x18, 0x0c, 0x06,
     65   1.1     ragge 	}
     66   1.1     ragge };
     67   1.1     ragge 
     68   1.1     ragge void
     69   1.1     ragge ledsattach(int a)
     70   1.1     ragge {
     71   1.1     ragge 	switch (vax_boardtype) {
     72   1.2      matt #if VAX46 || VAXANY
     73   1.1     ragge 	case VAX_BTYP_46: {
     74   1.1     ragge 		extern struct vs_cpu *ka46_cpu;
     75   1.1     ragge 		diagreg = (volatile u_short *)(&ka46_cpu->vc_diagdsp);
     76   1.1     ragge 		break;
     77   1.1     ragge 		}
     78   1.1     ragge #endif
     79   1.2      matt #if VAX48 || VAXANY
     80   1.1     ragge 	case VAX_BTYP_48: {
     81   1.1     ragge 		extern struct vs_cpu *ka48_cpu;
     82   1.1     ragge 		diagreg = (volatile u_short *)(&ka48_cpu->vc_diagdsp);
     83   1.1     ragge 		break;
     84   1.1     ragge 		}
     85   1.1     ragge #endif
     86   1.2      matt #if VAX49 || VAXANY
     87   1.1     ragge 	case VAX_BTYP_49:
     88   1.1     ragge 		diagreg = (volatile u_short *)vax_map_physmem(0x25800000, 1);
     89   1.1     ragge 		diagreg += 2;
     90   1.1     ragge 		break;
     91   1.1     ragge #endif
     92   1.1     ragge 	default:
     93   1.1     ragge 		return;
     94   1.1     ragge 	}
     95   1.1     ragge 
     96   1.1     ragge 	/* Turn on some lights. */
     97   1.1     ragge 	leds_intr();
     98   1.1     ragge }
     99   1.1     ragge 
    100   1.1     ragge /*
    101   1.1     ragge  * This is called by the clock interrupt.
    102   1.1     ragge  */
    103   1.1     ragge void
    104   1.6      matt leds_intr(void)
    105   1.1     ragge {
    106   1.1     ragge 	register u_char i;
    107   1.1     ragge 
    108   1.1     ragge 	if (diagreg == 0)
    109   1.1     ragge 		return;
    110   1.1     ragge 
    111   1.1     ragge 	if (led_countdown) {
    112   1.1     ragge 		led_countdown--;
    113   1.1     ragge 		return;
    114   1.1     ragge 	}
    115   1.1     ragge 
    116   1.1     ragge 	led_countdown = ledpat.divisor - 1;
    117   1.1     ragge 	i = led_px;
    118   1.1     ragge 
    119   1.1     ragge 	*diagreg = ~ledpat.pat[i];
    120   1.1     ragge 
    121   1.1     ragge 	i = i+1;
    122   1.1     ragge 	if (i == ledpat.patlen)
    123   1.1     ragge 		i = 0;
    124   1.1     ragge 	led_px = i;
    125   1.1     ragge }
    126   1.1     ragge 
    127   1.1     ragge /*
    128   1.1     ragge  * This is called by mem.c to handle /dev/leds
    129   1.1     ragge  */
    130   1.1     ragge int
    131   1.1     ragge leds_uio(struct uio *uio)
    132   1.1     ragge {
    133   1.1     ragge 	int cnt, error;
    134   1.1     ragge 	int off;	/* NOT off_t */
    135   1.8     jklos 	char *va;
    136   1.1     ragge 
    137   1.1     ragge 	off = uio->uio_offset;
    138   1.1     ragge 	if ((off < 0) || (off > sizeof(ledpat)))
    139   1.1     ragge 		return (EIO);
    140   1.1     ragge 
    141  1.10  riastrad 	cnt = uimin(uio->uio_resid, (sizeof(ledpat) - off));
    142   1.1     ragge 	if (cnt == 0)
    143   1.1     ragge 		return (0); /* EOF */
    144   1.1     ragge 
    145   1.8     jklos 
    146   1.8     jklos 	va = (char *)&ledpat;
    147   1.8     jklos 	va = va + off;
    148   1.1     ragge 	error = uiomove(va, cnt, uio);
    149   1.1     ragge 
    150   1.1     ragge 	return (error);
    151   1.1     ragge }
    152   1.1     ragge 
    153