Lines Matching +full:pcie +full:- +full:ep
1 // SPDX-License-Identifier: GPL-2.0
3 * pci-j721e - PCIe controller driver for TI's J721E SoCs
5 * Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com
22 #include "pcie-cadence.h"
74 static inline u32 j721e_pcie_user_readl(struct j721e_pcie *pcie, u32 offset) in j721e_pcie_user_readl() argument
76 return readl(pcie->user_cfg_base + offset); in j721e_pcie_user_readl()
79 static inline void j721e_pcie_user_writel(struct j721e_pcie *pcie, u32 offset, in j721e_pcie_user_writel() argument
82 writel(value, pcie->user_cfg_base + offset); in j721e_pcie_user_writel()
85 static inline u32 j721e_pcie_intd_readl(struct j721e_pcie *pcie, u32 offset) in j721e_pcie_intd_readl() argument
87 return readl(pcie->intd_cfg_base + offset); in j721e_pcie_intd_readl()
90 static inline void j721e_pcie_intd_writel(struct j721e_pcie *pcie, u32 offset, in j721e_pcie_intd_writel() argument
93 writel(value, pcie->intd_cfg_base + offset); in j721e_pcie_intd_writel()
98 struct j721e_pcie *pcie = priv; in j721e_pcie_link_irq_handler() local
99 struct device *dev = pcie->dev; in j721e_pcie_link_irq_handler()
102 reg = j721e_pcie_intd_readl(pcie, STATUS_REG_SYS_2); in j721e_pcie_link_irq_handler()
103 if (!(reg & pcie->linkdown_irq_regfield)) in j721e_pcie_link_irq_handler()
108 j721e_pcie_intd_writel(pcie, STATUS_CLR_REG_SYS_2, pcie->linkdown_irq_regfield); in j721e_pcie_link_irq_handler()
112 static void j721e_pcie_config_link_irq(struct j721e_pcie *pcie) in j721e_pcie_config_link_irq() argument
116 reg = j721e_pcie_intd_readl(pcie, ENABLE_REG_SYS_2); in j721e_pcie_config_link_irq()
117 reg |= pcie->linkdown_irq_regfield; in j721e_pcie_config_link_irq()
118 j721e_pcie_intd_writel(pcie, ENABLE_REG_SYS_2, reg); in j721e_pcie_config_link_irq()
123 struct j721e_pcie *pcie = dev_get_drvdata(cdns_pcie->dev); in j721e_pcie_start_link() local
126 reg = j721e_pcie_user_readl(pcie, J721E_PCIE_USER_CMD_STATUS); in j721e_pcie_start_link()
128 j721e_pcie_user_writel(pcie, J721E_PCIE_USER_CMD_STATUS, reg); in j721e_pcie_start_link()
135 struct j721e_pcie *pcie = dev_get_drvdata(cdns_pcie->dev); in j721e_pcie_stop_link() local
138 reg = j721e_pcie_user_readl(pcie, J721E_PCIE_USER_CMD_STATUS); in j721e_pcie_stop_link()
140 j721e_pcie_user_writel(pcie, J721E_PCIE_USER_CMD_STATUS, reg); in j721e_pcie_stop_link()
145 struct j721e_pcie *pcie = dev_get_drvdata(cdns_pcie->dev); in j721e_pcie_link_up() local
148 reg = j721e_pcie_user_readl(pcie, J721E_PCIE_USER_LINKSTATUS); in j721e_pcie_link_up()
162 static int j721e_pcie_set_mode(struct j721e_pcie *pcie, struct regmap *syscon) in j721e_pcie_set_mode() argument
164 struct device *dev = pcie->dev; in j721e_pcie_set_mode()
166 u32 mode = pcie->mode; in j721e_pcie_set_mode()
175 dev_err(dev, "failed to set pcie mode\n"); in j721e_pcie_set_mode()
180 static int j721e_pcie_set_link_speed(struct j721e_pcie *pcie, in j721e_pcie_set_link_speed() argument
183 struct device *dev = pcie->dev; in j721e_pcie_set_link_speed()
184 struct device_node *np = dev->of_node; in j721e_pcie_set_link_speed()
193 val = link_speed - 1; in j721e_pcie_set_link_speed()
201 static int j721e_pcie_set_lane_count(struct j721e_pcie *pcie, in j721e_pcie_set_lane_count() argument
204 struct device *dev = pcie->dev; in j721e_pcie_set_lane_count()
205 u32 lanes = pcie->num_lanes; in j721e_pcie_set_lane_count()
209 val = LANE_COUNT(lanes - 1); in j721e_pcie_set_lane_count()
217 static int j721e_pcie_ctrl_init(struct j721e_pcie *pcie) in j721e_pcie_ctrl_init() argument
219 struct device *dev = pcie->dev; in j721e_pcie_ctrl_init()
220 struct device_node *node = dev->of_node; in j721e_pcie_ctrl_init()
224 syscon = syscon_regmap_lookup_by_phandle(node, "ti,syscon-pcie-ctrl"); in j721e_pcie_ctrl_init()
226 dev_err(dev, "Unable to get ti,syscon-pcie-ctrl regmap\n"); in j721e_pcie_ctrl_init()
230 ret = j721e_pcie_set_mode(pcie, syscon); in j721e_pcie_ctrl_init()
236 ret = j721e_pcie_set_link_speed(pcie, syscon); in j721e_pcie_ctrl_init()
242 ret = j721e_pcie_set_lane_count(pcie, syscon); in j721e_pcie_ctrl_init()
244 dev_err(dev, "Failed to set num-lanes\n"); in j721e_pcie_ctrl_init()
314 .compatible = "ti,j721e-pcie-host",
318 .compatible = "ti,j721e-pcie-ep",
322 .compatible = "ti,j7200-pcie-host",
326 .compatible = "ti,j7200-pcie-ep",
330 .compatible = "ti,am64-pcie-host",
334 .compatible = "ti,am64-pcie-ep",
342 struct device *dev = &pdev->dev; in j721e_pcie_probe()
343 struct device_node *node = dev->of_node; in j721e_pcie_probe()
347 struct j721e_pcie *pcie; in j721e_pcie_probe() local
349 struct cdns_pcie_ep *ep; in j721e_pcie_probe() local
359 return -EINVAL; in j721e_pcie_probe()
361 mode = (u32)data->mode; in j721e_pcie_probe()
363 pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); in j721e_pcie_probe()
364 if (!pcie) in j721e_pcie_probe()
365 return -ENOMEM; in j721e_pcie_probe()
367 pcie->dev = dev; in j721e_pcie_probe()
368 pcie->mode = mode; in j721e_pcie_probe()
369 pcie->linkdown_irq_regfield = data->linkdown_irq_regfield; in j721e_pcie_probe()
374 pcie->intd_cfg_base = base; in j721e_pcie_probe()
379 pcie->user_cfg_base = base; in j721e_pcie_probe()
381 ret = of_property_read_u32(node, "num-lanes", &num_lanes); in j721e_pcie_probe()
384 pcie->num_lanes = num_lanes; in j721e_pcie_probe()
387 return -EINVAL; in j721e_pcie_probe()
393 dev_set_drvdata(dev, pcie); in j721e_pcie_probe()
401 ret = j721e_pcie_ctrl_init(pcie); in j721e_pcie_probe()
408 "j721e-pcie-link-down-irq", pcie); in j721e_pcie_probe()
414 j721e_pcie_config_link_irq(pcie); in j721e_pcie_probe()
419 ret = -ENODEV; in j721e_pcie_probe()
425 ret = -ENOMEM; in j721e_pcie_probe()
429 if (!data->byte_access_allowed) in j721e_pcie_probe()
430 bridge->ops = &cdns_ti_pcie_host_ops; in j721e_pcie_probe()
432 rc->quirk_retrain_flag = data->quirk_retrain_flag; in j721e_pcie_probe()
433 rc->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag; in j721e_pcie_probe()
435 cdns_pcie = &rc->pcie; in j721e_pcie_probe()
436 cdns_pcie->dev = dev; in j721e_pcie_probe()
437 cdns_pcie->ops = &j721e_pcie_ops; in j721e_pcie_probe()
438 pcie->cdns_pcie = cdns_pcie; in j721e_pcie_probe()
443 if (ret != -EPROBE_DEFER) in j721e_pcie_probe()
474 ret = -ENODEV; in j721e_pcie_probe()
478 ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL); in j721e_pcie_probe()
479 if (!ep) { in j721e_pcie_probe()
480 ret = -ENOMEM; in j721e_pcie_probe()
483 ep->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag; in j721e_pcie_probe()
485 cdns_pcie = &ep->pcie; in j721e_pcie_probe()
486 cdns_pcie->dev = dev; in j721e_pcie_probe()
487 cdns_pcie->ops = &j721e_pcie_ops; in j721e_pcie_probe()
488 pcie->cdns_pcie = cdns_pcie; in j721e_pcie_probe()
496 ret = cdns_pcie_ep_setup(ep); in j721e_pcie_probe()
519 struct j721e_pcie *pcie = platform_get_drvdata(pdev); in j721e_pcie_remove() local
520 struct cdns_pcie *cdns_pcie = pcie->cdns_pcie; in j721e_pcie_remove()
521 struct device *dev = &pdev->dev; in j721e_pcie_remove()
534 .name = "j721e-pcie",