blob: 04e7c5e37f8796370a680829746b05c932288dd4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Michael Trimarchiebc83002008-12-31 10:32:41 +01002/*-
3 * Copyright (c) 2007-2008, Juniper Networks, Inc.
4 * All rights reserved.
Michael Trimarchiebc83002008-12-31 10:32:41 +01005 */
6
7#include <common.h>
Simon Glassd0065dd2015-07-06 16:47:53 -06008#include <dm.h>
Vincent Palatin8d452892012-12-13 22:58:27 -08009#include <errno.h>
Michael Trimarchiebc83002008-12-31 10:32:41 +010010#include <pci.h>
11#include <usb.h>
Alexey Brodkin1ddd5402017-06-05 10:19:26 +030012#include <asm/io.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;
Marek Vasut8f58c782018-08-07 12:27:10 +020019 struct phy phy;
Simon Glassd0065dd2015-07-06 16:47:53 -060020};
21
Sven Schwermer8a3cb9f12018-11-21 08:43:56 +010022#if CONFIG_IS_ENABLED(DM_USB)
Marek Vasut8f58c782018-08-07 12:27:10 +020023static int ehci_pci_init(struct udevice *dev, struct ehci_hccr **ret_hccr,
Simon Glass261095b2015-11-29 13:18:07 -070024 struct ehci_hcor **ret_hcor)
Simon Glassd0065dd2015-07-06 16:47:53 -060025{
Marek Vasut8f58c782018-08-07 12:27:10 +020026 struct ehci_pci_priv *priv = dev_get_priv(dev);
Simon Glassd0065dd2015-07-06 16:47:53 -060027 struct ehci_hccr *hccr;
28 struct ehci_hcor *hcor;
Marek Vasut8f58c782018-08-07 12:27:10 +020029 int ret;
Simon Glass261095b2015-11-29 13:18:07 -070030 u32 cmd;
Simon Glassd0065dd2015-07-06 16:47:53 -060031
Marek Vasut8f58c782018-08-07 12:27:10 +020032 ret = ehci_setup_phy(dev, &priv->phy, 0);
33 if (ret)
34 return ret;
35
Simon Glass261095b2015-11-29 13:18:07 -070036 hccr = (struct ehci_hccr *)dm_pci_map_bar(dev,
Simon Glassd0065dd2015-07-06 16:47:53 -060037 PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
Simon Glass261095b2015-11-29 13:18:07 -070038 hcor = (struct ehci_hcor *)((uintptr_t) hccr +
Simon Glassd0065dd2015-07-06 16:47:53 -060039 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
40
Simon Glass26a2b2d2016-09-25 21:33:21 -060041 debug("EHCI-PCI init hccr %#lx and hcor %#lx hc_length %d\n",
42 (ulong)hccr, (ulong)hcor,
Simon Glass261095b2015-11-29 13:18:07 -070043 (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
Simon Glassd0065dd2015-07-06 16:47:53 -060044
45 *ret_hccr = hccr;
46 *ret_hcor = hcor;
47
48 /* enable busmaster */
Simon Glass261095b2015-11-29 13:18:07 -070049 dm_pci_read_config32(dev, PCI_COMMAND, &cmd);
Simon Glassd0065dd2015-07-06 16:47:53 -060050 cmd |= PCI_COMMAND_MASTER;
Simon Glass261095b2015-11-29 13:18:07 -070051 dm_pci_write_config32(dev, PCI_COMMAND, cmd);
Marek Vasut8f58c782018-08-07 12:27:10 +020052
53 return 0;
Simon Glassd0065dd2015-07-06 16:47:53 -060054}
55
Simon Glass261095b2015-11-29 13:18:07 -070056#else
Simon Glassd0065dd2015-07-06 16:47:53 -060057
Michael Trimarchiebc83002008-12-31 10:32:41 +010058#ifdef CONFIG_PCI_EHCI_DEVICE
59static struct pci_device_id ehci_pci_ids[] = {
60 /* Please add supported PCI EHCI controller ids here */
Trübenbach, Ralfd2c91882011-03-31 16:46:47 +000061 {0x1033, 0x00E0}, /* NEC */
Wolfgang Denke9366282011-04-05 12:24:20 +020062 {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */
Trübenbach, Ralfd2c91882011-03-31 16:46:47 +000063 {0x12D8, 0x400F}, /* Pericom */
Michael Trimarchiebc83002008-12-31 10:32:41 +010064 {0, 0}
65};
66#endif
67
Simon Glass261095b2015-11-29 13:18:07 -070068static void ehci_pci_legacy_init(pci_dev_t pdev, struct ehci_hccr **ret_hccr,
69 struct ehci_hcor **ret_hcor)
70{
71 struct ehci_hccr *hccr;
72 struct ehci_hcor *hcor;
73 u32 cmd;
74
75 hccr = (struct ehci_hccr *)pci_map_bar(pdev,
76 PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
77 hcor = (struct ehci_hcor *)((uintptr_t) hccr +
78 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
79
80 debug("EHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n",
81 (u32)hccr, (u32)hcor,
82 (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
83
84 *ret_hccr = hccr;
85 *ret_hcor = hcor;
86
87 /* enable busmaster */
88 pci_read_config_dword(pdev, PCI_COMMAND, &cmd);
89 cmd |= PCI_COMMAND_MASTER;
90 pci_write_config_dword(pdev, PCI_COMMAND, cmd);
91}
92
Michael Trimarchiebc83002008-12-31 10:32:41 +010093/*
94 * Create the appropriate control structures to manage
95 * a new EHCI host controller.
96 */
Troy Kisky7d6bbb92013-10-10 15:27:57 -070097int ehci_hcd_init(int index, enum usb_init_type init,
98 struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor)
Michael Trimarchiebc83002008-12-31 10:32:41 +010099{
100 pci_dev_t pdev;
Michael Trimarchiebc83002008-12-31 10:32:41 +0100101
Vincent Palatin8d452892012-12-13 22:58:27 -0800102#ifdef CONFIG_PCI_EHCI_DEVICE
Michael Trimarchiebc83002008-12-31 10:32:41 +0100103 pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE);
Vincent Palatin8d452892012-12-13 22:58:27 -0800104#else
Simon Glasseeb1d282015-01-27 22:13:30 -0700105 pdev = pci_find_class(PCI_CLASS_SERIAL_USB_EHCI, index);
Vincent Palatin8d452892012-12-13 22:58:27 -0800106#endif
107 if (pdev < 0) {
Michael Trimarchiebc83002008-12-31 10:32:41 +0100108 printf("EHCI host controller not found\n");
109 return -1;
110 }
Simon Glass261095b2015-11-29 13:18:07 -0700111 ehci_pci_legacy_init(pdev, ret_hccr, ret_hcor);
Michael Trimarchiebc83002008-12-31 10:32:41 +0100112
Michael Trimarchiebc83002008-12-31 10:32:41 +0100113 return 0;
114}
115
116/*
117 * Destroy the appropriate control structures corresponding
118 * the the EHCI host controller.
119 */
Lucas Stach3494a4c2012-09-26 00:14:35 +0200120int ehci_hcd_stop(int index)
Michael Trimarchiebc83002008-12-31 10:32:41 +0100121{
Simon Glassd0065dd2015-07-06 16:47:53 -0600122 return 0;
123}
Sven Schwermer8a3cb9f12018-11-21 08:43:56 +0100124#endif /* !CONFIG_IS_ENABLED(DM_USB) */
Simon Glassd0065dd2015-07-06 16:47:53 -0600125
Sven Schwermer8a3cb9f12018-11-21 08:43:56 +0100126#if CONFIG_IS_ENABLED(DM_USB)
Simon Glassd0065dd2015-07-06 16:47:53 -0600127static int ehci_pci_probe(struct udevice *dev)
128{
129 struct ehci_hccr *hccr;
130 struct ehci_hcor *hcor;
Marek Vasut8f58c782018-08-07 12:27:10 +0200131 int ret;
Simon Glassd0065dd2015-07-06 16:47:53 -0600132
Marek Vasut8f58c782018-08-07 12:27:10 +0200133 ret = ehci_pci_init(dev, &hccr, &hcor);
134 if (ret)
135 return ret;
Simon Glassd0065dd2015-07-06 16:47:53 -0600136
137 return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
138}
139
Marek Vasut8f58c782018-08-07 12:27:10 +0200140static int ehci_pci_remove(struct udevice *dev)
141{
142 struct ehci_pci_priv *priv = dev_get_priv(dev);
143 int ret;
144
145 ret = ehci_deregister(dev);
146 if (ret)
147 return ret;
148
149 return ehci_shutdown_phy(dev, &priv->phy);
150}
151
Simon Glass9470c722016-01-17 16:11:07 -0700152static const struct udevice_id ehci_pci_ids[] = {
153 { .compatible = "ehci-pci" },
154 { }
155};
156
Simon Glassd0065dd2015-07-06 16:47:53 -0600157U_BOOT_DRIVER(ehci_pci) = {
158 .name = "ehci_pci",
159 .id = UCLASS_USB,
160 .probe = ehci_pci_probe,
Marek Vasut8f58c782018-08-07 12:27:10 +0200161 .remove = ehci_pci_remove,
Simon Glass9470c722016-01-17 16:11:07 -0700162 .of_match = ehci_pci_ids,
Simon Glassd0065dd2015-07-06 16:47:53 -0600163 .ops = &ehci_usb_ops,
164 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
165 .priv_auto_alloc_size = sizeof(struct ehci_pci_priv),
166 .flags = DM_FLAG_ALLOC_PRIV_DMA,
167};
168
169static struct pci_device_id ehci_pci_supported[] = {
170 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0) },
171 {},
172};
173
174U_BOOT_PCI_DEVICE(ehci_pci, ehci_pci_supported);
175
Sven Schwermer8a3cb9f12018-11-21 08:43:56 +0100176#endif /* CONFIG_IS_ENABLED(DM_USB) */