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