blob: 2524fa7f833cff6ebacb81c5d2260577a5e6ad34 [file] [log] [blame]
Lee Leahy4dd34ee2016-05-02 14:31:02 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2016 Intel Corporation.
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
16#include <console/console.h>
17#include <device/pci_ids.h>
18#include <soc/pci_devs.h>
19#include <soc/reg_access.h>
20
21/* USB Phy Registers */
22#define USB2_GLOBAL_PORT 0x4001
23#define USB2_PLL1 0x7F02
24#define USB2_PLL2 0x7F03
25#define USB2_COMPBG 0x7F04
26
Lee Leahyf8841122016-05-22 09:23:49 -070027/* EHCI Packet Buffer OUT/IN Thresholds, values in number of DWORDs */
28#define EHCI_OUT_THRESHOLD_VALUE 0x7f
29#define EHCI_IN_THRESHOLD_VALUE 0x7f
30
Lee Leahyfd456582016-05-22 09:55:22 -070031/* Platform init USB device interrupt masks */
32#define V_IOH_USBDEVICE_D_INTR_MSK_UDC_REG (0x0000007f)
33#define V_IOH_USBDEVICE_EP_INTR_MSK_UDC_REG \
34 (B_IOH_USBDEVICE_EP_INTR_MSK_UDC_REG_OUT_EP_MASK \
35 | B_IOH_USBDEVICE_EP_INTR_MSK_UDC_REG_IN_EP_MASK)
36
Lee Leahy4dd34ee2016-05-02 14:31:02 -070037/* In order to configure the USB PHY to use clk120 (ickusbcoreclk) as PLL
38 * reference clock and Port2 as a USB device port, the following sequence must
39 * be followed
40 */
Lee Leahyfd456582016-05-22 09:55:22 -070041static const struct reg_script ehci_init_script[] = {
Lee Leahy4dd34ee2016-05-02 14:31:02 -070042
Lee Leahyf8841122016-05-22 09:23:49 -070043 /* Set packet buffer OUT/IN thresholds */
44 REG_MMIO_RMW32(R_IOH_EHCI_INSNREG01,
45 ~(B_IOH_EHCI_INSNREG01_OUT_THRESHOLD_MASK
46 | B_IOH_EHCI_INSNREG01_IN_THRESHOLD_MASK),
47 (EHCI_OUT_THRESHOLD_VALUE
48 << B_IOH_EHCI_INSNREG01_OUT_THRESHOLD_BP)
49 | (EHCI_IN_THRESHOLD_VALUE
50 << B_IOH_EHCI_INSNREG01_IN_THRESHOLD_BP)),
51
Lee Leahy4dd34ee2016-05-02 14:31:02 -070052 /* Sighting #4930631 PDNRESCFG [8:7] of USB2_GLOBAL_PORT = 11b.
53 * For port 0 & 1 as host and port 2 as device.
54 */
55 REG_USB_RXW(USB2_GLOBAL_PORT, ~(BIT8 | BIT7 | BIT1), (BIT8 | BIT7)),
56
57 /*
58 * Sighting #4930653 Required BIOS change on Disconnect vref to change
59 * to 600mV.
60 */
61 REG_USB_RXW(USB2_COMPBG, ~(BIT10 | BIT9 | BIT8 | BIT7),
62 (BIT10 | BIT7)),
63
64 /* Sideband register write to USB AFE (Phy)
65 * (pllbypass) to bypass/Disable PLL before switch
66 */
67 REG_USB_OR(USB2_PLL2, BIT29),
68
69 /* Sideband register write to USB AFE (Phy)
70 * (coreclksel) to select 120MHz (ickusbcoreclk) clk source.
71 * (Default 0 to select 96MHz (ickusbclk96_npad/ppad))
72 */
73 REG_USB_OR(USB2_PLL1, BIT1),
74
75 /* Sideband register write to USB AFE (Phy)
76 * (divide by 8) to achieve internal 480MHz clock
77 * for 120MHz input refclk. (Default: 4'b1000 (divide by 10) for 96MHz)
78 */
79 REG_USB_RXW(USB2_PLL1, ~(BIT6 | BIT5 | BIT4 | BIT3), BIT6),
80
81 /* Sideband register write to USB AFE (Phy)
82 * Clear (pllbypass)
83 */
84 REG_USB_AND(USB2_PLL2, ~BIT29),
85
86 /* Sideband register write to USB AFE (Phy)
87 * Set (startlock) to force the PLL FSM to restart the lock
88 * sequence due to input clock/freq switch.
89 */
90 REG_USB_OR(USB2_PLL2, BIT24),
91 REG_SCRIPT_END
92};
93
Lee Leahyfd456582016-05-22 09:55:22 -070094static const struct reg_script usb_device_port_init_script[] = {
95
96 /* Mask and clear controller interrupts */
97 REG_MMIO_WRITE32(R_IOH_USBDEVICE_D_INTR_MSK_UDC_REG,
98 V_IOH_USBDEVICE_D_INTR_MSK_UDC_REG),
99 REG_MMIO_WRITE32(R_IOH_USBDEVICE_D_INTR_UDC_REG,
100 V_IOH_USBDEVICE_D_INTR_MSK_UDC_REG),
101
102 /* Mask and clear end point interrupts */
103 REG_MMIO_WRITE32(R_IOH_USBDEVICE_EP_INTR_MSK_UDC_REG,
104 V_IOH_USBDEVICE_EP_INTR_MSK_UDC_REG),
105 REG_MMIO_WRITE32(R_IOH_USBDEVICE_EP_INTR_UDC_REG,
106 V_IOH_USBDEVICE_EP_INTR_MSK_UDC_REG),
107 REG_SCRIPT_END
108};
109
Lee Leahy4dd34ee2016-05-02 14:31:02 -0700110static void init(device_t dev)
111{
Lee Leahyfd456582016-05-22 09:55:22 -0700112 if ((dev->path.pci.devfn & 7) == EHCI_FUNC) {
113 printk(BIOS_INFO, "Initializing USB PLLs\n");
114 reg_script_run_on_dev(dev, ehci_init_script);
115 } else {
116 printk(BIOS_INFO, "Initializing USB device port\n");
117 reg_script_run_on_dev(dev, usb_device_port_init_script);
118 }
Lee Leahy4dd34ee2016-05-02 14:31:02 -0700119}
120
121static struct device_operations device_ops = {
122 .read_resources = pci_dev_read_resources,
123 .set_resources = pci_dev_set_resources,
124 .enable_resources = pci_dev_enable_resources,
125 .init = init,
126};
127
128static const struct pci_driver driver __pci_driver = {
129 .ops = &device_ops,
130 .vendor = PCI_VENDOR_ID_INTEL,
131 .device = EHCI_DEVID,
132};