Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2009 |
| 4 | * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com. |
| 5 | * Copyright 2019 Google Inc |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <dm.h> |
Simon Glass | f0c9890 | 2019-12-06 21:41:42 -0700 | [diff] [blame] | 10 | #include <spl.h> |
Simon Glass | 9daae2c | 2019-12-10 21:28:20 -0700 | [diff] [blame] | 11 | #include <asm/lpss.h> |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 12 | #include "designware_i2c.h" |
| 13 | |
Simon Glass | 9daae2c | 2019-12-10 21:28:20 -0700 | [diff] [blame] | 14 | enum { |
| 15 | VANILLA = 0, /* standard I2C with no tweaks */ |
| 16 | INTEL_APL, /* Apollo Lake I2C */ |
| 17 | }; |
| 18 | |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 19 | /* BayTrail HCNT/LCNT/SDA hold time */ |
| 20 | static struct dw_scl_sda_cfg byt_config = { |
| 21 | .ss_hcnt = 0x200, |
| 22 | .fs_hcnt = 0x55, |
| 23 | .ss_lcnt = 0x200, |
| 24 | .fs_lcnt = 0x99, |
| 25 | .sda_hold = 0x6, |
| 26 | }; |
| 27 | |
Simon Glass | 9daae2c | 2019-12-10 21:28:20 -0700 | [diff] [blame] | 28 | /* Have a weak function for now - possibly should be a new uclass */ |
| 29 | __weak void lpss_reset_release(void *regs); |
| 30 | |
Simon Glass | f0c9890 | 2019-12-06 21:41:42 -0700 | [diff] [blame] | 31 | static int designware_i2c_pci_ofdata_to_platdata(struct udevice *dev) |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 32 | { |
| 33 | struct dw_i2c *priv = dev_get_priv(dev); |
| 34 | |
Simon Glass | f0c9890 | 2019-12-06 21:41:42 -0700 | [diff] [blame] | 35 | if (spl_phase() < PHASE_SPL) { |
| 36 | u32 base; |
| 37 | int ret; |
| 38 | |
| 39 | ret = dev_read_u32(dev, "early-regs", &base); |
| 40 | if (ret) |
| 41 | return log_msg_ret("early-regs", ret); |
| 42 | |
| 43 | /* Set i2c base address */ |
| 44 | dm_pci_write_config32(dev, PCI_BASE_ADDRESS_0, base); |
| 45 | |
| 46 | /* Enable memory access and bus master */ |
| 47 | dm_pci_write_config32(dev, PCI_COMMAND, PCI_COMMAND_MEMORY | |
| 48 | PCI_COMMAND_MASTER); |
| 49 | } |
| 50 | |
| 51 | if (spl_phase() < PHASE_BOARD_F) { |
| 52 | /* Handle early, fixed mapping into a different address space */ |
| 53 | priv->regs = (struct i2c_regs *)dm_pci_read_bar32(dev, 0); |
| 54 | } else { |
| 55 | priv->regs = (struct i2c_regs *) |
| 56 | dm_pci_map_bar(dev, PCI_BASE_ADDRESS_0, PCI_REGION_MEM); |
| 57 | } |
| 58 | if (!priv->regs) |
| 59 | return -EINVAL; |
| 60 | |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 61 | /* Save base address from PCI BAR */ |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 62 | if (IS_ENABLED(CONFIG_INTEL_BAYTRAIL)) |
| 63 | /* Use BayTrail specific timing values */ |
| 64 | priv->scl_sda_cfg = &byt_config; |
| 65 | |
Simon Glass | f0c9890 | 2019-12-06 21:41:42 -0700 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static int designware_i2c_pci_probe(struct udevice *dev) |
| 70 | { |
Simon Glass | 9daae2c | 2019-12-10 21:28:20 -0700 | [diff] [blame] | 71 | struct dw_i2c *priv = dev_get_priv(dev); |
| 72 | |
| 73 | if (dev_get_driver_data(dev) == INTEL_APL) { |
| 74 | /* Ensure controller is in D0 state */ |
| 75 | lpss_set_power_state(dev, STATE_D0); |
| 76 | |
| 77 | lpss_reset_release(priv->regs); |
| 78 | } |
| 79 | |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 80 | return designware_i2c_probe(dev); |
| 81 | } |
| 82 | |
| 83 | static int designware_i2c_pci_bind(struct udevice *dev) |
| 84 | { |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 85 | char name[20]; |
| 86 | |
| 87 | /* |
| 88 | * Create a unique device name for PCI type devices |
| 89 | * ToDo: |
| 90 | * Setting req_seq in the driver is probably not recommended. |
| 91 | * But without a DT alias the number is not configured. And |
| 92 | * using this driver is impossible for PCIe I2C devices. |
| 93 | * This can be removed, once a better (correct) way for this |
| 94 | * is found and implemented. |
Simon Glass | f5bdce2 | 2019-12-06 21:41:41 -0700 | [diff] [blame] | 95 | * |
| 96 | * TODO(sjg@chromium.org): Perhaps if uclasses had platdata this would |
| 97 | * be possible. We cannot use static data in drivers since they may be |
| 98 | * used in SPL or before relocation. |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 99 | */ |
Simon Glass | f5bdce2 | 2019-12-06 21:41:41 -0700 | [diff] [blame] | 100 | dev->req_seq = gd->arch.dw_i2c_num_cards++; |
| 101 | sprintf(name, "i2c_designware#%u", dev->req_seq); |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 102 | device_set_name(dev, name); |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
Simon Glass | f0c9890 | 2019-12-06 21:41:42 -0700 | [diff] [blame] | 107 | static const struct udevice_id designware_i2c_pci_ids[] = { |
| 108 | { .compatible = "snps,designware-i2c-pci" }, |
Simon Glass | 9daae2c | 2019-12-10 21:28:20 -0700 | [diff] [blame] | 109 | { .compatible = "intel,apl-i2c", .data = INTEL_APL }, |
Simon Glass | f0c9890 | 2019-12-06 21:41:42 -0700 | [diff] [blame] | 110 | { } |
| 111 | }; |
| 112 | |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 113 | U_BOOT_DRIVER(i2c_designware_pci) = { |
| 114 | .name = "i2c_designware_pci", |
| 115 | .id = UCLASS_I2C, |
Simon Glass | f0c9890 | 2019-12-06 21:41:42 -0700 | [diff] [blame] | 116 | .of_match = designware_i2c_pci_ids, |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 117 | .bind = designware_i2c_pci_bind, |
Simon Glass | f0c9890 | 2019-12-06 21:41:42 -0700 | [diff] [blame] | 118 | .ofdata_to_platdata = designware_i2c_pci_ofdata_to_platdata, |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 119 | .probe = designware_i2c_pci_probe, |
| 120 | .priv_auto_alloc_size = sizeof(struct dw_i2c), |
| 121 | .remove = designware_i2c_remove, |
| 122 | .flags = DM_FLAG_OS_PREPARE, |
| 123 | .ops = &designware_i2c_ops, |
| 124 | }; |
| 125 | |
| 126 | static struct pci_device_id designware_pci_supported[] = { |
| 127 | /* Intel BayTrail has 7 I2C controller located on the PCI bus */ |
| 128 | { PCI_VDEVICE(INTEL, 0x0f41) }, |
| 129 | { PCI_VDEVICE(INTEL, 0x0f42) }, |
| 130 | { PCI_VDEVICE(INTEL, 0x0f43) }, |
| 131 | { PCI_VDEVICE(INTEL, 0x0f44) }, |
| 132 | { PCI_VDEVICE(INTEL, 0x0f45) }, |
| 133 | { PCI_VDEVICE(INTEL, 0x0f46) }, |
| 134 | { PCI_VDEVICE(INTEL, 0x0f47) }, |
Simon Glass | 9daae2c | 2019-12-10 21:28:20 -0700 | [diff] [blame] | 135 | { PCI_VDEVICE(INTEL, 0x5aac), .driver_data = INTEL_APL }, |
| 136 | { PCI_VDEVICE(INTEL, 0x5aae), .driver_data = INTEL_APL }, |
| 137 | { PCI_VDEVICE(INTEL, 0x5ab0), .driver_data = INTEL_APL }, |
| 138 | { PCI_VDEVICE(INTEL, 0x5ab2), .driver_data = INTEL_APL }, |
| 139 | { PCI_VDEVICE(INTEL, 0x5ab4), .driver_data = INTEL_APL }, |
| 140 | { PCI_VDEVICE(INTEL, 0x5ab6), .driver_data = INTEL_APL }, |
Simon Glass | e2be553 | 2019-12-06 21:41:40 -0700 | [diff] [blame] | 141 | {}, |
| 142 | }; |
| 143 | |
| 144 | U_BOOT_PCI_DEVICE(i2c_designware_pci, designware_pci_supported); |