Skip to content

Commit

Permalink
usb: mtu3: add support for usb3.1 IP
Browse files Browse the repository at this point in the history
Support SuperSpeedPlus for usb3.1 device IP

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
  • Loading branch information
Chunfeng Yun authored and Felipe Balbi committed Oct 19, 2017
1 parent c776f2c commit 4d79e04
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions drivers/usb/mtu3/mtu3.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ enum mtu3_speed {
MTU3_SPEED_FULL = 1,
MTU3_SPEED_HIGH = 3,
MTU3_SPEED_SUPER = 4,
MTU3_SPEED_SUPER_PLUS = 5,
};

/**
Expand Down
14 changes: 11 additions & 3 deletions drivers/usb/mtu3/mtu3_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void mtu3_ep_stall_set(struct mtu3_ep *mep, bool set)

void mtu3_dev_on_off(struct mtu3 *mtu, int is_on)
{
if (mtu->is_u3_ip && (mtu->max_speed == USB_SPEED_SUPER))
if (mtu->is_u3_ip && mtu->max_speed >= USB_SPEED_SUPER)
mtu3_ss_func_set(mtu, is_on);
else
mtu3_hs_softconn_set(mtu, is_on);
Expand Down Expand Up @@ -547,6 +547,9 @@ static void mtu3_set_speed(struct mtu3 *mtu)
mtu3_clrbits(mbase, U3D_USB3_CONFIG, USB3_EN);
/* HS/FS detected by HW */
mtu3_setbits(mbase, U3D_POWER_MANAGEMENT, HS_ENABLE);
} else if (mtu->max_speed == USB_SPEED_SUPER) {
mtu3_clrbits(mtu->ippc_base, SSUSB_U3_CTRL(0),
SSUSB_U3_PORT_SSP_SPEED);
}

dev_info(mtu->dev, "max_speed: %s\n",
Expand Down Expand Up @@ -624,6 +627,10 @@ static irqreturn_t mtu3_link_isr(struct mtu3 *mtu)
udev_speed = USB_SPEED_SUPER;
maxpkt = 512;
break;
case MTU3_SPEED_SUPER_PLUS:
udev_speed = USB_SPEED_SUPER_PLUS;
maxpkt = 512;
break;
default:
udev_speed = USB_SPEED_UNKNOWN;
break;
Expand Down Expand Up @@ -825,14 +832,15 @@ int ssusb_gadget_init(struct ssusb_mtk *ssusb)
case USB_SPEED_FULL:
case USB_SPEED_HIGH:
case USB_SPEED_SUPER:
case USB_SPEED_SUPER_PLUS:
break;
default:
dev_err(dev, "invalid max_speed: %s\n",
usb_speed_string(mtu->max_speed));
/* fall through */
case USB_SPEED_UNKNOWN:
/* default as SS */
mtu->max_speed = USB_SPEED_SUPER;
/* default as SSP */
mtu->max_speed = USB_SPEED_SUPER_PLUS;
break;
}

Expand Down
3 changes: 2 additions & 1 deletion drivers/usb/mtu3/mtu3_gadget.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ static int mtu3_ep_enable(struct mtu3_ep *mep)

switch (mtu->g.speed) {
case USB_SPEED_SUPER:
case USB_SPEED_SUPER_PLUS:
if (usb_endpoint_xfer_int(desc) ||
usb_endpoint_xfer_isoc(desc)) {
interval = desc->bInterval;
Expand Down Expand Up @@ -456,7 +457,7 @@ static int mtu3_gadget_wakeup(struct usb_gadget *gadget)
return -EOPNOTSUPP;

spin_lock_irqsave(&mtu->lock, flags);
if (mtu->g.speed == USB_SPEED_SUPER) {
if (mtu->g.speed >= USB_SPEED_SUPER) {
mtu3_setbits(mtu->mac_base, U3D_LINK_POWER_CONTROL, UX_EXIT);
} else {
mtu3_setbits(mtu->mac_base, U3D_POWER_MANAGEMENT, RESUME);
Expand Down
16 changes: 8 additions & 8 deletions drivers/usb/mtu3/mtu3_gadget_ep0.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ ep0_get_status(struct mtu3 *mtu, const struct usb_ctrlrequest *setup)
case USB_RECIP_DEVICE:
result[0] = mtu->is_self_powered << USB_DEVICE_SELF_POWERED;
result[0] |= mtu->may_wakeup << USB_DEVICE_REMOTE_WAKEUP;
/* superspeed only */
if (mtu->g.speed == USB_SPEED_SUPER) {

if (mtu->g.speed >= USB_SPEED_SUPER) {
result[0] |= mtu->u1_enable << USB_DEV_STAT_U1_ENABLED;
result[0] |= mtu->u2_enable << USB_DEV_STAT_U2_ENABLED;
}
Expand Down Expand Up @@ -329,8 +329,8 @@ static int ep0_handle_feature_dev(struct mtu3 *mtu,
handled = handle_test_mode(mtu, setup);
break;
case USB_DEVICE_U1_ENABLE:
if (mtu->g.speed != USB_SPEED_SUPER ||
mtu->g.state != USB_STATE_CONFIGURED)
if (mtu->g.speed < USB_SPEED_SUPER ||
mtu->g.state != USB_STATE_CONFIGURED)
break;

lpc = mtu3_readl(mbase, U3D_LINK_POWER_CONTROL);
Expand All @@ -344,8 +344,8 @@ static int ep0_handle_feature_dev(struct mtu3 *mtu,
handled = 1;
break;
case USB_DEVICE_U2_ENABLE:
if (mtu->g.speed != USB_SPEED_SUPER ||
mtu->g.state != USB_STATE_CONFIGURED)
if (mtu->g.speed < USB_SPEED_SUPER ||
mtu->g.state != USB_STATE_CONFIGURED)
break;

lpc = mtu3_readl(mbase, U3D_LINK_POWER_CONTROL);
Expand Down Expand Up @@ -384,8 +384,8 @@ static int ep0_handle_feature(struct mtu3 *mtu,
break;
case USB_RECIP_INTERFACE:
/* superspeed only */
if ((value == USB_INTRF_FUNC_SUSPEND)
&& (mtu->g.speed == USB_SPEED_SUPER)) {
if (value == USB_INTRF_FUNC_SUSPEND &&
mtu->g.speed >= USB_SPEED_SUPER) {
/*
* forward the request because function drivers
* should handle it
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/mtu3/mtu3_hw_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@
#define SSUSB_VBUS_CHG_INT_B_EN BIT(6)

/* U3D_SSUSB_U3_CTRL_0P */
#define SSUSB_U3_PORT_SSP_SPEED BIT(9)
#define SSUSB_U3_PORT_HOST_SEL BIT(2)
#define SSUSB_U3_PORT_PDN BIT(1)
#define SSUSB_U3_PORT_DIS BIT(0)
Expand Down

0 comments on commit 4d79e04

Please sign in to comment.