[U-Boot] [PATCH v2 2/4] usb: sunxi: ehci: get rid of ifdefs

Vasily Khoruzhick anarsoul at gmail.com
Thu Jun 7 02:30:09 UTC 2018


We can use compatibles instead.

Signed-off-by: Vasily Khoruzhick <anarsoul at gmail.com>
---
 drivers/usb/host/ehci-sunxi.c | 89 +++++++++++++++++++++++++++--------
 1 file changed, 69 insertions(+), 20 deletions(-)

diff --git a/drivers/usb/host/ehci-sunxi.c b/drivers/usb/host/ehci-sunxi.c
index 360efc9116..39b98c21ca 100644
--- a/drivers/usb/host/ehci-sunxi.c
+++ b/drivers/usb/host/ehci-sunxi.c
@@ -22,11 +22,24 @@
 #define AHB_CLK_DIST		1
 #endif
 
+enum ehci_sunxi_type {
+	sun4i_a10_ehci,
+	sun5i_a13_ehci,
+	sun6i_a31_ehci,
+	sun7i_a20_ehci,
+	sun8i_a23_ehci,
+	sun8i_a83t_ehci,
+	sun8i_h3_ehci,
+	sun9i_a80_ehci,
+	sun50i_a64_ehci,
+};
+
 struct ehci_sunxi_priv {
 	struct ehci_ctrl ehci;
 	struct sunxi_ccm_reg *ccm;
 	int ahb_gate_mask; /* Mask of ahb_gate0 clk gate bits for this hcd */
 	struct phy phy;
+	enum ehci_sunxi_type type;
 };
 
 static int ehci_usb_probe(struct udevice *dev)
@@ -38,6 +51,7 @@ static int ehci_usb_probe(struct udevice *dev)
 	int extra_ahb_gate_mask = 0;
 	int phys, ret;
 
+	priv->type = (enum ehci_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);
@@ -72,18 +86,22 @@ no_phy:
 	 * clocks resp. phys.
 	 */
 	priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
-#if defined(CONFIG_MACH_SUNXI_H3_H5) || defined(CONFIG_MACH_SUN50I)
-	extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI0;
-#endif
+	if (priv->type == sun8i_h3_ehci ||
+	    priv->type == sun50i_a64_ehci)
+		extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI0;
 	priv->ahb_gate_mask <<= phys * AHB_CLK_DIST;
 	extra_ahb_gate_mask <<= phys * AHB_CLK_DIST;
 
 	setbits_le32(&priv->ccm->ahb_gate0,
 		     priv->ahb_gate_mask | extra_ahb_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_ehci ||
+	    priv->type == sun8i_a23_ehci ||
+	    priv->type == sun8i_a83t_ehci ||
+	    priv->type == sun8i_h3_ehci ||
+	    priv->type == sun9i_a80_ehci ||
+	    priv->type == sun50i_a64_ehci)
+		setbits_le32(&priv->ccm->ahb_reset0_cfg,
+			     priv->ahb_gate_mask | extra_ahb_gate_mask);
 
 	hcor = (struct ehci_hcor *)((uintptr_t)hccr +
 				    HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
@@ -108,25 +126,56 @@ static int ehci_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_ehci ||
+	    priv->type == sun8i_a23_ehci ||
+	    priv->type == sun8i_a83t_ehci ||
+	    priv->type == sun8i_h3_ehci ||
+	    priv->type == sun9i_a80_ehci ||
+	    priv->type == sun50i_a64_ehci)
+		clrbits_le32(&priv->ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
 	clrbits_le32(&priv->ccm->ahb_gate0, priv->ahb_gate_mask);
 
 	return 0;
 }
 
 static const struct udevice_id ehci_usb_ids[] = {
-	{ .compatible = "allwinner,sun4i-a10-ehci", },
-	{ .compatible = "allwinner,sun5i-a13-ehci", },
-	{ .compatible = "allwinner,sun6i-a31-ehci", },
-	{ .compatible = "allwinner,sun7i-a20-ehci", },
-	{ .compatible = "allwinner,sun8i-a23-ehci", },
-	{ .compatible = "allwinner,sun8i-a83t-ehci", },
-	{ .compatible = "allwinner,sun8i-h3-ehci",  },
-	{ .compatible = "allwinner,sun9i-a80-ehci", },
-	{ .compatible = "allwinner,sun50i-a64-ehci", },
-	{ }
+	{
+		.compatible = "allwinner,sun4i-a10-ehci",
+		.data = (ulong)sun4i_a10_ehci,
+	},
+	{
+		.compatible = "allwinner,sun5i-a13-ehci",
+		.data = (ulong)sun5i_a13_ehci,
+	},
+	{
+		.compatible = "allwinner,sun6i-a31-ehci",
+		.data = (ulong)sun6i_a31_ehci,
+	},
+	{
+		.compatible = "allwinner,sun7i-a20-ehci",
+		.data = (ulong)sun7i_a20_ehci,
+	},
+	{
+		.compatible = "allwinner,sun8i-a23-ehci",
+		.data = (ulong)sun8i_a23_ehci,
+	},
+	{
+		.compatible = "allwinner,sun8i-a83t-ehci",
+		.data = (ulong)sun8i_a83t_ehci,
+	},
+	{
+		.compatible = "allwinner,sun8i-h3-ehci",
+		.data = (ulong)sun8i_h3_ehci,
+	},
+	{
+		.compatible = "allwinner,sun9i-a80-ehci",
+		.data = (ulong)sun9i_a80_ehci,
+	},
+	{
+		.compatible = "allwinner,sun50i-a64-ehci",
+		.data = (ulong)sun50i_a64_ehci,
+	},
+	{ /* sentinel */ }
 };
 
 U_BOOT_DRIVER(ehci_sunxi) = {
-- 
2.17.1



More information about the U-Boot mailing list