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 = true;
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                 err = PTR_ERR(phy->pllu_clk);
186                 goto fail_pll;
187         }
188         clk_enable(phy->pllu_clk);
189
190         phy->ctrlr_clk = clk_get(&phy->pdev->dev, NULL);
191         if (IS_ERR(phy->ctrlr_clk)) {
192                 dev_err(&phy->pdev->dev, "Can't get controller clock\n");
193                 err = PTR_ERR(phy->ctrlr_clk);
194                 goto fail_ctrlr_clk;
195         }
196
197         if (phy->pdata->op_mode == TEGRA_USB_OPMODE_HOST)
198                 if (phy->pdata->u_data.host.hot_plug ||
199                         phy->pdata->u_data.host.remote_wakeup_supported)
200                         clk_enable(phy->ctrlr_clk);
201
202         phy->sys_clk = clk_get(&phy->pdev->dev, "sclk");
203         if (IS_ERR(phy->sys_clk)) {
204                 dev_err(&phy->pdev->dev, "Can't get sclk clock\n");
205                 err = PTR_ERR(phy->sys_clk);
206                 goto fail_sclk;
207         }
208         clk_set_rate(phy->sys_clk, 80000000);
209
210         phy->emc_clk = clk_get(&phy->pdev->dev, "emc");
211         if (IS_ERR(phy->emc_clk)) {
212                 dev_err(&phy->pdev->dev, "Can't get emc clock\n");
213                 err = PTR_ERR(phy->emc_clk);
214                 goto fail_emc;
215         }
216
217         if(phy->pdata->has_hostpc)
218                 clk_set_rate(phy->emc_clk, 100000000);
219         else
220                 clk_set_rate(phy->emc_clk, 300000000);
221
222         return err;
223
224 fail_emc:
225         clk_put(phy->sys_clk);
226
227 fail_sclk:
228         clk_put(phy->ctrlr_clk);
229
230 fail_ctrlr_clk:
231         clk_disable(phy->pllu_clk);
232         clk_put(phy->pllu_clk);
233
234 fail_pll:
235         return err;
236 }
237
238 struct tegra_usb_phy *tegra_usb_phy_open(struct platform_device *pdev)
239 {
240         struct tegra_usb_phy *phy;
241         struct tegra_usb_platform_data *pdata;
242         struct resource *res;
243         int err;
244         int plat_data_size = sizeof(struct tegra_usb_platform_data);
245
246         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, pdev->id);
247         pdata = dev_get_platdata(&pdev->dev);
248         if (!pdata) {
249                 dev_err(&pdev->dev, "inst:[%d] Platform data missing\n",
250                                                                 pdev->id);
251                 err = -EINVAL;
252                 goto fail_inval;
253         }
254
255         phy = devm_kzalloc(&pdev->dev, sizeof(struct tegra_usb_phy), GFP_KERNEL);
256         if (!phy) {
257                 ERR("inst:[%d] malloc usb phy failed\n", pdev->id);
258                 err = -ENOMEM;
259                 goto fail_nomem;
260         }
261
262         phy->pdata = devm_kzalloc(&pdev->dev, plat_data_size, GFP_KERNEL);
263         if (!phy->pdata) {
264                 ERR("inst:[%d] malloc usb phy pdata failed\n", pdev->id);
265                 devm_kfree(&pdev->dev, phy);
266                 err = -ENOMEM;
267                 goto fail_nomem;
268         }
269
270         memcpy(phy->pdata, pdata, plat_data_size);
271
272         phy->pdev = pdev;
273         phy->inst = pdev->id;
274
275         print_usb_plat_data_info(phy);
276
277         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
278         if (!res) {
279                 ERR("inst:[%d] failed to get I/O memory\n", phy->inst);
280                 err = -ENXIO;
281                 goto fail_io;
282         }
283
284         phy->regs = ioremap(res->start, resource_size(res));
285         if (!phy->regs) {
286                 ERR("inst:[%d] Failed to remap I/O memory\n", phy->inst);
287                 err = -ENOMEM;
288                 goto fail_io;
289         }
290
291         phy->vdd_reg = regulator_get(&pdev->dev, "avdd_usb");
292         if (IS_ERR_OR_NULL(phy->vdd_reg)) {
293                 ERR("inst:[%d] couldn't get regulator avdd_usb: %ld\n",
294                         phy->inst, PTR_ERR(phy->vdd_reg));
295                 phy->vdd_reg = NULL;
296                 err = PTR_ERR(phy->vdd_reg);
297                 goto fail_io;
298         }
299
300         err = tegra_usb_phy_get_clocks(phy);
301         if (err) {
302                 ERR("inst:[%d] Failed to init clocks\n", phy->inst);
303                 goto fail_clk;
304         }
305
306         if (phy->pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
307                 if (phy->pdata->u_data.dev.vbus_pmu_irq) {
308                         err = request_threaded_irq(
309                                         phy->pdata->u_data.dev.vbus_pmu_irq,
310                                         NULL, usb_phy_dev_vbus_pmu_irq_thr,
311                                         IRQF_SHARED, "usb_pmu_vbus_irq", phy);
312                         if (err) {
313                                 ERR("inst:[%d] Failed to register IRQ\n",
314                                                                 phy->inst);
315                                 goto fail_init;
316                         }
317                 } else {
318                         clk_enable(phy->ctrlr_clk);
319                 }
320         } else {
321                 if (phy->pdata->u_data.host.vbus_reg) {
322                         phy->vbus_reg = regulator_get(NULL,
323                                         phy->pdata->u_data.host.vbus_reg);
324                         if (WARN_ON(IS_ERR_OR_NULL(phy->vbus_reg))) {
325                                 ERR("failed to get regulator vdd_vbus_usb: %ld,\
326                                  instance : %d\n", PTR_ERR(phy->vbus_reg),
327                                                                 phy->inst);
328                                 err = PTR_ERR(phy->vbus_reg);
329                                 goto fail_init;
330                         }
331                 } else {
332                         int gpio = phy->pdata->u_data.host.vbus_gpio;
333                         if (gpio != -1) {
334                                 if (gpio_request(gpio, "usb_host_vbus") < 0) {
335                                         ERR("inst:[%d] host vbus gpio \
336                                                  req failed\n", phy->inst);
337                                         goto fail_init;
338                                 }
339                                 if (gpio_direction_output(gpio, 1) < 0) {
340                                         ERR("inst:[%d] host vbus gpio \
341                                                  dir failed\n", phy->inst);
342                                         goto fail_init;
343                                 }
344                         }
345                 }
346                 usb_host_vbus_enable(phy, true);
347         }
348
349         err = tegra_usb_phy_init_ops(phy);
350         if (err) {
351                 ERR("inst:[%d] Failed to init ops\n", phy->inst);
352                 goto fail_init;
353         }
354
355         if (phy->pdata->ops && phy->pdata->ops->open)
356                 phy->pdata->ops->open();
357
358         if (phy->ops && phy->ops->open) {
359                 err = phy->ops->open(phy);
360                 if (err) {
361                         ERR("inst:[%d] Failed to open hw ops\n", phy->inst);
362                         goto fail_init;
363                 }
364         }
365
366         return phy;
367
368 fail_init:
369         tegra_usb_phy_release_clocks(phy);
370
371         if (phy->pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
372                 if (phy->pdata->u_data.dev.vbus_pmu_irq)
373                         free_irq(phy->pdata->u_data.dev.vbus_pmu_irq, phy);
374         } else {
375                 usb_host_vbus_enable(phy, false);
376
377                 if (phy->vbus_reg)
378                         regulator_put(phy->vbus_reg);
379                 else {
380                         int gpio = phy->pdata->u_data.host.vbus_gpio;
381                         if (gpio != -1) {
382                                 gpio_set_value_cansleep(gpio, 0);
383                                 gpio_free(gpio);
384                         }
385                 }
386         }
387
388 fail_clk:
389         regulator_put(phy->vdd_reg);
390         iounmap(phy->regs);
391 fail_io:
392         devm_kfree(&pdev->dev, phy->pdata);
393         devm_kfree(&pdev->dev, phy);
394
395 fail_nomem:
396 fail_inval:
397         return ERR_PTR(err);
398 }
399 EXPORT_SYMBOL_GPL(tegra_usb_phy_open);
400
401 void tegra_usb_phy_close(struct tegra_usb_phy *phy)
402 {
403         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
404
405         if (phy->ops && phy->ops->close)
406                 phy->ops->close(phy);
407
408         if (phy->pdata->ops && phy->pdata->ops->close)
409                 phy->pdata->ops->close();
410
411         if (phy->pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
412                 if (phy->pdata->u_data.dev.vbus_pmu_irq)
413                         free_irq(phy->pdata->u_data.dev.vbus_pmu_irq, phy);
414                 else
415                         clk_disable(phy->ctrlr_clk);
416         } else {
417                 usb_host_vbus_enable(phy, false);
418
419                 if (phy->vbus_reg)
420                         regulator_put(phy->vbus_reg);
421                 else {
422                         int gpio = phy->pdata->u_data.host.vbus_gpio;
423                         if (gpio != -1) {
424                                 gpio_set_value_cansleep(gpio, 0);
425                                 gpio_free(gpio);
426                         }
427                 }
428         }
429
430         if (phy->vdd_reg) {
431                 if (phy->vdd_reg_on)
432                         regulator_disable(phy->vdd_reg);
433                 regulator_put(phy->vdd_reg);
434         }
435
436         tegra_usb_phy_release_clocks(phy);
437
438         devm_kfree(&phy->pdev->dev, phy->pdata);
439         devm_kfree(&phy->pdev->dev, phy);
440 }
441 EXPORT_SYMBOL_GPL(tegra_usb_phy_close);
442
443 irqreturn_t tegra_usb_phy_irq(struct tegra_usb_phy *phy)
444 {
445         irqreturn_t status = IRQ_HANDLED;
446
447         if (phy->ops && phy->ops->irq)
448                 status = phy->ops->irq(phy);
449
450         return status;
451 }
452 EXPORT_SYMBOL_GPL(tegra_usb_phy_irq);
453
454 int tegra_usb_phy_init(struct tegra_usb_phy *phy)
455 {
456         int status = 0;
457
458         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
459
460         if (phy->pdata->ops && phy->pdata->ops->init)
461                 phy->pdata->ops->init();
462
463         if (phy->ops && phy->ops->init)
464                 status = phy->ops->init(phy);
465
466         return status;
467 }
468 EXPORT_SYMBOL_GPL(tegra_usb_phy_init);
469
470 int tegra_usb_phy_power_off(struct tegra_usb_phy *phy)
471 {
472         int err = 0;
473
474         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
475
476         if (!phy->phy_power_on)
477                 return err;
478
479         if (phy->ops && phy->ops->power_off) {
480                 if (phy->pdata->ops && phy->pdata->ops->pre_phy_off)
481                         phy->pdata->ops->pre_phy_off();
482                 err = phy->ops->power_off(phy);
483                 if (phy->pdata->ops && phy->pdata->ops->post_phy_off)
484                         phy->pdata->ops->post_phy_off();
485         }
486
487         clk_disable(phy->emc_clk);
488         clk_disable(phy->sys_clk);
489         if (phy->pdata->op_mode == TEGRA_USB_OPMODE_HOST) {
490                 if (!phy->pdata->u_data.host.hot_plug &&
491                         !phy->pdata->u_data.host.remote_wakeup_supported) {
492                         clk_disable(phy->ctrlr_clk);
493                         phy->ctrl_clk_on = false;
494                         if (phy->vdd_reg && phy->vdd_reg_on) {
495                                 regulator_disable(phy->vdd_reg);
496                                 phy->vdd_reg_on = false;
497                         }
498                 }
499         } else {
500                 /* In device mode clock regulator/clocks will be turned off
501                  * only if pmu interrupt is present on the board and host mode
502                  * support through OTG is supported on the board.
503                  */
504                 if (phy->pdata->u_data.dev.vbus_pmu_irq &&
505                         phy->pdata->builtin_host_disabled) {
506                         clk_disable(phy->ctrlr_clk);
507                         phy->ctrl_clk_on = false;
508                         if (phy->vdd_reg && phy->vdd_reg_on) {
509                                 regulator_disable(phy->vdd_reg);
510                                 phy->vdd_reg_on = false;
511                         }
512                 }
513         }
514
515         phy->phy_power_on = false;
516
517         return err;
518 }
519 EXPORT_SYMBOL_GPL(tegra_usb_phy_power_off);
520
521 int tegra_usb_phy_power_on(struct tegra_usb_phy *phy)
522 {
523         int status = 0;
524
525         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
526
527         if (phy->phy_power_on)
528                 return status;
529
530 #ifndef CONFIG_ARCH_TEGRA_2x_SOC
531         if (phy->vdd_reg && !phy->vdd_reg_on) {
532                 regulator_enable(phy->vdd_reg);
533                 phy->vdd_reg_on = true;
534         }
535 #endif
536
537         /* In device mode clock is turned on by pmu irq handler
538          * if pmu irq is not available clocks will not be turned off/on
539          */
540         if (phy->pdata->op_mode == TEGRA_USB_OPMODE_HOST) {
541                 if (!phy->pdata->u_data.host.hot_plug &&
542                         !phy->pdata->u_data.host.remote_wakeup_supported)
543                         clk_enable(phy->ctrlr_clk);
544         } else {
545                 if (phy->pdata->u_data.dev.vbus_pmu_irq &&
546                         !phy->ctrl_clk_on) {
547                         clk_enable(phy->ctrlr_clk);
548                         phy->ctrl_clk_on = true;
549                 }
550         }
551         clk_enable(phy->sys_clk);
552         clk_enable(phy->emc_clk);
553
554         if (phy->ops && phy->ops->power_on) {
555                 if (phy->pdata->ops && phy->pdata->ops->pre_phy_on)
556                         phy->pdata->ops->pre_phy_on();
557                 status = phy->ops->power_on(phy);
558                 if (phy->pdata->ops && phy->pdata->ops->post_phy_on)
559                         phy->pdata->ops->post_phy_on();
560         }
561
562         phy->phy_power_on = true;
563
564         return status;
565 }
566 EXPORT_SYMBOL_GPL(tegra_usb_phy_power_on);
567
568 int tegra_usb_phy_reset(struct tegra_usb_phy *phy)
569 {
570         int status = 0;
571
572         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
573         if (phy->ops && phy->ops->reset)
574                 status = phy->ops->reset(phy);
575
576         return status;
577 }
578 EXPORT_SYMBOL_GPL(tegra_usb_phy_reset);
579
580 int tegra_usb_phy_pre_suspend(struct tegra_usb_phy *phy)
581 {
582         int status = 0;
583
584         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
585
586         if (phy->pdata->ops && phy->pdata->ops->pre_suspend)
587                 phy->pdata->ops->pre_suspend();
588
589         if (phy->ops && phy->ops->pre_suspend)
590                 status = phy->ops->pre_suspend(phy);
591
592         return status;
593 }
594
595 int tegra_usb_phy_suspend(struct tegra_usb_phy *phy)
596 {
597         int err = 0;
598
599         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
600
601         if (phy->ops && phy->ops->suspend)
602                 err = phy->ops->suspend(phy);
603
604         if (!err && phy->pdata->u_data.host.power_off_on_suspend) {
605                 tegra_usb_phy_power_off(phy);
606         }
607
608         return err;
609 }
610 EXPORT_SYMBOL_GPL(tegra_usb_phy_suspend);
611
612 int tegra_usb_phy_post_suspend(struct tegra_usb_phy *phy)
613 {
614         int status = 0;
615
616         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
617
618         if (phy->ops && phy->ops->post_suspend)
619                 status = phy->ops->post_suspend(phy);
620
621         if (phy->pdata->ops && phy->pdata->ops->post_suspend)
622                 phy->pdata->ops->post_suspend();
623
624         return status;
625 }
626 EXPORT_SYMBOL_GPL(tegra_usb_phy_post_suspend);
627
628 int tegra_usb_phy_pre_resume(struct tegra_usb_phy *phy, bool remote_wakeup)
629 {
630         int status = 0;
631
632         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
633
634         if (phy->pdata->ops && phy->pdata->ops->pre_resume)
635                 phy->pdata->ops->pre_resume();
636
637         if (phy->ops && phy->ops->pre_resume)
638                 status = phy->ops->pre_resume(phy, remote_wakeup);
639
640         return status;
641 }
642 EXPORT_SYMBOL_GPL(tegra_usb_phy_pre_resume);
643
644 int tegra_usb_phy_resume(struct tegra_usb_phy *phy)
645 {
646         int err = 0;
647
648         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
649
650         if (phy->pdata->u_data.host.power_off_on_suspend) {
651                 tegra_usb_phy_power_on(phy);
652         }
653
654         if (!err && phy->ops && phy->ops->resume)
655                 err = phy->ops->resume(phy);
656
657         return err;
658
659 }
660 EXPORT_SYMBOL_GPL(tegra_usb_phy_resume);
661
662 int tegra_usb_phy_post_resume(struct tegra_usb_phy *phy)
663 {
664         int status = 0;
665
666         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
667
668         if (phy->ops && phy->ops->post_resume)
669                 status = phy->ops->post_resume(phy);
670
671         if (phy->pdata->ops && phy->pdata->ops->post_resume)
672                 phy->pdata->ops->post_resume();
673
674         return status;
675 }
676 EXPORT_SYMBOL_GPL(tegra_usb_phy_post_resume);
677
678 int tegra_usb_phy_port_power(struct tegra_usb_phy *phy)
679 {
680         int status = 0;
681
682         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
683
684         if (phy->ops && phy->ops->port_power)
685                 status = phy->ops->port_power(phy);
686
687         return status;
688 }
689 EXPORT_SYMBOL_GPL(tegra_usb_phy_port_power);
690
691 int tegra_usb_phy_bus_reset(struct tegra_usb_phy *phy)
692 {
693         int status = 0;
694
695         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
696
697         if (phy->ops && phy->ops->bus_reset)
698                 status = phy->ops->bus_reset(phy);
699
700         return status;
701 }
702 EXPORT_SYMBOL_GPL(tegra_usb_phy_bus_reset);
703
704 bool tegra_usb_phy_charger_detected(struct tegra_usb_phy *phy)
705 {
706         bool status = 0;
707
708         DBG("%s(%d) inst:[%d]\n", __func__, __LINE__, phy->inst);
709         if (phy->ops && phy->ops->charger_detect)
710                 status = phy->ops->charger_detect(phy);
711
712         return status;
713 }
714
715 bool tegra_usb_phy_hw_accessible(struct tegra_usb_phy *phy)
716 {
717         if (!phy->hw_accessible)
718                 DBG("%s(%d) inst:[%d] Not Accessible\n", __func__,
719                                                 __LINE__, phy->inst);
720
721         return phy->hw_accessible;
722 }
723 EXPORT_SYMBOL_GPL(tegra_usb_phy_hw_accessible);
724
725 bool tegra_usb_phy_remote_wakeup(struct tegra_usb_phy *phy)
726 {
727         return phy->remote_wakeup;
728 }
729 EXPORT_SYMBOL_GPL(tegra_usb_phy_remote_wakeup);
730
731 bool tegra_usb_phy_has_hostpc(struct tegra_usb_phy *phy)
732 {
733         return phy->pdata->has_hostpc;
734 }
735 EXPORT_SYMBOL_GPL(tegra_usb_phy_has_hostpc);
736
737 bool tegra_usb_phy_otg_supported(struct tegra_usb_phy *phy)
738 {
739         return phy->pdata->port_otg;
740 }
741 EXPORT_SYMBOL_GPL(tegra_usb_phy_otg_supported);
742
743 void tegra_usb_phy_memory_prefetch_on(struct tegra_usb_phy *phy)
744 {
745         void __iomem *ahb_gizmo = IO_ADDRESS(TEGRA_AHB_GIZMO_BASE);
746         unsigned long val;
747
748         if (phy->inst == 0 && phy->pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
749                 val = readl(ahb_gizmo + AHB_MEM_PREFETCH_CFG1);
750                 val |= PREFETCH_ENB;
751                 writel(val, ahb_gizmo + AHB_MEM_PREFETCH_CFG1);
752                 val = readl(ahb_gizmo + AHB_MEM_PREFETCH_CFG2);
753                 val |= PREFETCH_ENB;
754                 writel(val, ahb_gizmo + AHB_MEM_PREFETCH_CFG2);
755         }
756 }
757
758 void tegra_usb_phy_memory_prefetch_off(struct tegra_usb_phy *phy)
759 {
760         void __iomem *ahb_gizmo = IO_ADDRESS(TEGRA_AHB_GIZMO_BASE);
761         unsigned long val;
762
763         if (phy->inst == 0 && phy->pdata->op_mode == TEGRA_USB_OPMODE_DEVICE) {
764                 val = readl(ahb_gizmo + AHB_MEM_PREFETCH_CFG1);
765                 val &= ~(PREFETCH_ENB);
766                 writel(val, ahb_gizmo + AHB_MEM_PREFETCH_CFG1);
767                 val = readl(ahb_gizmo + AHB_MEM_PREFETCH_CFG2);
768                 val &= ~(PREFETCH_ENB);
769                 writel(val, ahb_gizmo + AHB_MEM_PREFETCH_CFG2);
770         }
771 }
772