temp revert rk change
[firefly-linux-kernel-4.4.55.git] / drivers / usb / gadget / fsl_tegra_udc.c
1 /*
2  * Description:
3  * Helper functions to support the tegra USB controller
4  *
5  * This program is free software; you can redistribute  it and/or modify it
6  * under  the terms of  the GNU General  Public License as published by the
7  * Free Software Foundation;  either version 2 of the  License, or (at your
8  * option) any later version.
9  */
10 #include <linux/fsl_devices.h>
11 #include <linux/platform_device.h>
12 #include <linux/err.h>
13 #include <linux/io.h>
14 #include <mach/usb_phy.h>
15
16 static struct tegra_usb_phy *phy;
17 static struct clk *udc_clk;
18 static struct clk *emc_clk;
19 static void *udc_base;
20
21 int fsl_udc_clk_init(struct platform_device *pdev)
22 {
23         struct resource *res;
24         int err;
25         int instance;
26         struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
27
28
29         udc_clk = clk_get(&pdev->dev, NULL);
30         if (IS_ERR(udc_clk)) {
31                 dev_err(&pdev->dev, "Can't get udc clock\n");
32                 return PTR_ERR(udc_clk);
33         }
34
35         clk_enable(udc_clk);
36
37         emc_clk = clk_get(&pdev->dev, "emc");
38         if (IS_ERR(emc_clk)) {
39                 dev_err(&pdev->dev, "Can't get emc clock\n");
40                 err = PTR_ERR(emc_clk);
41                 goto err_emc;
42         }
43
44         clk_enable(emc_clk);
45         clk_set_rate(emc_clk, 300000000);
46
47         /* we have to remap the registers ourselves as fsl_udc does not
48          * export them for us.
49          */
50         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
51         if (!res) {
52                 err = -ENXIO;
53                 goto err0;
54         }
55         udc_base = ioremap(res->start, resource_size(res));
56         if (!udc_base) {
57                 err = -ENOMEM;
58                 goto err0;
59         }
60
61         instance = pdev->id;
62         if (instance == -1)
63                 instance = 0;
64
65         phy = tegra_usb_phy_open(instance, udc_base, pdata->phy_config,
66                                                 TEGRA_USB_PHY_MODE_DEVICE);
67         if (IS_ERR(phy)) {
68                 dev_err(&pdev->dev, "Can't open phy\n");
69                 err = PTR_ERR(phy);
70                 goto err1;
71         }
72
73         tegra_usb_phy_power_on(phy);
74
75         return 0;
76 err1:
77         iounmap(udc_base);
78 err0:
79         clk_disable(emc_clk);
80         clk_put(emc_clk);
81 err_emc:
82         clk_disable(udc_clk);
83         clk_put(udc_clk);
84         return err;
85 }
86
87 void fsl_udc_clk_finalize(struct platform_device *pdev)
88 {
89 }
90
91 void fsl_udc_clk_release(void)
92 {
93         tegra_usb_phy_close(phy);
94
95         iounmap(udc_base);
96
97         clk_disable(udc_clk);
98         clk_put(udc_clk);
99
100         clk_disable(emc_clk);
101         clk_put(emc_clk);
102 }
103
104 void fsl_udc_clk_suspend(void)
105 {
106         tegra_usb_phy_power_off(phy);
107         clk_disable(udc_clk);
108         clk_disable(emc_clk);
109 }
110
111 void fsl_udc_clk_resume(void)
112 {
113         clk_enable(emc_clk);
114         clk_enable(udc_clk);
115         tegra_usb_phy_power_on(phy);
116 }