svn commit: r247475 - in stable/9: lib/libusb sys/dev/usb usr.sbin/usbconfig

Hans Petter Selasky hselasky at FreeBSD.org
Thu Feb 28 16:56:11 UTC 2013


Author: hselasky
Date: Thu Feb 28 16:56:08 2013
New Revision: 247475
URL: http://svnweb.freebsd.org/changeset/base/247475

Log:
  MFC r246789:
  Add USB API to read power draw on USB devices.
  Update usbconfig to print power draw on USB devices.

Modified:
  stable/9/lib/libusb/Makefile
  stable/9/lib/libusb/libusb20.3
  stable/9/lib/libusb/libusb20.c
  stable/9/lib/libusb/libusb20.h
  stable/9/lib/libusb/libusb20_int.h
  stable/9/lib/libusb/libusb20_ugen20.c
  stable/9/sys/dev/usb/usb_generic.c
  stable/9/sys/dev/usb/usb_ioctl.h
  stable/9/usr.sbin/usbconfig/dump.c
Directory Properties:
  stable/9/lib/   (props changed)
  stable/9/lib/libusb/   (props changed)
  stable/9/sys/   (props changed)
  stable/9/sys/dev/   (props changed)
  stable/9/usr.sbin/   (props changed)

Modified: stable/9/lib/libusb/Makefile
==============================================================================
--- stable/9/lib/libusb/Makefile	Thu Feb 28 16:43:41 2013	(r247474)
+++ stable/9/lib/libusb/Makefile	Thu Feb 28 16:56:08 2013	(r247475)
@@ -189,6 +189,7 @@ MLINKS += libusb20.3 libusb20_dev_reset.
 MLINKS += libusb20.3 libusb20_dev_check_connected.3
 MLINKS += libusb20.3 libusb20_dev_set_power_mode.3
 MLINKS += libusb20.3 libusb20_dev_get_power_mode.3
+MLINKS += libusb20.3 libusb20_dev_get_power_usage.3
 MLINKS += libusb20.3 libusb20_dev_set_alt_index.3
 MLINKS += libusb20.3 libusb20_dev_get_device_desc.3
 MLINKS += libusb20.3 libusb20_dev_alloc_config.3

Modified: stable/9/lib/libusb/libusb20.3
==============================================================================
--- stable/9/lib/libusb/libusb20.3	Thu Feb 28 16:43:41 2013	(r247474)
+++ stable/9/lib/libusb/libusb20.3	Thu Feb 28 16:56:08 2013	(r247475)
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd October 14, 2010
+.Dd February 14, 2013
 .Dt LIBUSB20 3
 .Os
 .Sh NAME
@@ -148,6 +148,8 @@ USB access library (libusb -lusb)
 .Fn libusb20_dev_set_power_mode "struct libusb20_device *pdev" "uint8_t power_mode"
 .Ft uint8_t
 .Fn libusb20_dev_get_power_mode "struct libusb20_device *pdev"
+.Ft uint16_t
+.Fn libusb20_dev_get_power_usage "struct libusb20_device *pdev"
 .Ft int
 .Fn libusb20_dev_set_alt_index "struct libusb20_device *pdev" "uint8_t iface_index" "uint8_t alt_index"
 .Ft struct LIBUSB20_DEVICE_DESC_DECODED *
@@ -728,6 +730,12 @@ USB device.
 .
 .Pp
 .
+.Fn libusb20_dev_get_power_usage
+returns the reported power usage in milliamps for the given USB device.
+A power usage of zero typically means that the device is self powered.
+.
+.Pp
+.
 .Fn libusb20_dev_set_alt_index
 will try to set the given alternate index for the given
 USB interface index.

Modified: stable/9/lib/libusb/libusb20.c
==============================================================================
--- stable/9/lib/libusb/libusb20.c	Thu Feb 28 16:43:41 2013	(r247474)
+++ stable/9/lib/libusb/libusb20.c	Thu Feb 28 16:56:08 2013	(r247475)
@@ -71,6 +71,7 @@ dummy_callback(struct libusb20_transfer 
 #define	dummy_check_connected (void *)dummy_int
 #define	dummy_set_power_mode (void *)dummy_int
 #define	dummy_get_power_mode (void *)dummy_int
+#define	dummy_get_power_usage (void *)dummy_int
 #define	dummy_kernel_driver_active (void *)dummy_int
 #define	dummy_detach_kernel_driver (void *)dummy_int
 #define	dummy_do_request_sync (void *)dummy_int
@@ -710,6 +711,18 @@ libusb20_dev_get_power_mode(struct libus
 	return (power_mode);
 }
 
+uint16_t
+libusb20_dev_get_power_usage(struct libusb20_device *pdev)
+{
+	int error;
+	uint16_t power_usage;
+
+	error = pdev->methods->get_power_usage(pdev, &power_usage);
+	if (error)
+		power_usage = 0;
+	return (power_usage);
+}
+
 int
 libusb20_dev_set_alt_index(struct libusb20_device *pdev, uint8_t ifaceIndex, uint8_t altIndex)
 {

Modified: stable/9/lib/libusb/libusb20.h
==============================================================================
--- stable/9/lib/libusb/libusb20.h	Thu Feb 28 16:43:41 2013	(r247474)
+++ stable/9/lib/libusb/libusb20.h	Thu Feb 28 16:56:08 2013	(r247475)
@@ -254,6 +254,7 @@ int	libusb20_dev_reset(struct libusb20_d
 int	libusb20_dev_check_connected(struct libusb20_device *pdev);
 int	libusb20_dev_set_power_mode(struct libusb20_device *pdev, uint8_t power_mode);
 uint8_t	libusb20_dev_get_power_mode(struct libusb20_device *pdev);
+uint16_t	libusb20_dev_get_power_usage(struct libusb20_device *pdev);
 int	libusb20_dev_set_alt_index(struct libusb20_device *pdev, uint8_t iface_index, uint8_t alt_index);
 int	libusb20_dev_get_info(struct libusb20_device *pdev, struct usb_device_info *pinfo);
 int	libusb20_dev_get_iface_desc(struct libusb20_device *pdev, uint8_t iface_index, char *buf, uint8_t len);

Modified: stable/9/lib/libusb/libusb20_int.h
==============================================================================
--- stable/9/lib/libusb/libusb20_int.h	Thu Feb 28 16:43:41 2013	(r247474)
+++ stable/9/lib/libusb/libusb20_int.h	Thu Feb 28 16:56:08 2013	(r247475)
@@ -105,6 +105,7 @@ typedef int (libusb20_process_t)(struct 
 typedef int (libusb20_reset_device_t)(struct libusb20_device *pdev);
 typedef int (libusb20_set_power_mode_t)(struct libusb20_device *pdev, uint8_t power_mode);
 typedef int (libusb20_get_power_mode_t)(struct libusb20_device *pdev, uint8_t *power_mode);
+typedef int (libusb20_get_power_usage_t)(struct libusb20_device *pdev, uint16_t *power_usage);
 typedef int (libusb20_set_alt_index_t)(struct libusb20_device *pdev, uint8_t iface_index, uint8_t alt_index);
 typedef int (libusb20_set_config_index_t)(struct libusb20_device *pdev, uint8_t index);
 typedef int (libusb20_check_connected_t)(struct libusb20_device *pdev);
@@ -127,6 +128,7 @@ typedef void (libusb20_tr_cancel_async_t
   m(n, check_connected) \
   m(n, set_power_mode) \
   m(n, get_power_mode) \
+  m(n, get_power_usage) \
   m(n, set_alt_index) \
   m(n, set_config_index) \
   m(n, tr_cancel_async) \

Modified: stable/9/lib/libusb/libusb20_ugen20.c
==============================================================================
--- stable/9/lib/libusb/libusb20_ugen20.c	Thu Feb 28 16:43:41 2013	(r247474)
+++ stable/9/lib/libusb/libusb20_ugen20.c	Thu Feb 28 16:56:08 2013	(r247475)
@@ -69,6 +69,7 @@ static libusb20_reset_device_t ugen20_re
 static libusb20_check_connected_t ugen20_check_connected;
 static libusb20_set_power_mode_t ugen20_set_power_mode;
 static libusb20_get_power_mode_t ugen20_get_power_mode;
+static libusb20_get_power_usage_t ugen20_get_power_usage;
 static libusb20_kernel_driver_active_t ugen20_kernel_driver_active;
 static libusb20_detach_kernel_driver_t ugen20_detach_kernel_driver;
 static libusb20_do_request_sync_t ugen20_do_request_sync;
@@ -639,6 +640,18 @@ ugen20_get_power_mode(struct libusb20_de
 }
 
 static int
+ugen20_get_power_usage(struct libusb20_device *pdev, uint16_t *power_usage)
+{
+	int temp;
+
+	if (ioctl(pdev->file_ctrl, USB_GET_POWER_USAGE, &temp)) {
+		return (LIBUSB20_ERROR_OTHER);
+	}
+	*power_usage = temp;
+	return (0);			/* success */
+}
+
+static int
 ugen20_kernel_driver_active(struct libusb20_device *pdev,
     uint8_t iface_index)
 {

Modified: stable/9/sys/dev/usb/usb_generic.c
==============================================================================
--- stable/9/sys/dev/usb/usb_generic.c	Thu Feb 28 16:43:41 2013	(r247474)
+++ stable/9/sys/dev/usb/usb_generic.c	Thu Feb 28 16:56:08 2013	(r247475)
@@ -1831,6 +1831,17 @@ ugen_get_power_mode(struct usb_fifo *f)
 }
 
 static int
+ugen_get_power_usage(struct usb_fifo *f)
+{
+	struct usb_device *udev = f->udev;
+
+	if (udev == NULL)
+		return (0);
+
+	return (udev->power);
+}
+
+static int
 ugen_do_port_feature(struct usb_fifo *f, uint8_t port_no,
     uint8_t set, uint16_t feature)
 {
@@ -2192,6 +2203,10 @@ ugen_ioctl_post(struct usb_fifo *f, u_lo
 		*u.pint = ugen_get_power_mode(f);
 		break;
 
+	case USB_GET_POWER_USAGE:
+		*u.pint = ugen_get_power_usage(f);
+		break;
+
 	case USB_SET_PORT_ENABLE:
 		error = ugen_do_port_feature(f,
 		    *u.pint, 1, UHF_PORT_ENABLE);

Modified: stable/9/sys/dev/usb/usb_ioctl.h
==============================================================================
--- stable/9/sys/dev/usb/usb_ioctl.h	Thu Feb 28 16:43:41 2013	(r247474)
+++ stable/9/sys/dev/usb/usb_ioctl.h	Thu Feb 28 16:56:08 2013	(r247475)
@@ -270,7 +270,8 @@ struct usb_gen_quirk {
 #define	USB_IFACE_DRIVER_DETACH	_IOW ('U', 125, int)
 #define	USB_GET_PLUGTIME	_IOR ('U', 126, uint32_t)
 #define	USB_READ_DIR		_IOW ('U', 127, struct usb_read_dir)
-/* 128 - 135 unused */
+/* 128 - 134 unused */
+#define	USB_GET_POWER_USAGE	_IOR ('U', 135, int)
 #define	USB_SET_TX_FORCE_SHORT	_IOW ('U', 136, int)
 #define	USB_SET_TX_TIMEOUT	_IOW ('U', 137, int)
 #define	USB_GET_TX_FRAME_SIZE	_IOR ('U', 138, int)

Modified: stable/9/usr.sbin/usbconfig/dump.c
==============================================================================
--- stable/9/usr.sbin/usbconfig/dump.c	Thu Feb 28 16:43:41 2013	(r247474)
+++ stable/9/usr.sbin/usbconfig/dump.c	Thu Feb 28 16:56:08 2013	(r247475)
@@ -225,13 +225,17 @@ dump_device_info(struct libusb20_device 
 {
 	char buf[128];
 	uint8_t n;
+	unsigned int usage;
 
-	printf("%s, cfg=%u md=%s spd=%s pwr=%s\n",
+	usage = libusb20_dev_get_power_usage(pdev);
+
+	printf("%s, cfg=%u md=%s spd=%s pwr=%s (%umA)\n",
 	    libusb20_dev_get_desc(pdev),
 	    libusb20_dev_get_config_index(pdev),
 	    dump_mode(libusb20_dev_get_mode(pdev)),
 	    dump_speed(libusb20_dev_get_speed(pdev)),
-	    dump_power_mode(libusb20_dev_get_power_mode(pdev)));
+	    dump_power_mode(libusb20_dev_get_power_mode(pdev)),
+	    usage);
 
 	if (!show_ifdrv)
 		return;


More information about the svn-src-stable-9 mailing list