John Su | 8fff297 | 2021-01-21 13:22:58 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | /* Driver for BayHub Technology LV2 PCI to SD bridge */ |
| 4 | |
| 5 | #include <console/console.h> |
| 6 | #include <device/device.h> |
| 7 | #include <device/path.h> |
| 8 | #include <device/pci.h> |
| 9 | #include <device/pci_ops.h> |
| 10 | #include <device/pci_ids.h> |
| 11 | #include "chip.h" |
| 12 | #include "lv2.h" |
| 13 | |
| 14 | static void lv2_init(struct device *dev) |
| 15 | { |
| 16 | struct drivers_generic_bayhub_lv2_config *config = dev->chip_info; |
| 17 | pci_dev_init(dev); |
| 18 | |
| 19 | if (!config || !config->enable_power_saving) |
| 20 | return; |
| 21 | /* |
| 22 | * This procedure for enabling power-saving mode is from the |
| 23 | * BayHub BIOS Implementation Guideline document. |
| 24 | */ |
| 25 | pci_write_config32(dev, LV2_PROTECT, LV2_PROTECT_OFF | LV2_PROTECT_LOCK_OFF); |
| 26 | pci_or_config32(dev, LV2_PCR_HEX_FC, LV2_PCIE_PHY_P1_ENABLE); |
| 27 | pci_update_config32(dev, LV2_PCR_HEX_E0, LV2_PCI_PM_L1_TIMER_MASK, LV2_PCI_PM_L1_TIMER); |
| 28 | pci_update_config32(dev, LV2_PCR_HEX_FC, LV2_ASPM_L1_TIMER_MASK, LV2_ASPM_L1_TIMER); |
| 29 | pci_or_config32(dev, LV2_PCR_HEX_A8, LV2_LTR_ENABLE); |
| 30 | pci_write_config32(dev, LV2_PCR_HEX_234, LV2_MAX_LATENCY_SETTING); |
| 31 | pci_update_config32(dev, LV2_PCR_HEX_248, LV2_L1_SUBSTATE_SETTING_MASK, |
| 32 | LV2_L1_SUBSTATE_SETTING); |
| 33 | pci_update_config32(dev, LV2_PCR_HEX_3F4, LV2_L1_SUBSTATE_OPTIMISE_MASK, |
| 34 | LV2_L1_SUBSTATE_OPTIMISE); |
| 35 | pci_or_config32(dev, LV2_LINK_CTRL, LV2_LINK_CTRL_CLKREQ); |
| 36 | pci_update_config32(dev, LV2_PCR_HEX_300, LV2_TUNING_WINDOW_MASK, LV2_TUNING_WINDOW); |
| 37 | pci_update_config32(dev, LV2_PCR_HEX_304, LV2_DRIVER_STRENGTH_MASK, |
| 38 | LV2_DRIVER_STRENGTH); |
| 39 | pci_update_config32(dev, LV2_PCR_HEX_308, LV2_RESET_DMA_DISABLE_MASK, |
| 40 | LV2_RESET_DMA_DISABLE); |
| 41 | pci_update_config32(dev, LV2_LINK_CTRL, LV2_LINK_CTRL_L1_L0_MASK, |
| 42 | LV2_LINK_CTRL_L1_ENABLE); |
| 43 | pci_write_config32(dev, LV2_PROTECT, LV2_PROTECT_ON | LV2_PROTECT_LOCK_ON); |
| 44 | printk(BIOS_INFO, "BayHub LV2: Power-saving enabled (link_ctrl=%#x)\n", |
| 45 | pci_read_config32(dev, LV2_LINK_CTRL)); |
| 46 | } |
| 47 | |
| 48 | static struct device_operations lv2_ops = { |
| 49 | .read_resources = pci_dev_read_resources, |
| 50 | .set_resources = pci_dev_set_resources, |
| 51 | .enable_resources = pci_dev_enable_resources, |
| 52 | .ops_pci = &pci_dev_ops_pci, |
| 53 | .init = lv2_init, |
| 54 | }; |
| 55 | |
| 56 | static const unsigned short pci_device_ids[] = { |
| 57 | PCI_DEVICE_ID_O2_LV2, |
| 58 | 0 |
| 59 | }; |
| 60 | |
| 61 | static const struct pci_driver bayhub_lv2 __pci_driver = { |
| 62 | .ops = &lv2_ops, |
| 63 | .vendor = PCI_VENDOR_ID_O2, |
| 64 | .devices = pci_device_ids, |
| 65 | }; |
| 66 | |
| 67 | struct chip_operations drivers_generic_bayhub_lv2_ops = { |
| 68 | CHIP_NAME("BayHub Technology LV2 PCIe to SD bridge") |
| 69 | }; |