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
mpc834x_usb_cfg(void)20*5951b62bSChristophe Leroy int __init mpc834x_usb_cfg(void)
21*5951b62bSChristophe Leroy {
22*5951b62bSChristophe Leroy unsigned long sccr, sicrl, sicrh;
23*5951b62bSChristophe Leroy void __iomem *immap;
24*5951b62bSChristophe Leroy struct device_node *np = NULL;
25*5951b62bSChristophe Leroy int port0_is_dr = 0, port1_is_dr = 0;
26*5951b62bSChristophe Leroy const void *prop, *dr_mode;
27*5951b62bSChristophe Leroy
28*5951b62bSChristophe Leroy immap = ioremap(get_immrbase(), 0x1000);
29*5951b62bSChristophe Leroy if (!immap)
30*5951b62bSChristophe Leroy return -ENOMEM;
31*5951b62bSChristophe Leroy
32*5951b62bSChristophe Leroy /* Read registers */
33*5951b62bSChristophe Leroy /* Note: DR and MPH must use the same clock setting in SCCR */
34*5951b62bSChristophe Leroy sccr = in_be32(immap + MPC83XX_SCCR_OFFS) & ~MPC83XX_SCCR_USB_MASK;
35*5951b62bSChristophe Leroy sicrl = in_be32(immap + MPC83XX_SICRL_OFFS) & ~MPC834X_SICRL_USB_MASK;
36*5951b62bSChristophe Leroy sicrh = in_be32(immap + MPC83XX_SICRH_OFFS) & ~MPC834X_SICRH_USB_UTMI;
37*5951b62bSChristophe Leroy
38*5951b62bSChristophe Leroy np = of_find_compatible_node(NULL, NULL, "fsl-usb2-dr");
39*5951b62bSChristophe Leroy if (np) {
40*5951b62bSChristophe Leroy sccr |= MPC83XX_SCCR_USB_DRCM_11; /* 1:3 */
41*5951b62bSChristophe Leroy
42*5951b62bSChristophe Leroy prop = of_get_property(np, "phy_type", NULL);
43*5951b62bSChristophe Leroy port1_is_dr = 1;
44*5951b62bSChristophe Leroy if (prop &&
45*5951b62bSChristophe Leroy (!strcmp(prop, "utmi") || !strcmp(prop, "utmi_wide"))) {
46*5951b62bSChristophe Leroy sicrl |= MPC834X_SICRL_USB0 | MPC834X_SICRL_USB1;
47*5951b62bSChristophe Leroy sicrh |= MPC834X_SICRH_USB_UTMI;
48*5951b62bSChristophe Leroy port0_is_dr = 1;
49*5951b62bSChristophe Leroy } else if (prop && !strcmp(prop, "serial")) {
50*5951b62bSChristophe Leroy dr_mode = of_get_property(np, "dr_mode", NULL);
51*5951b62bSChristophe Leroy if (dr_mode && !strcmp(dr_mode, "otg")) {
52*5951b62bSChristophe Leroy sicrl |= MPC834X_SICRL_USB0 | MPC834X_SICRL_USB1;
53*5951b62bSChristophe Leroy port0_is_dr = 1;
54*5951b62bSChristophe Leroy } else {
55*5951b62bSChristophe Leroy sicrl |= MPC834X_SICRL_USB1;
56*5951b62bSChristophe Leroy }
57*5951b62bSChristophe Leroy } else if (prop && !strcmp(prop, "ulpi")) {
58*5951b62bSChristophe Leroy sicrl |= MPC834X_SICRL_USB1;
59*5951b62bSChristophe Leroy } else {
60*5951b62bSChristophe Leroy pr_warn("834x USB PHY type not supported\n");
61*5951b62bSChristophe Leroy }
62*5951b62bSChristophe Leroy of_node_put(np);
63*5951b62bSChristophe Leroy }
64*5951b62bSChristophe Leroy np = of_find_compatible_node(NULL, NULL, "fsl-usb2-mph");
65*5951b62bSChristophe Leroy if (np) {
66*5951b62bSChristophe Leroy sccr |= MPC83XX_SCCR_USB_MPHCM_11; /* 1:3 */
67*5951b62bSChristophe Leroy
68*5951b62bSChristophe Leroy prop = of_get_property(np, "port0", NULL);
69*5951b62bSChristophe Leroy if (prop) {
70*5951b62bSChristophe Leroy if (port0_is_dr)
71*5951b62bSChristophe Leroy pr_warn("834x USB port0 can't be used by both DR and MPH!\n");
72*5951b62bSChristophe Leroy sicrl &= ~MPC834X_SICRL_USB0;
73*5951b62bSChristophe Leroy }
74*5951b62bSChristophe Leroy prop = of_get_property(np, "port1", NULL);
75*5951b62bSChristophe Leroy if (prop) {
76*5951b62bSChristophe Leroy if (port1_is_dr)
77*5951b62bSChristophe Leroy pr_warn("834x USB port1 can't be used by both DR and MPH!\n");
78*5951b62bSChristophe Leroy sicrl &= ~MPC834X_SICRL_USB1;
79*5951b62bSChristophe Leroy }
80*5951b62bSChristophe Leroy of_node_put(np);
81*5951b62bSChristophe Leroy }
82*5951b62bSChristophe Leroy
83*5951b62bSChristophe Leroy /* Write back */
84*5951b62bSChristophe Leroy out_be32(immap + MPC83XX_SCCR_OFFS, sccr);
85*5951b62bSChristophe Leroy out_be32(immap + MPC83XX_SICRL_OFFS, sicrl);
86*5951b62bSChristophe Leroy out_be32(immap + MPC83XX_SICRH_OFFS, sicrh);
87*5951b62bSChristophe Leroy
88*5951b62bSChristophe Leroy iounmap(immap);
89*5951b62bSChristophe Leroy return 0;
90*5951b62bSChristophe Leroy }
91