ODROID-COMMON: drivers/usb: code featuring for internal USB or external

This patch is to handle a SoC builtin or or an external USB controller by
the function 'odroid_amlogic_usb3()' where returns true for SoC builtin USB
controller and false for another one.

Change-Id: I13055dc87378175205ddb019c97d57db9d2e3d98
Signed-off-by: Dongjin Kim <tobetter@gmail.com>
This commit is contained in:
Dongjin Kim
2019-08-20 13:02:58 +09:00
committed by Chris KIM
parent 8a5ce0de85
commit 89bedbd9b3
10 changed files with 85 additions and 42 deletions

View File

@@ -80,6 +80,13 @@ u32 odroid_model(void)
{
return __odroid_model;
}
static bool __odroid_amlogic_usb3 = true;
bool odroid_amlogic_usb3(void)
{
return __odroid_amlogic_usb3;
}
#endif
/*
@@ -221,9 +228,11 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
if (!strcmp(machine_name, "Hardkernel ODROID-N2")) {
system_rev = 0x0400;
__odroid_model = BOARD_ODROIDN2;
__odroid_amlogic_usb3 = true;
} else if (!strcmp(machine_name, "Hardkernel ODROID-C4")) {
system_rev = 0x0500;
__odroid_model = BOARD_ODROIDC4;
__odroid_amlogic_usb3 = false;
}
#endif
}

View File

@@ -1317,13 +1317,15 @@ int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,
}
#ifdef CONFIG_AMLOGIC_USB
if (!(HCD_DWC_OTG(hcd))) {
if (tmp != &urb->urb_list)
return -EIDRM;
}
#else
if (HCD_DWC_OTG(hcd))
goto err_usb_hcd_check_unlink_urb;
#endif
if (tmp != &urb->urb_list)
return -EIDRM;
#ifdef CONFIG_AMLOGIC_USB
err_usb_hcd_check_unlink_urb:
#endif
/* Any status except -EINPROGRESS means something already started to

View File

@@ -2175,7 +2175,7 @@ free_interfaces:
usb_enable_ltm(dev);
#ifdef CONFIG_AMLOGIC_USB
if (usb_host_test_vid > 0) {
if (odroid_amlogic_usb3() && (usb_host_test_vid > 0)) {
if (dev->descriptor.idVendor == USB_HSET_TEST_VID) {
usb_host_test_vid = dev->descriptor.idVendor;
usb_host_test_pid = dev->descriptor.idProduct;

View File

@@ -9,6 +9,10 @@
#include "u_f.h"
#include "u_os_desc.h"
#ifdef CONFIG_AMLOGIC_USB
#include <linux/usb.h>
#endif
#ifdef CONFIG_USB_CONFIGFS_UEVENT
#include <linux/platform_device.h>
#include <linux/kdev_t.h>
@@ -1298,7 +1302,8 @@ static int configfs_composite_bind(struct usb_gadget *gadget,
cdev->gadget = gadget;
set_gadget_data(gadget, cdev);
#ifdef CONFIG_AMLOGIC_USB
wakeup_source_init(&Gadget_Lock.wakesrc, "gadget-connect");
if (odroid_amlogic_usb3())
wakeup_source_init(&Gadget_Lock.wakesrc, "gadget-connect");
#endif
ret = composite_dev_prepare(composite, cdev);
if (ret)
@@ -1465,7 +1470,8 @@ static void android_work(struct work_struct *data)
pr_info("%s: sent uevent %s\n", __func__, configured[0]);
uevent_sent = true;
#ifdef CONFIG_AMLOGIC_USB
gadget_hold(&Gadget_Lock);
if (odroid_amlogic_usb3())
gadget_hold(&Gadget_Lock);
#endif
}
@@ -1475,7 +1481,8 @@ static void android_work(struct work_struct *data)
pr_info("%s: sent uevent %s\n", __func__, disconnected[0]);
uevent_sent = true;
#ifdef CONFIG_AMLOGIC_USB
gadget_drop(&Gadget_Lock);
if (odroid_amlogic_usb3())
gadget_drop(&Gadget_Lock);
#endif
}
@@ -1502,7 +1509,8 @@ static void configfs_composite_unbind(struct usb_gadget *gadget)
composite_dev_cleanup(cdev);
usb_ep_autoconfig_reset(cdev->gadget);
#ifdef CONFIG_AMLOGIC_USB
wakeup_source_trash(&Gadget_Lock.wakesrc);
if (odroid_amlogic_usb3())
wakeup_source_trash(&Gadget_Lock.wakesrc);
#endif
cdev->gadget = NULL;
set_gadget_data(gadget, NULL);

View File

@@ -281,14 +281,21 @@ static void xhci_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci,
struct usb_hub_descriptor *desc)
{
#ifdef CONFIG_AMLOGIC_USB
if (xhci->quirks & XHCI_AML_SUPER_SPEED_SUPPORT) {
if (odroid_amlogic_usb3()) {
if (xhci->quirks & XHCI_AML_SUPER_SPEED_SUPPORT) {
if (hcd->speed >= HCD_USB3)
xhci_usb3_hub_descriptor(hcd, xhci, desc);
else
xhci_usb2_hub_descriptor(hcd, xhci, desc);
} else {
if (hcd->speed < HCD_USB3)
xhci_usb2_hub_descriptor(hcd, xhci, desc);
}
} else {
if (hcd->speed >= HCD_USB3)
xhci_usb3_hub_descriptor(hcd, xhci, desc);
else
xhci_usb2_hub_descriptor(hcd, xhci, desc);
} else {
if (hcd->speed < HCD_USB3)
xhci_usb2_hub_descriptor(hcd, xhci, desc);
}
#else
if (hcd->speed >= HCD_USB3)
@@ -552,12 +559,14 @@ static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue,
xhci_dbg(xhci, "clear port %s change, actual port %d status = 0x%x\n",
port_change_bit, wIndex, port_status);
#ifdef CONFIG_AMLOGIC_USB
if (DEV_HIGHSPEED(port_status) &&
(wValue == USB_PORT_FEAT_C_RESET))
set_usb_phy_host_tuning(wIndex, 0);
if (DEV_LOWSPEED(port_status) &&
(wValue == USB_PORT_FEAT_C_RESET))
set_usb_phy_host_low_reset(wIndex);
if (odroid_amlogic_usb3()) {
if (DEV_HIGHSPEED(port_status) &&
(wValue == USB_PORT_FEAT_C_RESET))
set_usb_phy_host_tuning(wIndex, 0);
if (DEV_LOWSPEED(port_status) &&
(wValue == USB_PORT_FEAT_C_RESET))
set_usb_phy_host_low_reset(wIndex);
}
#endif
}
@@ -1234,8 +1243,10 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
if (wValue == USB_PORT_FEAT_REMOTE_WAKE_MASK)
wake_mask = wIndex & 0xff00;
#ifdef CONFIG_AMLOGIC_USB
if (wValue == USB_PORT_FEAT_TEST)
test_mode = (wIndex & 0xff00) >> 8;
if (odroid_amlogic_usb3()) {
if (wValue == USB_PORT_FEAT_TEST)
test_mode = (wIndex & 0xff00) >> 8;
}
#endif
/* The MSB of wIndex is the U1/U2 timeout */
timeout = (wIndex & 0xff00) >> 8;

View File

@@ -2218,10 +2218,11 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
if ((xhci->hci_version >= 0x100) && (major_revision != 0x03)) {
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
"xHCI 1.0: support USB2 software lpm");
#ifdef CONFIG_AMLOGIC_USB
xhci->sw_lpm_support = 0;
#else
xhci->sw_lpm_support = 1;
#ifdef CONFIG_AMLOGIC_USB
if (odroid_amlogic_usb3())
xhci->sw_lpm_support = 0;
#endif
if (temp & XHCI_HLC) {
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
@@ -2254,17 +2255,17 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
continue;
}
xhci->port_array[i] = major_revision;
if (major_revision == 0x03)
#ifdef CONFIG_AMLOGIC_USB
if (xhci->quirks & XHCI_AML_SUPER_SPEED_SUPPORT)
xhci->num_usb3_ports++;
else
xhci->num_usb3_ports = 0;
#else
if (major_revision == 0x03) {
xhci->num_usb3_ports++;
#ifdef CONFIG_AMLOGIC_USB
if (odroid_amlogic_usb3()) {
if (!(xhci->quirks & XHCI_AML_SUPER_SPEED_SUPPORT))
xhci->num_usb3_ports = 0;
}
#endif
else
} else {
xhci->num_usb2_ports++;
}
}
/* FIXME: Should we disable ports not in the Extended Capabilities? */
}

View File

@@ -1710,8 +1710,10 @@ cleanup:
set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
spin_unlock(&xhci->lock);
#ifdef CONFIG_AMLOGIC_USB
if (!(temp & PORT_CONNECT) || !(temp & PORT_PE))
set_usb_phy_host_tuning(faked_port_index, 1);
if (odroid_amlogic_usb3()) {
if (!(temp & PORT_CONNECT) || !(temp & PORT_PE))
set_usb_phy_host_tuning(faked_port_index, 1);
}
#endif
/* Pass this up to the core */
usb_hcd_poll_rh_status(hcd);

View File

@@ -1411,9 +1411,11 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
if (xhci->xhc_state & XHCI_STATE_DYING)
goto dying;
#ifdef CONFIG_AMLOGIC_USB
#ifdef CONFIG_AMLOGIC_USB // FIXME:
setup = (struct usb_ctrlrequest *) urb->setup_packet;
if ((setup->bRequestType == 0x80) && (setup->bRequest == 0x06)
if (odroid_amlogic_usb3()
&& (setup->bRequestType == 0x80)
&& (setup->bRequest == 0x06)
&& (setup->wValue == 0x0100)
&& (setup->wIndex != 0x0)) {
if ((((setup->wIndex)>>8) & 0xff) == 7) {
@@ -3646,7 +3648,8 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
}
#ifdef CONFIG_AMLOGIC_USB
virt_dev->udev = NULL;
if (odroid_amlogic_usb3())
virt_dev->udev = NULL;
#endif
spin_lock_irqsave(&xhci->lock, flags);
@@ -4867,9 +4870,11 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
hcd->self.sg_tablesize = ~0;
#if defined(CONFIG_ARCH_MESON64_ODROID_COMMON)
if (kpara_sg_tablesize > 0)
hcd->self.sg_tablesize = kpara_sg_tablesize;
pr_info("usb: xhci: determined sg_tablesize: %u", hcd->self.sg_tablesize);
if (odroid_amlogic_usb3()) {
if (kpara_sg_tablesize > 0)
hcd->self.sg_tablesize = kpara_sg_tablesize;
pr_info("usb: xhci: determined sg_tablesize: %u", hcd->self.sg_tablesize);
}
#endif
/* support to build packet from discontinuous buffers */

View File

@@ -6,10 +6,11 @@
#define BOARD_ODROIDN2 0x09221000
#define BOARD_ODROIDC4 0x09051000
extern bool odroid_amlogic_usb(void);
extern u32 odroid_model(void);
#define board_is_odroidn2() (odroid_model() == BOARD_ODROIDN2)
#define board_is_odroidc4() (odroid_model() == BOARD_ODROIDC4)
extern bool odroid_amlogic_usb3(void);
#endif

View File

@@ -4,6 +4,10 @@
#include <linux/mod_devicetable.h>
#include <linux/usb/ch9.h>
#if defined(CONFIG_ARCH_MESON64_ODROID_COMMON)
#include <linux/platform_data/board_odroid.h>
#endif
#define USB_MAJOR 180
#define USB_DEVICE_MAJOR 189