]>
Commit | Line | Data |
---|---|---|
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> |
691d719d | 10 | #include <init.h> |
f7ae49fc | 11 | #include <log.h> |
8fea2914 MT |
12 | #include <pci.h> |
13 | #include <usb.h> | |
2cb7b900 | 14 | #include <asm/io.h> |
2731b9a8 JCPV |
15 | |
16 | #include "ehci.h" | |
8fea2914 | 17 | |
2b53b078 SG |
18 | /* Information about a USB port */ |
19 | struct ehci_pci_priv { | |
20 | struct ehci_ctrl ehci; | |
1335e774 | 21 | struct phy phy; |
2b53b078 SG |
22 | }; |
23 | ||
fd09c205 | 24 | #if CONFIG_IS_ENABLED(DM_USB) |
1335e774 | 25 | static int ehci_pci_init(struct udevice *dev, struct ehci_hccr **ret_hccr, |
09c5c164 | 26 | struct ehci_hcor **ret_hcor) |
2b53b078 | 27 | { |
1335e774 | 28 | struct ehci_pci_priv *priv = dev_get_priv(dev); |
2b53b078 SG |
29 | struct ehci_hccr *hccr; |
30 | struct ehci_hcor *hcor; | |
1335e774 | 31 | int ret; |
09c5c164 | 32 | u32 cmd; |
2b53b078 | 33 | |
1335e774 MV |
34 | ret = ehci_setup_phy(dev, &priv->phy, 0); |
35 | if (ret) | |
36 | return ret; | |
37 | ||
09c5c164 | 38 | hccr = (struct ehci_hccr *)dm_pci_map_bar(dev, |
2b53b078 | 39 | PCI_BASE_ADDRESS_0, PCI_REGION_MEM); |
09c5c164 | 40 | hcor = (struct ehci_hcor *)((uintptr_t) hccr + |
2b53b078 SG |
41 | HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
42 | ||
b11e2984 SG |
43 | debug("EHCI-PCI init hccr %#lx and hcor %#lx hc_length %d\n", |
44 | (ulong)hccr, (ulong)hcor, | |
09c5c164 | 45 | (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
2b53b078 SG |
46 | |
47 | *ret_hccr = hccr; | |
48 | *ret_hcor = hcor; | |
49 | ||
50 | /* enable busmaster */ | |
09c5c164 | 51 | dm_pci_read_config32(dev, PCI_COMMAND, &cmd); |
2b53b078 | 52 | cmd |= PCI_COMMAND_MASTER; |
09c5c164 | 53 | dm_pci_write_config32(dev, PCI_COMMAND, cmd); |
1335e774 MV |
54 | |
55 | return 0; | |
2b53b078 SG |
56 | } |
57 | ||
09c5c164 | 58 | #else |
2b53b078 | 59 | |
8fea2914 MT |
60 | #ifdef CONFIG_PCI_EHCI_DEVICE |
61 | static struct pci_device_id ehci_pci_ids[] = { | |
62 | /* Please add supported PCI EHCI controller ids here */ | |
0a5f7e1b | 63 | {0x1033, 0x00E0}, /* NEC */ |
4db2fa7f | 64 | {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */ |
0a5f7e1b | 65 | {0x12D8, 0x400F}, /* Pericom */ |
8fea2914 MT |
66 | {0, 0} |
67 | }; | |
68 | #endif | |
69 | ||
09c5c164 SG |
70 | static void ehci_pci_legacy_init(pci_dev_t pdev, struct ehci_hccr **ret_hccr, |
71 | struct ehci_hcor **ret_hcor) | |
72 | { | |
73 | struct ehci_hccr *hccr; | |
74 | struct ehci_hcor *hcor; | |
75 | u32 cmd; | |
76 | ||
77 | hccr = (struct ehci_hccr *)pci_map_bar(pdev, | |
78 | PCI_BASE_ADDRESS_0, PCI_REGION_MEM); | |
79 | hcor = (struct ehci_hcor *)((uintptr_t) hccr + | |
80 | HC_LENGTH(ehci_readl(&hccr->cr_capbase))); | |
81 | ||
82 | debug("EHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n", | |
83 | (u32)hccr, (u32)hcor, | |
84 | (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase))); | |
85 | ||
86 | *ret_hccr = hccr; | |
87 | *ret_hcor = hcor; | |
88 | ||
89 | /* enable busmaster */ | |
90 | pci_read_config_dword(pdev, PCI_COMMAND, &cmd); | |
91 | cmd |= PCI_COMMAND_MASTER; | |
92 | pci_write_config_dword(pdev, PCI_COMMAND, cmd); | |
93 | } | |
94 | ||
8fea2914 MT |
95 | /* |
96 | * Create the appropriate control structures to manage | |
97 | * a new EHCI host controller. | |
98 | */ | |
127efc4f TK |
99 | int ehci_hcd_init(int index, enum usb_init_type init, |
100 | struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor) | |
8fea2914 MT |
101 | { |
102 | pci_dev_t pdev; | |
8fea2914 | 103 | |
7c38e90a | 104 | #ifdef CONFIG_PCI_EHCI_DEVICE |
8fea2914 | 105 | pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE); |
7c38e90a | 106 | #else |
4fd46727 | 107 | pdev = pci_find_class(PCI_CLASS_SERIAL_USB_EHCI, index); |
7c38e90a VP |
108 | #endif |
109 | if (pdev < 0) { | |
8fea2914 MT |
110 | printf("EHCI host controller not found\n"); |
111 | return -1; | |
112 | } | |
09c5c164 | 113 | ehci_pci_legacy_init(pdev, ret_hccr, ret_hcor); |
8fea2914 | 114 | |
8fea2914 MT |
115 | return 0; |
116 | } | |
117 | ||
118 | /* | |
119 | * Destroy the appropriate control structures corresponding | |
120 | * the the EHCI host controller. | |
121 | */ | |
676ae068 | 122 | int ehci_hcd_stop(int index) |
8fea2914 MT |
123 | { |
124 | return 0; | |
125 | } | |
fd09c205 | 126 | #endif /* !CONFIG_IS_ENABLED(DM_USB) */ |
2b53b078 | 127 | |
fd09c205 | 128 | #if CONFIG_IS_ENABLED(DM_USB) |
2b53b078 SG |
129 | static int ehci_pci_probe(struct udevice *dev) |
130 | { | |
131 | struct ehci_hccr *hccr; | |
132 | struct ehci_hcor *hcor; | |
1335e774 | 133 | int ret; |
2b53b078 | 134 | |
1335e774 MV |
135 | ret = ehci_pci_init(dev, &hccr, &hcor); |
136 | if (ret) | |
137 | return ret; | |
2b53b078 SG |
138 | |
139 | return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST); | |
140 | } | |
141 | ||
1335e774 MV |
142 | static int ehci_pci_remove(struct udevice *dev) |
143 | { | |
144 | struct ehci_pci_priv *priv = dev_get_priv(dev); | |
145 | int ret; | |
146 | ||
147 | ret = ehci_deregister(dev); | |
148 | if (ret) | |
149 | return ret; | |
150 | ||
151 | return ehci_shutdown_phy(dev, &priv->phy); | |
152 | } | |
153 | ||
907eed2c SG |
154 | static const struct udevice_id ehci_pci_ids[] = { |
155 | { .compatible = "ehci-pci" }, | |
156 | { } | |
157 | }; | |
158 | ||
2b53b078 SG |
159 | U_BOOT_DRIVER(ehci_pci) = { |
160 | .name = "ehci_pci", | |
161 | .id = UCLASS_USB, | |
162 | .probe = ehci_pci_probe, | |
1335e774 | 163 | .remove = ehci_pci_remove, |
907eed2c | 164 | .of_match = ehci_pci_ids, |
2b53b078 | 165 | .ops = &ehci_usb_ops, |
41575d8e SG |
166 | .platdata_auto = sizeof(struct usb_platdata), |
167 | .priv_auto = sizeof(struct ehci_pci_priv), | |
2b53b078 SG |
168 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
169 | }; | |
170 | ||
171 | static struct pci_device_id ehci_pci_supported[] = { | |
172 | { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0) }, | |
173 | {}, | |
174 | }; | |
175 | ||
176 | U_BOOT_PCI_DEVICE(ehci_pci, ehci_pci_supported); | |
177 | ||
fd09c205 | 178 | #endif /* CONFIG_IS_ENABLED(DM_USB) */ |