| @@ -1,163 +1,163 @@ | | | @@ -1,163 +1,163 @@ |
1 | /* $NetBSD: auxio.c,v 1.25 2015/10/06 16:40:36 martin Exp $ */ | | 1 | /* $NetBSD: auxio.c,v 1.26 2016/10/14 11:33:08 mlelstv Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2000, 2001, 2015 Matthew R. Green | | 4 | * Copyright (c) 2000, 2001, 2015 Matthew R. Green |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * | | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | /* | | 29 | /* |
30 | * AUXIO registers support on the sbus & ebus2, used for the floppy driver | | 30 | * AUXIO registers support on the sbus & ebus2, used for the floppy driver |
31 | * and to control the system LED, for the BLINK option. | | 31 | * and to control the system LED, for the BLINK option. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #include <sys/cdefs.h> | | 34 | #include <sys/cdefs.h> |
35 | __KERNEL_RCSID(0, "$NetBSD: auxio.c,v 1.25 2015/10/06 16:40:36 martin Exp $"); | | 35 | __KERNEL_RCSID(0, "$NetBSD: auxio.c,v 1.26 2016/10/14 11:33:08 mlelstv Exp $"); |
36 | | | 36 | |
37 | #include "opt_auxio.h" | | 37 | #include "opt_auxio.h" |
38 | | | 38 | |
39 | #include <sys/param.h> | | 39 | #include <sys/param.h> |
40 | #include <sys/systm.h> | | 40 | #include <sys/systm.h> |
41 | #include <sys/kernel.h> | | 41 | #include <sys/kernel.h> |
42 | #include <sys/callout.h> | | 42 | #include <sys/callout.h> |
43 | #include <sys/errno.h> | | 43 | #include <sys/errno.h> |
44 | #include <sys/device.h> | | 44 | #include <sys/device.h> |
45 | #include <sys/malloc.h> | | 45 | #include <sys/malloc.h> |
46 | | | 46 | |
47 | #include <machine/autoconf.h> | | 47 | #include <machine/autoconf.h> |
48 | #include <machine/cpu.h> | | 48 | #include <machine/cpu.h> |
49 | | | 49 | |
50 | #include <dev/ebus/ebusreg.h> | | 50 | #include <dev/ebus/ebusreg.h> |
51 | #include <dev/ebus/ebusvar.h> | | 51 | #include <dev/ebus/ebusvar.h> |
52 | #include <dev/sbus/sbusvar.h> | | 52 | #include <dev/sbus/sbusvar.h> |
53 | #include <sparc64/dev/auxioreg.h> | | 53 | #include <sparc64/dev/auxioreg.h> |
54 | #include <sparc64/dev/auxiovar.h> | | 54 | #include <sparc64/dev/auxiovar.h> |
55 | | | 55 | |
56 | static uint32_t auxio_read_led(struct auxio_softc *); | | 56 | static uint32_t auxio_read_led(struct auxio_softc *); |
57 | static void auxio_write_led(struct auxio_softc *, uint32_t); | | 57 | static void auxio_write_led(struct auxio_softc *, uint32_t); |
58 | void auxio_attach_common(struct auxio_softc *); | | 58 | void auxio_attach_common(struct auxio_softc *); |
59 | | | 59 | |
60 | extern struct cfdriver auxio_cd; | | 60 | extern struct cfdriver auxio_cd; |
61 | | | 61 | |
62 | static __inline__ uint32_t | | 62 | static __inline__ uint32_t |
63 | auxio_read_led(struct auxio_softc *sc) | | 63 | auxio_read_led(struct auxio_softc *sc) |
64 | { | | 64 | { |
65 | uint32_t led; | | 65 | uint32_t led; |
66 | | | 66 | |
67 | if (sc->sc_flags & AUXIO_EBUS) | | 67 | if (sc->sc_flags & AUXIO_EBUS) |
68 | led = le32toh(bus_space_read_4(sc->sc_tag, sc->sc_led, 0)); | | 68 | led = le32toh(bus_space_read_4(sc->sc_tag, sc->sc_led, 0)); |
69 | else | | 69 | else |
70 | led = bus_space_read_1(sc->sc_tag, sc->sc_led, 0); | | 70 | led = bus_space_read_1(sc->sc_tag, sc->sc_led, 0); |
71 | | | 71 | |
72 | return led; | | 72 | return led; |
73 | } | | 73 | } |
74 | | | 74 | |
75 | static __inline__ void | | 75 | static __inline__ void |
76 | auxio_write_led(struct auxio_softc *sc, uint32_t led) | | 76 | auxio_write_led(struct auxio_softc *sc, uint32_t led) |
77 | { | | 77 | { |
78 | | | 78 | |
79 | if (sc->sc_flags & AUXIO_EBUS) | | 79 | if (sc->sc_flags & AUXIO_EBUS) |
80 | bus_space_write_4(sc->sc_tag, sc->sc_led, 0, htole32(led)); | | 80 | bus_space_write_4(sc->sc_tag, sc->sc_led, 0, htole32(led)); |
81 | else | | 81 | else |
82 | bus_space_write_1(sc->sc_tag, sc->sc_led, 0, led); | | 82 | bus_space_write_1(sc->sc_tag, sc->sc_led, 0, led); |
83 | } | | 83 | } |
84 | | | 84 | |
85 | #ifdef BLINK | | 85 | #ifdef BLINK |
86 | static callout_t blink_ch; | | 86 | static callout_t blink_ch; |
87 | static void auxio_blink(void *); | | 87 | static void auxio_blink(void *); |
88 | | | 88 | |
89 | /* let someone disable it if it's already turned on; XXX sysctl? */ | | 89 | /* let someone disable it if it's already turned on; XXX sysctl? */ |
90 | int do_blink = 1; | | 90 | int do_blink = 1; |
91 | | | 91 | |
92 | static void | | 92 | static void |
93 | auxio_blink(void *x) | | 93 | auxio_blink(void *x) |
94 | { | | 94 | { |
95 | struct auxio_softc *sc = x; | | 95 | struct auxio_softc *sc = x; |
96 | int s; | | 96 | int s; |
97 | uint32_t led; | | 97 | uint32_t led; |
98 | | | 98 | |
99 | if (do_blink == 0) | | 99 | if (do_blink == 0) |
100 | return; | | 100 | return; |
101 | | | 101 | |
102 | mutex_enter(&sc->sc_lock); | | 102 | mutex_enter(&sc->sc_lock); |
103 | led = auxio_read_led(sc); | | 103 | led = auxio_read_led(sc); |
104 | led = led ^ AUXIO_LED_LED; | | 104 | led = led ^ AUXIO_LED_LED; |
105 | auxio_write_led(sc, led); | | 105 | auxio_write_led(sc, led); |
106 | mutex_exit(&sc->sc_lock); | | 106 | mutex_exit(&sc->sc_lock); |
107 | | | 107 | |
108 | /* | | 108 | /* |
109 | * Blink rate is: | | 109 | * Blink rate is: |
110 | * full cycle every second if completely idle (loadav = 0) | | 110 | * full cycle every second if completely idle (loadav = 0) |
111 | * full cycle every 2 seconds if loadav = 1 | | 111 | * full cycle every 2 seconds if loadav = 1 |
112 | * full cycle every 3 seconds if loadav = 2 | | 112 | * full cycle every 3 seconds if loadav = 2 |
113 | * etc. | | 113 | * etc. |
114 | */ | | 114 | */ |
115 | s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1)); | | 115 | s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1)); |
116 | callout_reset(&blink_ch, s, auxio_blink, sc); | | 116 | callout_reset(&blink_ch, s, auxio_blink, sc); |
117 | } | | 117 | } |
118 | #endif | | 118 | #endif |
119 | | | 119 | |
120 | void | | 120 | void |
121 | auxio_attach_common(struct auxio_softc *sc) | | 121 | auxio_attach_common(struct auxio_softc *sc) |
122 | { | | 122 | { |
123 | #ifdef BLINK | | | |
124 | static int do_once = 1; | | 123 | static int do_once = 1; |
125 | | | 124 | |
126 | /* only start one blinker */ | | 125 | /* only start one blinker */ |
127 | if (do_once) { | | 126 | if (do_once) { |
128 | mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_HIGH); | | 127 | mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_HIGH); |
| | | 128 | #ifdef BLINK |
129 | callout_init(&blink_ch, CALLOUT_MPSAFE); | | 129 | callout_init(&blink_ch, CALLOUT_MPSAFE); |
130 | auxio_blink(sc); | | 130 | auxio_blink(sc); |
| | | 131 | #endif |
131 | do_once = 0; | | 132 | do_once = 0; |
132 | } | | 133 | } |
133 | #endif | | | |
134 | printf("\n"); | | 134 | printf("\n"); |
135 | } | | 135 | } |
136 | | | 136 | |
137 | int | | 137 | int |
138 | auxio_fd_control(u_int32_t bits) | | 138 | auxio_fd_control(u_int32_t bits) |
139 | { | | 139 | { |
140 | struct auxio_softc *sc; | | 140 | struct auxio_softc *sc; |
141 | u_int32_t led; | | 141 | u_int32_t led; |
142 | | | 142 | |
143 | if (auxio_cd.cd_ndevs == 0) { | | 143 | if (auxio_cd.cd_ndevs == 0) { |
144 | return ENXIO; | | 144 | return ENXIO; |
145 | } | | 145 | } |
146 | | | 146 | |
147 | /* | | 147 | /* |
148 | * XXX This does not handle > 1 auxio correctly. | | 148 | * XXX This does not handle > 1 auxio correctly. |
149 | * We'll assume the floppy drive is tied to first auxio found. | | 149 | * We'll assume the floppy drive is tied to first auxio found. |
150 | */ | | 150 | */ |
151 | sc = device_lookup_private(&auxio_cd, 0); | | 151 | sc = device_lookup_private(&auxio_cd, 0); |
152 | if (!sc) { | | 152 | if (!sc) { |
153 | return ENXIO; | | 153 | return ENXIO; |
154 | } | | 154 | } |
155 | | | 155 | |
156 | mutex_enter(&sc->sc_lock); | | 156 | mutex_enter(&sc->sc_lock); |
157 | led = auxio_read_led(sc); | | 157 | led = auxio_read_led(sc); |
158 | led = (led & ~AUXIO_LED_FLOPPY_MASK) | bits; | | 158 | led = (led & ~AUXIO_LED_FLOPPY_MASK) | bits; |
159 | auxio_write_led(sc, led); | | 159 | auxio_write_led(sc, led); |
160 | mutex_exit(&sc->sc_lock); | | 160 | mutex_exit(&sc->sc_lock); |
161 | | | 161 | |
162 | return 0; | | 162 | return 0; |
163 | } | | 163 | } |