blob: b9eabc55936a2aa47574c543b5f0db68019c03c7 [file] [log] [blame]
Michael Trimarchi8fea2912008-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 Palatin7c38e902012-12-13 22:58:27 -080022#include <errno.h>
Michael Trimarchi8fea2912008-12-31 10:32:41 +010023#include <pci.h>
24#include <usb.h>
Jean-Christophe PLAGNIOL-VILLARD2731b9a2009-04-03 12:46:58 +020025
26#include "ehci.h"
Michael Trimarchi8fea2912008-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, Ralf0a5f7e12011-03-31 16:46:47 +000031 {0x1033, 0x00E0}, /* NEC */
Wolfgang Denk4db2fa72011-04-05 12:24:20 +020032 {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */
Trübenbach, Ralf0a5f7e12011-03-31 16:46:47 +000033 {0x12D8, 0x400F}, /* Pericom */
Michael Trimarchi8fea2912008-12-31 10:32:41 +010034 {0, 0}
35};
Vincent Palatin7c38e902012-12-13 22:58:27 -080036#else
Michael Trimarchi8fea2912008-12-31 10:32:41 +010037#endif
38
39/*
40 * Create the appropriate control structures to manage
41 * a new EHCI host controller.
42 */
Troy Kisky127efc42013-10-10 15:27:57 -070043int ehci_hcd_init(int index, enum usb_init_type init,
44 struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor)
Michael Trimarchi8fea2912008-12-31 10:32:41 +010045{
46 pci_dev_t pdev;
Vincent Palatin7c38e902012-12-13 22:58:27 -080047 uint32_t cmd;
Vincent Palatinae003d02013-03-12 03:45:31 +000048 struct ehci_hccr *hccr;
49 struct ehci_hcor *hcor;
Michael Trimarchi8fea2912008-12-31 10:32:41 +010050
Vincent Palatin7c38e902012-12-13 22:58:27 -080051#ifdef CONFIG_PCI_EHCI_DEVICE
Michael Trimarchi8fea2912008-12-31 10:32:41 +010052 pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE);
Vincent Palatin7c38e902012-12-13 22:58:27 -080053#else
Simon Glass4fd46722015-01-27 22:13:30 -070054 pdev = pci_find_class(PCI_CLASS_SERIAL_USB_EHCI, index);
Vincent Palatin7c38e902012-12-13 22:58:27 -080055#endif
56 if (pdev < 0) {
Michael Trimarchi8fea2912008-12-31 10:32:41 +010057 printf("EHCI host controller not found\n");
58 return -1;
59 }
60
Vincent Palatinae003d02013-03-12 03:45:31 +000061 hccr = (struct ehci_hccr *)pci_map_bar(pdev,
Zhao Chenhuiae46d2a2011-04-19 10:47:05 +080062 PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
Vincent Palatinae003d02013-03-12 03:45:31 +000063 hcor = (struct ehci_hcor *)((uint32_t) hccr +
64 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
Michael Trimarchi8fea2912008-12-31 10:32:41 +010065
Florian Fainelliaf68c062010-10-15 15:53:45 +020066 debug("EHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n",
Vincent Palatinae003d02013-03-12 03:45:31 +000067 (uint32_t)hccr, (uint32_t)hcor,
68 (uint32_t)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
69
70 *ret_hccr = hccr;
71 *ret_hcor = hcor;
Florian Fainelliaf68c062010-10-15 15:53:45 +020072
Vincent Palatin7c38e902012-12-13 22:58:27 -080073 /* enable busmaster */
74 pci_read_config_dword(pdev, PCI_COMMAND, &cmd);
75 cmd |= PCI_COMMAND_MASTER;
76 pci_write_config_dword(pdev, PCI_COMMAND, cmd);
Michael Trimarchi8fea2912008-12-31 10:32:41 +010077 return 0;
78}
79
80/*
81 * Destroy the appropriate control structures corresponding
82 * the the EHCI host controller.
83 */
Lucas Stach676ae062012-09-26 00:14:35 +020084int ehci_hcd_stop(int index)
Michael Trimarchi8fea2912008-12-31 10:32:41 +010085{
86 return 0;
87}