// SPDX-License-Identifier: GPL-2.0+ /* * Central probing code for the FOTG210 dual role driver * We register one driver for the hardware and then we decide * whether to proceed with probing the host or the peripheral * driver.
*/ #include <linux/bitops.h> #include <linux/clk.h> #include <linux/device.h> #include <linux/mfd/syscon.h> #include <linux/module.h> #include <linux/of.h> #include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/string_choices.h> #include <linux/usb.h> #include <linux/usb/otg.h>
/* * Gemini-specific initialization function, only executed on the * Gemini SoC using the global misc control register. * * The gemini USB blocks are connected to either Mini-A (host mode) or * Mini-B (peripheral mode) plugs. There is no role switch support on the * Gemini SoC, just either-or.
*/ #define GEMINI_GLOBAL_MISC_CTRL 0x30 #define GEMINI_MISC_USB0_WAKEUP BIT(14) #define GEMINI_MISC_USB1_WAKEUP BIT(15) #define GEMINI_MISC_USB0_VBUS_ON BIT(22) #define GEMINI_MISC_USB1_VBUS_ON BIT(23) #define GEMINI_MISC_USB0_MINI_B BIT(29) #define GEMINI_MISC_USB1_MINI_B BIT(30)
map = syscon_regmap_lookup_by_phandle(np, "syscon"); if (IS_ERR(map)) return dev_err_probe(dev, PTR_ERR(map), "no syscon\n");
fotg->map = map;
wakeup = of_property_read_bool(np, "wakeup-source");
/* * Figure out if this is USB0 or USB1 by simply checking the * physical base address.
*/
mask = 0; if (res->start == 0x69000000) {
fotg->port = GEMINI_PORT_1;
mask = GEMINI_MISC_USB1_VBUS_ON | GEMINI_MISC_USB1_MINI_B |
GEMINI_MISC_USB1_WAKEUP; if (mode == USB_DR_MODE_HOST)
val = GEMINI_MISC_USB1_VBUS_ON; else
val = GEMINI_MISC_USB1_MINI_B; if (wakeup)
val |= GEMINI_MISC_USB1_WAKEUP;
} else {
fotg->port = GEMINI_PORT_0;
mask = GEMINI_MISC_USB0_VBUS_ON | GEMINI_MISC_USB0_MINI_B |
GEMINI_MISC_USB0_WAKEUP; if (mode == USB_DR_MODE_HOST)
val = GEMINI_MISC_USB0_VBUS_ON; else
val = GEMINI_MISC_USB0_MINI_B; if (wakeup)
val |= GEMINI_MISC_USB0_WAKEUP;
}
ret = regmap_update_bits(map, GEMINI_GLOBAL_MISC_CTRL, mask, val); if (ret) {
dev_err(dev, "failed to initialize Gemini PHY\n"); return ret;
}
fotg->base = devm_platform_get_and_ioremap_resource(pdev, 0, &fotg->res); if (IS_ERR(fotg->base)) return PTR_ERR(fotg->base);
fotg->pclk = devm_clk_get_optional_enabled(dev, "PCLK"); if (IS_ERR(fotg->pclk)) return PTR_ERR(fotg->pclk);
mode = usb_get_dr_mode(dev);
if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) {
ret = fotg210_gemini_init(fotg, fotg->res, mode); if (ret) return ret;
}
val = readl(fotg->base + FOTG210_RR); if (mode == USB_DR_MODE_PERIPHERAL) { if (!(val & FOTG210_RR_CROLE))
dev_err(dev, "block not in device role\n");
ret = fotg210_udc_probe(pdev, fotg);
} else { if (val & FOTG210_RR_CROLE)
dev_err(dev, "block not in host role\n");
ret = fotg210_hcd_probe(pdev, fotg);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.