summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2004-11-23 09:39:30 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2004-11-23 09:39:30 +0000
commita7b2471ab522d25c6e01aa1d3ee3b4fedbba8b71 (patch)
treef23f4e30287ee515d3008e3d6a992c3bce00be80 /sys
parent2a2ef5a2a5fe229808934f80cc470f56d09e1d52 (diff)
support the gpio found on ath(4) devices.
ok grange@
Diffstat (limited to 'sys')
-rw-r--r--sys/conf/files4
-rw-r--r--sys/dev/cardbus/if_ath_cardbus.c13
-rw-r--r--sys/dev/ic/ath.c95
-rw-r--r--sys/dev/ic/athvar.h29
-rw-r--r--sys/dev/pci/if_ath_pci.c9
5 files changed, 125 insertions, 25 deletions
diff --git a/sys/conf/files b/sys/conf/files
index 5193c7c6257..eac913ca9e3 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -1,4 +1,4 @@
-# $OpenBSD: files,v 1.319 2004/11/17 14:12:59 deraadt Exp $
+# $OpenBSD: files,v 1.320 2004/11/23 09:39:29 reyk Exp $
# $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@@ -329,7 +329,7 @@ file dev/ic/ar5210.c ar5xxx
#file dev/ic/ar5212.c ar5xxx
# Atheros AR5k (802.11/a/b/g) driver
-device ath: ether, ifnet, ifmedia, ar5xxx, wlan
+device ath: ether, ifnet, ifmedia, ar5xxx, wlan, gpiobus
file dev/ic/ath.c ath
# ADMtek ADM8211 802.11
diff --git a/sys/dev/cardbus/if_ath_cardbus.c b/sys/dev/cardbus/if_ath_cardbus.c
index c04fbb0dc91..d57184e3c7f 100644
--- a/sys/dev/cardbus/if_ath_cardbus.c
+++ b/sys/dev/cardbus/if_ath_cardbus.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ath_cardbus.c,v 1.1 2004/11/02 02:45:37 reyk Exp $ */
+/* $OpenBSD: if_ath_cardbus.c,v 1.2 2004/11/23 09:39:29 reyk Exp $ */
/* $NetBSD: if_ath_cardbus.c,v 1.4 2004/08/02 19:14:28 mycroft Exp $ */
/*
@@ -49,6 +49,7 @@
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <sys/device.h>
+#include <sys/gpio.h>
#include <machine/endian.h>
@@ -68,7 +69,6 @@
#include <net/bpf.h>
#endif
-
#ifdef NS
#include <netns/ns.h>
#include <netns/ns_if.h>
@@ -77,10 +77,7 @@
#include <machine/bus.h>
#include <machine/intr.h>
-#include <dev/mii/miivar.h>
-#include <dev/mii/mii_bitbang.h>
-
-#include <dev/ic/athvar.h>
+#include <dev/gpio/gpiovar.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
@@ -88,6 +85,8 @@
#include <dev/cardbus/cardbusvar.h>
+#include <dev/ic/athvar.h>
+
/*
* PCI configuration space registers
*/
@@ -211,7 +210,7 @@ ath_cardbus_detach(struct device *self, int flags)
panic("%s: data structure lacks", sc->sc_dev.dv_xname);
#endif
- rv = ath_detach(sc);
+ rv = ath_detach(sc, flags);
if (rv)
return (rv);
diff --git a/sys/dev/ic/ath.c b/sys/dev/ic/ath.c
index 3bb589f673f..83bc54de7cc 100644
--- a/sys/dev/ic/ath.c
+++ b/sys/dev/ic/ath.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ath.c,v 1.3 2004/11/11 20:11:28 reyk Exp $ */
+/* $OpenBSD: ath.c,v 1.4 2004/11/23 09:39:28 reyk Exp $ */
/* $NetBSD: ath.c,v 1.37 2004/08/18 21:59:39 dyoung Exp $ */
/*-
@@ -58,6 +58,7 @@
#include <sys/sockio.h>
#include <sys/errno.h>
#include <sys/timeout.h>
+#include <sys/gpio.h>
#include <machine/endian.h>
#include <machine/bus.h>
@@ -79,6 +80,8 @@
#include <net80211/ieee80211_var.h>
#include <net80211/ieee80211_compat.h>
+#include <dev/gpio/gpiovar.h>
+
#include <dev/ic/athvar.h>
/* unaligned little endian access */
@@ -154,6 +157,13 @@ int ath_enable(struct ath_softc *);
void ath_disable(struct ath_softc *);
void ath_power(int, void *);
+#if NGPIO > 0
+int ath_gpio_attach(struct ath_softc *);
+int ath_gpio_pin_read(void *, int);
+void ath_gpio_pin_write(void *, int, int);
+void ath_gpio_pin_ctl(void *, int, int);
+#endif
+
#ifdef __FreeBSD__
SYSCTL_DECL(_hw_ath);
/* XXX validate sysctl values */
@@ -598,6 +608,11 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
printf(", %s, address %s\n", ieee80211_regdomain2name(ath_regdomain),
ether_sprintf(ic->ic_myaddr));
+#if NGPIO > 0
+ if (ath_gpio_attach(sc) == 0)
+ sc->sc_flags |= ATH_GPIO;
+#endif
+
return 0;
bad2:
ath_desc_free(sc);
@@ -609,13 +624,16 @@ bad:
}
int
-ath_detach(struct ath_softc *sc)
+ath_detach(struct ath_softc *sc, int flags)
{
struct ifnet *ifp = &sc->sc_ic.ic_if;
int s;
+ config_detach_children(&sc->sc_dev, flags);
+
if ((sc->sc_flags & ATH_ATTACHED) == 0)
return (0);
+
DPRINTF(ATH_DEBUG_ANY, ("%s: if_flags %x\n", __func__, ifp->if_flags));
s = splnet();
@@ -638,6 +656,7 @@ ath_detach(struct ath_softc *sc)
ATH_TXQ_LOCK_DESTROY(sc);
#endif /* __FreeBSD__ */
+
return 0;
}
@@ -3620,3 +3639,75 @@ ath_printtxbuf(struct ath_buf *bf, int done)
}
}
#endif /* AR_DEBUG */
+
+#if NGPIO > 0
+int
+ath_gpio_attach(struct ath_softc *sc)
+{
+ struct ath_hal *ah = sc->sc_ah;
+ struct gpiobus_attach_args gba;
+ int i;
+
+ if (ah->ah_gpio_npins < 1)
+ return 0;
+
+ /* Initialize gpio pins array */
+ for (i = 0; i < ah->ah_gpio_npins; i++) {
+ sc->sc_gpio_pins[i].pin_num = i;
+ sc->sc_gpio_pins[i].pin_caps = GPIO_PIN_INPUT |
+ GPIO_PIN_OUTPUT;
+
+ /* Set pin mode to input */
+ ath_hal_gpiocfginput(ah, i);
+ sc->sc_gpio_pins[i].pin_flags = GPIO_PIN_INPUT;
+
+ /* Get pin input */
+ sc->sc_gpio_pins[i].pin_state = ath_hal_gpioget(ah, i) ?
+ GPIO_PIN_HIGH : GPIO_PIN_LOW;
+ }
+
+ /* Create gpio controller tag */
+ sc->sc_gpio_gc.gp_cookie = sc;
+ sc->sc_gpio_gc.gp_pin_read = ath_gpio_pin_read;
+ sc->sc_gpio_gc.gp_pin_write = ath_gpio_pin_write;
+ sc->sc_gpio_gc.gp_pin_ctl = ath_gpio_pin_ctl;
+
+ gba.gba_name = "gpio";
+ gba.gba_gc = &sc->sc_gpio_gc;
+ gba.gba_pins = sc->sc_gpio_pins;
+ gba.gba_npins = ah->ah_gpio_npins;
+
+ if (config_found(&sc->sc_dev, &gba, gpiobus_print) == NULL)
+ return (ENODEV);
+
+ return (0);
+}
+
+int
+ath_gpio_pin_read(void *arg, int pin)
+{
+ struct ath_softc *sc = arg;
+ struct ath_hal *ah = sc->sc_ah;
+ return (ath_hal_gpioget(ah, pin) ? GPIO_PIN_HIGH : GPIO_PIN_LOW);
+}
+
+void
+ath_gpio_pin_write(void *arg, int pin, int value)
+{
+ struct ath_softc *sc = arg;
+ struct ath_hal *ah = sc->sc_ah;
+ ath_hal_gpioset(ah, pin, value ? GPIO_PIN_HIGH : GPIO_PIN_LOW);
+}
+
+void
+ath_gpio_pin_ctl(void *arg, int pin, int flags)
+{
+ struct ath_softc *sc = arg;
+ struct ath_hal *ah = sc->sc_ah;
+
+ if (flags & GPIO_PIN_INPUT)
+ ath_hal_gpiocfginput(ah, pin);
+ else if (flags & GPIO_PIN_OUTPUT)
+ ath_hal_gpiocfgoutput(ah, pin);
+}
+#endif /* NGPIO */
diff --git a/sys/dev/ic/athvar.h b/sys/dev/ic/athvar.h
index b58ac745e70..88509914326 100644
--- a/sys/dev/ic/athvar.h
+++ b/sys/dev/ic/athvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: athvar.h,v 1.1 2004/11/02 02:45:37 reyk Exp $ */
+/* $OpenBSD: athvar.h,v 1.2 2004/11/23 09:39:29 reyk Exp $ */
/* $NetBSD: athvar.h,v 1.10 2004/08/10 01:03:53 dyoung Exp $ */
/*-
@@ -49,11 +49,14 @@
#include <dev/ic/ar5xxx.h>
+#include "gpio.h"
+
#define ATH_TIMEOUT 1000
#define ATH_RXBUF 40 /* number of RX buffers */
#define ATH_TXBUF 60 /* number of TX buffers */
#define ATH_TXDESC 8 /* number of descriptors per buffer */
+#define ATH_MAXGPIO 10 /* maximal number of gpio pins */
struct ath_recv_hist {
int arh_ticks; /* sample time by system clock */
@@ -323,8 +326,15 @@ struct ath_softc {
#endif
u_int8_t sc_broadcast_addr[IEEE80211_ADDR_LEN];
+
+#if NGPIO > 0
+ struct gpio_chipset_tag sc_gpio_gc; /* gpio(4) framework */
+ gpio_pin_t sc_gpio_pins[ATH_MAXGPIO];
+#endif
};
+
+
/*
* Wrapper code
*/
@@ -334,6 +344,7 @@ struct ath_softc {
#define ATH_ATTACHED 0x0001 /* attach has succeeded */
#define ATH_ENABLED 0x0002 /* chip is enabled */
+#define ATH_GPIO 0x0004 /* gpio device attached */
#define ATH_IS_ENABLED(sc) ((sc)->sc_flags & ATH_ENABLED)
#endif
@@ -378,7 +389,7 @@ struct ath_softc {
typedef unsigned long u_intptr_t;
int ath_attach(u_int16_t, struct ath_softc *);
-int ath_detach(struct ath_softc *);
+int ath_detach(struct ath_softc *, int);
void ath_resume(struct ath_softc *, int);
void ath_suspend(struct ath_softc *, int);
#ifdef __NetBSD__
@@ -472,18 +483,16 @@ int ath_intr(void *);
#define ath_hal_detach(_ah) \
((*(_ah)->ah_detach)(_ah))
-#ifdef SOFTLED
-#define ath_hal_gpioCfgOutput(_ah, _gpio) \
+#define ath_hal_gpiocfgoutput(_ah, _gpio) \
((*(_ah)->ah_gpioCfgOutput)((_ah), (_gpio)))
-#define ath_hal_gpioCfgInput(_ah, _gpio) \
+#define ath_hal_gpiocfginput(_ah, _gpio) \
((*(_ah)->ah_gpioCfgInput)((_ah), (_gpio)))
-#define ath_hal_gpioGet(_ah, _gpio) \
+#define ath_hal_gpioget(_ah, _gpio) \
((*(_ah)->ah_gpioGet)((_ah), (_gpio)))
-#define ath_hal_gpioSet(_ah, _gpio, _b) \
+#define ath_hal_gpioset(_ah, _gpio, _b) \
((*(_ah)->ah_gpioSet)((_ah), (_gpio), (_b)))
-#define ath_hal_gpioSetIntr(_ah, _gpioSel, _b) \
- ((*(_ah)->ah_gpioSetIntr)((_ah), (_sel), (_b)))
-#endif
+#define ath_hal_gpiosetintr(_ah, _gpio, _b) \
+ ((*(_ah)->ah_gpioSetIntr)((_ah), (_gpio), (_b)))
#define ath_hal_setopmode(_ah) \
((*(_ah)->ah_setPCUConfig)((_ah)))
diff --git a/sys/dev/pci/if_ath_pci.c b/sys/dev/pci/if_ath_pci.c
index 0538b40fa62..538e5b890b4 100644
--- a/sys/dev/pci/if_ath_pci.c
+++ b/sys/dev/pci/if_ath_pci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ath_pci.c,v 1.2 2004/11/02 03:19:15 brad Exp $ */
+/* $OpenBSD: if_ath_pci.c,v 1.3 2004/11/23 09:39:29 reyk Exp $ */
/* $NetBSD: if_ath_pci.c,v 1.7 2004/06/30 05:58:17 mycroft Exp $ */
/*-
@@ -51,6 +51,7 @@
#include <sys/sockio.h>
#include <sys/errno.h>
#include <sys/device.h>
+#include <sys/gpio.h>
#include <machine/bus.h>
@@ -67,13 +68,13 @@
#include <net80211/ieee80211_compat.h>
#include <net80211/ieee80211_var.h>
-#include <dev/ic/athvar.h>
+#include <dev/gpio/gpiovar.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcidevs.h>
-#include <sys/device.h>
+#include <dev/ic/athvar.h>
/*
* PCI glue.
@@ -235,7 +236,7 @@ ath_pci_detach(struct device *self, int flags)
{
struct ath_pci_softc *psc = (struct ath_pci_softc *)self;
- ath_detach(&psc->sc_sc);
+ ath_detach(&psc->sc_sc, flags);
pci_intr_disestablish(psc->sc_pc, psc->sc_ih);
return (0);