MCPcopy Create free account
hub / github.com/F-Stack/f-stack / mtk_usb_phy_attach

Function mtk_usb_phy_attach

freebsd/mips/mediatek/mtk_usb_phy.c:112–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112static int
113mtk_usb_phy_attach(device_t dev)
114{
115 struct mtk_usb_phy_softc * sc = device_get_softc(dev);
116 phandle_t node;
117 uint32_t val;
118 int rid;
119
120 sc->dev = dev;
121
122 /* Get our FDT node and SoC id */
123 node = ofw_bus_get_node(dev);
124
125 /* Now let's see about setting USB to host or device mode */
126 /* XXX: is it the same for all SoCs? */
127 val = mtk_sysctl_get(SYSCTL_SYSCFG1);
128 if (OF_hasprop(node, "mtk,usb-device"))
129 val &= ~SYSCFG1_USB_HOST_MODE;
130 else
131 val |= SYSCFG1_USB_HOST_MODE;
132 mtk_sysctl_set(SYSCTL_SYSCFG1, val);
133
134 /* If we have clocks defined - enable them */
135 if (OF_hasprop(node, "clocks"))
136 fdt_clock_enable_all(dev);
137
138 /* If we have resets defined - perform a reset sequence */
139 if (OF_hasprop(node, "resets")) {
140 fdt_reset_assert_all(dev);
141 DELAY(RESET_ASSERT_DELAY);
142 fdt_reset_deassert_all(dev);
143 DELAY(RESET_DEASSERT_DELAY);
144 }
145
146 /* Careful, some devices actually require resources */
147 if (OF_hasprop(node, "reg")) {
148 rid = 0;
149 sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
150 RF_ACTIVE);
151 if (sc->res == NULL) {
152 device_printf(dev, "could not map memory\n");
153 return (ENXIO);
154 }
155 } else {
156 sc->res = NULL;
157 }
158
159 /* Some SoCs require specific USB PHY init... handle these */
160 switch (sc->socid) {
161 case MTK_SOC_MT7628: /* Fallthrough */
162 case MTK_SOC_MT7688:
163 if (sc->res == NULL)
164 return (ENXIO);
165 sc->fm_base = MT7628_FM_FEG_BASE;
166 sc->u2_base = MT7628_U2_BASE;
167 sc->sr_coef = MT7628_SR_COEF;
168 mtk_usb_phy_mt7628_init(dev);
169 break;

Callers

nothing calls this directly

Calls 11

device_get_softcFunction · 0.85
mtk_sysctl_getFunction · 0.85
mtk_sysctl_setFunction · 0.85
fdt_reset_assert_allFunction · 0.85
fdt_reset_deassert_allFunction · 0.85
bus_alloc_resource_anyFunction · 0.85
device_printfFunction · 0.85
mtk_usb_phy_mt7628_initFunction · 0.85
mtk_usb_phy_mt7621_initFunction · 0.85
bus_release_resourceFunction · 0.85
DELAYFunction · 0.50

Tested by

no test coverage detected