All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	linux-usb@vger.kernel.org
Cc: John Youn <John.Youn@synopsys.com>
Subject: [PATCH 02/11] usb: gadget: composite: Avoid using magic numbers
Date: Thu, 16 Jul 2020 14:58:42 -0700	[thread overview]
Message-ID: <b94bbb8362043b43fec8642ee7f0c28418cf99d1.1594935978.git.thinhn@synopsys.com> (raw)
In-Reply-To: <cover.1594935978.git.thinhn@synopsys.com>

Magic numbers are difficult to read. Use macros for super-speed-plus BOS
descriptor attributes in the composite driver. They're self-documented.
So there's no need to provide comments as we did previously for the
magic numbers.

Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
---
 drivers/usb/gadget/composite.c | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 5c1eb96a5c57..a231ae382ac3 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/utsname.h>
+#include <linux/bitfield.h>
 
 #include <linux/usb/composite.h>
 #include <linux/usb/otg.h>
@@ -743,32 +744,30 @@ static int bos_desc(struct usb_composite_dev *cdev)
 		ssp_cap->bReserved = 0;
 		ssp_cap->wReserved = 0;
 
-		/* SSAC = 1 (2 attributes) */
-		ssp_cap->bmAttributes = cpu_to_le32(1);
+		ssp_cap->bmAttributes =
+			cpu_to_le32(FIELD_PREP(USB_SSP_SUBLINK_SPEED_ATTRIBS, 1) |
+				    FIELD_PREP(USB_SSP_SUBLINK_SPEED_IDS, 0));
 
-		/* Min RX/TX Lane Count = 1 */
 		ssp_cap->wFunctionalitySupport =
-			cpu_to_le16((1 << 8) | (1 << 12));
+			cpu_to_le16(FIELD_PREP(USB_SSP_MIN_SUBLINK_SPEED_ATTRIBUTE_ID, 0) |
+				    FIELD_PREP(USB_SSP_MIN_RX_LANE_COUNT, 1) |
+				    FIELD_PREP(USB_SSP_MIN_TX_LANE_COUNT, 1));
 
-		/*
-		 * bmSublinkSpeedAttr[0]:
-		 *   ST  = Symmetric, RX
-		 *   LSE =  3 (Gbps)
-		 *   LP  =  1 (SuperSpeedPlus)
-		 *   LSM = 10 (10 Gbps)
-		 */
 		ssp_cap->bmSublinkSpeedAttr[0] =
-			cpu_to_le32((3 << 4) | (1 << 14) | (0xa << 16));
-		/*
-		 * bmSublinkSpeedAttr[1] =
-		 *   ST  = Symmetric, TX
-		 *   LSE =  3 (Gbps)
-		 *   LP  =  1 (SuperSpeedPlus)
-		 *   LSM = 10 (10 Gbps)
-		 */
+			cpu_to_le32(FIELD_PREP(USB_SSP_SUBLINK_SPEED_SSID, 0) |
+				    FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSE, USB_LSE_GBPS) |
+				    FIELD_PREP(USB_SSP_SUBLINK_SPEED_ST,
+					       USB_ST_SYMMETRIC_RX) |
+				    FIELD_PREP(USB_SSP_SUBLINK_SPEED_LP, USB_LP_SSP) |
+				    FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSM, 10));
+
 		ssp_cap->bmSublinkSpeedAttr[1] =
-			cpu_to_le32((3 << 4) | (1 << 14) |
-				    (0xa << 16) | (1 << 7));
+			cpu_to_le32(FIELD_PREP(USB_SSP_SUBLINK_SPEED_SSID, 0) |
+				    FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSE, USB_LSE_GBPS) |
+				    FIELD_PREP(USB_SSP_SUBLINK_SPEED_ST,
+					       USB_ST_SYMMETRIC_TX) |
+				    FIELD_PREP(USB_SSP_SUBLINK_SPEED_LP, USB_LP_SSP) |
+				    FIELD_PREP(USB_SSP_SUBLINK_SPEED_LSM, 10));
 	}
 
 	return le16_to_cpu(bos->wTotalLength);
-- 
2.11.0


  parent reply	other threads:[~2020-07-16 21:58 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-16 21:58 [PATCH 00/11] usb: Handle different sublink speeds Thinh Nguyen
2020-07-16 21:58 ` [PATCH 01/11] usb: ch9: Add sublink speed struct Thinh Nguyen
2020-07-17  6:34   ` Greg Kroah-Hartman
2020-07-17  7:06     ` Thinh Nguyen
2020-07-17  7:33       ` Greg Kroah-Hartman
2020-07-17  7:47         ` Thinh Nguyen
2020-07-17  8:15           ` Greg Kroah-Hartman
2020-07-17  8:29             ` Thinh Nguyen
2020-07-17  8:39   ` kernel test robot
2020-07-17  8:39     ` kernel test robot
2020-07-17  8:46   ` Sergei Shtylyov
2020-07-17 22:42     ` Thinh Nguyen
2020-07-18 12:53   ` kernel test robot
2020-07-18 12:53     ` kernel test robot
2020-07-16 21:58 ` Thinh Nguyen [this message]
2020-07-16 21:58 ` [PATCH 03/11] usb: gadget: Expose sublink speed attributes Thinh Nguyen
2020-07-16 21:58 ` [PATCH 04/11] usb: gadget: Set max speed for SSP devices Thinh Nguyen
2020-07-16 21:59 ` [PATCH 05/11] usb: composite: Properly report sublink speed Thinh Nguyen
2020-07-16 21:59 ` [PATCH 06/11] usb: devicetree: dwc3: Introduce num-lanes and lsm Thinh Nguyen
2020-07-21  3:39   ` Rob Herring
2020-07-21  5:01     ` Thinh Nguyen
2020-07-21 15:04       ` Rob Herring
2020-07-21 16:41         ` Thinh Nguyen
2020-07-22 11:06           ` Felipe Balbi
2020-07-22 14:45           ` Rob Herring
2020-07-22 15:14             ` Thinh Nguyen
2020-07-22 17:30               ` Thinh Nguyen
2020-07-23  2:11                 ` Thinh Nguyen
2020-07-16 21:59 ` [PATCH 07/11] usb: dwc3: Initialize lane count and sublink speed Thinh Nguyen
2020-07-16 21:59 ` [PATCH 08/11] usb: dwc3: gadget: Report sublink speed capability Thinh Nguyen
2020-07-16 21:59 ` [PATCH 09/11] usb: dwc3: gadget: Implement setting of sublink speed Thinh Nguyen
2020-07-16 21:59 ` [PATCH 10/11] usb: dwc3: gadget: Track connected lane and " Thinh Nguyen
2020-07-16 21:59 ` [PATCH 11/11] usb: dwc3: gadget: Set speed only up to the max supported Thinh Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b94bbb8362043b43fec8642ee7f0c28418cf99d1.1594935978.git.thinhn@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=John.Youn@synopsys.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.