diff options
author | Dinh Nguyen <Dinh.Nguyen@freescale.com> | 2010-05-10 12:21:57 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-05-20 16:21:44 -0400 |
commit | 73a0bd77d60163d8b4639834119a1ed65155c062 (patch) | |
tree | 3551eb7a3fa53292d4ead92c3da15c12965ee528 /drivers/usb/gadget/fsl_mxc_udc.c | |
parent | 166ceb69075066cba196434482370f1e0318bc3e (diff) |
USB: mxc: gadget: remove 60mhz clock requirement for freescale mx51 usb core
renamed fsl_mx3_udc.c -> fsl_mxc_udc.c
for mx51, usb core is clocked from sources that are not 60mhz.
Signed-off-by: Dinh Nguyen <Dinh.Nguyen@freescale.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/gadget/fsl_mxc_udc.c')
-rw-r--r-- | drivers/usb/gadget/fsl_mxc_udc.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/drivers/usb/gadget/fsl_mxc_udc.c b/drivers/usb/gadget/fsl_mxc_udc.c new file mode 100644 index 000000000000..d0b8bde59e59 --- /dev/null +++ b/drivers/usb/gadget/fsl_mxc_udc.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2009 | ||
3 | * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de> | ||
4 | * | ||
5 | * Description: | ||
6 | * Helper routines for i.MX3x SoCs from Freescale, needed by the fsl_usb2_udc.c | ||
7 | * driver to function correctly on these systems. | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify it | ||
10 | * under the terms of the GNU General Public License as published by the | ||
11 | * Free Software Foundation; either version 2 of the License, or (at your | ||
12 | * option) any later version. | ||
13 | */ | ||
14 | #include <linux/clk.h> | ||
15 | #include <linux/delay.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/fsl_devices.h> | ||
18 | #include <linux/platform_device.h> | ||
19 | |||
20 | #include <mach/hardware.h> | ||
21 | |||
22 | static struct clk *mxc_ahb_clk; | ||
23 | static struct clk *mxc_usb_clk; | ||
24 | |||
25 | int fsl_udc_clk_init(struct platform_device *pdev) | ||
26 | { | ||
27 | struct fsl_usb2_platform_data *pdata; | ||
28 | unsigned long freq; | ||
29 | int ret; | ||
30 | |||
31 | pdata = pdev->dev.platform_data; | ||
32 | |||
33 | if (!cpu_is_mx35()) { | ||
34 | mxc_ahb_clk = clk_get(&pdev->dev, "usb_ahb"); | ||
35 | if (IS_ERR(mxc_ahb_clk)) | ||
36 | return PTR_ERR(mxc_ahb_clk); | ||
37 | |||
38 | ret = clk_enable(mxc_ahb_clk); | ||
39 | if (ret < 0) { | ||
40 | dev_err(&pdev->dev, "clk_enable(\"usb_ahb\") failed\n"); | ||
41 | goto eenahb; | ||
42 | } | ||
43 | } | ||
44 | |||
45 | /* make sure USB_CLK is running at 60 MHz +/- 1000 Hz */ | ||
46 | mxc_usb_clk = clk_get(&pdev->dev, "usb"); | ||
47 | if (IS_ERR(mxc_usb_clk)) { | ||
48 | dev_err(&pdev->dev, "clk_get(\"usb\") failed\n"); | ||
49 | ret = PTR_ERR(mxc_usb_clk); | ||
50 | goto egusb; | ||
51 | } | ||
52 | |||
53 | if (!cpu_is_mx51()) { | ||
54 | freq = clk_get_rate(mxc_usb_clk); | ||
55 | if (pdata->phy_mode != FSL_USB2_PHY_ULPI && | ||
56 | (freq < 59999000 || freq > 60001000)) { | ||
57 | dev_err(&pdev->dev, "USB_CLK=%lu, should be 60MHz\n", freq); | ||
58 | ret = -EINVAL; | ||
59 | goto eclkrate; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | ret = clk_enable(mxc_usb_clk); | ||
64 | if (ret < 0) { | ||
65 | dev_err(&pdev->dev, "clk_enable(\"usb_clk\") failed\n"); | ||
66 | goto eenusb; | ||
67 | } | ||
68 | |||
69 | return 0; | ||
70 | |||
71 | eenusb: | ||
72 | eclkrate: | ||
73 | clk_put(mxc_usb_clk); | ||
74 | mxc_usb_clk = NULL; | ||
75 | egusb: | ||
76 | if (!cpu_is_mx35()) | ||
77 | clk_disable(mxc_ahb_clk); | ||
78 | eenahb: | ||
79 | if (!cpu_is_mx35()) | ||
80 | clk_put(mxc_ahb_clk); | ||
81 | return ret; | ||
82 | } | ||
83 | |||
84 | void fsl_udc_clk_finalize(struct platform_device *pdev) | ||
85 | { | ||
86 | struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; | ||
87 | |||
88 | /* ULPI transceivers don't need usbpll */ | ||
89 | if (pdata->phy_mode == FSL_USB2_PHY_ULPI) { | ||
90 | clk_disable(mxc_usb_clk); | ||
91 | clk_put(mxc_usb_clk); | ||
92 | mxc_usb_clk = NULL; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | void fsl_udc_clk_release(void) | ||
97 | { | ||
98 | if (mxc_usb_clk) { | ||
99 | clk_disable(mxc_usb_clk); | ||
100 | clk_put(mxc_usb_clk); | ||
101 | } | ||
102 | if (!cpu_is_mx35()) { | ||
103 | clk_disable(mxc_ahb_clk); | ||
104 | clk_put(mxc_ahb_clk); | ||
105 | } | ||
106 | } | ||