Lines Matching +full:rk3568 +full:- +full:pcie
1 // SPDX-License-Identifier: GPL-2.0
3 * PCIe host controller driver for Rockchip SoCs.
6 * http://www.rock-chips.com
8 * Author: Simon Xue <xxm@rock-chips.com>
24 #include "pcie-designware.h"
34 #define to_rockchip_pcie(x) dev_get_drvdata((x)->dev)
77 return readl_relaxed(rockchip->apb_base + reg); in rockchip_pcie_readl_apb()
83 writel_relaxed(val, rockchip->apb_base + reg); in rockchip_pcie_writel_apb()
97 generic_handle_domain_irq(rockchip->irq_domain, hwirq); in rockchip_pcie_intx_handler()
105 HIWORD_UPDATE_BIT(BIT(data->hwirq)), in rockchip_intx_mask()
112 HIWORD_DISABLE_BIT(BIT(data->hwirq)), in rockchip_intx_unmask()
127 irq_set_chip_data(irq, domain->host_data); in rockchip_pcie_intx_map()
138 struct device *dev = rockchip->pci.dev; in rockchip_pcie_init_irq_domain()
141 intc = of_get_child_by_name(dev->of_node, "legacy-interrupt-controller"); in rockchip_pcie_init_irq_domain()
143 dev_err(dev, "missing child interrupt-controller node\n"); in rockchip_pcie_init_irq_domain()
144 return -EINVAL; in rockchip_pcie_init_irq_domain()
147 rockchip->irq_domain = irq_domain_add_linear(intc, PCI_NUM_INTX, in rockchip_pcie_init_irq_domain()
150 if (!rockchip->irq_domain) { in rockchip_pcie_init_irq_domain()
152 return -EINVAL; in rockchip_pcie_init_irq_domain()
192 gpiod_set_value_cansleep(rockchip->rst_gpio, 0); in rockchip_pcie_start_link()
197 * PCIe requires the refclk to be stable for 100µs prior to releasing in rockchip_pcie_start_link()
198 * PERST. See table 2-4 in section 2.6.2 AC Specifications of the PCI in rockchip_pcie_start_link()
206 gpiod_set_value_cansleep(rockchip->rst_gpio, 1); in rockchip_pcie_start_link()
222 struct device *dev = rockchip->pci.dev; in rockchip_pcie_host_init()
225 irq = of_irq_get_byname(dev->of_node, "legacy"); in rockchip_pcie_host_init()
265 dev_err(pci->dev, "UNKNOWN IRQ type\n"); in rockchip_pcie_raise_irq()
310 return rockchip->data->epc_features; in rockchip_pcie_get_features()
321 struct device *dev = rockchip->pci.dev; in rockchip_pcie_clk_init()
324 ret = devm_clk_bulk_get_all(dev, &rockchip->clks); in rockchip_pcie_clk_init()
328 rockchip->clk_cnt = ret; in rockchip_pcie_clk_init()
330 ret = clk_bulk_prepare_enable(rockchip->clk_cnt, rockchip->clks); in rockchip_pcie_clk_init()
340 rockchip->apb_base = devm_platform_ioremap_resource_byname(pdev, "apb"); in rockchip_pcie_resource_get()
341 if (IS_ERR(rockchip->apb_base)) in rockchip_pcie_resource_get()
342 return dev_err_probe(&pdev->dev, PTR_ERR(rockchip->apb_base), in rockchip_pcie_resource_get()
345 rockchip->rst_gpio = devm_gpiod_get_optional(&pdev->dev, "reset", in rockchip_pcie_resource_get()
347 if (IS_ERR(rockchip->rst_gpio)) in rockchip_pcie_resource_get()
348 return dev_err_probe(&pdev->dev, PTR_ERR(rockchip->rst_gpio), in rockchip_pcie_resource_get()
351 rockchip->rst = devm_reset_control_array_get_exclusive(&pdev->dev); in rockchip_pcie_resource_get()
352 if (IS_ERR(rockchip->rst)) in rockchip_pcie_resource_get()
353 return dev_err_probe(&pdev->dev, PTR_ERR(rockchip->rst), in rockchip_pcie_resource_get()
361 struct device *dev = rockchip->pci.dev; in rockchip_pcie_phy_init()
364 rockchip->phy = devm_phy_get(dev, "pcie-phy"); in rockchip_pcie_phy_init()
365 if (IS_ERR(rockchip->phy)) in rockchip_pcie_phy_init()
366 return dev_err_probe(dev, PTR_ERR(rockchip->phy), in rockchip_pcie_phy_init()
369 ret = phy_init(rockchip->phy); in rockchip_pcie_phy_init()
373 ret = phy_power_on(rockchip->phy); in rockchip_pcie_phy_init()
375 phy_exit(rockchip->phy); in rockchip_pcie_phy_init()
382 phy_exit(rockchip->phy); in rockchip_pcie_phy_deinit()
383 phy_power_off(rockchip->phy); in rockchip_pcie_phy_deinit()
395 struct dw_pcie *pci = &rockchip->pci; in rockchip_pcie_ep_sys_irq_thread()
396 struct device *dev = pci->dev; in rockchip_pcie_ep_sys_irq_thread()
406 dev_dbg(dev, "hot reset or link-down reset\n"); in rockchip_pcie_ep_sys_irq_thread()
407 dw_pcie_ep_linkdown(&pci->ep); in rockchip_pcie_ep_sys_irq_thread()
414 dw_pcie_ep_linkup(&pci->ep); in rockchip_pcie_ep_sys_irq_thread()
427 return -ENODEV; in rockchip_pcie_configure_rc()
436 pp = &rockchip->pci.pp; in rockchip_pcie_configure_rc()
437 pp->ops = &rockchip_pcie_host_ops; in rockchip_pcie_configure_rc()
445 struct device *dev = &pdev->dev; in rockchip_pcie_configure_ep()
450 return -ENODEV; in rockchip_pcie_configure_ep()
460 IRQF_ONESHOT, "pcie-sys", rockchip); in rockchip_pcie_configure_ep()
462 dev_err(dev, "failed to request PCIe sys IRQ\n"); in rockchip_pcie_configure_ep()
473 rockchip->pci.ep.ops = &rockchip_pcie_ep_ops; in rockchip_pcie_configure_ep()
474 rockchip->pci.ep.page_size = SZ_64K; in rockchip_pcie_configure_ep()
478 ret = dw_pcie_ep_init(&rockchip->pci.ep); in rockchip_pcie_configure_ep()
484 ret = dw_pcie_ep_init_registers(&rockchip->pci.ep); in rockchip_pcie_configure_ep()
487 dw_pcie_ep_deinit(&rockchip->pci.ep); in rockchip_pcie_configure_ep()
491 pci_epc_init_notify(rockchip->pci.ep.epc); in rockchip_pcie_configure_ep()
493 /* unmask DLL up/down indicator and hot reset/link-down reset */ in rockchip_pcie_configure_ep()
501 struct device *dev = &pdev->dev; in rockchip_pcie_probe()
508 return -EINVAL; in rockchip_pcie_probe()
512 return -ENOMEM; in rockchip_pcie_probe()
516 rockchip->pci.dev = dev; in rockchip_pcie_probe()
517 rockchip->pci.ops = &dw_pcie_ops; in rockchip_pcie_probe()
518 rockchip->data = data; in rockchip_pcie_probe()
524 ret = reset_control_assert(rockchip->rst); in rockchip_pcie_probe()
529 rockchip->vpcie3v3 = devm_regulator_get_optional(dev, "vpcie3v3"); in rockchip_pcie_probe()
530 if (IS_ERR(rockchip->vpcie3v3)) { in rockchip_pcie_probe()
531 if (PTR_ERR(rockchip->vpcie3v3) != -ENODEV) in rockchip_pcie_probe()
532 return dev_err_probe(dev, PTR_ERR(rockchip->vpcie3v3), in rockchip_pcie_probe()
534 rockchip->vpcie3v3 = NULL; in rockchip_pcie_probe()
536 ret = regulator_enable(rockchip->vpcie3v3); in rockchip_pcie_probe()
546 ret = reset_control_deassert(rockchip->rst); in rockchip_pcie_probe()
554 switch (data->mode) { in rockchip_pcie_probe()
566 dev_err(dev, "INVALID device type %d\n", data->mode); in rockchip_pcie_probe()
567 ret = -EINVAL; in rockchip_pcie_probe()
574 clk_bulk_disable_unprepare(rockchip->clk_cnt, rockchip->clks); in rockchip_pcie_probe()
578 if (rockchip->vpcie3v3) in rockchip_pcie_probe()
579 regulator_disable(rockchip->vpcie3v3); in rockchip_pcie_probe()
600 .compatible = "rockchip,rk3568-pcie",
604 .compatible = "rockchip,rk3568-pcie-ep",
608 .compatible = "rockchip,rk3588-pcie-ep",
616 .name = "rockchip-dw-pcie",