NetBSD Problem Report #52163

From www@NetBSD.org  Sat Apr 15 12:48:43 2017
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 20A837A1AE
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 15 Apr 2017 12:48:43 +0000 (UTC)
Message-Id: <20170415124841.535747A2B4@mollari.NetBSD.org>
Date: Sat, 15 Apr 2017 12:48:41 +0000 (UTC)
From: smesgr@gmail.com
Reply-To: smesgr@gmail.com
To: gnats-bugs@NetBSD.org
Subject: support for gpio for Xscale
X-Send-Pr-Version: www-1.0

>Number:         52163
>Category:       port-arm
>Synopsis:       support for gpio for Xscale
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pgoyette
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Apr 15 12:50:00 +0000 2017
>Closed-Date:    Fri Jun 16 22:43:07 +0000 2017
>Last-Modified:  Fri Jun 16 22:43:07 +0000 2017
>Originator:     Stephan Meisinger
>Release:        
>Organization:
>Environment:
>Description:
Support for gpio driver for Xscale GPIO driver
>How-To-Repeat:

>Fix:
Index: distrib/sets/lists/man/mi
===================================================================
RCS file: /cvsroot/src/distrib/sets/lists/man/mi,v
retrieving revision 1.1553
diff -u -r1.1553 mi
--- distrib/sets/lists/man/mi	11 Apr 2017 00:03:16 -0000	1.1553
+++ distrib/sets/lists/man/mi	15 Apr 2017 12:30:07 -0000
@@ -1577,6 +1577,7 @@
 ./usr/share/man/cat4/puffs.0			man-puffs-catman	.cat
 ./usr/share/man/cat4/pwdog.0			man-sys-catman		.cat
 ./usr/share/man/cat4/px.0			man-sys-catman		.cat
+./usr/share/man/cat4/pxagpio.0			man-sys-catman		.cat
 ./usr/share/man/cat4/pxaip.0			man-sys-catman		.cat
 ./usr/share/man/cat4/pxg.0			man-sys-catman		.cat
 ./usr/share/man/cat4/qe.0			man-sys-catman		.cat
@@ -4622,6 +4623,7 @@
 ./usr/share/man/html4/puffs.html		man-sys-htmlman		html
 ./usr/share/man/html4/pwdog.html		man-sys-htmlman		html
 ./usr/share/man/html4/px.html			man-sys-htmlman		html
+./usr/share/man/html4/pxagpio.html		man-sys-htmlman		html
 ./usr/share/man/html4/pxaip.html		man-sys-htmlman		html
 ./usr/share/man/html4/pxg.html			man-sys-htmlman		html
 ./usr/share/man/html4/qe.html			man-sys-htmlman		html
@@ -7569,6 +7571,7 @@
 ./usr/share/man/man4/puffs.4			man-sys-man		.man
 ./usr/share/man/man4/pwdog.4			man-sys-man		.man
 ./usr/share/man/man4/px.4			man-sys-man		.man
+./usr/share/man/man4/pxagpio.4			man-sys-man		.man
 ./usr/share/man/man4/pxaip.4			man-sys-man		.man
 ./usr/share/man/man4/pxg.4			man-sys-man		.man
 ./usr/share/man/man4/qe.4			man-sys-man		.man
Index: share/man/man4/Makefile
===================================================================
RCS file: /cvsroot/src/share/man/man4/Makefile,v
retrieving revision 1.634
diff -u -r1.634 Makefile
--- share/man/man4/Makefile	6 Mar 2017 09:06:01 -0000	1.634
+++ share/man/man4/Makefile	15 Apr 2017 12:31:30 -0000
@@ -50,8 +50,8 @@
 	pad.4 pas.4 pcdisplay.4 pcf8563rtc.4 pciide.4 pckbc.4 pckbd.4 pcn.4 \
 	pcppi.4 pcscp.4 pcweasel.4 pdcide.4 pdcsata.4 piixide.4 piixpcib.4 \
 	piixpm.4 pim.4 plip.4 pm3fb.4 pms.4 pmu.4 pnaphy.4 ppbus.4 ppp.4 pppoe.4 \
-	pseye.4 ptcd.4 ptm.4 pty.4 puc.4 pud.4 puffs.4 pwdog.4 px.4 pxaip.4 \
-	pxg.4 qe.4 qec.4 qsphy.4 \
+	pseye.4 ptcd.4 ptm.4 pty.4 puc.4 pud.4 puffs.4 pwdog.4 px.4 pxagpio.4 \
+	pxaip.4 pxg.4 qe.4 qec.4 qsphy.4 \
 	raid.4 ral.4 ray.4 rcons.4 rdcphy.4 re.4 rgephy.4 rlphy.4 \
 	rnd.4 route.4 rs5c372rtc.4 rtk.4 rtsx.4 rtw.4 rtwn.4 rum.4 run.4 \
 	s390rtc.4 satalink.4 sbus.4 scc.4 schide.4 \
Index: share/man/man4/pxagpio.4
===================================================================
RCS file: share/man/man4/pxagpio.4
diff -N share/man/man4/pxagpio.4
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ share/man/man4/pxagpio.4	15 Apr 2017 12:31:30 -0000
@@ -0,0 +1,65 @@
+.\"
+.\" Copyright (c) 2017 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Steve Woodford.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd April 15, 2017
+.Dt PXAGPIO 4
+.Os
+.Sh NAME
+.Nm pxaip
+.Nd Intel Xscale PXA250/PXA270 GPIO Controller
+.Sh SYNOPSIS
+.Cd "pxagpio0 at pxaip?"
+.Cd "gpio* at gpiobus?"
+.Sh DESCRIPTION
+.Nm
+is an on-board GPIO controller found in XScale PXA250, PXA255, PXA270,
+PXA271, PXA272 and PXA273 processors manufactured by Intel and Marvell Technology.
+The driver does support either 86 pins for PXA250 and 121 pins for PXA270 processor family.
+Access to the pins is provided by the
+.Xr gpio 4
+interface. The driver does support GPIO_PIN_INPUT and GPIO_PIN_OUTPUT. 
+GPIO pins being used in alternate configurations are not available
+for GPIO operations.
+.Sh SEE ALSO
+.Xr gpio 4 ,
+.Xr pxagpio 4
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Nx 2.0 . GPIO attachment appeared in 
+.Nx 8.0 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Steve Woodford
+.Aq Mt scw@NetBSD.org .
+This manual page was contributed by
+.An Stephan Meisinger .
Index: sys/arch/arm/xscale/files.pxa2x0
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/xscale/files.pxa2x0,v
retrieving revision 1.18
diff -u -r1.18 files.pxa2x0
--- sys/arch/arm/xscale/files.pxa2x0	6 Jun 2012 20:21:45 -0000	1.18
+++ sys/arch/arm/xscale/files.pxa2x0	15 Apr 2017 12:31:32 -0000
@@ -21,7 +21,7 @@
 defflag  opt_pxa2x0_gpio.h		PXAGPIO_HAS_GPION_INTRS

 # GPIO controller
-device	pxagpio
+device	pxagpio: gpiobus
 attach	pxagpio at pxaip
 file arch/arm/xscale/pxa2x0_gpio.c		pxagpio needs-flag

Index: sys/arch/arm/xscale/pxa2x0_gpio.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/xscale/pxa2x0_gpio.c,v
retrieving revision 1.16
diff -u -r1.16 pxa2x0_gpio.c
--- sys/arch/arm/xscale/pxa2x0_gpio.c	12 Nov 2012 18:00:38 -0000	1.16
+++ sys/arch/arm/xscale/pxa2x0_gpio.c	15 Apr 2017 12:31:32 -0000
@@ -38,6 +38,7 @@
 #include <sys/cdefs.h>
 __KERNEL_RCSID(0, "$NetBSD: pxa2x0_gpio.c,v 1.16 2012/11/12 18:00:38 skrll Exp $");

+#include "gpio.h"
 #include "opt_pxa2x0_gpio.h"

 #include <sys/param.h>
@@ -55,6 +56,9 @@

 #include "locators.h"

+#include <sys/gpio.h>
+#include <dev/gpio/gpiovar.h>
+
 struct gpio_irq_handler {
 	struct gpio_irq_handler *gh_next;
 	int (*gh_func)(void *);
@@ -75,11 +79,19 @@
 #else
 	struct gpio_irq_handler *sc_handlers[2];
 #endif
+	struct gpio_chipset_tag sc_gpio_gc;
+	gpio_pin_t sc_gpio_pins[GPIO_NPINS];
 };

 static int	pxagpio_match(device_t, cfdata_t, void *);
 static void	pxagpio_attach(device_t, device_t, void *);

+#if NGPIO > 0
+static int      pxa2x0_gpio_pin_read(void *, int);
+static void     pxa2x0_gpio_pin_write(void *, int, int);
+static void     pxa2x0_gpio_pin_ctl(void *, int, int);
+#endif
+
 CFATTACH_DECL_NEW(pxagpio, sizeof(struct pxagpio_softc),
     pxagpio_match, pxagpio_attach, NULL, NULL);

@@ -137,6 +149,11 @@
 {
 	struct pxagpio_softc *sc = device_private(self);
 	struct pxaip_attach_args *pxa = aux;
+#if NGPIO > 0
+	struct gpiobus_attach_args gba;
+	int pin, maxpin;
+	u_int func;
+#endif

 	sc->sc_dev = self;
 	sc->sc_bust = pxa->pxa_iot;
@@ -185,6 +202,43 @@
 	sc->sc_irqcookie[0] = sc->sc_irqcookie[1] = NULL;

 	pxagpio_softc = sc;
+#if NGPIO > 0
+#if defined(CPU_XSCALE_PXA250) && defined(CPU_XSCALE_PXA270)
+	maxpin = CPU_IS_PXA270 ? PXA270_GPIO_NPINS : PXA250_GPIO_NPINS;
+#else
+	maxpin = GPIO_NPINS;
+#endif
+	for (pin = 0; pin < maxpin; ++pin) {
+	
+	    sc->sc_gpio_pins[pin].pin_num = pin;
+
+		func = pxa2x0_gpio_get_function(pin);
+
+		if (GPIO_IS_GPIO(func)) {
+			sc->sc_gpio_pins[pin].pin_caps = GPIO_PIN_INPUT |
+				GPIO_PIN_OUTPUT;
+			sc->sc_gpio_pins[pin].pin_state =
+				pxa2x0_gpio_pin_read(sc, pin);
+		} else {
+	    	sc->sc_gpio_pins[pin].pin_caps = 0;
+			sc->sc_gpio_pins[pin].pin_state = 0;
+        }
+	}
+	
+	/* create controller tag */
+	sc->sc_gpio_gc.gp_cookie = sc;
+	sc->sc_gpio_gc.gp_pin_read = pxa2x0_gpio_pin_read;
+	sc->sc_gpio_gc.gp_pin_write = pxa2x0_gpio_pin_write;
+	sc->sc_gpio_gc.gp_pin_ctl = pxa2x0_gpio_pin_ctl;
+	
+	gba.gba_gc = &sc->sc_gpio_gc;
+	gba.gba_pins = sc->sc_gpio_pins;
+	gba.gba_npins = maxpin;
+
+	config_found_ia(self, "gpiobus", &gba, gpiobus_print);
+#else
+	aprint_normal_dev(sc->sc_dev, "no GPIO configured in kernel\n");
+#endif
 }

 void
@@ -668,6 +722,53 @@
 	splx(s);
 }

+#if NGPIO > 0
+/* GPIO support functions */
+static int
+pxa2x0_gpio_pin_read(void *arg, int pin)
+{
+	struct pxagpio_softc *sc = arg;
+
+	if (device_unit(sc->sc_dev) > 0) {
+		return 0;
+	}
+
+	return pxa2x0_gpio_get_bit(pin);
+}
+
+static void
+pxa2x0_gpio_pin_write(void *arg, int pin, int value)
+{
+	struct pxagpio_softc *sc = arg;
+
+	if (device_unit(sc->sc_dev) > 0) {
+		return;
+	}
+
+	if (value == GPIO_PIN_HIGH) {
+		pxa2x0_gpio_set_bit(pin);
+	} else {
+		pxa2x0_gpio_clear_bit(pin);
+	}
+}
+
+static void
+pxa2x0_gpio_pin_ctl(void *arg, int pin, int flags)
+{
+	struct pxagpio_softc *sc = arg;
+
+	if (device_unit(sc->sc_dev) > 0) {
+		return;
+	}
+
+	if(flags & GPIO_PIN_OUTPUT) {
+		pxa2x0_gpio_set_function(pin, GPIO_OUT);
+	} else if(flags & GPIO_PIN_INPUT) {
+		pxa2x0_gpio_set_function(pin, GPIO_IN);
+	}
+} 
+#endif
+

 #if defined(CPU_XSCALE_PXA250)
 /*
Index: sys/arch/evbarm/conf/GUMSTIX
===================================================================
RCS file: /cvsroot/src/sys/arch/evbarm/conf/GUMSTIX,v
retrieving revision 1.90
diff -u -r1.90 GUMSTIX
--- sys/arch/evbarm/conf/GUMSTIX	19 Feb 2017 07:47:00 -0000	1.90
+++ sys/arch/evbarm/conf/GUMSTIX	15 Apr 2017 12:31:33 -0000
@@ -179,6 +181,7 @@
 options 	PXAGPIO_HAS_GPION_INTRS

 pxagpio0 at pxaip?				# GPIO
+gpio* at gpiobus?
 pxartc0	at pxaip? addr 0x40900000		# RTC

 # cotulla integrated 16550 UARTs

>Release-Note:

>Audit-Trail:
From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-arm/52163 - support for gpio for Xscale
Date: Tue, 16 May 2017 16:27:15 +0800 (+08)

 Forward with correct PR category in subject line so it will get added to the 
 audit trail!


 Stephan,

 The driver looks pretty reasonable to me, but I've got no way to test it. 
 Hopefully one of the other folks here with appropriate hardware would be able 
 to jump in.

 One thing I did notice, is there's a large chunk of code conditionally compiled 
 based on #if NGPIO.  In a "modular" world, the gpio module could be loaded 
 later, so it would probably be best not to "cripple" the controller driver just 
 because the child driver is not currently present.

 Thanks for the contribution (and thanks for the completeness, including man 
 pages, configuration database update, etc.)!


 +------------------+--------------------------+----------------------------+
 | Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:          |
 | (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee dot com   |
 | Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd dot org |
 +------------------+--------------------------+----------------------------+

From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-arm/52163 - support for gpio for Xscale
Date: Tue, 16 May 2017 16:27:37 +0800 (+08)

 Forward with correct PR category so it will get logged.


 On Mon, 15 May 2017, smesgr wrote:

 > Hi Paul,
 > 
 > thanks for looking into the PR. So you would suggest moving all/most of the 
 > NGPIO stuff into "if_pxagpio_gpio.c" or something along this line?

 I would suggest just removing the #if NGPIO conditionals.  Compile that code 
 always.

 You will also need to separate the "search for children" code, which looks like 
 it consists only of a call to config_found_ia(..," gpiobus", ...), into a 
 separate function pxagpio_rescan() and add the rescan function to the 
 CFATTACH_DECL_NEW (you'll need to update that to use CFATTACH_DECL3_NEW).



 +------------------+--------------------------+----------------------------+
 | Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:          |
 | (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee dot com   |
 | Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd dot org |
 +------------------+--------------------------+----------------------------+

From: smesgr <smesgr@gmail.com>
To: gnats-bugs@NetBSD.org, port-arm-maintainer@netbsd.org,
 gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Cc: 
Subject: Re: port-arm/52163 - support for gpio for Xscale
Date: Tue, 16 May 2017 22:59:46 +0200

 Hi Paul,

 I have changed my local code according your suggestions. If gpio is 
 available in the kernel configuration the kernel compiles and runs fine. 
 If the gpio attachement in kernel configuration is removed however the 
 linker complaining about unresolved symbol gpiobus_print. To be honest I 
 already expected a linker error without NGPIO preprocessor directives. 
 I'm not entirely sure how NetBSD make process is done, but I assume the 
 sys/gpio/gpio.c isn't compiled if not configured.
 I can add the NGPIO conditions again, but doubtful If the additional 
 rescan is still useful.

 Best Regards

 Stephan

From: Paul Goyette <paul@whooppee.com>
To: smesgr <smesgr@gmail.com>
Cc: gnats-bugs@NetBSD.org, port-arm-maintainer@netbsd.org, 
    gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: port-arm/52163 - support for gpio for Xscale
Date: Wed, 17 May 2017 16:10:24 +0800 (+08)

 On Tue, 16 May 2017, smesgr wrote:

 > Hi Paul,
 >
 > I have changed my local code according your suggestions. If gpio is available 
 > in the kernel configuration the kernel compiles and runs fine. If the gpio 
 > attachement in kernel configuration is removed however the linker complaining 
 > about unresolved symbol gpiobus_print. To be honest I already expected a 
 > linker error without NGPIO preprocessor directives. I'm not entirely sure how 
 > NetBSD make process is done, but I assume the sys/gpio/gpio.c isn't compiled 
 > if not configured.
 > I can add the NGPIO conditions again, but doubtful If the additional rescan 
 > is still useful.

 Hmmm.  I would have to think about this further.



 +------------------+--------------------------+----------------------------+
 | Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:          |
 | (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee dot com   |
 | Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd dot org |
 +------------------+--------------------------+----------------------------+

From: Paul Goyette <paul@whooppee.com>
To: smesgr <smesgr@gmail.com>
Cc: gnats-bugs@NetBSD.org, port-arm-maintainer@netbsd.org, 
    gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: port-arm/52163 - support for gpio for Xscale
Date: Wed, 17 May 2017 16:51:06 +0800 (+08)

 On Wed, 17 May 2017, Paul Goyette wrote:

 > On Tue, 16 May 2017, smesgr wrote:
 >
 >> Hi Paul,
 >> 
 >> I have changed my local code according your suggestions. If gpio is 
 >> available in the kernel configuration the kernel compiles and runs fine. If 
 >> the gpio attachement in kernel configuration is removed however the linker 
 >> complaining about unresolved symbol gpiobus_print. To be honest I already 
 >> expected a linker error without NGPIO preprocessor directives. I'm not 
 >> entirely sure how NetBSD make process is done, but I assume the 
 >> sys/gpio/gpio.c isn't compiled if not configured.
 >> I can add the NGPIO conditions again, but doubtful If the additional rescan 
 >> is still useful.
 >
 > Hmmm.  I would have to think about this further.

 Yeah, for now let's ignore the modular aspects.  Hopefully someone with 
 more knowledge about the platform can review and import your original 
 driver.

 At some future time, we should probably extract gpiobus_print() (and any 
 other routines specific to the attachment attribute) into a separate 
 source file, rather than burying it in gpio.c  We might also need to 
 clean up all the other drivers that "provide" the attribute.  So, we're 
 not going to deal with it today.  :)


 +------------------+--------------------------+----------------------------+
 | Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:          |
 | (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee dot com   |
 | Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd dot org |
 +------------------+--------------------------+----------------------------+

From: matthew green <mrg@eterna.com.au>
To: gnats-bugs@NetBSD.org, smesgr@gmail.com
Cc: port-arm-maintainer@netbsd.org, gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org
Subject: re: port-arm/52163: support for gpio for Xscale
Date: Sun, 04 Jun 2017 06:03:34 +1000

 > +.Cd "pxagpio0 at pxaip?"
 > +.Cd "gpio* at gpiobus?"

 this part (forcing to unit zero) and below ..

 > +#if NGPIO > 0
 > +/* GPIO support functions */
 > +static int
 > +pxa2x0_gpio_pin_read(void *arg, int pin)
 > +{
 > +	struct pxagpio_softc *sc = arg;
 > +
 > +	if (device_unit(sc->sc_dev) > 0) {
 > +		return 0;
 > +	}
 > +
 > +	return pxa2x0_gpio_get_bit(pin);
 > +}

 this is what we call "cf_unit abuse".  the driver code hard-codes
 the definition of a device unit, where as this should not be the
 case in almost every case.

 i *think* you can simply remove all these checks for device_unit()
 and mark the device as "pxagpio* at pxaip?" in the manual.  on this
 hardware, only one will be found and the cf_unit doesn't matter.

 > +	if(flags & GPIO_PIN_OUTPUT) {
 > +		pxa2x0_gpio_set_function(pin, GPIO_OUT);

 nit:  "if (" not "if(".

 > +	} else if(flags & GPIO_PIN_INPUT) {

 and here too..

 another nit: the new pin loop in attach should be formatted properly,


 can you make these changes, test and re-send?  thanks.


 .mrg.

From: smesgr <smesgr@gmail.com>
To: gnats-bugs@NetBSD.org, port-arm-maintainer@netbsd.org,
 gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Cc: 
Subject: Re: port-arm/52163: support for gpio for Xscale
Date: Wed, 7 Jun 2017 19:28:59 +0200

 Patch changed according Matts suggestion. Tested with an Gumstix with 
 (Intel build) PXA250 and (Marvell build) PX270:


 Index: distrib/sets/lists/man/mi
 ===================================================================
 RCS file: /cvsroot/src/distrib/sets/lists/man/mi,v
 retrieving revision 1.1557
 diff -u -r1.1557 mi
 --- distrib/sets/lists/man/mi    27 May 2017 21:02:55 -0000 1.1557
 +++ distrib/sets/lists/man/mi    7 Jun 2017 16:56:37 -0000
 @@ -1579,6 +1579,7 @@
   ./usr/share/man/cat4/puffs.0            man-puffs-catman    .cat
   ./usr/share/man/cat4/pwdog.0            man-sys-catman        .cat
   ./usr/share/man/cat4/px.0            man-sys-catman        .cat
 +./usr/share/man/cat4/pxagpio.0            man-sys-catman .cat
   ./usr/share/man/cat4/pxaip.0            man-sys-catman        .cat
   ./usr/share/man/cat4/pxg.0            man-sys-catman        .cat
   ./usr/share/man/cat4/qe.0            man-sys-catman        .cat
 @@ -4629,6 +4630,7 @@
   ./usr/share/man/html4/puffs.html        man-sys-htmlman        html
   ./usr/share/man/html4/pwdog.html        man-sys-htmlman        html
   ./usr/share/man/html4/px.html            man-sys-htmlman html
 +./usr/share/man/html4/pxagpio.html        man-sys-htmlman html
   ./usr/share/man/html4/pxaip.html        man-sys-htmlman        html
   ./usr/share/man/html4/pxg.html            man-sys-htmlman html
   ./usr/share/man/html4/qe.html            man-sys-htmlman html
 @@ -7581,6 +7583,7 @@
   ./usr/share/man/man4/puffs.4            man-sys-man        .man
   ./usr/share/man/man4/pwdog.4            man-sys-man        .man
   ./usr/share/man/man4/px.4            man-sys-man        .man
 +./usr/share/man/man4/pxagpio.4            man-sys-man        .man
   ./usr/share/man/man4/pxaip.4            man-sys-man        .man
   ./usr/share/man/man4/pxg.4            man-sys-man        .man
   ./usr/share/man/man4/qe.4            man-sys-man        .man
 Index: share/man/man4/Makefile
 ===================================================================
 RCS file: /cvsroot/src/share/man/man4/Makefile,v
 retrieving revision 1.637
 diff -u -r1.637 Makefile
 --- share/man/man4/Makefile    27 May 2017 21:02:55 -0000    1.637
 +++ share/man/man4/Makefile    7 Jun 2017 16:56:37 -0000
 @@ -50,8 +50,8 @@
       pad.4 pas.4 pcdisplay.4 pcf8563rtc.4 pciide.4 pckbc.4 pckbd.4 pcn.4 \
       pcppi.4 pcscp.4 pcweasel.4 pdcide.4 pdcsata.4 piixide.4 piixpcib.4 \
       piixpm.4 pim.4 plip.4 pm3fb.4 pms.4 pmu.4 pnaphy.4 ppbus.4 ppp.4 
 pppoe.4 \
 -    pseye.4 ptcd.4 ptm.4 pty.4 puc.4 pud.4 puffs.4 pwdog.4 px.4 pxaip.4 \
 -    pxg.4 qe.4 qec.4 qsphy.4 \
 +    pseye.4 ptcd.4 ptm.4 pty.4 puc.4 pud.4 puffs.4 pwdog.4 px.4 pxagpio.4 \
 +    pxaip.4 pxg.4 qe.4 qec.4 qsphy.4 \
       raid.4 ral.4 ray.4 rcons.4 rdcphy.4 re.4 rgephy.4 rlphy.4 \
       rnd.4 route.4 rs5c372rtc.4 rtk.4 rtsx.4 rtw.4 rtwn.4 rum.4 run.4 \
       s390rtc.4 satalink.4 sbus.4 scc.4 schide.4 \
 Index: share/man/man4/pxagpio.4
 ===================================================================
 RCS file: share/man/man4/pxagpio.4
 diff -N share/man/man4/pxagpio.4
 --- /dev/null    1 Jan 1970 00:00:00 -0000
 +++ share/man/man4/pxagpio.4    7 Jun 2017 17:21:50 -0000
 @@ -0,0 +1,65 @@
 +.\"
 +.\" Copyright (c) 2017 The NetBSD Foundation, Inc.
 +.\" All rights reserved.
 +.\"
 +.\" This code is derived from software contributed to The NetBSD Foundation
 +.\" by Steve Woodford.
 +.\"
 +.\" Redistribution and use in source and binary forms, with or without
 +.\" modification, are permitted provided that the following conditions
 +.\" are met:
 +.\" 1. Redistributions of source code must retain the above copyright
 +.\"    notice, this list of conditions and the following disclaimer.
 +.\" 2. Redistributions in binary form must reproduce the above copyright
 +.\"    notice, this list of conditions and the following disclaimer in the
 +.\"    documentation and/or other materials provided with the distribution.
 +.\"
 +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 
 CONTRIBUTORS
 +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 LIMITED
 +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
 PARTICULAR
 +.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR 
 CONTRIBUTORS
 +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
 BUSINESS
 +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 OF THE
 +.\" POSSIBILITY OF SUCH DAMAGE.
 +.\"
 +.Dd April 15, 2017
 +.Dt PXAGPIO 4
 +.Os
 +.Sh NAME
 +.Nm pxaip
 +.Nd Intel Xscale PXA250/PXA270 GPIO Controller
 +.Sh SYNOPSIS
 +.Cd "pxagpio* at pxaip?"
 +.Cd "gpio* at gpiobus?"
 +.Sh DESCRIPTION
 +.Nm
 +is an on-board GPIO controller found in XScale PXA250, PXA255, PXA270,
 +PXA271, PXA272 and PXA273 processors manufactured by Intel and Marvell 
 Technology.
 +The driver does support either 86 pins for PXA250 and 121 pins for 
 PXA270 processor family.
 +Access to the pins is provided by the
 +.Xr gpio 4
 +interface. The driver does support GPIO_PIN_INPUT and GPIO_PIN_OUTPUT.
 +GPIO pins being used in alternate configurations are not available
 +for GPIO operations.
 +.Sh SEE ALSO
 +.Xr gpio 4 ,
 +.Xr pxagpio 4
 +.Sh HISTORY
 +The
 +.Nm
 +driver first appeared in
 +.Nx 2.0 . GPIO attachment appeared in
 +.Nx 8.0 .
 +.Sh AUTHORS
 +.An -nosplit
 +The
 +.Nm
 +driver was written by
 +.An Steve Woodford
 +.Aq Mt scw@NetBSD.org .
 +This manual page was contributed by
 +.An Stephan Meisinger .
 Index: sys/arch/arm/xscale/files.pxa2x0
 ===================================================================
 RCS file: /cvsroot/src/sys/arch/arm/xscale/files.pxa2x0,v
 retrieving revision 1.18
 diff -u -r1.18 files.pxa2x0
 --- sys/arch/arm/xscale/files.pxa2x0    6 Jun 2012 20:21:45 -0000 1.18
 +++ sys/arch/arm/xscale/files.pxa2x0    7 Jun 2017 16:56:37 -0000
 @@ -21,7 +21,7 @@
   defflag  opt_pxa2x0_gpio.h        PXAGPIO_HAS_GPION_INTRS

   # GPIO controller
 -device    pxagpio
 +device    pxagpio: gpiobus
   attach    pxagpio at pxaip
   file arch/arm/xscale/pxa2x0_gpio.c        pxagpio needs-flag

 Index: sys/arch/arm/xscale/pxa2x0_gpio.c
 ===================================================================
 RCS file: /cvsroot/src/sys/arch/arm/xscale/pxa2x0_gpio.c,v
 retrieving revision 1.16
 diff -u -r1.16 pxa2x0_gpio.c
 --- sys/arch/arm/xscale/pxa2x0_gpio.c    12 Nov 2012 18:00:38 -0000    1.16
 +++ sys/arch/arm/xscale/pxa2x0_gpio.c    7 Jun 2017 16:56:37 -0000
 @@ -38,6 +38,7 @@
   #include <sys/cdefs.h>
   __KERNEL_RCSID(0, "$NetBSD: pxa2x0_gpio.c,v 1.16 2012/11/12 18:00:38 
 skrll Exp $");

 +#include "gpio.h"
   #include "opt_pxa2x0_gpio.h"

   #include <sys/param.h>
 @@ -55,6 +56,9 @@

   #include "locators.h"

 +#include <sys/gpio.h>
 +#include <dev/gpio/gpiovar.h>
 +
   struct gpio_irq_handler {
       struct gpio_irq_handler *gh_next;
       int (*gh_func)(void *);
 @@ -75,11 +79,19 @@
   #else
       struct gpio_irq_handler *sc_handlers[2];
   #endif
 +    struct gpio_chipset_tag sc_gpio_gc;
 +    gpio_pin_t sc_gpio_pins[GPIO_NPINS];
   };

   static int    pxagpio_match(device_t, cfdata_t, void *);
   static void    pxagpio_attach(device_t, device_t, void *);

 +#if NGPIO > 0
 +static int      pxa2x0_gpio_pin_read(void *, int);
 +static void     pxa2x0_gpio_pin_write(void *, int, int);
 +static void     pxa2x0_gpio_pin_ctl(void *, int, int);
 +#endif
 +
   CFATTACH_DECL_NEW(pxagpio, sizeof(struct pxagpio_softc),
       pxagpio_match, pxagpio_attach, NULL, NULL);

 @@ -137,6 +149,11 @@
   {
       struct pxagpio_softc *sc = device_private(self);
       struct pxaip_attach_args *pxa = aux;
 +#if NGPIO > 0
 +    struct gpiobus_attach_args gba;
 +    int pin, maxpin;
 +    u_int func;
 +#endif

       sc->sc_dev = self;
       sc->sc_bust = pxa->pxa_iot;
 @@ -185,6 +202,42 @@
       sc->sc_irqcookie[0] = sc->sc_irqcookie[1] = NULL;

       pxagpio_softc = sc;
 +#if NGPIO > 0
 +#if defined(CPU_XSCALE_PXA250) && defined(CPU_XSCALE_PXA270)
 +    maxpin = CPU_IS_PXA270 ? PXA270_GPIO_NPINS : PXA250_GPIO_NPINS;
 +#else
 +    maxpin = GPIO_NPINS;
 +#endif
 +    for (pin = 0; pin < maxpin; ++pin) {
 +
 +        sc->sc_gpio_pins[pin].pin_num = pin;
 +        func = pxa2x0_gpio_get_function(pin);
 +
 +        if (GPIO_IS_GPIO(func)) {
 +            sc->sc_gpio_pins[pin].pin_caps = GPIO_PIN_INPUT |
 +                GPIO_PIN_OUTPUT;
 +            sc->sc_gpio_pins[pin].pin_state =
 +                pxa2x0_gpio_pin_read(sc, pin);
 +        } else {
 +            sc->sc_gpio_pins[pin].pin_caps = 0;
 +            sc->sc_gpio_pins[pin].pin_state = 0;
 +        }
 +    }
 +
 +    /* create controller tag */
 +    sc->sc_gpio_gc.gp_cookie = sc;
 +    sc->sc_gpio_gc.gp_pin_read = pxa2x0_gpio_pin_read;
 +    sc->sc_gpio_gc.gp_pin_write = pxa2x0_gpio_pin_write;
 +    sc->sc_gpio_gc.gp_pin_ctl = pxa2x0_gpio_pin_ctl;
 +
 +    gba.gba_gc = &sc->sc_gpio_gc;
 +    gba.gba_pins = sc->sc_gpio_pins;
 +    gba.gba_npins = maxpin;
 +
 +    config_found_ia(self, "gpiobus", &gba, gpiobus_print);
 +#else
 +    aprint_normal_dev(sc->sc_dev, "no GPIO configured in kernel\n");
 +#endif
   }

   void
 @@ -668,6 +721,35 @@
       splx(s);
   }

 +#if NGPIO > 0
 +/* GPIO support functions */
 +static int
 +pxa2x0_gpio_pin_read(void *arg, int pin)
 +{
 +    return pxa2x0_gpio_get_bit(pin);
 +}
 +
 +static void
 +pxa2x0_gpio_pin_write(void *arg, int pin, int value)
 +{
 +    if (value == GPIO_PIN_HIGH) {
 +        pxa2x0_gpio_set_bit(pin);
 +    } else {
 +        pxa2x0_gpio_clear_bit(pin);
 +    }
 +}
 +
 +static void
 +pxa2x0_gpio_pin_ctl(void *arg, int pin, int flags)
 +{
 +    if (flags & GPIO_PIN_OUTPUT) {
 +        pxa2x0_gpio_set_function(pin, GPIO_OUT);
 +    } else if (flags & GPIO_PIN_INPUT) {
 +        pxa2x0_gpio_set_function(pin, GPIO_IN);
 +    }
 +}
 +#endif
 +

   #if defined(CPU_XSCALE_PXA250)
   /*
 Index: sys/arch/evbarm/conf/GUMSTIX
 Index: sys/arch/evbarm/conf/GUMSTIX
 ===================================================================
 RCS file: /cvsroot/src/sys/arch/evbarm/conf/GUMSTIX,v
 retrieving revision 1.90
 diff -u -r1.90 GUMSTIX
 --- sys/arch/evbarm/conf/GUMSTIX    19 Feb 2017 07:47:00 -0000 1.90
 +++ sys/arch/evbarm/conf/GUMSTIX    7 Jun 2017 16:56:37 -0000
 @@ -179,6 +181,7 @@
   options     PXAGPIO_HAS_GPION_INTRS

   pxagpio0 at pxaip?                # GPIO
 +gpio* at gpiobus?
   pxartc0    at pxaip? addr 0x40900000        # RTC

   # cotulla integrated 16550 UARTs

From: "Paul Goyette" <pgoyette@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52163 CVS commit: src
Date: Fri, 16 Jun 2017 22:39:34 +0000

 Module Name:	src
 Committed By:	pgoyette
 Date:		Fri Jun 16 22:39:34 UTC 2017

 Modified Files:
 	src/distrib/sets/lists/man: mi
 	src/share/man/man4: Makefile
 	src/sys/arch/arm/xscale: files.pxa2x0 pxa2x0_gpio.c
 	src/sys/arch/evbarm/conf: GUMSTIX
 Added Files:
 	src/share/man/man4: pxagpio.4

 Log Message:
 Add gpio support for Xscale

 From Stephan Meisenger in PR/52163


 To generate a diff of this commit:
 cvs rdiff -u -r1.1558 -r1.1559 src/distrib/sets/lists/man/mi
 cvs rdiff -u -r1.640 -r1.641 src/share/man/man4/Makefile
 cvs rdiff -u -r0 -r1.1 src/share/man/man4/pxagpio.4
 cvs rdiff -u -r1.18 -r1.19 src/sys/arch/arm/xscale/files.pxa2x0
 cvs rdiff -u -r1.16 -r1.17 src/sys/arch/arm/xscale/pxa2x0_gpio.c
 cvs rdiff -u -r1.90 -r1.91 src/sys/arch/evbarm/conf/GUMSTIX

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

Responsible-Changed-From-To: port-arm-maintainer->pgoyette
Responsible-Changed-By: pgoyette@NetBSD.org
Responsible-Changed-When: Fri, 16 Jun 2017 22:43:07 +0000
Responsible-Changed-Why:
I handled it


State-Changed-From-To: open->closed
State-Changed-By: pgoyette@NetBSD.org
State-Changed-When: Fri, 16 Jun 2017 22:43:07 +0000
State-Changed-Why:
Patch committed to HEAD


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.