Lines Matching +full:hba +full:- +full:cap
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright 2004-2005 Red Hat, Inc.
37 * ahci_platform_enable_phys - Enable PHYs
40 * This function enables all the PHYs found in hpriv->phys, if any.
51 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_enable_phys()
52 rc = phy_init(hpriv->phys[i]); in ahci_platform_enable_phys()
56 rc = phy_set_mode(hpriv->phys[i], PHY_MODE_SATA); in ahci_platform_enable_phys()
58 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
62 rc = phy_power_on(hpriv->phys[i]); in ahci_platform_enable_phys()
64 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
72 while (--i >= 0) { in ahci_platform_enable_phys()
73 phy_power_off(hpriv->phys[i]); in ahci_platform_enable_phys()
74 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
81 * ahci_platform_disable_phys - Disable PHYs
84 * This function disables all PHYs found in hpriv->phys.
90 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_disable_phys()
91 phy_power_off(hpriv->phys[i]); in ahci_platform_disable_phys()
92 phy_exit(hpriv->phys[i]); in ahci_platform_disable_phys()
98 * ahci_platform_find_clk - Find platform clock
112 for (i = 0; i < hpriv->n_clks; i++) { in ahci_platform_find_clk()
113 if (hpriv->clks[i].id && !strcmp(hpriv->clks[i].id, con_id)) in ahci_platform_find_clk()
114 return hpriv->clks[i].clk; in ahci_platform_find_clk()
122 * ahci_platform_enable_clks - Enable platform clocks
132 return clk_bulk_prepare_enable(hpriv->n_clks, hpriv->clks); in ahci_platform_enable_clks()
137 * ahci_platform_disable_clks - Disable platform clocks
141 * (bulk-clocks-disable function is supposed to do that in reverse
146 clk_bulk_disable_unprepare(hpriv->n_clks, hpriv->clks); in ahci_platform_disable_clks()
151 * ahci_platform_deassert_rsts - Deassert/trigger platform resets
162 if (hpriv->f_rsts & AHCI_PLATFORM_RST_TRIGGER) in ahci_platform_deassert_rsts()
163 return reset_control_reset(hpriv->rsts); in ahci_platform_deassert_rsts()
165 return reset_control_deassert(hpriv->rsts); in ahci_platform_deassert_rsts()
170 * ahci_platform_assert_rsts - Assert/rearm platform resets
173 * This function asserts or rearms (for self-deasserting resets) all
181 if (hpriv->f_rsts & AHCI_PLATFORM_RST_TRIGGER) in ahci_platform_assert_rsts()
182 return reset_control_rearm(hpriv->rsts); in ahci_platform_assert_rsts()
184 return reset_control_assert(hpriv->rsts); in ahci_platform_assert_rsts()
189 * ahci_platform_enable_regulators - Enable regulators
193 * hpriv->target_pwrs, if any. If a regulator fails to be enabled, it
204 rc = regulator_enable(hpriv->ahci_regulator); in ahci_platform_enable_regulators()
208 rc = regulator_enable(hpriv->phy_regulator); in ahci_platform_enable_regulators()
212 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_enable_regulators()
213 if (!hpriv->target_pwrs[i]) in ahci_platform_enable_regulators()
216 rc = regulator_enable(hpriv->target_pwrs[i]); in ahci_platform_enable_regulators()
224 while (--i >= 0) in ahci_platform_enable_regulators()
225 if (hpriv->target_pwrs[i]) in ahci_platform_enable_regulators()
226 regulator_disable(hpriv->target_pwrs[i]); in ahci_platform_enable_regulators()
228 regulator_disable(hpriv->phy_regulator); in ahci_platform_enable_regulators()
230 regulator_disable(hpriv->ahci_regulator); in ahci_platform_enable_regulators()
236 * ahci_platform_disable_regulators - Disable regulators
239 * This function disables all regulators found in hpriv->target_pwrs and
246 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_disable_regulators()
247 if (!hpriv->target_pwrs[i]) in ahci_platform_disable_regulators()
249 regulator_disable(hpriv->target_pwrs[i]); in ahci_platform_disable_regulators()
252 regulator_disable(hpriv->ahci_regulator); in ahci_platform_disable_regulators()
253 regulator_disable(hpriv->phy_regulator); in ahci_platform_disable_regulators()
257 * ahci_platform_enable_resources - Enable platform resources
309 * ahci_platform_disable_resources - Disable platform resources
336 if (hpriv->got_runtime_pm) { in ahci_platform_put_resources()
346 for (c = 0; c < hpriv->nports; c++) in ahci_platform_put_resources()
347 if (hpriv->target_pwrs && hpriv->target_pwrs[c]) in ahci_platform_put_resources()
348 regulator_put(hpriv->target_pwrs[c]); in ahci_platform_put_resources()
350 kfree(hpriv->target_pwrs); in ahci_platform_put_resources()
358 hpriv->phys[port] = devm_of_phy_get(dev, node, NULL); in ahci_platform_get_phy()
360 if (!IS_ERR(hpriv->phys[port])) in ahci_platform_get_phy()
363 rc = PTR_ERR(hpriv->phys[port]); in ahci_platform_get_phy()
365 case -ENOSYS: in ahci_platform_get_phy()
374 case -ENODEV: in ahci_platform_get_phy()
376 hpriv->phys[port] = NULL; in ahci_platform_get_phy()
379 case -EPROBE_DEFER: in ahci_platform_get_phy()
403 hpriv->target_pwrs[port] = target_pwr; in ahci_platform_get_regulator()
416 if (!of_property_read_u32(dev->of_node, "hba-cap", &hpriv->saved_cap)) in ahci_platform_get_firmware()
417 hpriv->saved_cap &= (HOST_CAP_SSS | HOST_CAP_MPS); in ahci_platform_get_firmware()
419 of_property_read_u32(dev->of_node, in ahci_platform_get_firmware()
420 "ports-implemented", &hpriv->saved_port_map); in ahci_platform_get_firmware()
422 for_each_child_of_node(dev->of_node, child) { in ahci_platform_get_firmware()
428 return -EINVAL; in ahci_platform_get_firmware()
431 if (!of_property_read_u32(child, "hba-port-cap", &hpriv->saved_port_cap[port])) in ahci_platform_get_firmware()
432 hpriv->saved_port_cap[port] &= PORT_CMD_CAP; in ahci_platform_get_firmware()
439 * ahci_platform_get_resources - Get platform resources
450 * clock for non-OF platforms (optional)
460 int child_nodes, rc = -ENOMEM, enabled_ports = 0; in ahci_platform_get_resources()
461 struct device *dev = &pdev->dev; in ahci_platform_get_resources()
467 return ERR_PTR(-ENOMEM); in ahci_platform_get_resources()
481 hpriv->mmio = devm_platform_ioremap_resource_byname(pdev, "ahci"); in ahci_platform_get_resources()
483 hpriv->mmio = devm_platform_ioremap_resource(pdev, 0); in ahci_platform_get_resources()
484 if (IS_ERR(hpriv->mmio)) { in ahci_platform_get_resources()
485 rc = PTR_ERR(hpriv->mmio); in ahci_platform_get_resources()
491 * running on a non-OF platform or due to the clocks being defined in in ahci_platform_get_resources()
496 rc = devm_clk_bulk_get_all(dev, &hpriv->clks); in ahci_platform_get_resources()
502 hpriv->n_clks = rc; in ahci_platform_get_resources()
508 hpriv->clks = devm_kzalloc(dev, sizeof(*hpriv->clks), GFP_KERNEL); in ahci_platform_get_resources()
509 if (!hpriv->clks) { in ahci_platform_get_resources()
510 rc = -ENOMEM; in ahci_platform_get_resources()
513 hpriv->clks->clk = devm_clk_get_optional(dev, NULL); in ahci_platform_get_resources()
514 if (IS_ERR(hpriv->clks->clk)) { in ahci_platform_get_resources()
515 rc = PTR_ERR(hpriv->clks->clk); in ahci_platform_get_resources()
517 } else if (hpriv->clks->clk) { in ahci_platform_get_resources()
518 hpriv->clks->id = "ahci"; in ahci_platform_get_resources()
519 hpriv->n_clks = 1; in ahci_platform_get_resources()
523 hpriv->ahci_regulator = devm_regulator_get(dev, "ahci"); in ahci_platform_get_resources()
524 if (IS_ERR(hpriv->ahci_regulator)) { in ahci_platform_get_resources()
525 rc = PTR_ERR(hpriv->ahci_regulator); in ahci_platform_get_resources()
530 hpriv->phy_regulator = devm_regulator_get(dev, "phy"); in ahci_platform_get_resources()
531 if (IS_ERR(hpriv->phy_regulator)) { in ahci_platform_get_resources()
532 rc = PTR_ERR(hpriv->phy_regulator); in ahci_platform_get_resources()
537 hpriv->rsts = devm_reset_control_array_get_optional_shared(dev); in ahci_platform_get_resources()
538 if (IS_ERR(hpriv->rsts)) { in ahci_platform_get_resources()
539 rc = PTR_ERR(hpriv->rsts); in ahci_platform_get_resources()
543 hpriv->f_rsts = flags & AHCI_PLATFORM_RST_TRIGGER; in ahci_platform_get_resources()
547 * Too many sub-nodes most likely means having something wrong with in ahci_platform_get_resources()
550 child_nodes = of_get_child_count(dev->of_node); in ahci_platform_get_resources()
552 rc = -EINVAL; in ahci_platform_get_resources()
557 * If no sub-node was found, we still need to set nports to in ahci_platform_get_resources()
562 hpriv->nports = child_nodes; in ahci_platform_get_resources()
564 hpriv->nports = 1; in ahci_platform_get_resources()
566 hpriv->phys = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GFP_KERNEL); in ahci_platform_get_resources()
567 if (!hpriv->phys) { in ahci_platform_get_resources()
568 rc = -ENOMEM; in ahci_platform_get_resources()
575 hpriv->target_pwrs = kcalloc(hpriv->nports, sizeof(*hpriv->target_pwrs), GFP_KERNEL); in ahci_platform_get_resources()
576 if (!hpriv->target_pwrs) { in ahci_platform_get_resources()
577 rc = -ENOMEM; in ahci_platform_get_resources()
582 for_each_child_of_node(dev->of_node, child) { in ahci_platform_get_resources()
590 rc = -EINVAL; in ahci_platform_get_resources()
595 if (port >= hpriv->nports) { in ahci_platform_get_resources()
608 &port_dev->dev); in ahci_platform_get_resources()
609 if (rc == -EPROBE_DEFER) { in ahci_platform_get_resources()
626 rc = -ENODEV; in ahci_platform_get_resources()
630 if (!hpriv->mask_port_map) in ahci_platform_get_resources()
631 hpriv->mask_port_map = mask_port_map; in ahci_platform_get_resources()
634 * If no sub-node was found, keep this for device tree in ahci_platform_get_resources()
637 rc = ahci_platform_get_phy(hpriv, 0, dev, dev->of_node); in ahci_platform_get_resources()
642 if (rc == -EPROBE_DEFER) in ahci_platform_get_resources()
647 * Retrieve firmware-specific flags which then will be used to set in ahci_platform_get_resources()
648 * the HW-init fields of HBA and its ports in ahci_platform_get_resources()
656 hpriv->got_runtime_pm = true; in ahci_platform_get_resources()
668 * ahci_platform_init_host - Bring up an ahci-platform host
670 * @hpriv: ahci-host private data for the host
675 * ahci-platform host, note any necessary resources (ie clks, phys, etc.)
686 struct device *dev = &pdev->dev; in ahci_platform_init_host()
696 return -EINVAL; in ahci_platform_init_host()
698 hpriv->irq = irq; in ahci_platform_init_host()
701 pi.private_data = (void *)(unsigned long)hpriv->flags; in ahci_platform_init_host()
705 if (hpriv->cap & HOST_CAP_NCQ) in ahci_platform_init_host()
708 if (hpriv->cap & HOST_CAP_PMP) in ahci_platform_init_host()
713 /* CAP.NP sometimes indicate the index of the last enabled in ahci_platform_init_host()
716 * both CAP.NP and port_map. in ahci_platform_init_host()
718 n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); in ahci_platform_init_host()
722 return -ENOMEM; in ahci_platform_init_host()
724 host->private_data = hpriv; in ahci_platform_init_host()
726 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) in ahci_platform_init_host()
727 host->flags |= ATA_HOST_PARALLEL_SCAN; in ahci_platform_init_host()
734 for (i = 0; i < host->n_ports; i++) { in ahci_platform_init_host()
735 struct ata_port *ap = host->ports[i]; in ahci_platform_init_host()
739 ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80); in ahci_platform_init_host()
742 if (ap->flags & ATA_FLAG_EM) in ahci_platform_init_host()
743 ap->em_message_type = hpriv->em_msg_type; in ahci_platform_init_host()
745 /* disabled/not-implemented port */ in ahci_platform_init_host()
746 if (!(hpriv->port_map & (1 << i))) in ahci_platform_init_host()
747 ap->ops = &ata_dummy_port_ops; in ahci_platform_init_host()
750 if (hpriv->cap & HOST_CAP_64) { in ahci_platform_init_host()
753 dev_err(dev, "Failed to enable 64-bit DMA.\n"); in ahci_platform_init_host()
771 struct ahci_host_priv *hpriv = host->private_data; in ahci_host_stop()
777 * ahci_platform_shutdown - Disable interrupts and stop DMA for host ports
787 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_shutdown()
788 void __iomem *mmio = hpriv->mmio; in ahci_platform_shutdown()
791 for (i = 0; i < host->n_ports; i++) { in ahci_platform_shutdown()
792 struct ata_port *ap = host->ports[i]; in ahci_platform_shutdown()
795 if (ap->ops->freeze) in ahci_platform_shutdown()
796 ap->ops->freeze(ap); in ahci_platform_shutdown()
799 if (ap->ops->port_stop) in ahci_platform_shutdown()
800 ap->ops->port_stop(ap); in ahci_platform_shutdown()
806 writel(GENMASK(host->n_ports, 0), mmio + HOST_IRQ_STAT); in ahci_platform_shutdown()
812 * ahci_platform_suspend_host - Suspend an ahci-platform host
816 * ahci-platform host, note any necessary resources (ie clks, phys, etc.)
825 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend_host()
826 void __iomem *mmio = hpriv->mmio; in ahci_platform_suspend_host()
829 if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) { in ahci_platform_suspend_host()
831 return -EIO; in ahci_platform_suspend_host()
837 * transition of the HBA to D3 state. in ahci_platform_suspend_host()
844 if (hpriv->flags & AHCI_HFLAG_SUSPEND_PHYS) in ahci_platform_suspend_host()
853 * ahci_platform_resume_host - Resume an ahci-platform host
856 * This function does all the usual steps needed to resume an ahci-platform
866 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_resume_host()
869 if (dev->power.power_state.event == PM_EVENT_SUSPEND) { in ahci_platform_resume_host()
877 if (hpriv->flags & AHCI_HFLAG_SUSPEND_PHYS) in ahci_platform_resume_host()
887 * ahci_platform_suspend - Suspend an ahci-platform device
899 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend()
913 * ahci_platform_resume - Resume an ahci-platform device
925 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_resume()