[U-Boot] [PATCH v2 3/4] usb: sunxi: ohci: get rid of ifdefs
Vasily Khoruzhick
anarsoul at gmail.com
Thu Jun 7 02:30:10 UTC 2018
We can use compatibles instead.
Signed-off-by: Vasily Khoruzhick <anarsoul at gmail.com>
---
drivers/usb/host/ohci-sunxi.c | 88 +++++++++++++++++++++++++++--------
1 file changed, 68 insertions(+), 20 deletions(-)
diff --git a/drivers/usb/host/ohci-sunxi.c b/drivers/usb/host/ohci-sunxi.c
index ce2b47a5c4..dfdd1e538d 100644
--- a/drivers/usb/host/ohci-sunxi.c
+++ b/drivers/usb/host/ohci-sunxi.c
@@ -22,12 +22,25 @@
#define AHB_CLK_DIST 1
#endif
+enum ohci_sunxi_type {
+ sun4i_a10_ohci,
+ sun5i_a13_ohci,
+ sun6i_a31_ohci,
+ sun7i_a20_ohci,
+ sun8i_a23_ohci,
+ sun8i_a83t_ohci,
+ sun8i_h3_ohci,
+ sun9i_a80_ohci,
+ sun50i_a64_ohci,
+};
+
struct ohci_sunxi_priv {
struct sunxi_ccm_reg *ccm;
ohci_t ohci;
int ahb_gate_mask; /* Mask of ahb_gate0 clk gate bits for this hcd */
int usb_gate_mask; /* Mask of usb_clk_cfg clk gate bits for this hcd */
struct phy phy;
+ enum ohci_sunxi_type type;
};
static int ohci_usb_probe(struct udevice *dev)
@@ -38,6 +51,7 @@ static int ohci_usb_probe(struct udevice *dev)
int extra_ahb_gate_mask = 0;
int phys, ret;
+ priv->type = (enum ohci_sunxi_type)dev_get_driver_data(dev);
priv->ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
if (IS_ERR(priv->ccm))
return PTR_ERR(priv->ccm);
@@ -74,9 +88,8 @@ no_phy:
* clocks resp. phys.
*/
priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI0;
-#ifdef CONFIG_MACH_SUN8I_H3
- extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
-#endif
+ if (priv->type == sun8i_h3_ohci)
+ extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
priv->usb_gate_mask = CCM_USB_CTRL_OHCI0_CLK;
priv->ahb_gate_mask <<= phys * AHB_CLK_DIST;
extra_ahb_gate_mask <<= phys * AHB_CLK_DIST;
@@ -85,10 +98,14 @@ no_phy:
setbits_le32(&priv->ccm->ahb_gate0,
priv->ahb_gate_mask | extra_ahb_gate_mask);
setbits_le32(&priv->ccm->usb_clk_cfg, priv->usb_gate_mask);
-#ifdef CONFIG_SUNXI_GEN_SUN6I
- setbits_le32(&priv->ccm->ahb_reset0_cfg,
- priv->ahb_gate_mask | extra_ahb_gate_mask);
-#endif
+ if (priv->type == sun6i_a31_ohci ||
+ priv->type == sun8i_a23_ohci ||
+ priv->type == sun8i_a83t_ohci ||
+ priv->type == sun8i_h3_ohci ||
+ priv->type == sun9i_a80_ohci ||
+ priv->type == sun50i_a64_ohci)
+ setbits_le32(&priv->ccm->ahb_reset0_cfg,
+ priv->ahb_gate_mask | extra_ahb_gate_mask);
return ohci_register(dev, regs);
}
@@ -110,9 +127,13 @@ static int ohci_usb_remove(struct udevice *dev)
if (ret)
return ret;
-#ifdef CONFIG_SUNXI_GEN_SUN6I
- clrbits_le32(&priv->ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
-#endif
+ if (priv->type == sun6i_a31_ohci ||
+ priv->type == sun8i_a23_ohci ||
+ priv->type == sun8i_a83t_ohci ||
+ priv->type == sun8i_h3_ohci ||
+ priv->type == sun9i_a80_ohci ||
+ priv->type == sun50i_a64_ohci)
+ clrbits_le32(&priv->ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
clrbits_le32(&priv->ccm->usb_clk_cfg, priv->usb_gate_mask);
clrbits_le32(&priv->ccm->ahb_gate0, priv->ahb_gate_mask);
@@ -120,16 +141,43 @@ static int ohci_usb_remove(struct udevice *dev)
}
static const struct udevice_id ohci_usb_ids[] = {
- { .compatible = "allwinner,sun4i-a10-ohci", },
- { .compatible = "allwinner,sun5i-a13-ohci", },
- { .compatible = "allwinner,sun6i-a31-ohci", },
- { .compatible = "allwinner,sun7i-a20-ohci", },
- { .compatible = "allwinner,sun8i-a23-ohci", },
- { .compatible = "allwinner,sun8i-a83t-ohci", },
- { .compatible = "allwinner,sun8i-h3-ohci", },
- { .compatible = "allwinner,sun9i-a80-ohci", },
- { .compatible = "allwinner,sun50i-a64-ohci", },
- { }
+ {
+ .compatible = "allwinner,sun4i-a10-ohci",
+ .data = (ulong)sun4i_a10_ohci,
+ },
+ {
+ .compatible = "allwinner,sun5i-a13-ohci",
+ .data = (ulong)sun5i_a13_ohci,
+ },
+ {
+ .compatible = "allwinner,sun6i-a31-ohci",
+ .data = (ulong)sun6i_a31_ohci,
+ },
+ {
+ .compatible = "allwinner,sun7i-a20-ohci",
+ .data = (ulong)sun7i_a20_ohci,
+ },
+ {
+ .compatible = "allwinner,sun8i-a23-ohci",
+ .data = (ulong)sun8i_a23_ohci,
+ },
+ {
+ .compatible = "allwinner,sun8i-a83t-ohci",
+ .data = (ulong)sun8i_a83t_ohci,
+ },
+ {
+ .compatible = "allwinner,sun8i-h3-ohci",
+ .data = (ulong)sun8i_h3_ohci,
+ },
+ {
+ .compatible = "allwinner,sun9i-a80-ohci",
+ .data = (ulong)sun9i_a80_ohci,
+ },
+ {
+ .compatible = "allwinner,sun50i-a64-ohci",
+ .data = (ulong)sun50i_a64_ohci,
+ },
+ { /* sentinel */ }
};
U_BOOT_DRIVER(usb_ohci) = {
--
2.17.1
More information about the U-Boot
mailing list