Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 1 | /* |
| 2 | * PCIe host controller driver for Samsung EXYNOS SoCs |
| 3 | * |
| 4 | * Copyright (C) 2013 Samsung Electronics Co., Ltd. |
| 5 | * http://www.samsung.com |
| 6 | * |
| 7 | * Author: Jingoo Han <jg1.han@samsung.com> |
| 8 | * |
| 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 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/clk.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/gpio.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/kernel.h> |
Paul Gortmaker | caf5548 | 2016-08-22 17:59:47 -0400 | [diff] [blame] | 19 | #include <linux/init.h> |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 20 | #include <linux/of_gpio.h> |
| 21 | #include <linux/pci.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/resource.h> |
| 24 | #include <linux/signal.h> |
| 25 | #include <linux/types.h> |
| 26 | |
| 27 | #include "pcie-designware.h" |
| 28 | |
| 29 | #define to_exynos_pcie(x) container_of(x, struct exynos_pcie, pp) |
| 30 | |
| 31 | struct exynos_pcie { |
| 32 | void __iomem *elbi_base; |
| 33 | void __iomem *phy_base; |
| 34 | void __iomem *block_base; |
| 35 | int reset_gpio; |
| 36 | struct clk *clk; |
| 37 | struct clk *bus_clk; |
| 38 | struct pcie_port pp; |
| 39 | }; |
| 40 | |
| 41 | /* PCIe ELBI registers */ |
| 42 | #define PCIE_IRQ_PULSE 0x000 |
| 43 | #define IRQ_INTA_ASSERT (0x1 << 0) |
| 44 | #define IRQ_INTB_ASSERT (0x1 << 2) |
| 45 | #define IRQ_INTC_ASSERT (0x1 << 4) |
| 46 | #define IRQ_INTD_ASSERT (0x1 << 6) |
| 47 | #define PCIE_IRQ_LEVEL 0x004 |
| 48 | #define PCIE_IRQ_SPECIAL 0x008 |
| 49 | #define PCIE_IRQ_EN_PULSE 0x00c |
| 50 | #define PCIE_IRQ_EN_LEVEL 0x010 |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 51 | #define IRQ_MSI_ENABLE (0x1 << 2) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 52 | #define PCIE_IRQ_EN_SPECIAL 0x014 |
| 53 | #define PCIE_PWR_RESET 0x018 |
| 54 | #define PCIE_CORE_RESET 0x01c |
| 55 | #define PCIE_CORE_RESET_ENABLE (0x1 << 0) |
| 56 | #define PCIE_STICKY_RESET 0x020 |
| 57 | #define PCIE_NONSTICKY_RESET 0x024 |
| 58 | #define PCIE_APP_INIT_RESET 0x028 |
| 59 | #define PCIE_APP_LTSSM_ENABLE 0x02c |
| 60 | #define PCIE_ELBI_RDLH_LINKUP 0x064 |
| 61 | #define PCIE_ELBI_LTSSM_ENABLE 0x1 |
| 62 | #define PCIE_ELBI_SLV_AWMISC 0x11c |
| 63 | #define PCIE_ELBI_SLV_ARMISC 0x120 |
| 64 | #define PCIE_ELBI_SLV_DBI_ENABLE (0x1 << 21) |
| 65 | |
| 66 | /* PCIe Purple registers */ |
| 67 | #define PCIE_PHY_GLOBAL_RESET 0x000 |
| 68 | #define PCIE_PHY_COMMON_RESET 0x004 |
| 69 | #define PCIE_PHY_CMN_REG 0x008 |
| 70 | #define PCIE_PHY_MAC_RESET 0x00c |
| 71 | #define PCIE_PHY_PLL_LOCKED 0x010 |
| 72 | #define PCIE_PHY_TRSVREG_RESET 0x020 |
| 73 | #define PCIE_PHY_TRSV_RESET 0x024 |
| 74 | |
| 75 | /* PCIe PHY registers */ |
| 76 | #define PCIE_PHY_IMPEDANCE 0x004 |
| 77 | #define PCIE_PHY_PLL_DIV_0 0x008 |
| 78 | #define PCIE_PHY_PLL_BIAS 0x00c |
| 79 | #define PCIE_PHY_DCC_FEEDBACK 0x014 |
| 80 | #define PCIE_PHY_PLL_DIV_1 0x05c |
Jingoo Han | f62b878 | 2013-09-06 17:21:45 +0900 | [diff] [blame] | 81 | #define PCIE_PHY_COMMON_POWER 0x064 |
| 82 | #define PCIE_PHY_COMMON_PD_CMN (0x1 << 3) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 83 | #define PCIE_PHY_TRSV0_EMP_LVL 0x084 |
| 84 | #define PCIE_PHY_TRSV0_DRV_LVL 0x088 |
| 85 | #define PCIE_PHY_TRSV0_RXCDR 0x0ac |
Jingoo Han | f62b878 | 2013-09-06 17:21:45 +0900 | [diff] [blame] | 86 | #define PCIE_PHY_TRSV0_POWER 0x0c4 |
| 87 | #define PCIE_PHY_TRSV0_PD_TSV (0x1 << 7) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 88 | #define PCIE_PHY_TRSV0_LVCC 0x0dc |
| 89 | #define PCIE_PHY_TRSV1_EMP_LVL 0x144 |
| 90 | #define PCIE_PHY_TRSV1_RXCDR 0x16c |
Jingoo Han | f62b878 | 2013-09-06 17:21:45 +0900 | [diff] [blame] | 91 | #define PCIE_PHY_TRSV1_POWER 0x184 |
| 92 | #define PCIE_PHY_TRSV1_PD_TSV (0x1 << 7) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 93 | #define PCIE_PHY_TRSV1_LVCC 0x19c |
| 94 | #define PCIE_PHY_TRSV2_EMP_LVL 0x204 |
| 95 | #define PCIE_PHY_TRSV2_RXCDR 0x22c |
Jingoo Han | f62b878 | 2013-09-06 17:21:45 +0900 | [diff] [blame] | 96 | #define PCIE_PHY_TRSV2_POWER 0x244 |
| 97 | #define PCIE_PHY_TRSV2_PD_TSV (0x1 << 7) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 98 | #define PCIE_PHY_TRSV2_LVCC 0x25c |
| 99 | #define PCIE_PHY_TRSV3_EMP_LVL 0x2c4 |
| 100 | #define PCIE_PHY_TRSV3_RXCDR 0x2ec |
Jingoo Han | f62b878 | 2013-09-06 17:21:45 +0900 | [diff] [blame] | 101 | #define PCIE_PHY_TRSV3_POWER 0x304 |
| 102 | #define PCIE_PHY_TRSV3_PD_TSV (0x1 << 7) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 103 | #define PCIE_PHY_TRSV3_LVCC 0x31c |
| 104 | |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 105 | static inline void exynos_elb_writel(struct exynos_pcie *pcie, u32 val, u32 reg) |
| 106 | { |
| 107 | writel(val, pcie->elbi_base + reg); |
| 108 | } |
| 109 | |
| 110 | static inline u32 exynos_elb_readl(struct exynos_pcie *pcie, u32 reg) |
| 111 | { |
| 112 | return readl(pcie->elbi_base + reg); |
| 113 | } |
| 114 | |
| 115 | static inline void exynos_phy_writel(struct exynos_pcie *pcie, u32 val, u32 reg) |
| 116 | { |
| 117 | writel(val, pcie->phy_base + reg); |
| 118 | } |
| 119 | |
| 120 | static inline u32 exynos_phy_readl(struct exynos_pcie *pcie, u32 reg) |
| 121 | { |
| 122 | return readl(pcie->phy_base + reg); |
| 123 | } |
| 124 | |
| 125 | static inline void exynos_blk_writel(struct exynos_pcie *pcie, u32 val, u32 reg) |
| 126 | { |
| 127 | writel(val, pcie->block_base + reg); |
| 128 | } |
| 129 | |
| 130 | static inline u32 exynos_blk_readl(struct exynos_pcie *pcie, u32 reg) |
| 131 | { |
| 132 | return readl(pcie->block_base + reg); |
| 133 | } |
| 134 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 135 | static void exynos_pcie_sideband_dbi_w_mode(struct pcie_port *pp, bool on) |
| 136 | { |
| 137 | u32 val; |
| 138 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
| 139 | |
| 140 | if (on) { |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 141 | val = exynos_elb_readl(exynos_pcie, PCIE_ELBI_SLV_AWMISC); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 142 | val |= PCIE_ELBI_SLV_DBI_ENABLE; |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 143 | exynos_elb_writel(exynos_pcie, val, PCIE_ELBI_SLV_AWMISC); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 144 | } else { |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 145 | val = exynos_elb_readl(exynos_pcie, PCIE_ELBI_SLV_AWMISC); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 146 | val &= ~PCIE_ELBI_SLV_DBI_ENABLE; |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 147 | exynos_elb_writel(exynos_pcie, val, PCIE_ELBI_SLV_AWMISC); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
| 151 | static void exynos_pcie_sideband_dbi_r_mode(struct pcie_port *pp, bool on) |
| 152 | { |
| 153 | u32 val; |
| 154 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
| 155 | |
| 156 | if (on) { |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 157 | val = exynos_elb_readl(exynos_pcie, PCIE_ELBI_SLV_ARMISC); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 158 | val |= PCIE_ELBI_SLV_DBI_ENABLE; |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 159 | exynos_elb_writel(exynos_pcie, val, PCIE_ELBI_SLV_ARMISC); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 160 | } else { |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 161 | val = exynos_elb_readl(exynos_pcie, PCIE_ELBI_SLV_ARMISC); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 162 | val &= ~PCIE_ELBI_SLV_DBI_ENABLE; |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 163 | exynos_elb_writel(exynos_pcie, val, PCIE_ELBI_SLV_ARMISC); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
| 167 | static void exynos_pcie_assert_core_reset(struct pcie_port *pp) |
| 168 | { |
| 169 | u32 val; |
| 170 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 171 | |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 172 | val = exynos_elb_readl(exynos_pcie, PCIE_CORE_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 173 | val &= ~PCIE_CORE_RESET_ENABLE; |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 174 | exynos_elb_writel(exynos_pcie, val, PCIE_CORE_RESET); |
| 175 | exynos_elb_writel(exynos_pcie, 0, PCIE_PWR_RESET); |
| 176 | exynos_elb_writel(exynos_pcie, 0, PCIE_STICKY_RESET); |
| 177 | exynos_elb_writel(exynos_pcie, 0, PCIE_NONSTICKY_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static void exynos_pcie_deassert_core_reset(struct pcie_port *pp) |
| 181 | { |
| 182 | u32 val; |
| 183 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 184 | |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 185 | val = exynos_elb_readl(exynos_pcie, PCIE_CORE_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 186 | val |= PCIE_CORE_RESET_ENABLE; |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 187 | |
| 188 | exynos_elb_writel(exynos_pcie, val, PCIE_CORE_RESET); |
| 189 | exynos_elb_writel(exynos_pcie, 1, PCIE_STICKY_RESET); |
| 190 | exynos_elb_writel(exynos_pcie, 1, PCIE_NONSTICKY_RESET); |
| 191 | exynos_elb_writel(exynos_pcie, 1, PCIE_APP_INIT_RESET); |
| 192 | exynos_elb_writel(exynos_pcie, 0, PCIE_APP_INIT_RESET); |
| 193 | exynos_blk_writel(exynos_pcie, 1, PCIE_PHY_MAC_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static void exynos_pcie_assert_phy_reset(struct pcie_port *pp) |
| 197 | { |
| 198 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 199 | |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 200 | exynos_blk_writel(exynos_pcie, 0, PCIE_PHY_MAC_RESET); |
| 201 | exynos_blk_writel(exynos_pcie, 1, PCIE_PHY_GLOBAL_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static void exynos_pcie_deassert_phy_reset(struct pcie_port *pp) |
| 205 | { |
| 206 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 207 | |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 208 | exynos_blk_writel(exynos_pcie, 0, PCIE_PHY_GLOBAL_RESET); |
| 209 | exynos_elb_writel(exynos_pcie, 1, PCIE_PWR_RESET); |
| 210 | exynos_blk_writel(exynos_pcie, 0, PCIE_PHY_COMMON_RESET); |
| 211 | exynos_blk_writel(exynos_pcie, 0, PCIE_PHY_CMN_REG); |
| 212 | exynos_blk_writel(exynos_pcie, 0, PCIE_PHY_TRSVREG_RESET); |
| 213 | exynos_blk_writel(exynos_pcie, 0, PCIE_PHY_TRSV_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 214 | } |
| 215 | |
Jingoo Han | f62b878 | 2013-09-06 17:21:45 +0900 | [diff] [blame] | 216 | static void exynos_pcie_power_on_phy(struct pcie_port *pp) |
| 217 | { |
| 218 | u32 val; |
| 219 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
| 220 | |
| 221 | val = exynos_phy_readl(exynos_pcie, PCIE_PHY_COMMON_POWER); |
| 222 | val &= ~PCIE_PHY_COMMON_PD_CMN; |
| 223 | exynos_phy_writel(exynos_pcie, val, PCIE_PHY_COMMON_POWER); |
| 224 | |
| 225 | val = exynos_phy_readl(exynos_pcie, PCIE_PHY_TRSV0_POWER); |
| 226 | val &= ~PCIE_PHY_TRSV0_PD_TSV; |
| 227 | exynos_phy_writel(exynos_pcie, val, PCIE_PHY_TRSV0_POWER); |
| 228 | |
| 229 | val = exynos_phy_readl(exynos_pcie, PCIE_PHY_TRSV1_POWER); |
| 230 | val &= ~PCIE_PHY_TRSV1_PD_TSV; |
| 231 | exynos_phy_writel(exynos_pcie, val, PCIE_PHY_TRSV1_POWER); |
| 232 | |
| 233 | val = exynos_phy_readl(exynos_pcie, PCIE_PHY_TRSV2_POWER); |
| 234 | val &= ~PCIE_PHY_TRSV2_PD_TSV; |
| 235 | exynos_phy_writel(exynos_pcie, val, PCIE_PHY_TRSV2_POWER); |
| 236 | |
| 237 | val = exynos_phy_readl(exynos_pcie, PCIE_PHY_TRSV3_POWER); |
| 238 | val &= ~PCIE_PHY_TRSV3_PD_TSV; |
| 239 | exynos_phy_writel(exynos_pcie, val, PCIE_PHY_TRSV3_POWER); |
| 240 | } |
| 241 | |
| 242 | static void exynos_pcie_power_off_phy(struct pcie_port *pp) |
| 243 | { |
| 244 | u32 val; |
| 245 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
| 246 | |
| 247 | val = exynos_phy_readl(exynos_pcie, PCIE_PHY_COMMON_POWER); |
| 248 | val |= PCIE_PHY_COMMON_PD_CMN; |
| 249 | exynos_phy_writel(exynos_pcie, val, PCIE_PHY_COMMON_POWER); |
| 250 | |
| 251 | val = exynos_phy_readl(exynos_pcie, PCIE_PHY_TRSV0_POWER); |
| 252 | val |= PCIE_PHY_TRSV0_PD_TSV; |
| 253 | exynos_phy_writel(exynos_pcie, val, PCIE_PHY_TRSV0_POWER); |
| 254 | |
| 255 | val = exynos_phy_readl(exynos_pcie, PCIE_PHY_TRSV1_POWER); |
| 256 | val |= PCIE_PHY_TRSV1_PD_TSV; |
| 257 | exynos_phy_writel(exynos_pcie, val, PCIE_PHY_TRSV1_POWER); |
| 258 | |
| 259 | val = exynos_phy_readl(exynos_pcie, PCIE_PHY_TRSV2_POWER); |
| 260 | val |= PCIE_PHY_TRSV2_PD_TSV; |
| 261 | exynos_phy_writel(exynos_pcie, val, PCIE_PHY_TRSV2_POWER); |
| 262 | |
| 263 | val = exynos_phy_readl(exynos_pcie, PCIE_PHY_TRSV3_POWER); |
| 264 | val |= PCIE_PHY_TRSV3_PD_TSV; |
| 265 | exynos_phy_writel(exynos_pcie, val, PCIE_PHY_TRSV3_POWER); |
| 266 | } |
| 267 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 268 | static void exynos_pcie_init_phy(struct pcie_port *pp) |
| 269 | { |
| 270 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 271 | |
| 272 | /* DCC feedback control off */ |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 273 | exynos_phy_writel(exynos_pcie, 0x29, PCIE_PHY_DCC_FEEDBACK); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 274 | |
| 275 | /* set TX/RX impedance */ |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 276 | exynos_phy_writel(exynos_pcie, 0xd5, PCIE_PHY_IMPEDANCE); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 277 | |
| 278 | /* set 50Mhz PHY clock */ |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 279 | exynos_phy_writel(exynos_pcie, 0x14, PCIE_PHY_PLL_DIV_0); |
| 280 | exynos_phy_writel(exynos_pcie, 0x12, PCIE_PHY_PLL_DIV_1); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 281 | |
| 282 | /* set TX Differential output for lane 0 */ |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 283 | exynos_phy_writel(exynos_pcie, 0x7f, PCIE_PHY_TRSV0_DRV_LVL); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 284 | |
| 285 | /* set TX Pre-emphasis Level Control for lane 0 to minimum */ |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 286 | exynos_phy_writel(exynos_pcie, 0x0, PCIE_PHY_TRSV0_EMP_LVL); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 287 | |
| 288 | /* set RX clock and data recovery bandwidth */ |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 289 | exynos_phy_writel(exynos_pcie, 0xe7, PCIE_PHY_PLL_BIAS); |
| 290 | exynos_phy_writel(exynos_pcie, 0x82, PCIE_PHY_TRSV0_RXCDR); |
| 291 | exynos_phy_writel(exynos_pcie, 0x82, PCIE_PHY_TRSV1_RXCDR); |
| 292 | exynos_phy_writel(exynos_pcie, 0x82, PCIE_PHY_TRSV2_RXCDR); |
| 293 | exynos_phy_writel(exynos_pcie, 0x82, PCIE_PHY_TRSV3_RXCDR); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 294 | |
| 295 | /* change TX Pre-emphasis Level Control for lanes */ |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 296 | exynos_phy_writel(exynos_pcie, 0x39, PCIE_PHY_TRSV0_EMP_LVL); |
| 297 | exynos_phy_writel(exynos_pcie, 0x39, PCIE_PHY_TRSV1_EMP_LVL); |
| 298 | exynos_phy_writel(exynos_pcie, 0x39, PCIE_PHY_TRSV2_EMP_LVL); |
| 299 | exynos_phy_writel(exynos_pcie, 0x39, PCIE_PHY_TRSV3_EMP_LVL); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 300 | |
| 301 | /* set LVCC */ |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 302 | exynos_phy_writel(exynos_pcie, 0x20, PCIE_PHY_TRSV0_LVCC); |
| 303 | exynos_phy_writel(exynos_pcie, 0xa0, PCIE_PHY_TRSV1_LVCC); |
| 304 | exynos_phy_writel(exynos_pcie, 0xa0, PCIE_PHY_TRSV2_LVCC); |
| 305 | exynos_phy_writel(exynos_pcie, 0xa0, PCIE_PHY_TRSV3_LVCC); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | static void exynos_pcie_assert_reset(struct pcie_port *pp) |
| 309 | { |
| 310 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 311 | struct device *dev = pp->dev; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 312 | |
| 313 | if (exynos_pcie->reset_gpio >= 0) |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 314 | devm_gpio_request_one(dev, exynos_pcie->reset_gpio, |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 315 | GPIOF_OUT_INIT_HIGH, "RESET"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | static int exynos_pcie_establish_link(struct pcie_port *pp) |
| 319 | { |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 320 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 321 | struct device *dev = pp->dev; |
Bjorn Helgaas | 6cbb247 | 2015-06-02 16:47:17 -0500 | [diff] [blame] | 322 | u32 val; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 323 | |
| 324 | if (dw_pcie_link_up(pp)) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 325 | dev_err(dev, "Link already up\n"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | /* assert reset signals */ |
| 330 | exynos_pcie_assert_core_reset(pp); |
| 331 | exynos_pcie_assert_phy_reset(pp); |
| 332 | |
| 333 | /* de-assert phy reset */ |
| 334 | exynos_pcie_deassert_phy_reset(pp); |
| 335 | |
Jingoo Han | f62b878 | 2013-09-06 17:21:45 +0900 | [diff] [blame] | 336 | /* power on phy */ |
| 337 | exynos_pcie_power_on_phy(pp); |
| 338 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 339 | /* initialize phy */ |
| 340 | exynos_pcie_init_phy(pp); |
| 341 | |
| 342 | /* pulse for common reset */ |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 343 | exynos_blk_writel(exynos_pcie, 1, PCIE_PHY_COMMON_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 344 | udelay(500); |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 345 | exynos_blk_writel(exynos_pcie, 0, PCIE_PHY_COMMON_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 346 | |
| 347 | /* de-assert core reset */ |
| 348 | exynos_pcie_deassert_core_reset(pp); |
| 349 | |
| 350 | /* setup root complex */ |
| 351 | dw_pcie_setup_rc(pp); |
| 352 | |
| 353 | /* assert reset signal */ |
| 354 | exynos_pcie_assert_reset(pp); |
| 355 | |
| 356 | /* assert LTSSM enable */ |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 357 | exynos_elb_writel(exynos_pcie, PCIE_ELBI_LTSSM_ENABLE, |
| 358 | PCIE_APP_LTSSM_ENABLE); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 359 | |
| 360 | /* check if the link is up or not */ |
Joao Pinto | 886bc5c | 2016-03-10 14:44:35 -0600 | [diff] [blame] | 361 | if (!dw_pcie_wait_for_link(pp)) |
| 362 | return 0; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 363 | |
Bjorn Helgaas | 6cbb247 | 2015-06-02 16:47:17 -0500 | [diff] [blame] | 364 | while (exynos_phy_readl(exynos_pcie, PCIE_PHY_PLL_LOCKED) == 0) { |
| 365 | val = exynos_blk_readl(exynos_pcie, PCIE_PHY_PLL_LOCKED); |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 366 | dev_info(dev, "PLL Locked: 0x%x\n", val); |
Bjorn Helgaas | 6cbb247 | 2015-06-02 16:47:17 -0500 | [diff] [blame] | 367 | } |
| 368 | /* power off phy */ |
| 369 | exynos_pcie_power_off_phy(pp); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 370 | |
Joao Pinto | 886bc5c | 2016-03-10 14:44:35 -0600 | [diff] [blame] | 371 | return -ETIMEDOUT; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | static void exynos_pcie_clear_irq_pulse(struct pcie_port *pp) |
| 375 | { |
| 376 | u32 val; |
| 377 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 378 | |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 379 | val = exynos_elb_readl(exynos_pcie, PCIE_IRQ_PULSE); |
| 380 | exynos_elb_writel(exynos_pcie, val, PCIE_IRQ_PULSE); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static void exynos_pcie_enable_irq_pulse(struct pcie_port *pp) |
| 384 | { |
| 385 | u32 val; |
| 386 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 387 | |
| 388 | /* enable INTX interrupt */ |
| 389 | val = IRQ_INTA_ASSERT | IRQ_INTB_ASSERT | |
Jaehoon Chung | 01d06a9 | 2015-03-25 14:13:12 +0900 | [diff] [blame] | 390 | IRQ_INTC_ASSERT | IRQ_INTD_ASSERT; |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 391 | exynos_elb_writel(exynos_pcie, val, PCIE_IRQ_EN_PULSE); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | static irqreturn_t exynos_pcie_irq_handler(int irq, void *arg) |
| 395 | { |
| 396 | struct pcie_port *pp = arg; |
| 397 | |
| 398 | exynos_pcie_clear_irq_pulse(pp); |
| 399 | return IRQ_HANDLED; |
| 400 | } |
| 401 | |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 402 | static irqreturn_t exynos_pcie_msi_irq_handler(int irq, void *arg) |
| 403 | { |
| 404 | struct pcie_port *pp = arg; |
| 405 | |
Lucas Stach | 7f4f16e | 2014-03-28 17:52:58 +0100 | [diff] [blame] | 406 | return dw_handle_msi_irq(pp); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | static void exynos_pcie_msi_init(struct pcie_port *pp) |
| 410 | { |
| 411 | u32 val; |
| 412 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
| 413 | |
| 414 | dw_pcie_msi_init(pp); |
| 415 | |
| 416 | /* enable MSI interrupt */ |
| 417 | val = exynos_elb_readl(exynos_pcie, PCIE_IRQ_EN_LEVEL); |
| 418 | val |= IRQ_MSI_ENABLE; |
| 419 | exynos_elb_writel(exynos_pcie, val, PCIE_IRQ_EN_LEVEL); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 420 | } |
| 421 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 422 | static void exynos_pcie_enable_interrupts(struct pcie_port *pp) |
| 423 | { |
| 424 | exynos_pcie_enable_irq_pulse(pp); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 425 | |
| 426 | if (IS_ENABLED(CONFIG_PCI_MSI)) |
| 427 | exynos_pcie_msi_init(pp); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 428 | } |
| 429 | |
Bjorn Helgaas | 7e00dfd | 2016-10-06 13:25:46 -0500 | [diff] [blame] | 430 | static inline u32 exynos_pcie_readl_rc(struct pcie_port *pp, u32 reg) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 431 | { |
Bjorn Helgaas | 446fc23 | 2016-08-17 14:17:58 -0500 | [diff] [blame] | 432 | u32 val; |
| 433 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 434 | exynos_pcie_sideband_dbi_r_mode(pp, true); |
Bjorn Helgaas | 7e00dfd | 2016-10-06 13:25:46 -0500 | [diff] [blame] | 435 | val = readl(pp->dbi_base + reg); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 436 | exynos_pcie_sideband_dbi_r_mode(pp, false); |
Bjorn Helgaas | 446fc23 | 2016-08-17 14:17:58 -0500 | [diff] [blame] | 437 | return val; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 438 | } |
| 439 | |
Bjorn Helgaas | ad88021 | 2016-10-06 13:25:46 -0500 | [diff] [blame] | 440 | static inline void exynos_pcie_writel_rc(struct pcie_port *pp, u32 reg, u32 val) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 441 | { |
| 442 | exynos_pcie_sideband_dbi_w_mode(pp, true); |
Bjorn Helgaas | 7e00dfd | 2016-10-06 13:25:46 -0500 | [diff] [blame] | 443 | writel(val, pp->dbi_base + reg); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 444 | exynos_pcie_sideband_dbi_w_mode(pp, false); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | static int exynos_pcie_rd_own_conf(struct pcie_port *pp, int where, int size, |
| 448 | u32 *val) |
| 449 | { |
| 450 | int ret; |
| 451 | |
| 452 | exynos_pcie_sideband_dbi_r_mode(pp, true); |
Gabriele Paoloni | 4c45852 | 2015-10-08 14:27:48 -0500 | [diff] [blame] | 453 | ret = dw_pcie_cfg_read(pp->dbi_base + where, size, val); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 454 | exynos_pcie_sideband_dbi_r_mode(pp, false); |
| 455 | return ret; |
| 456 | } |
| 457 | |
| 458 | static int exynos_pcie_wr_own_conf(struct pcie_port *pp, int where, int size, |
| 459 | u32 val) |
| 460 | { |
| 461 | int ret; |
| 462 | |
| 463 | exynos_pcie_sideband_dbi_w_mode(pp, true); |
Gabriele Paoloni | 4c45852 | 2015-10-08 14:27:48 -0500 | [diff] [blame] | 464 | ret = dw_pcie_cfg_write(pp->dbi_base + where, size, val); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 465 | exynos_pcie_sideband_dbi_w_mode(pp, false); |
| 466 | return ret; |
| 467 | } |
| 468 | |
| 469 | static int exynos_pcie_link_up(struct pcie_port *pp) |
| 470 | { |
| 471 | struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp); |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 472 | u32 val = exynos_elb_readl(exynos_pcie, PCIE_ELBI_RDLH_LINKUP); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 473 | |
| 474 | if (val == PCIE_ELBI_LTSSM_ENABLE) |
| 475 | return 1; |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | static void exynos_pcie_host_init(struct pcie_port *pp) |
| 481 | { |
| 482 | exynos_pcie_establish_link(pp); |
| 483 | exynos_pcie_enable_interrupts(pp); |
| 484 | } |
| 485 | |
| 486 | static struct pcie_host_ops exynos_pcie_host_ops = { |
| 487 | .readl_rc = exynos_pcie_readl_rc, |
| 488 | .writel_rc = exynos_pcie_writel_rc, |
| 489 | .rd_own_conf = exynos_pcie_rd_own_conf, |
| 490 | .wr_own_conf = exynos_pcie_wr_own_conf, |
| 491 | .link_up = exynos_pcie_link_up, |
| 492 | .host_init = exynos_pcie_host_init, |
| 493 | }; |
| 494 | |
Jingoo Han | 70b3e89 | 2014-10-22 13:58:49 +0900 | [diff] [blame] | 495 | static int __init exynos_add_pcie_port(struct pcie_port *pp, |
| 496 | struct platform_device *pdev) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 497 | { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 498 | struct device *dev = pp->dev; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 499 | int ret; |
| 500 | |
| 501 | pp->irq = platform_get_irq(pdev, 1); |
| 502 | if (!pp->irq) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 503 | dev_err(dev, "failed to get irq\n"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 504 | return -ENODEV; |
| 505 | } |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 506 | ret = devm_request_irq(dev, pp->irq, exynos_pcie_irq_handler, |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 507 | IRQF_SHARED, "exynos-pcie", pp); |
| 508 | if (ret) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 509 | dev_err(dev, "failed to request irq\n"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 510 | return ret; |
| 511 | } |
| 512 | |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 513 | if (IS_ENABLED(CONFIG_PCI_MSI)) { |
| 514 | pp->msi_irq = platform_get_irq(pdev, 0); |
| 515 | if (!pp->msi_irq) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 516 | dev_err(dev, "failed to get msi irq\n"); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 517 | return -ENODEV; |
| 518 | } |
| 519 | |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 520 | ret = devm_request_irq(dev, pp->msi_irq, |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 521 | exynos_pcie_msi_irq_handler, |
Grygorii Strashko | 8ff0ef9 | 2015-12-10 21:18:20 +0200 | [diff] [blame] | 522 | IRQF_SHARED | IRQF_NO_THREAD, |
| 523 | "exynos-pcie", pp); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 524 | if (ret) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 525 | dev_err(dev, "failed to request msi irq\n"); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 526 | return ret; |
| 527 | } |
| 528 | } |
| 529 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 530 | pp->root_bus_nr = -1; |
| 531 | pp->ops = &exynos_pcie_host_ops; |
| 532 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 533 | ret = dw_pcie_host_init(pp); |
| 534 | if (ret) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 535 | dev_err(dev, "failed to initialize host\n"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 536 | return ret; |
| 537 | } |
| 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | static int __init exynos_pcie_probe(struct platform_device *pdev) |
| 543 | { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 544 | struct device *dev = &pdev->dev; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 545 | struct exynos_pcie *exynos_pcie; |
| 546 | struct pcie_port *pp; |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 547 | struct device_node *np = dev->of_node; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 548 | struct resource *elbi_base; |
| 549 | struct resource *phy_base; |
| 550 | struct resource *block_base; |
| 551 | int ret; |
| 552 | |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 553 | exynos_pcie = devm_kzalloc(dev, sizeof(*exynos_pcie), GFP_KERNEL); |
Jingoo Han | 755ba5e | 2014-05-09 14:31:25 +0900 | [diff] [blame] | 554 | if (!exynos_pcie) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 555 | return -ENOMEM; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 556 | |
| 557 | pp = &exynos_pcie->pp; |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 558 | pp->dev = dev; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 559 | |
| 560 | exynos_pcie->reset_gpio = of_get_named_gpio(np, "reset-gpio", 0); |
| 561 | |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 562 | exynos_pcie->clk = devm_clk_get(dev, "pcie"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 563 | if (IS_ERR(exynos_pcie->clk)) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 564 | dev_err(dev, "Failed to get pcie rc clock\n"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 565 | return PTR_ERR(exynos_pcie->clk); |
| 566 | } |
| 567 | ret = clk_prepare_enable(exynos_pcie->clk); |
| 568 | if (ret) |
| 569 | return ret; |
| 570 | |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 571 | exynos_pcie->bus_clk = devm_clk_get(dev, "pcie_bus"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 572 | if (IS_ERR(exynos_pcie->bus_clk)) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 573 | dev_err(dev, "Failed to get pcie bus clock\n"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 574 | ret = PTR_ERR(exynos_pcie->bus_clk); |
| 575 | goto fail_clk; |
| 576 | } |
| 577 | ret = clk_prepare_enable(exynos_pcie->bus_clk); |
| 578 | if (ret) |
| 579 | goto fail_clk; |
| 580 | |
| 581 | elbi_base = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 582 | exynos_pcie->elbi_base = devm_ioremap_resource(dev, elbi_base); |
Wei Yongjun | f8db3c9 | 2013-09-29 10:29:11 +0800 | [diff] [blame] | 583 | if (IS_ERR(exynos_pcie->elbi_base)) { |
| 584 | ret = PTR_ERR(exynos_pcie->elbi_base); |
| 585 | goto fail_bus_clk; |
| 586 | } |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 587 | |
| 588 | phy_base = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 589 | exynos_pcie->phy_base = devm_ioremap_resource(dev, phy_base); |
Wei Yongjun | f8db3c9 | 2013-09-29 10:29:11 +0800 | [diff] [blame] | 590 | if (IS_ERR(exynos_pcie->phy_base)) { |
| 591 | ret = PTR_ERR(exynos_pcie->phy_base); |
| 592 | goto fail_bus_clk; |
| 593 | } |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 594 | |
| 595 | block_base = platform_get_resource(pdev, IORESOURCE_MEM, 2); |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame^] | 596 | exynos_pcie->block_base = devm_ioremap_resource(dev, block_base); |
Wei Yongjun | f8db3c9 | 2013-09-29 10:29:11 +0800 | [diff] [blame] | 597 | if (IS_ERR(exynos_pcie->block_base)) { |
| 598 | ret = PTR_ERR(exynos_pcie->block_base); |
| 599 | goto fail_bus_clk; |
| 600 | } |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 601 | |
Jingoo Han | 70b3e89 | 2014-10-22 13:58:49 +0900 | [diff] [blame] | 602 | ret = exynos_add_pcie_port(pp, pdev); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 603 | if (ret < 0) |
| 604 | goto fail_bus_clk; |
| 605 | |
| 606 | platform_set_drvdata(pdev, exynos_pcie); |
| 607 | return 0; |
| 608 | |
| 609 | fail_bus_clk: |
| 610 | clk_disable_unprepare(exynos_pcie->bus_clk); |
| 611 | fail_clk: |
| 612 | clk_disable_unprepare(exynos_pcie->clk); |
| 613 | return ret; |
| 614 | } |
| 615 | |
| 616 | static int __exit exynos_pcie_remove(struct platform_device *pdev) |
| 617 | { |
| 618 | struct exynos_pcie *exynos_pcie = platform_get_drvdata(pdev); |
| 619 | |
| 620 | clk_disable_unprepare(exynos_pcie->bus_clk); |
| 621 | clk_disable_unprepare(exynos_pcie->clk); |
| 622 | |
| 623 | return 0; |
| 624 | } |
| 625 | |
| 626 | static const struct of_device_id exynos_pcie_of_match[] = { |
| 627 | { .compatible = "samsung,exynos5440-pcie", }, |
| 628 | {}, |
| 629 | }; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 630 | |
| 631 | static struct platform_driver exynos_pcie_driver = { |
| 632 | .remove = __exit_p(exynos_pcie_remove), |
| 633 | .driver = { |
| 634 | .name = "exynos-pcie", |
Sachin Kamat | eb36309 | 2013-10-21 14:36:43 +0530 | [diff] [blame] | 635 | .of_match_table = exynos_pcie_of_match, |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 636 | }, |
| 637 | }; |
| 638 | |
| 639 | /* Exynos PCIe driver does not allow module unload */ |
| 640 | |
Jingoo Han | 70b3e89 | 2014-10-22 13:58:49 +0900 | [diff] [blame] | 641 | static int __init exynos_pcie_init(void) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 642 | { |
| 643 | return platform_driver_probe(&exynos_pcie_driver, exynos_pcie_probe); |
| 644 | } |
Jingoo Han | 70b3e89 | 2014-10-22 13:58:49 +0900 | [diff] [blame] | 645 | subsys_initcall(exynos_pcie_init); |