]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/usb/host/ohci-sunxi.c
sunxi: usb-phy: Never power off the usb ports
[karo-tx-uboot.git] / drivers / usb / host / ohci-sunxi.c
1 /*
2  * Sunxi ohci glue
3  *
4  * Copyright (C) 2015 Hans de Goede <hdegoede@redhat.com>
5  *
6  * Based on code from
7  * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
8  *
9  * SPDX-License-Identifier:     GPL-2.0+
10  */
11
12 #include <common.h>
13 #include <asm/arch/clock.h>
14 #include <asm/arch/usb_phy.h>
15 #include <asm/io.h>
16 #include <dm.h>
17 #include <usb.h>
18 #include "ohci.h"
19
20 struct ohci_sunxi_priv {
21         ohci_t ohci;
22         int ahb_gate_mask; /* Mask of ahb_gate0 clk gate bits for this hcd */
23         int usb_gate_mask; /* Mask of usb_clk_cfg clk gate bits for this hcd */
24         int phy_index;     /* Index of the usb-phy attached to this hcd */
25 };
26
27 static int ohci_usb_probe(struct udevice *dev)
28 {
29         struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
30         struct usb_bus_priv *bus_priv = dev_get_uclass_priv(dev);
31         struct ohci_sunxi_priv *priv = dev_get_priv(dev);
32         struct ohci_regs *regs = (struct ohci_regs *)dev_get_addr(dev);
33
34         bus_priv->companion = true;
35
36         /*
37          * This should go away once we've moved to the driver model for
38          * clocks resp. phys.
39          */
40         if (regs == (void *)(SUNXI_USB1_BASE + 0x400)) {
41                 priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI0;
42                 priv->usb_gate_mask = CCM_USB_CTRL_OHCI0_CLK;
43                 priv->phy_index = 1;
44         } else {
45                 priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI1;
46                 priv->usb_gate_mask = CCM_USB_CTRL_OHCI1_CLK;
47                 priv->phy_index = 2;
48         }
49
50         setbits_le32(&ccm->ahb_gate0, priv->ahb_gate_mask);
51         setbits_le32(&ccm->usb_clk_cfg, priv->usb_gate_mask);
52 #ifdef CONFIG_SUNXI_GEN_SUN6I
53         setbits_le32(&ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
54 #endif
55
56         sunxi_usb_phy_init(priv->phy_index);
57         sunxi_usb_phy_power_on(priv->phy_index);
58
59         return ohci_register(dev, regs);
60 }
61
62 static int ohci_usb_remove(struct udevice *dev)
63 {
64         struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
65         struct ohci_sunxi_priv *priv = dev_get_priv(dev);
66         int ret;
67
68         ret = ohci_deregister(dev);
69         if (ret)
70                 return ret;
71
72         sunxi_usb_phy_exit(priv->phy_index);
73
74 #ifdef CONFIG_SUNXI_GEN_SUN6I
75         clrbits_le32(&ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
76 #endif
77         clrbits_le32(&ccm->usb_clk_cfg, priv->usb_gate_mask);
78         clrbits_le32(&ccm->ahb_gate0, priv->ahb_gate_mask);
79
80         return 0;
81 }
82
83 static const struct udevice_id ohci_usb_ids[] = {
84         { .compatible = "allwinner,sun4i-a10-ohci", },
85         { .compatible = "allwinner,sun5i-a13-ohci", },
86         { .compatible = "allwinner,sun6i-a31-ohci", },
87         { .compatible = "allwinner,sun7i-a20-ohci", },
88         { .compatible = "allwinner,sun8i-a23-ohci", },
89         { .compatible = "allwinner,sun9i-a80-ohci", },
90         { }
91 };
92
93 U_BOOT_DRIVER(usb_ohci) = {
94         .name   = "ohci_sunxi",
95         .id     = UCLASS_USB,
96         .of_match = ohci_usb_ids,
97         .probe = ohci_usb_probe,
98         .remove = ohci_usb_remove,
99         .ops    = &ohci_usb_ops,
100         .platdata_auto_alloc_size = sizeof(struct usb_platdata),
101         .priv_auto_alloc_size = sizeof(struct ohci_sunxi_priv),
102         .flags  = DM_FLAG_ALLOC_PRIV_DMA,
103 };