From: Dinh Nguyen <dingu...@altera.com>

gadget_init() will get called from the platform probe function.

Signed-off-by: Dinh Nguyen <dingu...@altera.com>
---
 drivers/usb/dwc2/gadget.c |  144 +++++++++++++++++----------------------------
 1 file changed, 55 insertions(+), 89 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 171ed28..e74656c 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3372,25 +3372,24 @@ static void s3c_hsotg_delete_debug(struct dwc2_hsotg 
*dwc2)
 }
 
 /**
- * s3c_hsotg_probe - probe function for hsotg driver
- * @pdev: The platform information for the driver
+ * dwc2_gadget_init - init function for gadget
+ * @dwc2: The data structure for the DWC2 driver.
+ * @irq: The IRQ number for the controller.
  */
 
-static int s3c_hsotg_probe(struct platform_device *pdev)
+static int dwc2_gadget_init(struct dwc2_hsotg *dwc2, int irq)
 {
-       struct s3c_hsotg_plat *plat = dev_get_platdata(&pdev->dev);
+       struct s3c_hsotg_plat *plat = dwc2->dev->platform_data;
        struct phy *phy;
        struct usb_phy *uphy;
-       struct device *dev = &pdev->dev;
+       struct device *dev = dwc2->dev;
        struct s3c_hsotg_ep *eps;
-       struct s3c_hsotg *hsotg;
-       struct resource *res;
        int epnum;
        int ret;
        int i;
 
-       hsotg = devm_kzalloc(&pdev->dev, sizeof(struct s3c_hsotg), GFP_KERNEL);
-       if (!hsotg) {
+       dwc2->s3c_hsotg = devm_kzalloc(dev, sizeof(struct s3c_hsotg), 
GFP_KERNEL);
+       if (!dwc2->s3c_hsotg) {
                dev_err(dev, "cannot get memory\n");
                return -ENOMEM;
        }
@@ -3399,117 +3398,84 @@ static int s3c_hsotg_probe(struct platform_device 
*pdev)
         * Attempt to find a generic PHY, then look for an old style
         * USB PHY, finally fall back to pdata
         */
-       phy = devm_phy_get(&pdev->dev, "usb2-phy");
+       phy = devm_phy_get(dev, "usb2-phy");
        if (IS_ERR(phy)) {
                uphy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
                if (IS_ERR(uphy)) {
                        /* Fallback for pdata */
-                       plat = dev_get_platdata(&pdev->dev);
+                       plat = dev_get_platdata(dev);
                        if (!plat) {
-                               dev_err(&pdev->dev,
+                               dev_err(dev,
                                "no platform data or transceiver defined\n");
                                return -EPROBE_DEFER;
                        }
-                       hsotg->plat = plat;
+                       dwc2->s3c_hsotg->plat = plat;
                } else
-                       hsotg->uphy = uphy;
+                       dwc2->s3c_hsotg->uphy = uphy;
        } else
-               hsotg->phy = phy;
+               dwc2->s3c_hsotg->phy = phy;
 
-       hsotg->dev = dev;
-
-       hsotg->clk = devm_clk_get(&pdev->dev, "otg");
-       if (IS_ERR(hsotg->clk)) {
+       dwc2->s3c_hsotg->clk = devm_clk_get(dev, "otg");
+       if (IS_ERR(dwc2->s3c_hsotg->clk)) {
                dev_err(dev, "cannot get otg clock\n");
-               return PTR_ERR(hsotg->clk);
-       }
-
-       platform_set_drvdata(pdev, hsotg);
-
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-
-       hsotg->regs = devm_ioremap_resource(&pdev->dev, res);
-       if (IS_ERR(hsotg->regs)) {
-               ret = PTR_ERR(hsotg->regs);
-               goto err_clk;
-       }
-
-       ret = platform_get_irq(pdev, 0);
-       if (ret < 0) {
-               dev_err(dev, "cannot find IRQ\n");
-               goto err_clk;
-       }
-
-       spin_lock_init(&hsotg->lock);
-
-       hsotg->irq = ret;
-
-       ret = devm_request_irq(&pdev->dev, hsotg->irq, s3c_hsotg_irq, 0,
-                               dev_name(dev), hsotg);
-       if (ret < 0) {
-               dev_err(dev, "cannot claim IRQ\n");
-               goto err_clk;
+               return PTR_ERR(dwc2->s3c_hsotg->clk);
        }
 
-       dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq);
-
-       hsotg->gadget.max_speed = USB_SPEED_HIGH;
-       hsotg->gadget.ops = &s3c_hsotg_gadget_ops;
-       hsotg->gadget.name = dev_name(dev);
+       dwc2->gadget.max_speed = USB_SPEED_HIGH;
+       dwc2->gadget.ops = &s3c_hsotg_gadget_ops;
+       dwc2->gadget.name = dev_name(dev);
 
-       /* reset the system */
-
-       clk_prepare_enable(hsotg->clk);
+       clk_prepare_enable(dwc2->s3c_hsotg->clk);
 
        /* regulators */
 
-       for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++)
-               hsotg->supplies[i].supply = s3c_hsotg_supply_names[i];
+       for (i = 0; i < ARRAY_SIZE(dwc2->s3c_hsotg->supplies); i++)
+               dwc2->s3c_hsotg->supplies[i].supply = s3c_hsotg_supply_names[i];
 
-       ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(hsotg->supplies),
-                                hsotg->supplies);
+       ret = devm_regulator_bulk_get(dev, 
ARRAY_SIZE(dwc2->s3c_hsotg->supplies),
+                                dwc2->s3c_hsotg->supplies);
        if (ret) {
                dev_err(dev, "failed to request supplies: %d\n", ret);
                goto err_clk;
        }
 
-       ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
-                                   hsotg->supplies);
+       ret = regulator_bulk_enable(ARRAY_SIZE(dwc2->s3c_hsotg->supplies),
+                                   dwc2->s3c_hsotg->supplies);
 
        if (ret) {
-               dev_err(hsotg->dev, "failed to enable supplies: %d\n", ret);
+               dev_err(dev, "failed to enable supplies: %d\n", ret);
                goto err_supplies;
        }
 
        /* Set default UTMI width */
-       hsotg->phyif = GUSBCFG_PHYIF16;
+       dwc2->s3c_hsotg->phyif = GUSBCFG_PHYIF16;
 
        /*
         * If using the generic PHY framework, check if the PHY bus
         * width is 8-bit and set the phyif appropriately.
         */
-       if (hsotg->phy && (phy_get_bus_width(phy) == 8))
-               hsotg->phyif = GUSBCFG_PHYIF8;
+       if (dwc2->s3c_hsotg->phy && (phy_get_bus_width(phy) == 8))
+               dwc2->s3c_hsotg->phyif = GUSBCFG_PHYIF8;
 
-       if (hsotg->phy)
-               phy_init(hsotg->phy);
+       if (dwc2->s3c_hsotg->phy)
+               phy_init(dwc2->s3c_hsotg->phy);
 
        /* usb phy enable */
-       s3c_hsotg_phy_enable(hsotg);
+       s3c_hsotg_phy_enable(dwc2);
 
-       s3c_hsotg_corereset(hsotg);
-       s3c_hsotg_init(hsotg);
-       s3c_hsotg_hw_cfg(hsotg);
+       s3c_hsotg_corereset(dwc2);
+       s3c_hsotg_init(dwc2);
+       s3c_hsotg_hw_cfg(dwc2);
 
        /* hsotg->num_of_eps holds number of EPs other than ep0 */
 
-       if (hsotg->num_of_eps == 0) {
+       if (dwc2->s3c_hsotg->num_of_eps == 0) {
                dev_err(dev, "wrong number of EPs (zero)\n");
                ret = -EINVAL;
                goto err_supplies;
        }
 
-       eps = kcalloc(hsotg->num_of_eps + 1, sizeof(struct s3c_hsotg_ep),
+       eps = kcalloc(dwc2->s3c_hsotg->num_of_eps + 1, sizeof(struct 
s3c_hsotg_ep),
                      GFP_KERNEL);
        if (!eps) {
                dev_err(dev, "cannot get memory\n");
@@ -3517,54 +3483,54 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
                goto err_supplies;
        }
 
-       hsotg->eps = eps;
+       dwc2->eps = eps;
 
        /* setup endpoint information */
 
-       INIT_LIST_HEAD(&hsotg->gadget.ep_list);
-       hsotg->gadget.ep0 = &hsotg->eps[0].ep;
+       INIT_LIST_HEAD(&dwc2->gadget.ep_list);
+       dwc2->gadget.ep0 = &dwc2->eps[0].ep;
 
        /* allocate EP0 request */
 
-       hsotg->ctrl_req = s3c_hsotg_ep_alloc_request(&hsotg->eps[0].ep,
+       dwc2->s3c_hsotg->ctrl_req = s3c_hsotg_ep_alloc_request(&dwc2->eps[0].ep,
                                                     GFP_KERNEL);
-       if (!hsotg->ctrl_req) {
+       if (!dwc2->s3c_hsotg->ctrl_req) {
                dev_err(dev, "failed to allocate ctrl req\n");
                ret = -ENOMEM;
                goto err_ep_mem;
        }
 
        /* initialise the endpoints now the core has been initialised */
-       for (epnum = 0; epnum < hsotg->num_of_eps; epnum++)
-               s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum);
+       for (epnum = 0; epnum < dwc2->s3c_hsotg->num_of_eps; epnum++)
+               s3c_hsotg_initep(dwc2, &dwc2->eps[epnum], epnum);
 
        /* disable power and clock */
 
-       ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
-                                   hsotg->supplies);
+       ret = regulator_bulk_disable(ARRAY_SIZE(dwc2->s3c_hsotg->supplies),
+                                   dwc2->s3c_hsotg->supplies);
        if (ret) {
-               dev_err(hsotg->dev, "failed to disable supplies: %d\n", ret);
+               dev_err(dev, "failed to disable supplies: %d\n", ret);
                goto err_ep_mem;
        }
 
-       s3c_hsotg_phy_disable(hsotg);
+       s3c_hsotg_phy_disable(dwc2);
 
-       ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget);
+       ret = usb_add_gadget_udc(dev, &dwc2->gadget);
        if (ret)
                goto err_ep_mem;
 
-       s3c_hsotg_create_debug(hsotg);
+       s3c_hsotg_create_debug(dwc2);
 
-       s3c_hsotg_dump(hsotg);
+       s3c_hsotg_dump(dwc2);
 
        return 0;
 
 err_ep_mem:
        kfree(eps);
 err_supplies:
-       s3c_hsotg_phy_disable(hsotg);
+       s3c_hsotg_phy_disable(dwc2);
 err_clk:
-       clk_disable_unprepare(hsotg->clk);
+       clk_disable_unprepare(dwc2->s3c_hsotg->clk);
 
        return ret;
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to