Lines Matching +full:host +full:- +full:port
4 * Copyright 2004-2005 Red Hat, Inc.
31 static void ahci_host_stop(struct ata_host *host);
40 * ahci_platform_enable_phys - Enable PHYs
41 * @hpriv: host private area to store config values
43 * This function enables all the PHYs found in hpriv->phys, if any.
54 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_enable_phys()
55 rc = phy_init(hpriv->phys[i]); in ahci_platform_enable_phys()
59 rc = phy_power_on(hpriv->phys[i]); in ahci_platform_enable_phys()
61 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
69 while (--i >= 0) { in ahci_platform_enable_phys()
70 phy_power_off(hpriv->phys[i]); in ahci_platform_enable_phys()
71 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
78 * ahci_platform_disable_phys - Disable PHYs
79 * @hpriv: host private area to store config values
81 * This function disables all PHYs found in hpriv->phys.
87 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_disable_phys()
88 phy_power_off(hpriv->phys[i]); in ahci_platform_disable_phys()
89 phy_exit(hpriv->phys[i]); in ahci_platform_disable_phys()
95 * ahci_platform_enable_clks - Enable platform clocks
96 * @hpriv: host private area to store config values
98 * This function enables all the clks found in hpriv->clks, starting at
109 for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++) { in ahci_platform_enable_clks()
110 rc = clk_prepare_enable(hpriv->clks[c]); in ahci_platform_enable_clks()
117 while (--c >= 0) in ahci_platform_enable_clks()
118 clk_disable_unprepare(hpriv->clks[c]); in ahci_platform_enable_clks()
124 * ahci_platform_disable_clks - Disable platform clocks
125 * @hpriv: host private area to store config values
127 * This function disables all the clks found in hpriv->clks, in reverse
134 for (c = AHCI_MAX_CLKS - 1; c >= 0; c--) in ahci_platform_disable_clks()
135 if (hpriv->clks[c]) in ahci_platform_disable_clks()
136 clk_disable_unprepare(hpriv->clks[c]); in ahci_platform_disable_clks()
141 * ahci_platform_enable_regulators - Enable regulators
142 * @hpriv: host private area to store config values
145 * hpriv->target_pwrs, if any. If a regulator fails to be enabled, it
156 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_enable_regulators()
157 if (!hpriv->target_pwrs[i]) in ahci_platform_enable_regulators()
160 rc = regulator_enable(hpriv->target_pwrs[i]); in ahci_platform_enable_regulators()
168 while (--i >= 0) in ahci_platform_enable_regulators()
169 if (hpriv->target_pwrs[i]) in ahci_platform_enable_regulators()
170 regulator_disable(hpriv->target_pwrs[i]); in ahci_platform_enable_regulators()
177 * ahci_platform_disable_regulators - Disable regulators
178 * @hpriv: host private area to store config values
180 * This function disables all regulators found in hpriv->target_pwrs.
186 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_disable_regulators()
187 if (!hpriv->target_pwrs[i]) in ahci_platform_disable_regulators()
189 regulator_disable(hpriv->target_pwrs[i]); in ahci_platform_disable_regulators()
194 * ahci_platform_enable_resources - Enable platform resources
195 * @hpriv: host private area to store config values
222 rc = reset_control_deassert(hpriv->rsts); in ahci_platform_enable_resources()
233 reset_control_assert(hpriv->rsts); in ahci_platform_enable_resources()
246 * ahci_platform_disable_resources - Disable platform resources
247 * @hpriv: host private area to store config values
260 reset_control_assert(hpriv->rsts); in ahci_platform_disable_resources()
273 if (hpriv->got_runtime_pm) { in ahci_platform_put_resources()
278 for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++) in ahci_platform_put_resources()
279 clk_put(hpriv->clks[c]); in ahci_platform_put_resources()
285 for (c = 0; c < hpriv->nports; c++) in ahci_platform_put_resources()
286 if (hpriv->target_pwrs && hpriv->target_pwrs[c]) in ahci_platform_put_resources()
287 regulator_put(hpriv->target_pwrs[c]); in ahci_platform_put_resources()
289 kfree(hpriv->target_pwrs); in ahci_platform_put_resources()
292 static int ahci_platform_get_phy(struct ahci_host_priv *hpriv, u32 port, in ahci_platform_get_phy() argument
297 hpriv->phys[port] = devm_of_phy_get(dev, node, NULL); in ahci_platform_get_phy()
299 if (!IS_ERR(hpriv->phys[port])) in ahci_platform_get_phy()
302 rc = PTR_ERR(hpriv->phys[port]); in ahci_platform_get_phy()
304 case -ENOSYS: in ahci_platform_get_phy()
309 node->name); in ahci_platform_get_phy()
313 case -ENODEV: in ahci_platform_get_phy()
315 hpriv->phys[port] = NULL; in ahci_platform_get_phy()
318 case -EPROBE_DEFER: in ahci_platform_get_phy()
325 node->name, rc); in ahci_platform_get_phy()
333 static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port, in ahci_platform_get_regulator() argument
342 hpriv->target_pwrs[port] = target_pwr; in ahci_platform_get_regulator()
350 * ahci_platform_get_resources - Get platform resources
359 * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node,
370 struct device *dev = &pdev->dev; in ahci_platform_get_resources()
374 int i, enabled_ports = 0, rc = -ENOMEM, child_nodes; in ahci_platform_get_resources()
378 return ERR_PTR(-ENOMEM); in ahci_platform_get_resources()
387 hpriv->mmio = devm_ioremap_resource(dev, in ahci_platform_get_resources()
389 if (IS_ERR(hpriv->mmio)) { in ahci_platform_get_resources()
391 rc = PTR_ERR(hpriv->mmio); in ahci_platform_get_resources()
400 * this is equivalent to of_clk_get(dev->of_node, 0). in ahci_platform_get_resources()
405 clk = of_clk_get(dev->of_node, i); in ahci_platform_get_resources()
409 if (rc == -EPROBE_DEFER) in ahci_platform_get_resources()
413 hpriv->clks[i] = clk; in ahci_platform_get_resources()
417 hpriv->rsts = devm_reset_control_array_get_optional_shared(dev); in ahci_platform_get_resources()
418 if (IS_ERR(hpriv->rsts)) { in ahci_platform_get_resources()
419 rc = PTR_ERR(hpriv->rsts); in ahci_platform_get_resources()
424 hpriv->nports = child_nodes = of_get_child_count(dev->of_node); in ahci_platform_get_resources()
427 * If no sub-node was found, we still need to set nports to in ahci_platform_get_resources()
432 hpriv->nports = 1; in ahci_platform_get_resources()
434 hpriv->phys = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GFP_KERNEL); in ahci_platform_get_resources()
435 if (!hpriv->phys) { in ahci_platform_get_resources()
436 rc = -ENOMEM; in ahci_platform_get_resources()
443 hpriv->target_pwrs = kcalloc(hpriv->nports, sizeof(*hpriv->target_pwrs), GFP_KERNEL); in ahci_platform_get_resources()
444 if (!hpriv->target_pwrs) { in ahci_platform_get_resources()
445 rc = -ENOMEM; in ahci_platform_get_resources()
450 for_each_child_of_node(dev->of_node, child) { in ahci_platform_get_resources()
451 u32 port; in ahci_platform_get_resources() local
457 if (of_property_read_u32(child, "reg", &port)) { in ahci_platform_get_resources()
458 rc = -EINVAL; in ahci_platform_get_resources()
462 if (port >= hpriv->nports) { in ahci_platform_get_resources()
463 dev_warn(dev, "invalid port number %d\n", port); in ahci_platform_get_resources()
466 mask_port_map |= BIT(port); in ahci_platform_get_resources()
474 rc = ahci_platform_get_regulator(hpriv, port, in ahci_platform_get_resources()
475 &port_dev->dev); in ahci_platform_get_resources()
476 if (rc == -EPROBE_DEFER) in ahci_platform_get_resources()
481 rc = ahci_platform_get_phy(hpriv, port, dev, child); in ahci_platform_get_resources()
488 dev_warn(dev, "No port enabled\n"); in ahci_platform_get_resources()
489 rc = -ENODEV; in ahci_platform_get_resources()
493 if (!hpriv->mask_port_map) in ahci_platform_get_resources()
494 hpriv->mask_port_map = mask_port_map; in ahci_platform_get_resources()
497 * If no sub-node was found, keep this for device tree in ahci_platform_get_resources()
500 rc = ahci_platform_get_phy(hpriv, 0, dev, dev->of_node); in ahci_platform_get_resources()
505 if (rc == -EPROBE_DEFER) in ahci_platform_get_resources()
510 hpriv->got_runtime_pm = true; in ahci_platform_get_resources()
522 * ahci_platform_init_host - Bring up an ahci-platform host
523 * @pdev: platform device pointer for the host
524 * @hpriv: ahci-host private data for the host
529 * ahci-platform host, note any necessary resources (ie clks, phys, etc.)
540 struct device *dev = &pdev->dev; in ahci_platform_init_host()
543 struct ata_host *host; in ahci_platform_init_host() local
548 if (irq != -EPROBE_DEFER) in ahci_platform_init_host()
553 hpriv->irq = irq; in ahci_platform_init_host()
555 /* prepare host */ in ahci_platform_init_host()
556 pi.private_data = (void *)(unsigned long)hpriv->flags; in ahci_platform_init_host()
560 if (hpriv->cap & HOST_CAP_NCQ) in ahci_platform_init_host()
563 if (hpriv->cap & HOST_CAP_PMP) in ahci_platform_init_host()
569 * port, at other times, that of the last possible port, so in ahci_platform_init_host()
570 * determining the maximum port number requires looking at in ahci_platform_init_host()
573 n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); in ahci_platform_init_host()
575 host = ata_host_alloc_pinfo(dev, ppi, n_ports); in ahci_platform_init_host()
576 if (!host) in ahci_platform_init_host()
577 return -ENOMEM; in ahci_platform_init_host()
579 host->private_data = hpriv; in ahci_platform_init_host()
581 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) in ahci_platform_init_host()
582 host->flags |= ATA_HOST_PARALLEL_SCAN; in ahci_platform_init_host()
587 ahci_reset_em(host); in ahci_platform_init_host()
589 for (i = 0; i < host->n_ports; i++) { in ahci_platform_init_host()
590 struct ata_port *ap = host->ports[i]; in ahci_platform_init_host()
594 ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80); in ahci_platform_init_host()
597 if (ap->flags & ATA_FLAG_EM) in ahci_platform_init_host()
598 ap->em_message_type = hpriv->em_msg_type; in ahci_platform_init_host()
600 /* disabled/not-implemented port */ in ahci_platform_init_host()
601 if (!(hpriv->port_map & (1 << i))) in ahci_platform_init_host()
602 ap->ops = &ata_dummy_port_ops; in ahci_platform_init_host()
605 if (hpriv->cap & HOST_CAP_64) { in ahci_platform_init_host()
611 dev_err(dev, "Failed to enable 64-bit DMA.\n"); in ahci_platform_init_host()
614 dev_warn(dev, "Enable 32-bit DMA instead of 64-bit.\n"); in ahci_platform_init_host()
618 rc = ahci_reset_controller(host); in ahci_platform_init_host()
622 ahci_init_controller(host); in ahci_platform_init_host()
623 ahci_print_info(host, "platform"); in ahci_platform_init_host()
625 return ahci_host_activate(host, sht); in ahci_platform_init_host()
629 static void ahci_host_stop(struct ata_host *host) in ahci_host_stop() argument
631 struct ahci_host_priv *hpriv = host->private_data; in ahci_host_stop()
637 * ahci_platform_shutdown - Disable interrupts and stop DMA for host ports
638 * @pdev: platform device pointer for the host
641 * deconfiguration required to ensure that an ahci_platform host cannot
646 struct ata_host *host = platform_get_drvdata(pdev); in ahci_platform_shutdown() local
647 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_shutdown()
648 void __iomem *mmio = hpriv->mmio; in ahci_platform_shutdown()
651 for (i = 0; i < host->n_ports; i++) { in ahci_platform_shutdown()
652 struct ata_port *ap = host->ports[i]; in ahci_platform_shutdown()
654 /* Disable port interrupts */ in ahci_platform_shutdown()
655 if (ap->ops->freeze) in ahci_platform_shutdown()
656 ap->ops->freeze(ap); in ahci_platform_shutdown()
658 /* Stop the port DMA engines */ in ahci_platform_shutdown()
659 if (ap->ops->port_stop) in ahci_platform_shutdown()
660 ap->ops->port_stop(ap); in ahci_platform_shutdown()
663 /* Disable and clear host interrupts */ in ahci_platform_shutdown()
666 writel(GENMASK(host->n_ports, 0), mmio + HOST_IRQ_STAT); in ahci_platform_shutdown()
672 * ahci_platform_suspend_host - Suspend an ahci-platform host
673 * @dev: device pointer for the host
676 * ahci-platform host, note any necessary resources (ie clks, phys, etc.)
684 struct ata_host *host = dev_get_drvdata(dev); in ahci_platform_suspend_host() local
685 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend_host()
686 void __iomem *mmio = hpriv->mmio; in ahci_platform_suspend_host()
689 if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) { in ahci_platform_suspend_host()
691 return -EIO; in ahci_platform_suspend_host()
704 return ata_host_suspend(host, PMSG_SUSPEND); in ahci_platform_suspend_host()
709 * ahci_platform_resume_host - Resume an ahci-platform host
710 * @dev: device pointer for the host
712 * This function does all the usual steps needed to resume an ahci-platform
713 * host, note any necessary resources (ie clks, phys, etc.) must be
721 struct ata_host *host = dev_get_drvdata(dev); in ahci_platform_resume_host() local
724 if (dev->power.power_state.event == PM_EVENT_SUSPEND) { in ahci_platform_resume_host()
725 rc = ahci_reset_controller(host); in ahci_platform_resume_host()
729 ahci_init_controller(host); in ahci_platform_resume_host()
732 ata_host_resume(host); in ahci_platform_resume_host()
739 * ahci_platform_suspend - Suspend an ahci-platform device
742 * This function suspends the host associated with the device, followed by
750 struct ata_host *host = dev_get_drvdata(dev); in ahci_platform_suspend() local
751 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend()
765 * ahci_platform_resume - Resume an ahci-platform device
769 * resuming the host associated with the device.
776 struct ata_host *host = dev_get_drvdata(dev); in ahci_platform_resume() local
777 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_resume()