]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/usb/gadget/fsl_mxc_udc.c
usb: gadget: fsl-mxc-udc: replace cpu_is_xxx() with platform_device_id
[karo-tx-linux.git] / drivers / usb / gadget / fsl_mxc_udc.c
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 #include <linux/io.h>
20
21 static struct clk *mxc_ahb_clk;
22 static struct clk *mxc_per_clk;
23 static struct clk *mxc_ipg_clk;
24
25 /* workaround ENGcm09152 for i.MX35 */
26 #define USBPHYCTRL_OTGBASE_OFFSET       0x608
27 #define USBPHYCTRL_EVDO                 (1 << 23)
28
29 int fsl_udc_clk_init(struct platform_device *pdev)
30 {
31         struct fsl_usb2_platform_data *pdata;
32         unsigned long freq;
33         int ret;
34
35         pdata = pdev->dev.platform_data;
36
37         mxc_ipg_clk = devm_clk_get(&pdev->dev, "ipg");
38         if (IS_ERR(mxc_ipg_clk)) {
39                 dev_err(&pdev->dev, "clk_get(\"ipg\") failed\n");
40                 return PTR_ERR(mxc_ipg_clk);
41         }
42
43         mxc_ahb_clk = devm_clk_get(&pdev->dev, "ahb");
44         if (IS_ERR(mxc_ahb_clk)) {
45                 dev_err(&pdev->dev, "clk_get(\"ahb\") failed\n");
46                 return PTR_ERR(mxc_ahb_clk);
47         }
48
49         mxc_per_clk = devm_clk_get(&pdev->dev, "per");
50         if (IS_ERR(mxc_per_clk)) {
51                 dev_err(&pdev->dev, "clk_get(\"per\") failed\n");
52                 return PTR_ERR(mxc_per_clk);
53         }
54
55         clk_prepare_enable(mxc_ipg_clk);
56         clk_prepare_enable(mxc_ahb_clk);
57         clk_prepare_enable(mxc_per_clk);
58
59         /* make sure USB_CLK is running at 60 MHz +/- 1000 Hz */
60         if (!strcmp(pdev->id_entry->name, "imx-udc-mx27")) {
61                 freq = clk_get_rate(mxc_per_clk);
62                 if (pdata->phy_mode != FSL_USB2_PHY_ULPI &&
63                     (freq < 59999000 || freq > 60001000)) {
64                         dev_err(&pdev->dev, "USB_CLK=%lu, should be 60MHz\n", freq);
65                         ret = -EINVAL;
66                         goto eclkrate;
67                 }
68         }
69
70         return 0;
71
72 eclkrate:
73         clk_disable_unprepare(mxc_ipg_clk);
74         clk_disable_unprepare(mxc_ahb_clk);
75         clk_disable_unprepare(mxc_per_clk);
76         mxc_per_clk = NULL;
77         return ret;
78 }
79
80 void fsl_udc_clk_finalize(struct platform_device *pdev)
81 {
82         struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
83         unsigned int v;
84
85         /* workaround ENGcm09152 for i.MX35 */
86         if (pdata->workaround & FLS_USB2_WORKAROUND_ENGCM09152) {
87                 v = readl(MX35_IO_ADDRESS(MX35_USB_BASE_ADDR +
88                                 USBPHYCTRL_OTGBASE_OFFSET));
89                 writel(v | USBPHYCTRL_EVDO,
90                         MX35_IO_ADDRESS(MX35_USB_BASE_ADDR +
91                                 USBPHYCTRL_OTGBASE_OFFSET));
92         }
93
94         /* ULPI transceivers don't need usbpll */
95         if (pdata->phy_mode == FSL_USB2_PHY_ULPI) {
96                 clk_disable_unprepare(mxc_per_clk);
97                 mxc_per_clk = NULL;
98         }
99 }
100
101 void fsl_udc_clk_release(void)
102 {
103         if (mxc_per_clk)
104                 clk_disable_unprepare(mxc_per_clk);
105         clk_disable_unprepare(mxc_ahb_clk);
106         clk_disable_unprepare(mxc_ipg_clk);
107 }