1 /* $NetBSD: nslu2_leds.c,v 1.7 2007/10/17 19:54:13 garbled Exp $ */
4 * Copyright (c) 2006 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: nslu2_leds.c,v 1.7 2007/10/17 19:54:13 garbled Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/device.h>
39 #include <sys/callout.h>
42 #include <machine/intr.h>
44 #include <dev/usb/usb.h>
45 #include <dev/usb/usbcdc.h>
46 #include <dev/usb/usbdi.h> /* XXX: For IPL_USB */
48 #include <arm/xscale/ixp425var.h>
50 #include <evbarm/nslu2/nslu2reg.h>
52 #define SLUGLED_FLASH_LEN (hz/8) /* How many ticks an LED stays lit */
54 #define LEDBITS_USB0 (1u << GPIO_LED_DISK1)
55 #define LEDBITS_USB1 (1u << GPIO_LED_DISK2)
58 * The Ready/Status bits control a tricolour LED.
59 * Ready is green, status is red.
61 #define LEDBITS_READY (1u << GPIO_LED_READY)
62 #define LEDBITS_STATUS (1u << GPIO_LED_STATUS)
64 struct slugled_softc
{
67 struct callout sc_usb0
;
69 struct callout sc_usb1
;
71 struct callout sc_usb2
;
75 static int slugled_attached
;
78 slugled_callout(void *arg
)
83 bit
= (uint32_t)(uintptr_t)arg
;
85 is
= disable_interrupts(I32_bit
);
86 reg
= GPIO_CONF_READ_4(ixp425_softc
, IXP425_GPIO_GPOUTR
);
87 GPIO_CONF_WRITE_4(ixp425_softc
, IXP425_GPIO_GPOUTR
, reg
| bit
);
88 restore_interrupts(is
);
92 slugled_intr0(void *arg
)
94 struct slugled_softc
*sc
= arg
;
98 is
= disable_interrupts(I32_bit
);
99 reg
= GPIO_CONF_READ_4(ixp425_softc
, IXP425_GPIO_GPOUTR
);
100 reg
&= ~LEDBITS_USB0
;
101 GPIO_CONF_WRITE_4(ixp425_softc
, IXP425_GPIO_GPOUTR
, reg
);
102 restore_interrupts(is
);
104 callout_schedule(&sc
->sc_usb0
, SLUGLED_FLASH_LEN
);
110 slugled_intr1(void *arg
)
112 struct slugled_softc
*sc
= arg
;
116 is
= disable_interrupts(I32_bit
);
117 reg
= GPIO_CONF_READ_4(ixp425_softc
, IXP425_GPIO_GPOUTR
);
118 reg
&= ~LEDBITS_USB1
;
119 GPIO_CONF_WRITE_4(ixp425_softc
, IXP425_GPIO_GPOUTR
, reg
);
120 restore_interrupts(is
);
122 callout_schedule(&sc
->sc_usb1
, SLUGLED_FLASH_LEN
);
128 slugled_intr2(void *arg
)
130 struct slugled_softc
*sc
= arg
;
134 is
= disable_interrupts(I32_bit
);
135 reg
= GPIO_CONF_READ_4(ixp425_softc
, IXP425_GPIO_GPOUTR
);
136 reg
&= ~(LEDBITS_USB0
| LEDBITS_USB1
);
137 GPIO_CONF_WRITE_4(ixp425_softc
, IXP425_GPIO_GPOUTR
, reg
);
138 restore_interrupts(is
);
140 callout_schedule(&sc
->sc_usb2
, SLUGLED_FLASH_LEN
);
146 slugled_tmr(void *arg
)
148 struct clockframe
*frame
= arg
;
152 if (CLKF_INTR(frame
) || sched_curcpu_runnable_p() ||
153 (curlwp
!= NULL
&& curlwp
!= curcpu()->ci_data
.cpu_idlelwp
))
154 bit
= LEDBITS_STATUS
;
158 is
= disable_interrupts(I32_bit
);
159 reg
= GPIO_CONF_READ_4(ixp425_softc
, IXP425_GPIO_GPOUTR
);
160 reg
&= ~LEDBITS_STATUS
;
161 GPIO_CONF_WRITE_4(ixp425_softc
, IXP425_GPIO_GPOUTR
, reg
| bit
);
162 restore_interrupts(is
);
168 slugled_shutdown(void *arg
)
170 struct slugled_softc
*sc
= arg
;
174 ixp425_intr_disestablish(sc
->sc_usb0_ih
);
175 ixp425_intr_disestablish(sc
->sc_usb1_ih
);
176 ixp425_intr_disestablish(sc
->sc_tmr_ih
);
178 /* Cancel the callouts */
180 callout_stop(&sc
->sc_usb0
);
181 callout_stop(&sc
->sc_usb1
);
184 /* Turn off the disk LEDs, and set Ready/Status to amber */
186 reg
= GPIO_CONF_READ_4(ixp425_softc
,IXP425_GPIO_GPOUTR
);
187 reg
|= LEDBITS_USB0
| LEDBITS_USB1
| LEDBITS_STATUS
| LEDBITS_READY
;
188 GPIO_CONF_WRITE_4(ixp425_softc
,IXP425_GPIO_GPOUTR
, reg
);
193 slugled_defer(struct device
*self
)
195 struct slugled_softc
*sc
= (struct slugled_softc
*) self
;
196 struct ixp425_softc
*ixsc
= ixp425_softc
;
202 /* Configure LED GPIO pins as output */
203 reg
= GPIO_CONF_READ_4(ixsc
, IXP425_GPIO_GPOER
);
204 reg
&= ~(LEDBITS_USB0
| LEDBITS_USB1
);
205 reg
&= ~(LEDBITS_READY
| LEDBITS_STATUS
);
206 GPIO_CONF_WRITE_4(ixsc
, IXP425_GPIO_GPOER
, reg
);
209 reg
= GPIO_CONF_READ_4(ixsc
, IXP425_GPIO_GPOUTR
);
210 reg
|= LEDBITS_USB0
| LEDBITS_USB1
;
211 reg
&= ~(LEDBITS_STATUS
| LEDBITS_READY
);
212 GPIO_CONF_WRITE_4(ixsc
, IXP425_GPIO_GPOUTR
, reg
);
216 if (shutdownhook_establish(slugled_shutdown
, sc
) == NULL
)
217 aprint_error("%s: WARNING - Failed to register shutdown hook\n",
218 sc
->sc_dev
.dv_xname
);
220 callout_init(&sc
->sc_usb0
, 0);
221 callout_setfunc(&sc
->sc_usb0
, slugled_callout
,
222 (void *)(uintptr_t)LEDBITS_USB0
);
224 callout_init(&sc
->sc_usb1
, 0);
225 callout_setfunc(&sc
->sc_usb1
, slugled_callout
,
226 (void *)(uintptr_t)LEDBITS_USB1
);
228 callout_init(&sc
->sc_usb2
, 0);
229 callout_setfunc(&sc
->sc_usb2
, slugled_callout
,
230 (void *)(uintptr_t)(LEDBITS_USB0
| LEDBITS_USB1
));
232 sc
->sc_usb0_ih
= ixp425_intr_establish(PCI_INT_A
, IPL_USB
,
234 KDASSERT(sc
->sc_usb0_ih
!= NULL
);
235 sc
->sc_usb1_ih
= ixp425_intr_establish(PCI_INT_B
, IPL_USB
,
237 KDASSERT(sc
->sc_usb1_ih
!= NULL
);
238 sc
->sc_usb2_ih
= ixp425_intr_establish(PCI_INT_C
, IPL_USB
,
240 KDASSERT(sc
->sc_usb2_ih
!= NULL
);
242 sc
->sc_tmr_ih
= ixp425_intr_establish(IXP425_INT_TMR0
, IPL_CLOCK
,
244 KDASSERT(sc
->sc_tmr_ih
!= NULL
);
248 slugled_match(struct device
*parent
, struct cfdata
*match
, void *aux
)
251 return (slugled_attached
== 0);
255 slugled_attach(struct device
*parent
, struct device
*self
, void *aux
)
258 aprint_normal(": LED support\n");
260 slugled_attached
= 1;
262 config_interrupts(self
, slugled_defer
);
265 CFATTACH_DECL(slugled
, sizeof(struct slugled_softc
),
266 slugled_match
, slugled_attach
, NULL
, NULL
);