Home | History | Annotate | Download | only in musb
      1 // SPDX-License-Identifier: GPL-2.0+
      2 /*
      3  * TI's Davinci platform specific USB wrapper functions.
      4  *
      5  * Copyright (c) 2008 Texas Instruments
      6  *
      7  * Author: Thomas Abraham t-abraham (at) ti.com, Texas Instruments
      8  */
      9 
     10 #include <common.h>
     11 #include <asm/io.h>
     12 #include "davinci.h"
     13 #include <asm/arch/hardware.h>
     14 
     15 #if !defined(CONFIG_DV_USBPHY_CTL)
     16 #define CONFIG_DV_USBPHY_CTL (USBPHY_SESNDEN | USBPHY_VBDTCTEN)
     17 #endif
     18 
     19 /* MUSB platform configuration */
     20 struct musb_config musb_cfg = {
     21 	.regs		= (struct musb_regs *)MENTOR_USB0_BASE,
     22 	.timeout	= DAVINCI_USB_TIMEOUT,
     23 	.musb_speed	= 0,
     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;
     35 #ifdef DAVINCI_DM365EVM
     36 	u32 val;
     37 #endif
     38 	/* Wait until the USB phy is turned on */
     39 #ifdef DAVINCI_DM365EVM
     40 	writel(USBPHY_PHY24MHZ | USBPHY_SESNDEN |
     41 			USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
     42 #else
     43 	writel(CONFIG_DV_USBPHY_CTL, USBPHY_CTL_PADDR);
     44 #endif
     45 	timeout = musb_cfg.timeout;
     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
     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 
     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 
     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();
     91 
     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 }
    124