Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 39e07ffb authored by Felipe Balbi's avatar Felipe Balbi
Browse files

usb: dwc3: ep0: simplify dwc3_ep0_handle_feature()



By extracting smaller functions from
dwc3_ep0_handle_feature(), it becomes far easier to
understand what's going on. Cleanup only, no
functional changes.

Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent 6d729a55
Loading
Loading
Loading
Loading
+164 −93
Original line number Original line Diff line number Diff line
@@ -371,33 +371,11 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc,
	return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req);
	return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req);
}
}


static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
static int dwc3_ep0_handle_u1(struct dwc3 *dwc, enum usb_device_state state,
		struct usb_ctrlrequest *ctrl, int set)
		int set)
{
{
	struct dwc3_ep		*dep;
	u32			recip;
	u32			wValue;
	u32			wIndex;
	u32 reg;
	u32 reg;
	int			ret;
	enum usb_device_state	state;


	wValue = le16_to_cpu(ctrl->wValue);
	wIndex = le16_to_cpu(ctrl->wIndex);
	recip = ctrl->bRequestType & USB_RECIP_MASK;
	state = dwc->gadget.state;

	switch (recip) {
	case USB_RECIP_DEVICE:

		switch (wValue) {
		case USB_DEVICE_REMOTE_WAKEUP:
			break;
		/*
		 * 9.4.1 says only only for SS, in AddressState only for
		 * default control pipe
		 */
		case USB_DEVICE_U1_ENABLE:
	if (state != USB_STATE_CONFIGURED)
	if (state != USB_STATE_CONFIGURED)
		return -EINVAL;
		return -EINVAL;
	if ((dwc->speed != DWC3_DSTS_SUPERSPEED) &&
	if ((dwc->speed != DWC3_DSTS_SUPERSPEED) &&
@@ -410,9 +388,16 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
	else
	else
		reg &= ~DWC3_DCTL_INITU1ENA;
		reg &= ~DWC3_DCTL_INITU1ENA;
	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
			break;


		case USB_DEVICE_U2_ENABLE:
	return 0;
}

static int dwc3_ep0_handle_u2(struct dwc3 *dwc, enum usb_device_state state,
		int set)
{
	u32 reg;


	if (state != USB_STATE_CONFIGURED)
	if (state != USB_STATE_CONFIGURED)
		return -EINVAL;
		return -EINVAL;
	if ((dwc->speed != DWC3_DSTS_SUPERSPEED) &&
	if ((dwc->speed != DWC3_DSTS_SUPERSPEED) &&
@@ -425,12 +410,13 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
	else
	else
		reg &= ~DWC3_DCTL_INITU2ENA;
		reg &= ~DWC3_DCTL_INITU2ENA;
	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
			break;


		case USB_DEVICE_LTM_ENABLE:
	return 0;
			return -EINVAL;
}


		case USB_DEVICE_TEST_MODE:
static int dwc3_ep0_handle_test(struct dwc3 *dwc, enum usb_device_state state,
		u32 wIndex, int set)
{
	if ((wIndex & 0xff) != 0)
	if ((wIndex & 0xff) != 0)
		return -EINVAL;
		return -EINVAL;
	if (!set)
	if (!set)
@@ -448,13 +434,60 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
	default:
	default:
		return -EINVAL;
		return -EINVAL;
	}
	}

	return 0;
}

static int dwc3_ep0_handle_device(struct dwc3 *dwc,
		struct usb_ctrlrequest *ctrl, int set)
{
	enum usb_device_state	state;
	u32			wValue;
	u32			wIndex;
	int			ret = 0;

	wValue = le16_to_cpu(ctrl->wValue);
	wIndex = le16_to_cpu(ctrl->wIndex);
	state = dwc->gadget.state;

	switch (wValue) {
	case USB_DEVICE_REMOTE_WAKEUP:
		break;
	/*
	 * 9.4.1 says only only for SS, in AddressState only for
	 * default control pipe
	 */
	case USB_DEVICE_U1_ENABLE:
		ret = dwc3_ep0_handle_u1(dwc, state, set);
		break;
	case USB_DEVICE_U2_ENABLE:
		ret = dwc3_ep0_handle_u2(dwc, state, set);
		break;
	case USB_DEVICE_LTM_ENABLE:
		ret = -EINVAL;
		break;
	case USB_DEVICE_TEST_MODE:
		ret = dwc3_ep0_handle_test(dwc, state, wIndex, set);
		break;
		break;
	default:
	default:
			return -EINVAL;
		ret = -EINVAL;
	}
	}
		break;


	case USB_RECIP_INTERFACE:
	return ret;
}

static int dwc3_ep0_handle_intf(struct dwc3 *dwc,
		struct usb_ctrlrequest *ctrl, int set)
{
	enum usb_device_state	state;
	u32			wValue;
	u32			wIndex;
	int			ret = 0;

	wValue = le16_to_cpu(ctrl->wValue);
	wIndex = le16_to_cpu(ctrl->wIndex);
	state = dwc->gadget.state;

	switch (wValue) {
	switch (wValue) {
	case USB_INTRF_FUNC_SUSPEND:
	case USB_INTRF_FUNC_SUSPEND:
		if (wIndex & USB_INTRF_FUNC_SUSPEND_LP)
		if (wIndex & USB_INTRF_FUNC_SUSPEND_LP)
@@ -465,18 +498,34 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
			;
			;
		break;
		break;
	default:
	default:
			return -EINVAL;
		ret = -EINVAL;
	}
	}
		break;


	case USB_RECIP_ENDPOINT:
	return ret;
}

static int dwc3_ep0_handle_endpoint(struct dwc3 *dwc,
		struct usb_ctrlrequest *ctrl, int set)
{
	struct dwc3_ep		*dep;
	enum usb_device_state	state;
	u32			wValue;
	u32			wIndex;
	int			ret;

	wValue = le16_to_cpu(ctrl->wValue);
	wIndex = le16_to_cpu(ctrl->wIndex);
	state = dwc->gadget.state;

	switch (wValue) {
	switch (wValue) {
	case USB_ENDPOINT_HALT:
	case USB_ENDPOINT_HALT:
		dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex);
		dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex);
		if (!dep)
		if (!dep)
			return -EINVAL;
			return -EINVAL;

		if (set == 0 && (dep->flags & DWC3_EP_WEDGE))
		if (set == 0 && (dep->flags & DWC3_EP_WEDGE))
			break;
			break;

		ret = __dwc3_gadget_ep_set_halt(dep, set, true);
		ret = __dwc3_gadget_ep_set_halt(dep, set, true);
		if (ret)
		if (ret)
			return -EINVAL;
			return -EINVAL;
@@ -484,13 +533,35 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
	default:
	default:
		return -EINVAL;
		return -EINVAL;
	}
	}
		break;


	return 0;
}

static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
		struct usb_ctrlrequest *ctrl, int set)
{
	u32			recip;
	int			ret;
	enum usb_device_state	state;

	recip = ctrl->bRequestType & USB_RECIP_MASK;
	state = dwc->gadget.state;

	switch (recip) {
	case USB_RECIP_DEVICE:
		ret = dwc3_ep0_handle_device(dwc, ctrl, set);
		break;
	case USB_RECIP_INTERFACE:
		ret = dwc3_ep0_handle_intf(dwc, ctrl, set);
		break;
	case USB_RECIP_ENDPOINT:
		ret = dwc3_ep0_handle_endpoint(dwc, ctrl, set);
		break;
	default:
	default:
		return -EINVAL;
		ret = -EINVAL;
	}
	}


	return 0;
	return ret;
}
}


static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)