xref: /openbmc/linux/drivers/usb/cdns3/host.c (revision 20e2fc42)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Cadence USBSS DRD Driver - host side
4  *
5  * Copyright (C) 2018-2019 Cadence Design Systems.
6  * Copyright (C) 2017-2018 NXP
7  *
8  * Authors: Peter Chen <peter.chen@nxp.com>
9  *          Pawel Laszczak <pawell@cadence.com>
10  */
11 
12 #include <linux/platform_device.h>
13 #include "core.h"
14 #include "drd.h"
15 
16 static int __cdns3_host_init(struct cdns3 *cdns)
17 {
18 	struct platform_device *xhci;
19 	int ret;
20 
21 	cdns3_drd_switch_host(cdns, 1);
22 
23 	xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
24 	if (!xhci) {
25 		dev_err(cdns->dev, "couldn't allocate xHCI device\n");
26 		return -ENOMEM;
27 	}
28 
29 	xhci->dev.parent = cdns->dev;
30 	cdns->host_dev = xhci;
31 
32 	ret = platform_device_add_resources(xhci, cdns->xhci_res,
33 					    CDNS3_XHCI_RESOURCES_NUM);
34 	if (ret) {
35 		dev_err(cdns->dev, "couldn't add resources to xHCI device\n");
36 		goto err1;
37 	}
38 
39 	ret = platform_device_add(xhci);
40 	if (ret) {
41 		dev_err(cdns->dev, "failed to register xHCI device\n");
42 		goto err1;
43 	}
44 
45 	return 0;
46 err1:
47 	platform_device_put(xhci);
48 	return ret;
49 }
50 
51 static void cdns3_host_exit(struct cdns3 *cdns)
52 {
53 	platform_device_unregister(cdns->host_dev);
54 	cdns->host_dev = NULL;
55 	cdns3_drd_switch_host(cdns, 0);
56 }
57 
58 int cdns3_host_init(struct cdns3 *cdns)
59 {
60 	struct cdns3_role_driver *rdrv;
61 
62 	rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL);
63 	if (!rdrv)
64 		return -ENOMEM;
65 
66 	rdrv->start	= __cdns3_host_init;
67 	rdrv->stop	= cdns3_host_exit;
68 	rdrv->state	= CDNS3_ROLE_STATE_INACTIVE;
69 	rdrv->name	= "host";
70 
71 	cdns->roles[USB_ROLE_HOST] = rdrv;
72 
73 	return 0;
74 }
75