usb_831x.c 3.27 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-or-later
2 3 4 5 6 7 8 9 10 11
/*
 * Freescale 83xx USB SOC setup code
 *
 * Copyright (C) 2007 Freescale Semiconductor, Inc.
 * Author: Li Yang
 */

#include <linux/stddef.h>
#include <linux/kernel.h>
#include <linux/errno.h>
12
#include <linux/of.h>
13
#include <linux/of_address.h>
14
#include <linux/io.h>
15 16 17 18 19

#include <sysdev/fsl_soc.h>

#include "mpc83xx.h"

20
int __init mpc831x_usb_cfg(void)
21 22 23 24
{
	u32 temp;
	void __iomem *immap, *usb_regs;
	struct device_node *np = NULL;
25
	struct device_node *immr_node = NULL;
26 27 28 29 30 31 32
	const void *prop;
	struct resource res;
	int ret = 0;
#ifdef CONFIG_USB_OTG
	const void *dr_mode;
#endif

33
	np = of_find_compatible_node(NULL, NULL, "fsl-usb2-dr");
34 35 36 37 38 39 40 41 42 43 44 45
	if (!np)
		return -ENODEV;
	prop = of_get_property(np, "phy_type", NULL);

	/* Map IMMR space for pin and clock settings */
	immap = ioremap(get_immrbase(), 0x1000);
	if (!immap) {
		of_node_put(np);
		return -ENOMEM;
	}

	/* Configure clock */
46
	immr_node = of_get_parent(np);
47
	if (immr_node && (of_device_is_compatible(immr_node, "fsl,mpc8315-immr") ||
48
			  of_device_is_compatible(immr_node, "fsl,mpc8308-immr")))
49
		clrsetbits_be32(immap + MPC83XX_SCCR_OFFS,
50 51
				MPC8315_SCCR_USB_MASK,
				MPC8315_SCCR_USB_DRCM_01);
52 53
	else
		clrsetbits_be32(immap + MPC83XX_SCCR_OFFS,
54 55
				MPC83XX_SCCR_USB_MASK,
				MPC83XX_SCCR_USB_DRCM_11);
56 57

	/* Configure pin mux for ULPI.  There is no pin mux for UTMI */
58
	if (prop && !strcmp(prop, "ulpi")) {
59 60 61 62 63
		if (of_device_is_compatible(immr_node, "fsl,mpc8308-immr")) {
			clrsetbits_be32(immap + MPC83XX_SICRH_OFFS,
					MPC8308_SICRH_USB_MASK,
					MPC8308_SICRH_USB_ULPI);
		} else if (of_device_is_compatible(immr_node, "fsl,mpc8315-immr")) {
64 65 66 67 68 69 70 71 72 73 74 75 76 77
			clrsetbits_be32(immap + MPC83XX_SICRL_OFFS,
					MPC8315_SICRL_USB_MASK,
					MPC8315_SICRL_USB_ULPI);
			clrsetbits_be32(immap + MPC83XX_SICRH_OFFS,
					MPC8315_SICRH_USB_MASK,
					MPC8315_SICRH_USB_ULPI);
		} else {
			clrsetbits_be32(immap + MPC83XX_SICRL_OFFS,
					MPC831X_SICRL_USB_MASK,
					MPC831X_SICRL_USB_ULPI);
			clrsetbits_be32(immap + MPC83XX_SICRH_OFFS,
					MPC831X_SICRH_USB_MASK,
					MPC831X_SICRH_USB_ULPI);
		}
78 79 80 81
	}

	iounmap(immap);

82
	of_node_put(immr_node);
83

84 85 86 87 88 89
	/* Map USB SOC space */
	ret = of_address_to_resource(np, 0, &res);
	if (ret) {
		of_node_put(np);
		return ret;
	}
90
	usb_regs = ioremap(res.start, resource_size(&res));
91 92

	/* Using on-chip PHY */
93
	if (prop && (!strcmp(prop, "utmi_wide") || !strcmp(prop, "utmi"))) {
94 95
		u32 refsel;

96 97 98
		if (of_device_is_compatible(immr_node, "fsl,mpc8308-immr"))
			goto out;

99 100 101 102 103
		if (of_device_is_compatible(immr_node, "fsl,mpc8315-immr"))
			refsel = CONTROL_REFSEL_24MHZ;
		else
			refsel = CONTROL_REFSEL_48MHZ;
		/* Set UTMI_PHY_EN and REFSEL */
104
		out_be32(usb_regs + FSL_USB2_CONTROL_OFFS,
105
			 CONTROL_UTMI_PHY_EN | refsel);
106
	/* Using external UPLI PHY */
107
	} else if (prop && !strcmp(prop, "ulpi")) {
108 109 110 111
		/* Set PHY_CLK_SEL to ULPI */
		temp = CONTROL_PHY_CLK_SEL_ULPI;
#ifdef CONFIG_USB_OTG
		/* Set OTG_PORT */
112 113 114 115 116
		if (!of_device_is_compatible(immr_node, "fsl,mpc8308-immr")) {
			dr_mode = of_get_property(np, "dr_mode", NULL);
			if (dr_mode && !strcmp(dr_mode, "otg"))
				temp |= CONTROL_OTG_PORT;
		}
117 118 119
#endif /* CONFIG_USB_OTG */
		out_be32(usb_regs + FSL_USB2_CONTROL_OFFS, temp);
	} else {
120
		pr_warn("831x USB PHY type not supported\n");
121 122 123
		ret = -EINVAL;
	}

124
out:
125 126 127 128
	iounmap(usb_regs);
	of_node_put(np);
	return ret;
}