coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
ehci.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpi.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_ids.h>
7 #include <stdint.h>
8 #include <reg_script.h>
9 
10 #include <soc/iomap.h>
11 #include <soc/iosf.h>
12 #include <soc/pci_devs.h>
13 #include <soc/pm.h>
14 #include <soc/ramstage.h>
15 #include <soc/ehci.h>
16 
17 #include "chip.h"
18 
19 static const struct reg_script ehci_init_script[] = {
20  /* Enable S0 PLL shutdown
21  * D29:F0:7A[12,10,7,6,4,3,2,1]=11111111b */
22  REG_PCI_OR16(0x7a, 0x14de),
23  /* Enable SB local clock gating
24  * D29:F0:7C[14,3,2]=111b (14 set in clock gating step) */
25  REG_PCI_OR32(0x7c, 0x0000000c),
26  REG_PCI_OR32(0x8c, 0x00000001),
27  /* Enable dynamic clock gating 0x4001=0xCE */
28  REG_IOSF_RMW(IOSF_PORT_USBPHY, 0x4001, 0xFFFFFF00, 0xCE),
29  /* Magic RCBA register set sequence */
30  /* RCBA + 0x200=0x1 */
31  REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x200, 0x00000001),
32  /* RCBA + 0x204=0x2 */
33  REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x204, 0x00000002),
34  /* RCBA + 0x208=0x0 */
35  REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x208, 0x00000000),
36  /* RCBA + 0x240[4,3,2,1,0]=00000b */
37  REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x240, ~0x0000001f, 0),
38  /* RCBA + 0x318[9,8,6,5,4,3,2,1,0]=000000111b */
39  REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x318, ~0x00000378, 0x00000007),
40  /* RCBA + 0x31c[3,2,1,0]=0011b */
41  REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x31c, ~0x0000000c, 0x00000003),
43 };
44 
45 static const struct reg_script ehci_clock_gating_script[] = {
46  /* Enable SB local clock gating */
47  REG_PCI_OR32(0x7c, 0x00004000),
48  /* RCBA + 0x284=0xbe (step B0+) */
49  REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x284, 0x000000be),
51 };
52 
53 static const struct reg_script ehci_disable_script[] = {
54  /* Clear Run/Stop Bit */
56  /* Wait for HC Halted */
59  /* Disable Interrupts */
61  /* Disable Asynchronous and Periodic Scheduler */
63  ~(USB2CMD_ASE | USB2CMD_PSE), 0),
64  /* Disable port wake */
66  /* Set Function Disable bit in RCBA */
69 };
70 
71 static const struct reg_script ehci_hc_reset[] = {
74 };
75 
76 static void usb2_phy_init(struct device *dev)
77 {
79  u32 usb2_comp_bg = (config->usb2_comp_bg == 0 ?
80  0x4700 : config->usb2_comp_bg);
81  struct reg_script usb2_phy_script[] = {
82  /* USB3PHYInit() */
83  REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_COMPBG,
84  usb2_comp_bg),
85  /* Per port phy settings, set in devicetree.cb */
87  config->usb2_per_port_lane0),
88  REG_IOSF_WRITE(IOSF_PORT_USBPHY,
90  config->usb2_per_port_rcomp_hs_pullup0),
92  config->usb2_per_port_lane1),
93  REG_IOSF_WRITE(IOSF_PORT_USBPHY,
95  config->usb2_per_port_rcomp_hs_pullup1),
97  config->usb2_per_port_lane2),
98  REG_IOSF_WRITE(IOSF_PORT_USBPHY,
100  config->usb2_per_port_rcomp_hs_pullup2),
101  REG_IOSF_WRITE(IOSF_PORT_USBPHY, USBPHY_PER_PORT_LANE3,
102  config->usb2_per_port_lane3),
103  REG_IOSF_WRITE(IOSF_PORT_USBPHY,
105  config->usb2_per_port_rcomp_hs_pullup3),
107  };
108  reg_script_run(usb2_phy_script);
109 }
110 
111 static void ehci_init(struct device *dev)
112 {
114  struct reg_script ehci_hc_init[] = {
115  /* Controller init */
117  /* Enable clock gating */
119  /*
120  * Disable ports if requested
121  */
122  /* Open per-port disable control override */
124  REG_PCI_WRITE8(EHCI_USB2PDO, config->usb2_port_disable_mask),
125  /* Close per-port disable control override */
128  };
129 
130  /* Don't reset controller in S3 resume path */
131  if (!acpi_is_wakeup_s3())
133 
134  /* Disable controller if ports are routed to XHCI */
135  if (config->usb_route_to_xhci) {
136  /* Disable controller */
138 
139  /* Hide device with southcluster function */
140  dev->enabled = 0;
142  } else {
143  /* Initialize EHCI controller */
144  reg_script_run_on_dev(dev, ehci_hc_init);
145  }
146 
147  /* Setup USB2 PHY based on board config */
149 }
150 
151 static struct device_operations ehci_device_ops = {
153  .set_resources = pci_dev_set_resources,
154  .enable_resources = pci_dev_enable_resources,
155  .init = ehci_init,
156  .ops_pci = &soc_pci_ops,
157 };
158 
159 static const struct pci_driver baytrail_ehci __pci_driver = {
160  .ops = &ehci_device_ops,
161  .vendor = PCI_VID_INTEL,
162  .device = EHCI_DEVID
163 };
static int acpi_is_wakeup_s3(void)
Definition: acpi.h:9
static const struct reg_script ehci_disable_script[]
Definition: ehci.c:53
static const struct reg_script ehci_hc_reset[]
Definition: ehci.c:71
static const struct pci_driver baytrail_ehci __pci_driver
Definition: ehci.c:159
static struct device_operations ehci_device_ops
Definition: ehci.c:151
static const struct reg_script ehci_init_script[]
Definition: ehci.c:19
static void usb2_phy_init(struct device *dev)
Definition: ehci.c:76
static void ehci_init(struct device *dev)
Definition: ehci.c:111
static const struct reg_script ehci_clock_gating_script[]
Definition: ehci.c:45
#define USBPHY_PER_PORT_RCOMP_HS_PULLUP2
Definition: iosf.h:313
#define USBPHY_COMPBG
Definition: iosf.h:307
#define USBPHY_PER_PORT_RCOMP_HS_PULLUP0
Definition: iosf.h:309
#define USBPHY_PER_PORT_LANE1
Definition: iosf.h:310
#define USBPHY_PER_PORT_RCOMP_HS_PULLUP3
Definition: iosf.h:315
#define USBPHY_PER_PORT_RCOMP_HS_PULLUP1
Definition: iosf.h:311
#define USBPHY_PER_PORT_LANE0
Definition: iosf.h:308
#define USBPHY_PER_PORT_LANE2
Definition: iosf.h:312
#define USBPHY_PER_PORT_LANE3
Definition: iosf.h:314
#define IOSF_PORT_USBPHY
Definition: iosf.h:99
#define UPRWC_WR_EN
Definition: pm.h:222
#define UPRWC
Definition: pm.h:221
static DEVTREE_CONST void * config_of(const struct device *dev)
Definition: device.h:382
#define ACPI_BASE_ADDRESS
Definition: iomap.h:99
#define RCBA_BASE_ADDRESS
Definition: iomap.h:42
enum board_config config
Definition: memory.c:448
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
void pci_dev_enable_resources(struct device *dev)
Definition: pci_device.c:721
void pci_dev_read_resources(struct device *dev)
Definition: pci_device.c:534
void pci_dev_set_resources(struct device *dev)
Definition: pci_device.c:691
#define PCI_VID_INTEL
Definition: pci_ids.h:2157
#define REG_RES_RMW32(bar_, reg_, mask_, value_)
Definition: reg_script.h:331
#define REG_RES_OR16(bar_, reg_, value_)
Definition: reg_script.h:341
#define REG_RES_POLL32(bar_, reg_, mask_, value_, timeout_)
Definition: reg_script.h:349
#define REG_PCI_OR32(reg_, value_)
Definition: reg_script.h:187
#define REG_MMIO_WRITE32(reg_, value_)
Definition: reg_script.h:273
#define REG_MMIO_RMW32(reg_, mask_, value_)
Definition: reg_script.h:279
#define REG_SCRIPT_NEXT(next_)
Definition: reg_script.h:411
void reg_script_run(const struct reg_script *script)
Definition: reg_script.c:700
#define REG_PCI_WRITE8(reg_, value_)
Definition: reg_script.h:165
void reg_script_run_on_dev(struct device *dev, const struct reg_script *step)
Definition: reg_script.c:689
#define REG_PCI_OR16(reg_, value_)
Definition: reg_script.h:185
#define REG_MMIO_OR32(reg_, value_)
Definition: reg_script.h:291
#define REG_IO_RMW16(reg_, mask_, value_)
Definition: reg_script.h:225
#define REG_PCI_RMW32(reg_, mask_, value_)
Definition: reg_script.h:175
#define REG_SCRIPT_END
Definition: reg_script.h:427
struct pci_operations soc_pci_ops
Definition: chip.c:51
#define USB2CMD_ASE
Definition: ehci.h:16
#define USB2CMD
Definition: ehci.h:15
#define USB2STS
Definition: ehci.h:20
#define RCBA_EHCI_DIS
Definition: ehci.h:25
#define EHCI_SBRN_FLA_PWC
Definition: ehci.h:9
#define INTRDIS
Definition: ehci.h:8
#define PORTWKCAPMASK
Definition: ehci.h:11
#define USB2CMD_HCRESET
Definition: ehci.h:18
#define USB2CMD_PSE
Definition: ehci.h:17
#define RCBA_FUNC_DIS
Definition: ehci.h:24
#define EHCI_USB2PDO
Definition: ehci.h:12
#define PORTWKIMP
Definition: ehci.h:10
#define USB2STS_HCHALT
Definition: ehci.h:21
#define USB2CMD_RS
Definition: ehci.h:19
#define EHCI_CMD_STS
Definition: ehci.h:7
#define EHCI_DEVID
Definition: pci_devs.h:134
void southcluster_enable_dev(struct device *dev)
Definition: southcluster.c:452
uint32_t u32
Definition: stdint.h:51
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
unsigned int enabled
Definition: device.h:122
struct device * dev
Definition: reg_script.h:78
uint32_t usb2_comp_bg
Definition: chip.h:42