blob: b44e7df11319db4ad8df3108349e071addf97210 [file] [log] [blame]
Vignesh Raghavendra7e91f6c2019-10-01 17:26:33 +05301// 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#include <dm.h>
Simon Glass61b29b82020-02-03 07:36:15 -070012#include <dm/devres.h>
Vignesh Raghavendra7e91f6c2019-10-01 17:26:33 +053013#include <linux/compat.h>
14#include <usb.h>
Vignesh Raghavendrae5521b12019-11-18 19:16:33 +053015#include <usb/xhci.h>
Vignesh Raghavendra7e91f6c2019-10-01 17:26:33 +053016
17#include "core.h"
18#include "drd.h"
19
20static int __cdns3_host_init(struct cdns3 *cdns)
21{
22 struct xhci_hcor *hcor;
23 struct xhci_hccr *hccr;
24
25 cdns3_drd_switch_host(cdns, 1);
26
27 hccr = (struct xhci_hccr *)cdns->xhci_regs;
28 hcor = (struct xhci_hcor *)(cdns->xhci_regs +
29 HC_LENGTH(xhci_readl(&(hccr)->cr_capbase)));
30
31 return xhci_register(cdns->dev, hccr, hcor);
32}
33
34static void cdns3_host_exit(struct cdns3 *cdns)
35{
36 xhci_deregister(cdns->dev);
37 cdns3_drd_switch_host(cdns, 0);
38}
39
40int cdns3_host_init(struct cdns3 *cdns)
41{
42 struct cdns3_role_driver *rdrv;
43
44 rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL);
45 if (!rdrv)
46 return -ENOMEM;
47
48 rdrv->start = __cdns3_host_init;
49 rdrv->stop = cdns3_host_exit;
50 rdrv->state = CDNS3_ROLE_STATE_INACTIVE;
51 rdrv->name = "host";
52
53 cdns->roles[USB_ROLE_HOST] = rdrv;
54
55 return 0;
56}