summaryrefslogtreecommitdiffstats
path: root/drivers/phy/phy-da8xx-usb.c
blob: d025188eae983d42d8f91cc2a44df4e653d649ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: GPL-2.0+
/*
 * Based on the DA8xx "glue layer" code.
 * Copyright (c) 2008-2019, MontaVista Software, Inc. <source@mvista.com>
 *
 * DT support added by: Adam Ford <aford173@gmail.com>
 */

#include <common.h>
#include <dm.h>
#include <log.h>
#include <dm/device-internal.h>
#include <dm/lists.h>
#include <asm/arch/hardware.h>
#include <asm/arch/da8xx-usb.h>
#include <asm/io.h>
#include <generic-phy.h>

static int da8xx_usb_phy_power_on(struct phy *phy)
{
	unsigned long timeout;

	clrsetbits_le32(&davinci_syscfg_regs->cfgchip2,
			CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN |
			CFGCHIP2_OTGMODE | CFGCHIP2_REFFREQ,
			CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN |
			CFGCHIP2_PHY_PLLON | CFGCHIP2_REFFREQ_24MHZ);

	/* wait until the usb phy pll locks */
	timeout = get_timer(0);
	while (get_timer(timeout) < 10) {
		if (readl(&davinci_syscfg_regs->cfgchip2) & CFGCHIP2_PHYCLKGD)
			return 0;
	}

	debug("Phy was not turned on\n");

	return -ENODEV;
}

static int da8xx_usb_phy_power_off(struct phy *phy)
{
	clrsetbits_le32(&davinci_syscfg_regs->cfgchip2,
			CFGCHIP2_PHY_PLLON,
			CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN);

	return 0;
}

static const struct udevice_id da8xx_phy_ids[] = {
	{ .compatible = "ti,da830-usb-phy" },
	{ }
};

static struct phy_ops da8xx_phy_ops = {
	.power_on = da8xx_usb_phy_power_on,
	.power_off = da8xx_usb_phy_power_off,
};

U_BOOT_DRIVER(da8xx_phy) = {
	.name	= "da8xx-usb-phy",
	.id	= UCLASS_PHY,
	.of_match = da8xx_phy_ids,
	.ops = &da8xx_phy_ops,
};