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