Date: Wed, 23 May 2018 13:35:26 -0700 From: Ravi Pokala <rpokala@freebsd.org> To: Edward Tomasz Napierala <trasz@FreeBSD.org>, <src-committers@freebsd.org>, <svn-src-all@freebsd.org>, <svn-src-head@freebsd.org> Subject: Re: svn commit: r334115 - in head: share/man/man4 sys/dev/usb/template Message-ID: <9B0033E1-56EC-4CA0-BC28-056871B32B0A@panasas.com> In-Reply-To: <201805232006.w4NK64jS044384@repo.freebsd.org> References: <201805232006.w4NK64jS044384@repo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi Traz, You're referring to power consumption in terms of (milli)Amps. That's not r= ight; power is measured in Watts. What you're actually talking about is *cur= rent*. And it looks like in some situations USB devices can draw more than 5= 00mA. https://en.wikipedia.org/wiki/USB_(Physical)#POWER Thanks, Ravi (rpokala@)=20 =EF=BB=BF-----Original Message----- From: <owner-src-committers@freebsd.org> on behalf of Edward Tomasz Napiera= la <trasz@FreeBSD.org> Date: 2018-05-23, Wednesday at 13:06 To: <src-committers@freebsd.org>, <svn-src-all@freebsd.org>, <svn-src-head@= freebsd.org> Subject: svn commit: r334115 - in head: share/man/man4 sys/dev/usb/template Author: trasz Date: Wed May 23 20:06:04 2018 New Revision: 334115 URL: https://svnweb.freebsd.org/changeset/base/334115 Log: Centralize USB device mode bus power reporting, and add hw.usb.template_power sysctl to control it. =20 Reviewed by: hselasky@ (earlier version) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Modified: head/share/man/man4/usb_template.4 head/sys/dev/usb/template/usb_template.c head/sys/dev/usb/template/usb_template_audio.c head/sys/dev/usb/template/usb_template_cdce.c head/sys/dev/usb/template/usb_template_kbd.c head/sys/dev/usb/template/usb_template_midi.c head/sys/dev/usb/template/usb_template_modem.c head/sys/dev/usb/template/usb_template_mouse.c head/sys/dev/usb/template/usb_template_msc.c head/sys/dev/usb/template/usb_template_mtp.c head/sys/dev/usb/template/usb_template_multi.c head/sys/dev/usb/template/usb_template_phone.c head/sys/dev/usb/template/usb_template_serialnet.c Modified: head/share/man/man4/usb_template.4 =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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/share/man/man4/usb_template.4 Wed May 23 19:55:47 2018 (r334114) +++ head/share/man/man4/usb_template.4 Wed May 23 20:06:04 2018 (r334115) @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd May 17, 2018 +.Dd May 23, 2018 .Dt USB_TEMPLATE 4 .Os . @@ -100,6 +100,11 @@ tunables: .It Va hw.usb.template Currently selected template. Set to -1 to make the device disappear from the USB host point of view. +.It Va hw.usb.template_power +USB bus power consumption in mA. +Must be between 0 and 500. +Setting to 0 marks the device as self-powered. +Defaults to 500mA. .It Va hw.usb.templates.N Configuration for template number .Va N . Modified: head/sys/dev/usb/template/usb_template.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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/sys/dev/usb/template/usb_template.c Wed May 23 19:55:47 2018 (r334= 114) +++ head/sys/dev/usb/template/usb_template.c Wed May 23 20:06:04 2018 (r334= 115) @@ -76,14 +76,12 @@ #include <dev/usb/template/usb_template.h> #endif /* USB_GLOBAL_INCLUDE_FILE */ =20 -SYSCTL_NODE(_hw_usb, OID_AUTO, templates, CTLFLAG_RW, 0, - "USB device side templates"); - MODULE_DEPEND(usb_template, usb, 1, 1, 1); MODULE_VERSION(usb_template, 1); =20 /* function prototypes */ =20 +static int sysctl_hw_usb_template_power(SYSCTL_HANDLER_ARGS); static void usb_make_raw_desc(struct usb_temp_setup *, const uint8_t *); static void usb_make_endpoint_desc(struct usb_temp_setup *, const struct usb_temp_endpoint_desc *); @@ -117,6 +115,33 @@ static usb_error_t usb_temp_setup_by_index(struct usb_ uint16_t index); static void usb_temp_init(void *); =20 +SYSCTL_NODE(_hw_usb, OID_AUTO, templates, CTLFLAG_RW, 0, + "USB device side templates"); +SYSCTL_PROC(_hw_usb, OID_AUTO, template_power, + CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, + NULL, 0, sysctl_hw_usb_template_power, + "I", "USB bus power consumption in mA"); + +static int usb_template_power =3D 500; /* 500mA */ + +static int +sysctl_hw_usb_template_power(SYSCTL_HANDLER_ARGS) +{ + int error, val; + + val =3D usb_template_power; + error =3D sysctl_handle_int(oidp, &val, 0, req); + if (error !=3D 0 || req->newptr =3D=3D NULL) + return (error); + + if (val < 0 || val > 500) + return (EINVAL); + + usb_template_power =3D val; + + return (0); +} + /*------------------------------------------------------------------------= * * usb_decode_str_desc * @@ -426,6 +451,7 @@ usb_make_config_desc(struct usb_temp_setup *temp, struct usb_config_descriptor *cd; const struct usb_temp_interface_desc **tid; uint16_t old_size; + int power; =20 /* Reserve memory */ =20 @@ -463,13 +489,16 @@ usb_make_config_desc(struct usb_temp_setup *temp, cd->bConfigurationValue =3D temp->bConfigurationValue; cd->iConfiguration =3D tcd->iConfiguration; cd->bmAttributes =3D tcd->bmAttributes; - cd->bMaxPower =3D tcd->bMaxPower; - cd->bmAttributes |=3D (UC_REMOTE_WAKEUP | UC_BUS_POWERED); =20 - if (temp->self_powered) { - cd->bmAttributes |=3D UC_SELF_POWERED; - } else { + power =3D usb_template_power; + cd->bMaxPower =3D power / 2; /* 2 mA units */ + cd->bmAttributes |=3D UC_REMOTE_WAKEUP; + if (power > 0) { + cd->bmAttributes |=3D UC_BUS_POWERED; cd->bmAttributes &=3D ~UC_SELF_POWERED; + } else { + cd->bmAttributes &=3D ~UC_BUS_POWERED; + cd->bmAttributes |=3D UC_SELF_POWERED; } } } Modified: head/sys/dev/usb/template/usb_template_audio.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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/sys/dev/usb/template/usb_template_audio.c Wed May 23 19:55:47 2018= (r334114) +++ head/sys/dev/usb/template/usb_template_audio.c Wed May 23 20:06:04 2018= (r334115) @@ -351,8 +351,8 @@ static const struct usb_temp_interface_desc *audio_int =20 static const struct usb_temp_config_desc audio_config_desc =3D { .ppIfaceDesc =3D audio_interfaces, - .bmAttributes =3D UC_BUS_POWERED, - .bMaxPower =3D 25, /* 50 mA */ + .bmAttributes =3D 0, + .bMaxPower =3D 0, .iConfiguration =3D AUDIO_PRODUCT_INDEX, }; =20 Modified: head/sys/dev/usb/template/usb_template_cdce.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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/sys/dev/usb/template/usb_template_cdce.c Wed May 23 19:55:47 2018 = (r334114) +++ head/sys/dev/usb/template/usb_template_cdce.c Wed May 23 20:06:04 2018 = (r334115) @@ -219,8 +219,8 @@ static const struct usb_temp_interface_desc *eth_inter =20 static const struct usb_temp_config_desc eth_config_desc =3D { .ppIfaceDesc =3D eth_interfaces, - .bmAttributes =3D UC_BUS_POWERED, - .bMaxPower =3D 25, /* 50 mA */ + .bmAttributes =3D 0, + .bMaxPower =3D 0, .iConfiguration =3D ETH_CONFIGURATION_INDEX, }; =20 Modified: head/sys/dev/usb/template/usb_template_kbd.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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/sys/dev/usb/template/usb_template_kbd.c Wed May 23 19:55:47 2018 (= r334114) +++ head/sys/dev/usb/template/usb_template_kbd.c Wed May 23 20:06:04 2018 (= r334115) @@ -157,8 +157,8 @@ static const struct usb_temp_interface_desc *keyboard_ =20 static const struct usb_temp_config_desc keyboard_config_desc =3D { .ppIfaceDesc =3D keyboard_interfaces, - .bmAttributes =3D UC_BUS_POWERED, - .bMaxPower =3D 25, /* 50 mA */ + .bmAttributes =3D 0, + .bMaxPower =3D 0, .iConfiguration =3D KBD_PRODUCT_INDEX, }; =20 Modified: head/sys/dev/usb/template/usb_template_midi.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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/sys/dev/usb/template/usb_template_midi.c Wed May 23 19:55:47 2018 = (r334114) +++ head/sys/dev/usb/template/usb_template_midi.c Wed May 23 20:06:04 2018 = (r334115) @@ -199,8 +199,8 @@ static const struct usb_temp_interface_desc *midi_inte =20 static const struct usb_temp_config_desc midi_config_desc =3D { .ppIfaceDesc =3D midi_interfaces, - .bmAttributes =3D UC_BUS_POWERED, - .bMaxPower =3D 25, /* 50 mA */ + .bmAttributes =3D 0, + .bMaxPower =3D 0, .iConfiguration =3D MIDI_PRODUCT_INDEX, }; =20 Modified: head/sys/dev/usb/template/usb_template_modem.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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/sys/dev/usb/template/usb_template_modem.c Wed May 23 19:55:47 2018= (r334114) +++ head/sys/dev/usb/template/usb_template_modem.c Wed May 23 20:06:04 2018= (r334115) @@ -198,8 +198,8 @@ static const struct usb_temp_interface_desc *modem_int =20 static const struct usb_temp_config_desc modem_config_desc =3D { .ppIfaceDesc =3D modem_interfaces, - .bmAttributes =3D UC_BUS_POWERED, - .bMaxPower =3D 25, /* 50 mA */ + .bmAttributes =3D 0, + .bMaxPower =3D 0, .iConfiguration =3D MODEM_PRODUCT_INDEX, }; =20 Modified: head/sys/dev/usb/template/usb_template_mouse.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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/sys/dev/usb/template/usb_template_mouse.c Wed May 23 19:55:47 2018= (r334114) +++ head/sys/dev/usb/template/usb_template_mouse.c Wed May 23 20:06:04 2018= (r334115) @@ -155,8 +155,8 @@ static const struct usb_temp_interface_desc *mouse_int =20 static const struct usb_temp_config_desc mouse_config_desc =3D { .ppIfaceDesc =3D mouse_interfaces, - .bmAttributes =3D UC_BUS_POWERED, - .bMaxPower =3D 25, /* 50 mA */ + .bmAttributes =3D 0, + .bMaxPower =3D 0, .iConfiguration =3D MOUSE_INTERFACE_INDEX, }; =20 Modified: head/sys/dev/usb/template/usb_template_msc.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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/sys/dev/usb/template/usb_template_msc.c Wed May 23 19:55:47 2018 (= r334114) +++ head/sys/dev/usb/template/usb_template_msc.c Wed May 23 20:06:04 2018 (= r334115) @@ -142,8 +142,8 @@ static const struct usb_temp_interface_desc *msc_inter =20 static const struct usb_temp_config_desc msc_config_desc =3D { .ppIfaceDesc =3D msc_interfaces, - .bmAttributes =3D UC_BUS_POWERED, - .bMaxPower =3D 25, /* 50 mA */ + .bmAttributes =3D 0, + .bMaxPower =3D 0, .iConfiguration =3D MSC_CONFIGURATION_INDEX, }; =20 Modified: head/sys/dev/usb/template/usb_template_mtp.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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/sys/dev/usb/template/usb_template_mtp.c Wed May 23 19:55:47 2018 (= r334114) +++ head/sys/dev/usb/template/usb_template_mtp.c Wed May 23 20:06:04 2018 (= r334115) @@ -164,8 +164,8 @@ static const struct usb_temp_interface_desc *mtp_inter =20 static const struct usb_temp_config_desc mtp_config_desc =3D { .ppIfaceDesc =3D mtp_interfaces, - .bmAttributes =3D UC_BUS_POWERED, - .bMaxPower =3D 25, /* 50 mA */ + .bmAttributes =3D 0, + .bMaxPower =3D 0, .iConfiguration =3D MTP_CONFIGURATION_INDEX, }; =20 Modified: head/sys/dev/usb/template/usb_template_multi.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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/sys/dev/usb/template/usb_template_multi.c Wed May 23 19:55:47 2018= (r334114) +++ head/sys/dev/usb/template/usb_template_multi.c Wed May 23 20:06:04 2018= (r334115) @@ -370,8 +370,8 @@ static const struct usb_temp_interface_desc *multi_int =20 static const struct usb_temp_config_desc multi_config_desc =3D { .ppIfaceDesc =3D multi_interfaces, - .bmAttributes =3D UC_BUS_POWERED, - .bMaxPower =3D 25, /* 50 mA */ + .bmAttributes =3D 0, + .bMaxPower =3D 0, .iConfiguration =3D MULTI_CONFIGURATION_INDEX, }; static const struct usb_temp_config_desc *multi_configs[] =3D { Modified: head/sys/dev/usb/template/usb_template_phone.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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/sys/dev/usb/template/usb_template_phone.c Wed May 23 19:55:47 2018= (r334114) +++ head/sys/dev/usb/template/usb_template_phone.c Wed May 23 20:06:04 2018= (r334115) @@ -347,8 +347,8 @@ static const struct usb_temp_interface_desc *phone_int =20 static const struct usb_temp_config_desc phone_config_desc =3D { .ppIfaceDesc =3D phone_interfaces, - .bmAttributes =3D UC_BUS_POWERED, - .bMaxPower =3D 25, /* 50 mA */ + .bmAttributes =3D 0, + .bMaxPower =3D 0, .iConfiguration =3D PHONE_PRODUCT_INDEX, }; =20 Modified: head/sys/dev/usb/template/usb_template_serialnet.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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- head/sys/dev/usb/template/usb_template_serialnet.c Wed May 23 19:55:47 = 2018 (r334114) +++ head/sys/dev/usb/template/usb_template_serialnet.c Wed May 23 20:06:04 = 2018 (r334115) @@ -327,8 +327,8 @@ static const struct usb_temp_interface_desc *serialnet =20 static const struct usb_temp_config_desc serialnet_config_desc =3D { .ppIfaceDesc =3D serialnet_interfaces, - .bmAttributes =3D UC_BUS_POWERED, - .bMaxPower =3D 25, /* 50 mA */ + .bmAttributes =3D 0, + .bMaxPower =3D 0, .iConfiguration =3D SERIALNET_CONFIGURATION_INDEX, }; static const struct usb_temp_config_desc *serialnet_configs[] =3D {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9B0033E1-56EC-4CA0-BC28-056871B32B0A>