New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
usb: make usb descriptor power options configurable #21461
usb: make usb descriptor power options configurable #21461
Conversation
All checks are passing now. checkpatch (informational only, not a failure)
Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages. |
7cfce3f
to
35fa2a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also squash to one commit.
35fa2a8
to
369178f
Compare
@jfischer-phytec-iot I made all the changes John recommended and squashed to a single commit. |
include/usb/usb_common.h
Outdated
| (COND_CODE_1(CONFIG_USB_DEVICE_REMOTE_WAKEUP, \ | ||
(USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP), (0))) | ||
#define USB_CONFIGURATION_ATTRIBUTES_SELF_POWERED 0xC0 | ||
#define USB_CONFIGURATION_ATTRIBUTES ((COND_CODE_1(USB_SELF_POWERED, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/USB_SELF_POWERED/CONFIG_USB_SELF_POWERED
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Should be set to y is the device" -> "Should be set to y if the device" in the commit message
include/usb/usb_common.h
Outdated
@@ -101,9 +101,11 @@ | |||
* D4...0:Reserved -> 0 | |||
*/ | |||
#define USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP 0x20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact USB_CONFIGURATION_ATTRIBUTES is bitmask so i would personally go for:
diff --git a/include/usb/usb_common.h b/include/usb/usb_common.h
index 632524a464..d2220a9692 100644
--- a/include/usb/usb_common.h
+++ b/include/usb/usb_common.h
@@ -100,9 +100,10 @@
* D5:Remote Wakeup -> 0,
* D4...0:Reserved -> 0
*/
-#define USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP 0x20
-#define USB_CONFIGURATION_ATTRIBUTES_SELF_POWERED 0xC0
-#define USB_CONFIGURATION_ATTRIBUTES ((COND_CODE_1(USB_SELF_POWERED, \
+#define USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP BIT(5)
+#define USB_CONFIGURATION_ATTRIBUTES_SELF_POWERED BIT(6)
+#define USB_CONFIGURATION_ATTRIBUTES BIT(7) \
+ | ((COND_CODE_1(USB_SELF_POWERED, \
(USB_CONFIGURATION_ATTRIBUTES_SELF_POWERED), (0))) \
| (COND_CODE_1(CONFIG_USB_DEVICE_REMOTE_WAKEUP, \
(USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP), (0))))
As @jfischer-phytec-iot mentioned BIT(7) must be set (historical reasons - could be found in usb20 spec)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(+) s/USB_SELF_POWERED/CONFIG_USB_SELF_POWERED as @jfischer-phytec-iot mentioned. I forgot about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And on the parentheses around the zeo in the 3rd argument of COND_CODE_1 that seems pretty standard. I see it in other places in the repo. Sometimes the argument is even empty parentheses.
369178f
to
0611e0e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgmt now.
Add two new kconfig options USB_SELF_POWERED and USB_MAX_POWER. These can be set by the user to change the USB configuration descriptor. USB_MAX_POWER can be set to any value between 0 and 250, but practically should be 50 or 250. These values are half the ammount of mA that the device will tell the host that it needs. USB_SELF_POWERED sets the 7th bit in bmAttributes of the USB config descriptor. Should be set to y if the device has its own power source other than USB. Signed-off-by: Barry Solomon <barry.solomon@dexcom.com>
0611e0e
to
95c500f
Compare
#define USB_CONFIGURATION_ATTRIBUTES 0xC0 \ | ||
| (COND_CODE_1(CONFIG_USB_DEVICE_REMOTE_WAKEUP, \ | ||
(USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP), (0))) | ||
#define USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP BIT(5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will consider one more thing:
diff --git a/include/usb/usb_common.h b/include/usb/usb_common.h
index c3c0058e2e..7aa98c3d8e 100644
--- a/include/usb/usb_common.h
+++ b/include/usb/usb_common.h
@@ -95,13 +95,9 @@
* D5:Remote Wakeup -> 0,
* D4...0:Reserved -> 0
*/
-#define USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP BIT(5)
-#define USB_CONFIGURATION_ATTRIBUTES_SELF_POWERED BIT(6)
#define USB_CONFIGURATION_ATTRIBUTES BIT(7) \
- | ((COND_CODE_1(CONFIG_USB_SELF_POWERED, \
- (USB_CONFIGURATION_ATTRIBUTES_SELF_POWERED), (0))) \
- | (COND_CODE_1(CONFIG_USB_DEVICE_REMOTE_WAKEUP, \
- (USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP), (0))))
+ | (COND_CODE_1(CONFIG_USB_SELF_POWERED, (BIT(6)), (0))) \
+ | (COND_CODE_1(CONFIG_USB_DEVICE_REMOTE_WAKEUP, (BIT(5)), (0)))
/* Classes */
#define COMMUNICATION_DEVICE_CLASS 0x02
As those macros are not used anywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No please do not remove this defines, it makes code more readable also could be used in the stack or application (it is public API ).
(USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP), (0))) | ||
#define USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP BIT(5) | ||
#define USB_CONFIGURATION_ATTRIBUTES_SELF_POWERED BIT(6) | ||
#define USB_CONFIGURATION_ATTRIBUTES BIT(7) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would indent this line with tabs to be aligned with the lines above.
diff --git a/include/usb/usb_common.h b/include/usb/usb_common.h
index c3c0058e2e..1dba1d163b 100644
--- a/include/usb/usb_common.h
+++ b/include/usb/usb_common.h
@@ -97,11 +97,11 @@
*/
#define USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP BIT(5)
#define USB_CONFIGURATION_ATTRIBUTES_SELF_POWERED BIT(6)
-#define USB_CONFIGURATION_ATTRIBUTES BIT(7) \
- | ((COND_CODE_1(CONFIG_USB_SELF_POWERED, \
- (USB_CONFIGURATION_ATTRIBUTES_SELF_POWERED), (0))) \
- | (COND_CODE_1(CONFIG_USB_DEVICE_REMOTE_WAKEUP, \
- (USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP), (0))))
+#define USB_CONFIGURATION_ATTRIBUTES BIT(7) \
+ | ((COND_CODE_1(CONFIG_USB_SELF_POWERED, \
+ (USB_CONFIGURATION_ATTRIBUTES_SELF_POWERED), (0))) \
+ | (COND_CODE_1(CONFIG_USB_DEVICE_REMOTE_WAKEUP, \
+ (USB_CONFIGURATION_ATTRIBUTES_REMOTE_WAKEUP), (0))))
Add two new kconfig options USB_SELF_POWERED and USB_MAX_POWER.
These can be set by the user to change the USB configuration descriptor.
USB_MAX_POWER can be set to any value between 0 and 250, but practically
should be 50 or 250. These values are half the ammount of mA that the
device will tell the host that it needs.
USB_SELF_POWERED sets the 7th bit in bmAttributes of the USB config
descriptor. Should be set to y is the device has its own power source
other than USB.
Proposed fix for #19545
Signed-off-by: Barry Solomon barry.solomon@dexcom.com