Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Michael Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 2 | /*- |
| 3 | * Copyright (c) 2007-2008, Juniper Networks, Inc. |
| 4 | * All rights reserved. |
Michael Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 8 | #include <dm.h> |
Vincent Palatin | 7c38e90 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 9 | #include <errno.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
Michael Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 11 | #include <pci.h> |
| 12 | #include <usb.h> |
Alexey Brodkin | 2cb7b90 | 2017-06-05 10:19:26 +0300 | [diff] [blame] | 13 | #include <asm/io.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2731b9a | 2009-04-03 12:46:58 +0200 | [diff] [blame] | 14 | |
| 15 | #include "ehci.h" |
Michael Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 16 | |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 17 | /* Information about a USB port */ |
| 18 | struct ehci_pci_priv { |
| 19 | struct ehci_ctrl ehci; |
Marek Vasut | 1335e77 | 2018-08-07 12:27:10 +0200 | [diff] [blame] | 20 | struct phy phy; |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 21 | }; |
| 22 | |
Sven Schwermer | fd09c20 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 23 | #if CONFIG_IS_ENABLED(DM_USB) |
Marek Vasut | 1335e77 | 2018-08-07 12:27:10 +0200 | [diff] [blame] | 24 | static int ehci_pci_init(struct udevice *dev, struct ehci_hccr **ret_hccr, |
Simon Glass | 09c5c16 | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 25 | struct ehci_hcor **ret_hcor) |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 26 | { |
Marek Vasut | 1335e77 | 2018-08-07 12:27:10 +0200 | [diff] [blame] | 27 | struct ehci_pci_priv *priv = dev_get_priv(dev); |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 28 | struct ehci_hccr *hccr; |
| 29 | struct ehci_hcor *hcor; |
Marek Vasut | 1335e77 | 2018-08-07 12:27:10 +0200 | [diff] [blame] | 30 | int ret; |
Simon Glass | 09c5c16 | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 31 | u32 cmd; |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 32 | |
Marek Vasut | 1335e77 | 2018-08-07 12:27:10 +0200 | [diff] [blame] | 33 | ret = ehci_setup_phy(dev, &priv->phy, 0); |
| 34 | if (ret) |
| 35 | return ret; |
| 36 | |
Simon Glass | 09c5c16 | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 37 | hccr = (struct ehci_hccr *)dm_pci_map_bar(dev, |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 38 | PCI_BASE_ADDRESS_0, PCI_REGION_MEM); |
Simon Glass | 09c5c16 | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 39 | hcor = (struct ehci_hcor *)((uintptr_t) hccr + |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 40 | HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
| 41 | |
Simon Glass | b11e298 | 2016-09-25 21:33:21 -0600 | [diff] [blame] | 42 | debug("EHCI-PCI init hccr %#lx and hcor %#lx hc_length %d\n", |
| 43 | (ulong)hccr, (ulong)hcor, |
Simon Glass | 09c5c16 | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 44 | (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 45 | |
| 46 | *ret_hccr = hccr; |
| 47 | *ret_hcor = hcor; |
| 48 | |
| 49 | /* enable busmaster */ |
Simon Glass | 09c5c16 | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 50 | dm_pci_read_config32(dev, PCI_COMMAND, &cmd); |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 51 | cmd |= PCI_COMMAND_MASTER; |
Simon Glass | 09c5c16 | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 52 | dm_pci_write_config32(dev, PCI_COMMAND, cmd); |
Marek Vasut | 1335e77 | 2018-08-07 12:27:10 +0200 | [diff] [blame] | 53 | |
| 54 | return 0; |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 55 | } |
| 56 | |
Simon Glass | 09c5c16 | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 57 | #else |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 58 | |
Michael Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 59 | #ifdef CONFIG_PCI_EHCI_DEVICE |
| 60 | static struct pci_device_id ehci_pci_ids[] = { |
| 61 | /* Please add supported PCI EHCI controller ids here */ |
Trübenbach, Ralf | 0a5f7e1 | 2011-03-31 16:46:47 +0000 | [diff] [blame] | 62 | {0x1033, 0x00E0}, /* NEC */ |
Wolfgang Denk | 4db2fa7 | 2011-04-05 12:24:20 +0200 | [diff] [blame] | 63 | {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */ |
Trübenbach, Ralf | 0a5f7e1 | 2011-03-31 16:46:47 +0000 | [diff] [blame] | 64 | {0x12D8, 0x400F}, /* Pericom */ |
Michael Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 65 | {0, 0} |
| 66 | }; |
| 67 | #endif |
| 68 | |
Simon Glass | 09c5c16 | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 69 | static 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 Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 94 | /* |
| 95 | * Create the appropriate control structures to manage |
| 96 | * a new EHCI host controller. |
| 97 | */ |
Troy Kisky | 127efc4 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 98 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 99 | struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor) |
Michael Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 100 | { |
| 101 | pci_dev_t pdev; |
Michael Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 102 | |
Vincent Palatin | 7c38e90 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 103 | #ifdef CONFIG_PCI_EHCI_DEVICE |
Michael Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 104 | pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE); |
Vincent Palatin | 7c38e90 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 105 | #else |
Simon Glass | 4fd4672 | 2015-01-27 22:13:30 -0700 | [diff] [blame] | 106 | pdev = pci_find_class(PCI_CLASS_SERIAL_USB_EHCI, index); |
Vincent Palatin | 7c38e90 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 107 | #endif |
| 108 | if (pdev < 0) { |
Michael Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 109 | printf("EHCI host controller not found\n"); |
| 110 | return -1; |
| 111 | } |
Simon Glass | 09c5c16 | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 112 | ehci_pci_legacy_init(pdev, ret_hccr, ret_hcor); |
Michael Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 113 | |
Michael Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * Destroy the appropriate control structures corresponding |
| 119 | * the the EHCI host controller. |
| 120 | */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 121 | int ehci_hcd_stop(int index) |
Michael Trimarchi | 8fea291 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 122 | { |
| 123 | return 0; |
| 124 | } |
Sven Schwermer | fd09c20 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 125 | #endif /* !CONFIG_IS_ENABLED(DM_USB) */ |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 126 | |
Sven Schwermer | fd09c20 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 127 | #if CONFIG_IS_ENABLED(DM_USB) |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 128 | static int ehci_pci_probe(struct udevice *dev) |
| 129 | { |
| 130 | struct ehci_hccr *hccr; |
| 131 | struct ehci_hcor *hcor; |
Marek Vasut | 1335e77 | 2018-08-07 12:27:10 +0200 | [diff] [blame] | 132 | int ret; |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 133 | |
Marek Vasut | 1335e77 | 2018-08-07 12:27:10 +0200 | [diff] [blame] | 134 | ret = ehci_pci_init(dev, &hccr, &hcor); |
| 135 | if (ret) |
| 136 | return ret; |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 137 | |
| 138 | return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST); |
| 139 | } |
| 140 | |
Marek Vasut | 1335e77 | 2018-08-07 12:27:10 +0200 | [diff] [blame] | 141 | static 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 Glass | 907eed2 | 2016-01-17 16:11:07 -0700 | [diff] [blame] | 153 | static const struct udevice_id ehci_pci_ids[] = { |
| 154 | { .compatible = "ehci-pci" }, |
| 155 | { } |
| 156 | }; |
| 157 | |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 158 | U_BOOT_DRIVER(ehci_pci) = { |
| 159 | .name = "ehci_pci", |
| 160 | .id = UCLASS_USB, |
| 161 | .probe = ehci_pci_probe, |
Marek Vasut | 1335e77 | 2018-08-07 12:27:10 +0200 | [diff] [blame] | 162 | .remove = ehci_pci_remove, |
Simon Glass | 907eed2 | 2016-01-17 16:11:07 -0700 | [diff] [blame] | 163 | .of_match = ehci_pci_ids, |
Simon Glass | 2b53b07 | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 164 | .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 | |
| 170 | static struct pci_device_id ehci_pci_supported[] = { |
| 171 | { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0) }, |
| 172 | {}, |
| 173 | }; |
| 174 | |
| 175 | U_BOOT_PCI_DEVICE(ehci_pci, ehci_pci_supported); |
| 176 | |
Sven Schwermer | fd09c20 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 177 | #endif /* CONFIG_IS_ENABLED(DM_USB) */ |