Bjorn Helgaas | 8cfab3c | 2018-01-26 12:50:27 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 2 | /* |
Paul Gortmaker | f9a6660 | 2016-08-24 16:57:48 -0400 | [diff] [blame] | 3 | * Qualcomm PCIe root complex driver |
| 4 | * |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 5 | * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. |
| 6 | * Copyright 2015 Linaro Limited. |
| 7 | * |
Paul Gortmaker | f9a6660 | 2016-08-24 16:57:48 -0400 | [diff] [blame] | 8 | * Author: Stanimir Varbanov <svarbanov@mm-sol.com> |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/clk.h> |
| 12 | #include <linux/delay.h> |
| 13 | #include <linux/gpio.h> |
| 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/io.h> |
| 16 | #include <linux/iopoll.h> |
| 17 | #include <linux/kernel.h> |
Paul Gortmaker | f9a6660 | 2016-08-24 16:57:48 -0400 | [diff] [blame] | 18 | #include <linux/init.h> |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 19 | #include <linux/of_device.h> |
| 20 | #include <linux/of_gpio.h> |
| 21 | #include <linux/pci.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/phy/phy.h> |
| 24 | #include <linux/regulator/consumer.h> |
| 25 | #include <linux/reset.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/types.h> |
| 28 | |
| 29 | #include "pcie-designware.h" |
| 30 | |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 31 | #define PCIE20_PARF_SYS_CTRL 0x00 |
Varadarajan Narayanan | 5d76117 | 2017-08-18 12:59:53 +0530 | [diff] [blame] | 32 | #define MST_WAKEUP_EN BIT(13) |
| 33 | #define SLV_WAKEUP_EN BIT(12) |
| 34 | #define MSTR_ACLK_CGC_DIS BIT(10) |
| 35 | #define SLV_ACLK_CGC_DIS BIT(9) |
| 36 | #define CORE_CLK_CGC_DIS BIT(6) |
| 37 | #define AUX_PWR_DET BIT(4) |
| 38 | #define L23_CLK_RMV_DIS BIT(2) |
| 39 | #define L1_CLK_RMV_DIS BIT(1) |
| 40 | |
| 41 | #define PCIE20_COMMAND_STATUS 0x04 |
| 42 | #define CMD_BME_VAL 0x4 |
| 43 | #define PCIE20_DEVICE_CONTROL2_STATUS2 0x98 |
| 44 | #define PCIE_CAP_CPL_TIMEOUT_DISABLE 0x10 |
| 45 | |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 46 | #define PCIE20_PARF_PHY_CTRL 0x40 |
| 47 | #define PCIE20_PARF_PHY_REFCLK 0x4C |
| 48 | #define PCIE20_PARF_DBI_BASE_ADDR 0x168 |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 49 | #define PCIE20_PARF_SLV_ADDR_SPACE_SIZE 0x16C |
| 50 | #define PCIE20_PARF_MHI_CLOCK_RESET_CTRL 0x174 |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 51 | #define PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT 0x178 |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 52 | #define PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT_V2 0x1A8 |
| 53 | #define PCIE20_PARF_LTSSM 0x1B0 |
| 54 | #define PCIE20_PARF_SID_OFFSET 0x234 |
| 55 | #define PCIE20_PARF_BDF_TRANSLATE_CFG 0x24C |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 56 | |
| 57 | #define PCIE20_ELBI_SYS_CTRL 0x04 |
| 58 | #define PCIE20_ELBI_SYS_CTRL_LT_ENABLE BIT(0) |
| 59 | |
Srinivas Kandagatla | b8f2a85 | 2017-06-29 17:34:55 +0200 | [diff] [blame] | 60 | #define PCIE20_AXI_MSTR_RESP_COMP_CTRL0 0x818 |
| 61 | #define CFG_REMOTE_RD_REQ_BRIDGE_SIZE_2K 0x4 |
| 62 | #define CFG_REMOTE_RD_REQ_BRIDGE_SIZE_4K 0x5 |
| 63 | #define PCIE20_AXI_MSTR_RESP_COMP_CTRL1 0x81c |
| 64 | #define CFG_BRIDGE_SB_INIT BIT(0) |
| 65 | |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 66 | #define PCIE20_CAP 0x70 |
Varadarajan Narayanan | 5d76117 | 2017-08-18 12:59:53 +0530 | [diff] [blame] | 67 | #define PCIE20_CAP_LINK_CAPABILITIES (PCIE20_CAP + 0xC) |
| 68 | #define PCIE20_CAP_ACTIVE_STATE_LINK_PM_SUPPORT (BIT(10) | BIT(11)) |
| 69 | #define PCIE20_CAP_LINK_1 (PCIE20_CAP + 0x14) |
| 70 | #define PCIE_CAP_LINK1_VAL 0x2FD7F |
| 71 | |
| 72 | #define PCIE20_PARF_Q2A_FLUSH 0x1AC |
| 73 | |
| 74 | #define PCIE20_MISC_CONTROL_1_REG 0x8BC |
| 75 | #define DBI_RO_WR_EN 1 |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 76 | |
| 77 | #define PERST_DELAY_US 1000 |
| 78 | |
Varadarajan Narayanan | 5d76117 | 2017-08-18 12:59:53 +0530 | [diff] [blame] | 79 | #define PCIE20_v3_PARF_SLV_ADDR_SPACE_SIZE 0x358 |
| 80 | #define SLV_ADDR_SPACE_SZ 0x10000000 |
| 81 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 82 | struct qcom_pcie_resources_2_1_0 { |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 83 | struct clk *iface_clk; |
| 84 | struct clk *core_clk; |
| 85 | struct clk *phy_clk; |
| 86 | struct reset_control *pci_reset; |
| 87 | struct reset_control *axi_reset; |
| 88 | struct reset_control *ahb_reset; |
| 89 | struct reset_control *por_reset; |
| 90 | struct reset_control *phy_reset; |
| 91 | struct regulator *vdda; |
| 92 | struct regulator *vdda_phy; |
| 93 | struct regulator *vdda_refclk; |
| 94 | }; |
| 95 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 96 | struct qcom_pcie_resources_1_0_0 { |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 97 | struct clk *iface; |
| 98 | struct clk *aux; |
| 99 | struct clk *master_bus; |
| 100 | struct clk *slave_bus; |
| 101 | struct reset_control *core; |
| 102 | struct regulator *vdda; |
| 103 | }; |
| 104 | |
Srinivas Kandagatla | f625b1a | 2018-02-15 13:22:48 +0000 | [diff] [blame^] | 105 | #define QCOM_PCIE_2_3_2_MAX_SUPPLY 2 |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 106 | struct qcom_pcie_resources_2_3_2 { |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 107 | struct clk *aux_clk; |
| 108 | struct clk *master_clk; |
| 109 | struct clk *slave_clk; |
| 110 | struct clk *cfg_clk; |
| 111 | struct clk *pipe_clk; |
Srinivas Kandagatla | f625b1a | 2018-02-15 13:22:48 +0000 | [diff] [blame^] | 112 | struct regulator_bulk_data supplies[QCOM_PCIE_2_3_2_MAX_SUPPLY]; |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 115 | struct qcom_pcie_resources_2_4_0 { |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 116 | struct clk *aux_clk; |
| 117 | struct clk *master_clk; |
| 118 | struct clk *slave_clk; |
| 119 | struct reset_control *axi_m_reset; |
| 120 | struct reset_control *axi_s_reset; |
| 121 | struct reset_control *pipe_reset; |
| 122 | struct reset_control *axi_m_vmid_reset; |
| 123 | struct reset_control *axi_s_xpu_reset; |
| 124 | struct reset_control *parf_reset; |
| 125 | struct reset_control *phy_reset; |
| 126 | struct reset_control *axi_m_sticky_reset; |
| 127 | struct reset_control *pipe_sticky_reset; |
| 128 | struct reset_control *pwr_reset; |
| 129 | struct reset_control *ahb_reset; |
| 130 | struct reset_control *phy_ahb_reset; |
| 131 | }; |
| 132 | |
Varadarajan Narayanan | 5d76117 | 2017-08-18 12:59:53 +0530 | [diff] [blame] | 133 | struct qcom_pcie_resources_2_3_3 { |
| 134 | struct clk *iface; |
| 135 | struct clk *axi_m_clk; |
| 136 | struct clk *axi_s_clk; |
| 137 | struct clk *ahb_clk; |
| 138 | struct clk *aux_clk; |
| 139 | struct reset_control *rst[7]; |
| 140 | }; |
| 141 | |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 142 | union qcom_pcie_resources { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 143 | struct qcom_pcie_resources_1_0_0 v1_0_0; |
| 144 | struct qcom_pcie_resources_2_1_0 v2_1_0; |
| 145 | struct qcom_pcie_resources_2_3_2 v2_3_2; |
Varadarajan Narayanan | 5d76117 | 2017-08-18 12:59:53 +0530 | [diff] [blame] | 146 | struct qcom_pcie_resources_2_3_3 v2_3_3; |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 147 | struct qcom_pcie_resources_2_4_0 v2_4_0; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | struct qcom_pcie; |
| 151 | |
| 152 | struct qcom_pcie_ops { |
| 153 | int (*get_resources)(struct qcom_pcie *pcie); |
| 154 | int (*init)(struct qcom_pcie *pcie); |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 155 | int (*post_init)(struct qcom_pcie *pcie); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 156 | void (*deinit)(struct qcom_pcie *pcie); |
Bjorn Andersson | 71cee8e | 2017-07-15 23:42:03 -0700 | [diff] [blame] | 157 | void (*post_deinit)(struct qcom_pcie *pcie); |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 158 | void (*ltssm_enable)(struct qcom_pcie *pcie); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | struct qcom_pcie { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 162 | struct dw_pcie *pci; |
Bjorn Helgaas | ee05369 | 2016-10-06 13:39:37 -0500 | [diff] [blame] | 163 | void __iomem *parf; /* DT parf */ |
| 164 | void __iomem *elbi; /* DT elbi */ |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 165 | union qcom_pcie_resources res; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 166 | struct phy *phy; |
| 167 | struct gpio_desc *reset; |
Julia Lawall | 8e64a7c | 2018-01-02 14:28:00 +0100 | [diff] [blame] | 168 | const struct qcom_pcie_ops *ops; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 169 | }; |
| 170 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 171 | #define to_qcom_pcie(x) dev_get_drvdata((x)->dev) |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 172 | |
| 173 | static void qcom_ep_reset_assert(struct qcom_pcie *pcie) |
| 174 | { |
Fabio Estevam | a8c2038 | 2017-07-16 19:56:38 -0300 | [diff] [blame] | 175 | gpiod_set_value_cansleep(pcie->reset, 1); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 176 | usleep_range(PERST_DELAY_US, PERST_DELAY_US + 500); |
| 177 | } |
| 178 | |
| 179 | static void qcom_ep_reset_deassert(struct qcom_pcie *pcie) |
| 180 | { |
Fabio Estevam | a8c2038 | 2017-07-16 19:56:38 -0300 | [diff] [blame] | 181 | gpiod_set_value_cansleep(pcie->reset, 0); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 182 | usleep_range(PERST_DELAY_US, PERST_DELAY_US + 500); |
| 183 | } |
| 184 | |
| 185 | static irqreturn_t qcom_pcie_msi_irq_handler(int irq, void *arg) |
| 186 | { |
| 187 | struct pcie_port *pp = arg; |
| 188 | |
| 189 | return dw_handle_msi_irq(pp); |
| 190 | } |
| 191 | |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 192 | static int qcom_pcie_establish_link(struct qcom_pcie *pcie) |
| 193 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 194 | struct dw_pcie *pci = pcie->pci; |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 195 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 196 | if (dw_pcie_link_up(pci)) |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 197 | return 0; |
| 198 | |
| 199 | /* Enable Link Training state machine */ |
| 200 | if (pcie->ops->ltssm_enable) |
| 201 | pcie->ops->ltssm_enable(pcie); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 202 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 203 | return dw_pcie_wait_for_link(pci); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 204 | } |
| 205 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 206 | static void qcom_pcie_2_1_0_ltssm_enable(struct qcom_pcie *pcie) |
Bjorn Helgaas | 5d0f1b8 | 2017-05-24 15:19:36 -0500 | [diff] [blame] | 207 | { |
| 208 | u32 val; |
| 209 | |
| 210 | /* enable link training */ |
| 211 | val = readl(pcie->elbi + PCIE20_ELBI_SYS_CTRL); |
| 212 | val |= PCIE20_ELBI_SYS_CTRL_LT_ENABLE; |
| 213 | writel(val, pcie->elbi + PCIE20_ELBI_SYS_CTRL); |
| 214 | } |
| 215 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 216 | static int qcom_pcie_get_resources_2_1_0(struct qcom_pcie *pcie) |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 217 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 218 | struct qcom_pcie_resources_2_1_0 *res = &pcie->res.v2_1_0; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 219 | struct dw_pcie *pci = pcie->pci; |
| 220 | struct device *dev = pci->dev; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 221 | |
| 222 | res->vdda = devm_regulator_get(dev, "vdda"); |
| 223 | if (IS_ERR(res->vdda)) |
| 224 | return PTR_ERR(res->vdda); |
| 225 | |
| 226 | res->vdda_phy = devm_regulator_get(dev, "vdda_phy"); |
| 227 | if (IS_ERR(res->vdda_phy)) |
| 228 | return PTR_ERR(res->vdda_phy); |
| 229 | |
| 230 | res->vdda_refclk = devm_regulator_get(dev, "vdda_refclk"); |
| 231 | if (IS_ERR(res->vdda_refclk)) |
| 232 | return PTR_ERR(res->vdda_refclk); |
| 233 | |
| 234 | res->iface_clk = devm_clk_get(dev, "iface"); |
| 235 | if (IS_ERR(res->iface_clk)) |
| 236 | return PTR_ERR(res->iface_clk); |
| 237 | |
| 238 | res->core_clk = devm_clk_get(dev, "core"); |
| 239 | if (IS_ERR(res->core_clk)) |
| 240 | return PTR_ERR(res->core_clk); |
| 241 | |
| 242 | res->phy_clk = devm_clk_get(dev, "phy"); |
| 243 | if (IS_ERR(res->phy_clk)) |
| 244 | return PTR_ERR(res->phy_clk); |
| 245 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 246 | res->pci_reset = devm_reset_control_get_exclusive(dev, "pci"); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 247 | if (IS_ERR(res->pci_reset)) |
| 248 | return PTR_ERR(res->pci_reset); |
| 249 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 250 | res->axi_reset = devm_reset_control_get_exclusive(dev, "axi"); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 251 | if (IS_ERR(res->axi_reset)) |
| 252 | return PTR_ERR(res->axi_reset); |
| 253 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 254 | res->ahb_reset = devm_reset_control_get_exclusive(dev, "ahb"); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 255 | if (IS_ERR(res->ahb_reset)) |
| 256 | return PTR_ERR(res->ahb_reset); |
| 257 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 258 | res->por_reset = devm_reset_control_get_exclusive(dev, "por"); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 259 | if (IS_ERR(res->por_reset)) |
| 260 | return PTR_ERR(res->por_reset); |
| 261 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 262 | res->phy_reset = devm_reset_control_get_exclusive(dev, "phy"); |
Fengguang Wu | 11a61a8 | 2017-02-04 09:35:32 +0800 | [diff] [blame] | 263 | return PTR_ERR_OR_ZERO(res->phy_reset); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 264 | } |
| 265 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 266 | static void qcom_pcie_deinit_2_1_0(struct qcom_pcie *pcie) |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 267 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 268 | struct qcom_pcie_resources_2_1_0 *res = &pcie->res.v2_1_0; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 269 | |
| 270 | reset_control_assert(res->pci_reset); |
| 271 | reset_control_assert(res->axi_reset); |
| 272 | reset_control_assert(res->ahb_reset); |
| 273 | reset_control_assert(res->por_reset); |
| 274 | reset_control_assert(res->pci_reset); |
| 275 | clk_disable_unprepare(res->iface_clk); |
| 276 | clk_disable_unprepare(res->core_clk); |
| 277 | clk_disable_unprepare(res->phy_clk); |
| 278 | regulator_disable(res->vdda); |
| 279 | regulator_disable(res->vdda_phy); |
| 280 | regulator_disable(res->vdda_refclk); |
| 281 | } |
| 282 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 283 | static int qcom_pcie_init_2_1_0(struct qcom_pcie *pcie) |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 284 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 285 | struct qcom_pcie_resources_2_1_0 *res = &pcie->res.v2_1_0; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 286 | struct dw_pcie *pci = pcie->pci; |
| 287 | struct device *dev = pci->dev; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 288 | u32 val; |
| 289 | int ret; |
| 290 | |
| 291 | ret = regulator_enable(res->vdda); |
| 292 | if (ret) { |
| 293 | dev_err(dev, "cannot enable vdda regulator\n"); |
| 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | ret = regulator_enable(res->vdda_refclk); |
| 298 | if (ret) { |
| 299 | dev_err(dev, "cannot enable vdda_refclk regulator\n"); |
| 300 | goto err_refclk; |
| 301 | } |
| 302 | |
| 303 | ret = regulator_enable(res->vdda_phy); |
| 304 | if (ret) { |
| 305 | dev_err(dev, "cannot enable vdda_phy regulator\n"); |
| 306 | goto err_vdda_phy; |
| 307 | } |
| 308 | |
| 309 | ret = reset_control_assert(res->ahb_reset); |
| 310 | if (ret) { |
| 311 | dev_err(dev, "cannot assert ahb reset\n"); |
| 312 | goto err_assert_ahb; |
| 313 | } |
| 314 | |
| 315 | ret = clk_prepare_enable(res->iface_clk); |
| 316 | if (ret) { |
| 317 | dev_err(dev, "cannot prepare/enable iface clock\n"); |
| 318 | goto err_assert_ahb; |
| 319 | } |
| 320 | |
| 321 | ret = clk_prepare_enable(res->phy_clk); |
| 322 | if (ret) { |
| 323 | dev_err(dev, "cannot prepare/enable phy clock\n"); |
| 324 | goto err_clk_phy; |
| 325 | } |
| 326 | |
| 327 | ret = clk_prepare_enable(res->core_clk); |
| 328 | if (ret) { |
| 329 | dev_err(dev, "cannot prepare/enable core clock\n"); |
| 330 | goto err_clk_core; |
| 331 | } |
| 332 | |
| 333 | ret = reset_control_deassert(res->ahb_reset); |
| 334 | if (ret) { |
| 335 | dev_err(dev, "cannot deassert ahb reset\n"); |
| 336 | goto err_deassert_ahb; |
| 337 | } |
| 338 | |
| 339 | /* enable PCIe clocks and resets */ |
| 340 | val = readl(pcie->parf + PCIE20_PARF_PHY_CTRL); |
| 341 | val &= ~BIT(0); |
| 342 | writel(val, pcie->parf + PCIE20_PARF_PHY_CTRL); |
| 343 | |
| 344 | /* enable external reference clock */ |
| 345 | val = readl(pcie->parf + PCIE20_PARF_PHY_REFCLK); |
| 346 | val |= BIT(16); |
| 347 | writel(val, pcie->parf + PCIE20_PARF_PHY_REFCLK); |
| 348 | |
| 349 | ret = reset_control_deassert(res->phy_reset); |
| 350 | if (ret) { |
| 351 | dev_err(dev, "cannot deassert phy reset\n"); |
| 352 | return ret; |
| 353 | } |
| 354 | |
| 355 | ret = reset_control_deassert(res->pci_reset); |
| 356 | if (ret) { |
| 357 | dev_err(dev, "cannot deassert pci reset\n"); |
| 358 | return ret; |
| 359 | } |
| 360 | |
| 361 | ret = reset_control_deassert(res->por_reset); |
| 362 | if (ret) { |
| 363 | dev_err(dev, "cannot deassert por reset\n"); |
| 364 | return ret; |
| 365 | } |
| 366 | |
| 367 | ret = reset_control_deassert(res->axi_reset); |
| 368 | if (ret) { |
| 369 | dev_err(dev, "cannot deassert axi reset\n"); |
| 370 | return ret; |
| 371 | } |
| 372 | |
| 373 | /* wait for clock acquisition */ |
| 374 | usleep_range(1000, 1500); |
| 375 | |
Srinivas Kandagatla | b8f2a85 | 2017-06-29 17:34:55 +0200 | [diff] [blame] | 376 | |
| 377 | /* Set the Max TLP size to 2K, instead of using default of 4K */ |
| 378 | writel(CFG_REMOTE_RD_REQ_BRIDGE_SIZE_2K, |
| 379 | pci->dbi_base + PCIE20_AXI_MSTR_RESP_COMP_CTRL0); |
| 380 | writel(CFG_BRIDGE_SB_INIT, |
| 381 | pci->dbi_base + PCIE20_AXI_MSTR_RESP_COMP_CTRL1); |
| 382 | |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 383 | return 0; |
| 384 | |
| 385 | err_deassert_ahb: |
| 386 | clk_disable_unprepare(res->core_clk); |
| 387 | err_clk_core: |
| 388 | clk_disable_unprepare(res->phy_clk); |
| 389 | err_clk_phy: |
| 390 | clk_disable_unprepare(res->iface_clk); |
| 391 | err_assert_ahb: |
| 392 | regulator_disable(res->vdda_phy); |
| 393 | err_vdda_phy: |
| 394 | regulator_disable(res->vdda_refclk); |
| 395 | err_refclk: |
| 396 | regulator_disable(res->vdda); |
| 397 | |
| 398 | return ret; |
| 399 | } |
| 400 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 401 | static int qcom_pcie_get_resources_1_0_0(struct qcom_pcie *pcie) |
Bjorn Helgaas | 5d0f1b8 | 2017-05-24 15:19:36 -0500 | [diff] [blame] | 402 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 403 | struct qcom_pcie_resources_1_0_0 *res = &pcie->res.v1_0_0; |
Bjorn Helgaas | 5d0f1b8 | 2017-05-24 15:19:36 -0500 | [diff] [blame] | 404 | struct dw_pcie *pci = pcie->pci; |
| 405 | struct device *dev = pci->dev; |
| 406 | |
| 407 | res->vdda = devm_regulator_get(dev, "vdda"); |
| 408 | if (IS_ERR(res->vdda)) |
| 409 | return PTR_ERR(res->vdda); |
| 410 | |
| 411 | res->iface = devm_clk_get(dev, "iface"); |
| 412 | if (IS_ERR(res->iface)) |
| 413 | return PTR_ERR(res->iface); |
| 414 | |
| 415 | res->aux = devm_clk_get(dev, "aux"); |
| 416 | if (IS_ERR(res->aux)) |
| 417 | return PTR_ERR(res->aux); |
| 418 | |
| 419 | res->master_bus = devm_clk_get(dev, "master_bus"); |
| 420 | if (IS_ERR(res->master_bus)) |
| 421 | return PTR_ERR(res->master_bus); |
| 422 | |
| 423 | res->slave_bus = devm_clk_get(dev, "slave_bus"); |
| 424 | if (IS_ERR(res->slave_bus)) |
| 425 | return PTR_ERR(res->slave_bus); |
| 426 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 427 | res->core = devm_reset_control_get_exclusive(dev, "core"); |
Bjorn Helgaas | 5d0f1b8 | 2017-05-24 15:19:36 -0500 | [diff] [blame] | 428 | return PTR_ERR_OR_ZERO(res->core); |
| 429 | } |
| 430 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 431 | static void qcom_pcie_deinit_1_0_0(struct qcom_pcie *pcie) |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 432 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 433 | struct qcom_pcie_resources_1_0_0 *res = &pcie->res.v1_0_0; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 434 | |
| 435 | reset_control_assert(res->core); |
| 436 | clk_disable_unprepare(res->slave_bus); |
| 437 | clk_disable_unprepare(res->master_bus); |
| 438 | clk_disable_unprepare(res->iface); |
| 439 | clk_disable_unprepare(res->aux); |
| 440 | regulator_disable(res->vdda); |
| 441 | } |
| 442 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 443 | static int qcom_pcie_init_1_0_0(struct qcom_pcie *pcie) |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 444 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 445 | struct qcom_pcie_resources_1_0_0 *res = &pcie->res.v1_0_0; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 446 | struct dw_pcie *pci = pcie->pci; |
| 447 | struct device *dev = pci->dev; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 448 | int ret; |
| 449 | |
| 450 | ret = reset_control_deassert(res->core); |
| 451 | if (ret) { |
| 452 | dev_err(dev, "cannot deassert core reset\n"); |
| 453 | return ret; |
| 454 | } |
| 455 | |
| 456 | ret = clk_prepare_enable(res->aux); |
| 457 | if (ret) { |
| 458 | dev_err(dev, "cannot prepare/enable aux clock\n"); |
| 459 | goto err_res; |
| 460 | } |
| 461 | |
| 462 | ret = clk_prepare_enable(res->iface); |
| 463 | if (ret) { |
| 464 | dev_err(dev, "cannot prepare/enable iface clock\n"); |
| 465 | goto err_aux; |
| 466 | } |
| 467 | |
| 468 | ret = clk_prepare_enable(res->master_bus); |
| 469 | if (ret) { |
| 470 | dev_err(dev, "cannot prepare/enable master_bus clock\n"); |
| 471 | goto err_iface; |
| 472 | } |
| 473 | |
| 474 | ret = clk_prepare_enable(res->slave_bus); |
| 475 | if (ret) { |
| 476 | dev_err(dev, "cannot prepare/enable slave_bus clock\n"); |
| 477 | goto err_master; |
| 478 | } |
| 479 | |
| 480 | ret = regulator_enable(res->vdda); |
| 481 | if (ret) { |
| 482 | dev_err(dev, "cannot enable vdda regulator\n"); |
| 483 | goto err_slave; |
| 484 | } |
| 485 | |
| 486 | /* change DBI base address */ |
| 487 | writel(0, pcie->parf + PCIE20_PARF_DBI_BASE_ADDR); |
| 488 | |
| 489 | if (IS_ENABLED(CONFIG_PCI_MSI)) { |
| 490 | u32 val = readl(pcie->parf + PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT); |
| 491 | |
| 492 | val |= BIT(31); |
| 493 | writel(val, pcie->parf + PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT); |
| 494 | } |
| 495 | |
| 496 | return 0; |
| 497 | err_slave: |
| 498 | clk_disable_unprepare(res->slave_bus); |
| 499 | err_master: |
| 500 | clk_disable_unprepare(res->master_bus); |
| 501 | err_iface: |
| 502 | clk_disable_unprepare(res->iface); |
| 503 | err_aux: |
| 504 | clk_disable_unprepare(res->aux); |
| 505 | err_res: |
| 506 | reset_control_assert(res->core); |
| 507 | |
| 508 | return ret; |
| 509 | } |
| 510 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 511 | static void qcom_pcie_2_3_2_ltssm_enable(struct qcom_pcie *pcie) |
Bjorn Helgaas | 5d0f1b8 | 2017-05-24 15:19:36 -0500 | [diff] [blame] | 512 | { |
| 513 | u32 val; |
| 514 | |
| 515 | /* enable link training */ |
| 516 | val = readl(pcie->parf + PCIE20_PARF_LTSSM); |
| 517 | val |= BIT(8); |
| 518 | writel(val, pcie->parf + PCIE20_PARF_LTSSM); |
| 519 | } |
| 520 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 521 | static int qcom_pcie_get_resources_2_3_2(struct qcom_pcie *pcie) |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 522 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 523 | struct qcom_pcie_resources_2_3_2 *res = &pcie->res.v2_3_2; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 524 | struct dw_pcie *pci = pcie->pci; |
| 525 | struct device *dev = pci->dev; |
Srinivas Kandagatla | f625b1a | 2018-02-15 13:22:48 +0000 | [diff] [blame^] | 526 | int ret; |
| 527 | |
| 528 | res->supplies[0].supply = "vdda"; |
| 529 | res->supplies[1].supply = "vddpe-3v3"; |
| 530 | ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(res->supplies), |
| 531 | res->supplies); |
| 532 | if (ret) |
| 533 | return ret; |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 534 | |
| 535 | res->aux_clk = devm_clk_get(dev, "aux"); |
| 536 | if (IS_ERR(res->aux_clk)) |
| 537 | return PTR_ERR(res->aux_clk); |
| 538 | |
| 539 | res->cfg_clk = devm_clk_get(dev, "cfg"); |
| 540 | if (IS_ERR(res->cfg_clk)) |
| 541 | return PTR_ERR(res->cfg_clk); |
| 542 | |
| 543 | res->master_clk = devm_clk_get(dev, "bus_master"); |
| 544 | if (IS_ERR(res->master_clk)) |
| 545 | return PTR_ERR(res->master_clk); |
| 546 | |
| 547 | res->slave_clk = devm_clk_get(dev, "bus_slave"); |
| 548 | if (IS_ERR(res->slave_clk)) |
| 549 | return PTR_ERR(res->slave_clk); |
| 550 | |
| 551 | res->pipe_clk = devm_clk_get(dev, "pipe"); |
Fengguang Wu | 11a61a8 | 2017-02-04 09:35:32 +0800 | [diff] [blame] | 552 | return PTR_ERR_OR_ZERO(res->pipe_clk); |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 555 | static void qcom_pcie_deinit_2_3_2(struct qcom_pcie *pcie) |
Bjorn Helgaas | 5d0f1b8 | 2017-05-24 15:19:36 -0500 | [diff] [blame] | 556 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 557 | struct qcom_pcie_resources_2_3_2 *res = &pcie->res.v2_3_2; |
Bjorn Helgaas | 5d0f1b8 | 2017-05-24 15:19:36 -0500 | [diff] [blame] | 558 | |
Bjorn Helgaas | 5d0f1b8 | 2017-05-24 15:19:36 -0500 | [diff] [blame] | 559 | clk_disable_unprepare(res->slave_clk); |
| 560 | clk_disable_unprepare(res->master_clk); |
| 561 | clk_disable_unprepare(res->cfg_clk); |
| 562 | clk_disable_unprepare(res->aux_clk); |
Srinivas Kandagatla | f625b1a | 2018-02-15 13:22:48 +0000 | [diff] [blame^] | 563 | |
| 564 | regulator_bulk_disable(ARRAY_SIZE(res->supplies), res->supplies); |
Bjorn Helgaas | 5d0f1b8 | 2017-05-24 15:19:36 -0500 | [diff] [blame] | 565 | } |
| 566 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 567 | static void qcom_pcie_post_deinit_2_3_2(struct qcom_pcie *pcie) |
Bjorn Andersson | 71cee8e | 2017-07-15 23:42:03 -0700 | [diff] [blame] | 568 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 569 | struct qcom_pcie_resources_2_3_2 *res = &pcie->res.v2_3_2; |
Bjorn Andersson | 71cee8e | 2017-07-15 23:42:03 -0700 | [diff] [blame] | 570 | |
| 571 | clk_disable_unprepare(res->pipe_clk); |
| 572 | } |
| 573 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 574 | static int qcom_pcie_init_2_3_2(struct qcom_pcie *pcie) |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 575 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 576 | struct qcom_pcie_resources_2_3_2 *res = &pcie->res.v2_3_2; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 577 | struct dw_pcie *pci = pcie->pci; |
| 578 | struct device *dev = pci->dev; |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 579 | u32 val; |
| 580 | int ret; |
| 581 | |
Srinivas Kandagatla | f625b1a | 2018-02-15 13:22:48 +0000 | [diff] [blame^] | 582 | ret = regulator_bulk_enable(ARRAY_SIZE(res->supplies), res->supplies); |
| 583 | if (ret < 0) { |
| 584 | dev_err(dev, "cannot enable regulators\n"); |
| 585 | return ret; |
| 586 | } |
| 587 | |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 588 | ret = clk_prepare_enable(res->aux_clk); |
| 589 | if (ret) { |
| 590 | dev_err(dev, "cannot prepare/enable aux clock\n"); |
Srinivas Kandagatla | f625b1a | 2018-02-15 13:22:48 +0000 | [diff] [blame^] | 591 | goto err_aux_clk; |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | ret = clk_prepare_enable(res->cfg_clk); |
| 595 | if (ret) { |
| 596 | dev_err(dev, "cannot prepare/enable cfg clock\n"); |
| 597 | goto err_cfg_clk; |
| 598 | } |
| 599 | |
| 600 | ret = clk_prepare_enable(res->master_clk); |
| 601 | if (ret) { |
| 602 | dev_err(dev, "cannot prepare/enable master clock\n"); |
| 603 | goto err_master_clk; |
| 604 | } |
| 605 | |
| 606 | ret = clk_prepare_enable(res->slave_clk); |
| 607 | if (ret) { |
| 608 | dev_err(dev, "cannot prepare/enable slave clock\n"); |
| 609 | goto err_slave_clk; |
| 610 | } |
| 611 | |
| 612 | /* enable PCIe clocks and resets */ |
| 613 | val = readl(pcie->parf + PCIE20_PARF_PHY_CTRL); |
| 614 | val &= ~BIT(0); |
| 615 | writel(val, pcie->parf + PCIE20_PARF_PHY_CTRL); |
| 616 | |
| 617 | /* change DBI base address */ |
| 618 | writel(0, pcie->parf + PCIE20_PARF_DBI_BASE_ADDR); |
| 619 | |
| 620 | /* MAC PHY_POWERDOWN MUX DISABLE */ |
| 621 | val = readl(pcie->parf + PCIE20_PARF_SYS_CTRL); |
| 622 | val &= ~BIT(29); |
| 623 | writel(val, pcie->parf + PCIE20_PARF_SYS_CTRL); |
| 624 | |
| 625 | val = readl(pcie->parf + PCIE20_PARF_MHI_CLOCK_RESET_CTRL); |
| 626 | val |= BIT(4); |
| 627 | writel(val, pcie->parf + PCIE20_PARF_MHI_CLOCK_RESET_CTRL); |
| 628 | |
| 629 | val = readl(pcie->parf + PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT_V2); |
| 630 | val |= BIT(31); |
| 631 | writel(val, pcie->parf + PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT_V2); |
| 632 | |
| 633 | return 0; |
| 634 | |
| 635 | err_slave_clk: |
| 636 | clk_disable_unprepare(res->master_clk); |
| 637 | err_master_clk: |
| 638 | clk_disable_unprepare(res->cfg_clk); |
| 639 | err_cfg_clk: |
| 640 | clk_disable_unprepare(res->aux_clk); |
| 641 | |
Srinivas Kandagatla | f625b1a | 2018-02-15 13:22:48 +0000 | [diff] [blame^] | 642 | err_aux_clk: |
| 643 | regulator_bulk_disable(ARRAY_SIZE(res->supplies), res->supplies); |
| 644 | |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 645 | return ret; |
| 646 | } |
| 647 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 648 | static int qcom_pcie_post_init_2_3_2(struct qcom_pcie *pcie) |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 649 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 650 | struct qcom_pcie_resources_2_3_2 *res = &pcie->res.v2_3_2; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 651 | struct dw_pcie *pci = pcie->pci; |
| 652 | struct device *dev = pci->dev; |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 653 | int ret; |
| 654 | |
| 655 | ret = clk_prepare_enable(res->pipe_clk); |
| 656 | if (ret) { |
| 657 | dev_err(dev, "cannot prepare/enable pipe clock\n"); |
| 658 | return ret; |
| 659 | } |
| 660 | |
| 661 | return 0; |
| 662 | } |
| 663 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 664 | static int qcom_pcie_get_resources_2_4_0(struct qcom_pcie *pcie) |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 665 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 666 | struct qcom_pcie_resources_2_4_0 *res = &pcie->res.v2_4_0; |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 667 | struct dw_pcie *pci = pcie->pci; |
| 668 | struct device *dev = pci->dev; |
| 669 | |
| 670 | res->aux_clk = devm_clk_get(dev, "aux"); |
| 671 | if (IS_ERR(res->aux_clk)) |
| 672 | return PTR_ERR(res->aux_clk); |
| 673 | |
| 674 | res->master_clk = devm_clk_get(dev, "master_bus"); |
| 675 | if (IS_ERR(res->master_clk)) |
| 676 | return PTR_ERR(res->master_clk); |
| 677 | |
| 678 | res->slave_clk = devm_clk_get(dev, "slave_bus"); |
| 679 | if (IS_ERR(res->slave_clk)) |
| 680 | return PTR_ERR(res->slave_clk); |
| 681 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 682 | res->axi_m_reset = devm_reset_control_get_exclusive(dev, "axi_m"); |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 683 | if (IS_ERR(res->axi_m_reset)) |
| 684 | return PTR_ERR(res->axi_m_reset); |
| 685 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 686 | res->axi_s_reset = devm_reset_control_get_exclusive(dev, "axi_s"); |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 687 | if (IS_ERR(res->axi_s_reset)) |
| 688 | return PTR_ERR(res->axi_s_reset); |
| 689 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 690 | res->pipe_reset = devm_reset_control_get_exclusive(dev, "pipe"); |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 691 | if (IS_ERR(res->pipe_reset)) |
| 692 | return PTR_ERR(res->pipe_reset); |
| 693 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 694 | res->axi_m_vmid_reset = devm_reset_control_get_exclusive(dev, |
| 695 | "axi_m_vmid"); |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 696 | if (IS_ERR(res->axi_m_vmid_reset)) |
| 697 | return PTR_ERR(res->axi_m_vmid_reset); |
| 698 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 699 | res->axi_s_xpu_reset = devm_reset_control_get_exclusive(dev, |
| 700 | "axi_s_xpu"); |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 701 | if (IS_ERR(res->axi_s_xpu_reset)) |
| 702 | return PTR_ERR(res->axi_s_xpu_reset); |
| 703 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 704 | res->parf_reset = devm_reset_control_get_exclusive(dev, "parf"); |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 705 | if (IS_ERR(res->parf_reset)) |
| 706 | return PTR_ERR(res->parf_reset); |
| 707 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 708 | res->phy_reset = devm_reset_control_get_exclusive(dev, "phy"); |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 709 | if (IS_ERR(res->phy_reset)) |
| 710 | return PTR_ERR(res->phy_reset); |
| 711 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 712 | res->axi_m_sticky_reset = devm_reset_control_get_exclusive(dev, |
| 713 | "axi_m_sticky"); |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 714 | if (IS_ERR(res->axi_m_sticky_reset)) |
| 715 | return PTR_ERR(res->axi_m_sticky_reset); |
| 716 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 717 | res->pipe_sticky_reset = devm_reset_control_get_exclusive(dev, |
| 718 | "pipe_sticky"); |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 719 | if (IS_ERR(res->pipe_sticky_reset)) |
| 720 | return PTR_ERR(res->pipe_sticky_reset); |
| 721 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 722 | res->pwr_reset = devm_reset_control_get_exclusive(dev, "pwr"); |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 723 | if (IS_ERR(res->pwr_reset)) |
| 724 | return PTR_ERR(res->pwr_reset); |
| 725 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 726 | res->ahb_reset = devm_reset_control_get_exclusive(dev, "ahb"); |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 727 | if (IS_ERR(res->ahb_reset)) |
| 728 | return PTR_ERR(res->ahb_reset); |
| 729 | |
Philipp Zabel | 244e000 | 2017-07-19 17:25:55 +0200 | [diff] [blame] | 730 | res->phy_ahb_reset = devm_reset_control_get_exclusive(dev, "phy_ahb"); |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 731 | if (IS_ERR(res->phy_ahb_reset)) |
| 732 | return PTR_ERR(res->phy_ahb_reset); |
| 733 | |
| 734 | return 0; |
| 735 | } |
| 736 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 737 | static void qcom_pcie_deinit_2_4_0(struct qcom_pcie *pcie) |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 738 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 739 | struct qcom_pcie_resources_2_4_0 *res = &pcie->res.v2_4_0; |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 740 | |
| 741 | reset_control_assert(res->axi_m_reset); |
| 742 | reset_control_assert(res->axi_s_reset); |
| 743 | reset_control_assert(res->pipe_reset); |
| 744 | reset_control_assert(res->pipe_sticky_reset); |
| 745 | reset_control_assert(res->phy_reset); |
| 746 | reset_control_assert(res->phy_ahb_reset); |
| 747 | reset_control_assert(res->axi_m_sticky_reset); |
| 748 | reset_control_assert(res->pwr_reset); |
| 749 | reset_control_assert(res->ahb_reset); |
| 750 | clk_disable_unprepare(res->aux_clk); |
| 751 | clk_disable_unprepare(res->master_clk); |
| 752 | clk_disable_unprepare(res->slave_clk); |
| 753 | } |
| 754 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 755 | static int qcom_pcie_init_2_4_0(struct qcom_pcie *pcie) |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 756 | { |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 757 | struct qcom_pcie_resources_2_4_0 *res = &pcie->res.v2_4_0; |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 758 | struct dw_pcie *pci = pcie->pci; |
| 759 | struct device *dev = pci->dev; |
| 760 | u32 val; |
| 761 | int ret; |
| 762 | |
| 763 | ret = reset_control_assert(res->axi_m_reset); |
| 764 | if (ret) { |
| 765 | dev_err(dev, "cannot assert axi master reset\n"); |
| 766 | return ret; |
| 767 | } |
| 768 | |
| 769 | ret = reset_control_assert(res->axi_s_reset); |
| 770 | if (ret) { |
Colin Ian King | 7a5966e | 2017-05-31 06:34:14 +0100 | [diff] [blame] | 771 | dev_err(dev, "cannot assert axi slave reset\n"); |
John Crispin | 90d52d5 | 2017-05-23 15:02:28 -0500 | [diff] [blame] | 772 | return ret; |
| 773 | } |
| 774 | |
| 775 | usleep_range(10000, 12000); |
| 776 | |
| 777 | ret = reset_control_assert(res->pipe_reset); |
| 778 | if (ret) { |
| 779 | dev_err(dev, "cannot assert pipe reset\n"); |
| 780 | return ret; |
| 781 | } |
| 782 | |
| 783 | ret = reset_control_assert(res->pipe_sticky_reset); |
| 784 | if (ret) { |
| 785 | dev_err(dev, "cannot assert pipe sticky reset\n"); |
| 786 | return ret; |
| 787 | } |
| 788 | |
| 789 | ret = reset_control_assert(res->phy_reset); |
| 790 | if (ret) { |
| 791 | dev_err(dev, "cannot assert phy reset\n"); |
| 792 | return ret; |
| 793 | } |
| 794 | |
| 795 | ret = reset_control_assert(res->phy_ahb_reset); |
| 796 | if (ret) { |
| 797 | dev_err(dev, "cannot assert phy ahb reset\n"); |
| 798 | return ret; |
| 799 | } |
| 800 | |
| 801 | usleep_range(10000, 12000); |
| 802 | |
| 803 | ret = reset_control_assert(res->axi_m_sticky_reset); |
| 804 | if (ret) { |
| 805 | dev_err(dev, "cannot assert axi master sticky reset\n"); |
| 806 | return ret; |
| 807 | } |
| 808 | |
| 809 | ret = reset_control_assert(res->pwr_reset); |
| 810 | if (ret) { |
| 811 | dev_err(dev, "cannot assert power reset\n"); |
| 812 | return ret; |
| 813 | } |
| 814 | |
| 815 | ret = reset_control_assert(res->ahb_reset); |
| 816 | if (ret) { |
| 817 | dev_err(dev, "cannot assert ahb reset\n"); |
| 818 | return ret; |
| 819 | } |
| 820 | |
| 821 | usleep_range(10000, 12000); |
| 822 | |
| 823 | ret = reset_control_deassert(res->phy_ahb_reset); |
| 824 | if (ret) { |
| 825 | dev_err(dev, "cannot deassert phy ahb reset\n"); |
| 826 | return ret; |
| 827 | } |
| 828 | |
| 829 | ret = reset_control_deassert(res->phy_reset); |
| 830 | if (ret) { |
| 831 | dev_err(dev, "cannot deassert phy reset\n"); |
| 832 | goto err_rst_phy; |
| 833 | } |
| 834 | |
| 835 | ret = reset_control_deassert(res->pipe_reset); |
| 836 | if (ret) { |
| 837 | dev_err(dev, "cannot deassert pipe reset\n"); |
| 838 | goto err_rst_pipe; |
| 839 | } |
| 840 | |
| 841 | ret = reset_control_deassert(res->pipe_sticky_reset); |
| 842 | if (ret) { |
| 843 | dev_err(dev, "cannot deassert pipe sticky reset\n"); |
| 844 | goto err_rst_pipe_sticky; |
| 845 | } |
| 846 | |
| 847 | usleep_range(10000, 12000); |
| 848 | |
| 849 | ret = reset_control_deassert(res->axi_m_reset); |
| 850 | if (ret) { |
| 851 | dev_err(dev, "cannot deassert axi master reset\n"); |
| 852 | goto err_rst_axi_m; |
| 853 | } |
| 854 | |
| 855 | ret = reset_control_deassert(res->axi_m_sticky_reset); |
| 856 | if (ret) { |
| 857 | dev_err(dev, "cannot deassert axi master sticky reset\n"); |
| 858 | goto err_rst_axi_m_sticky; |
| 859 | } |
| 860 | |
| 861 | ret = reset_control_deassert(res->axi_s_reset); |
| 862 | if (ret) { |
| 863 | dev_err(dev, "cannot deassert axi slave reset\n"); |
| 864 | goto err_rst_axi_s; |
| 865 | } |
| 866 | |
| 867 | ret = reset_control_deassert(res->pwr_reset); |
| 868 | if (ret) { |
| 869 | dev_err(dev, "cannot deassert power reset\n"); |
| 870 | goto err_rst_pwr; |
| 871 | } |
| 872 | |
| 873 | ret = reset_control_deassert(res->ahb_reset); |
| 874 | if (ret) { |
| 875 | dev_err(dev, "cannot deassert ahb reset\n"); |
| 876 | goto err_rst_ahb; |
| 877 | } |
| 878 | |
| 879 | usleep_range(10000, 12000); |
| 880 | |
| 881 | ret = clk_prepare_enable(res->aux_clk); |
| 882 | if (ret) { |
| 883 | dev_err(dev, "cannot prepare/enable iface clock\n"); |
| 884 | goto err_clk_aux; |
| 885 | } |
| 886 | |
| 887 | ret = clk_prepare_enable(res->master_clk); |
| 888 | if (ret) { |
| 889 | dev_err(dev, "cannot prepare/enable core clock\n"); |
| 890 | goto err_clk_axi_m; |
| 891 | } |
| 892 | |
| 893 | ret = clk_prepare_enable(res->slave_clk); |
| 894 | if (ret) { |
| 895 | dev_err(dev, "cannot prepare/enable phy clock\n"); |
| 896 | goto err_clk_axi_s; |
| 897 | } |
| 898 | |
| 899 | /* enable PCIe clocks and resets */ |
| 900 | val = readl(pcie->parf + PCIE20_PARF_PHY_CTRL); |
| 901 | val &= !BIT(0); |
| 902 | writel(val, pcie->parf + PCIE20_PARF_PHY_CTRL); |
| 903 | |
| 904 | /* change DBI base address */ |
| 905 | writel(0, pcie->parf + PCIE20_PARF_DBI_BASE_ADDR); |
| 906 | |
| 907 | /* MAC PHY_POWERDOWN MUX DISABLE */ |
| 908 | val = readl(pcie->parf + PCIE20_PARF_SYS_CTRL); |
| 909 | val &= ~BIT(29); |
| 910 | writel(val, pcie->parf + PCIE20_PARF_SYS_CTRL); |
| 911 | |
| 912 | val = readl(pcie->parf + PCIE20_PARF_MHI_CLOCK_RESET_CTRL); |
| 913 | val |= BIT(4); |
| 914 | writel(val, pcie->parf + PCIE20_PARF_MHI_CLOCK_RESET_CTRL); |
| 915 | |
| 916 | val = readl(pcie->parf + PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT_V2); |
| 917 | val |= BIT(31); |
| 918 | writel(val, pcie->parf + PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT_V2); |
| 919 | |
| 920 | return 0; |
| 921 | |
| 922 | err_clk_axi_s: |
| 923 | clk_disable_unprepare(res->master_clk); |
| 924 | err_clk_axi_m: |
| 925 | clk_disable_unprepare(res->aux_clk); |
| 926 | err_clk_aux: |
| 927 | reset_control_assert(res->ahb_reset); |
| 928 | err_rst_ahb: |
| 929 | reset_control_assert(res->pwr_reset); |
| 930 | err_rst_pwr: |
| 931 | reset_control_assert(res->axi_s_reset); |
| 932 | err_rst_axi_s: |
| 933 | reset_control_assert(res->axi_m_sticky_reset); |
| 934 | err_rst_axi_m_sticky: |
| 935 | reset_control_assert(res->axi_m_reset); |
| 936 | err_rst_axi_m: |
| 937 | reset_control_assert(res->pipe_sticky_reset); |
| 938 | err_rst_pipe_sticky: |
| 939 | reset_control_assert(res->pipe_reset); |
| 940 | err_rst_pipe: |
| 941 | reset_control_assert(res->phy_reset); |
| 942 | err_rst_phy: |
| 943 | reset_control_assert(res->phy_ahb_reset); |
| 944 | return ret; |
| 945 | } |
| 946 | |
Varadarajan Narayanan | 5d76117 | 2017-08-18 12:59:53 +0530 | [diff] [blame] | 947 | static int qcom_pcie_get_resources_2_3_3(struct qcom_pcie *pcie) |
| 948 | { |
| 949 | struct qcom_pcie_resources_2_3_3 *res = &pcie->res.v2_3_3; |
| 950 | struct dw_pcie *pci = pcie->pci; |
| 951 | struct device *dev = pci->dev; |
| 952 | int i; |
| 953 | const char *rst_names[] = { "axi_m", "axi_s", "pipe", |
| 954 | "axi_m_sticky", "sticky", |
| 955 | "ahb", "sleep", }; |
| 956 | |
| 957 | res->iface = devm_clk_get(dev, "iface"); |
| 958 | if (IS_ERR(res->iface)) |
| 959 | return PTR_ERR(res->iface); |
| 960 | |
| 961 | res->axi_m_clk = devm_clk_get(dev, "axi_m"); |
| 962 | if (IS_ERR(res->axi_m_clk)) |
| 963 | return PTR_ERR(res->axi_m_clk); |
| 964 | |
| 965 | res->axi_s_clk = devm_clk_get(dev, "axi_s"); |
| 966 | if (IS_ERR(res->axi_s_clk)) |
| 967 | return PTR_ERR(res->axi_s_clk); |
| 968 | |
| 969 | res->ahb_clk = devm_clk_get(dev, "ahb"); |
| 970 | if (IS_ERR(res->ahb_clk)) |
| 971 | return PTR_ERR(res->ahb_clk); |
| 972 | |
| 973 | res->aux_clk = devm_clk_get(dev, "aux"); |
| 974 | if (IS_ERR(res->aux_clk)) |
| 975 | return PTR_ERR(res->aux_clk); |
| 976 | |
| 977 | for (i = 0; i < ARRAY_SIZE(rst_names); i++) { |
| 978 | res->rst[i] = devm_reset_control_get(dev, rst_names[i]); |
| 979 | if (IS_ERR(res->rst[i])) |
| 980 | return PTR_ERR(res->rst[i]); |
| 981 | } |
| 982 | |
| 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | static void qcom_pcie_deinit_2_3_3(struct qcom_pcie *pcie) |
| 987 | { |
| 988 | struct qcom_pcie_resources_2_3_3 *res = &pcie->res.v2_3_3; |
| 989 | |
| 990 | clk_disable_unprepare(res->iface); |
| 991 | clk_disable_unprepare(res->axi_m_clk); |
| 992 | clk_disable_unprepare(res->axi_s_clk); |
| 993 | clk_disable_unprepare(res->ahb_clk); |
| 994 | clk_disable_unprepare(res->aux_clk); |
| 995 | } |
| 996 | |
| 997 | static int qcom_pcie_init_2_3_3(struct qcom_pcie *pcie) |
| 998 | { |
| 999 | struct qcom_pcie_resources_2_3_3 *res = &pcie->res.v2_3_3; |
| 1000 | struct dw_pcie *pci = pcie->pci; |
| 1001 | struct device *dev = pci->dev; |
| 1002 | int i, ret; |
| 1003 | u32 val; |
| 1004 | |
| 1005 | for (i = 0; i < ARRAY_SIZE(res->rst); i++) { |
| 1006 | ret = reset_control_assert(res->rst[i]); |
| 1007 | if (ret) { |
| 1008 | dev_err(dev, "reset #%d assert failed (%d)\n", i, ret); |
| 1009 | return ret; |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | usleep_range(2000, 2500); |
| 1014 | |
| 1015 | for (i = 0; i < ARRAY_SIZE(res->rst); i++) { |
| 1016 | ret = reset_control_deassert(res->rst[i]); |
| 1017 | if (ret) { |
| 1018 | dev_err(dev, "reset #%d deassert failed (%d)\n", i, |
| 1019 | ret); |
| 1020 | return ret; |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | /* |
| 1025 | * Don't have a way to see if the reset has completed. |
| 1026 | * Wait for some time. |
| 1027 | */ |
| 1028 | usleep_range(2000, 2500); |
| 1029 | |
| 1030 | ret = clk_prepare_enable(res->iface); |
| 1031 | if (ret) { |
| 1032 | dev_err(dev, "cannot prepare/enable core clock\n"); |
| 1033 | goto err_clk_iface; |
| 1034 | } |
| 1035 | |
| 1036 | ret = clk_prepare_enable(res->axi_m_clk); |
| 1037 | if (ret) { |
| 1038 | dev_err(dev, "cannot prepare/enable core clock\n"); |
| 1039 | goto err_clk_axi_m; |
| 1040 | } |
| 1041 | |
| 1042 | ret = clk_prepare_enable(res->axi_s_clk); |
| 1043 | if (ret) { |
| 1044 | dev_err(dev, "cannot prepare/enable axi slave clock\n"); |
| 1045 | goto err_clk_axi_s; |
| 1046 | } |
| 1047 | |
| 1048 | ret = clk_prepare_enable(res->ahb_clk); |
| 1049 | if (ret) { |
| 1050 | dev_err(dev, "cannot prepare/enable ahb clock\n"); |
| 1051 | goto err_clk_ahb; |
| 1052 | } |
| 1053 | |
| 1054 | ret = clk_prepare_enable(res->aux_clk); |
| 1055 | if (ret) { |
| 1056 | dev_err(dev, "cannot prepare/enable aux clock\n"); |
| 1057 | goto err_clk_aux; |
| 1058 | } |
| 1059 | |
| 1060 | writel(SLV_ADDR_SPACE_SZ, |
| 1061 | pcie->parf + PCIE20_v3_PARF_SLV_ADDR_SPACE_SIZE); |
| 1062 | |
| 1063 | val = readl(pcie->parf + PCIE20_PARF_PHY_CTRL); |
| 1064 | val &= ~BIT(0); |
| 1065 | writel(val, pcie->parf + PCIE20_PARF_PHY_CTRL); |
| 1066 | |
| 1067 | writel(0, pcie->parf + PCIE20_PARF_DBI_BASE_ADDR); |
| 1068 | |
| 1069 | writel(MST_WAKEUP_EN | SLV_WAKEUP_EN | MSTR_ACLK_CGC_DIS |
| 1070 | | SLV_ACLK_CGC_DIS | CORE_CLK_CGC_DIS | |
| 1071 | AUX_PWR_DET | L23_CLK_RMV_DIS | L1_CLK_RMV_DIS, |
| 1072 | pcie->parf + PCIE20_PARF_SYS_CTRL); |
| 1073 | writel(0, pcie->parf + PCIE20_PARF_Q2A_FLUSH); |
| 1074 | |
| 1075 | writel(CMD_BME_VAL, pci->dbi_base + PCIE20_COMMAND_STATUS); |
| 1076 | writel(DBI_RO_WR_EN, pci->dbi_base + PCIE20_MISC_CONTROL_1_REG); |
| 1077 | writel(PCIE_CAP_LINK1_VAL, pci->dbi_base + PCIE20_CAP_LINK_1); |
| 1078 | |
| 1079 | val = readl(pci->dbi_base + PCIE20_CAP_LINK_CAPABILITIES); |
| 1080 | val &= ~PCIE20_CAP_ACTIVE_STATE_LINK_PM_SUPPORT; |
| 1081 | writel(val, pci->dbi_base + PCIE20_CAP_LINK_CAPABILITIES); |
| 1082 | |
| 1083 | writel(PCIE_CAP_CPL_TIMEOUT_DISABLE, pci->dbi_base + |
| 1084 | PCIE20_DEVICE_CONTROL2_STATUS2); |
| 1085 | |
| 1086 | return 0; |
| 1087 | |
| 1088 | err_clk_aux: |
| 1089 | clk_disable_unprepare(res->ahb_clk); |
| 1090 | err_clk_ahb: |
| 1091 | clk_disable_unprepare(res->axi_s_clk); |
| 1092 | err_clk_axi_s: |
| 1093 | clk_disable_unprepare(res->axi_m_clk); |
| 1094 | err_clk_axi_m: |
| 1095 | clk_disable_unprepare(res->iface); |
| 1096 | err_clk_iface: |
| 1097 | /* |
| 1098 | * Not checking for failure, will anyway return |
| 1099 | * the original failure in 'ret'. |
| 1100 | */ |
| 1101 | for (i = 0; i < ARRAY_SIZE(res->rst); i++) |
| 1102 | reset_control_assert(res->rst[i]); |
| 1103 | |
| 1104 | return ret; |
| 1105 | } |
| 1106 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 1107 | static int qcom_pcie_link_up(struct dw_pcie *pci) |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1108 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 1109 | u16 val = readw(pci->dbi_base + PCIE20_CAP + PCI_EXP_LNKSTA); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1110 | |
| 1111 | return !!(val & PCI_EXP_LNKSTA_DLLLA); |
| 1112 | } |
| 1113 | |
Bjorn Andersson | 4a30176 | 2017-07-15 23:39:45 -0700 | [diff] [blame] | 1114 | static int qcom_pcie_host_init(struct pcie_port *pp) |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1115 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 1116 | struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
| 1117 | struct qcom_pcie *pcie = to_qcom_pcie(pci); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1118 | int ret; |
| 1119 | |
| 1120 | qcom_ep_reset_assert(pcie); |
| 1121 | |
| 1122 | ret = pcie->ops->init(pcie); |
| 1123 | if (ret) |
Bjorn Andersson | 89539f0 | 2017-07-15 23:41:53 -0700 | [diff] [blame] | 1124 | return ret; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1125 | |
| 1126 | ret = phy_power_on(pcie->phy); |
| 1127 | if (ret) |
| 1128 | goto err_deinit; |
| 1129 | |
Bjorn Andersson | 71cee8e | 2017-07-15 23:42:03 -0700 | [diff] [blame] | 1130 | if (pcie->ops->post_init) { |
| 1131 | ret = pcie->ops->post_init(pcie); |
| 1132 | if (ret) |
| 1133 | goto err_disable_phy; |
| 1134 | } |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 1135 | |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1136 | dw_pcie_setup_rc(pp); |
| 1137 | |
| 1138 | if (IS_ENABLED(CONFIG_PCI_MSI)) |
| 1139 | dw_pcie_msi_init(pp); |
| 1140 | |
| 1141 | qcom_ep_reset_deassert(pcie); |
| 1142 | |
| 1143 | ret = qcom_pcie_establish_link(pcie); |
| 1144 | if (ret) |
| 1145 | goto err; |
| 1146 | |
Bjorn Andersson | 4a30176 | 2017-07-15 23:39:45 -0700 | [diff] [blame] | 1147 | return 0; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1148 | err: |
| 1149 | qcom_ep_reset_assert(pcie); |
Bjorn Andersson | 71cee8e | 2017-07-15 23:42:03 -0700 | [diff] [blame] | 1150 | if (pcie->ops->post_deinit) |
| 1151 | pcie->ops->post_deinit(pcie); |
| 1152 | err_disable_phy: |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1153 | phy_power_off(pcie->phy); |
| 1154 | err_deinit: |
| 1155 | pcie->ops->deinit(pcie); |
Bjorn Andersson | 4a30176 | 2017-07-15 23:39:45 -0700 | [diff] [blame] | 1156 | |
| 1157 | return ret; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | static int qcom_pcie_rd_own_conf(struct pcie_port *pp, int where, int size, |
| 1161 | u32 *val) |
| 1162 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 1163 | struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
| 1164 | |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1165 | /* the device class is not reported correctly from the register */ |
| 1166 | if (where == PCI_CLASS_REVISION && size == 4) { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 1167 | *val = readl(pci->dbi_base + PCI_CLASS_REVISION); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1168 | *val &= 0xff; /* keep revision id */ |
| 1169 | *val |= PCI_CLASS_BRIDGE_PCI << 16; |
| 1170 | return PCIBIOS_SUCCESSFUL; |
| 1171 | } |
| 1172 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 1173 | return dw_pcie_read(pci->dbi_base + where, size, val); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1174 | } |
| 1175 | |
Jisheng Zhang | 4ab2e7c | 2017-06-05 16:53:46 +0800 | [diff] [blame] | 1176 | static const struct dw_pcie_host_ops qcom_pcie_dw_ops = { |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1177 | .host_init = qcom_pcie_host_init, |
| 1178 | .rd_own_conf = qcom_pcie_rd_own_conf, |
| 1179 | }; |
| 1180 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 1181 | /* Qcom IP rev.: 2.1.0 Synopsys IP rev.: 4.01a */ |
| 1182 | static const struct qcom_pcie_ops ops_2_1_0 = { |
| 1183 | .get_resources = qcom_pcie_get_resources_2_1_0, |
| 1184 | .init = qcom_pcie_init_2_1_0, |
| 1185 | .deinit = qcom_pcie_deinit_2_1_0, |
| 1186 | .ltssm_enable = qcom_pcie_2_1_0_ltssm_enable, |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1187 | }; |
| 1188 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 1189 | /* Qcom IP rev.: 1.0.0 Synopsys IP rev.: 4.11a */ |
| 1190 | static const struct qcom_pcie_ops ops_1_0_0 = { |
| 1191 | .get_resources = qcom_pcie_get_resources_1_0_0, |
| 1192 | .init = qcom_pcie_init_1_0_0, |
| 1193 | .deinit = qcom_pcie_deinit_1_0_0, |
| 1194 | .ltssm_enable = qcom_pcie_2_1_0_ltssm_enable, |
Srinivas Kandagatla | d0491fc | 2016-11-22 10:43:29 +0000 | [diff] [blame] | 1195 | }; |
| 1196 | |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 1197 | /* Qcom IP rev.: 2.3.2 Synopsys IP rev.: 4.21a */ |
| 1198 | static const struct qcom_pcie_ops ops_2_3_2 = { |
| 1199 | .get_resources = qcom_pcie_get_resources_2_3_2, |
| 1200 | .init = qcom_pcie_init_2_3_2, |
| 1201 | .post_init = qcom_pcie_post_init_2_3_2, |
| 1202 | .deinit = qcom_pcie_deinit_2_3_2, |
| 1203 | .post_deinit = qcom_pcie_post_deinit_2_3_2, |
| 1204 | .ltssm_enable = qcom_pcie_2_3_2_ltssm_enable, |
| 1205 | }; |
| 1206 | |
| 1207 | /* Qcom IP rev.: 2.4.0 Synopsys IP rev.: 4.20a */ |
| 1208 | static const struct qcom_pcie_ops ops_2_4_0 = { |
| 1209 | .get_resources = qcom_pcie_get_resources_2_4_0, |
| 1210 | .init = qcom_pcie_init_2_4_0, |
| 1211 | .deinit = qcom_pcie_deinit_2_4_0, |
| 1212 | .ltssm_enable = qcom_pcie_2_3_2_ltssm_enable, |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1213 | }; |
| 1214 | |
Varadarajan Narayanan | 5d76117 | 2017-08-18 12:59:53 +0530 | [diff] [blame] | 1215 | /* Qcom IP rev.: 2.3.3 Synopsys IP rev.: 4.30a */ |
| 1216 | static const struct qcom_pcie_ops ops_2_3_3 = { |
| 1217 | .get_resources = qcom_pcie_get_resources_2_3_3, |
| 1218 | .init = qcom_pcie_init_2_3_3, |
| 1219 | .deinit = qcom_pcie_deinit_2_3_3, |
| 1220 | .ltssm_enable = qcom_pcie_2_3_2_ltssm_enable, |
| 1221 | }; |
| 1222 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 1223 | static const struct dw_pcie_ops dw_pcie_ops = { |
| 1224 | .link_up = qcom_pcie_link_up, |
| 1225 | }; |
| 1226 | |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1227 | static int qcom_pcie_probe(struct platform_device *pdev) |
| 1228 | { |
| 1229 | struct device *dev = &pdev->dev; |
| 1230 | struct resource *res; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1231 | struct pcie_port *pp; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 1232 | struct dw_pcie *pci; |
| 1233 | struct qcom_pcie *pcie; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1234 | int ret; |
| 1235 | |
| 1236 | pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); |
| 1237 | if (!pcie) |
| 1238 | return -ENOMEM; |
| 1239 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 1240 | pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); |
| 1241 | if (!pci) |
| 1242 | return -ENOMEM; |
| 1243 | |
| 1244 | pci->dev = dev; |
| 1245 | pci->ops = &dw_pcie_ops; |
| 1246 | pp = &pci->pp; |
| 1247 | |
Guenter Roeck | c046406 | 2017-02-25 02:08:12 -0800 | [diff] [blame] | 1248 | pcie->pci = pci; |
| 1249 | |
Julia Lawall | 8e64a7c | 2018-01-02 14:28:00 +0100 | [diff] [blame] | 1250 | pcie->ops = of_device_get_match_data(dev); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1251 | |
| 1252 | pcie->reset = devm_gpiod_get_optional(dev, "perst", GPIOD_OUT_LOW); |
| 1253 | if (IS_ERR(pcie->reset)) |
| 1254 | return PTR_ERR(pcie->reset); |
| 1255 | |
| 1256 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "parf"); |
| 1257 | pcie->parf = devm_ioremap_resource(dev, res); |
| 1258 | if (IS_ERR(pcie->parf)) |
| 1259 | return PTR_ERR(pcie->parf); |
| 1260 | |
| 1261 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi"); |
Lorenzo Pieralisi | 10c736f | 2017-04-19 17:49:01 +0100 | [diff] [blame] | 1262 | pci->dbi_base = devm_pci_remap_cfg_resource(dev, res); |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 1263 | if (IS_ERR(pci->dbi_base)) |
| 1264 | return PTR_ERR(pci->dbi_base); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1265 | |
| 1266 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "elbi"); |
| 1267 | pcie->elbi = devm_ioremap_resource(dev, res); |
| 1268 | if (IS_ERR(pcie->elbi)) |
| 1269 | return PTR_ERR(pcie->elbi); |
| 1270 | |
| 1271 | pcie->phy = devm_phy_optional_get(dev, "pciephy"); |
| 1272 | if (IS_ERR(pcie->phy)) |
| 1273 | return PTR_ERR(pcie->phy); |
| 1274 | |
| 1275 | ret = pcie->ops->get_resources(pcie); |
| 1276 | if (ret) |
| 1277 | return ret; |
| 1278 | |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1279 | pp->root_bus_nr = -1; |
| 1280 | pp->ops = &qcom_pcie_dw_ops; |
| 1281 | |
| 1282 | if (IS_ENABLED(CONFIG_PCI_MSI)) { |
| 1283 | pp->msi_irq = platform_get_irq_byname(pdev, "msi"); |
| 1284 | if (pp->msi_irq < 0) |
| 1285 | return pp->msi_irq; |
| 1286 | |
| 1287 | ret = devm_request_irq(dev, pp->msi_irq, |
| 1288 | qcom_pcie_msi_irq_handler, |
Jisheng Zhang | 3eefa79 | 2017-04-20 18:27:18 +0800 | [diff] [blame] | 1289 | IRQF_SHARED | IRQF_NO_THREAD, |
| 1290 | "qcom-pcie-msi", pp); |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1291 | if (ret) { |
| 1292 | dev_err(dev, "cannot request msi irq\n"); |
| 1293 | return ret; |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | ret = phy_init(pcie->phy); |
| 1298 | if (ret) |
| 1299 | return ret; |
| 1300 | |
Kishon Vijay Abraham I | 9bcf0a6 | 2017-02-15 18:48:11 +0530 | [diff] [blame] | 1301 | platform_set_drvdata(pdev, pcie); |
| 1302 | |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1303 | ret = dw_pcie_host_init(pp); |
| 1304 | if (ret) { |
| 1305 | dev_err(dev, "cannot initialize host\n"); |
| 1306 | return ret; |
| 1307 | } |
| 1308 | |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1309 | return 0; |
| 1310 | } |
| 1311 | |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1312 | static const struct of_device_id qcom_pcie_match[] = { |
Varadarajan Narayanan | 5d76117 | 2017-08-18 12:59:53 +0530 | [diff] [blame] | 1313 | { .compatible = "qcom,pcie-apq8084", .data = &ops_1_0_0 }, |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 1314 | { .compatible = "qcom,pcie-ipq8064", .data = &ops_2_1_0 }, |
| 1315 | { .compatible = "qcom,pcie-apq8064", .data = &ops_2_1_0 }, |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 1316 | { .compatible = "qcom,pcie-msm8996", .data = &ops_2_3_2 }, |
Varadarajan Narayanan | 5d76117 | 2017-08-18 12:59:53 +0530 | [diff] [blame] | 1317 | { .compatible = "qcom,pcie-ipq8074", .data = &ops_2_3_3 }, |
Varadarajan Narayanan | deff11f | 2017-08-18 12:59:51 +0530 | [diff] [blame] | 1318 | { .compatible = "qcom,pcie-ipq4019", .data = &ops_2_4_0 }, |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1319 | { } |
| 1320 | }; |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1321 | |
| 1322 | static struct platform_driver qcom_pcie_driver = { |
| 1323 | .probe = qcom_pcie_probe, |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1324 | .driver = { |
| 1325 | .name = "qcom-pcie", |
Paul Gortmaker | f9a6660 | 2016-08-24 16:57:48 -0400 | [diff] [blame] | 1326 | .suppress_bind_attrs = true, |
Stanimir Varbanov | 82a8238 | 2015-12-18 14:38:57 +0200 | [diff] [blame] | 1327 | .of_match_table = qcom_pcie_match, |
| 1328 | }, |
| 1329 | }; |
Paul Gortmaker | f9a6660 | 2016-08-24 16:57:48 -0400 | [diff] [blame] | 1330 | builtin_platform_driver(qcom_pcie_driver); |