blob: 450caf056c5d9b5eab86135be1e51c789f9cfad9 [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>
Michael Trimarchi8fea2912008-12-31 10:32:41 +010011#include <pci.h>
12#include <usb.h>
Alexey Brodkin2cb7b902017-06-05 10:19:26 +030013#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARD2731b9a2009-04-03 12:46:58 +020014
15#include "ehci.h"
Michael Trimarchi8fea2912008-12-31 10:32:41 +010016
Simon Glass2b53b072015-07-06 16:47:53 -060017/* Information about a USB port */
18struct ehci_pci_priv {
19 struct ehci_ctrl ehci;
Marek Vasut1335e772018-08-07 12:27:10 +020020 struct phy phy;
Simon Glass2b53b072015-07-06 16:47:53 -060021};
22
Sven Schwermerfd09c202018-11-21 08:43:56 +010023#if CONFIG_IS_ENABLED(DM_USB)
Marek Vasut1335e772018-08-07 12:27:10 +020024static int ehci_pci_init(struct udevice *dev, struct ehci_hccr **ret_hccr,
Simon Glass09c5c162015-11-29 13:18:07 -070025 struct ehci_hcor **ret_hcor)
Simon Glass2b53b072015-07-06 16:47:53 -060026{
Marek Vasut1335e772018-08-07 12:27:10 +020027 struct ehci_pci_priv *priv = dev_get_priv(dev);
Simon Glass2b53b072015-07-06 16:47:53 -060028 struct ehci_hccr *hccr;
29 struct ehci_hcor *hcor;
Marek Vasut1335e772018-08-07 12:27:10 +020030 int ret;
Simon Glass09c5c162015-11-29 13:18:07 -070031 u32 cmd;
Simon Glass2b53b072015-07-06 16:47:53 -060032
Marek Vasut1335e772018-08-07 12:27:10 +020033 ret = ehci_setup_phy(dev, &priv->phy, 0);
34 if (ret)
35 return ret;
36
Simon Glass09c5c162015-11-29 13:18:07 -070037 hccr = (struct ehci_hccr *)dm_pci_map_bar(dev,
Simon Glass2b53b072015-07-06 16:47:53 -060038 PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
Simon Glass09c5c162015-11-29 13:18:07 -070039 hcor = (struct ehci_hcor *)((uintptr_t) hccr +
Simon Glass2b53b072015-07-06 16:47:53 -060040 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
41
Simon Glassb11e2982016-09-25 21:33:21 -060042 debug("EHCI-PCI init hccr %#lx and hcor %#lx hc_length %d\n",
43 (ulong)hccr, (ulong)hcor,
Simon Glass09c5c162015-11-29 13:18:07 -070044 (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
Simon Glass2b53b072015-07-06 16:47:53 -060045
46 *ret_hccr = hccr;
47 *ret_hcor = hcor;
48
49 /* enable busmaster */
Simon Glass09c5c162015-11-29 13:18:07 -070050 dm_pci_read_config32(dev, PCI_COMMAND, &cmd);
Simon Glass2b53b072015-07-06 16:47:53 -060051 cmd |= PCI_COMMAND_MASTER;
Simon Glass09c5c162015-11-29 13:18:07 -070052 dm_pci_write_config32(dev, PCI_COMMAND, cmd);
Marek Vasut1335e772018-08-07 12:27:10 +020053
54 return 0;
Simon Glass2b53b072015-07-06 16:47:53 -060055}
56
Simon Glass09c5c162015-11-29 13:18:07 -070057#else
Simon Glass2b53b072015-07-06 16:47:53 -060058
Michael Trimarchi8fea2912008-12-31 10:32:41 +010059#ifdef CONFIG_PCI_EHCI_DEVICE
60static struct pci_device_id ehci_pci_ids[] = {
61 /* Please add supported PCI EHCI controller ids here */
Trübenbach, Ralf0a5f7e12011-03-31 16:46:47 +000062 {0x1033, 0x00E0}, /* NEC */
Wolfgang Denk4db2fa72011-04-05 12:24:20 +020063 {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */
Trübenbach, Ralf0a5f7e12011-03-31 16:46:47 +000064 {0x12D8, 0x400F}, /* Pericom */
Michael Trimarchi8fea2912008-12-31 10:32:41 +010065 {0, 0}
66};
67#endif
68
Simon Glass09c5c162015-11-29 13:18:07 -070069static void ehci_pci_legacy_init(pci_dev_t pdev, struct ehci_hccr **ret_hccr,
70 struct ehci_hcor **ret_hcor)
71{
72 struct ehci_hccr *hccr;
73 struct ehci_hcor *hcor;
74 u32 cmd;
75
76 hccr = (struct ehci_hccr *)pci_map_bar(pdev,
77 PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
78 hcor = (struct ehci_hcor *)((uintptr_t) hccr +
79 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
80
81 debug("EHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n",
82 (u32)hccr, (u32)hcor,
83 (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
84
85 *ret_hccr = hccr;
86 *ret_hcor = hcor;
87
88 /* enable busmaster */
89 pci_read_config_dword(pdev, PCI_COMMAND, &cmd);
90 cmd |= PCI_COMMAND_MASTER;
91 pci_write_config_dword(pdev, PCI_COMMAND, cmd);
92}
93
Michael Trimarchi8fea2912008-12-31 10:32:41 +010094/*
95 * Create the appropriate control structures to manage
96 * a new EHCI host controller.
97 */
Troy Kisky127efc42013-10-10 15:27:57 -070098int ehci_hcd_init(int index, enum usb_init_type init,
99 struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor)
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100100{
101 pci_dev_t pdev;
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100102
Vincent Palatin7c38e902012-12-13 22:58:27 -0800103#ifdef CONFIG_PCI_EHCI_DEVICE
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100104 pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE);
Vincent Palatin7c38e902012-12-13 22:58:27 -0800105#else
Simon Glass4fd46722015-01-27 22:13:30 -0700106 pdev = pci_find_class(PCI_CLASS_SERIAL_USB_EHCI, index);
Vincent Palatin7c38e902012-12-13 22:58:27 -0800107#endif
108 if (pdev < 0) {
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100109 printf("EHCI host controller not found\n");
110 return -1;
111 }
Simon Glass09c5c162015-11-29 13:18:07 -0700112 ehci_pci_legacy_init(pdev, ret_hccr, ret_hcor);
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100113
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100114 return 0;
115}
116
117/*
118 * Destroy the appropriate control structures corresponding
119 * the the EHCI host controller.
120 */
Lucas Stach676ae062012-09-26 00:14:35 +0200121int ehci_hcd_stop(int index)
Michael Trimarchi8fea2912008-12-31 10:32:41 +0100122{
123 return 0;
124}
Sven Schwermerfd09c202018-11-21 08:43:56 +0100125#endif /* !CONFIG_IS_ENABLED(DM_USB) */
Simon Glass2b53b072015-07-06 16:47:53 -0600126
Sven Schwermerfd09c202018-11-21 08:43:56 +0100127#if CONFIG_IS_ENABLED(DM_USB)
Simon Glass2b53b072015-07-06 16:47:53 -0600128static int ehci_pci_probe(struct udevice *dev)
129{
130 struct ehci_hccr *hccr;
131 struct ehci_hcor *hcor;
Marek Vasut1335e772018-08-07 12:27:10 +0200132 int ret;
Simon Glass2b53b072015-07-06 16:47:53 -0600133
Marek Vasut1335e772018-08-07 12:27:10 +0200134 ret = ehci_pci_init(dev, &hccr, &hcor);
135 if (ret)
136 return ret;
Simon Glass2b53b072015-07-06 16:47:53 -0600137
138 return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
139}
140
Marek Vasut1335e772018-08-07 12:27:10 +0200141static int ehci_pci_remove(struct udevice *dev)
142{
143 struct ehci_pci_priv *priv = dev_get_priv(dev);
144 int ret;
145
146 ret = ehci_deregister(dev);
147 if (ret)
148 return ret;
149
150 return ehci_shutdown_phy(dev, &priv->phy);
151}
152
Simon Glass907eed22016-01-17 16:11:07 -0700153static const struct udevice_id ehci_pci_ids[] = {
154 { .compatible = "ehci-pci" },
155 { }
156};
157
Simon Glass2b53b072015-07-06 16:47:53 -0600158U_BOOT_DRIVER(ehci_pci) = {
159 .name = "ehci_pci",
160 .id = UCLASS_USB,
161 .probe = ehci_pci_probe,
Marek Vasut1335e772018-08-07 12:27:10 +0200162 .remove = ehci_pci_remove,
Simon Glass907eed22016-01-17 16:11:07 -0700163 .of_match = ehci_pci_ids,
Simon Glass2b53b072015-07-06 16:47:53 -0600164 .ops = &ehci_usb_ops,
165 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
166 .priv_auto_alloc_size = sizeof(struct ehci_pci_priv),
167 .flags = DM_FLAG_ALLOC_PRIV_DMA,
168};
169
170static struct pci_device_id ehci_pci_supported[] = {
171 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0) },
172 {},
173};
174
175U_BOOT_PCI_DEVICE(ehci_pci, ehci_pci_supported);
176
Sven Schwermerfd09c202018-11-21 08:43:56 +0100177#endif /* CONFIG_IS_ENABLED(DM_USB) */