Skip to content

Commit 8a182c2

Browse files
Russell Kingbjorn-helgaas
authored andcommitted
PCI: mvebu: Use gpio_desc to carry around gpio
Use a gpio_desc to carry around the gpio, so we can then make use of the GPIOF_ACTIVE_LOW property rather than carrying that around as well. This also avoids needing to use gpio_is_valid() to check whether we have a GPIO; checking for a non-NULL descriptor is simpler. Tested-by: Willy Tarreau <[email protected]> (Iomega iConnect Kirkwood, MiraBox Armada 370) Tested-by: Andrew Lunn <[email protected]> (D-Link DIR664 Kirkwood) Tested-by: Thomas Petazzoni <[email protected]> (Armada XP GP) Signed-off-by: Russell King <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Thomas Petazzoni <[email protected]>
1 parent 19fdb80 commit 8a182c2

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

drivers/pci/host/pci-mvebu.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ struct mvebu_pcie_port {
119119
unsigned int io_target;
120120
unsigned int io_attr;
121121
struct clk *clk;
122-
int reset_gpio;
123-
int reset_active_low;
122+
struct gpio_desc *reset_gpio;
124123
char *reset_name;
125124
struct mvebu_sw_pci_bridge bridge;
126125
struct device_node *dn;
@@ -940,7 +939,7 @@ static int mvebu_pcie_parse_port(struct mvebu_pcie *pcie,
940939
{
941940
struct device *dev = &pcie->pdev->dev;
942941
enum of_gpio_flags flags;
943-
int ret;
942+
int reset_gpio, ret;
944943

945944
port->pcie = pcie;
946945

@@ -980,29 +979,40 @@ static int mvebu_pcie_parse_port(struct mvebu_pcie *pcie,
980979
port->io_attr = -1;
981980
}
982981

983-
port->reset_gpio = of_get_named_gpio_flags(child, "reset-gpios", 0,
984-
&flags);
985-
if (port->reset_gpio == -EPROBE_DEFER) {
986-
ret = port->reset_gpio;
982+
reset_gpio = of_get_named_gpio_flags(child, "reset-gpios", 0, &flags);
983+
if (reset_gpio == -EPROBE_DEFER) {
984+
ret = reset_gpio;
987985
goto err;
988986
}
989987

990-
if (gpio_is_valid(port->reset_gpio)) {
991-
port->reset_active_low = flags & OF_GPIO_ACTIVE_LOW;
988+
if (gpio_is_valid(reset_gpio)) {
989+
unsigned long gpio_flags;
990+
992991
port->reset_name = devm_kasprintf(dev, GFP_KERNEL, "%s-reset",
993992
port->name);
994993
if (!port->reset_name) {
995994
ret = -ENOMEM;
996995
goto err;
997996
}
998997

999-
ret = devm_gpio_request_one(dev, port->reset_gpio,
1000-
GPIOF_DIR_OUT, port->reset_name);
998+
if (flags & OF_GPIO_ACTIVE_LOW) {
999+
dev_info(dev, "%s: reset gpio is active low\n",
1000+
of_node_full_name(child));
1001+
gpio_flags = GPIOF_ACTIVE_LOW |
1002+
GPIOF_OUT_INIT_LOW;
1003+
} else {
1004+
gpio_flags = GPIOF_OUT_INIT_HIGH;
1005+
}
1006+
1007+
ret = devm_gpio_request_one(dev, reset_gpio, gpio_flags,
1008+
port->reset_name);
10011009
if (ret) {
10021010
if (ret == -EPROBE_DEFER)
10031011
goto err;
10041012
goto skip;
10051013
}
1014+
1015+
port->reset_gpio = gpio_to_desc(reset_gpio);
10061016
}
10071017

10081018
port->clk = of_clk_get_by_name(child, NULL);
@@ -1104,15 +1114,14 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
11041114
if (!child)
11051115
continue;
11061116

1107-
if (gpio_is_valid(port->reset_gpio)) {
1117+
if (port->reset_gpio) {
11081118
u32 reset_udelay = 20000;
11091119

11101120
of_property_read_u32(child, "reset-delay-us",
11111121
&reset_udelay);
11121122

1113-
gpio_set_value_cansleep(port->reset_gpio,
1114-
!!port->reset_active_low);
1115-
msleep(reset_udelay/1000);
1123+
gpiod_set_value_cansleep(port->reset_gpio, 0);
1124+
msleep(reset_udelay / 1000);
11161125
}
11171126

11181127
ret = clk_prepare_enable(port->clk);

0 commit comments

Comments
 (0)