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