2017-11-03 18:28:30 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2009-04-15 20:25:33 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009
|
|
|
|
* Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de>
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Helper routines for i.MX3x SoCs from Freescale, needed by the fsl_usb2_udc.c
|
|
|
|
* driver to function correctly on these systems.
|
|
|
|
*/
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/fsl_devices.h>
|
2018-06-20 13:47:28 +08:00
|
|
|
#include <linux/mod_devicetable.h>
|
2009-04-15 20:25:33 +08:00
|
|
|
#include <linux/platform_device.h>
|
2011-11-22 23:48:28 +08:00
|
|
|
#include <linux/io.h>
|
2009-04-15 20:25:33 +08:00
|
|
|
|
2014-07-17 01:23:55 +08:00
|
|
|
#include "fsl_usb2_udc.h"
|
|
|
|
|
2009-04-15 20:25:33 +08:00
|
|
|
static struct clk *mxc_ahb_clk;
|
2012-06-16 05:39:02 +08:00
|
|
|
static struct clk *mxc_per_clk;
|
|
|
|
static struct clk *mxc_ipg_clk;
|
2009-04-15 20:25:33 +08:00
|
|
|
|
2010-10-15 20:30:58 +08:00
|
|
|
/* workaround ENGcm09152 for i.MX35 */
|
2013-01-17 18:03:16 +08:00
|
|
|
#define MX35_USBPHYCTRL_OFFSET 0x600
|
|
|
|
#define USBPHYCTRL_OTGBASE_OFFSET 0x8
|
2010-10-15 20:30:58 +08:00
|
|
|
#define USBPHYCTRL_EVDO (1 << 23)
|
|
|
|
|
2009-04-15 20:25:33 +08:00
|
|
|
int fsl_udc_clk_init(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct fsl_usb2_platform_data *pdata;
|
|
|
|
unsigned long freq;
|
|
|
|
int ret;
|
|
|
|
|
2013-07-30 16:00:51 +08:00
|
|
|
pdata = dev_get_platdata(&pdev->dev);
|
2009-04-15 20:25:33 +08:00
|
|
|
|
2012-06-16 05:39:02 +08:00
|
|
|
mxc_ipg_clk = devm_clk_get(&pdev->dev, "ipg");
|
|
|
|
if (IS_ERR(mxc_ipg_clk)) {
|
|
|
|
dev_err(&pdev->dev, "clk_get(\"ipg\") failed\n");
|
|
|
|
return PTR_ERR(mxc_ipg_clk);
|
|
|
|
}
|
2009-04-15 20:25:33 +08:00
|
|
|
|
2012-06-16 05:39:02 +08:00
|
|
|
mxc_ahb_clk = devm_clk_get(&pdev->dev, "ahb");
|
|
|
|
if (IS_ERR(mxc_ahb_clk)) {
|
|
|
|
dev_err(&pdev->dev, "clk_get(\"ahb\") failed\n");
|
|
|
|
return PTR_ERR(mxc_ahb_clk);
|
2009-04-15 20:25:33 +08:00
|
|
|
}
|
|
|
|
|
2012-06-16 05:39:02 +08:00
|
|
|
mxc_per_clk = devm_clk_get(&pdev->dev, "per");
|
|
|
|
if (IS_ERR(mxc_per_clk)) {
|
|
|
|
dev_err(&pdev->dev, "clk_get(\"per\") failed\n");
|
|
|
|
return PTR_ERR(mxc_per_clk);
|
2009-04-15 20:25:33 +08:00
|
|
|
}
|
|
|
|
|
2012-06-16 05:39:02 +08:00
|
|
|
clk_prepare_enable(mxc_ipg_clk);
|
|
|
|
clk_prepare_enable(mxc_ahb_clk);
|
|
|
|
clk_prepare_enable(mxc_per_clk);
|
|
|
|
|
|
|
|
/* make sure USB_CLK is running at 60 MHz +/- 1000 Hz */
|
2013-01-17 18:03:15 +08:00
|
|
|
if (!strcmp(pdev->id_entry->name, "imx-udc-mx27")) {
|
2012-06-16 05:39:02 +08:00
|
|
|
freq = clk_get_rate(mxc_per_clk);
|
2010-05-11 00:21:57 +08:00
|
|
|
if (pdata->phy_mode != FSL_USB2_PHY_ULPI &&
|
|
|
|
(freq < 59999000 || freq > 60001000)) {
|
|
|
|
dev_err(&pdev->dev, "USB_CLK=%lu, should be 60MHz\n", freq);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto eclkrate;
|
|
|
|
}
|
2009-04-15 20:25:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
eclkrate:
|
2012-06-16 05:39:02 +08:00
|
|
|
clk_disable_unprepare(mxc_ipg_clk);
|
|
|
|
clk_disable_unprepare(mxc_ahb_clk);
|
|
|
|
clk_disable_unprepare(mxc_per_clk);
|
|
|
|
mxc_per_clk = NULL;
|
2009-04-15 20:25:33 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-17 18:03:16 +08:00
|
|
|
int fsl_udc_clk_finalize(struct platform_device *pdev)
|
2009-04-15 20:25:33 +08:00
|
|
|
{
|
2013-07-30 16:00:51 +08:00
|
|
|
struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2013-01-17 18:03:16 +08:00
|
|
|
int ret = 0;
|
2013-01-17 18:03:15 +08:00
|
|
|
|
|
|
|
/* workaround ENGcm09152 for i.MX35 */
|
|
|
|
if (pdata->workaround & FLS_USB2_WORKAROUND_ENGCM09152) {
|
2013-01-17 18:03:16 +08:00
|
|
|
unsigned int v;
|
|
|
|
struct resource *res = platform_get_resource
|
|
|
|
(pdev, IORESOURCE_MEM, 0);
|
|
|
|
void __iomem *phy_regs = ioremap(res->start +
|
|
|
|
MX35_USBPHYCTRL_OFFSET, 512);
|
|
|
|
if (!phy_regs) {
|
|
|
|
dev_err(&pdev->dev, "ioremap for phy address fails\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto ioremap_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = readl(phy_regs + USBPHYCTRL_OTGBASE_OFFSET);
|
2013-01-17 18:03:15 +08:00
|
|
|
writel(v | USBPHYCTRL_EVDO,
|
2013-01-17 18:03:16 +08:00
|
|
|
phy_regs + USBPHYCTRL_OTGBASE_OFFSET);
|
|
|
|
|
|
|
|
iounmap(phy_regs);
|
2010-10-15 20:30:58 +08:00
|
|
|
}
|
2009-04-15 20:25:33 +08:00
|
|
|
|
2013-01-17 18:03:16 +08:00
|
|
|
|
|
|
|
ioremap_err:
|
2009-04-15 20:25:33 +08:00
|
|
|
/* ULPI transceivers don't need usbpll */
|
|
|
|
if (pdata->phy_mode == FSL_USB2_PHY_ULPI) {
|
2012-06-16 05:39:02 +08:00
|
|
|
clk_disable_unprepare(mxc_per_clk);
|
|
|
|
mxc_per_clk = NULL;
|
2009-04-15 20:25:33 +08:00
|
|
|
}
|
2013-01-17 18:03:16 +08:00
|
|
|
|
|
|
|
return ret;
|
2009-04-15 20:25:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void fsl_udc_clk_release(void)
|
|
|
|
{
|
2012-06-16 05:39:02 +08:00
|
|
|
if (mxc_per_clk)
|
|
|
|
clk_disable_unprepare(mxc_per_clk);
|
|
|
|
clk_disable_unprepare(mxc_ahb_clk);
|
|
|
|
clk_disable_unprepare(mxc_ipg_clk);
|
2009-04-15 20:25:33 +08:00
|
|
|
}
|