1 *5951b62bSChristophe Leroy // SPDX-License-Identifier: GPL-2.0-or-later
2 *5951b62bSChristophe Leroy /*
3 *5951b62bSChristophe Leroy * Freescale 83xx USB SOC setup code
4 *5951b62bSChristophe Leroy *
5 *5951b62bSChristophe Leroy * Copyright (C) 2007 Freescale Semiconductor, Inc.
6 *5951b62bSChristophe Leroy * Author: Li Yang
7 *5951b62bSChristophe Leroy */
8 *5951b62bSChristophe Leroy
9 *5951b62bSChristophe Leroy #include <linux/stddef.h>
10 *5951b62bSChristophe Leroy #include <linux/kernel.h>
11 *5951b62bSChristophe Leroy #include <linux/errno.h>
12 *5951b62bSChristophe Leroy #include <linux/of.h>
13 *5951b62bSChristophe Leroy #include <linux/of_address.h>
14 *5951b62bSChristophe Leroy #include <linux/io.h>
15 *5951b62bSChristophe Leroy
16 *5951b62bSChristophe Leroy #include <sysdev/fsl_soc.h>
17 *5951b62bSChristophe Leroy
18 *5951b62bSChristophe Leroy #include "mpc83xx.h"
19 *5951b62bSChristophe Leroy
mpc837x_usb_cfg(void)20 *5951b62bSChristophe Leroy int __init mpc837x_usb_cfg(void)
21 *5951b62bSChristophe Leroy {
22 *5951b62bSChristophe Leroy void __iomem *immap;
23 *5951b62bSChristophe Leroy struct device_node *np = NULL;
24 *5951b62bSChristophe Leroy const void *prop;
25 *5951b62bSChristophe Leroy int ret = 0;
26 *5951b62bSChristophe Leroy
27 *5951b62bSChristophe Leroy np = of_find_compatible_node(NULL, NULL, "fsl-usb2-dr");
28 *5951b62bSChristophe Leroy if (!np || !of_device_is_available(np)) {
29 *5951b62bSChristophe Leroy of_node_put(np);
30 *5951b62bSChristophe Leroy return -ENODEV;
31 *5951b62bSChristophe Leroy }
32 *5951b62bSChristophe Leroy prop = of_get_property(np, "phy_type", NULL);
33 *5951b62bSChristophe Leroy
34 *5951b62bSChristophe Leroy if (!prop || (strcmp(prop, "ulpi") && strcmp(prop, "serial"))) {
35 *5951b62bSChristophe Leroy pr_warn("837x USB PHY type not supported\n");
36 *5951b62bSChristophe Leroy of_node_put(np);
37 *5951b62bSChristophe Leroy return -EINVAL;
38 *5951b62bSChristophe Leroy }
39 *5951b62bSChristophe Leroy
40 *5951b62bSChristophe Leroy /* Map IMMR space for pin and clock settings */
41 *5951b62bSChristophe Leroy immap = ioremap(get_immrbase(), 0x1000);
42 *5951b62bSChristophe Leroy if (!immap) {
43 *5951b62bSChristophe Leroy of_node_put(np);
44 *5951b62bSChristophe Leroy return -ENOMEM;
45 *5951b62bSChristophe Leroy }
46 *5951b62bSChristophe Leroy
47 *5951b62bSChristophe Leroy /* Configure clock */
48 *5951b62bSChristophe Leroy clrsetbits_be32(immap + MPC83XX_SCCR_OFFS, MPC837X_SCCR_USB_DRCM_11,
49 *5951b62bSChristophe Leroy MPC837X_SCCR_USB_DRCM_11);
50 *5951b62bSChristophe Leroy
51 *5951b62bSChristophe Leroy /* Configure pin mux for ULPI/serial */
52 *5951b62bSChristophe Leroy clrsetbits_be32(immap + MPC83XX_SICRL_OFFS, MPC837X_SICRL_USB_MASK,
53 *5951b62bSChristophe Leroy MPC837X_SICRL_USB_ULPI);
54 *5951b62bSChristophe Leroy
55 *5951b62bSChristophe Leroy iounmap(immap);
56 *5951b62bSChristophe Leroy of_node_put(np);
57 *5951b62bSChristophe Leroy return ret;
58 *5951b62bSChristophe Leroy }
59