Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2007-2008, Juniper Networks, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Simon Glass | 1b2e365 | 2015-07-06 16:47:42 -0600 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0 |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | d0065dd | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 9 | #include <dm.h> |
Vincent Palatin | 8d45289 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 10 | #include <errno.h> |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 11 | #include <pci.h> |
| 12 | #include <usb.h> |
Alexey Brodkin | 1ddd540 | 2017-06-05 10:19:26 +0300 | [diff] [blame] | 13 | #include <asm/io.h> |
Jean-Christophe PLAGNIOL-VILLARD | 8f6bcf4 | 2009-04-03 12:46:58 +0200 | [diff] [blame] | 14 | |
| 15 | #include "ehci.h" |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 16 | |
Simon Glass | d0065dd | 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; |
| 20 | }; |
| 21 | |
Simon Glass | 261095b | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 22 | #ifdef CONFIG_DM_USB |
| 23 | |
| 24 | static void ehci_pci_init(struct udevice *dev, struct ehci_hccr **ret_hccr, |
| 25 | struct ehci_hcor **ret_hcor) |
Simon Glass | d0065dd | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 26 | { |
| 27 | struct ehci_hccr *hccr; |
| 28 | struct ehci_hcor *hcor; |
Simon Glass | 261095b | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 29 | u32 cmd; |
Simon Glass | d0065dd | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 30 | |
Simon Glass | 261095b | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 31 | hccr = (struct ehci_hccr *)dm_pci_map_bar(dev, |
Simon Glass | d0065dd | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 32 | PCI_BASE_ADDRESS_0, PCI_REGION_MEM); |
Simon Glass | 261095b | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 33 | hcor = (struct ehci_hcor *)((uintptr_t) hccr + |
Simon Glass | d0065dd | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 34 | HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
| 35 | |
Simon Glass | 26a2b2d | 2016-09-25 21:33:21 -0600 | [diff] [blame] | 36 | debug("EHCI-PCI init hccr %#lx and hcor %#lx hc_length %d\n", |
| 37 | (ulong)hccr, (ulong)hcor, |
Simon Glass | 261095b | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 38 | (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
Simon Glass | d0065dd | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 39 | |
| 40 | *ret_hccr = hccr; |
| 41 | *ret_hcor = hcor; |
| 42 | |
| 43 | /* enable busmaster */ |
Simon Glass | 261095b | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 44 | dm_pci_read_config32(dev, PCI_COMMAND, &cmd); |
Simon Glass | d0065dd | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 45 | cmd |= PCI_COMMAND_MASTER; |
Simon Glass | 261095b | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 46 | dm_pci_write_config32(dev, PCI_COMMAND, cmd); |
Simon Glass | d0065dd | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 47 | } |
| 48 | |
Simon Glass | 261095b | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 49 | #else |
Simon Glass | d0065dd | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 50 | |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 51 | #ifdef CONFIG_PCI_EHCI_DEVICE |
| 52 | static struct pci_device_id ehci_pci_ids[] = { |
| 53 | /* Please add supported PCI EHCI controller ids here */ |
Trübenbach, Ralf | d2c9188 | 2011-03-31 16:46:47 +0000 | [diff] [blame] | 54 | {0x1033, 0x00E0}, /* NEC */ |
Wolfgang Denk | e936628 | 2011-04-05 12:24:20 +0200 | [diff] [blame] | 55 | {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */ |
Trübenbach, Ralf | d2c9188 | 2011-03-31 16:46:47 +0000 | [diff] [blame] | 56 | {0x12D8, 0x400F}, /* Pericom */ |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 57 | {0, 0} |
| 58 | }; |
| 59 | #endif |
| 60 | |
Simon Glass | 261095b | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 61 | static void ehci_pci_legacy_init(pci_dev_t pdev, struct ehci_hccr **ret_hccr, |
| 62 | struct ehci_hcor **ret_hcor) |
| 63 | { |
| 64 | struct ehci_hccr *hccr; |
| 65 | struct ehci_hcor *hcor; |
| 66 | u32 cmd; |
| 67 | |
| 68 | hccr = (struct ehci_hccr *)pci_map_bar(pdev, |
| 69 | PCI_BASE_ADDRESS_0, PCI_REGION_MEM); |
| 70 | hcor = (struct ehci_hcor *)((uintptr_t) hccr + |
| 71 | HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
| 72 | |
| 73 | debug("EHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n", |
| 74 | (u32)hccr, (u32)hcor, |
| 75 | (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
| 76 | |
| 77 | *ret_hccr = hccr; |
| 78 | *ret_hcor = hcor; |
| 79 | |
| 80 | /* enable busmaster */ |
| 81 | pci_read_config_dword(pdev, PCI_COMMAND, &cmd); |
| 82 | cmd |= PCI_COMMAND_MASTER; |
| 83 | pci_write_config_dword(pdev, PCI_COMMAND, cmd); |
| 84 | } |
| 85 | |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 86 | /* |
| 87 | * Create the appropriate control structures to manage |
| 88 | * a new EHCI host controller. |
| 89 | */ |
Troy Kisky | 7d6bbb9 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 90 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 91 | struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor) |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 92 | { |
| 93 | pci_dev_t pdev; |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 94 | |
Vincent Palatin | 8d45289 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 95 | #ifdef CONFIG_PCI_EHCI_DEVICE |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 96 | pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE); |
Vincent Palatin | 8d45289 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 97 | #else |
Simon Glass | eeb1d28 | 2015-01-27 22:13:30 -0700 | [diff] [blame] | 98 | pdev = pci_find_class(PCI_CLASS_SERIAL_USB_EHCI, index); |
Vincent Palatin | 8d45289 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 99 | #endif |
| 100 | if (pdev < 0) { |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 101 | printf("EHCI host controller not found\n"); |
| 102 | return -1; |
| 103 | } |
Simon Glass | 261095b | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 104 | ehci_pci_legacy_init(pdev, ret_hccr, ret_hcor); |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 105 | |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | /* |
| 110 | * Destroy the appropriate control structures corresponding |
| 111 | * the the EHCI host controller. |
| 112 | */ |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 113 | int ehci_hcd_stop(int index) |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 114 | { |
Simon Glass | d0065dd | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | #endif /* nCONFIG_DM_USB */ |
| 118 | |
| 119 | #ifdef CONFIG_DM_USB |
| 120 | static int ehci_pci_probe(struct udevice *dev) |
| 121 | { |
| 122 | struct ehci_hccr *hccr; |
| 123 | struct ehci_hcor *hcor; |
| 124 | |
Simon Glass | 261095b | 2015-11-29 13:18:07 -0700 | [diff] [blame] | 125 | ehci_pci_init(dev, &hccr, &hcor); |
Simon Glass | d0065dd | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 126 | |
| 127 | return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST); |
| 128 | } |
| 129 | |
Simon Glass | 9470c72 | 2016-01-17 16:11:07 -0700 | [diff] [blame] | 130 | static const struct udevice_id ehci_pci_ids[] = { |
| 131 | { .compatible = "ehci-pci" }, |
| 132 | { } |
| 133 | }; |
| 134 | |
Simon Glass | d0065dd | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 135 | U_BOOT_DRIVER(ehci_pci) = { |
| 136 | .name = "ehci_pci", |
| 137 | .id = UCLASS_USB, |
| 138 | .probe = ehci_pci_probe, |
Masahiro Yamada | d41919b | 2016-09-06 22:17:34 +0900 | [diff] [blame] | 139 | .remove = ehci_deregister, |
Simon Glass | 9470c72 | 2016-01-17 16:11:07 -0700 | [diff] [blame] | 140 | .of_match = ehci_pci_ids, |
Simon Glass | d0065dd | 2015-07-06 16:47:53 -0600 | [diff] [blame] | 141 | .ops = &ehci_usb_ops, |
| 142 | .platdata_auto_alloc_size = sizeof(struct usb_platdata), |
| 143 | .priv_auto_alloc_size = sizeof(struct ehci_pci_priv), |
| 144 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 145 | }; |
| 146 | |
| 147 | static struct pci_device_id ehci_pci_supported[] = { |
| 148 | { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0) }, |
| 149 | {}, |
| 150 | }; |
| 151 | |
| 152 | U_BOOT_PCI_DEVICE(ehci_pci, ehci_pci_supported); |
| 153 | |
| 154 | #endif /* CONFIG_DM_USB */ |