Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Feb 2015 21:02:33 +0000 (UTC)
From:      Luiz Otavio O Souza <loos@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r278785 - stable/10/sys/dev/gpio
Message-ID:  <201502142102.t1EL2XMS079782@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: loos
Date: Sat Feb 14 21:02:33 2015
New Revision: 278785
URL: https://svnweb.freebsd.org/changeset/base/278785

Log:
  MFC r274642, 274643:
  
  Remove unnecessary code.
  
  After r273566, the gpiobus version of bus_print_child() also works on FDT
  systems.
  
  Fix gpiobus_child_location_str() to return a real string with the mapped
  pins.
  
  Make gpiobus_print_pins() static again.

Modified:
  stable/10/sys/dev/gpio/gpiobus.c
  stable/10/sys/dev/gpio/gpiobusvar.h
  stable/10/sys/dev/gpio/ofw_gpiobus.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/gpio/gpiobus.c
==============================================================================
--- stable/10/sys/dev/gpio/gpiobus.c	Sat Feb 14 20:57:27 2015	(r278784)
+++ stable/10/sys/dev/gpio/gpiobus.c	Sat Feb 14 21:02:33 2015	(r278785)
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
 #define	dprintf(x, arg...)
 #endif
 
+static void gpiobus_print_pins(struct gpiobus_ivar *, char *, size_t);
 static int gpiobus_parse_pins(struct gpiobus_softc *, device_t, int);
 static int gpiobus_probe(device_t);
 static int gpiobus_attach(device_t);
@@ -69,11 +70,11 @@ static int gpiobus_pin_set(device_t, dev
 static int gpiobus_pin_get(device_t, device_t, uint32_t, unsigned int*);
 static int gpiobus_pin_toggle(device_t, device_t, uint32_t);
 
-void
-gpiobus_print_pins(struct gpiobus_ivar *devi)
+static void
+gpiobus_print_pins(struct gpiobus_ivar *devi, char *buf, size_t buflen)
 {
-	int range_start, range_stop, need_coma;
-	int i;
+	char tmp[128];
+	int i, range_start, range_stop, need_coma;
 
 	if (devi->npins == 0)
 		return;
@@ -83,11 +84,15 @@ gpiobus_print_pins(struct gpiobus_ivar *
 	for (i = 1; i < devi->npins; i++) {
 		if (devi->pins[i] != (range_stop + 1)) {
 			if (need_coma)
-				printf(",");
+				strlcat(buf, ",", buflen);
+			memset(tmp, 0, sizeof(tmp));
 			if (range_start != range_stop)
-				printf("%d-%d", range_start, range_stop);
+				snprintf(tmp, sizeof(tmp) - 1, "%d-%d",
+				    range_start, range_stop);
 			else
-				printf("%d", range_start);
+				snprintf(tmp, sizeof(tmp) - 1, "%d",
+				    range_start);
+			strlcat(buf, tmp, buflen);
 
 			range_start = range_stop = devi->pins[i];
 			need_coma = 1;
@@ -97,11 +102,15 @@ gpiobus_print_pins(struct gpiobus_ivar *
 	}
 
 	if (need_coma)
-		printf(",");
+		strlcat(buf, ",", buflen);
+	memset(tmp, 0, sizeof(tmp));
 	if (range_start != range_stop)
-		printf("%d-%d", range_start, range_stop);
+		snprintf(tmp, sizeof(tmp) - 1, "%d-%d",
+		    range_start, range_stop);
 	else
-		printf("%d", range_start);
+		snprintf(tmp, sizeof(tmp) - 1, "%d",
+		    range_start);
+	strlcat(buf, tmp, buflen);
 }
 
 int
@@ -273,12 +282,16 @@ gpiobus_resume(device_t dev)
 static int
 gpiobus_print_child(device_t dev, device_t child)
 {
-	struct gpiobus_ivar *devi = GPIOBUS_IVAR(child);
+	char pins[128];
 	int retval = 0;
+	struct gpiobus_ivar *devi;
 
+	devi = GPIOBUS_IVAR(child);
+	memset(pins, 0, sizeof(pins));
 	retval += bus_print_child_header(dev, child);
 	retval += printf(" at pin(s) ");
-	gpiobus_print_pins(devi);
+	gpiobus_print_pins(devi, pins, sizeof(pins));
+	retval += printf("%s", pins);
 	resource_list_print_type(&devi->rl, "irq", SYS_RES_IRQ, "%ld");
 	retval += bus_print_child_footer(dev, child);
 
@@ -289,8 +302,12 @@ static int
 gpiobus_child_location_str(device_t bus, device_t child, char *buf,
     size_t buflen)
 {
+	struct gpiobus_ivar *devi;
+
+	devi = GPIOBUS_IVAR(child);
+	strlcpy(buf, "pin(s)=", buflen);
+	gpiobus_print_pins(devi, buf, buflen);
 
-	snprintf(buf, buflen, "pins=?");
 	return (0);
 }
 

Modified: stable/10/sys/dev/gpio/gpiobusvar.h
==============================================================================
--- stable/10/sys/dev/gpio/gpiobusvar.h	Sat Feb 14 20:57:27 2015	(r278784)
+++ stable/10/sys/dev/gpio/gpiobusvar.h	Sat Feb 14 21:02:33 2015	(r278785)
@@ -94,7 +94,6 @@ gpio_map_gpios(device_t bus, phandle_t d
 
 device_t ofw_gpiobus_add_fdt_child(device_t, phandle_t);
 #endif
-void gpiobus_print_pins(struct gpiobus_ivar *);
 int gpiobus_init_softc(device_t);
 
 extern driver_t gpiobus_driver;

Modified: stable/10/sys/dev/gpio/ofw_gpiobus.c
==============================================================================
--- stable/10/sys/dev/gpio/ofw_gpiobus.c	Sat Feb 14 20:57:27 2015	(r278784)
+++ stable/10/sys/dev/gpio/ofw_gpiobus.c	Sat Feb 14 21:02:33 2015	(r278785)
@@ -324,23 +324,6 @@ ofw_gpiobus_add_child(device_t dev, u_in
 	return (child);
 }
 
-static int
-ofw_gpiobus_print_child(device_t dev, device_t child)
-{
-	struct ofw_gpiobus_devinfo *devi;
-	int retval = 0;
-
-	devi = device_get_ivars(child);
-	retval += bus_print_child_header(dev, child);
-	retval += printf(" at pin(s) ");
-	gpiobus_print_pins(&devi->opd_dinfo);
-	resource_list_print_type(&devi->opd_dinfo.rl, "irq", SYS_RES_IRQ,
-	    "%ld");
-	retval += bus_print_child_footer(dev, child);
-
-	return (retval);
-}
-
 static const struct ofw_bus_devinfo *
 ofw_gpiobus_get_devinfo(device_t bus, device_t dev)
 {
@@ -358,7 +341,6 @@ static device_method_t ofw_gpiobus_metho
 
 	/* Bus interface */
 	DEVMETHOD(bus_child_pnpinfo_str,	ofw_bus_gen_child_pnpinfo_str),
-	DEVMETHOD(bus_print_child,	ofw_gpiobus_print_child),
 	DEVMETHOD(bus_add_child,	ofw_gpiobus_add_child),
 
 	/* ofw_bus interface */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201502142102.t1EL2XMS079782>