^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * phy-bcm-kona-usb2.c - Broadcom Kona USB2 Phy Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2013 Linaro Limited
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Matt Porter <mporter@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/phy/phy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define OTGCTL (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define OTGCTL_OTGSTAT2 BIT(31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define OTGCTL_OTGSTAT1 BIT(30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define OTGCTL_PRST_N_SW BIT(11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define OTGCTL_HRESET_N BIT(10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define OTGCTL_UTMI_LINE_STATE1 BIT(9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define OTGCTL_UTMI_LINE_STATE0 BIT(8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define P1CTL (8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define P1CTL_SOFT_RESET BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define P1CTL_NON_DRIVING BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct bcm_kona_usb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) void __iomem *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static void bcm_kona_usb_phy_power(struct bcm_kona_usb *phy, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) val = readl(phy->regs + OTGCTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* Configure and power PHY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) val &= ~(OTGCTL_OTGSTAT2 | OTGCTL_OTGSTAT1 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) OTGCTL_UTMI_LINE_STATE1 | OTGCTL_UTMI_LINE_STATE0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) val |= OTGCTL_PRST_N_SW | OTGCTL_HRESET_N;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) val &= ~(OTGCTL_PRST_N_SW | OTGCTL_HRESET_N);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) writel(val, phy->regs + OTGCTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int bcm_kona_usb_phy_init(struct phy *gphy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct bcm_kona_usb *phy = phy_get_drvdata(gphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* Soft reset PHY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) val = readl(phy->regs + P1CTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) val &= ~P1CTL_NON_DRIVING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) val |= P1CTL_SOFT_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) writel(val, phy->regs + P1CTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) writel(val & ~P1CTL_SOFT_RESET, phy->regs + P1CTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* Reset needs to be asserted for 2ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) mdelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) writel(val | P1CTL_SOFT_RESET, phy->regs + P1CTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int bcm_kona_usb_phy_power_on(struct phy *gphy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct bcm_kona_usb *phy = phy_get_drvdata(gphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) bcm_kona_usb_phy_power(phy, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static int bcm_kona_usb_phy_power_off(struct phy *gphy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct bcm_kona_usb *phy = phy_get_drvdata(gphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) bcm_kona_usb_phy_power(phy, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static const struct phy_ops ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .init = bcm_kona_usb_phy_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .power_on = bcm_kona_usb_phy_power_on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .power_off = bcm_kona_usb_phy_power_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static int bcm_kona_usb2_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct bcm_kona_usb *phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct phy *gphy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct phy_provider *phy_provider;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (!phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) phy->regs = devm_ioremap_resource(&pdev->dev, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (IS_ERR(phy->regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return PTR_ERR(phy->regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) platform_set_drvdata(pdev, phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) gphy = devm_phy_create(dev, NULL, &ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (IS_ERR(gphy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return PTR_ERR(gphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /* The Kona PHY supports an 8-bit wide UTMI interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) phy_set_bus_width(gphy, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) phy_set_drvdata(gphy, phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) phy_provider = devm_of_phy_provider_register(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) of_phy_simple_xlate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return PTR_ERR_OR_ZERO(phy_provider);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static const struct of_device_id bcm_kona_usb2_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) { .compatible = "brcm,kona-usb2-phy" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) { /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) MODULE_DEVICE_TABLE(of, bcm_kona_usb2_dt_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static struct platform_driver bcm_kona_usb2_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .probe = bcm_kona_usb2_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .name = "bcm-kona-usb2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .of_match_table = bcm_kona_usb2_dt_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) module_platform_driver(bcm_kona_usb2_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) MODULE_ALIAS("platform:bcm-kona-usb2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) MODULE_AUTHOR("Matt Porter <mporter@linaro.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) MODULE_DESCRIPTION("BCM Kona USB 2.0 PHY driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) MODULE_LICENSE("GPL v2");