blob: e2ff3189b24d28e24dae64d8153cc5d98414a171 [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.
Duncan Laurie3c9f1742013-11-01 13:34:00 -070014 */
15
16#include <arch/acpi.h>
17#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include <stdint.h>
22#include <reg_script.h>
23
Julius Werner18ea2d32014-10-07 16:42:17 -070024#include <soc/iomap.h>
25#include <soc/iosf.h>
26#include <soc/pci_devs.h>
27#include <soc/pmc.h>
28#include <soc/ramstage.h>
29#include <soc/ehci.h>
Duncan Laurie3c9f1742013-11-01 13:34:00 -070030
31#include "chip.h"
32
Aaron Durbin616f3942013-12-10 17:12:44 -080033static const struct reg_script ehci_init_script[] = {
Duncan Laurie3c9f1742013-11-01 13:34:00 -070034 /* Enable S0 PLL shutdown
35 * D29:F0:7A[12,10,7,6,4,3,2,1]=11111111b */
36 REG_PCI_OR16(0x7a, 0x14de),
37 /* Enable SB local clock gating
38 * D29:F0:7C[14,3,2]=111b (14 set in clock gating step) */
39 REG_PCI_OR32(0x7c, 0x0000000c),
40 REG_PCI_OR32(0x8c, 0x00000001),
41 /* Enable dynamic clock gating 0x4001=0xCE */
42 REG_IOSF_RMW(IOSF_PORT_USBPHY, 0x4001, 0xFFFFFF00, 0xCE),
43 /* Magic RCBA register set sequence */
44 /* RCBA + 0x200=0x1 */
45 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x200, 0x00000001),
46 /* RCBA + 0x204=0x2 */
47 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x204, 0x00000002),
48 /* RCBA + 0x208=0x0 */
49 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x208, 0x00000000),
50 /* RCBA + 0x240[4,3,2,1,0]=00000b */
51 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x240, ~0x0000001f, 0),
52 /* RCBA + 0x318[9,8,6,5,4,3,2,1,0]=000000111b */
53 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x318, ~0x00000378, 0x00000007),
54 /* RCBA + 0x31c[3,2,1,0]=0011b */
55 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x31c, ~0x0000000c, 0x00000003),
56 REG_SCRIPT_END
57};
58
Aaron Durbin616f3942013-12-10 17:12:44 -080059static const struct reg_script ehci_clock_gating_script[] = {
Duncan Laurie3c9f1742013-11-01 13:34:00 -070060 /* Enable SB local clock gating */
61 REG_PCI_OR32(0x7c, 0x00004000),
62 /* RCBA + 0x284=0xbe (step B0+) */
63 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x284, 0x000000be),
64 REG_SCRIPT_END
65};
66
Aaron Durbin616f3942013-12-10 17:12:44 -080067static const struct reg_script ehci_disable_script[] = {
Duncan Laurie3c9f1742013-11-01 13:34:00 -070068 /* Clear Run/Stop Bit */
69 REG_RES_RMW32(PCI_BASE_ADDRESS_0, USB2CMD, ~USB2CMD_RS, 0),
70 /* Wait for HC Halted */
71 REG_RES_POLL32(PCI_BASE_ADDRESS_0, USB2STS,
72 USB2STS_HCHALT, USB2STS_HCHALT, 10000),
73 /* Disable Interrupts */
74 REG_PCI_OR32(EHCI_CMD_STS, INTRDIS),
75 /* Disable Asynchronous and Periodic Scheduler */
76 REG_RES_RMW32(PCI_BASE_ADDRESS_0, USB2CMD,
77 ~(USB2CMD_ASE | USB2CMD_PSE), 0),
78 /* Disable port wake */
79 REG_PCI_RMW32(EHCI_SBRN_FLA_PWC, ~(PORTWKIMP | PORTWKCAPMASK), 0),
80 /* Set Function Disable bit in RCBA */
81 REG_MMIO_OR32(RCBA_BASE_ADDRESS + RCBA_FUNC_DIS, RCBA_EHCI_DIS),
82 REG_SCRIPT_END
83};
84
Aaron Durbin616f3942013-12-10 17:12:44 -080085static const struct reg_script ehci_hc_reset[] = {
86 REG_RES_OR16(PCI_BASE_ADDRESS_0, USB2CMD, USB2CMD_HCRESET),
87 REG_SCRIPT_END
88};
89
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020090static void usb2_phy_init(struct device *dev)
Duncan Laurie3c9f1742013-11-01 13:34:00 -070091{
92 struct soc_intel_baytrail_config *config = dev->chip_info;
Kane Chen374f27b2014-07-17 11:31:57 -070093 u32 usb2_comp_bg = (config->usb2_comp_bg == 0 ?
94 0x4700 : config->usb2_comp_bg);
Duncan Laurie3c9f1742013-11-01 13:34:00 -070095 struct reg_script usb2_phy_script[] = {
96 /* USB3PHYInit() */
Kane Chen314c4c32014-07-17 09:51:50 -070097 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_COMPBG,
Kane Chen374f27b2014-07-17 11:31:57 -070098 usb2_comp_bg),
Duncan Laurie3c9f1742013-11-01 13:34:00 -070099 /* Per port phy settings, set in devicetree.cb */
100 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_PER_PORT_LANE0,
101 config->usb2_per_port_lane0),
102 REG_IOSF_WRITE(IOSF_PORT_USBPHY,
103 USBPHY_PER_PORT_RCOMP_HS_PULLUP0,
104 config->usb2_per_port_rcomp_hs_pullup0),
105 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_PER_PORT_LANE1,
106 config->usb2_per_port_lane1),
107 REG_IOSF_WRITE(IOSF_PORT_USBPHY,
108 USBPHY_PER_PORT_RCOMP_HS_PULLUP1,
109 config->usb2_per_port_rcomp_hs_pullup1),
110 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_PER_PORT_LANE2,
111 config->usb2_per_port_lane2),
112 REG_IOSF_WRITE(IOSF_PORT_USBPHY,
113 USBPHY_PER_PORT_RCOMP_HS_PULLUP2,
114 config->usb2_per_port_rcomp_hs_pullup2),
115 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_PER_PORT_LANE3,
116 config->usb2_per_port_lane3),
117 REG_IOSF_WRITE(IOSF_PORT_USBPHY,
118 USBPHY_PER_PORT_RCOMP_HS_PULLUP3,
119 config->usb2_per_port_rcomp_hs_pullup3),
120 REG_SCRIPT_END
121 };
122 reg_script_run(usb2_phy_script);
123}
124
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200125static void ehci_init(struct device *dev)
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700126{
127 struct soc_intel_baytrail_config *config = dev->chip_info;
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700128 struct reg_script ehci_hc_init[] = {
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700129 /* Controller init */
130 REG_SCRIPT_NEXT(ehci_init_script),
131 /* Enable clock gating */
132 REG_SCRIPT_NEXT(ehci_clock_gating_script),
133 /*
134 * Disable ports if requested
135 */
136 /* Open per-port disable control override */
137 REG_IO_RMW16(ACPI_BASE_ADDRESS + UPRWC, ~0, UPRWC_WR_EN),
138 REG_PCI_WRITE8(EHCI_USB2PDO, config->usb2_port_disable_mask),
139 /* Close per-port disable control override */
140 REG_IO_RMW16(ACPI_BASE_ADDRESS + UPRWC, ~UPRWC_WR_EN, 0),
141 REG_SCRIPT_END
142 };
143
144 /* Don't reset controller in S3 resume path */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300145 if (!acpi_is_wakeup_s3())
Aaron Durbin616f3942013-12-10 17:12:44 -0800146 reg_script_run_on_dev(dev, ehci_hc_reset);
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700147
148 /* Disable controller if ports are routed to XHCI */
149 if (config->usb_route_to_xhci) {
150 /* Disable controller */
Aaron Durbin616f3942013-12-10 17:12:44 -0800151 reg_script_run_on_dev(dev, ehci_disable_script);
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700152
153 /* Hide device with southcluster function */
154 dev->enabled = 0;
155 southcluster_enable_dev(dev);
156 } else {
157 /* Initialize EHCI controller */
Aaron Durbin616f3942013-12-10 17:12:44 -0800158 reg_script_run_on_dev(dev, ehci_hc_init);
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700159 }
160
161 /* Setup USB2 PHY based on board config */
162 usb2_phy_init(dev);
163}
164
165static struct device_operations ehci_device_ops = {
166 .read_resources = pci_dev_read_resources,
167 .set_resources = pci_dev_set_resources,
168 .enable_resources = pci_dev_enable_resources,
169 .init = ehci_init,
170 .ops_pci = &soc_pci_ops,
171};
172
173static const struct pci_driver baytrail_ehci __pci_driver = {
174 .ops = &ehci_device_ops,
175 .vendor = PCI_VENDOR_ID_INTEL,
176 .device = EHCI_DEVID
177};