aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2013-02-14 12:22:40 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2013-02-14 12:22:40 +0000
commitaafcb7320759529843b0d0efa3c6a918aa1aaa50 (patch)
treea0b0c710f98a991d5594c3cd1efed27bd508c825 /lib
parent0af99eef9e4d3c463ece2da2342499cd5b55b8ab (diff)
downloadsrc-aafcb7320759529843b0d0efa3c6a918aa1aaa50.tar.gz
src-aafcb7320759529843b0d0efa3c6a918aa1aaa50.zip
Add USB API to read power draw on USB devices.
Update usbconfig to print power draw on USB devices. MFC after: 2 weeks Submitted by: Matt Burke @ icritical.com
Notes
Notes: svn path=/head/; revision=246789
Diffstat (limited to 'lib')
-rw-r--r--lib/libusb/Makefile1
-rw-r--r--lib/libusb/libusb20.310
-rw-r--r--lib/libusb/libusb20.c13
-rw-r--r--lib/libusb/libusb20.h1
-rw-r--r--lib/libusb/libusb20_int.h2
-rw-r--r--lib/libusb/libusb20_ugen20.c13
6 files changed, 39 insertions, 1 deletions
diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile
index d45dd567b437..9c2c9b45a87d 100644
--- a/lib/libusb/Makefile
+++ b/lib/libusb/Makefile
@@ -190,6 +190,7 @@ MLINKS += libusb20.3 libusb20_dev_reset.3
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
diff --git a/lib/libusb/libusb20.3 b/lib/libusb/libusb20.3
index af80c6ca564e..8d286f13723f 100644
--- a/lib/libusb/libusb20.3
+++ b/lib/libusb/libusb20.3
@@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd August 13, 2012
+.Dd February 14, 2013
.Dt LIBUSB20 3
.Os
.Sh NAME
@@ -149,6 +149,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 *
@@ -740,6 +742,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.
diff --git a/lib/libusb/libusb20.c b/lib/libusb/libusb20.c
index aa459913ec98..ce7551131d10 100644
--- a/lib/libusb/libusb20.c
+++ b/lib/libusb/libusb20.c
@@ -71,6 +71,7 @@ dummy_callback(struct libusb20_transfer *xfer)
#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
@@ -717,6 +718,18 @@ libusb20_dev_get_power_mode(struct libusb20_device *pdev)
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)
{
diff --git a/lib/libusb/libusb20.h b/lib/libusb/libusb20.h
index 87e057262067..81928b143466 100644
--- a/lib/libusb/libusb20.h
+++ b/lib/libusb/libusb20.h
@@ -255,6 +255,7 @@ int libusb20_dev_reset(struct libusb20_device *pdev);
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);
diff --git a/lib/libusb/libusb20_int.h b/lib/libusb/libusb20_int.h
index 0251c5f6ed07..6705c630c868 100644
--- a/lib/libusb/libusb20_int.h
+++ b/lib/libusb/libusb20_int.h
@@ -105,6 +105,7 @@ typedef int (libusb20_process_t)(struct libusb20_device *pdev);
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)(struct libusb20_transfer *xfer);
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) \
diff --git a/lib/libusb/libusb20_ugen20.c b/lib/libusb/libusb20_ugen20.c
index 2c677783d850..bff8e02e7c26 100644
--- a/lib/libusb/libusb20_ugen20.c
+++ b/lib/libusb/libusb20_ugen20.c
@@ -69,6 +69,7 @@ static libusb20_reset_device_t ugen20_reset_device;
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_device *pdev, uint8_t *power_mode)
}
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)
{