static int mtu3_remove(struct platform_device *pdev) { struct ssusb_mtk *ssusb = platform_get_drvdata(pdev); switch (ssusb->dr_mode) { case USB_DR_MODE_PERIPHERAL: ssusb_gadget_exit(ssusb); break; case USB_DR_MODE_HOST: ssusb_host_exit(ssusb); break; case USB_DR_MODE_OTG: ssusb_otg_switch_exit(ssusb); ssusb_gadget_exit(ssusb); ssusb_host_exit(ssusb); break; default: return -EINVAL; } ssusb_rscs_exit(ssusb); pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); return 0; }
static int mtu3_probe(struct platform_device *pdev) { struct device_node *node = pdev->dev.of_node; struct device *dev = &pdev->dev; struct ssusb_mtk *ssusb; int ret = -ENOMEM; /* all elements are set to ZERO as default value */ ssusb = devm_kzalloc(dev, sizeof(*ssusb), GFP_KERNEL); if (!ssusb) return -ENOMEM; ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); if (ret) { dev_err(dev, "No suitable DMA config available\n"); return -ENOTSUPP; } platform_set_drvdata(pdev, ssusb); ssusb->dev = dev; ret = get_ssusb_rscs(pdev, ssusb); if (ret) return ret; ssusb_debugfs_create_root(ssusb); /* enable power domain */ pm_runtime_enable(dev); pm_runtime_get_sync(dev); device_enable_async_suspend(dev); ret = ssusb_rscs_init(ssusb); if (ret) goto comm_init_err; ssusb_ip_sw_reset(ssusb); if (IS_ENABLED(CONFIG_USB_MTU3_HOST)) ssusb->dr_mode = USB_DR_MODE_HOST; else if (IS_ENABLED(CONFIG_USB_MTU3_GADGET)) ssusb->dr_mode = USB_DR_MODE_PERIPHERAL; /* default as host */ ssusb->is_host = !(ssusb->dr_mode == USB_DR_MODE_PERIPHERAL); switch (ssusb->dr_mode) { case USB_DR_MODE_PERIPHERAL: ret = ssusb_gadget_init(ssusb); if (ret) { dev_err(dev, "failed to initialize gadget\n"); goto comm_exit; } break; case USB_DR_MODE_HOST: ret = ssusb_host_init(ssusb, node); if (ret) { dev_err(dev, "failed to initialize host\n"); goto comm_exit; } break; case USB_DR_MODE_OTG: ret = ssusb_gadget_init(ssusb); if (ret) { dev_err(dev, "failed to initialize gadget\n"); goto comm_exit; } ret = ssusb_host_init(ssusb, node); if (ret) { dev_err(dev, "failed to initialize host\n"); goto gadget_exit; } ret = ssusb_otg_switch_init(ssusb); if (ret) { dev_err(dev, "failed to initialize switch\n"); goto host_exit; } break; default: dev_err(dev, "unsupported mode: %d\n", ssusb->dr_mode); ret = -EINVAL; goto comm_exit; } return 0; host_exit: ssusb_host_exit(ssusb); gadget_exit: ssusb_gadget_exit(ssusb); comm_exit: ssusb_rscs_exit(ssusb); comm_init_err: pm_runtime_put_sync(dev); pm_runtime_disable(dev); ssusb_debugfs_remove_root(ssusb); return ret; }