Lines Matching +full:mt7621 +full:- +full:gpio
1 // SPDX-License-Identifier: GPL-2.0+
21 #include <linux/gpio/consumer.h>
35 /* MediaTek-specific configuration registers */
40 /* Host-PCI bridge registers */
67 * struct mt7621_pcie_port - PCIe port information
74 * @gpio_rst: gpio reset
91 * struct mt7621_pcie - PCIe host information
107 return readl_relaxed(pcie->base + reg); in pcie_read()
112 writel_relaxed(val, pcie->base + reg); in pcie_write()
117 return readl_relaxed(port->base + reg); in pcie_port_read()
123 writel_relaxed(val, port->base + reg); in pcie_port_write()
129 struct mt7621_pcie *pcie = bus->sysdata; in mt7621_pcie_map_bus()
130 u32 address = PCI_CONF1_EXT_ADDRESS(bus->number, PCI_SLOT(devfn), in mt7621_pcie_map_bus()
133 writel_relaxed(address, pcie->base + RALINK_PCI_CONFIG_ADDR); in mt7621_pcie_map_bus()
135 return pcie->base + RALINK_PCI_CONFIG_DATA + (where & 3); in mt7621_pcie_map_bus()
163 if (port->gpio_rst) in mt7621_rst_gpio_pcie_assert()
164 gpiod_set_value(port->gpio_rst, 1); in mt7621_rst_gpio_pcie_assert()
169 if (port->gpio_rst) in mt7621_rst_gpio_pcie_deassert()
170 gpiod_set_value(port->gpio_rst, 0); in mt7621_rst_gpio_pcie_deassert()
180 struct mt7621_pcie *pcie = port->pcie; in mt7621_control_assert()
182 if (pcie->resets_inverted) in mt7621_control_assert()
183 reset_control_assert(port->pcie_rst); in mt7621_control_assert()
185 reset_control_deassert(port->pcie_rst); in mt7621_control_assert()
190 struct mt7621_pcie *pcie = port->pcie; in mt7621_control_deassert()
192 if (pcie->resets_inverted) in mt7621_control_deassert()
193 reset_control_deassert(port->pcie_rst); in mt7621_control_deassert()
195 reset_control_assert(port->pcie_rst); in mt7621_control_deassert()
203 struct device *dev = pcie->dev; in mt7621_pcie_parse_port()
210 return -ENOMEM; in mt7621_pcie_parse_port()
212 port->base = devm_platform_ioremap_resource(pdev, slot + 1); in mt7621_pcie_parse_port()
213 if (IS_ERR(port->base)) in mt7621_pcie_parse_port()
214 return PTR_ERR(port->base); in mt7621_pcie_parse_port()
216 port->clk = devm_get_clk_from_child(dev, node, NULL); in mt7621_pcie_parse_port()
217 if (IS_ERR(port->clk)) { in mt7621_pcie_parse_port()
219 return PTR_ERR(port->clk); in mt7621_pcie_parse_port()
222 port->pcie_rst = of_reset_control_get_exclusive(node, NULL); in mt7621_pcie_parse_port()
223 if (PTR_ERR(port->pcie_rst) == -EPROBE_DEFER) { in mt7621_pcie_parse_port()
225 return PTR_ERR(port->pcie_rst); in mt7621_pcie_parse_port()
228 snprintf(name, sizeof(name), "pcie-phy%d", slot); in mt7621_pcie_parse_port()
229 port->phy = devm_of_phy_get(dev, node, name); in mt7621_pcie_parse_port()
230 if (IS_ERR(port->phy)) { in mt7621_pcie_parse_port()
231 dev_err(dev, "failed to get pcie-phy%d\n", slot); in mt7621_pcie_parse_port()
232 err = PTR_ERR(port->phy); in mt7621_pcie_parse_port()
236 port->gpio_rst = devm_gpiod_get_index_optional(dev, "reset", slot, in mt7621_pcie_parse_port()
238 if (IS_ERR(port->gpio_rst)) { in mt7621_pcie_parse_port()
239 dev_err(dev, "failed to get GPIO for PCIe%d\n", slot); in mt7621_pcie_parse_port()
240 err = PTR_ERR(port->gpio_rst); in mt7621_pcie_parse_port()
244 port->slot = slot; in mt7621_pcie_parse_port()
245 port->pcie = pcie; in mt7621_pcie_parse_port()
247 INIT_LIST_HEAD(&port->list); in mt7621_pcie_parse_port()
248 list_add_tail(&port->list, &pcie->ports); in mt7621_pcie_parse_port()
253 reset_control_put(port->pcie_rst); in mt7621_pcie_parse_port()
259 struct device *dev = pcie->dev; in mt7621_pcie_parse_dt()
261 struct device_node *node = dev->of_node, *child; in mt7621_pcie_parse_dt()
264 pcie->base = devm_platform_ioremap_resource(pdev, 0); in mt7621_pcie_parse_dt()
265 if (IS_ERR(pcie->base)) in mt7621_pcie_parse_dt()
266 return PTR_ERR(pcie->base); in mt7621_pcie_parse_dt()
292 struct mt7621_pcie *pcie = port->pcie; in mt7621_pcie_init_port()
293 struct device *dev = pcie->dev; in mt7621_pcie_init_port()
294 u32 slot = port->slot; in mt7621_pcie_init_port()
297 err = phy_init(port->phy); in mt7621_pcie_init_port()
303 err = phy_power_on(port->phy); in mt7621_pcie_init_port()
306 phy_exit(port->phy); in mt7621_pcie_init_port()
310 port->enabled = true; in mt7621_pcie_init_port()
319 list_for_each_entry(port, &pcie->ports, list) { in mt7621_pcie_reset_assert()
334 list_for_each_entry(port, &pcie->ports, list) in mt7621_pcie_reset_rc_deassert()
342 list_for_each_entry(port, &pcie->ports, list) in mt7621_pcie_reset_ep_deassert()
350 struct device *dev = pcie->dev; in mt7621_pcie_init_ports()
358 list_for_each_entry_safe(port, tmp, &pcie->ports, list) { in mt7621_pcie_init_ports()
359 u32 slot = port->slot; in mt7621_pcie_init_ports()
362 port->enabled = true; in mt7621_pcie_init_ports()
369 list_del(&port->list); in mt7621_pcie_init_ports()
377 list_for_each_entry(port, &pcie->ports, list) { in mt7621_pcie_init_ports()
378 u32 slot = port->slot; in mt7621_pcie_init_ports()
384 port->enabled = false; in mt7621_pcie_init_ports()
392 if (slot == 1 && tmp && !tmp->enabled) in mt7621_pcie_init_ports()
393 phy_power_off(tmp->phy); in mt7621_pcie_init_ports()
397 return (num_disabled != PCIE_PORT_CNT) ? 0 : -ENODEV; in mt7621_pcie_init_ports()
402 struct mt7621_pcie *pcie = port->pcie; in mt7621_pcie_enable_port()
403 u32 slot = port->slot; in mt7621_pcie_enable_port()
429 struct device *dev = pcie->dev; in mt7621_pcie_enable_ports()
434 entry = resource_list_first_type(&host->windows, IORESOURCE_IO); in mt7621_pcie_enable_ports()
437 return -EINVAL; in mt7621_pcie_enable_ports()
442 pcie_write(pcie, entry->res->start - entry->offset, RALINK_PCI_IOBASE); in mt7621_pcie_enable_ports()
444 list_for_each_entry(port, &pcie->ports, list) { in mt7621_pcie_enable_ports()
445 if (port->enabled) { in mt7621_pcie_enable_ports()
446 err = clk_prepare_enable(port->clk); in mt7621_pcie_enable_ports()
449 port->slot); in mt7621_pcie_enable_ports()
454 dev_info(dev, "PCIE%d enabled\n", port->slot); in mt7621_pcie_enable_ports()
465 host->ops = &mt7621_pcie_ops; in mt7621_pcie_register_host()
466 host->sysdata = pcie; in mt7621_pcie_register_host()
471 { .soc_id = "mt7621", .revision = "E2" },
477 struct device *dev = &pdev->dev; in mt7621_pcie_probe()
484 if (!dev->of_node) in mt7621_pcie_probe()
485 return -ENODEV; in mt7621_pcie_probe()
489 return -ENOMEM; in mt7621_pcie_probe()
492 pcie->dev = dev; in mt7621_pcie_probe()
494 INIT_LIST_HEAD(&pcie->ports); in mt7621_pcie_probe()
498 pcie->resets_inverted = true; in mt7621_pcie_probe()
521 list_for_each_entry(port, &pcie->ports, list) in mt7621_pcie_probe()
522 reset_control_put(port->pcie_rst); in mt7621_pcie_probe()
532 list_for_each_entry(port, &pcie->ports, list) in mt7621_pcie_remove()
533 reset_control_put(port->pcie_rst); in mt7621_pcie_remove()
537 { .compatible = "mediatek,mt7621-pci" },
546 .name = "mt7621-pci",
552 MODULE_DESCRIPTION("MediaTek MT7621 PCIe host controller driver");