| .. | .. |
|---|
| 14 | 14 | #include <linux/clk.h> |
|---|
| 15 | 15 | #include <linux/delay.h> |
|---|
| 16 | 16 | #include <linux/gpio/consumer.h> |
|---|
| 17 | | -#include <linux/of_address.h> |
|---|
| 17 | +#include <linux/iopoll.h> |
|---|
| 18 | +#include <linux/module.h> |
|---|
| 18 | 19 | #include <linux/of_pci.h> |
|---|
| 19 | 20 | #include <linux/phy/phy.h> |
|---|
| 20 | 21 | #include <linux/platform_device.h> |
|---|
| .. | .. |
|---|
| 28 | 29 | struct device *dev = rockchip->dev; |
|---|
| 29 | 30 | struct platform_device *pdev = to_platform_device(dev); |
|---|
| 30 | 31 | struct device_node *node = dev->of_node; |
|---|
| 31 | | - struct device_node *mem; |
|---|
| 32 | | - struct resource reg; |
|---|
| 33 | 32 | struct resource *regs; |
|---|
| 34 | 33 | int err; |
|---|
| 35 | 34 | |
|---|
| .. | .. |
|---|
| 48 | 47 | return -EINVAL; |
|---|
| 49 | 48 | } |
|---|
| 50 | 49 | |
|---|
| 51 | | - regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
|---|
| 52 | | - "apb-base"); |
|---|
| 53 | | - rockchip->apb_base = devm_ioremap_resource(dev, regs); |
|---|
| 50 | + rockchip->apb_base = |
|---|
| 51 | + devm_platform_ioremap_resource_byname(pdev, "apb-base"); |
|---|
| 54 | 52 | if (IS_ERR(rockchip->apb_base)) |
|---|
| 55 | 53 | return PTR_ERR(rockchip->apb_base); |
|---|
| 56 | 54 | |
|---|
| .. | .. |
|---|
| 86 | 84 | } |
|---|
| 87 | 85 | |
|---|
| 88 | 86 | rockchip->mgmt_sticky_rst = devm_reset_control_get_exclusive(dev, |
|---|
| 89 | | - "mgmt-sticky"); |
|---|
| 87 | + "mgmt-sticky"); |
|---|
| 90 | 88 | if (IS_ERR(rockchip->mgmt_sticky_rst)) { |
|---|
| 91 | 89 | if (PTR_ERR(rockchip->mgmt_sticky_rst) != -EPROBE_DEFER) |
|---|
| 92 | 90 | dev_err(dev, "missing mgmt-sticky reset property in node\n"); |
|---|
| .. | .. |
|---|
| 122 | 120 | } |
|---|
| 123 | 121 | |
|---|
| 124 | 122 | if (rockchip->is_rc) { |
|---|
| 125 | | - rockchip->ep_gpio = devm_gpiod_get_optional(dev, "ep", GPIOD_OUT_HIGH); |
|---|
| 126 | | - if (IS_ERR(rockchip->ep_gpio)) { |
|---|
| 127 | | - dev_err(dev, "invalid ep-gpios property in node\n"); |
|---|
| 128 | | - return PTR_ERR(rockchip->ep_gpio); |
|---|
| 129 | | - } |
|---|
| 123 | + rockchip->ep_gpio = devm_gpiod_get_optional(dev, "ep", |
|---|
| 124 | + GPIOD_OUT_HIGH); |
|---|
| 125 | + if (IS_ERR(rockchip->ep_gpio)) |
|---|
| 126 | + return dev_err_probe(dev, PTR_ERR(rockchip->ep_gpio), |
|---|
| 127 | + "failed to get ep GPIO\n"); |
|---|
| 130 | 128 | } |
|---|
| 131 | 129 | |
|---|
| 132 | 130 | rockchip->aclk_pcie = devm_clk_get(dev, "aclk"); |
|---|
| .. | .. |
|---|
| 153 | 151 | return PTR_ERR(rockchip->clk_pcie_pm); |
|---|
| 154 | 152 | } |
|---|
| 155 | 153 | |
|---|
| 156 | | - if (rockchip->is_rc) { |
|---|
| 157 | | - mem = of_parse_phandle(node, "memory-region", 0); |
|---|
| 158 | | - if (!mem) { |
|---|
| 159 | | - dev_warn(dev, "missing \"memory-region\" property\n"); |
|---|
| 160 | | - return 0; |
|---|
| 161 | | - } |
|---|
| 162 | | - |
|---|
| 163 | | - err = of_address_to_resource(mem, 0, ®); |
|---|
| 164 | | - if (err < 0) { |
|---|
| 165 | | - dev_warn(dev, "missing \"reg\" property\n"); |
|---|
| 166 | | - return 0; |
|---|
| 167 | | - } |
|---|
| 168 | | - |
|---|
| 169 | | - rockchip->mem_reserve_start = reg.start; |
|---|
| 170 | | - rockchip->mem_reserve_size = resource_size(®); |
|---|
| 171 | | - |
|---|
| 172 | | - err = of_property_read_u32(node, "rockchip,dma_trx_enabled", |
|---|
| 173 | | - &rockchip->dma_trx_enabled); |
|---|
| 174 | | - if (err < 0) { |
|---|
| 175 | | - dev_warn(dev, |
|---|
| 176 | | - "missing \"rockchip,dma_trx_enabled\" property\n"); |
|---|
| 177 | | - return 0; |
|---|
| 178 | | - } |
|---|
| 179 | | - |
|---|
| 180 | | - err = of_property_read_u32(node, "rockchip,deferred", |
|---|
| 181 | | - &rockchip->deferred); |
|---|
| 182 | | - if (err < 0) { |
|---|
| 183 | | - dev_warn(dev, "missing \"rockchip,deferred\" property\n"); |
|---|
| 184 | | - return 0; |
|---|
| 185 | | - } |
|---|
| 186 | | - } |
|---|
| 187 | | - |
|---|
| 188 | 154 | return 0; |
|---|
| 189 | 155 | } |
|---|
| 190 | 156 | EXPORT_SYMBOL_GPL(rockchip_pcie_parse_dt); |
|---|
| 157 | + |
|---|
| 158 | +#define rockchip_pcie_read_addr(addr) rockchip_pcie_read(rockchip, addr) |
|---|
| 159 | +/* 100 ms max wait time for PHY PLLs to lock */ |
|---|
| 160 | +#define RK_PHY_PLL_LOCK_TIMEOUT_US 100000 |
|---|
| 161 | +/* Sleep should be less than 20ms */ |
|---|
| 162 | +#define RK_PHY_PLL_LOCK_SLEEP_US 1000 |
|---|
| 191 | 163 | |
|---|
| 192 | 164 | int rockchip_pcie_init_port(struct rockchip_pcie *rockchip) |
|---|
| 193 | 165 | { |
|---|
| .. | .. |
|---|
| 288 | 260 | dev_err(dev, "power on phy%d err %d\n", i, err); |
|---|
| 289 | 261 | goto err_power_off_phy; |
|---|
| 290 | 262 | } |
|---|
| 263 | + } |
|---|
| 264 | + |
|---|
| 265 | + err = readx_poll_timeout(rockchip_pcie_read_addr, |
|---|
| 266 | + PCIE_CLIENT_SIDE_BAND_STATUS, |
|---|
| 267 | + regs, !(regs & PCIE_CLIENT_PHY_ST), |
|---|
| 268 | + RK_PHY_PLL_LOCK_SLEEP_US, |
|---|
| 269 | + RK_PHY_PLL_LOCK_TIMEOUT_US); |
|---|
| 270 | + if (err) { |
|---|
| 271 | + dev_err(dev, "PHY PLLs could not lock, %d\n", err); |
|---|
| 272 | + goto err_power_off_phy; |
|---|
| 291 | 273 | } |
|---|
| 292 | 274 | |
|---|
| 293 | 275 | /* |
|---|
| .. | .. |
|---|
| 457 | 439 | rockchip_pcie_write(rockchip, 0x0, PCIE_CORE_OB_REGION_DESC1); |
|---|
| 458 | 440 | } |
|---|
| 459 | 441 | EXPORT_SYMBOL_GPL(rockchip_pcie_cfg_configuration_accesses); |
|---|
| 442 | + |
|---|
| 443 | +MODULE_AUTHOR("Rockchip Inc"); |
|---|
| 444 | +MODULE_DESCRIPTION("Rockchip AXI PCIe driver"); |
|---|
| 445 | +MODULE_LICENSE("GPL v2"); |
|---|