Revert "Merge commit 'main-jb-2012.08.03-B4' into t114-0806"
[linux-2.6.git] / arch / arm / mach-tegra / usb_phy.c
1 /*
2  * arch/arm/mach-tegra/usb_phy.c
3  *
4  * Copyright (C) 2010 Google, Inc.
5  * Copyright (c) 2010-2012, NVIDIA CORPORATION.  All rights reserved.
6  *
7  * Author:
8  *      Erik Gilling <konkers@google.com>
9  *      Benoit Goby <benoit@android.com>
10  *
11  * This software is licensed under the terms of the GNU General Public
12  * License version 2, as published by the Free Software Foundation, and
13  * may be copied, distributed, and modified under those terms.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  */
21 #include <linux/resource.h>
22 #include <linux/delay.h>
23 #include <linux/interrupt.h>
24 #include <linux/slab.h>
25 #include <linux/err.h>
26 #include <linux/export.h>
27 #include <linux/platform_device.h>
28 #include <linux/io.h>
29 #include <linux/gpio.h>
30 #include <linux/interrupt.h>
31 #include <linux/clk.h>
32 #include <linux/regulator/consumer.h>
33 #include <linux/platform_data/tegra_usb.h>
34
35 #include <mach/iomap.h>
36 #include <mach/gpio-tegra.h>
37 #include <mach/hardware.h>
38
39 #include "tegra_usb_phy.h"
40 #include "fuse.h"
41
42 #define ERR(stuff...)           pr_err("usb_phy: " stuff)
43 #define WARNING(stuff...)       pr_warning("usb_phy: " stuff)
44 #define INFO(stuff...)          pr_info("usb_phy: " stuff)
45
46 #define AHB_MEM_PREFETCH_CFG3           0xe0
47 #define AHB_MEM_PREFETCH_CFG4           0xe4
48 #define AHB_MEM_PREFETCH_CFG1           0xec
49 #define AHB_MEM_PREFETCH_CFG2           0xf0
50 #define PREFETCH_ENB                    (1 << 31)
51
52 #ifdef DEBUG
53 #define DBG(stuff...)           pr_info("usb_phy: " stuff)
54 #else
55 #define DBG(stuff...)           do {} while (0)
56 #endif
57
58 static void print_usb_plat_data_info(struct tegra_usb_phy *phy)
59 {
60         struct tegra_usb_platform_data *pdata = phy->pdata;
61         char op_mode[][50] = {
62                 "TEGRA_USB_OPMODE_DEVICE",
63                 "TEGRA_USB_OPMODE_HOST"
64         };
65         char phy_intf[][50] = {
66                 "USB_PHY_INTF_UTMI",
67                 "USB_PHY_INTF_ULPI_LINK",
68                 "USB_PHY_INTF_ULPI_NULL",
69                 "USB_PHY_INTF_HSIC",
70                 "USB_PHY_INTF_ICUSB"
71         };
72
73         pr_info("tegra USB phy - inst[%d] platform info:\n", phy->inst);
74         pr_info("port_otg: %s\n", pdata->port_otg ? "yes" : "no");
75         pr_info("has_hostpc: %s\n", pdata->has_hostpc ? "yes" : "no");
76         pr_info("phy_interface: %s\n", phy_intf[pdata->phy_intf]);
77         pr_info("op_mode: %s\n", op_mode[pdata->op_mode]);
78         if (pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
79                 pr_info("vbus_pmu_irq: %d\n", pdata->u_data.dev.vbus_pmu_irq);
80                 pr_info("vbus_gpio: %d\n", pdata->u_data.dev.vbus_gpio);
81                 pr_info("charging: %s\n", pdata->u_data.dev.charging_supported ?
82                                 "enabled" : "disabled");
83                 pr_info("remote_wakeup: %s\n", pdata->u_data.dev.remote_wakeup_supported
84                                 ? "enabled" : "disabled");
85         } else {
86                 pr_info("vbus_gpio: %d\n", pdata->u_data.host.vbus_gpio);
87                 pr_info("vbus_reg: %s\n", pdata->u_data.host.vbus_reg ?
88                                 pdata->u_data.host.vbus_reg : "NULL");
89                 pr_info("hot_plug: %s\n", pdata->u_data.host.hot_plug ?
90                                 "enabled" : "disabled");
91                 pr_info("remote_wakeup: %s\n", pdata->u_data.host.remote_wakeup_supported
92                                 ? "enabled" : "disabled");
93         }
94 }
95
96 static void usb_host_vbus_enable(struct tegra_usb_phy *phy, bool enable)
97 {
98         if (phy->vbus_reg) {
99                 if (enable)
100                         regulator_enable(phy->vbus_reg);
101                 else
102                         regulator_disable(phy->vbus_reg);
103         } else {
104                 int gpio = phy->pdata->u_data.host.vbus_gpio;
105                 if (gpio == -1)
106                         return;
107                 gpio_set_value_cansleep(gpio, enable ? 1 : 0);
108         }
109 }
110
111 int usb_phy_reg_status_wait(void __iomem *reg, u32 mask,
112                                         u32 result, u32 timeout)
113 {
114         do {
115                 if ((readl(reg) & mask) == result)
116                         return 0;
117                 udelay(1);
118                 timeout--;
119         } while (timeout);
120
121         return -1;
122 }
123
124 static int tegra_usb_phy_init_ops(struct tegra_usb_phy *phy)
125 {
126         int err = 0;
127
128         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
129
130         if (phy->pdata->has_hostpc)
131 #if defined(CONFIG_ARCH_TEGRA_11x_SOC)
132                 err = tegra11x_usb_phy_init_ops(phy);
133 #else
134                 err = tegra3_usb_phy_init_ops(phy);
135 #endif
136         else
137                 err = tegra2_usb_phy_init_ops(phy);
138
139         return err;
140 }
141
142 static irqreturn_t usb_phy_dev_vbus_pmu_irq_thr(int irq, void *pdata)
143 {
144         struct tegra_usb_phy *phy = pdata;
145
146         if (phy->vdd_reg && !phy->vdd_reg_on) {
147                 regulator_enable(phy->vdd_reg);
148                 phy->vdd_reg_on = 1;
149                 /*
150                  * Optimal time to get the regulator turned on
151                  * before detecting vbus interrupt.
152                  */
153                 mdelay(15);
154         }
155
156         /* clk is disabled during phy power off and not here*/
157         if (!phy->ctrl_clk_on) {
158                 clk_enable(phy->ctrlr_clk);
159                 phy->ctrl_clk_on = true;
160         }
161
162         return IRQ_HANDLED;
163 }
164
165 static void tegra_usb_phy_release_clocks(struct tegra_usb_phy *phy)
166 {
167         clk_put(phy->emc_clk);
168         clk_put(phy->sys_clk);
169         if (phy->pdata->op_mode == TEGRA_USB_OPMODE_HOST)
170                 if (phy->pdata->u_data.host.hot_plug ||
171                         phy->pdata->u_data.host.remote_wakeup_supported)
172                         clk_disable(phy->ctrlr_clk);
173         clk_put(phy->ctrlr_clk);
174         clk_disable(phy->pllu_clk);
175         clk_put(phy->pllu_clk);
176 }
177
178 static int tegra_usb_phy_get_clocks(struct tegra_usb_phy *phy)
179 {
180         int err = 0;
181
182         phy->pllu_clk = clk_get_sys(NULL, "pll_u");
183         if (IS_ERR(phy->pllu_clk)) {
184                 ERR("inst:[%d] Can't get pllu_clk clock\n", phy->inst);
185                 return PTR_ERR(phy->pllu_clk);
186         }
187         clk_enable(phy->pllu_clk);
188
189         phy->ctrlr_clk = clk_get(&phy->pdev->dev, NULL);
190         if (IS_ERR(phy->ctrlr_clk)) {
191                 dev_err(&phy->pdev->dev, "Can't get controller clock\n");
192                 err = PTR_ERR(phy->ctrlr_clk);
193                 goto fail_ctrlr_clk;
194         }
195
196         if (phy->pdata->op_mode == TEGRA_USB_OPMODE_HOST)
197                 if (phy->pdata->u_data.host.hot_plug ||
198                         phy->pdata->u_data.host.remote_wakeup_supported)
199                         clk_enable(phy->ctrlr_clk);
200
201         phy->sys_clk = clk_get(&phy->pdev->dev, "sclk");
202         if (IS_ERR(phy->sys_clk)) {
203                 dev_err(&phy->pdev->dev, "Can't get sclk clock\n");
204                 err = PTR_ERR(phy->sys_clk);
205                 goto fail_sclk;
206         }
207         clk_set_rate(phy->sys_clk, 80000000);
208
209         phy->emc_clk = clk_get(&phy->pdev->dev, "emc");
210         if (IS_ERR(phy->emc_clk)) {
211                 dev_err(&phy->pdev->dev, "Can't get emc clock\n");
212                 err = PTR_ERR(phy->emc_clk);
213                 goto fail_emc;
214         }
215
216         if(phy->pdata->has_hostpc)
217                 clk_set_rate(phy->emc_clk, 100000000);
218         else
219                 clk_set_rate(phy->emc_clk, 300000000);
220
221         return err;
222
223 fail_emc:
224         clk_put(phy->sys_clk);
225
226 fail_sclk:
227         clk_put(phy->ctrlr_clk);
228
229 fail_ctrlr_clk:
230         clk_disable(phy->pllu_clk);
231         clk_put(phy->pllu_clk);
232
233         return err;
234 }
235
236 struct tegra_usb_phy *tegra_usb_phy_open(struct platform_device *pdev)
237 {
238         struct tegra_usb_phy *phy;
239         struct tegra_usb_platform_data *pdata;
240         struct resource *res;
241         int err;
242         int plat_data_size = sizeof(struct tegra_usb_platform_data);
243
244         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, pdev->id);
245         pdata = dev_get_platdata(&pdev->dev);
246         if (!pdata) {
247                 dev_err(&pdev->dev, "inst:[%d] Platform data missing\n",
248                                                                 pdev->id);
249                 return ERR_PTR(-EINVAL);
250         }
251
252         phy = devm_kzalloc(&pdev->dev, sizeof(struct tegra_usb_phy), GFP_KERNEL);
253         if (!phy) {
254                 ERR("inst:[%d] malloc usb phy failed\n", pdev->id);
255                 return ERR_PTR(-ENOMEM);
256         }
257
258         phy->pdata = devm_kzalloc(&pdev->dev, plat_data_size, GFP_KERNEL);
259         if (!phy->pdata) {
260                 ERR("inst:[%d] malloc usb phy pdata failed\n", pdev->id);
261                 kfree(phy);
262                 return ERR_PTR(-ENOMEM);
263         }
264
265         memcpy(phy->pdata, pdata, plat_data_size);
266
267         phy->pdev = pdev;
268         phy->inst = pdev->id;
269
270         print_usb_plat_data_info(phy);
271
272         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
273         if (!res) {
274                 ERR("inst:[%d] failed to get I/O memory\n", phy->inst);
275                 return ERR_PTR(-ENXIO);
276         }
277
278         phy->regs = ioremap(res->start, resource_size(res));
279         if (!phy->regs) {
280                 ERR("inst:[%d] Failed to remap I/O memory\n", phy->inst);
281                 return ERR_PTR(-ENOMEM);
282         }
283
284         phy->vdd_reg = regulator_get(NULL, "avdd_usb");
285         if (IS_ERR_OR_NULL(phy->vdd_reg)) {
286                 ERR("inst:[%d] couldn't get regulator avdd_usb: %ld\n",
287                         phy->inst, PTR_ERR(phy->vdd_reg));
288                 phy->vdd_reg = NULL;
289         }
290
291         err = tegra_usb_phy_get_clocks(phy);
292         if (err) {
293                 ERR("inst:[%d] Failed to init clocks\n", phy->inst);
294                 goto fail_clk;
295         }
296
297         if (phy->pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
298                 if (phy->pdata->u_data.dev.vbus_pmu_irq) {
299                         err = request_threaded_irq(
300                                         phy->pdata->u_data.dev.vbus_pmu_irq,
301                                         NULL, usb_phy_dev_vbus_pmu_irq_thr,
302                                         IRQF_SHARED, "usb_pmu_vbus_irq", phy);
303                         if (err) {
304                                 ERR("inst:[%d] Failed to register IRQ\n",
305                                                                 phy->inst);
306                                 goto fail_init;
307                         }
308                 } else {
309                         clk_enable(phy->ctrlr_clk);
310                 }
311         } else {
312                 if (phy->pdata->u_data.host.vbus_reg) {
313                         phy->vbus_reg = regulator_get(NULL,
314                                         phy->pdata->u_data.host.vbus_reg);
315                         if (WARN_ON(IS_ERR_OR_NULL(phy->vbus_reg))) {
316                                 ERR("failed to get regulator vdd_vbus_usb: %ld,\
317                                  instance : %d\n", PTR_ERR(phy->vbus_reg),
318                                                                 phy->inst);
319                                 err = PTR_ERR(phy->vbus_reg);
320                                 goto fail_init;
321                         }
322                 } else {
323                         int gpio = phy->pdata->u_data.host.vbus_gpio;
324                         if (gpio != -1) {
325                                 if (gpio_request(gpio, "usb_host_vbus") < 0) {
326                                         ERR("inst:[%d] host vbus gpio \
327                                                  req failed\n", phy->inst);
328                                         goto fail_init;
329                                 }
330                                 if (gpio < TEGRA_NR_GPIOS)
331                                         tegra_gpio_enable(gpio);
332                                 if (gpio_direction_output(gpio, 1) < 0) {
333                                         ERR("inst:[%d] host vbus gpio \
334                                                  dir failed\n", phy->inst);
335                                         goto fail_init;
336                                 }
337                         }
338                 }
339                 usb_host_vbus_enable(phy, true);
340         }
341
342         err = tegra_usb_phy_init_ops(phy);
343         if (err) {
344                 ERR("inst:[%d] Failed to init ops\n", phy->inst);
345                 goto fail_init;
346         }
347
348         if (phy->pdata->ops && phy->pdata->ops->open)
349                 phy->pdata->ops->open();
350
351         if (phy->ops && phy->ops->open) {
352                 err = phy->ops->open(phy);
353                 if (err) {
354                         ERR("inst:[%d] Failed to open hw ops\n", phy->inst);
355                         goto fail_init;
356                 }
357         }
358
359         return phy;
360
361 fail_init:
362         tegra_usb_phy_release_clocks(phy);
363
364         if (phy->pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
365                 if (phy->pdata->u_data.dev.vbus_pmu_irq)
366                         free_irq(phy->pdata->u_data.dev.vbus_pmu_irq, phy);
367         } else {
368                 usb_host_vbus_enable(phy, false);
369
370                 if (phy->vbus_reg)
371                         regulator_put(phy->vbus_reg);
372                 else {
373                         int gpio = phy->pdata->u_data.host.vbus_gpio;
374                         if (gpio != -1) {
375                                 gpio_set_value_cansleep(gpio, 0);
376                                 gpio_free(gpio);
377                         }
378                 }
379         }
380
381 fail_clk:
382         regulator_put(phy->vdd_reg);
383         iounmap(phy->regs);
384         return ERR_PTR(err);
385 }
386 EXPORT_SYMBOL_GPL(tegra_usb_phy_open);
387
388 void tegra_usb_phy_close(struct tegra_usb_phy *phy)
389 {
390         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
391
392         if (phy->ops && phy->ops->close)
393                 phy->ops->close(phy);
394
395         if (phy->pdata->ops && phy->pdata->ops->close)
396                 phy->pdata->ops->close();
397
398         if (phy->pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
399                 if (phy->pdata->u_data.dev.vbus_pmu_irq)
400                         free_irq(phy->pdata->u_data.dev.vbus_pmu_irq, phy);
401                 else
402                         clk_disable(phy->ctrlr_clk);
403         } else {
404                 usb_host_vbus_enable(phy, false);
405
406                 if (phy->vbus_reg)
407                         regulator_put(phy->vbus_reg);
408                 else {
409                         int gpio = phy->pdata->u_data.host.vbus_gpio;
410                         if (gpio != -1) {
411                                 gpio_set_value_cansleep(gpio, 0);
412                                 gpio_free(gpio);
413                         }
414                 }
415         }
416
417         if (phy->vdd_reg) {
418                 if (phy->vdd_reg_on)
419                         regulator_disable(phy->vdd_reg);
420                 regulator_put(phy->vdd_reg);
421         }
422
423
424         tegra_usb_phy_release_clocks(phy);
425 }
426 EXPORT_SYMBOL_GPL(tegra_usb_phy_close);
427
428 irqreturn_t tegra_usb_phy_irq(struct tegra_usb_phy *phy)
429 {
430         irqreturn_t status = IRQ_HANDLED;
431
432         if (phy->ops && phy->ops->irq)
433                 status = phy->ops->irq(phy);
434
435         return status;
436 }
437 EXPORT_SYMBOL_GPL(tegra_usb_phy_irq);
438
439 int tegra_usb_phy_init(struct tegra_usb_phy *phy)
440 {
441         int status = 0;
442
443         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
444
445         if (phy->pdata->ops && phy->pdata->ops->init)
446                 phy->pdata->ops->init();
447
448         if (phy->ops && phy->ops->init)
449                 status = phy->ops->init(phy);
450
451         return status;
452 }
453 EXPORT_SYMBOL_GPL(tegra_usb_phy_init);
454
455 int tegra_usb_phy_power_off(struct tegra_usb_phy *phy)
456 {
457         int err = 0;
458
459         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
460
461         if (!phy->phy_power_on)
462                 return err;
463
464         if (phy->ops && phy->ops->power_off) {
465                 if (phy->pdata->ops && phy->pdata->ops->pre_phy_off)
466                         phy->pdata->ops->pre_phy_off();
467                 err = phy->ops->power_off(phy);
468                 if (phy->pdata->ops && phy->pdata->ops->post_phy_off)
469                         phy->pdata->ops->post_phy_off();
470         }
471
472         clk_disable(phy->emc_clk);
473         clk_disable(phy->sys_clk);
474         if (phy->pdata->op_mode == TEGRA_USB_OPMODE_HOST) {
475                 if (!phy->pdata->u_data.host.hot_plug &&
476                         !phy->pdata->u_data.host.remote_wakeup_supported)
477                         clk_disable(phy->ctrlr_clk);
478         } else {
479                 /* In device mode clock is turned on by pmu irq handler
480                  * if pmu irq is not available clocks will not be turned off/on
481                  */
482                 if (phy->pdata->u_data.dev.vbus_pmu_irq) {
483                         clk_disable(phy->ctrlr_clk);
484                         phy->ctrl_clk_on = false;
485                 }
486         }
487
488 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
489         if (phy->vdd_reg && phy->vdd_reg_on)
490                 if (phy->pdata->has_hostpc || phy->pdata->builtin_host_disabled) {
491                         regulator_disable(phy->vdd_reg);
492                         phy->vdd_reg_on = false;
493         }
494 #endif
495
496         phy->phy_power_on = false;
497
498         return err;
499 }
500 EXPORT_SYMBOL_GPL(tegra_usb_phy_power_off);
501
502 int tegra_usb_phy_power_on(struct tegra_usb_phy *phy)
503 {
504         int status = 0;
505
506         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
507
508         if (phy->phy_power_on)
509                 return status;
510
511 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
512         if (phy->vdd_reg && !phy->vdd_reg_on) {
513                 regulator_enable(phy->vdd_reg);
514                 phy->vdd_reg_on = true;
515         }
516 #endif
517
518         /* In device mode clock is turned on by pmu irq handler
519          * if pmu irq is not available clocks will not be turned off/on
520          */
521         if (phy->pdata->op_mode == TEGRA_USB_OPMODE_HOST) {
522                 if (!phy->pdata->u_data.host.hot_plug &&
523                         !phy->pdata->u_data.host.remote_wakeup_supported)
524                         clk_enable(phy->ctrlr_clk);
525         } else {
526                 if (phy->pdata->u_data.dev.vbus_pmu_irq &&
527                         !phy->ctrl_clk_on) {
528                         clk_enable(phy->ctrlr_clk);
529                         phy->ctrl_clk_on = true;
530                 }
531         }
532         clk_enable(phy->sys_clk);
533         clk_enable(phy->emc_clk);
534
535         if (phy->ops && phy->ops->power_on) {
536                 if (phy->pdata->ops && phy->pdata->ops->pre_phy_on)
537                         phy->pdata->ops->pre_phy_on();
538                 status = phy->ops->power_on(phy);
539                 if (phy->pdata->ops && phy->pdata->ops->post_phy_on)
540                         phy->pdata->ops->post_phy_on();
541         }
542
543         phy->phy_power_on = true;
544
545         return status;
546 }
547 EXPORT_SYMBOL_GPL(tegra_usb_phy_power_on);
548
549 int tegra_usb_phy_reset(struct tegra_usb_phy *phy)
550 {
551         int status = 0;
552
553         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
554         if (phy->ops && phy->ops->reset)
555                 status = phy->ops->reset(phy);
556
557         return status;
558 }
559 EXPORT_SYMBOL_GPL(tegra_usb_phy_reset);
560
561 int tegra_usb_phy_pre_suspend(struct tegra_usb_phy *phy)
562 {
563         int status = 0;
564
565         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
566
567         if (phy->pdata->ops && phy->pdata->ops->pre_suspend)
568                 phy->pdata->ops->pre_suspend();
569
570         if (phy->ops && phy->ops->pre_suspend)
571                 status = phy->ops->pre_suspend(phy);
572
573         return status;
574 }
575
576 int tegra_usb_phy_suspend(struct tegra_usb_phy *phy)
577 {
578         int err = 0;
579
580         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
581
582         if (phy->ops && phy->ops->suspend)
583                 err = phy->ops->suspend(phy);
584
585         if (!err && phy->pdata->u_data.host.power_off_on_suspend) {
586                 tegra_usb_phy_power_off(phy);
587         }
588
589         return err;
590 }
591 EXPORT_SYMBOL_GPL(tegra_usb_phy_suspend);
592
593 int tegra_usb_phy_post_suspend(struct tegra_usb_phy *phy)
594 {
595         int status = 0;
596
597         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
598
599         if (phy->ops && phy->ops->post_suspend)
600                 status = phy->ops->post_suspend(phy);
601
602         if (phy->pdata->ops && phy->pdata->ops->post_suspend)
603                 phy->pdata->ops->post_suspend();
604
605         return status;
606 }
607 EXPORT_SYMBOL_GPL(tegra_usb_phy_post_suspend);
608
609 int tegra_usb_phy_pre_resume(struct tegra_usb_phy *phy, bool remote_wakeup)
610 {
611         int status = 0;
612
613         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
614
615         if (phy->pdata->ops && phy->pdata->ops->pre_resume)
616                 phy->pdata->ops->pre_resume();
617
618         if (phy->ops && phy->ops->pre_resume)
619                 status = phy->ops->pre_resume(phy, remote_wakeup);
620
621         return status;
622 }
623 EXPORT_SYMBOL_GPL(tegra_usb_phy_pre_resume);
624
625 int tegra_usb_phy_resume(struct tegra_usb_phy *phy)
626 {
627         int err = 0;
628
629         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
630
631         if (phy->pdata->u_data.host.power_off_on_suspend) {
632                 tegra_usb_phy_power_on(phy);
633         }
634
635         if (!err && phy->ops && phy->ops->resume)
636                 err = phy->ops->resume(phy);
637
638         return err;
639
640 }
641 EXPORT_SYMBOL_GPL(tegra_usb_phy_resume);
642
643 int tegra_usb_phy_post_resume(struct tegra_usb_phy *phy)
644 {
645         int status = 0;
646
647         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
648
649         if (phy->ops && phy->ops->post_resume)
650                 status = phy->ops->post_resume(phy);
651
652         if (phy->pdata->ops && phy->pdata->ops->post_resume)
653                 phy->pdata->ops->post_resume();
654
655         return status;
656 }
657 EXPORT_SYMBOL_GPL(tegra_usb_phy_post_resume);
658
659 int tegra_usb_phy_port_power(struct tegra_usb_phy *phy)
660 {
661         int status = 0;
662
663         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
664
665         if (phy->ops && phy->ops->port_power)
666                 status = phy->ops->port_power(phy);
667
668         return status;
669 }
670 EXPORT_SYMBOL_GPL(tegra_usb_phy_port_power);
671
672 int tegra_usb_phy_bus_reset(struct tegra_usb_phy *phy)
673 {
674         int status = 0;
675
676         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
677
678         if (phy->ops && phy->ops->bus_reset)
679                 status = phy->ops->bus_reset(phy);
680
681         return status;
682 }
683 EXPORT_SYMBOL_GPL(tegra_usb_phy_bus_reset);
684
685 bool tegra_usb_phy_charger_detected(struct tegra_usb_phy *phy)
686 {
687         bool status = 0;
688
689         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
690         if (phy->ops && phy->ops->charger_detect)
691                 status = phy->ops->charger_detect(phy);
692
693         return status;
694 }
695
696 bool tegra_usb_phy_hw_accessible(struct tegra_usb_phy *phy)
697 {
698         if (!phy->hw_accessible)
699                 DBG("%s(%d) inst:[%d] Not Accessible\n", __func__,
700                                                 __LINE__, phy->inst);
701
702         return phy->hw_accessible;
703 }
704 EXPORT_SYMBOL_GPL(tegra_usb_phy_hw_accessible);
705
706 bool tegra_usb_phy_remote_wakeup(struct tegra_usb_phy *phy)
707 {
708         return phy->remote_wakeup;
709 }
710 EXPORT_SYMBOL_GPL(tegra_usb_phy_remote_wakeup);
711
712 bool tegra_usb_phy_has_hostpc(struct tegra_usb_phy *phy)
713 {
714         return phy->pdata->has_hostpc;
715 }
716 EXPORT_SYMBOL_GPL(tegra_usb_phy_has_hostpc);
717
718 bool tegra_usb_phy_otg_supported(struct tegra_usb_phy *phy)
719 {
720         return phy->pdata->port_otg;
721 }
722 EXPORT_SYMBOL_GPL(tegra_usb_phy_otg_supported);
723
724 void tegra_usb_phy_memory_prefetch_on(struct tegra_usb_phy *phy)
725 {
726         void __iomem *ahb_gizmo = IO_ADDRESS(TEGRA_AHB_GIZMO_BASE);
727         unsigned long val;
728
729         if (phy->inst == 0 && phy->pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
730                 val = readl(ahb_gizmo + AHB_MEM_PREFETCH_CFG1);
731                 val |= PREFETCH_ENB;
732                 writel(val, ahb_gizmo + AHB_MEM_PREFETCH_CFG1);
733                 val = readl(ahb_gizmo + AHB_MEM_PREFETCH_CFG2);
734                 val |= PREFETCH_ENB;
735                 writel(val, ahb_gizmo + AHB_MEM_PREFETCH_CFG2);
736         }
737 }
738
739 void tegra_usb_phy_memory_prefetch_off(struct tegra_usb_phy *phy)
740 {
741         void __iomem *ahb_gizmo = IO_ADDRESS(TEGRA_AHB_GIZMO_BASE);
742         unsigned long val;
743
744         if (phy->inst == 0 && phy->pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
745                 val = readl(ahb_gizmo + AHB_MEM_PREFETCH_CFG1);
746                 val &= ~(PREFETCH_ENB);
747                 writel(val, ahb_gizmo + AHB_MEM_PREFETCH_CFG1);
748                 val = readl(ahb_gizmo + AHB_MEM_PREFETCH_CFG2);
749                 val &= ~(PREFETCH_ENB);
750                 writel(val, ahb_gizmo + AHB_MEM_PREFETCH_CFG2);
751         }
752 }
753