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