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