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

Commit 85ff7bfb authored by Neil Zhang's avatar Neil Zhang Committed by Felipe Balbi
Browse files

usb: gadget: mv_udc: refine the clock relative code



Split the clock relative code from clock gating solution.
Then we can remove some duplicate code, make the code more clean.

Signed-off-by: default avatarNeil Zhang <zhangwm@marvell.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 309d6d2b
Loading
Loading
Loading
Loading
+25 −20
Original line number Original line Diff line number Diff line
@@ -1138,11 +1138,11 @@ static int udc_reset(struct mv_udc *udc)
	return 0;
	return 0;
}
}


static int mv_udc_enable(struct mv_udc *udc)
static int mv_udc_enable_internal(struct mv_udc *udc)
{
{
	int retval;
	int retval;


	if (udc->clock_gating == 0 || udc->active)
	if (udc->active)
		return 0;
		return 0;


	dev_dbg(&udc->dev->dev, "enable udc\n");
	dev_dbg(&udc->dev->dev, "enable udc\n");
@@ -1161,9 +1161,17 @@ static int mv_udc_enable(struct mv_udc *udc)
	return 0;
	return 0;
}
}


static void mv_udc_disable(struct mv_udc *udc)
static int mv_udc_enable(struct mv_udc *udc)
{
{
	if (udc->clock_gating && udc->active) {
	if (udc->clock_gating)
		return mv_udc_enable_internal(udc);

	return 0;
}

static void mv_udc_disable_internal(struct mv_udc *udc)
{
	if (udc->active) {
		dev_dbg(&udc->dev->dev, "disable udc\n");
		dev_dbg(&udc->dev->dev, "disable udc\n");
		if (udc->pdata->phy_deinit)
		if (udc->pdata->phy_deinit)
			udc->pdata->phy_deinit(udc->phy_regs);
			udc->pdata->phy_deinit(udc->phy_regs);
@@ -1172,6 +1180,12 @@ static void mv_udc_disable(struct mv_udc *udc)
	}
	}
}
}


static void mv_udc_disable(struct mv_udc *udc)
{
	if (udc->clock_gating)
		mv_udc_disable_internal(udc);
}

static int mv_udc_get_frame(struct usb_gadget *gadget)
static int mv_udc_get_frame(struct usb_gadget *gadget)
{
{
	struct mv_udc *udc;
	struct mv_udc *udc;
@@ -2253,14 +2267,9 @@ static int __devinit mv_udc_probe(struct platform_device *dev)
	}
	}


	/* we will acces controller register, so enable the clk */
	/* we will acces controller register, so enable the clk */
	udc_clock_enable(udc);
	retval = mv_udc_enable_internal(udc);
	if (pdata->phy_init) {
	if (retval)
		retval = pdata->phy_init(udc->phy_regs);
		if (retval) {
			dev_err(&dev->dev, "phy init error %d\n", retval);
		goto err_iounmap_phyreg;
		goto err_iounmap_phyreg;
		}
	}


	udc->op_regs = (struct mv_op_regs __iomem *)((u32)udc->cap_regs
	udc->op_regs = (struct mv_op_regs __iomem *)((u32)udc->cap_regs
		+ (readl(&udc->cap_regs->caplength_hciversion)
		+ (readl(&udc->cap_regs->caplength_hciversion)
@@ -2388,11 +2397,9 @@ static int __devinit mv_udc_probe(struct platform_device *dev)
	 * If not, it means that VBUS detection is not supported, we
	 * If not, it means that VBUS detection is not supported, we
	 * have to enable vbus active all the time to let controller work.
	 * have to enable vbus active all the time to let controller work.
	 */
	 */
	if (udc->clock_gating) {
	if (udc->clock_gating)
		if (udc->pdata->phy_deinit)
		mv_udc_disable_internal(udc);
			udc->pdata->phy_deinit(udc->phy_regs);
	else
		udc_clock_disable(udc);
	} else
		udc->vbus_active = 1;
		udc->vbus_active = 1;


	retval = usb_add_gadget_udc(&dev->dev, &udc->gadget);
	retval = usb_add_gadget_udc(&dev->dev, &udc->gadget);
@@ -2422,9 +2429,7 @@ static int __devinit mv_udc_probe(struct platform_device *dev)
	dma_free_coherent(&dev->dev, udc->ep_dqh_size,
	dma_free_coherent(&dev->dev, udc->ep_dqh_size,
			udc->ep_dqh, udc->ep_dqh_dma);
			udc->ep_dqh, udc->ep_dqh_dma);
err_disable_clock:
err_disable_clock:
	if (udc->pdata->phy_deinit)
	mv_udc_disable_internal(udc);
		udc->pdata->phy_deinit(udc->phy_regs);
	udc_clock_disable(udc);
err_iounmap_phyreg:
err_iounmap_phyreg:
	iounmap((void *)udc->phy_regs);
	iounmap((void *)udc->phy_regs);
err_iounmap_capreg:
err_iounmap_capreg: