]>
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 | ||
d678a59d | 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 | |
083f8aa9 | 34 | ret = generic_setup_phy(dev, &priv->phy, 0); |
1335e774 MV |
35 | if (ret) |
36 | return ret; | |
37 | ||
09c5c164 | 38 | hccr = (struct ehci_hccr *)dm_pci_map_bar(dev, |
2635e3b5 AS |
39 | PCI_BASE_ADDRESS_0, 0, 0, PCI_REGION_TYPE, |
40 | PCI_REGION_MEM); | |
09c5c164 | 41 | hcor = (struct ehci_hcor *)((uintptr_t) hccr + |
2b53b078 SG |
42 | HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
43 | ||
b11e2984 SG |
44 | debug("EHCI-PCI init hccr %#lx and hcor %#lx hc_length %d\n", |
45 | (ulong)hccr, (ulong)hcor, | |
09c5c164 | 46 | (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
2b53b078 SG |
47 | |
48 | *ret_hccr = hccr; | |
49 | *ret_hcor = hcor; | |
50 | ||
51 | /* enable busmaster */ | |
09c5c164 | 52 | dm_pci_read_config32(dev, PCI_COMMAND, &cmd); |
2b53b078 | 53 | cmd |= PCI_COMMAND_MASTER; |
09c5c164 | 54 | dm_pci_write_config32(dev, PCI_COMMAND, cmd); |
1335e774 MV |
55 | |
56 | return 0; | |
2b53b078 SG |
57 | } |
58 | ||
09c5c164 | 59 | #else |
2b53b078 | 60 | |
8fea2914 MT |
61 | #ifdef CONFIG_PCI_EHCI_DEVICE |
62 | static struct pci_device_id ehci_pci_ids[] = { | |
63 | /* Please add supported PCI EHCI controller ids here */ | |
0a5f7e1b | 64 | {0x1033, 0x00E0}, /* NEC */ |
4db2fa7f | 65 | {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */ |
0a5f7e1b | 66 | {0x12D8, 0x400F}, /* Pericom */ |
8fea2914 MT |
67 | {0, 0} |
68 | }; | |
69 | #endif | |
70 | ||
09c5c164 SG |
71 | static 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 | ||
8fea2914 MT |
96 | /* |
97 | * Create the appropriate control structures to manage | |
98 | * a new EHCI host controller. | |
99 | */ | |
127efc4f TK |
100 | int ehci_hcd_init(int index, enum usb_init_type init, |
101 | struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor) | |
8fea2914 MT |
102 | { |
103 | pci_dev_t pdev; | |
8fea2914 | 104 | |
7c38e90a | 105 | #ifdef CONFIG_PCI_EHCI_DEVICE |
8fea2914 | 106 | pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE); |
7c38e90a | 107 | #else |
4fd46727 | 108 | pdev = pci_find_class(PCI_CLASS_SERIAL_USB_EHCI, index); |
7c38e90a VP |
109 | #endif |
110 | if (pdev < 0) { | |
8fea2914 MT |
111 | printf("EHCI host controller not found\n"); |
112 | return -1; | |
113 | } | |
09c5c164 | 114 | ehci_pci_legacy_init(pdev, ret_hccr, ret_hcor); |
8fea2914 | 115 | |
8fea2914 MT |
116 | return 0; |
117 | } | |
118 | ||
119 | /* | |
120 | * Destroy the appropriate control structures corresponding | |
121 | * the the EHCI host controller. | |
122 | */ | |
676ae068 | 123 | int ehci_hcd_stop(int index) |
8fea2914 MT |
124 | { |
125 | return 0; | |
126 | } | |
fd09c205 | 127 | #endif /* !CONFIG_IS_ENABLED(DM_USB) */ |
2b53b078 | 128 | |
fd09c205 | 129 | #if CONFIG_IS_ENABLED(DM_USB) |
2b53b078 SG |
130 | static int ehci_pci_probe(struct udevice *dev) |
131 | { | |
132 | struct ehci_hccr *hccr; | |
133 | struct ehci_hcor *hcor; | |
1335e774 | 134 | int ret; |
2b53b078 | 135 | |
1335e774 MV |
136 | ret = ehci_pci_init(dev, &hccr, &hcor); |
137 | if (ret) | |
138 | return ret; | |
2b53b078 SG |
139 | |
140 | return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST); | |
141 | } | |
142 | ||
1335e774 MV |
143 | static 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 | ||
083f8aa9 | 152 | return generic_shutdown_phy(&priv->phy); |
1335e774 MV |
153 | } |
154 | ||
907eed2c SG |
155 | static const struct udevice_id ehci_pci_ids[] = { |
156 | { .compatible = "ehci-pci" }, | |
157 | { } | |
158 | }; | |
159 | ||
2b53b078 SG |
160 | U_BOOT_DRIVER(ehci_pci) = { |
161 | .name = "ehci_pci", | |
162 | .id = UCLASS_USB, | |
163 | .probe = ehci_pci_probe, | |
1335e774 | 164 | .remove = ehci_pci_remove, |
907eed2c | 165 | .of_match = ehci_pci_ids, |
2b53b078 | 166 | .ops = &ehci_usb_ops, |
8a8d24bd | 167 | .plat_auto = sizeof(struct usb_plat), |
41575d8e | 168 | .priv_auto = sizeof(struct ehci_pci_priv), |
2b53b078 SG |
169 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
170 | }; | |
171 | ||
172 | static struct pci_device_id ehci_pci_supported[] = { | |
173 | { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0) }, | |
174 | {}, | |
175 | }; | |
176 | ||
177 | U_BOOT_PCI_DEVICE(ehci_pci, ehci_pci_supported); | |
178 | ||
fd09c205 | 179 | #endif /* CONFIG_IS_ENABLED(DM_USB) */ |