usb: ehci: Add PHY support to ehci-pci
authorMarek Vasut <marek.vasut+renesas@gmail.com>
Tue, 7 Aug 2018 10:27:10 +0000 (12:27 +0200)
committerMarek Vasut <marex@denx.de>
Tue, 28 Aug 2018 09:00:19 +0000 (11:00 +0200)
Add support for operating a PHY attached to ehci-pci. There are
systems where the EHCI controller is internally wired to a PCI
bus and has a PHY connected to it as well, ie. the R-Car Gen2.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
drivers/usb/host/ehci-pci.c

index a56e5bd..6150f3d 100644 (file)
 /* Information about a USB port */
 struct ehci_pci_priv {
        struct ehci_ctrl ehci;
+       struct phy phy;
 };
 
 #ifdef CONFIG_DM_USB
-
-static void ehci_pci_init(struct udevice *dev, struct ehci_hccr **ret_hccr,
+static int ehci_pci_init(struct udevice *dev, struct ehci_hccr **ret_hccr,
                          struct ehci_hcor **ret_hcor)
 {
+       struct ehci_pci_priv *priv = dev_get_priv(dev);
        struct ehci_hccr *hccr;
        struct ehci_hcor *hcor;
+       int ret;
        u32 cmd;
 
+       ret = ehci_setup_phy(dev, &priv->phy, 0);
+       if (ret)
+               return ret;
+
        hccr = (struct ehci_hccr *)dm_pci_map_bar(dev,
                        PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
        hcor = (struct ehci_hcor *)((uintptr_t) hccr +
@@ -43,6 +49,8 @@ static void ehci_pci_init(struct udevice *dev, struct ehci_hccr **ret_hccr,
        dm_pci_read_config32(dev, PCI_COMMAND, &cmd);
        cmd |= PCI_COMMAND_MASTER;
        dm_pci_write_config32(dev, PCI_COMMAND, cmd);
+
+       return 0;
 }
 
 #else
@@ -120,12 +128,27 @@ static int ehci_pci_probe(struct udevice *dev)
 {
        struct ehci_hccr *hccr;
        struct ehci_hcor *hcor;
+       int ret;
 
-       ehci_pci_init(dev, &hccr, &hcor);
+       ret = ehci_pci_init(dev, &hccr, &hcor);
+       if (ret)
+               return ret;
 
        return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
 }
 
+static int ehci_pci_remove(struct udevice *dev)
+{
+       struct ehci_pci_priv *priv = dev_get_priv(dev);
+       int ret;
+
+       ret = ehci_deregister(dev);
+       if (ret)
+               return ret;
+
+       return ehci_shutdown_phy(dev, &priv->phy);
+}
+
 static const struct udevice_id ehci_pci_ids[] = {
        { .compatible = "ehci-pci" },
        { }
@@ -135,7 +158,7 @@ U_BOOT_DRIVER(ehci_pci) = {
        .name   = "ehci_pci",
        .id     = UCLASS_USB,
        .probe = ehci_pci_probe,
-       .remove = ehci_deregister,
+       .remove = ehci_pci_remove,
        .of_match = ehci_pci_ids,
        .ops    = &ehci_usb_ops,
        .platdata_auto_alloc_size = sizeof(struct usb_platdata),