ath - Basic re-port, base code compile
[dragonfly.git] / sys / dev / netif / ath / ath / if_ath_led.c
CommitLineData
572ff6f6
MD
1/*-
2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
15 *
16 * NO WARRANTY
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
28 */
29
30#include <sys/cdefs.h>
572ff6f6
MD
31
32/*
33 * Driver for the Atheros Wireless LAN controller.
34 *
35 * This software is derived from work of Atsushi Onoe; his contribution
36 * is greatly appreciated.
37 */
38
39#include "opt_inet.h"
40#include "opt_ath.h"
41/*
42 * This is needed for register operations which are performed
43 * by the driver - eg, calls to ath_hal_gettsf32().
44 */
45#include "opt_ah.h"
46#include "opt_wlan.h"
47
48#include <sys/param.h>
49#include <sys/systm.h>
50#include <sys/sysctl.h>
51#include <sys/mbuf.h>
52#include <sys/malloc.h>
53#include <sys/lock.h>
54#include <sys/mutex.h>
55#include <sys/kernel.h>
56#include <sys/socket.h>
57#include <sys/sockio.h>
58#include <sys/errno.h>
59#include <sys/callout.h>
60#include <sys/bus.h>
61#include <sys/endian.h>
62#include <sys/kthread.h>
63#include <sys/taskqueue.h>
64#include <sys/priv.h>
65#include <sys/module.h>
66#include <sys/ktr.h>
572ff6f6
MD
67
68#include <net/if.h>
69#include <net/if_dl.h>
70#include <net/if_media.h>
71#include <net/if_types.h>
72#include <net/if_arp.h>
73#include <net/ethernet.h>
74#include <net/if_llc.h>
75
5cd80a8c
MD
76#include <netproto/802_11/ieee80211_var.h>
77#include <netproto/802_11/ieee80211_regdomain.h>
572ff6f6 78#ifdef IEEE80211_SUPPORT_SUPERG
5cd80a8c 79#include <netproto/802_11/ieee80211_superg.h>
572ff6f6
MD
80#endif
81#ifdef IEEE80211_SUPPORT_TDMA
5cd80a8c 82#include <netproto/802_11/ieee80211_tdma.h>
572ff6f6
MD
83#endif
84
85#include <net/bpf.h>
86
87#ifdef INET
88#include <netinet/in.h>
89#include <netinet/if_ether.h>
90#endif
91
5cd80a8c
MD
92#include <dev/netif/ath/ath/if_athvar.h>
93#include <dev/netif/ath/ath_hal/ah_devid.h> /* XXX for softled */
94#include <dev/netif/ath/ath_hal/ah_diagcodes.h>
572ff6f6 95
5cd80a8c
MD
96#include <dev/netif/ath/ath/if_ath_debug.h>
97#include <dev/netif/ath/ath/if_ath_misc.h>
572ff6f6 98
5cd80a8c 99#include <dev/netif/ath/ath/if_ath_led.h>
572ff6f6
MD
100
101/*
102 * Software LED driver routines.
103 */
104
105/*
106 * XXX TODO: move the LED sysctls here.
107 */
108
109
110/*
111 * Configure the hardware for software and LED blinking.
112 * The user may choose to configure part of each, depending upon the
113 * NIC being used.
114 *
115 * This requires the configuration to be set before this function
116 * is called.
117 */
118void
119ath_led_config(struct ath_softc *sc)
120{
121 /* Software LED blinking - GPIO controlled LED */
122 if (sc->sc_softled) {
123 ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_ledpin,
124 HAL_GPIO_OUTPUT_MUX_AS_OUTPUT);
125 ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, !sc->sc_ledon);
126 }
127
128 /* Hardware LED blinking - MAC controlled LED */
129 if (sc->sc_hardled) {
130 /*
131 * Only enable each LED if required.
132 *
133 * Some NICs only have one LED connected; others may
134 * have GPIO1/GPIO2 connected to other hardware.
135 */
136 if (sc->sc_led_pwr_pin > 0)
137 ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_led_pwr_pin,
138 HAL_GPIO_OUTPUT_MUX_MAC_POWER_LED);
139 if (sc->sc_led_net_pin > 0)
140 ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_led_net_pin,
141 HAL_GPIO_OUTPUT_MUX_MAC_NETWORK_LED);
142 }
143}
144
145static void
146ath_led_done(void *arg)
147{
148 struct ath_softc *sc = arg;
149
3133c5e3 150 wlan_serialize_enter();
572ff6f6 151 sc->sc_blinking = 0;
3133c5e3 152 wlan_serialize_exit();
572ff6f6
MD
153}
154
155/*
156 * Turn the LED off: flip the pin and then set a timer so no
157 * update will happen for the specified duration.
158 */
159static void
160ath_led_off(void *arg)
161{
162 struct ath_softc *sc = arg;
163
3133c5e3 164 wlan_serialize_enter();
572ff6f6
MD
165 ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, !sc->sc_ledon);
166 callout_reset(&sc->sc_ledtimer, sc->sc_ledoff, ath_led_done, sc);
3133c5e3 167 wlan_serialize_exit();
572ff6f6
MD
168}
169
170/*
171 * Blink the LED according to the specified on/off times.
172 */
173static void
174ath_led_blink(struct ath_softc *sc, int on, int off)
175{
176 DPRINTF(sc, ATH_DEBUG_LED, "%s: on %u off %u\n", __func__, on, off);
3133c5e3 177 wlan_serialize_enter();
572ff6f6
MD
178 ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin, sc->sc_ledon);
179 sc->sc_blinking = 1;
180 sc->sc_ledoff = off;
181 callout_reset(&sc->sc_ledtimer, on, ath_led_off, sc);
3133c5e3 182 wlan_serialize_exit();
572ff6f6
MD
183}
184
185void
186ath_led_event(struct ath_softc *sc, int rix)
187{
188 sc->sc_ledevent = ticks; /* time of last event */
189 if (sc->sc_blinking) /* don't interrupt active blink */
190 return;
191 ath_led_blink(sc, sc->sc_hwmap[rix].ledon, sc->sc_hwmap[rix].ledoff);
192}