]> git.ipfire.org Git - thirdparty/u-boot.git/blame - drivers/usb/host/ehci-pci.c
usb: s/CONFIG_DM_USB/CONFIG_IS_ENABLED(DM_USB)/
[thirdparty/u-boot.git] / drivers / usb / host / ehci-pci.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0
8fea2914
MT
2/*-
3 * Copyright (c) 2007-2008, Juniper Networks, Inc.
4 * All rights reserved.
8fea2914
MT
5 */
6
7#include <common.h>
2b53b078 8#include <dm.h>
7c38e90a 9#include <errno.h>
8fea2914
MT
10#include <pci.h>
11#include <usb.h>
2cb7b900 12#include <asm/io.h>
2731b9a8
JCPV
13
14#include "ehci.h"
8fea2914 15
2b53b078
SG
16/* Information about a USB port */
17struct ehci_pci_priv {
18 struct ehci_ctrl ehci;
1335e774 19 struct phy phy;
2b53b078
SG
20};
21
fd09c205 22#if CONFIG_IS_ENABLED(DM_USB)
1335e774 23static int ehci_pci_init(struct udevice *dev, struct ehci_hccr **ret_hccr,
09c5c164 24 struct ehci_hcor **ret_hcor)
2b53b078 25{
1335e774 26 struct ehci_pci_priv *priv = dev_get_priv(dev);
2b53b078
SG
27 struct ehci_hccr *hccr;
28 struct ehci_hcor *hcor;
1335e774 29 int ret;
09c5c164 30 u32 cmd;
2b53b078 31
1335e774
MV
32 ret = ehci_setup_phy(dev, &priv->phy, 0);
33 if (ret)
34 return ret;
35
09c5c164 36 hccr = (struct ehci_hccr *)dm_pci_map_bar(dev,
2b53b078 37 PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
09c5c164 38 hcor = (struct ehci_hcor *)((uintptr_t) hccr +
2b53b078
SG
39 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
40
b11e2984
SG
41 debug("EHCI-PCI init hccr %#lx and hcor %#lx hc_length %d\n",
42 (ulong)hccr, (ulong)hcor,
09c5c164 43 (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
2b53b078
SG
44
45 *ret_hccr = hccr;
46 *ret_hcor = hcor;
47
48 /* enable busmaster */
09c5c164 49 dm_pci_read_config32(dev, PCI_COMMAND, &cmd);
2b53b078 50 cmd |= PCI_COMMAND_MASTER;
09c5c164 51 dm_pci_write_config32(dev, PCI_COMMAND, cmd);
1335e774
MV
52
53 return 0;
2b53b078
SG
54}
55
09c5c164 56#else
2b53b078 57
8fea2914
MT
58#ifdef CONFIG_PCI_EHCI_DEVICE
59static struct pci_device_id ehci_pci_ids[] = {
60 /* Please add supported PCI EHCI controller ids here */
0a5f7e1b 61 {0x1033, 0x00E0}, /* NEC */
4db2fa7f 62 {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */
0a5f7e1b 63 {0x12D8, 0x400F}, /* Pericom */
8fea2914
MT
64 {0, 0}
65};
66#endif
67
09c5c164
SG
68static 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
8fea2914
MT
93/*
94 * Create the appropriate control structures to manage
95 * a new EHCI host controller.
96 */
127efc4f
TK
97int ehci_hcd_init(int index, enum usb_init_type init,
98 struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor)
8fea2914
MT
99{
100 pci_dev_t pdev;
8fea2914 101
7c38e90a 102#ifdef CONFIG_PCI_EHCI_DEVICE
8fea2914 103 pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE);
7c38e90a 104#else
4fd46727 105 pdev = pci_find_class(PCI_CLASS_SERIAL_USB_EHCI, index);
7c38e90a
VP
106#endif
107 if (pdev < 0) {
8fea2914
MT
108 printf("EHCI host controller not found\n");
109 return -1;
110 }
09c5c164 111 ehci_pci_legacy_init(pdev, ret_hccr, ret_hcor);
8fea2914 112
8fea2914
MT
113 return 0;
114}
115
116/*
117 * Destroy the appropriate control structures corresponding
118 * the the EHCI host controller.
119 */
676ae068 120int ehci_hcd_stop(int index)
8fea2914
MT
121{
122 return 0;
123}
fd09c205 124#endif /* !CONFIG_IS_ENABLED(DM_USB) */
2b53b078 125
fd09c205 126#if CONFIG_IS_ENABLED(DM_USB)
2b53b078
SG
127static int ehci_pci_probe(struct udevice *dev)
128{
129 struct ehci_hccr *hccr;
130 struct ehci_hcor *hcor;
1335e774 131 int ret;
2b53b078 132
1335e774
MV
133 ret = ehci_pci_init(dev, &hccr, &hcor);
134 if (ret)
135 return ret;
2b53b078
SG
136
137 return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
138}
139
1335e774
MV
140static 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
907eed2c
SG
152static const struct udevice_id ehci_pci_ids[] = {
153 { .compatible = "ehci-pci" },
154 { }
155};
156
2b53b078
SG
157U_BOOT_DRIVER(ehci_pci) = {
158 .name = "ehci_pci",
159 .id = UCLASS_USB,
160 .probe = ehci_pci_probe,
1335e774 161 .remove = ehci_pci_remove,
907eed2c 162 .of_match = ehci_pci_ids,
2b53b078
SG
163 .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
fd09c205 176#endif /* CONFIG_IS_ENABLED(DM_USB) */