Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Documentation/devicetree/bindings/pci/toshiba,tc9563.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ $defs:
type: object

properties:
reset-gpios:
maxItems: 1
description:
TC9563 GPIO, provided by the embedded GPIO controller, that
resets the endpoint connected to the downstream port. The PCIe
host controller drives it together with its own PERST# when it
keeps the switch powered across system suspend.

toshiba,tx-amplitude-microvolt:
description:
Change Tx Margin setting for low power consumption.
Expand Down Expand Up @@ -140,6 +148,8 @@ examples:
device_type = "pci";
#address-cells = <3>;
#size-cells = <2>;
gpio-controller;
#gpio-cells = <2>;
ranges;
bus-range = <0x02 0xff>;

Expand All @@ -154,9 +164,6 @@ examples:

resx-gpios = <&gpio 1 GPIO_ACTIVE_LOW>;

gpio-controller;
#gpio-cells = <2>;

pcie@1,0 {
compatible = "pciclass,0604";
reg = <0x20800 0x0 0x0 0x0 0x0>;
Expand Down
47 changes: 24 additions & 23 deletions drivers/pci/controller/dwc/pcie-qcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1493,16 +1493,10 @@ static int qcom_pcie_host_init(struct dw_pcie_rp *pp)
if (ret)
goto err_deinit;

if (!pci->suspended) {
ret = pci_pwrctrl_create_devices(pci->dev);
if (ret)
goto err_disable_phy;
}

if (!pp->skip_pwrctrl_off) {
ret = pci_pwrctrl_power_on_devices(pci->dev);
if (ret)
goto err_pwrctrl_destroy;
goto err_disable_phy;
}

if (pcie->cfg->ops->post_init) {
Expand Down Expand Up @@ -1534,9 +1528,6 @@ static int qcom_pcie_host_init(struct dw_pcie_rp *pp)
err_pwrctrl_power_off:
if (!pp->skip_pwrctrl_off)
pci_pwrctrl_power_off_devices(pci->dev);
err_pwrctrl_destroy:
if (ret != -EPROBE_DEFER && !pci->suspended)
pci_pwrctrl_destroy_devices(pci->dev);
err_disable_phy:
qcom_pcie_phy_power_off(pcie);
err_deinit:
Expand Down Expand Up @@ -2069,6 +2060,7 @@ static int qcom_pcie_parse_perst(struct qcom_pcie *pcie,
struct qcom_pcie_perst *perst;
struct device_node *gpio_np;
struct gpio_desc *reset;
enum gpiod_flags flags;
int ret;

if (pcie->reset) {
Expand All @@ -2082,26 +2074,22 @@ static int qcom_pcie_parse_perst(struct qcom_pcie *pcie,
goto parse_child_node;

/*
* Skip GPIOs provided by a PCIe device which is a child of the Root
* Complex (e.g., a PCIe switch with GPIO controller capability). Such
* controllers won't be available at RC probe time and their PERST#
* should be controlled by the respective PCI client driver
* implementation.
* GPIOs provided by a PCIe device which is a child of the Root Complex
* (e.g., a PCIe switch with GPIO controller capability) can't be
* accessed at RC probe time, as the device is not powered on yet. Don't
* change their state here.
*/
gpio_np = of_parse_phandle(np, "reset-gpios", 0);
if (!gpio_np) {
dev_err(dev, "Failed to parse GPIO provider\n");
return -EINVAL;
}

if (qcom_pcie_is_child_node(dev, gpio_np)) {
of_node_put(gpio_np);
goto parse_child_node;
}
flags = qcom_pcie_is_child_node(dev, gpio_np) ? GPIOD_ASIS : GPIOD_OUT_HIGH;
of_node_put(gpio_np);

reset = devm_fwnode_gpiod_get(dev, of_fwnode_handle(np), "reset",
GPIOD_OUT_HIGH, "PERST#");
flags, "PERST#");
if (IS_ERR(reset)) {
/*
* FIXME: GPIOLIB currently supports exclusive GPIO access only.
Expand Down Expand Up @@ -2159,8 +2147,10 @@ static int qcom_pcie_parse_port(struct qcom_pcie *pcie, struct device_node *node
INIT_LIST_HEAD(&port->perst);

ret = qcom_pcie_parse_perst(pcie, port, node);
if (ret)
if (ret) {
phy_exit(phy);
return ret;
}

/* TODO: Move to DWC core after multi Root Port support is added */
of_property_read_u32(node, "t-power-on-us", &port->l1ss_t_power_on);
Expand Down Expand Up @@ -2376,12 +2366,20 @@ static int qcom_pcie_probe(struct platform_device *pdev)

pp->ops = &qcom_pcie_dw_ops;

/*
* Create the pwrctrl devices before parsing the ports, as the PERST#
* GPIOs of downstream devices can be provided by them.
*/
ret = pci_pwrctrl_create_devices(dev);
if (ret)
goto err_pm_runtime_put;

ret = qcom_pcie_parse_ports(pcie);
if (ret) {
if (ret != -ENODEV) {
dev_err_probe(pci->dev, ret,
"Failed to parse Root Port: %d\n", ret);
goto err_pm_runtime_put;
goto err_pwrctrl_destroy;
}

/*
Expand All @@ -2391,7 +2389,7 @@ static int qcom_pcie_probe(struct platform_device *pdev)
*/
ret = qcom_pcie_parse_legacy_binding(pcie);
if (ret)
goto err_pm_runtime_put;
goto err_pwrctrl_destroy;
}

platform_set_drvdata(pdev, pcie);
Expand Down Expand Up @@ -2444,6 +2442,9 @@ static int qcom_pcie_probe(struct platform_device *pdev)
phy_exit(port->phy);
list_del(&port->list);
}
err_pwrctrl_destroy:
if (ret != -EPROBE_DEFER)
pci_pwrctrl_destroy_devices(dev);
err_pm_runtime_put:
pm_runtime_put(dev);
pm_runtime_disable(dev);
Expand Down
38 changes: 36 additions & 2 deletions drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio/driver.h>
#include <linux/i2c.h>
#include <linux/idr.h>
#include <linux/module.h>
Expand Down Expand Up @@ -520,6 +521,35 @@ static int tc9563_pwrctrl_add_gpio_adev(struct tc9563_pwrctrl *tc9563)
tc9563->regmap);
}

/*
* The PCIe host controller driver may request the endpoint reset GPIOs before
* the switch is powered. gpiolib cannot read their direction then, and refuses
* to drive a line it does not know to be an output. Now that the switch is
* accessible and the lines are outputs, make gpiolib read the direction again.
*
* Only DSP1 and DSP2 connect to external devices and expose a reset line on
* the embedded GPIO controller, at the same fixed offsets (port index + 1)
* used by the legacy regmap-based reset in tc9563_pwrctrl_assert_deassert_reset().
*/
static void tc9563_pwrctrl_sync_gpio_direction(struct tc9563_pwrctrl *tc9563)
{
struct gpio_device *gdev;
struct gpio_desc *desc;
int i;

gdev = gpio_device_find_by_fwnode(dev_fwnode(tc9563->pwrctrl.dev));
if (!gdev)
return;

for (i = TC9563_DSP1; i <= TC9563_DSP2; i++) {
desc = gpio_device_get_desc(gdev, i + 1);
if (!IS_ERR(desc))
gpiod_get_direction(desc);
}

gpio_device_put(gdev);
}

static int tc9563_pwrctrl_power_off(struct pci_pwrctrl *pwrctrl)
{
struct tc9563_pwrctrl *tc9563 = container_of(pwrctrl,
Expand Down Expand Up @@ -612,8 +642,12 @@ static int tc9563_pwrctrl_power_on(struct pci_pwrctrl *pwrctrl)
}

ret = tc9563_pwrctrl_assert_deassert_reset(tc9563, true);
if (!ret)
return 0;
if (ret)
goto power_off;

tc9563_pwrctrl_sync_gpio_direction(tc9563);

return 0;

power_off:
tc9563_pwrctrl_power_off(&tc9563->pwrctrl);
Expand Down
Loading