usb: phy: rename nop_usb_xceiv => usb_phy_gen_xceiv
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Fri, 26 Jul 2013 10:16:42 +0000 (12:16 +0200)
committerFelipe Balbi <balbi@ti.com>
Fri, 9 Aug 2013 14:26:00 +0000 (17:26 +0300)
The "nop" driver isn't a do-nothing-stub but supports a couple functions
like clock on/off or is able to use a voltage regulator. This patch
simply renames the driver to "generic" since it is easy possible to
extend it by a simple function istead of writing a complete driver.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
17 files changed:
arch/arm/mach-omap2/board-omap3beagle.c
arch/arm/mach-omap2/board-omap3evm.c
arch/arm/mach-omap2/board-omap3pandora.c
arch/arm/mach-omap2/usb-host.c
drivers/usb/dwc3/dwc3-exynos.c
drivers/usb/dwc3/dwc3-pci.c
drivers/usb/musb/am35x.c
drivers/usb/musb/blackfin.c
drivers/usb/musb/da8xx.c
drivers/usb/musb/davinci.c
drivers/usb/musb/musb_dsps.c
drivers/usb/musb/tusb6010.c
drivers/usb/phy/Makefile
drivers/usb/phy/phy-generic.c [new file with mode: 0644]
drivers/usb/phy/phy-nop.c [deleted file]
include/linux/usb/nop-usb-xceiv.h [deleted file]
include/linux/usb/usb_phy_gen_xceiv.h [new file with mode: 0644]

index 04c1165554125553b29fc1292404c1cc922ed965..1c6ae5f5bae76753ca637aea07b3ce828d1e7512 100644 (file)
@@ -33,7 +33,7 @@
 #include <linux/mtd/nand.h>
 #include <linux/mmc/host.h>
 #include <linux/usb/phy.h>
-#include <linux/usb/nop-usb-xceiv.h>
+#include <linux/usb/usb_phy_gen_xceiv.h>
 
 #include <linux/regulator/machine.h>
 #include <linux/i2c/twl.h>
@@ -279,7 +279,7 @@ static struct regulator_consumer_supply beagle_vsim_supply[] = {
 static struct gpio_led gpio_leds[];
 
 /* PHY's VCC regulator might be added later, so flag that we need it */
-static struct nop_usb_xceiv_platform_data hsusb2_phy_data = {
+static struct usb_phy_gen_xceiv_platform_data hsusb2_phy_data = {
        .needs_vcc = true,
 };
 
index 8c026269bacaa379ec583dbeb81bd6f3ef9568b9..52bdddd41e0e38d3a1783eb1cc82cd116e2a5ea5 100644 (file)
@@ -33,7 +33,7 @@
 #include <linux/i2c/twl.h>
 #include <linux/usb/otg.h>
 #include <linux/usb/musb.h>
-#include <linux/usb/nop-usb-xceiv.h>
+#include <linux/usb/usb_phy_gen_xceiv.h>
 #include <linux/smsc911x.h>
 
 #include <linux/wl12xx.h>
@@ -468,7 +468,7 @@ struct wl12xx_platform_data omap3evm_wlan_data __initdata = {
 static struct regulator_consumer_supply omap3evm_vaux2_supplies[] = {
        REGULATOR_SUPPLY("VDD_CSIPHY1", "omap3isp"),    /* OMAP ISP */
        REGULATOR_SUPPLY("VDD_CSIPHY2", "omap3isp"),    /* OMAP ISP */
-       REGULATOR_SUPPLY("vcc", "nop_usb_xceiv.2"),     /* hsusb port 2 */
+       REGULATOR_SUPPLY("vcc", "usb_phy_gen_xceiv.2"), /* hsusb port 2 */
        REGULATOR_SUPPLY("vaux2", NULL),
 };
 
index b1547a0edfcd7df38b6e6e2cf5f74daec4ab0b36..d2b455e704861af41e7d36ec174ee7b7c7d8e014 100644 (file)
@@ -352,7 +352,7 @@ static struct regulator_consumer_supply pandora_vcc_lcd_supply[] = {
 };
 
 static struct regulator_consumer_supply pandora_usb_phy_supply[] = {
-       REGULATOR_SUPPLY("vcc", "nop_usb_xceiv.2"),     /* hsusb port 2 */
+       REGULATOR_SUPPLY("vcc", "usb_phy_gen_xceiv.2"), /* hsusb port 2 */
 };
 
 /* ads7846 on SPI and 2 nub controllers on I2C */
index 2eb19d4d0aa1cc041942ce7c8e2586dcc71d6852..e83a6a4b184af23c315a5e509a56ba8362d820e7 100644 (file)
@@ -28,7 +28,7 @@
 #include <linux/io.h>
 #include <linux/gpio.h>
 #include <linux/usb/phy.h>
-#include <linux/usb/nop-usb-xceiv.h>
+#include <linux/usb/usb_phy_gen_xceiv.h>
 
 #include "soc.h"
 #include "omap_device.h"
@@ -349,7 +349,7 @@ static struct fixed_voltage_config hsusb_reg_config = {
        /* .init_data filled later */
 };
 
-static const char *nop_name = "nop_usb_xceiv"; /* NOP PHY driver */
+static const char *nop_name = "usb_phy_gen_xceiv"; /* NOP PHY driver */
 static const char *reg_name = "reg-fixed-voltage"; /* Regulator driver */
 
 /**
@@ -460,9 +460,9 @@ int usbhs_init_phys(struct usbhs_phy_data *phy, int num_phys)
                pdevinfo.name = nop_name;
                pdevinfo.id = phy->port;
                pdevinfo.data = phy->platform_data;
-               pdevinfo.size_data = sizeof(struct nop_usb_xceiv_platform_data);
-
-               scnprintf(phy_id, MAX_STR, "nop_usb_xceiv.%d",
+               pdevinfo.size_data =
+                       sizeof(struct usb_phy_gen_xceiv_platform_data);
+               scnprintf(phy_id, MAX_STR, "usb_phy_gen_xceiv.%d",
                                        phy->port);
                pdev = platform_device_register_full(&pdevinfo);
                if (IS_ERR(pdev)) {
index 8ce9d7fd6cfc30051462373d3c8d1f2b681dfcb3..a179c5a54b39de4c343134a13e1f61518ca91c0b 100644 (file)
@@ -20,7 +20,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/clk.h>
 #include <linux/usb/otg.h>
-#include <linux/usb/nop-usb-xceiv.h>
+#include <linux/usb/usb_phy_gen_xceiv.h>
 #include <linux/of.h>
 #include <linux/of_platform.h>
 
@@ -34,13 +34,13 @@ struct dwc3_exynos {
 
 static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
 {
-       struct nop_usb_xceiv_platform_data pdata;
+       struct usb_phy_gen_xceiv_platform_data pdata;
        struct platform_device  *pdev;
        int                     ret;
 
        memset(&pdata, 0x00, sizeof(pdata));
 
-       pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
+       pdev = platform_device_alloc("usb_phy_gen_xceiv", PLATFORM_DEVID_AUTO);
        if (!pdev)
                return -ENOMEM;
 
@@ -51,7 +51,7 @@ static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
        if (ret)
                goto err1;
 
-       pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
+       pdev = platform_device_alloc("usb_phy_gen_xceiv", PLATFORM_DEVID_AUTO);
        if (!pdev) {
                ret = -ENOMEM;
                goto err1;
index ed07ec04a9622526b94666acc4f7390bcac56e25..87ea3d503fc55d4e30739291dc2b456e6105a1b9 100644 (file)
@@ -43,7 +43,7 @@
 #include <linux/platform_device.h>
 
 #include <linux/usb/otg.h>
-#include <linux/usb/nop-usb-xceiv.h>
+#include <linux/usb/usb_phy_gen_xceiv.h>
 
 /* FIXME define these in <linux/pci_ids.h> */
 #define PCI_VENDOR_ID_SYNOPSYS         0x16c3
@@ -58,13 +58,13 @@ struct dwc3_pci {
 
 static int dwc3_pci_register_phys(struct dwc3_pci *glue)
 {
-       struct nop_usb_xceiv_platform_data pdata;
+       struct usb_phy_gen_xceiv_platform_data pdata;
        struct platform_device  *pdev;
        int                     ret;
 
        memset(&pdata, 0x00, sizeof(pdata));
 
-       pdev = platform_device_alloc("nop_usb_xceiv", 0);
+       pdev = platform_device_alloc("usb_phy_gen_xceiv", 0);
        if (!pdev)
                return -ENOMEM;
 
@@ -75,7 +75,7 @@ static int dwc3_pci_register_phys(struct dwc3_pci *glue)
        if (ret)
                goto err1;
 
-       pdev = platform_device_alloc("nop_usb_xceiv", 1);
+       pdev = platform_device_alloc("usb_phy_gen_xceiv", 1);
        if (!pdev) {
                ret = -ENOMEM;
                goto err1;
index 2231850c062530765f49b761bd711e83bcde9579..5733a209ab955c37210a5a89531f739f64c2d206 100644 (file)
@@ -33,7 +33,7 @@
 #include <linux/io.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
-#include <linux/usb/nop-usb-xceiv.h>
+#include <linux/usb/usb_phy_gen_xceiv.h>
 #include <linux/platform_data/usb-omap.h>
 
 #include "musb_core.h"
index 6ba8439bd5a6e037d124a2fd5db152387fa3dd5a..195e96674fff9fed408cd75dfde0e9792d8193d5 100644 (file)
@@ -19,7 +19,7 @@
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <linux/prefetch.h>
-#include <linux/usb/nop-usb-xceiv.h>
+#include <linux/usb/usb_phy_gen_xceiv.h>
 
 #include <asm/cacheflush.h>
 
index 0da6f648a9fe1393faab16726bcc8d8725eb316c..ccc6b63bc3804e96637514eee93aac06f0a92d62 100644 (file)
@@ -33,7 +33,7 @@
 #include <linux/io.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
-#include <linux/usb/nop-usb-xceiv.h>
+#include <linux/usb/usb_phy_gen_xceiv.h>
 
 #include <mach/da8xx.h>
 #include <linux/platform_data/usb-davinci.h>
index f8aeaf2e2cd1f88ba2526861b2b932b6d6081050..91f300e93cf426d8c2ee45ead21f872076eb087e 100644 (file)
@@ -33,7 +33,7 @@
 #include <linux/gpio.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
-#include <linux/usb/nop-usb-xceiv.h>
+#include <linux/usb/usb_phy_gen_xceiv.h>
 
 #include <mach/cputype.h>
 #include <mach/hardware.h>
index 5233804d66b11f4b4890d2c53c2be0f49a0dfe0d..55fe3c292cd28043a69b8b65d1627b95d4a9bc9f 100644 (file)
@@ -36,7 +36,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/pm_runtime.h>
 #include <linux/module.h>
-#include <linux/usb/nop-usb-xceiv.h>
+#include <linux/usb/usb_phy_gen_xceiv.h>
 #include <linux/platform_data/usb-omap.h>
 #include <linux/sizes.h>
 
index 2c06a8969a9f793153d6f6f0546be9d5eb1ff8a0..20f182c6184a21b8291ac96f8f2f7cb80846005a 100644 (file)
@@ -25,7 +25,7 @@
 #include <linux/io.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
-#include <linux/usb/nop-usb-xceiv.h>
+#include <linux/usb/usb_phy_gen_xceiv.h>
 
 #include "musb_core.h"
 
index 070eca3af18b756e416d5bc9475c18ee9aaa5460..24c5816409fddd2d62858dd36b1cf82b9e33491b 100644 (file)
@@ -14,7 +14,7 @@ phy-fsl-usb2-objs                     := phy-fsl-usb.o phy-fsm-usb.o
 obj-$(CONFIG_FSL_USB2_OTG)             += phy-fsl-usb2.o
 obj-$(CONFIG_ISP1301_OMAP)             += phy-isp1301-omap.o
 obj-$(CONFIG_MV_U3D_PHY)               += phy-mv-u3d-usb.o
-obj-$(CONFIG_NOP_USB_XCEIV)            += phy-nop.o
+obj-$(CONFIG_NOP_USB_XCEIV)            += phy-generic.o
 obj-$(CONFIG_OMAP_CONTROL_USB)         += phy-omap-control.o
 obj-$(CONFIG_OMAP_USB2)                        += phy-omap-usb2.o
 obj-$(CONFIG_OMAP_USB3)                        += phy-omap-usb3.o
diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
new file mode 100644 (file)
index 0000000..f379b7d
--- /dev/null
@@ -0,0 +1,292 @@
+/*
+ * drivers/usb/otg/nop-usb-xceiv.c
+ *
+ * NOP USB transceiver for all USB transceiver which are either built-in
+ * into USB IP or which are mostly autonomous.
+ *
+ * Copyright (C) 2009 Texas Instruments Inc
+ * Author: Ajay Kumar Gupta <ajay.gupta@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Current status:
+ *     This provides a "nop" transceiver for PHYs which are
+ *     autonomous such as isp1504, isp1707, etc.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/usb_phy_gen_xceiv.h>
+#include <linux/slab.h>
+#include <linux/clk.h>
+#include <linux/regulator/consumer.h>
+#include <linux/of.h>
+
+struct usb_phy_gen_xceiv {
+       struct usb_phy phy;
+       struct device *dev;
+       struct clk *clk;
+       struct regulator *vcc;
+       struct regulator *reset;
+};
+
+static struct platform_device *pd;
+
+void usb_nop_xceiv_register(void)
+{
+       if (pd)
+               return;
+       pd = platform_device_register_simple("usb_phy_gen_xceiv", -1, NULL, 0);
+       if (!pd) {
+               pr_err("Unable to register generic usb transceiver\n");
+               return;
+       }
+}
+EXPORT_SYMBOL(usb_nop_xceiv_register);
+
+void usb_nop_xceiv_unregister(void)
+{
+       platform_device_unregister(pd);
+       pd = NULL;
+}
+EXPORT_SYMBOL(usb_nop_xceiv_unregister);
+
+static int nop_set_suspend(struct usb_phy *x, int suspend)
+{
+       return 0;
+}
+
+static int nop_init(struct usb_phy *phy)
+{
+       struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev);
+
+       if (!IS_ERR(nop->vcc)) {
+               if (regulator_enable(nop->vcc))
+                       dev_err(phy->dev, "Failed to enable power\n");
+       }
+
+       if (!IS_ERR(nop->clk))
+               clk_enable(nop->clk);
+
+       if (!IS_ERR(nop->reset)) {
+               /* De-assert RESET */
+               if (regulator_enable(nop->reset))
+                       dev_err(phy->dev, "Failed to de-assert reset\n");
+       }
+
+       return 0;
+}
+
+static void nop_shutdown(struct usb_phy *phy)
+{
+       struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev);
+
+       if (!IS_ERR(nop->reset)) {
+               /* Assert RESET */
+               if (regulator_disable(nop->reset))
+                       dev_err(phy->dev, "Failed to assert reset\n");
+       }
+
+       if (!IS_ERR(nop->clk))
+               clk_disable(nop->clk);
+
+       if (!IS_ERR(nop->vcc)) {
+               if (regulator_disable(nop->vcc))
+                       dev_err(phy->dev, "Failed to disable power\n");
+       }
+}
+
+static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
+{
+       if (!otg)
+               return -ENODEV;
+
+       if (!gadget) {
+               otg->gadget = NULL;
+               return -ENODEV;
+       }
+
+       otg->gadget = gadget;
+       otg->phy->state = OTG_STATE_B_IDLE;
+       return 0;
+}
+
+static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
+{
+       if (!otg)
+               return -ENODEV;
+
+       if (!host) {
+               otg->host = NULL;
+               return -ENODEV;
+       }
+
+       otg->host = host;
+       return 0;
+}
+
+static int usb_phy_gen_xceiv_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct usb_phy_gen_xceiv_platform_data *pdata = pdev->dev.platform_data;
+       struct usb_phy_gen_xceiv        *nop;
+       enum usb_phy_type       type = USB_PHY_TYPE_USB2;
+       int err;
+       u32 clk_rate = 0;
+       bool needs_vcc = false;
+       bool needs_reset = false;
+
+       nop = devm_kzalloc(&pdev->dev, sizeof(*nop), GFP_KERNEL);
+       if (!nop)
+               return -ENOMEM;
+
+       nop->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*nop->phy.otg),
+                                                       GFP_KERNEL);
+       if (!nop->phy.otg)
+               return -ENOMEM;
+
+       if (dev->of_node) {
+               struct device_node *node = dev->of_node;
+
+               if (of_property_read_u32(node, "clock-frequency", &clk_rate))
+                       clk_rate = 0;
+
+               needs_vcc = of_property_read_bool(node, "vcc-supply");
+               needs_reset = of_property_read_bool(node, "reset-supply");
+
+       } else if (pdata) {
+               type = pdata->type;
+               clk_rate = pdata->clk_rate;
+               needs_vcc = pdata->needs_vcc;
+               needs_reset = pdata->needs_reset;
+       }
+
+       nop->clk = devm_clk_get(&pdev->dev, "main_clk");
+       if (IS_ERR(nop->clk)) {
+               dev_dbg(&pdev->dev, "Can't get phy clock: %ld\n",
+                                       PTR_ERR(nop->clk));
+       }
+
+       if (!IS_ERR(nop->clk) && clk_rate) {
+               err = clk_set_rate(nop->clk, clk_rate);
+               if (err) {
+                       dev_err(&pdev->dev, "Error setting clock rate\n");
+                       return err;
+               }
+       }
+
+       if (!IS_ERR(nop->clk)) {
+               err = clk_prepare(nop->clk);
+               if (err) {
+                       dev_err(&pdev->dev, "Error preparing clock\n");
+                       return err;
+               }
+       }
+
+       nop->vcc = devm_regulator_get(&pdev->dev, "vcc");
+       if (IS_ERR(nop->vcc)) {
+               dev_dbg(&pdev->dev, "Error getting vcc regulator: %ld\n",
+                                       PTR_ERR(nop->vcc));
+               if (needs_vcc)
+                       return -EPROBE_DEFER;
+       }
+
+       nop->reset = devm_regulator_get(&pdev->dev, "reset");
+       if (IS_ERR(nop->reset)) {
+               dev_dbg(&pdev->dev, "Error getting reset regulator: %ld\n",
+                                       PTR_ERR(nop->reset));
+               if (needs_reset)
+                       return -EPROBE_DEFER;
+       }
+
+       nop->dev                = &pdev->dev;
+       nop->phy.dev            = nop->dev;
+       nop->phy.label          = "nop-xceiv";
+       nop->phy.set_suspend    = nop_set_suspend;
+       nop->phy.init           = nop_init;
+       nop->phy.shutdown       = nop_shutdown;
+       nop->phy.state          = OTG_STATE_UNDEFINED;
+       nop->phy.type           = type;
+
+       nop->phy.otg->phy               = &nop->phy;
+       nop->phy.otg->set_host          = nop_set_host;
+       nop->phy.otg->set_peripheral    = nop_set_peripheral;
+
+       err = usb_add_phy_dev(&nop->phy);
+       if (err) {
+               dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
+                       err);
+               goto err_add;
+       }
+
+       platform_set_drvdata(pdev, nop);
+
+       ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier);
+
+       return 0;
+
+err_add:
+       if (!IS_ERR(nop->clk))
+               clk_unprepare(nop->clk);
+       return err;
+}
+
+static int usb_phy_gen_xceiv_remove(struct platform_device *pdev)
+{
+       struct usb_phy_gen_xceiv *nop = platform_get_drvdata(pdev);
+
+       if (!IS_ERR(nop->clk))
+               clk_unprepare(nop->clk);
+
+       usb_remove_phy(&nop->phy);
+
+       return 0;
+}
+
+static const struct of_device_id nop_xceiv_dt_ids[] = {
+       { .compatible = "usb-nop-xceiv" },
+       { }
+};
+
+MODULE_DEVICE_TABLE(of, nop_xceiv_dt_ids);
+
+static struct platform_driver usb_phy_gen_xceiv_driver = {
+       .probe          = usb_phy_gen_xceiv_probe,
+       .remove         = usb_phy_gen_xceiv_remove,
+       .driver         = {
+               .name   = "usb_phy_gen_xceiv",
+               .owner  = THIS_MODULE,
+               .of_match_table = nop_xceiv_dt_ids,
+       },
+};
+
+static int __init usb_phy_gen_xceiv_init(void)
+{
+       return platform_driver_register(&usb_phy_gen_xceiv_driver);
+}
+subsys_initcall(usb_phy_gen_xceiv_init);
+
+static void __exit usb_phy_gen_xceiv_exit(void)
+{
+       platform_driver_unregister(&usb_phy_gen_xceiv_driver);
+}
+module_exit(usb_phy_gen_xceiv_exit);
+
+MODULE_ALIAS("platform:usb_phy_gen_xceiv");
+MODULE_AUTHOR("Texas Instruments Inc");
+MODULE_DESCRIPTION("NOP USB Transceiver driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/usb/phy/phy-nop.c b/drivers/usb/phy/phy-nop.c
deleted file mode 100644 (file)
index 55445e5..0000000
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * drivers/usb/otg/nop-usb-xceiv.c
- *
- * NOP USB transceiver for all USB transceiver which are either built-in
- * into USB IP or which are mostly autonomous.
- *
- * Copyright (C) 2009 Texas Instruments Inc
- * Author: Ajay Kumar Gupta <ajay.gupta@ti.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Current status:
- *     This provides a "nop" transceiver for PHYs which are
- *     autonomous such as isp1504, isp1707, etc.
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/dma-mapping.h>
-#include <linux/usb/otg.h>
-#include <linux/usb/nop-usb-xceiv.h>
-#include <linux/slab.h>
-#include <linux/clk.h>
-#include <linux/regulator/consumer.h>
-#include <linux/of.h>
-
-struct nop_usb_xceiv {
-       struct usb_phy phy;
-       struct device *dev;
-       struct clk *clk;
-       struct regulator *vcc;
-       struct regulator *reset;
-};
-
-static struct platform_device *pd;
-
-void usb_nop_xceiv_register(void)
-{
-       if (pd)
-               return;
-       pd = platform_device_register_simple("nop_usb_xceiv", -1, NULL, 0);
-       if (!pd) {
-               printk(KERN_ERR "Unable to register usb nop transceiver\n");
-               return;
-       }
-}
-EXPORT_SYMBOL(usb_nop_xceiv_register);
-
-void usb_nop_xceiv_unregister(void)
-{
-       platform_device_unregister(pd);
-       pd = NULL;
-}
-EXPORT_SYMBOL(usb_nop_xceiv_unregister);
-
-static int nop_set_suspend(struct usb_phy *x, int suspend)
-{
-       return 0;
-}
-
-static int nop_init(struct usb_phy *phy)
-{
-       struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev);
-
-       if (!IS_ERR(nop->vcc)) {
-               if (regulator_enable(nop->vcc))
-                       dev_err(phy->dev, "Failed to enable power\n");
-       }
-
-       if (!IS_ERR(nop->clk))
-               clk_enable(nop->clk);
-
-       if (!IS_ERR(nop->reset)) {
-               /* De-assert RESET */
-               if (regulator_enable(nop->reset))
-                       dev_err(phy->dev, "Failed to de-assert reset\n");
-       }
-
-       return 0;
-}
-
-static void nop_shutdown(struct usb_phy *phy)
-{
-       struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev);
-
-       if (!IS_ERR(nop->reset)) {
-               /* Assert RESET */
-               if (regulator_disable(nop->reset))
-                       dev_err(phy->dev, "Failed to assert reset\n");
-       }
-
-       if (!IS_ERR(nop->clk))
-               clk_disable(nop->clk);
-
-       if (!IS_ERR(nop->vcc)) {
-               if (regulator_disable(nop->vcc))
-                       dev_err(phy->dev, "Failed to disable power\n");
-       }
-}
-
-static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
-{
-       if (!otg)
-               return -ENODEV;
-
-       if (!gadget) {
-               otg->gadget = NULL;
-               return -ENODEV;
-       }
-
-       otg->gadget = gadget;
-       otg->phy->state = OTG_STATE_B_IDLE;
-       return 0;
-}
-
-static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
-{
-       if (!otg)
-               return -ENODEV;
-
-       if (!host) {
-               otg->host = NULL;
-               return -ENODEV;
-       }
-
-       otg->host = host;
-       return 0;
-}
-
-static int nop_usb_xceiv_probe(struct platform_device *pdev)
-{
-       struct device *dev = &pdev->dev;
-       struct nop_usb_xceiv_platform_data *pdata = pdev->dev.platform_data;
-       struct nop_usb_xceiv    *nop;
-       enum usb_phy_type       type = USB_PHY_TYPE_USB2;
-       int err;
-       u32 clk_rate = 0;
-       bool needs_vcc = false;
-       bool needs_reset = false;
-
-       nop = devm_kzalloc(&pdev->dev, sizeof(*nop), GFP_KERNEL);
-       if (!nop)
-               return -ENOMEM;
-
-       nop->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*nop->phy.otg),
-                                                       GFP_KERNEL);
-       if (!nop->phy.otg)
-               return -ENOMEM;
-
-       if (dev->of_node) {
-               struct device_node *node = dev->of_node;
-
-               if (of_property_read_u32(node, "clock-frequency", &clk_rate))
-                       clk_rate = 0;
-
-               needs_vcc = of_property_read_bool(node, "vcc-supply");
-               needs_reset = of_property_read_bool(node, "reset-supply");
-
-       } else if (pdata) {
-               type = pdata->type;
-               clk_rate = pdata->clk_rate;
-               needs_vcc = pdata->needs_vcc;
-               needs_reset = pdata->needs_reset;
-       }
-
-       nop->clk = devm_clk_get(&pdev->dev, "main_clk");
-       if (IS_ERR(nop->clk)) {
-               dev_dbg(&pdev->dev, "Can't get phy clock: %ld\n",
-                                       PTR_ERR(nop->clk));
-       }
-
-       if (!IS_ERR(nop->clk) && clk_rate) {
-               err = clk_set_rate(nop->clk, clk_rate);
-               if (err) {
-                       dev_err(&pdev->dev, "Error setting clock rate\n");
-                       return err;
-               }
-       }
-
-       if (!IS_ERR(nop->clk)) {
-               err = clk_prepare(nop->clk);
-               if (err) {
-                       dev_err(&pdev->dev, "Error preparing clock\n");
-                       return err;
-               }
-       }
-
-       nop->vcc = devm_regulator_get(&pdev->dev, "vcc");
-       if (IS_ERR(nop->vcc)) {
-               dev_dbg(&pdev->dev, "Error getting vcc regulator: %ld\n",
-                                       PTR_ERR(nop->vcc));
-               if (needs_vcc)
-                       return -EPROBE_DEFER;
-       }
-
-       nop->reset = devm_regulator_get(&pdev->dev, "reset");
-       if (IS_ERR(nop->reset)) {
-               dev_dbg(&pdev->dev, "Error getting reset regulator: %ld\n",
-                                       PTR_ERR(nop->reset));
-               if (needs_reset)
-                       return -EPROBE_DEFER;
-       }
-
-       nop->dev                = &pdev->dev;
-       nop->phy.dev            = nop->dev;
-       nop->phy.label          = "nop-xceiv";
-       nop->phy.set_suspend    = nop_set_suspend;
-       nop->phy.init           = nop_init;
-       nop->phy.shutdown       = nop_shutdown;
-       nop->phy.state          = OTG_STATE_UNDEFINED;
-       nop->phy.type           = type;
-
-       nop->phy.otg->phy               = &nop->phy;
-       nop->phy.otg->set_host          = nop_set_host;
-       nop->phy.otg->set_peripheral    = nop_set_peripheral;
-
-       err = usb_add_phy_dev(&nop->phy);
-       if (err) {
-               dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
-                       err);
-               goto err_add;
-       }
-
-       platform_set_drvdata(pdev, nop);
-
-       ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier);
-
-       return 0;
-
-err_add:
-       if (!IS_ERR(nop->clk))
-               clk_unprepare(nop->clk);
-       return err;
-}
-
-static int nop_usb_xceiv_remove(struct platform_device *pdev)
-{
-       struct nop_usb_xceiv *nop = platform_get_drvdata(pdev);
-
-       if (!IS_ERR(nop->clk))
-               clk_unprepare(nop->clk);
-
-       usb_remove_phy(&nop->phy);
-
-       return 0;
-}
-
-static const struct of_device_id nop_xceiv_dt_ids[] = {
-       { .compatible = "usb-nop-xceiv" },
-       { }
-};
-
-MODULE_DEVICE_TABLE(of, nop_xceiv_dt_ids);
-
-static struct platform_driver nop_usb_xceiv_driver = {
-       .probe          = nop_usb_xceiv_probe,
-       .remove         = nop_usb_xceiv_remove,
-       .driver         = {
-               .name   = "nop_usb_xceiv",
-               .owner  = THIS_MODULE,
-               .of_match_table = nop_xceiv_dt_ids,
-       },
-};
-
-static int __init nop_usb_xceiv_init(void)
-{
-       return platform_driver_register(&nop_usb_xceiv_driver);
-}
-subsys_initcall(nop_usb_xceiv_init);
-
-static void __exit nop_usb_xceiv_exit(void)
-{
-       platform_driver_unregister(&nop_usb_xceiv_driver);
-}
-module_exit(nop_usb_xceiv_exit);
-
-MODULE_ALIAS("platform:nop_usb_xceiv");
-MODULE_AUTHOR("Texas Instruments Inc");
-MODULE_DESCRIPTION("NOP USB Transceiver driver");
-MODULE_LICENSE("GPL");
diff --git a/include/linux/usb/nop-usb-xceiv.h b/include/linux/usb/nop-usb-xceiv.h
deleted file mode 100644 (file)
index 148d351..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef __LINUX_USB_NOP_XCEIV_H
-#define __LINUX_USB_NOP_XCEIV_H
-
-#include <linux/usb/otg.h>
-
-struct nop_usb_xceiv_platform_data {
-       enum usb_phy_type type;
-       unsigned long clk_rate;
-
-       /* if set fails with -EPROBE_DEFER if can't get regulator */
-       unsigned int needs_vcc:1;
-       unsigned int needs_reset:1;
-};
-
-#if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))
-/* sometimes transceivers are accessed only through e.g. ULPI */
-extern void usb_nop_xceiv_register(void);
-extern void usb_nop_xceiv_unregister(void);
-#else
-static inline void usb_nop_xceiv_register(void)
-{
-}
-
-static inline void usb_nop_xceiv_unregister(void)
-{
-}
-#endif
-
-#endif /* __LINUX_USB_NOP_XCEIV_H */
diff --git a/include/linux/usb/usb_phy_gen_xceiv.h b/include/linux/usb/usb_phy_gen_xceiv.h
new file mode 100644 (file)
index 0000000..f9a7e7b
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef __LINUX_USB_NOP_XCEIV_H
+#define __LINUX_USB_NOP_XCEIV_H
+
+#include <linux/usb/otg.h>
+
+struct usb_phy_gen_xceiv_platform_data {
+       enum usb_phy_type type;
+       unsigned long clk_rate;
+
+       /* if set fails with -EPROBE_DEFER if can't get regulator */
+       unsigned int needs_vcc:1;
+       unsigned int needs_reset:1;
+};
+
+#if IS_ENABLED(CONFIG_NOP_USB_XCEIV)
+/* sometimes transceivers are accessed only through e.g. ULPI */
+extern void usb_nop_xceiv_register(void);
+extern void usb_nop_xceiv_unregister(void);
+#else
+static inline void usb_nop_xceiv_register(void)
+{
+}
+
+static inline void usb_nop_xceiv_unregister(void)
+{
+}
+#endif
+
+#endif /* __LINUX_USB_NOP_XCEIV_H */