Re: [RFC PATCH V2 2/2] USB: Set usb port's DevicerRemovable according acpi information in EHCI

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2012/9/5 0:15, Alan Stern wrote:
On Mon, 3 Sep 2012, Lan Tianyu wrote:

ACPI provide "_PLD" and "_UPC" aml methods to describe usb port
visibility and connectability. This patch is to use those information
to set usb port's DeviceRemovable.

Signed-off-by: Lan Tianyu <tianyu.lan@xxxxxxxxx>
---
v2: Set DeviceRemovable according acpi infomation in the hub_configure()
instead of calling get_hub_descriptor().

@@ -1566,6 +1566,25 @@ static int hub_configure(struct usb_hub *hub,
  			dev_err(hub->intfdev,
  				"couldn't create port%d device.\n", i + 1);

+	if (hub_is_superspeed(hdev)) {
+		for (i = 1; i <= hdev->maxchild; i++)
+			if (hub->ports[i - 1]->connect_type
+					== USB_PORT_CONNECT_TYPE_HARD_WIRED)
+				hub->descriptor->u.hs.DeviceRemovable[i/8]
+					|= 1 << (i%8);
+	} else  {
+		u16 port_removable = 0;
+
+		for (i = i; i <= hdev->maxchild; i++)
+			if (hub->ports[i - 1]->connect_type
+					== USB_PORT_CONNECT_TYPE_HARD_WIRED)
+				port_removable |= 1 << i;
+
+		memset(&hub->descriptor->u.ss.DeviceRemovable,
+			(__force __u16) cpu_to_le16(port_removable),
+			sizeof(__u16));

Use put_unaligned_le16() instead of memset, if you're worried about
alignment.
This is copied from xhci_usb3_hub_descriptor().

struct usb_hub_descriptor {
	__u8  bDescLength;
	__u8  bDescriptorType;
	__u8  bNbrPorts;
	__le16 wHubCharacteristics;
	__u8  bPwrOn2PwrGood;
	__u8  bHubContrCurrent;

	/* 2.0 and 3.0 hubs differ here */
	union {
		struct {
			/* add 1 bit for hub status change; round to bytes */
			__u8  DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
			__u8  PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
		}  __attribute__ ((packed)) hs;

		struct {
			__u8 bHubHdrDecLat;
			__u16 wHubDelay;
			__u16 DeviceRemovable;
		}  __attribute__ ((packed)) ss;
	} u;
} __attribute__ ((packed));

The struct has been defined with __attribute__ ((packed)). So there is
no alignment problem. Or we can
	hub->descriptor->u.ss.DeviceRemovable = (__force __u16)
			cpu_to_le16(port_removable);
I think we also should define wHubDelay and DeviceRemovable as __le16
for ss since they are little-endian order, right?



This isn't right, because you overwrite information provided by the hub
with what ACPI says, even if ACPI doesn't say anything.  You should
initialize port_removable to the original value of
u.ss.DeviceRemovable, not to 0.
OK. I get it.


Alan Stern



--
Best Regards
Tianyu Lan
linux kernel enabling team
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux