blob: f21a1fa773b3ac01934a216b709dc107041d6f6f [file] [log] [blame]
Michael Trimarchiebc83002008-12-31 10:32:41 +01001/*-
2 * Copyright (c) 2007-2008, Juniper Networks, Inc.
3 * All rights reserved.
4 *
Simon Glass1b2e3652015-07-06 16:47:42 -06005 * SPDX-License-Identifier: GPL-2.0
Michael Trimarchiebc83002008-12-31 10:32:41 +01006 */
7
8#include <common.h>
Simon Glassd0065dd2015-07-06 16:47:53 -06009#include <dm.h>
Vincent Palatin8d452892012-12-13 22:58:27 -080010#include <errno.h>
Michael Trimarchiebc83002008-12-31 10:32:41 +010011#include <pci.h>
12#include <usb.h>
Jean-Christophe PLAGNIOL-VILLARD8f6bcf42009-04-03 12:46:58 +020013
14#include "ehci.h"
Michael Trimarchiebc83002008-12-31 10:32:41 +010015
Simon Glassd0065dd2015-07-06 16:47:53 -060016/* Information about a USB port */
17struct ehci_pci_priv {
18 struct ehci_ctrl ehci;
19};
20
Simon Glass261095b2015-11-29 13:18:07 -070021#ifdef CONFIG_DM_USB
22
23static void ehci_pci_init(struct udevice *dev, struct ehci_hccr **ret_hccr,
24 struct ehci_hcor **ret_hcor)
Simon Glassd0065dd2015-07-06 16:47:53 -060025{
26 struct ehci_hccr *hccr;
27 struct ehci_hcor *hcor;
Simon Glass261095b2015-11-29 13:18:07 -070028 u32 cmd;
Simon Glassd0065dd2015-07-06 16:47:53 -060029
Simon Glass261095b2015-11-29 13:18:07 -070030 hccr = (struct ehci_hccr *)dm_pci_map_bar(dev,
Simon Glassd0065dd2015-07-06 16:47:53 -060031 PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
Simon Glass261095b2015-11-29 13:18:07 -070032 hcor = (struct ehci_hcor *)((uintptr_t) hccr +
Simon Glassd0065dd2015-07-06 16:47:53 -060033 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
34
35 debug("EHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n",
Simon Glass261095b2015-11-29 13:18:07 -070036 (u32)hccr, (u32)hcor,
37 (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
Simon Glassd0065dd2015-07-06 16:47:53 -060038
39 *ret_hccr = hccr;
40 *ret_hcor = hcor;
41
42 /* enable busmaster */
Simon Glass261095b2015-11-29 13:18:07 -070043 dm_pci_read_config32(dev, PCI_COMMAND, &cmd);
Simon Glassd0065dd2015-07-06 16:47:53 -060044 cmd |= PCI_COMMAND_MASTER;
Simon Glass261095b2015-11-29 13:18:07 -070045 dm_pci_write_config32(dev, PCI_COMMAND, cmd);
Simon Glassd0065dd2015-07-06 16:47:53 -060046}
47
Simon Glass261095b2015-11-29 13:18:07 -070048#else
Simon Glassd0065dd2015-07-06 16:47:53 -060049
Michael Trimarchiebc83002008-12-31 10:32:41 +010050#ifdef CONFIG_PCI_EHCI_DEVICE
51static struct pci_device_id ehci_pci_ids[] = {
52 /* Please add supported PCI EHCI controller ids here */
Trübenbach, Ralfd2c91882011-03-31 16:46:47 +000053 {0x1033, 0x00E0}, /* NEC */
Wolfgang Denke9366282011-04-05 12:24:20 +020054 {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */
Trübenbach, Ralfd2c91882011-03-31 16:46:47 +000055 {0x12D8, 0x400F}, /* Pericom */
Michael Trimarchiebc83002008-12-31 10:32:41 +010056 {0, 0}
57};
58#endif
59
Simon Glass261095b2015-11-29 13:18:07 -070060static void ehci_pci_legacy_init(pci_dev_t pdev, struct ehci_hccr **ret_hccr,
61 struct ehci_hcor **ret_hcor)
62{
63 struct ehci_hccr *hccr;
64 struct ehci_hcor *hcor;
65 u32 cmd;
66
67 hccr = (struct ehci_hccr *)pci_map_bar(pdev,
68 PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
69 hcor = (struct ehci_hcor *)((uintptr_t) hccr +
70 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
71
72 debug("EHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n",
73 (u32)hccr, (u32)hcor,
74 (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
75
76 *ret_hccr = hccr;
77 *ret_hcor = hcor;
78
79 /* enable busmaster */
80 pci_read_config_dword(pdev, PCI_COMMAND, &cmd);
81 cmd |= PCI_COMMAND_MASTER;
82 pci_write_config_dword(pdev, PCI_COMMAND, cmd);
83}
84
Michael Trimarchiebc83002008-12-31 10:32:41 +010085/*
86 * Create the appropriate control structures to manage
87 * a new EHCI host controller.
88 */
Troy Kisky7d6bbb92013-10-10 15:27:57 -070089int ehci_hcd_init(int index, enum usb_init_type init,
90 struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor)
Michael Trimarchiebc83002008-12-31 10:32:41 +010091{
92 pci_dev_t pdev;
Michael Trimarchiebc83002008-12-31 10:32:41 +010093
Vincent Palatin8d452892012-12-13 22:58:27 -080094#ifdef CONFIG_PCI_EHCI_DEVICE
Michael Trimarchiebc83002008-12-31 10:32:41 +010095 pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE);
Vincent Palatin8d452892012-12-13 22:58:27 -080096#else
Simon Glasseeb1d282015-01-27 22:13:30 -070097 pdev = pci_find_class(PCI_CLASS_SERIAL_USB_EHCI, index);
Vincent Palatin8d452892012-12-13 22:58:27 -080098#endif
99 if (pdev < 0) {
Michael Trimarchiebc83002008-12-31 10:32:41 +0100100 printf("EHCI host controller not found\n");
101 return -1;
102 }
Simon Glass261095b2015-11-29 13:18:07 -0700103 ehci_pci_legacy_init(pdev, ret_hccr, ret_hcor);
Michael Trimarchiebc83002008-12-31 10:32:41 +0100104
Michael Trimarchiebc83002008-12-31 10:32:41 +0100105 return 0;
106}
107
108/*
109 * Destroy the appropriate control structures corresponding
110 * the the EHCI host controller.
111 */
Lucas Stach3494a4c2012-09-26 00:14:35 +0200112int ehci_hcd_stop(int index)
Michael Trimarchiebc83002008-12-31 10:32:41 +0100113{
Simon Glassd0065dd2015-07-06 16:47:53 -0600114 return 0;
115}
116#endif /* nCONFIG_DM_USB */
117
118#ifdef CONFIG_DM_USB
119static int ehci_pci_probe(struct udevice *dev)
120{
121 struct ehci_hccr *hccr;
122 struct ehci_hcor *hcor;
123
Simon Glass261095b2015-11-29 13:18:07 -0700124 ehci_pci_init(dev, &hccr, &hcor);
Simon Glassd0065dd2015-07-06 16:47:53 -0600125
126 return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
127}
128
129static int ehci_pci_remove(struct udevice *dev)
130{
131 int ret;
132
133 ret = ehci_deregister(dev);
134 if (ret)
135 return ret;
136
Michael Trimarchiebc83002008-12-31 10:32:41 +0100137 return 0;
138}
Simon Glassd0065dd2015-07-06 16:47:53 -0600139
Simon Glass9470c722016-01-17 16:11:07 -0700140static const struct udevice_id ehci_pci_ids[] = {
141 { .compatible = "ehci-pci" },
142 { }
143};
144
Simon Glassd0065dd2015-07-06 16:47:53 -0600145U_BOOT_DRIVER(ehci_pci) = {
146 .name = "ehci_pci",
147 .id = UCLASS_USB,
148 .probe = ehci_pci_probe,
149 .remove = ehci_pci_remove,
Simon Glass9470c722016-01-17 16:11:07 -0700150 .of_match = ehci_pci_ids,
Simon Glassd0065dd2015-07-06 16:47:53 -0600151 .ops = &ehci_usb_ops,
152 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
153 .priv_auto_alloc_size = sizeof(struct ehci_pci_priv),
154 .flags = DM_FLAG_ALLOC_PRIV_DMA,
155};
156
157static struct pci_device_id ehci_pci_supported[] = {
158 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0) },
159 {},
160};
161
162U_BOOT_PCI_DEVICE(ehci_pci, ehci_pci_supported);
163
164#endif /* CONFIG_DM_USB */