blob: e3facb997b7fdaf8d6d560f664dc13606f58ed61 [file] [log] [blame]
Duncan Laurief81a91a2013-11-01 13:32:53 -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 <console/console.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
24#include <stdint.h>
25#include <reg_script.h>
26
27#include <baytrail/iomap.h>
28#include <baytrail/iosf.h>
29#include <baytrail/pci_devs.h>
30#include <baytrail/pmc.h>
31#include <baytrail/ramstage.h>
32#include <baytrail/xhci.h>
33
34#include "chip.h"
35
36struct reg_script usb3_phy_script[] = {
37 /* USB3PHYInit() */
38 REG_IOSF_RMW(IOSF_PORT_USHPHY, USHPHY_CDN_PLL_CONTROL,
39 ~0x00700000, 0x00500000),
40 REG_IOSF_RMW(IOSF_PORT_USHPHY, USHPHY_CDN_VCO_START_CAL_POINT,
41 ~0x001f0000, 0x000A0000),
42 REG_IOSF_RMW(IOSF_PORT_USHPHY, USHPHY_CCDRLF,
43 ~0x0000000f, 0x0000000b),
44 REG_IOSF_RMW(IOSF_PORT_USHPHY, USHPHY_PEAKING_AMP_CONFIG_DIAG,
45 ~0x000000f0, 0x000000f0),
46 REG_IOSF_RMW(IOSF_PORT_USHPHY, USHPHY_OFFSET_COR_CONFIG_DIAG,
47 ~0x000001c0, 0x00000000),
48 REG_IOSF_RMW(IOSF_PORT_USHPHY, USHPHY_VGA_GAIN_CONFIG_DIAG,
49 ~0x00000070, 0x00000020),
50 REG_IOSF_RMW(IOSF_PORT_USHPHY, USHPHY_REE_DAC_CONTROL,
51 ~0x00000002, 0x00000002),
52 REG_IOSF_RMW(IOSF_PORT_USHPHY, USHPHY_CDN_U1_POWER_STATE_DEF,
53 ~0x00000000, 0x00040000),
54 REG_SCRIPT_END
55};
56
57const struct reg_script xhci_init_script[] = {
58 /* CommonXhciHcInit() */
59 /* BAR + 0x0c[31:16] = 0x0200 */
60 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x000c, 0x0000ffff, 0x02000000),
61 /* BAR + 0x0c[7:0] = 0x0a */
62 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x000c, 0xffffff00, 0x0000000a),
63 /* BAR + 0x8094[23,21,14]=111b */
64 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x8094, 0x00a04000),
65 /* BAR + 0x8110[20,11,8,2]=1100b */
66 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x8110, ~0x00000104, 0x00100800),
67 /* BAR + 0x8144[8,7,6]=111b */
68 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x8144, 0x000001c0),
69 /* BAR + 0x8154[21,13,3]=010b */
70 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x8154, ~0x00200008, 0x80002000),
71 /* BAR + 0x816c[19:0]=1110x100000000111100b */
72 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x816c, 0xfff08000, 0x000e0030),
73 /* BAR + 0x8188[26,24]=11b */
74 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x8188, 0x05000000),
75 /* BAR + 0x8174=0x1000c0a*/
76 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x8174, 0xfe000000, 0x01000c0a),
77 /* BAR + 0x854c[29]=0b */
78 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x854c, ~0x20000000, 0),
79 /* BAR + 0x8178[12:0]=0b */
80 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x8178, ~0xffffe000, 0),
81 /* BAR + 0x8164[7:0]=0xff */
82 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x8164, 0x000000ff),
83 /* BAR + 0x0010[10,9,5]=110b */
84 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x0010, ~0x00000020, 0x00000600),
85 /* BAR + 0x8058[20,16,8]=110b */
Duncan Lauriea90a59f52013-11-04 11:22:27 -080086 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x8058, ~0x00000100, 0x00110000),
Duncan Laurief81a91a2013-11-01 13:32:53 -070087 /* BAR + 0x8060[25]=1b */
88 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x8060, 0x02000000),
Duncan Lauriea90a59f52013-11-04 11:22:27 -080089 /* BAR + 0x80e0[16,9,6]=001b, toggle bit 24=1 */
90 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x80e0, ~0x00010200, 0x01000040),
Duncan Laurief81a91a2013-11-01 13:32:53 -070091 /* BAR + 0x80e0 toggle bit 24=0 */
92 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x80e0, ~0x01000000, 0),
93 /* BAR + 0x80f0[20]=0b */
94 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x80f0, ~0x00100000, 0),
95 /* BAR + 0x8008[19]=1b (to enable LPM) */
96 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x8008, 0x00080000),
97 /* BAR + 0x80fc[25]=1b */
98 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x80fc, 0x02000000),
99 /* 0x40/0x44 are written as bytes to avoid touching bit31 */
100 /* D20:F0:40[21,20,18,10,9,8]=111001b (don't write byte3) */
101 REG_PCI_RMW8(0x41, ~0x06, 0x01),
102 /* Except [21,20,19,18]=0001b USB wake W/A is disable IIL1E */
103 REG_PCI_RMW8(0x42, 0x3c, 0x04),
104 /* D20:F0:44[19:14,10,9,7,3:0]=1 (don't write byte3) */
105 REG_PCI_RMW8(0x44, 0x00, 0x8f),
106 REG_PCI_RMW8(0x45, ~0xcf, 0xc6),
107 REG_PCI_RMW8(0x46, ~0x0f, 0x0f),
108 /* BAR + 0x8140 = 0xff00f03c */
109 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x8140, 0, 0xff00f03c),
110 REG_SCRIPT_END
111};
112
113const struct reg_script xhci_clock_gating_script[] = {
114 /* ConfigureXhciClockGating() */
115 /* D20:F0:40[21:19,18,10:8]=000,1,001 (don't write byte 3) */
Duncan Lauriea90a59f52013-11-04 11:22:27 -0800116 REG_PCI_RMW16(0x40, ~0x0600, 0x0100),
Duncan Laurief81a91a2013-11-01 13:32:53 -0700117 REG_PCI_RMW8(0x42, ~0x38, 0x04),
118 /* D20:F0:44[5:3]=001b */
119 REG_PCI_RMW16(0x44, ~0x0030, 0x0008),
120 /* D20:F0:A0[19:18]=01b */
121 REG_PCI_RMW32(0xa0, ~0x00080000, 0x00040000),
122 /* D20:F0:A4[15:0]=0x00 */
123 REG_PCI_WRITE16(0xa4, 0x0000),
124 /* D20:F0:B0[21:17,14:13]=0000000b */
125 REG_PCI_RMW32(0xb0, ~0x00376000, 0x00000000),
126 /* D20:F0:50[31:0]=0x0bce6e5f */
127 REG_PCI_WRITE32(0x50, 0x0bce6e5f),
128 REG_SCRIPT_END
129};
130
131/* Warm Reset a USB3 port */
132static void xhci_reset_port_usb3(device_t dev, int port)
133{
134 struct reg_script reset_port_usb3_script[] = {
Duncan Laurief81a91a2013-11-01 13:32:53 -0700135 /* Issue Warm Port Rest to the port */
136 REG_RES_OR32(PCI_BASE_ADDRESS_0, XHCI_USB3_PORTSC(port),
137 XHCI_USB3_PORTSC_WPR),
138 /* Wait up to 100ms for it to complete */
139 REG_RES_POLL32(PCI_BASE_ADDRESS_0, XHCI_USB3_PORTSC(port),
140 XHCI_USB3_PORTSC_WRC, XHCI_USB3_PORTSC_WRC,
141 XHCI_RESET_TIMEOUT),
142 /* Clear change status bits, do not set PED */
143 REG_RES_RMW32(PCI_BASE_ADDRESS_0, XHCI_USB3_PORTSC(port),
144 ~XHCI_USB3_PORTSC_PED, XHCI_USB3_PORTSC_CHST),
145 REG_SCRIPT_END
146 };
Aaron Durbin616f3942013-12-10 17:12:44 -0800147 reg_script_run_on_dev(dev, reset_port_usb3_script);
Duncan Laurief81a91a2013-11-01 13:32:53 -0700148}
149
150/* Prepare ports to be routed to EHCI or XHCI */
151static void xhci_route_all(device_t dev)
152{
Aaron Durbin616f3942013-12-10 17:12:44 -0800153 static const struct reg_script xhci_route_all_script[] = {
Duncan Laurief81a91a2013-11-01 13:32:53 -0700154 /* USB3 SuperSpeed Enable */
155 REG_PCI_WRITE32(XHCI_USB3PR, BYTM_USB3_PORT_MAP),
156 /* USB2 Port Route to XHCI */
157 REG_PCI_WRITE32(XHCI_USB2PR, BYTM_USB2_PORT_MAP),
158 REG_SCRIPT_END
159 };
160 u32 port_disabled;
161 int port;
162
163 printk(BIOS_INFO, "USB: Route ports to XHCI controller\n");
164
165 /* Route ports to XHCI controller */
Aaron Durbin616f3942013-12-10 17:12:44 -0800166 reg_script_run_on_dev(dev, xhci_route_all_script);
Duncan Laurief81a91a2013-11-01 13:32:53 -0700167
168 /* Reset enabled USB3 ports */
169 port_disabled = pci_read_config32(dev, XHCI_USB3PDO);
170 for (port = 0; port < BYTM_USB3_PORT_COUNT; port++) {
171 if (port_disabled & (1 << port))
172 continue;
173 xhci_reset_port_usb3(dev, port);
174 }
175}
176
177static void xhci_init(device_t dev)
178{
179 struct soc_intel_baytrail_config *config = dev->chip_info;
180 struct reg_script xhci_hc_init[] = {
Duncan Laurief81a91a2013-11-01 13:32:53 -0700181 /* Setup USB3 phy */
182 REG_SCRIPT_NEXT(usb3_phy_script),
183 /* Initialize host controller */
184 REG_SCRIPT_NEXT(xhci_init_script),
185 /* Initialize clock gating */
186 REG_SCRIPT_NEXT(xhci_clock_gating_script),
Duncan Lauriea90a59f52013-11-04 11:22:27 -0800187 /* Finalize XHCC1 and XHCC2 */
188 REG_PCI_RMW32(0x44, ~0x00000000, 0x83c00000),
189 REG_PCI_RMW32(0x40, ~0x00800000, 0x80000000),
Duncan Laurief81a91a2013-11-01 13:32:53 -0700190 /* Set USB2 Port Routing Mask */
191 REG_PCI_WRITE32(XHCI_USB2PRM, BYTM_USB2_PORT_MAP),
192 /* Set USB3 Port Routing Mask */
193 REG_PCI_WRITE32(XHCI_USB3PRM, BYTM_USB3_PORT_MAP),
194 /*
195 * Disable ports if requested
196 */
197 /* Open per-port disable control override */
198 REG_IO_RMW16(ACPI_BASE_ADDRESS + UPRWC, ~0, UPRWC_WR_EN),
199 REG_PCI_WRITE32(XHCI_USB2PDO, config->usb2_port_disable_mask),
200 REG_PCI_WRITE32(XHCI_USB3PDO, config->usb3_port_disable_mask),
201 /* Close per-port disable control override */
202 REG_IO_RMW16(ACPI_BASE_ADDRESS + UPRWC, ~UPRWC_WR_EN, 0),
203 REG_SCRIPT_END
204 };
205
206 /* Initialize XHCI controller */
Aaron Durbin616f3942013-12-10 17:12:44 -0800207 reg_script_run_on_dev(dev, xhci_hc_init);
Duncan Laurief81a91a2013-11-01 13:32:53 -0700208
209 /* Route all ports to XHCI if requested */
210 if (config->usb_route_to_xhci)
211 xhci_route_all(dev);
212}
213
214static struct device_operations xhci_device_ops = {
215 .read_resources = pci_dev_read_resources,
216 .set_resources = pci_dev_set_resources,
217 .enable_resources = pci_dev_enable_resources,
218 .init = xhci_init,
219 .ops_pci = &soc_pci_ops,
220};
221
222static const struct pci_driver baytrail_xhci __pci_driver = {
223 .ops = &xhci_device_ops,
224 .vendor = PCI_VENDOR_ID_INTEL,
225 .device = XHCI_DEVID
226};