1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2983e3700STom Rini /*
3983e3700STom Rini  * This file configures the internal USB PHY in AM35X.
4983e3700STom Rini  *
5983e3700STom Rini  * Copyright (C) 2012 Ilya Yanok <ilya.yanok@gmail.com>
6983e3700STom Rini  *
7983e3700STom Rini  * Based on omap_phy_internal.c code from Linux by
8983e3700STom Rini  * Hema HK <hemahk@ti.com>
9983e3700STom Rini  */
10983e3700STom Rini 
11983e3700STom Rini #include <common.h>
12983e3700STom Rini #include <asm/io.h>
13983e3700STom Rini #include <asm/arch/am35x_def.h>
14983e3700STom Rini 
am35x_musb_reset(struct udevice * dev)151cac34ceSMugunthan V N void am35x_musb_reset(struct udevice *dev)
16983e3700STom Rini {
17983e3700STom Rini 	/* Reset the musb interface */
18983e3700STom Rini 	clrsetbits_le32(&am35x_scm_general_regs->ip_sw_reset,
19983e3700STom Rini 			0, USBOTGSS_SW_RST);
20983e3700STom Rini 	clrsetbits_le32(&am35x_scm_general_regs->ip_sw_reset,
21983e3700STom Rini 			USBOTGSS_SW_RST, 0);
22983e3700STom Rini }
23983e3700STom Rini 
am35x_musb_phy_power(struct udevice * dev,u8 on)241cac34ceSMugunthan V N void am35x_musb_phy_power(struct udevice *dev, u8 on)
25983e3700STom Rini {
26983e3700STom Rini 	unsigned long start = get_timer(0);
27983e3700STom Rini 
28983e3700STom Rini 	if (on) {
29983e3700STom Rini 		/*
30983e3700STom Rini 		 * Start the on-chip PHY and its PLL.
31983e3700STom Rini 		 */
32983e3700STom Rini 		clrsetbits_le32(&am35x_scm_general_regs->devconf2,
33983e3700STom Rini 				CONF2_RESET | CONF2_PHYPWRDN | CONF2_OTGPWRDN,
34983e3700STom Rini 				CONF2_PHY_PLLON);
35983e3700STom Rini 
36983e3700STom Rini 		debug("Waiting for PHY clock good...\n");
37983e3700STom Rini 		while (!(readl(&am35x_scm_general_regs->devconf2)
38983e3700STom Rini 				& CONF2_PHYCLKGD)) {
39983e3700STom Rini 
40983e3700STom Rini 			if (get_timer(start) > CONFIG_SYS_HZ / 10) {
41983e3700STom Rini 				printf("musb PHY clock good timed out\n");
42983e3700STom Rini 				break;
43983e3700STom Rini 			}
44983e3700STom Rini 		}
45983e3700STom Rini 	} else {
46983e3700STom Rini 		/*
47983e3700STom Rini 		 * Power down the on-chip PHY.
48983e3700STom Rini 		 */
49983e3700STom Rini 		clrsetbits_le32(&am35x_scm_general_regs->devconf2,
50983e3700STom Rini 				CONF2_PHY_PLLON,
51983e3700STom Rini 				CONF2_PHYPWRDN | CONF2_OTGPWRDN);
52983e3700STom Rini 	}
53983e3700STom Rini }
54983e3700STom Rini 
am35x_musb_clear_irq(struct udevice * dev)551cac34ceSMugunthan V N void am35x_musb_clear_irq(struct udevice *dev)
56983e3700STom Rini {
57983e3700STom Rini 	clrsetbits_le32(&am35x_scm_general_regs->lvl_intr_clr,
58983e3700STom Rini 			0, USBOTGSS_INT_CLR);
59983e3700STom Rini 	readl(&am35x_scm_general_regs->lvl_intr_clr);
60983e3700STom Rini }
61