On 11/10/2015 05:36 PM, Dave Young wrote:
[snip]

diff --git a/drivers/usb/host/xhci-sysfs.c b/drivers/usb/host/xhci-sysfs.c
new file mode 100644
index 0000000..0192ac4
--- /dev/null
+++ b/drivers/usb/host/xhci-sysfs.c
@@ -0,0 +1,100 @@
+/*
+ * sysfs interface for xHCI host controller driver
+ *
+ * Copyright (C) 2015 Intel Corp.
+ *
+ * Author: Lu Baolu <baolu...@linux.intel.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/kernel.h>
+
+#include "xhci.h"
+
+/*
+ * Return the register offset of a extended capability specified
+ * by @cap_id. Return 0 if @cap_id capability is not supported or
+ * in error cases.
+ */
+static int get_extended_capability_offset(struct xhci_hcd *xhci,
+                                       int cap_id)
+{
+       u32             cap_reg;
+       unsigned long   flags;
+       int             offset;
+       void __iomem    *base = (void __iomem *) xhci->cap_regs;
+       struct usb_hcd  *hcd = xhci_to_hcd(xhci);
+       int             time_to_leave = XHCI_EXT_MAX_CAPID;
+
+       spin_lock_irqsave(&xhci->lock, flags);
+
+       offset = xhci_find_next_cap_offset(base, XHCI_HCC_PARAMS_OFFSET);
+       if (!HCD_HW_ACCESSIBLE(hcd) || !offset) {
+               spin_unlock_irqrestore(&xhci->lock, flags);
+               return 0;
+       }
+
+       while (time_to_leave--) {
+               cap_reg = readl(base + offset);
+
+               if (XHCI_EXT_CAPS_ID(cap_reg) == cap_id)
+                       break;
+
+               offset = xhci_find_next_cap_offset(base, offset);
+               if (!offset)
+                       break;
+       }
+
+       spin_unlock_irqrestore(&xhci->lock, flags);
I'm not sure spin_lock is good and necessary here, also seems there's already

The lock is unnecessary here. I will remove it.

a function to find the cap offset:
xhci_find_ext_cap_by_id() in xhci-ext-caps.h

Yes, I will refactor the code.

Thanks,
Baolu

+
+       return offset;
+}
+
Thanks
Dave


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to