Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Nov 2011 23:12:55 +0100
From:      Stefan Bethke <stb@lassitu.de>
To:        freebsd-embedded@freebsd.org
Subject:   TL-WR1043: LEDs
Message-ID:  <E612E671-6F2A-49A3-BF5D-A80FEF8AA583@lassitu.de>

next in thread | raw e-mail | index | archive | help

--Apple-Mail=_1774D2C1-62A7-427A-8EA3-CA8CD3BF121E
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

Here's a quick and dirty hack to use the ar71xx GPIO module to get the =
pin configuration from a hint.

Add
  device  gpio
  device  gpioled
to your kernel config to enable these.  See gpioctl(1) and led(4) for =
how to control them.  The buttons can be polled with gpioctl.

--=20
Stefan Bethke <stb@lassitu.de>   Fon +49 151 14070811



--Apple-Mail=_1774D2C1-62A7-427A-8EA3-CA8CD3BF121E
Content-Disposition: attachment;
	filename=patch-tl-wr1043nd-leds.txt
Content-Type: text/plain;
	name="patch-tl-wr1043nd-leds.txt"
Content-Transfer-Encoding: quoted-printable

Index: mips/atheros/ar71xx_gpio.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- mips/atheros/ar71xx_gpio.c	(revision 228073)
+++ mips/atheros/ar71xx_gpio.c	(working copy)
@@ -349,6 +349,50 @@
 }
=20
 static int
+ar71xx_gpio_configure_from_hint(device_t dev)
+{
+	struct ar71xx_gpio_softc *sc =3D device_get_softc(dev);
+	const char *c, *d;
+	int i;
+=09
+	if (resource_string_value(device_get_name(dev),=20
+	    device_get_unit(dev), "pins", &c))
+		return (ENXIO);
+	device_printf(dev, "pins=3D%s\n", c);
+	i =3D 0;
+	/* "1=3Do:usb,2=3Do:sys,3=3Di:reset,5=3Do:qss,7=3Di:qss,9=3Do:wlan=
" */
+	while (c) {
+		d =3D strchr(c, '=3D');
+		if (d =3D=3D NULL)
+			return (ENXIO);
+        sc->gpio_pins[i].gp_pin =3D strtol(c, NULL, 10);
+        sc->gpio_pins[i].gp_caps =3D DEFAULT_CAPS;
+        sc->gpio_pins[i].gp_flags =3D 0;
+		d++;
+		if (d[0] !=3D 'i' && d[0] !=3D 'o' && d[1] !=3D ':')
+			return (ENXIO);
+        ar71xx_gpio_pin_configure(sc, &sc->gpio_pins[i],
+			d[0] =3D=3D 'o' ? GPIO_PIN_OUTPUT : =
GPIO_PIN_INPUT);
+		d +=3D 2;
+		c =3D d;
+		d =3D strchr(d, ',');
+		if (d !=3D NULL) {
+	        strncpy(sc->gpio_pins[i].gp_name, c,
+				d - c < GPIOMAXNAME ? d - c : =
GPIOMAXNAME);
+			c =3D d;
+			c++;
+		} else {
+	        strncpy(sc->gpio_pins[i].gp_name, c, GPIOMAXNAME);
+			c =3D NULL;
+		}
+		device_printf(dev, "pin %0x=3D%s\n", =
sc->gpio_pins[i].gp_pin, sc->gpio_pins[i].gp_name);
+		i++;
+	}
+	sc->gpio_npins =3D i;
+	return (0);
+}
+
+static int
 ar71xx_gpio_attach(device_t dev)
 {
 	struct ar71xx_gpio_softc *sc =3D device_get_softc(dev);
@@ -393,20 +437,21 @@
 	/* Configure all pins as input */
 	/* disable interrupts for all pins */
 	GPIO_WRITE(sc, AR71XX_GPIO_INT_MASK, 0);
-	pinp =3D ar71xx_gpio_pins;
-	i =3D 0;
-	while (pinp->name) {
-		strncpy(sc->gpio_pins[i].gp_name, pinp->name, =
GPIOMAXNAME);
-		sc->gpio_pins[i].gp_pin =3D pinp->pin;
-		sc->gpio_pins[i].gp_caps =3D DEFAULT_CAPS;
-		sc->gpio_pins[i].gp_flags =3D 0;
-		ar71xx_gpio_pin_configure(sc, &sc->gpio_pins[i], =
pinp->flags);
-		pinp++;
-		i++;
+	if (ar71xx_gpio_configure_from_hint(dev)) {
+        pinp =3D ar71xx_gpio_pins;
+        i =3D 0;
+        while (pinp->name) {
+            strncpy(sc->gpio_pins[i].gp_name, pinp->name, GPIOMAXNAME);
+            sc->gpio_pins[i].gp_pin =3D pinp->pin;
+            sc->gpio_pins[i].gp_caps =3D DEFAULT_CAPS;
+            sc->gpio_pins[i].gp_flags =3D 0;
+            ar71xx_gpio_pin_configure(sc, &sc->gpio_pins[i], =
pinp->flags);
+            pinp++;
+            i++;
+        }
+        sc->gpio_npins =3D i;
 	}
=20
-	sc->gpio_npins =3D i;
-
 	device_add_child(dev, "gpioc", device_get_unit(dev));
 	device_add_child(dev, "gpiobus", device_get_unit(dev));
 	return (bus_generic_attach(dev));
Index: mips/conf/TP-WN1043ND.hints
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- mips/conf/TP-WN1043ND.hints	(revision 228073)
+++ mips/conf/TP-WN1043ND.hints	(working copy)
@@ -75,3 +75,27 @@
 hint.map.4.end=3D0x00800000
 hint.map.4.name=3D"art"
 hint.map.4.readonly=3D1
+
+# GPIO
+hint.gpio.0.at=3D"apb0"
+hint.gpio.0.maddr=3D0x18040000
+hint.gpio.0.msize=3D0x10000
+hint.gpio.0.irq=3D2
+hint.gpio.0.pins=3D"1=3Do:usb,2=3Do:sys,3=3Di:reset,5=3Do:qss,7=3Di:qss,9=
=3Do:wlan"
+
+# LEDs
+hint.gpioled.0.at=3D"gpiobus0"
+hint.gpioled.0.name=3D"usb"
+hint.gpioled.0.pins=3D0x0002
+
+hint.gpioled.1.at=3D"gpiobus0"
+hint.gpioled.1.name=3D"sys"
+hint.gpioled.1.pins=3D0x0004
+
+hint.gpioled.2.at=3D"gpiobus0"
+hint.gpioled.2.name=3D"qss"
+hint.gpioled.2.pins=3D0x0020
+
+hint.gpioled.3.at=3D"gpiobus0"
+hint.gpioled.3.name=3D"wlan"
+hint.gpioled.3.pins=3D0x0200

--Apple-Mail=_1774D2C1-62A7-427A-8EA3-CA8CD3BF121E--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E612E671-6F2A-49A3-BF5D-A80FEF8AA583>