blob: bfdb61aa1ad86b4614391c2775d145d402c2c6ac [file] [log] [blame]
Duncan Laurie3c9f1742013-11-01 13:34:00 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2013 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <arch/acpi.h>
21#include <console/console.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
25#include <stdint.h>
26#include <reg_script.h>
27
28#include <baytrail/iomap.h>
29#include <baytrail/iosf.h>
30#include <baytrail/pci_devs.h>
31#include <baytrail/pmc.h>
32#include <baytrail/ramstage.h>
33#include <baytrail/ehci.h>
34
35#include "chip.h"
36
Aaron Durbin616f3942013-12-10 17:12:44 -080037static const struct reg_script ehci_init_script[] = {
Duncan Laurie3c9f1742013-11-01 13:34:00 -070038 /* Enable S0 PLL shutdown
39 * D29:F0:7A[12,10,7,6,4,3,2,1]=11111111b */
40 REG_PCI_OR16(0x7a, 0x14de),
41 /* Enable SB local clock gating
42 * D29:F0:7C[14,3,2]=111b (14 set in clock gating step) */
43 REG_PCI_OR32(0x7c, 0x0000000c),
44 REG_PCI_OR32(0x8c, 0x00000001),
45 /* Enable dynamic clock gating 0x4001=0xCE */
46 REG_IOSF_RMW(IOSF_PORT_USBPHY, 0x4001, 0xFFFFFF00, 0xCE),
47 /* Magic RCBA register set sequence */
48 /* RCBA + 0x200=0x1 */
49 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x200, 0x00000001),
50 /* RCBA + 0x204=0x2 */
51 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x204, 0x00000002),
52 /* RCBA + 0x208=0x0 */
53 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x208, 0x00000000),
54 /* RCBA + 0x240[4,3,2,1,0]=00000b */
55 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x240, ~0x0000001f, 0),
56 /* RCBA + 0x318[9,8,6,5,4,3,2,1,0]=000000111b */
57 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x318, ~0x00000378, 0x00000007),
58 /* RCBA + 0x31c[3,2,1,0]=0011b */
59 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x31c, ~0x0000000c, 0x00000003),
60 REG_SCRIPT_END
61};
62
Aaron Durbin616f3942013-12-10 17:12:44 -080063static const struct reg_script ehci_clock_gating_script[] = {
Duncan Laurie3c9f1742013-11-01 13:34:00 -070064 /* Enable SB local clock gating */
65 REG_PCI_OR32(0x7c, 0x00004000),
66 /* RCBA + 0x284=0xbe (step B0+) */
67 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x284, 0x000000be),
68 REG_SCRIPT_END
69};
70
Aaron Durbin616f3942013-12-10 17:12:44 -080071static const struct reg_script ehci_disable_script[] = {
Duncan Laurie3c9f1742013-11-01 13:34:00 -070072 /* Clear Run/Stop Bit */
73 REG_RES_RMW32(PCI_BASE_ADDRESS_0, USB2CMD, ~USB2CMD_RS, 0),
74 /* Wait for HC Halted */
75 REG_RES_POLL32(PCI_BASE_ADDRESS_0, USB2STS,
76 USB2STS_HCHALT, USB2STS_HCHALT, 10000),
77 /* Disable Interrupts */
78 REG_PCI_OR32(EHCI_CMD_STS, INTRDIS),
79 /* Disable Asynchronous and Periodic Scheduler */
80 REG_RES_RMW32(PCI_BASE_ADDRESS_0, USB2CMD,
81 ~(USB2CMD_ASE | USB2CMD_PSE), 0),
82 /* Disable port wake */
83 REG_PCI_RMW32(EHCI_SBRN_FLA_PWC, ~(PORTWKIMP | PORTWKCAPMASK), 0),
84 /* Set Function Disable bit in RCBA */
85 REG_MMIO_OR32(RCBA_BASE_ADDRESS + RCBA_FUNC_DIS, RCBA_EHCI_DIS),
86 REG_SCRIPT_END
87};
88
Aaron Durbin616f3942013-12-10 17:12:44 -080089static const struct reg_script ehci_hc_reset[] = {
90 REG_RES_OR16(PCI_BASE_ADDRESS_0, USB2CMD, USB2CMD_HCRESET),
91 REG_SCRIPT_END
92};
93
Duncan Laurie3c9f1742013-11-01 13:34:00 -070094static void usb2_phy_init(device_t dev)
95{
96 struct soc_intel_baytrail_config *config = dev->chip_info;
97 struct reg_script usb2_phy_script[] = {
98 /* USB3PHYInit() */
Kane Chen314c4c32014-07-17 09:51:50 -070099 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_COMPBG,
100 config->usb2_comp_bg),
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700101 /* Per port phy settings, set in devicetree.cb */
102 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_PER_PORT_LANE0,
103 config->usb2_per_port_lane0),
104 REG_IOSF_WRITE(IOSF_PORT_USBPHY,
105 USBPHY_PER_PORT_RCOMP_HS_PULLUP0,
106 config->usb2_per_port_rcomp_hs_pullup0),
107 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_PER_PORT_LANE1,
108 config->usb2_per_port_lane1),
109 REG_IOSF_WRITE(IOSF_PORT_USBPHY,
110 USBPHY_PER_PORT_RCOMP_HS_PULLUP1,
111 config->usb2_per_port_rcomp_hs_pullup1),
112 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_PER_PORT_LANE2,
113 config->usb2_per_port_lane2),
114 REG_IOSF_WRITE(IOSF_PORT_USBPHY,
115 USBPHY_PER_PORT_RCOMP_HS_PULLUP2,
116 config->usb2_per_port_rcomp_hs_pullup2),
117 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_PER_PORT_LANE3,
118 config->usb2_per_port_lane3),
119 REG_IOSF_WRITE(IOSF_PORT_USBPHY,
120 USBPHY_PER_PORT_RCOMP_HS_PULLUP3,
121 config->usb2_per_port_rcomp_hs_pullup3),
122 REG_SCRIPT_END
123 };
124 reg_script_run(usb2_phy_script);
125}
126
127static void ehci_init(device_t dev)
128{
129 struct soc_intel_baytrail_config *config = dev->chip_info;
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700130 struct reg_script ehci_hc_init[] = {
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700131 /* Controller init */
132 REG_SCRIPT_NEXT(ehci_init_script),
133 /* Enable clock gating */
134 REG_SCRIPT_NEXT(ehci_clock_gating_script),
135 /*
136 * Disable ports if requested
137 */
138 /* Open per-port disable control override */
139 REG_IO_RMW16(ACPI_BASE_ADDRESS + UPRWC, ~0, UPRWC_WR_EN),
140 REG_PCI_WRITE8(EHCI_USB2PDO, config->usb2_port_disable_mask),
141 /* Close per-port disable control override */
142 REG_IO_RMW16(ACPI_BASE_ADDRESS + UPRWC, ~UPRWC_WR_EN, 0),
143 REG_SCRIPT_END
144 };
145
146 /* Don't reset controller in S3 resume path */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300147 if (!acpi_is_wakeup_s3())
Aaron Durbin616f3942013-12-10 17:12:44 -0800148 reg_script_run_on_dev(dev, ehci_hc_reset);
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700149
150 /* Disable controller if ports are routed to XHCI */
151 if (config->usb_route_to_xhci) {
152 /* Disable controller */
Aaron Durbin616f3942013-12-10 17:12:44 -0800153 reg_script_run_on_dev(dev, ehci_disable_script);
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700154
155 /* Hide device with southcluster function */
156 dev->enabled = 0;
157 southcluster_enable_dev(dev);
158 } else {
159 /* Initialize EHCI controller */
Aaron Durbin616f3942013-12-10 17:12:44 -0800160 reg_script_run_on_dev(dev, ehci_hc_init);
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700161 }
162
163 /* Setup USB2 PHY based on board config */
164 usb2_phy_init(dev);
165}
166
167static struct device_operations ehci_device_ops = {
168 .read_resources = pci_dev_read_resources,
169 .set_resources = pci_dev_set_resources,
170 .enable_resources = pci_dev_enable_resources,
171 .init = ehci_init,
172 .ops_pci = &soc_pci_ops,
173};
174
175static const struct pci_driver baytrail_ehci __pci_driver = {
176 .ops = &ehci_device_ops,
177 .vendor = PCI_VENDOR_ID_INTEL,
178 .device = EHCI_DEVID
179};