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> |
Vincent Palatin | 8d45289 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 9 | #include <errno.h> |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 10 | #include <pci.h> |
| 11 | #include <usb.h> |
Jean-Christophe PLAGNIOL-VILLARD | 8f6bcf4 | 2009-04-03 12:46:58 +0200 | [diff] [blame] | 12 | |
| 13 | #include "ehci.h" |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 14 | |
| 15 | #ifdef CONFIG_PCI_EHCI_DEVICE |
| 16 | static struct pci_device_id ehci_pci_ids[] = { |
| 17 | /* Please add supported PCI EHCI controller ids here */ |
Trübenbach, Ralf | d2c9188 | 2011-03-31 16:46:47 +0000 | [diff] [blame] | 18 | {0x1033, 0x00E0}, /* NEC */ |
Wolfgang Denk | e936628 | 2011-04-05 12:24:20 +0200 | [diff] [blame] | 19 | {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */ |
Trübenbach, Ralf | d2c9188 | 2011-03-31 16:46:47 +0000 | [diff] [blame] | 20 | {0x12D8, 0x400F}, /* Pericom */ |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 21 | {0, 0} |
| 22 | }; |
Vincent Palatin | 8d45289 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 23 | #else |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 24 | #endif |
| 25 | |
| 26 | /* |
| 27 | * Create the appropriate control structures to manage |
| 28 | * a new EHCI host controller. |
| 29 | */ |
Troy Kisky | 7d6bbb9 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 30 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 31 | struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor) |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 32 | { |
| 33 | pci_dev_t pdev; |
Vincent Palatin | 8d45289 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 34 | uint32_t cmd; |
Vincent Palatin | 871be85 | 2013-03-12 03:45:31 +0000 | [diff] [blame] | 35 | struct ehci_hccr *hccr; |
| 36 | struct ehci_hcor *hcor; |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 37 | |
Vincent Palatin | 8d45289 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 38 | #ifdef CONFIG_PCI_EHCI_DEVICE |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 39 | pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE); |
Vincent Palatin | 8d45289 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 40 | #else |
Simon Glass | eeb1d28 | 2015-01-27 22:13:30 -0700 | [diff] [blame] | 41 | pdev = pci_find_class(PCI_CLASS_SERIAL_USB_EHCI, index); |
Vincent Palatin | 8d45289 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 42 | #endif |
| 43 | if (pdev < 0) { |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 44 | printf("EHCI host controller not found\n"); |
| 45 | return -1; |
| 46 | } |
| 47 | |
Vincent Palatin | 871be85 | 2013-03-12 03:45:31 +0000 | [diff] [blame] | 48 | hccr = (struct ehci_hccr *)pci_map_bar(pdev, |
Zhao Chenhui | 20799c9 | 2011-04-19 10:47:05 +0800 | [diff] [blame] | 49 | PCI_BASE_ADDRESS_0, PCI_REGION_MEM); |
Vincent Palatin | 871be85 | 2013-03-12 03:45:31 +0000 | [diff] [blame] | 50 | hcor = (struct ehci_hcor *)((uint32_t) hccr + |
| 51 | HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 52 | |
Florian Fainelli | 17e648b | 2010-10-15 15:53:45 +0200 | [diff] [blame] | 53 | debug("EHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n", |
Vincent Palatin | 871be85 | 2013-03-12 03:45:31 +0000 | [diff] [blame] | 54 | (uint32_t)hccr, (uint32_t)hcor, |
| 55 | (uint32_t)HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
| 56 | |
| 57 | *ret_hccr = hccr; |
| 58 | *ret_hcor = hcor; |
Florian Fainelli | 17e648b | 2010-10-15 15:53:45 +0200 | [diff] [blame] | 59 | |
Vincent Palatin | 8d45289 | 2012-12-13 22:58:27 -0800 | [diff] [blame] | 60 | /* enable busmaster */ |
| 61 | pci_read_config_dword(pdev, PCI_COMMAND, &cmd); |
| 62 | cmd |= PCI_COMMAND_MASTER; |
| 63 | pci_write_config_dword(pdev, PCI_COMMAND, cmd); |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | * Destroy the appropriate control structures corresponding |
| 69 | * the the EHCI host controller. |
| 70 | */ |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 71 | int ehci_hcd_stop(int index) |
Michael Trimarchi | ebc8300 | 2008-12-31 10:32:41 +0100 | [diff] [blame] | 72 | { |
| 73 | return 0; |
| 74 | } |