blob: dc9855ddf868d0fe8ed43159357227c065291578 [file] [log] [blame]
Angel Ponsc3f58f62020-04-05 15:46:41 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Duncan Laurie3c9f1742013-11-01 13:34:00 -07003
4#include <arch/acpi.h>
Duncan Laurie3c9f1742013-11-01 13:34:00 -07005#include <device/device.h>
6#include <device/pci.h>
7#include <device/pci_ids.h>
8#include <stdint.h>
9#include <reg_script.h>
10
Julius Werner18ea2d32014-10-07 16:42:17 -070011#include <soc/iomap.h>
12#include <soc/iosf.h>
13#include <soc/pci_devs.h>
14#include <soc/pmc.h>
15#include <soc/ramstage.h>
16#include <soc/ehci.h>
Duncan Laurie3c9f1742013-11-01 13:34:00 -070017
18#include "chip.h"
19
Aaron Durbin616f3942013-12-10 17:12:44 -080020static const struct reg_script ehci_init_script[] = {
Duncan Laurie3c9f1742013-11-01 13:34:00 -070021 /* Enable S0 PLL shutdown
22 * D29:F0:7A[12,10,7,6,4,3,2,1]=11111111b */
23 REG_PCI_OR16(0x7a, 0x14de),
24 /* Enable SB local clock gating
25 * D29:F0:7C[14,3,2]=111b (14 set in clock gating step) */
26 REG_PCI_OR32(0x7c, 0x0000000c),
27 REG_PCI_OR32(0x8c, 0x00000001),
28 /* Enable dynamic clock gating 0x4001=0xCE */
29 REG_IOSF_RMW(IOSF_PORT_USBPHY, 0x4001, 0xFFFFFF00, 0xCE),
30 /* Magic RCBA register set sequence */
31 /* RCBA + 0x200=0x1 */
32 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x200, 0x00000001),
33 /* RCBA + 0x204=0x2 */
34 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x204, 0x00000002),
35 /* RCBA + 0x208=0x0 */
36 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x208, 0x00000000),
37 /* RCBA + 0x240[4,3,2,1,0]=00000b */
38 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x240, ~0x0000001f, 0),
39 /* RCBA + 0x318[9,8,6,5,4,3,2,1,0]=000000111b */
40 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x318, ~0x00000378, 0x00000007),
41 /* RCBA + 0x31c[3,2,1,0]=0011b */
42 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x31c, ~0x0000000c, 0x00000003),
43 REG_SCRIPT_END
44};
45
Aaron Durbin616f3942013-12-10 17:12:44 -080046static const struct reg_script ehci_clock_gating_script[] = {
Duncan Laurie3c9f1742013-11-01 13:34:00 -070047 /* Enable SB local clock gating */
48 REG_PCI_OR32(0x7c, 0x00004000),
49 /* RCBA + 0x284=0xbe (step B0+) */
50 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x284, 0x000000be),
51 REG_SCRIPT_END
52};
53
Aaron Durbin616f3942013-12-10 17:12:44 -080054static const struct reg_script ehci_disable_script[] = {
Duncan Laurie3c9f1742013-11-01 13:34:00 -070055 /* Clear Run/Stop Bit */
56 REG_RES_RMW32(PCI_BASE_ADDRESS_0, USB2CMD, ~USB2CMD_RS, 0),
57 /* Wait for HC Halted */
58 REG_RES_POLL32(PCI_BASE_ADDRESS_0, USB2STS,
59 USB2STS_HCHALT, USB2STS_HCHALT, 10000),
60 /* Disable Interrupts */
61 REG_PCI_OR32(EHCI_CMD_STS, INTRDIS),
62 /* Disable Asynchronous and Periodic Scheduler */
63 REG_RES_RMW32(PCI_BASE_ADDRESS_0, USB2CMD,
64 ~(USB2CMD_ASE | USB2CMD_PSE), 0),
65 /* Disable port wake */
66 REG_PCI_RMW32(EHCI_SBRN_FLA_PWC, ~(PORTWKIMP | PORTWKCAPMASK), 0),
67 /* Set Function Disable bit in RCBA */
68 REG_MMIO_OR32(RCBA_BASE_ADDRESS + RCBA_FUNC_DIS, RCBA_EHCI_DIS),
69 REG_SCRIPT_END
70};
71
Aaron Durbin616f3942013-12-10 17:12:44 -080072static const struct reg_script ehci_hc_reset[] = {
73 REG_RES_OR16(PCI_BASE_ADDRESS_0, USB2CMD, USB2CMD_HCRESET),
74 REG_SCRIPT_END
75};
76
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020077static void usb2_phy_init(struct device *dev)
Duncan Laurie3c9f1742013-11-01 13:34:00 -070078{
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +030079 struct soc_intel_baytrail_config *config = config_of(dev);
Kane Chen374f27b2014-07-17 11:31:57 -070080 u32 usb2_comp_bg = (config->usb2_comp_bg == 0 ?
81 0x4700 : config->usb2_comp_bg);
Duncan Laurie3c9f1742013-11-01 13:34:00 -070082 struct reg_script usb2_phy_script[] = {
83 /* USB3PHYInit() */
Kane Chen314c4c32014-07-17 09:51:50 -070084 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_COMPBG,
Kane Chen374f27b2014-07-17 11:31:57 -070085 usb2_comp_bg),
Duncan Laurie3c9f1742013-11-01 13:34:00 -070086 /* Per port phy settings, set in devicetree.cb */
87 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_PER_PORT_LANE0,
88 config->usb2_per_port_lane0),
89 REG_IOSF_WRITE(IOSF_PORT_USBPHY,
90 USBPHY_PER_PORT_RCOMP_HS_PULLUP0,
91 config->usb2_per_port_rcomp_hs_pullup0),
92 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_PER_PORT_LANE1,
93 config->usb2_per_port_lane1),
94 REG_IOSF_WRITE(IOSF_PORT_USBPHY,
95 USBPHY_PER_PORT_RCOMP_HS_PULLUP1,
96 config->usb2_per_port_rcomp_hs_pullup1),
97 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_PER_PORT_LANE2,
98 config->usb2_per_port_lane2),
99 REG_IOSF_WRITE(IOSF_PORT_USBPHY,
100 USBPHY_PER_PORT_RCOMP_HS_PULLUP2,
101 config->usb2_per_port_rcomp_hs_pullup2),
102 REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_PER_PORT_LANE3,
103 config->usb2_per_port_lane3),
104 REG_IOSF_WRITE(IOSF_PORT_USBPHY,
105 USBPHY_PER_PORT_RCOMP_HS_PULLUP3,
106 config->usb2_per_port_rcomp_hs_pullup3),
107 REG_SCRIPT_END
108 };
109 reg_script_run(usb2_phy_script);
110}
111
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200112static void ehci_init(struct device *dev)
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700113{
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300114 struct soc_intel_baytrail_config *config = config_of(dev);
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700115 struct reg_script ehci_hc_init[] = {
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700116 /* Controller init */
117 REG_SCRIPT_NEXT(ehci_init_script),
118 /* Enable clock gating */
119 REG_SCRIPT_NEXT(ehci_clock_gating_script),
120 /*
121 * Disable ports if requested
122 */
123 /* Open per-port disable control override */
124 REG_IO_RMW16(ACPI_BASE_ADDRESS + UPRWC, ~0, UPRWC_WR_EN),
125 REG_PCI_WRITE8(EHCI_USB2PDO, config->usb2_port_disable_mask),
126 /* Close per-port disable control override */
127 REG_IO_RMW16(ACPI_BASE_ADDRESS + UPRWC, ~UPRWC_WR_EN, 0),
128 REG_SCRIPT_END
129 };
130
131 /* Don't reset controller in S3 resume path */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300132 if (!acpi_is_wakeup_s3())
Aaron Durbin616f3942013-12-10 17:12:44 -0800133 reg_script_run_on_dev(dev, ehci_hc_reset);
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700134
135 /* Disable controller if ports are routed to XHCI */
136 if (config->usb_route_to_xhci) {
137 /* Disable controller */
Aaron Durbin616f3942013-12-10 17:12:44 -0800138 reg_script_run_on_dev(dev, ehci_disable_script);
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700139
140 /* Hide device with southcluster function */
141 dev->enabled = 0;
142 southcluster_enable_dev(dev);
143 } else {
144 /* Initialize EHCI controller */
Aaron Durbin616f3942013-12-10 17:12:44 -0800145 reg_script_run_on_dev(dev, ehci_hc_init);
Duncan Laurie3c9f1742013-11-01 13:34:00 -0700146 }
147
148 /* Setup USB2 PHY based on board config */
149 usb2_phy_init(dev);
150}
151
152static struct device_operations ehci_device_ops = {
153 .read_resources = pci_dev_read_resources,
154 .set_resources = pci_dev_set_resources,
155 .enable_resources = pci_dev_enable_resources,
156 .init = ehci_init,
157 .ops_pci = &soc_pci_ops,
158};
159
160static const struct pci_driver baytrail_ehci __pci_driver = {
161 .ops = &ehci_device_ops,
162 .vendor = PCI_VENDOR_ID_INTEL,
163 .device = EHCI_DEVID
164};