blob: e98ab312618daac821c7dcf8485e251f27101d7f [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Michael Trimarchi8fea2912008-12-31 10:32:41 +01002/*-
3 * Copyright (c) 2007-2008, Juniper Networks, Inc.
4 * All rights reserved.
Michael Trimarchi8fea2912008-12-31 10:32:41 +01005 */
6
7#include <common.h>
Simon Glass2b53b072015-07-06 16:47:53 -06008#include <dm.h>
Vincent Palatin7c38e902012-12-13 22:58:27 -08009#include <errno.h>
Simon Glass691d7192020-05-10 11:40:02 -060010#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Michael Trimarchi8fea2912008-12-31 10:32:41 +010012#include <pci.h>
13#include <usb.h>
Alexey Brodkin2cb7b902017-06-05 10:19:26 +030014#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARD2731b9a2009-04-03 12:46:58 +020015
16#include "ehci.h"
Michael Trimarchi8fea2912008-12-31 10:32:41 +010017
Simon Glass2b53b072015-07-06 16:47:53 -060018/* Information about a USB port */
19struct ehci_pci_priv {
20 struct ehci_ctrl ehci;
Marek Vasut1335e772018-08-07 12:27:10 +020021 struct phy phy;
Simon Glass2b53b072015-07-06 16:47:53 -060022};
23
Sven Schwermerfd09c202018-11-21 08:43:56 +010024#if CONFIG_IS_ENABLED(DM_USB)
Marek Vasut1335e772018-08-07 12:27:10 +020025static int ehci_pci_init(struct udevice *dev, struct ehci_hccr **ret_hccr,
Simon Glass09c5c162015-11-29 13:18:07 -070026 struct ehci_hcor **ret_hcor)
Simon Glass2b53b072015-07-06 16:47:53 -060027{
Marek Vasut1335e772018-08-07 12:27:10 +020028 struct ehci_pci_priv *priv = dev_get_priv(dev);
Simon Glass2b53b072015-07-06 16:47:53 -060029 struct ehci_hccr *hccr;
30 struct ehci_hcor *hcor;
Marek Vasut1335e772018-08-07 12:27:10 +020031 int ret;
Simon Glass09c5c162015-11-29 13:18:07 -070032 u32 cmd;
Simon Glass2b53b072015-07-06 16:47:53 -060033
Patrice Chotard083f8aa2022-09-06 08:15:28 +020034 ret = generic_setup_phy(dev, &priv->phy, 0);
Marek Vasut1335e772018-08-07 12:27:10 +020035 if (ret)
36 return ret;
37
Simon Glass09c5c162015-11-29 13:18:07 -070038 hccr = (struct ehci_hccr *)dm_pci_map_bar(dev,
Andrew Scull2635e3b2022-04-21 16:11:13 +000039 PCI_BASE_ADDRESS_0, 0, 0, PCI_REGION_TYPE,
40 PCI_REGION_MEM);
Simon Glass09c5c162015-11-29 13:18:07 -070041 hcor = (struct ehci_hcor *)((uintptr_t) hccr +
Simon Glass2b53b072015-07-06 16:47:53 -060042 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
43
Simon Glassb11e2982016-09-25 21:33:21 -060044 debug("EHCI-PCI init hccr %#lx and hcor %#lx hc_length %d\n",
45 (ulong)hccr, (ulong)hcor,
Simon Glass09c5c162015-11-29 13:18:07 -070046 (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
Simon Glass2b53b072015-07-06 16:47:53 -060047
48 *ret_hccr = hccr;
49 *ret_hcor = hcor;
50
51 /* enable busmaster */
Simon Glass09c5c162015-11-29 13:18:07 -070052 dm_pci_read_config32(dev, PCI_COMMAND, &cmd);
Simon Glass2b53b072015-07-06 16:47:53 -060053 cmd |= PCI_COMMAND_MASTER;
Simon Glass09c5c162015-11-29 13:18:07 -070054 dm_pci_write_config32(dev, PCI_COMMAND, cmd);
Marek Vasut1335e772018-08-07 12:27:10 +020055
56 return 0;
Simon Glass2b53b072015-07-06 16:47:53 -060057}
58
Simon Glass09c5c162015-11-29 13:18:07 -070059#else
Simon Glass2b53b072015-07-06 16:47:53 -060060
Michael Trimarchi8fea2912008-12-31 10:32:41 +010061#ifdef CONFIG_PCI_EHCI_DEVICE
62static struct pci_device_id ehci_pci_ids[] = {
63 /* Please add supported PCI EHCI controller ids here */
Trübenbach, Ralf0a5f7e12011-03-31 16:46:47 +000064 {0x1033, 0x00E0}, /* NEC */
Wolfgang Denk4db2fa72011-04-05 12:24:20 +020065 {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */
Trübenbach, Ralf0a5f7e12011-03-31 16:46:47 +000066 {0x12D8, 0x400F}, /* Pericom */
Michael Trimarchi8fea2912008-12-31 10:32:41 +010067 {0, 0}
68};
69#endif
70
Simon Glass09c5c162015-11-29 13:18:07 -070071static void ehci_pci_legacy_init(pci_dev_t pdev, struct ehci_hccr **ret_hccr,
72 struct ehci_hcor **ret_hcor)
73{
74 struct ehci_hccr *hccr;
75 struct ehci_hcor *hcor;
76 u32 cmd;
77
78 hccr = (struct ehci_hccr *)pci_map_bar(pdev,
79 PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
80 hcor = (struct ehci_hcor *)((uintptr_t) hccr +
81 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
82
83 debug("EHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n",
84 (u32)hccr, (u32)hcor,
85 (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
86
87 *ret_hccr = hccr;
88 *ret_hcor = hcor;
89
90 /* enable busmaster */
91 pci_read_config_dword(pdev, PCI_COMMAND, &cmd);
92 cmd |= PCI_COMMAND_MASTER;
93 pci_write_config_dword(pdev, PCI_COMMAND, cmd);
94}
95
Michael Trimarchi8fea2912008-12-31 10:32:41 +010096/*
97 * Create the appropriate control structures to manage
98 * a new EHCI host controller.
99 */
Troy Kisky127efc42013-10-10 15:27:57 -0700100int ehci_hcd_init(int index, enum usb_init_type init,
101 struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor)
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100102{
103 pci_dev_t pdev;
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100104
Vincent Palatin7c38e902012-12-13 22:58:27 -0800105#ifdef CONFIG_PCI_EHCI_DEVICE
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100106 pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE);
Vincent Palatin7c38e902012-12-13 22:58:27 -0800107#else
Simon Glass4fd46722015-01-27 22:13:30 -0700108 pdev = pci_find_class(PCI_CLASS_SERIAL_USB_EHCI, index);
Vincent Palatin7c38e902012-12-13 22:58:27 -0800109#endif
110 if (pdev < 0) {
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100111 printf("EHCI host controller not found\n");
112 return -1;
113 }
Simon Glass09c5c162015-11-29 13:18:07 -0700114 ehci_pci_legacy_init(pdev, ret_hccr, ret_hcor);
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100115
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100116 return 0;
117}
118
119/*
120 * Destroy the appropriate control structures corresponding
121 * the the EHCI host controller.
122 */
Lucas Stach676ae062012-09-26 00:14:35 +0200123int ehci_hcd_stop(int index)
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100124{
125 return 0;
126}
Sven Schwermerfd09c202018-11-21 08:43:56 +0100127#endif /* !CONFIG_IS_ENABLED(DM_USB) */
Simon Glass2b53b072015-07-06 16:47:53 -0600128
Sven Schwermerfd09c202018-11-21 08:43:56 +0100129#if CONFIG_IS_ENABLED(DM_USB)
Simon Glass2b53b072015-07-06 16:47:53 -0600130static int ehci_pci_probe(struct udevice *dev)
131{
132 struct ehci_hccr *hccr;
133 struct ehci_hcor *hcor;
Marek Vasut1335e772018-08-07 12:27:10 +0200134 int ret;
Simon Glass2b53b072015-07-06 16:47:53 -0600135
Marek Vasut1335e772018-08-07 12:27:10 +0200136 ret = ehci_pci_init(dev, &hccr, &hcor);
137 if (ret)
138 return ret;
Simon Glass2b53b072015-07-06 16:47:53 -0600139
140 return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
141}
142
Marek Vasut1335e772018-08-07 12:27:10 +0200143static int ehci_pci_remove(struct udevice *dev)
144{
145 struct ehci_pci_priv *priv = dev_get_priv(dev);
146 int ret;
147
148 ret = ehci_deregister(dev);
149 if (ret)
150 return ret;
151
Patrice Chotard083f8aa2022-09-06 08:15:28 +0200152 return generic_shutdown_phy(&priv->phy);
Marek Vasut1335e772018-08-07 12:27:10 +0200153}
154
Simon Glass907eed22016-01-17 16:11:07 -0700155static const struct udevice_id ehci_pci_ids[] = {
156 { .compatible = "ehci-pci" },
157 { }
158};
159
Simon Glass2b53b072015-07-06 16:47:53 -0600160U_BOOT_DRIVER(ehci_pci) = {
161 .name = "ehci_pci",
162 .id = UCLASS_USB,
163 .probe = ehci_pci_probe,
Marek Vasut1335e772018-08-07 12:27:10 +0200164 .remove = ehci_pci_remove,
Simon Glass907eed22016-01-17 16:11:07 -0700165 .of_match = ehci_pci_ids,
Simon Glass2b53b072015-07-06 16:47:53 -0600166 .ops = &ehci_usb_ops,
Simon Glass8a8d24b2020-12-03 16:55:23 -0700167 .plat_auto = sizeof(struct usb_plat),
Simon Glass41575d82020-12-03 16:55:17 -0700168 .priv_auto = sizeof(struct ehci_pci_priv),
Simon Glass2b53b072015-07-06 16:47:53 -0600169 .flags = DM_FLAG_ALLOC_PRIV_DMA,
170};
171
172static struct pci_device_id ehci_pci_supported[] = {
173 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0) },
174 {},
175};
176
177U_BOOT_PCI_DEVICE(ehci_pci, ehci_pci_supported);
178
Sven Schwermerfd09c202018-11-21 08:43:56 +0100179#endif /* CONFIG_IS_ENABLED(DM_USB) */