Move struct sunxi_ccm_reg pointer to private structure
so-that accessing ccm reg base become more proper way
and avoid local initialization in each function.

Signed-off-by: Jagan Teki <ja...@amarulasolutions.com>
---
 drivers/usb/host/ehci-sunxi.c | 15 +++++++++------
 drivers/usb/host/ohci-sunxi.c | 19 +++++++++++--------
 drivers/usb/musb-new/sunxi.c  | 34 +++++++++++++++++++++++-----------
 3 files changed, 43 insertions(+), 25 deletions(-)

diff --git a/drivers/usb/host/ehci-sunxi.c b/drivers/usb/host/ehci-sunxi.c
index 6ecb7c4..ed9763c 100644
--- a/drivers/usb/host/ehci-sunxi.c
+++ b/drivers/usb/host/ehci-sunxi.c
@@ -27,19 +27,23 @@
 
 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 */
        int phy_index;     /* Index of the usb-phy attached to this hcd */
 };
 
 static int ehci_usb_probe(struct udevice *dev)
 {
-       struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
        struct usb_platdata *plat = dev_get_platdata(dev);
        struct ehci_sunxi_priv *priv = dev_get_priv(dev);
        struct ehci_hccr *hccr = (struct ehci_hccr *)devfdt_get_addr(dev);
        struct ehci_hcor *hcor;
        int extra_ahb_gate_mask = 0;
 
+       priv->ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
+       if (IS_ERR(priv->ccm))
+               return PTR_ERR(priv->ccm);
+
        /*
         * This should go away once we've moved to the driver model for
         * clocks resp. phys.
@@ -53,10 +57,10 @@ static int ehci_usb_probe(struct udevice *dev)
        extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
        priv->phy_index++; /* Non otg phys start at 1 */
 
-       setbits_le32(&ccm->ahb_gate0,
+       setbits_le32(&priv->ccm->ahb_gate0,
                     priv->ahb_gate_mask | extra_ahb_gate_mask);
 #ifdef CONFIG_SUNXI_GEN_SUN6I
-       setbits_le32(&ccm->ahb_reset0_cfg,
+       setbits_le32(&priv->ccm->ahb_reset0_cfg,
                     priv->ahb_gate_mask | extra_ahb_gate_mask);
 #endif
 
@@ -71,7 +75,6 @@ static int ehci_usb_probe(struct udevice *dev)
 
 static int ehci_usb_remove(struct udevice *dev)
 {
-       struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
        struct ehci_sunxi_priv *priv = dev_get_priv(dev);
        int ret;
 
@@ -82,9 +85,9 @@ static int ehci_usb_remove(struct udevice *dev)
        sunxi_usb_phy_exit(priv->phy_index);
 
 #ifdef CONFIG_SUNXI_GEN_SUN6I
-       clrbits_le32(&ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
+       clrbits_le32(&priv->ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
 #endif
-       clrbits_le32(&ccm->ahb_gate0, priv->ahb_gate_mask);
+       clrbits_le32(&priv->ccm->ahb_gate0, priv->ahb_gate_mask);
 
        return 0;
 }
diff --git a/drivers/usb/host/ohci-sunxi.c b/drivers/usb/host/ohci-sunxi.c
index 133774f..35efa88 100644
--- a/drivers/usb/host/ohci-sunxi.c
+++ b/drivers/usb/host/ohci-sunxi.c
@@ -26,6 +26,7 @@
 #endif
 
 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 */
@@ -34,12 +35,15 @@ struct ohci_sunxi_priv {
 
 static int ohci_usb_probe(struct udevice *dev)
 {
-       struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
        struct usb_bus_priv *bus_priv = dev_get_uclass_priv(dev);
        struct ohci_sunxi_priv *priv = dev_get_priv(dev);
        struct ohci_regs *regs = (struct ohci_regs *)devfdt_get_addr(dev);
        int extra_ahb_gate_mask = 0;
 
+       priv->ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
+       if (IS_ERR(priv->ccm))
+               return PTR_ERR(priv->ccm);
+
        bus_priv->companion = true;
 
        /*
@@ -57,11 +61,11 @@ static int ohci_usb_probe(struct udevice *dev)
        priv->usb_gate_mask <<= priv->phy_index;
        priv->phy_index++; /* Non otg phys start at 1 */
 
-       setbits_le32(&ccm->ahb_gate0,
+       setbits_le32(&priv->ccm->ahb_gate0,
                     priv->ahb_gate_mask | extra_ahb_gate_mask);
-       setbits_le32(&ccm->usb_clk_cfg, priv->usb_gate_mask);
+       setbits_le32(&priv->ccm->usb_clk_cfg, priv->usb_gate_mask);
 #ifdef CONFIG_SUNXI_GEN_SUN6I
-       setbits_le32(&ccm->ahb_reset0_cfg,
+       setbits_le32(&priv->ccm->ahb_reset0_cfg,
                     priv->ahb_gate_mask | extra_ahb_gate_mask);
 #endif
 
@@ -73,7 +77,6 @@ static int ohci_usb_probe(struct udevice *dev)
 
 static int ohci_usb_remove(struct udevice *dev)
 {
-       struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
        struct ohci_sunxi_priv *priv = dev_get_priv(dev);
        int ret;
 
@@ -84,10 +87,10 @@ static int ohci_usb_remove(struct udevice *dev)
        sunxi_usb_phy_exit(priv->phy_index);
 
 #ifdef CONFIG_SUNXI_GEN_SUN6I
-       clrbits_le32(&ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
+       clrbits_le32(&priv->ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
 #endif
-       clrbits_le32(&ccm->usb_clk_cfg, priv->usb_gate_mask);
-       clrbits_le32(&ccm->ahb_gate0, 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);
 
        return 0;
 }
diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c
index aedc24b..c77bde0 100644
--- a/drivers/usb/musb-new/sunxi.c
+++ b/drivers/usb/musb-new/sunxi.c
@@ -76,6 +76,13 @@
  * From usbc/usbc.c
  
******************************************************************************/
 
+struct sunxi_glue {
+       struct musb_host_data mdata;
+       struct sunxi_ccm_reg *ccm;
+       struct device dev;
+};
+#define to_sunxi_glue(d)       container_of(d, struct sunxi_glue, dev)
+
 static u32 USBC_WakeUp_ClearChangeDetect(u32 reg_val)
 {
        u32 temp = reg_val;
@@ -256,15 +263,15 @@ static void sunxi_musb_disable(struct musb *musb)
 
 static int sunxi_musb_init(struct musb *musb)
 {
-       struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
+       struct sunxi_glue *glue = to_sunxi_glue(musb->controller);
 
        pr_debug("%s():\n", __func__);
 
        musb->isr = sunxi_musb_interrupt;
 
-       setbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_USB0);
+       setbits_le32(&glue->ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_USB0);
 #ifdef CONFIG_SUNXI_GEN_SUN6I
-       setbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_GATE_OFFSET_USB0);
+       setbits_le32(&glue->ccm->ahb_reset0_cfg, 1 << AHB_GATE_OFFSET_USB0);
 #endif
        sunxi_usb_phy_init(0);
 
@@ -310,7 +317,8 @@ static struct musb_hdrc_platform_data musb_plat = {
 
 static int musb_usb_probe(struct udevice *dev)
 {
-       struct musb_host_data *host = dev_get_priv(dev);
+       struct sunxi_glue *glue = dev_get_priv(dev);
+       struct musb_host_data *host = &glue->mdata;
        struct usb_bus_priv *priv = dev_get_uclass_priv(dev);
        void *base = dev_read_addr_ptr(dev);
        int ret;
@@ -318,10 +326,14 @@ static int musb_usb_probe(struct udevice *dev)
        if (!base)
                return -EINVAL;
 
+       glue->ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
+       if (IS_ERR(glue->ccm))
+               return PTR_ERR(glue->ccm);
+
        priv->desc_before_addr = true;
 
 #ifdef CONFIG_USB_MUSB_HOST
-       host->host = musb_init_controller(&musb_plat, NULL, base);
+       host->host = musb_init_controller(&musb_plat, &glue->dev, base);
        if (!host->host)
                return -EIO;
 
@@ -329,7 +341,7 @@ static int musb_usb_probe(struct udevice *dev)
        if (!ret)
                printf("Allwinner mUSB OTG (Host)\n");
 #else
-       ret = musb_register(&musb_plat, NULL, base);
+       ret = musb_register(&musb_plat, &glue->dev, base);
        if (!ret)
                printf("Allwinner mUSB OTG (Peripheral)\n");
 #endif
@@ -339,16 +351,16 @@ static int musb_usb_probe(struct udevice *dev)
 
 static int musb_usb_remove(struct udevice *dev)
 {
-       struct musb_host_data *host = dev_get_priv(dev);
-       struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
+       struct sunxi_glue *glue = dev_get_priv(dev);
+       struct musb_host_data *host = &glue->mdata;
 
        musb_stop(host->host);
 
        sunxi_usb_phy_exit(0);
 #ifdef CONFIG_SUNXI_GEN_SUN6I
-       clrbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_GATE_OFFSET_USB0);
+       clrbits_le32(&glue->ccm->ahb_reset0_cfg, 1 << AHB_GATE_OFFSET_USB0);
 #endif
-       clrbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_USB0);
+       clrbits_le32(&glue->ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_USB0);
 
        free(host->host);
        host->host = NULL;
@@ -378,5 +390,5 @@ U_BOOT_DRIVER(usb_musb) = {
        .ops            = &musb_usb_ops,
 #endif
        .platdata_auto_alloc_size = sizeof(struct usb_platdata),
-       .priv_auto_alloc_size = sizeof(struct musb_host_data),
+       .priv_auto_alloc_size = sizeof(struct sunxi_glue),
 };
-- 
2.7.4

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to