Factor out a few commonly duplicated functions from northbridge.c.
[coreboot.git] / src / southbridge / intel / i82801bx / i82801bx_usb_ehci.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2005 Tyan Computer
5  * (Written by Yinghai Lu <yinghailu@gmail.com> for Tyan Computer>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #include <console/console.h>
23 #include <device/device.h>
24 #include <device/pci.h>
25 #include <device/pci_ids.h>
26 #include "i82801bx.h"
27
28 static void usb_ehci_init(struct device *dev)
29 {
30         /* TODO: Is any special init really needed? */
31         uint32_t cmd;
32
33         printk(BIOS_DEBUG, "EHCI: Setting up controller.. ");
34         cmd = pci_read_config32(dev, PCI_COMMAND);
35         pci_write_config32(dev, PCI_COMMAND, cmd | PCI_COMMAND_MASTER);
36
37         printk(BIOS_DEBUG, "done.\n");
38 }
39
40 static void usb_ehci_set_subsystem(device_t dev, unsigned vendor,
41                                    unsigned device)
42 {
43         uint8_t access_cntl;
44
45         access_cntl = pci_read_config8(dev, 0x80);
46
47         /* Enable writes to protected registers. */
48         pci_write_config8(dev, 0x80, access_cntl | 1);
49
50         /* Write the subsystem vendor and device ID. */
51         pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
52                            ((device & 0xffff) << 16) | (vendor & 0xffff));
53
54         /* Restore protection. */
55         pci_write_config8(dev, 0x80, access_cntl);
56 }
57
58 static struct pci_operations lops_pci = {
59         .set_subsystem  = &usb_ehci_set_subsystem,
60 };
61
62 static struct device_operations usb_ehci_ops = {
63         .read_resources         = pci_dev_read_resources,
64         .set_resources          = pci_dev_set_resources,
65         .enable_resources       = pci_dev_enable_resources,
66         .init                   = usb_ehci_init,
67         .scan_bus               = 0,
68         .enable                 = i82801bx_enable,
69         .ops_pci                = &lops_pci,
70 };
71
72 /* 82801DB and 82801DBM */
73 static const struct pci_driver i82801db_usb_ehci __pci_driver = {
74         .ops    = &usb_ehci_ops,
75         .vendor = PCI_VENDOR_ID_INTEL,
76         .device = 0x24cd,
77 };
78
79 /* 82801EB and 82801ER */
80 static const struct pci_driver i82801ex_usb_ehci __pci_driver = {
81         .ops    = &usb_ehci_ops,
82         .vendor = PCI_VENDOR_ID_INTEL,
83         .device = 0x24dd,
84 };