Angel Pons | 0612b27 | 2020-04-05 15:46:56 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Kane Chen | 01ebc74 | 2019-08-23 12:03:05 +0800 | [diff] [blame] | 2 | |
| 3 | #include <device/pci.h> |
| 4 | #include <device/pci_ids.h> |
| 5 | #include <console/console.h> |
Kyösti Mälkki | 32d47eb | 2019-09-28 00:00:30 +0300 | [diff] [blame] | 6 | #include <intelblocks/cfg.h> |
Kane Chen | 01ebc74 | 2019-08-23 12:03:05 +0800 | [diff] [blame] | 7 | #include <intelblocks/mmc.h> |
| 8 | |
| 9 | static int mmc_write_dll_reg(void *bar, uint32_t reg, uint32_t val) |
| 10 | { |
| 11 | int ret = 0; |
| 12 | if (val) { |
| 13 | write32(bar + reg, val); |
| 14 | ret = 1; |
| 15 | } |
| 16 | return ret; |
| 17 | } |
| 18 | |
| 19 | int set_mmc_dll(void *bar) |
| 20 | { |
| 21 | const struct soc_intel_common_config *common_config; |
| 22 | const struct mmc_dll_params *dll_params; |
| 23 | int override = 0; |
| 24 | |
| 25 | common_config = chip_get_common_soc_structure(); |
| 26 | dll_params = &common_config->emmc_dll; |
| 27 | |
| 28 | override |= mmc_write_dll_reg(bar, EMMC_TX_CMD_CNTL_OFFSET, |
| 29 | dll_params->emmc_tx_cmd_cntl); |
| 30 | |
| 31 | override |= mmc_write_dll_reg(bar, EMMC_TX_DATA_CNTL1_OFFSET, |
| 32 | dll_params->emmc_tx_data_cntl1); |
| 33 | |
| 34 | override |= mmc_write_dll_reg(bar, EMMC_TX_DATA_CNTL2_OFFSET, |
| 35 | dll_params->emmc_tx_data_cntl2); |
| 36 | |
| 37 | override |= mmc_write_dll_reg(bar, EMMC_RX_CMD_DATA_CNTL1_OFFSET, |
| 38 | dll_params->emmc_rx_cmd_data_cntl1); |
| 39 | |
| 40 | override |= mmc_write_dll_reg(bar, EMMC_RX_STROBE_CNTL_OFFSET, |
| 41 | dll_params->emmc_rx_strobe_cntl); |
| 42 | |
| 43 | override |= mmc_write_dll_reg(bar, EMMC_RX_CMD_DATA_CNTL2_OFFSET, |
| 44 | dll_params->emmc_rx_cmd_data_cntl2); |
| 45 | |
| 46 | if (override == 0) { |
| 47 | printk(BIOS_INFO, "Skip Emmc dll value programming\n"); |
| 48 | return -1; |
| 49 | } |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static void mmc_soc_init(struct device *dev) |
| 55 | { |
| 56 | const struct resource *res; |
| 57 | |
| 58 | if (!CONFIG(SOC_INTEL_COMMON_MMC_OVERRIDE)) |
| 59 | return; |
| 60 | |
| 61 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 62 | set_mmc_dll((void *)(uintptr_t)(res->base)); |
| 63 | } |
| 64 | |
| 65 | static struct device_operations dev_ops = { |
| 66 | .read_resources = pci_dev_read_resources, |
| 67 | .set_resources = pci_dev_set_resources, |
| 68 | .enable_resources = pci_dev_enable_resources, |
| 69 | .init = mmc_soc_init, |
| 70 | .ops_pci = &pci_dev_ops_pci, |
| 71 | }; |
| 72 | |
| 73 | static const unsigned short pci_device_ids[] = { |
| 74 | PCI_DEVICE_ID_INTEL_CMP_EMMC, |
Meera Ravindranath | 3f4af0d | 2020-02-12 16:01:22 +0530 | [diff] [blame] | 75 | PCI_DEVICE_ID_INTEL_JSP_EMMC, |
Krishna Prasad Bhat | eed82d1 | 2022-01-16 20:05:07 +0530 | [diff] [blame^] | 76 | PCI_DEVICE_ID_INTEL_ADP_EMMC, |
Kane Chen | 01ebc74 | 2019-08-23 12:03:05 +0800 | [diff] [blame] | 77 | 0 |
| 78 | }; |
| 79 | |
| 80 | static const struct pci_driver pch_sd __pci_driver = { |
| 81 | .ops = &dev_ops, |
| 82 | .vendor = PCI_VENDOR_ID_INTEL, |
| 83 | .devices = pci_device_ids, |
| 84 | }; |