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