Lines Matching +full:syscon +full:- +full:pcie +full:- +full:ctrl

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
10 #include <linux/clk-provider.h>
17 #include <linux/mfd/syscon.h>
25 #include "pcie-cadence.h"
27 #define cdns_pcie_to_rc(p) container_of(p, struct cdns_pcie_rc, pcie)
80 static inline u32 j721e_pcie_user_readl(struct j721e_pcie *pcie, u32 offset) in j721e_pcie_user_readl() argument
82 return readl(pcie->user_cfg_base + offset); in j721e_pcie_user_readl()
85 static inline void j721e_pcie_user_writel(struct j721e_pcie *pcie, u32 offset, in j721e_pcie_user_writel() argument
88 writel(value, pcie->user_cfg_base + offset); in j721e_pcie_user_writel()
91 static inline u32 j721e_pcie_intd_readl(struct j721e_pcie *pcie, u32 offset) in j721e_pcie_intd_readl() argument
93 return readl(pcie->intd_cfg_base + offset); in j721e_pcie_intd_readl()
96 static inline void j721e_pcie_intd_writel(struct j721e_pcie *pcie, u32 offset, in j721e_pcie_intd_writel() argument
99 writel(value, pcie->intd_cfg_base + offset); in j721e_pcie_intd_writel()
104 struct j721e_pcie *pcie = priv; in j721e_pcie_link_irq_handler() local
105 struct device *dev = pcie->cdns_pcie->dev; in j721e_pcie_link_irq_handler()
108 reg = j721e_pcie_intd_readl(pcie, STATUS_REG_SYS_2); in j721e_pcie_link_irq_handler()
109 if (!(reg & pcie->linkdown_irq_regfield)) in j721e_pcie_link_irq_handler()
114 j721e_pcie_intd_writel(pcie, STATUS_CLR_REG_SYS_2, pcie->linkdown_irq_regfield); in j721e_pcie_link_irq_handler()
118 static void j721e_pcie_config_link_irq(struct j721e_pcie *pcie) in j721e_pcie_config_link_irq() argument
122 reg = j721e_pcie_intd_readl(pcie, ENABLE_REG_SYS_2); in j721e_pcie_config_link_irq()
123 reg |= pcie->linkdown_irq_regfield; in j721e_pcie_config_link_irq()
124 j721e_pcie_intd_writel(pcie, ENABLE_REG_SYS_2, reg); in j721e_pcie_config_link_irq()
129 struct j721e_pcie *pcie = dev_get_drvdata(cdns_pcie->dev); in j721e_pcie_start_link() local
132 reg = j721e_pcie_user_readl(pcie, J721E_PCIE_USER_CMD_STATUS); in j721e_pcie_start_link()
134 j721e_pcie_user_writel(pcie, J721E_PCIE_USER_CMD_STATUS, reg); in j721e_pcie_start_link()
141 struct j721e_pcie *pcie = dev_get_drvdata(cdns_pcie->dev); in j721e_pcie_stop_link() local
144 reg = j721e_pcie_user_readl(pcie, J721E_PCIE_USER_CMD_STATUS); in j721e_pcie_stop_link()
146 j721e_pcie_user_writel(pcie, J721E_PCIE_USER_CMD_STATUS, reg); in j721e_pcie_stop_link()
151 struct j721e_pcie *pcie = dev_get_drvdata(cdns_pcie->dev); in j721e_pcie_link_up() local
154 reg = j721e_pcie_user_readl(pcie, J721E_PCIE_USER_LINKSTATUS); in j721e_pcie_link_up()
168 static int j721e_pcie_set_mode(struct j721e_pcie *pcie, struct regmap *syscon, in j721e_pcie_set_mode() argument
171 struct device *dev = pcie->cdns_pcie->dev; in j721e_pcie_set_mode()
173 u32 mode = pcie->mode; in j721e_pcie_set_mode()
180 ret = regmap_update_bits(syscon, offset, mask, val); in j721e_pcie_set_mode()
182 dev_err(dev, "failed to set pcie mode\n"); in j721e_pcie_set_mode()
187 static int j721e_pcie_set_link_speed(struct j721e_pcie *pcie, in j721e_pcie_set_link_speed() argument
188 struct regmap *syscon, unsigned int offset) in j721e_pcie_set_link_speed() argument
190 struct device *dev = pcie->cdns_pcie->dev; in j721e_pcie_set_link_speed()
191 struct device_node *np = dev->of_node; in j721e_pcie_set_link_speed()
200 val = link_speed - 1; in j721e_pcie_set_link_speed()
201 ret = regmap_update_bits(syscon, offset, GENERATION_SEL_MASK, val); in j721e_pcie_set_link_speed()
208 static int j721e_pcie_set_lane_count(struct j721e_pcie *pcie, in j721e_pcie_set_lane_count() argument
209 struct regmap *syscon, unsigned int offset) in j721e_pcie_set_lane_count() argument
211 struct device *dev = pcie->cdns_pcie->dev; in j721e_pcie_set_lane_count()
212 u32 lanes = pcie->num_lanes; in j721e_pcie_set_lane_count()
217 if (pcie->max_lanes == 4) in j721e_pcie_set_lane_count()
220 val = LANE_COUNT(lanes - 1); in j721e_pcie_set_lane_count()
221 ret = regmap_update_bits(syscon, offset, mask, val); in j721e_pcie_set_lane_count()
228 static int j721e_pcie_ctrl_init(struct j721e_pcie *pcie) in j721e_pcie_ctrl_init() argument
230 struct device *dev = pcie->cdns_pcie->dev; in j721e_pcie_ctrl_init()
231 struct device_node *node = dev->of_node; in j721e_pcie_ctrl_init()
234 struct regmap *syscon; in j721e_pcie_ctrl_init() local
237 syscon = syscon_regmap_lookup_by_phandle(node, "ti,syscon-pcie-ctrl"); in j721e_pcie_ctrl_init()
238 if (IS_ERR(syscon)) { in j721e_pcie_ctrl_init()
239 dev_err(dev, "Unable to get ti,syscon-pcie-ctrl regmap\n"); in j721e_pcie_ctrl_init()
240 return PTR_ERR(syscon); in j721e_pcie_ctrl_init()
244 ret = of_parse_phandle_with_fixed_args(node, "ti,syscon-pcie-ctrl", 1, in j721e_pcie_ctrl_init()
249 ret = j721e_pcie_set_mode(pcie, syscon, offset); in j721e_pcie_ctrl_init()
255 ret = j721e_pcie_set_link_speed(pcie, syscon, offset); in j721e_pcie_ctrl_init()
261 ret = j721e_pcie_set_lane_count(pcie, syscon, offset); in j721e_pcie_ctrl_init()
263 dev_err(dev, "Failed to set num-lanes\n"); in j721e_pcie_ctrl_init()
340 .compatible = "ti,j721e-pcie-host",
344 .compatible = "ti,j721e-pcie-ep",
348 .compatible = "ti,j7200-pcie-host",
352 .compatible = "ti,j7200-pcie-ep",
356 .compatible = "ti,am64-pcie-host",
360 .compatible = "ti,am64-pcie-ep",
368 struct device *dev = &pdev->dev; in j721e_pcie_probe()
369 struct device_node *node = dev->of_node; in j721e_pcie_probe()
373 struct j721e_pcie *pcie; in j721e_pcie_probe() local
386 return -EINVAL; in j721e_pcie_probe()
388 mode = (u32)data->mode; in j721e_pcie_probe()
390 pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); in j721e_pcie_probe()
391 if (!pcie) in j721e_pcie_probe()
392 return -ENOMEM; in j721e_pcie_probe()
397 return -ENODEV; in j721e_pcie_probe()
401 return -ENOMEM; in j721e_pcie_probe()
403 if (!data->byte_access_allowed) in j721e_pcie_probe()
404 bridge->ops = &cdns_ti_pcie_host_ops; in j721e_pcie_probe()
406 rc->quirk_retrain_flag = data->quirk_retrain_flag; in j721e_pcie_probe()
407 rc->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag; in j721e_pcie_probe()
409 cdns_pcie = &rc->pcie; in j721e_pcie_probe()
410 cdns_pcie->dev = dev; in j721e_pcie_probe()
411 cdns_pcie->ops = &j721e_pcie_ops; in j721e_pcie_probe()
412 pcie->cdns_pcie = cdns_pcie; in j721e_pcie_probe()
416 return -ENODEV; in j721e_pcie_probe()
420 return -ENOMEM; in j721e_pcie_probe()
422 ep->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag; in j721e_pcie_probe()
423 ep->quirk_disable_flr = data->quirk_disable_flr; in j721e_pcie_probe()
425 cdns_pcie = &ep->pcie; in j721e_pcie_probe()
426 cdns_pcie->dev = dev; in j721e_pcie_probe()
427 cdns_pcie->ops = &j721e_pcie_ops; in j721e_pcie_probe()
428 pcie->cdns_pcie = cdns_pcie; in j721e_pcie_probe()
435 pcie->mode = mode; in j721e_pcie_probe()
436 pcie->linkdown_irq_regfield = data->linkdown_irq_regfield; in j721e_pcie_probe()
441 pcie->intd_cfg_base = base; in j721e_pcie_probe()
446 pcie->user_cfg_base = base; in j721e_pcie_probe()
448 ret = of_property_read_u32(node, "num-lanes", &num_lanes); in j721e_pcie_probe()
449 if (ret || num_lanes > data->max_lanes) { in j721e_pcie_probe()
450 dev_warn(dev, "num-lanes property not provided or invalid, setting num-lanes to 1\n"); in j721e_pcie_probe()
454 pcie->num_lanes = num_lanes; in j721e_pcie_probe()
455 pcie->max_lanes = data->max_lanes; in j721e_pcie_probe()
458 return -EINVAL; in j721e_pcie_probe()
464 dev_set_drvdata(dev, pcie); in j721e_pcie_probe()
472 ret = j721e_pcie_ctrl_init(pcie); in j721e_pcie_probe()
479 "j721e-pcie-link-down-irq", pcie); in j721e_pcie_probe()
485 j721e_pcie_config_link_irq(pcie); in j721e_pcie_probe()
492 if (ret != -EPROBE_DEFER) in j721e_pcie_probe()
496 pcie->reset_gpio = gpiod; in j721e_pcie_probe()
516 pcie->refclk = clk; in j721e_pcie_probe()
532 clk_disable_unprepare(pcie->refclk); in j721e_pcie_probe()
565 struct j721e_pcie *pcie = platform_get_drvdata(pdev); in j721e_pcie_remove() local
566 struct cdns_pcie *cdns_pcie = pcie->cdns_pcie; in j721e_pcie_remove()
567 struct device *dev = &pdev->dev; in j721e_pcie_remove()
569 clk_disable_unprepare(pcie->refclk); in j721e_pcie_remove()
577 struct j721e_pcie *pcie = dev_get_drvdata(dev); in j721e_pcie_suspend_noirq() local
579 if (pcie->mode == PCI_MODE_RC) { in j721e_pcie_suspend_noirq()
580 gpiod_set_value_cansleep(pcie->reset_gpio, 0); in j721e_pcie_suspend_noirq()
581 clk_disable_unprepare(pcie->refclk); in j721e_pcie_suspend_noirq()
584 cdns_pcie_disable_phy(pcie->cdns_pcie); in j721e_pcie_suspend_noirq()
591 struct j721e_pcie *pcie = dev_get_drvdata(dev); in j721e_pcie_resume_noirq() local
592 struct cdns_pcie *cdns_pcie = pcie->cdns_pcie; in j721e_pcie_resume_noirq()
595 ret = j721e_pcie_ctrl_init(pcie); in j721e_pcie_resume_noirq()
599 j721e_pcie_config_link_irq(pcie); in j721e_pcie_resume_noirq()
605 ret = cdns_pcie_enable_phy(pcie->cdns_pcie); in j721e_pcie_resume_noirq()
609 if (pcie->mode == PCI_MODE_RC) { in j721e_pcie_resume_noirq()
612 ret = clk_prepare_enable(pcie->refclk); in j721e_pcie_resume_noirq()
623 if (pcie->reset_gpio) { in j721e_pcie_resume_noirq()
625 gpiod_set_value_cansleep(pcie->reset_gpio, 1); in j721e_pcie_resume_noirq()
630 clk_disable_unprepare(pcie->refclk); in j721e_pcie_resume_noirq()
639 rc->avail_ib_bar[bar] = true; in j721e_pcie_resume_noirq()
643 clk_disable_unprepare(pcie->refclk); in j721e_pcie_resume_noirq()
659 .name = "j721e-pcie",