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