• Home
  • Raw
  • Download

Lines Matching +full:port +full:- +full:phys

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright 2004-2005 Red Hat, Inc.
36 * ahci_platform_enable_phys - Enable PHYs
39 * This function enables all the PHYs found in hpriv->phys, if any.
40 * If a PHY fails to be enabled, it disables all the PHYs already
50 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_enable_phys()
51 rc = phy_init(hpriv->phys[i]); in ahci_platform_enable_phys()
55 rc = phy_set_mode(hpriv->phys[i], PHY_MODE_SATA); in ahci_platform_enable_phys()
57 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
61 rc = phy_power_on(hpriv->phys[i]); in ahci_platform_enable_phys()
62 if (rc && !(rc == -EOPNOTSUPP && (hpriv->flags & AHCI_HFLAG_IGN_NOTSUPP_POWER_ON))) { in ahci_platform_enable_phys()
63 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
71 while (--i >= 0) { in ahci_platform_enable_phys()
72 phy_power_off(hpriv->phys[i]); in ahci_platform_enable_phys()
73 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
80 * ahci_platform_disable_phys - Disable PHYs
83 * This function disables all PHYs found in hpriv->phys.
89 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_disable_phys()
90 phy_power_off(hpriv->phys[i]); in ahci_platform_disable_phys()
91 phy_exit(hpriv->phys[i]); in ahci_platform_disable_phys()
97 * ahci_platform_enable_clks - Enable platform clocks
100 * This function enables all the clks found in hpriv->clks, starting at
111 for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++) { in ahci_platform_enable_clks()
112 rc = clk_prepare_enable(hpriv->clks[c]); in ahci_platform_enable_clks()
119 while (--c >= 0) in ahci_platform_enable_clks()
120 clk_disable_unprepare(hpriv->clks[c]); in ahci_platform_enable_clks()
126 * ahci_platform_disable_clks - Disable platform clocks
129 * This function disables all the clks found in hpriv->clks, in reverse
136 for (c = AHCI_MAX_CLKS - 1; c >= 0; c--) in ahci_platform_disable_clks()
137 if (hpriv->clks[c]) in ahci_platform_disable_clks()
138 clk_disable_unprepare(hpriv->clks[c]); in ahci_platform_disable_clks()
143 * ahci_platform_enable_regulators - Enable regulators
147 * hpriv->target_pwrs, if any. If a regulator fails to be enabled, it
158 rc = regulator_enable(hpriv->ahci_regulator); in ahci_platform_enable_regulators()
162 rc = regulator_enable(hpriv->phy_regulator); in ahci_platform_enable_regulators()
166 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_enable_regulators()
167 if (!hpriv->target_pwrs[i]) in ahci_platform_enable_regulators()
170 rc = regulator_enable(hpriv->target_pwrs[i]); in ahci_platform_enable_regulators()
178 while (--i >= 0) in ahci_platform_enable_regulators()
179 if (hpriv->target_pwrs[i]) in ahci_platform_enable_regulators()
180 regulator_disable(hpriv->target_pwrs[i]); in ahci_platform_enable_regulators()
182 regulator_disable(hpriv->phy_regulator); in ahci_platform_enable_regulators()
184 regulator_disable(hpriv->ahci_regulator); in ahci_platform_enable_regulators()
190 * ahci_platform_disable_regulators - Disable regulators
193 * This function disables all regulators found in hpriv->target_pwrs and
200 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_disable_regulators()
201 if (!hpriv->target_pwrs[i]) in ahci_platform_disable_regulators()
203 regulator_disable(hpriv->target_pwrs[i]); in ahci_platform_disable_regulators()
206 regulator_disable(hpriv->ahci_regulator); in ahci_platform_disable_regulators()
207 regulator_disable(hpriv->phy_regulator); in ahci_platform_disable_regulators()
211 * ahci_platform_enable_resources - Enable platform resources
219 * 4) Phys
239 rc = reset_control_deassert(hpriv->rsts); in ahci_platform_enable_resources()
250 reset_control_assert(hpriv->rsts); in ahci_platform_enable_resources()
263 * ahci_platform_disable_resources - Disable platform resources
268 * 1) Phys
277 reset_control_assert(hpriv->rsts); in ahci_platform_disable_resources()
290 if (hpriv->got_runtime_pm) { in ahci_platform_put_resources()
295 for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++) in ahci_platform_put_resources()
296 clk_put(hpriv->clks[c]); in ahci_platform_put_resources()
302 for (c = 0; c < hpriv->nports; c++) in ahci_platform_put_resources()
303 if (hpriv->target_pwrs && hpriv->target_pwrs[c]) in ahci_platform_put_resources()
304 regulator_put(hpriv->target_pwrs[c]); in ahci_platform_put_resources()
306 kfree(hpriv->target_pwrs); in ahci_platform_put_resources()
309 static int ahci_platform_get_phy(struct ahci_host_priv *hpriv, u32 port, in ahci_platform_get_phy() argument
314 hpriv->phys[port] = devm_of_phy_get(dev, node, NULL); in ahci_platform_get_phy()
316 if (!IS_ERR(hpriv->phys[port])) in ahci_platform_get_phy()
319 rc = PTR_ERR(hpriv->phys[port]); in ahci_platform_get_phy()
321 case -ENOSYS: in ahci_platform_get_phy()
323 if (of_find_property(node, "phys", NULL)) { in ahci_platform_get_phy()
330 case -ENODEV: in ahci_platform_get_phy()
332 hpriv->phys[port] = NULL; in ahci_platform_get_phy()
335 case -EPROBE_DEFER: in ahci_platform_get_phy()
350 static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port, in ahci_platform_get_regulator() argument
359 hpriv->target_pwrs[port] = target_pwr; in ahci_platform_get_regulator()
367 * ahci_platform_get_resources - Get platform resources
377 * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node,
380 * 5) phys (optional)
388 struct device *dev = &pdev->dev; in ahci_platform_get_resources()
392 int i, enabled_ports = 0, rc = -ENOMEM, child_nodes; in ahci_platform_get_resources()
396 return ERR_PTR(-ENOMEM); in ahci_platform_get_resources()
405 hpriv->mmio = devm_ioremap_resource(dev, in ahci_platform_get_resources()
407 if (IS_ERR(hpriv->mmio)) { in ahci_platform_get_resources()
408 rc = PTR_ERR(hpriv->mmio); in ahci_platform_get_resources()
417 * this is equivalent to of_clk_get(dev->of_node, 0). in ahci_platform_get_resources()
422 clk = of_clk_get(dev->of_node, i); in ahci_platform_get_resources()
426 if (rc == -EPROBE_DEFER) in ahci_platform_get_resources()
430 hpriv->clks[i] = clk; in ahci_platform_get_resources()
433 hpriv->ahci_regulator = devm_regulator_get(dev, "ahci"); in ahci_platform_get_resources()
434 if (IS_ERR(hpriv->ahci_regulator)) { in ahci_platform_get_resources()
435 rc = PTR_ERR(hpriv->ahci_regulator); in ahci_platform_get_resources()
440 hpriv->phy_regulator = devm_regulator_get(dev, "phy"); in ahci_platform_get_resources()
441 if (IS_ERR(hpriv->phy_regulator)) { in ahci_platform_get_resources()
442 rc = PTR_ERR(hpriv->phy_regulator); in ahci_platform_get_resources()
447 hpriv->rsts = devm_reset_control_array_get_optional_shared(dev); in ahci_platform_get_resources()
448 if (IS_ERR(hpriv->rsts)) { in ahci_platform_get_resources()
449 rc = PTR_ERR(hpriv->rsts); in ahci_platform_get_resources()
455 * Too many sub-nodes most likely means having something wrong with in ahci_platform_get_resources()
458 child_nodes = of_get_child_count(dev->of_node); in ahci_platform_get_resources()
460 rc = -EINVAL; in ahci_platform_get_resources()
465 * If no sub-node was found, we still need to set nports to in ahci_platform_get_resources()
467 * ahci_platform_[en|dis]able_[phys|regulators] functions. in ahci_platform_get_resources()
470 hpriv->nports = child_nodes; in ahci_platform_get_resources()
472 hpriv->nports = 1; in ahci_platform_get_resources()
474 hpriv->phys = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GFP_KERNEL); in ahci_platform_get_resources()
475 if (!hpriv->phys) { in ahci_platform_get_resources()
476 rc = -ENOMEM; in ahci_platform_get_resources()
483 hpriv->target_pwrs = kcalloc(hpriv->nports, sizeof(*hpriv->target_pwrs), GFP_KERNEL); in ahci_platform_get_resources()
484 if (!hpriv->target_pwrs) { in ahci_platform_get_resources()
485 rc = -ENOMEM; in ahci_platform_get_resources()
490 for_each_child_of_node(dev->of_node, child) { in ahci_platform_get_resources()
491 u32 port; in ahci_platform_get_resources() local
497 if (of_property_read_u32(child, "reg", &port)) { in ahci_platform_get_resources()
498 rc = -EINVAL; in ahci_platform_get_resources()
503 if (port >= hpriv->nports) { in ahci_platform_get_resources()
504 dev_warn(dev, "invalid port number %d\n", port); in ahci_platform_get_resources()
507 mask_port_map |= BIT(port); in ahci_platform_get_resources()
515 rc = ahci_platform_get_regulator(hpriv, port, in ahci_platform_get_resources()
516 &port_dev->dev); in ahci_platform_get_resources()
517 if (rc == -EPROBE_DEFER) { in ahci_platform_get_resources()
524 rc = ahci_platform_get_phy(hpriv, port, dev, child); in ahci_platform_get_resources()
533 dev_warn(dev, "No port enabled\n"); in ahci_platform_get_resources()
534 rc = -ENODEV; in ahci_platform_get_resources()
538 if (!hpriv->mask_port_map) in ahci_platform_get_resources()
539 hpriv->mask_port_map = mask_port_map; in ahci_platform_get_resources()
542 * If no sub-node was found, keep this for device tree in ahci_platform_get_resources()
545 rc = ahci_platform_get_phy(hpriv, 0, dev, dev->of_node); in ahci_platform_get_resources()
550 if (rc == -EPROBE_DEFER) in ahci_platform_get_resources()
555 hpriv->got_runtime_pm = true; in ahci_platform_get_resources()
567 * ahci_platform_init_host - Bring up an ahci-platform host
569 * @hpriv: ahci-host private data for the host
574 * ahci-platform host, note any necessary resources (ie clks, phys, etc.)
585 struct device *dev = &pdev->dev; in ahci_platform_init_host()
593 if (irq != -EPROBE_DEFER) in ahci_platform_init_host()
598 return -EINVAL; in ahci_platform_init_host()
600 hpriv->irq = irq; in ahci_platform_init_host()
603 pi.private_data = (void *)(unsigned long)hpriv->flags; in ahci_platform_init_host()
607 if (hpriv->cap & HOST_CAP_NCQ) in ahci_platform_init_host()
610 if (hpriv->cap & HOST_CAP_PMP) in ahci_platform_init_host()
616 * port, at other times, that of the last possible port, so in ahci_platform_init_host()
617 * determining the maximum port number requires looking at in ahci_platform_init_host()
620 n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); in ahci_platform_init_host()
624 return -ENOMEM; in ahci_platform_init_host()
626 host->private_data = hpriv; in ahci_platform_init_host()
628 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) in ahci_platform_init_host()
629 host->flags |= ATA_HOST_PARALLEL_SCAN; in ahci_platform_init_host()
636 for (i = 0; i < host->n_ports; i++) { in ahci_platform_init_host()
637 struct ata_port *ap = host->ports[i]; in ahci_platform_init_host()
641 ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80); in ahci_platform_init_host()
644 if (ap->flags & ATA_FLAG_EM) in ahci_platform_init_host()
645 ap->em_message_type = hpriv->em_msg_type; in ahci_platform_init_host()
647 /* disabled/not-implemented port */ in ahci_platform_init_host()
648 if (!(hpriv->port_map & (1 << i))) in ahci_platform_init_host()
649 ap->ops = &ata_dummy_port_ops; in ahci_platform_init_host()
652 if (hpriv->cap & HOST_CAP_64) { in ahci_platform_init_host()
658 dev_err(dev, "Failed to enable 64-bit DMA.\n"); in ahci_platform_init_host()
661 dev_warn(dev, "Enable 32-bit DMA instead of 64-bit.\n"); in ahci_platform_init_host()
678 struct ahci_host_priv *hpriv = host->private_data; in ahci_host_stop()
684 * ahci_platform_shutdown - Disable interrupts and stop DMA for host ports
694 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_shutdown()
695 void __iomem *mmio = hpriv->mmio; in ahci_platform_shutdown()
698 for (i = 0; i < host->n_ports; i++) { in ahci_platform_shutdown()
699 struct ata_port *ap = host->ports[i]; in ahci_platform_shutdown()
701 /* Disable port interrupts */ in ahci_platform_shutdown()
702 if (ap->ops->freeze) in ahci_platform_shutdown()
703 ap->ops->freeze(ap); in ahci_platform_shutdown()
705 /* Stop the port DMA engines */ in ahci_platform_shutdown()
706 if (ap->ops->port_stop) in ahci_platform_shutdown()
707 ap->ops->port_stop(ap); in ahci_platform_shutdown()
713 writel(GENMASK(host->n_ports, 0), mmio + HOST_IRQ_STAT); in ahci_platform_shutdown()
719 * ahci_platform_suspend_host - Suspend an ahci-platform host
723 * ahci-platform host, note any necessary resources (ie clks, phys, etc.)
732 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend_host()
733 void __iomem *mmio = hpriv->mmio; in ahci_platform_suspend_host()
736 if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) { in ahci_platform_suspend_host()
738 return -EIO; in ahci_platform_suspend_host()
751 if (hpriv->flags & AHCI_HFLAG_SUSPEND_PHYS) in ahci_platform_suspend_host()
759 * ahci_platform_resume_host - Resume an ahci-platform host
762 * This function does all the usual steps needed to resume an ahci-platform
763 * host, note any necessary resources (ie clks, phys, etc.) must be
772 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_resume_host()
775 if (dev->power.power_state.event == PM_EVENT_SUSPEND) { in ahci_platform_resume_host()
783 if (hpriv->flags & AHCI_HFLAG_SUSPEND_PHYS) in ahci_platform_resume_host()
793 * ahci_platform_suspend - Suspend an ahci-platform device
805 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend()
819 * ahci_platform_resume - Resume an ahci-platform device
831 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_resume()