treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / usb / cdns3 / host.c
blobad788bf3fe4f6f8e9ac1865fd3d6c6ca518ba341
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Cadence USBSS DRD Driver - host side
5 * Copyright (C) 2018-2019 Cadence Design Systems.
6 * Copyright (C) 2017-2018 NXP
8 * Authors: Peter Chen <peter.chen@nxp.com>
9 * Pawel Laszczak <pawell@cadence.com>
12 #include <linux/platform_device.h>
13 #include "core.h"
14 #include "drd.h"
15 #include "host-export.h"
17 static int __cdns3_host_init(struct cdns3 *cdns)
19 struct platform_device *xhci;
20 int ret;
22 cdns3_drd_switch_host(cdns, 1);
24 xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
25 if (!xhci) {
26 dev_err(cdns->dev, "couldn't allocate xHCI device\n");
27 return -ENOMEM;
30 xhci->dev.parent = cdns->dev;
31 cdns->host_dev = xhci;
33 ret = platform_device_add_resources(xhci, cdns->xhci_res,
34 CDNS3_XHCI_RESOURCES_NUM);
35 if (ret) {
36 dev_err(cdns->dev, "couldn't add resources to xHCI device\n");
37 goto err1;
40 ret = platform_device_add(xhci);
41 if (ret) {
42 dev_err(cdns->dev, "failed to register xHCI device\n");
43 goto err1;
46 return 0;
47 err1:
48 platform_device_put(xhci);
49 return ret;
52 static void cdns3_host_exit(struct cdns3 *cdns)
54 platform_device_unregister(cdns->host_dev);
55 cdns->host_dev = NULL;
56 cdns3_drd_switch_host(cdns, 0);
59 int cdns3_host_init(struct cdns3 *cdns)
61 struct cdns3_role_driver *rdrv;
63 rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL);
64 if (!rdrv)
65 return -ENOMEM;
67 rdrv->start = __cdns3_host_init;
68 rdrv->stop = cdns3_host_exit;
69 rdrv->state = CDNS3_ROLE_STATE_INACTIVE;
70 rdrv->name = "host";
72 cdns->roles[USB_ROLE_HOST] = rdrv;
74 return 0;