blob: 001d141e0d47a9ae6a5634defadb7d9c4d3a210f [file] [log] [blame]
Michael Trimarchiebc83002008-12-31 10:32:41 +01001/*-
2 * Copyright (c) 2007-2008, Juniper Networks, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation version 2 of
8 * the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 * MA 02111-1307 USA
19 */
20
21#include <common.h>
Vincent Palatin8d452892012-12-13 22:58:27 -080022#include <errno.h>
Michael Trimarchiebc83002008-12-31 10:32:41 +010023#include <pci.h>
24#include <usb.h>
Jean-Christophe PLAGNIOL-VILLARD8f6bcf42009-04-03 12:46:58 +020025
26#include "ehci.h"
Michael Trimarchiebc83002008-12-31 10:32:41 +010027
28#ifdef CONFIG_PCI_EHCI_DEVICE
29static struct pci_device_id ehci_pci_ids[] = {
30 /* Please add supported PCI EHCI controller ids here */
Trübenbach, Ralfd2c91882011-03-31 16:46:47 +000031 {0x1033, 0x00E0}, /* NEC */
Wolfgang Denke9366282011-04-05 12:24:20 +020032 {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */
Trübenbach, Ralfd2c91882011-03-31 16:46:47 +000033 {0x12D8, 0x400F}, /* Pericom */
Michael Trimarchiebc83002008-12-31 10:32:41 +010034 {0, 0}
35};
Vincent Palatin8d452892012-12-13 22:58:27 -080036#else
37static pci_dev_t ehci_find_class(void)
38{
39 int bus;
40 int devnum;
41 pci_dev_t bdf;
42 uint32_t class;
43
44 for (bus = 0; bus <= pci_last_busno(); bus++) {
45 for (devnum = 0; devnum < PCI_MAX_PCI_DEVICES-1; devnum++) {
46 pci_read_config_dword(PCI_BDF(bus, devnum, 0),
47 PCI_CLASS_REVISION, &class);
48 if (class >> 16 == 0xffff)
49 continue;
50
51 for (bdf = PCI_BDF(bus, devnum, 0);
52 bdf <= PCI_BDF(bus, devnum,
53 PCI_MAX_PCI_FUNCTIONS - 1);
54 bdf += PCI_BDF(0, 0, 1)) {
55 pci_read_config_dword(bdf, PCI_CLASS_REVISION,
56 &class);
57 if (class >> 8 == PCI_CLASS_SERIAL_USB_EHCI)
58 return bdf;
59 }
60 }
61 }
62
63 return -ENODEV;
64}
Michael Trimarchiebc83002008-12-31 10:32:41 +010065#endif
66
67/*
68 * Create the appropriate control structures to manage
69 * a new EHCI host controller.
70 */
Lucas Stach3494a4c2012-09-26 00:14:35 +020071int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Michael Trimarchiebc83002008-12-31 10:32:41 +010072{
73 pci_dev_t pdev;
Vincent Palatin8d452892012-12-13 22:58:27 -080074 uint32_t cmd;
Michael Trimarchiebc83002008-12-31 10:32:41 +010075
Vincent Palatin8d452892012-12-13 22:58:27 -080076#ifdef CONFIG_PCI_EHCI_DEVICE
Michael Trimarchiebc83002008-12-31 10:32:41 +010077 pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE);
Vincent Palatin8d452892012-12-13 22:58:27 -080078#else
79 pdev = ehci_find_class();
80#endif
81 if (pdev < 0) {
Michael Trimarchiebc83002008-12-31 10:32:41 +010082 printf("EHCI host controller not found\n");
83 return -1;
84 }
85
Lucas Stach3494a4c2012-09-26 00:14:35 +020086 *hccr = (struct ehci_hccr *)pci_map_bar(pdev,
Zhao Chenhui20799c92011-04-19 10:47:05 +080087 PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
Lucas Stach3494a4c2012-09-26 00:14:35 +020088 *hcor = (struct ehci_hcor *)((uint32_t) *hccr +
89 HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Michael Trimarchiebc83002008-12-31 10:32:41 +010090
Florian Fainelli17e648b2010-10-15 15:53:45 +020091 debug("EHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n",
Lucas Stach3494a4c2012-09-26 00:14:35 +020092 (uint32_t)*hccr, (uint32_t)*hcor,
93 (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Florian Fainelli17e648b2010-10-15 15:53:45 +020094
Vincent Palatin8d452892012-12-13 22:58:27 -080095 /* enable busmaster */
96 pci_read_config_dword(pdev, PCI_COMMAND, &cmd);
97 cmd |= PCI_COMMAND_MASTER;
98 pci_write_config_dword(pdev, PCI_COMMAND, cmd);
Michael Trimarchiebc83002008-12-31 10:32:41 +010099 return 0;
100}
101
102/*
103 * Destroy the appropriate control structures corresponding
104 * the the EHCI host controller.
105 */
Lucas Stach3494a4c2012-09-26 00:14:35 +0200106int ehci_hcd_stop(int index)
Michael Trimarchiebc83002008-12-31 10:32:41 +0100107{
108 return 0;
109}