Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Thomas Abraham | e142e9f | 2009-01-04 09:41:13 +0530 | [diff] [blame] | 2 | /* |
| 3 | * TI's Davinci platform specific USB wrapper functions. |
| 4 | * |
| 5 | * Copyright (c) 2008 Texas Instruments |
| 6 | * |
Thomas Abraham | e142e9f | 2009-01-04 09:41:13 +0530 | [diff] [blame] | 7 | * Author: Thomas Abraham t-abraham@ti.com, Texas Instruments |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <asm/io.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2731b9a | 2009-04-03 12:46:58 +0200 | [diff] [blame] | 12 | #include "davinci.h" |
Prathap Srinivas | 6e20e64 | 2010-01-11 15:36:46 +0530 | [diff] [blame] | 13 | #include <asm/arch/hardware.h> |
Thomas Abraham | e142e9f | 2009-01-04 09:41:13 +0530 | [diff] [blame] | 14 | |
Heiko Schocher | 1fa892c | 2011-11-01 20:00:26 +0000 | [diff] [blame] | 15 | #if !defined(CONFIG_DV_USBPHY_CTL) |
| 16 | #define CONFIG_DV_USBPHY_CTL (USBPHY_SESNDEN | USBPHY_VBDTCTEN) |
| 17 | #endif |
| 18 | |
Thomas Abraham | e142e9f | 2009-01-04 09:41:13 +0530 | [diff] [blame] | 19 | /* MUSB platform configuration */ |
| 20 | struct musb_config musb_cfg = { |
Ajay Kumar Gupta | bbf4c01 | 2010-06-10 11:20:47 +0530 | [diff] [blame] | 21 | .regs = (struct musb_regs *)MENTOR_USB0_BASE, |
| 22 | .timeout = DAVINCI_USB_TIMEOUT, |
| 23 | .musb_speed = 0, |
Thomas Abraham | e142e9f | 2009-01-04 09:41:13 +0530 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | /* MUSB module register overlay */ |
| 27 | struct davinci_usb_regs *dregs; |
| 28 | |
| 29 | /* |
| 30 | * Enable the USB phy |
| 31 | */ |
| 32 | static u8 phy_on(void) |
| 33 | { |
| 34 | u32 timeout; |
Prathap Srinivas | 6e20e64 | 2010-01-11 15:36:46 +0530 | [diff] [blame] | 35 | #ifdef DAVINCI_DM365EVM |
| 36 | u32 val; |
| 37 | #endif |
Thomas Abraham | e142e9f | 2009-01-04 09:41:13 +0530 | [diff] [blame] | 38 | /* Wait until the USB phy is turned on */ |
Prathap Srinivas | 6e20e64 | 2010-01-11 15:36:46 +0530 | [diff] [blame] | 39 | #ifdef DAVINCI_DM365EVM |
| 40 | writel(USBPHY_PHY24MHZ | USBPHY_SESNDEN | |
| 41 | USBPHY_VBDTCTEN, USBPHY_CTL_PADDR); |
| 42 | #else |
Heiko Schocher | 1fa892c | 2011-11-01 20:00:26 +0000 | [diff] [blame] | 43 | writel(CONFIG_DV_USBPHY_CTL, USBPHY_CTL_PADDR); |
Prathap Srinivas | 6e20e64 | 2010-01-11 15:36:46 +0530 | [diff] [blame] | 44 | #endif |
Thomas Abraham | e142e9f | 2009-01-04 09:41:13 +0530 | [diff] [blame] | 45 | timeout = musb_cfg.timeout; |
Prathap Srinivas | 6e20e64 | 2010-01-11 15:36:46 +0530 | [diff] [blame] | 46 | |
| 47 | #ifdef DAVINCI_DM365EVM |
| 48 | /* Set the ownership of GIO33 to USB */ |
| 49 | val = readl(PINMUX4); |
| 50 | val &= ~(PINMUX4_USBDRVBUS_BITCLEAR); |
| 51 | val |= PINMUX4_USBDRVBUS_BITSET; |
| 52 | writel(val, PINMUX4); |
| 53 | #endif |
Thomas Abraham | e142e9f | 2009-01-04 09:41:13 +0530 | [diff] [blame] | 54 | while (timeout--) |
| 55 | if (readl(USBPHY_CTL_PADDR) & USBPHY_PHYCLKGD) |
| 56 | return 1; |
| 57 | |
| 58 | /* USB phy was not turned on */ |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * Disable the USB phy |
| 64 | */ |
| 65 | static void phy_off(void) |
| 66 | { |
| 67 | /* powerdown the on-chip PHY and its oscillator */ |
| 68 | writel(USBPHY_OSCPDWN | USBPHY_PHYPDWN, USBPHY_CTL_PADDR); |
| 69 | } |
| 70 | |
Heiko Schocher | 4ebe208 | 2011-11-01 20:00:25 +0000 | [diff] [blame] | 71 | void __enable_vbus(void) |
| 72 | { |
| 73 | /* |
| 74 | * nothing to do, vbus is handled through the cpu. |
| 75 | * Define this function in board code, if it is |
| 76 | * different on your board. |
| 77 | */ |
| 78 | } |
| 79 | void enable_vbus(void) |
| 80 | __attribute__((weak, alias("__enable_vbus"))); |
| 81 | |
Thomas Abraham | e142e9f | 2009-01-04 09:41:13 +0530 | [diff] [blame] | 82 | /* |
| 83 | * This function performs Davinci platform specific initialization for usb0. |
| 84 | */ |
| 85 | int musb_platform_init(void) |
| 86 | { |
| 87 | u32 revision; |
| 88 | |
| 89 | /* enable USB VBUS */ |
| 90 | enable_vbus(); |
Heiko Schocher | 4ebe208 | 2011-11-01 20:00:25 +0000 | [diff] [blame] | 91 | |
Thomas Abraham | e142e9f | 2009-01-04 09:41:13 +0530 | [diff] [blame] | 92 | /* start the on-chip USB phy and its pll */ |
| 93 | if (!phy_on()) |
| 94 | return -1; |
| 95 | |
| 96 | /* reset the controller */ |
| 97 | dregs = (struct davinci_usb_regs *)DAVINCI_USB0_BASE; |
| 98 | writel(1, &dregs->ctrlr); |
| 99 | udelay(5000); |
| 100 | |
| 101 | /* Returns zero if e.g. not clocked */ |
| 102 | revision = readl(&dregs->version); |
| 103 | if (!revision) |
| 104 | return -1; |
| 105 | |
| 106 | /* Disable all interrupts */ |
| 107 | writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_RXINT_MASK | |
| 108 | DAVINCI_USB_TXINT_MASK , &dregs->intmsksetr); |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | * This function performs Davinci platform specific deinitialization for usb0. |
| 114 | */ |
| 115 | void musb_platform_deinit(void) |
| 116 | { |
| 117 | /* Turn of the phy */ |
| 118 | phy_off(); |
| 119 | |
| 120 | /* flush any interrupts */ |
| 121 | writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_TXINT_MASK | |
| 122 | DAVINCI_USB_RXINT_MASK , &dregs->intclrr); |
| 123 | } |