Lines Matching refs:hpriv
47 int ahci_platform_enable_phys(struct ahci_host_priv *hpriv) in ahci_platform_enable_phys() argument
51 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_enable_phys()
52 if (ahci_ignore_port(hpriv, i)) in ahci_platform_enable_phys()
55 rc = phy_init(hpriv->phys[i]); in ahci_platform_enable_phys()
59 rc = phy_set_mode(hpriv->phys[i], PHY_MODE_SATA); in ahci_platform_enable_phys()
61 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
65 rc = phy_power_on(hpriv->phys[i]); in ahci_platform_enable_phys()
67 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
76 if (ahci_ignore_port(hpriv, i)) in ahci_platform_enable_phys()
79 phy_power_off(hpriv->phys[i]); in ahci_platform_enable_phys()
80 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
92 void ahci_platform_disable_phys(struct ahci_host_priv *hpriv) in ahci_platform_disable_phys() argument
96 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_disable_phys()
97 if (ahci_ignore_port(hpriv, i)) in ahci_platform_disable_phys()
100 phy_power_off(hpriv->phys[i]); in ahci_platform_disable_phys()
101 phy_exit(hpriv->phys[i]); in ahci_platform_disable_phys()
117 struct clk *ahci_platform_find_clk(struct ahci_host_priv *hpriv, const char *con_id) in ahci_platform_find_clk() argument
121 for (i = 0; i < hpriv->n_clks; i++) { in ahci_platform_find_clk()
122 if (hpriv->clks[i].id && !strcmp(hpriv->clks[i].id, con_id)) in ahci_platform_find_clk()
123 return hpriv->clks[i].clk; in ahci_platform_find_clk()
139 int ahci_platform_enable_clks(struct ahci_host_priv *hpriv) in ahci_platform_enable_clks() argument
141 return clk_bulk_prepare_enable(hpriv->n_clks, hpriv->clks); in ahci_platform_enable_clks()
153 void ahci_platform_disable_clks(struct ahci_host_priv *hpriv) in ahci_platform_disable_clks() argument
155 clk_bulk_disable_unprepare(hpriv->n_clks, hpriv->clks); in ahci_platform_disable_clks()
169 int ahci_platform_deassert_rsts(struct ahci_host_priv *hpriv) in ahci_platform_deassert_rsts() argument
171 if (hpriv->f_rsts & AHCI_PLATFORM_RST_TRIGGER) in ahci_platform_deassert_rsts()
172 return reset_control_reset(hpriv->rsts); in ahci_platform_deassert_rsts()
174 return reset_control_deassert(hpriv->rsts); in ahci_platform_deassert_rsts()
188 int ahci_platform_assert_rsts(struct ahci_host_priv *hpriv) in ahci_platform_assert_rsts() argument
190 if (hpriv->f_rsts & AHCI_PLATFORM_RST_TRIGGER) in ahci_platform_assert_rsts()
191 return reset_control_rearm(hpriv->rsts); in ahci_platform_assert_rsts()
193 return reset_control_assert(hpriv->rsts); in ahci_platform_assert_rsts()
209 int ahci_platform_enable_regulators(struct ahci_host_priv *hpriv) in ahci_platform_enable_regulators() argument
213 rc = regulator_enable(hpriv->ahci_regulator); in ahci_platform_enable_regulators()
217 rc = regulator_enable(hpriv->phy_regulator); in ahci_platform_enable_regulators()
221 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_enable_regulators()
222 if (!hpriv->target_pwrs[i]) in ahci_platform_enable_regulators()
225 rc = regulator_enable(hpriv->target_pwrs[i]); in ahci_platform_enable_regulators()
234 if (hpriv->target_pwrs[i]) in ahci_platform_enable_regulators()
235 regulator_disable(hpriv->target_pwrs[i]); in ahci_platform_enable_regulators()
237 regulator_disable(hpriv->phy_regulator); in ahci_platform_enable_regulators()
239 regulator_disable(hpriv->ahci_regulator); in ahci_platform_enable_regulators()
251 void ahci_platform_disable_regulators(struct ahci_host_priv *hpriv) in ahci_platform_disable_regulators() argument
255 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_disable_regulators()
256 if (!hpriv->target_pwrs[i]) in ahci_platform_disable_regulators()
258 regulator_disable(hpriv->target_pwrs[i]); in ahci_platform_disable_regulators()
261 regulator_disable(hpriv->ahci_regulator); in ahci_platform_disable_regulators()
262 regulator_disable(hpriv->phy_regulator); in ahci_platform_disable_regulators()
282 int ahci_platform_enable_resources(struct ahci_host_priv *hpriv) in ahci_platform_enable_resources() argument
286 rc = ahci_platform_enable_regulators(hpriv); in ahci_platform_enable_resources()
290 rc = ahci_platform_enable_clks(hpriv); in ahci_platform_enable_resources()
294 rc = ahci_platform_deassert_rsts(hpriv); in ahci_platform_enable_resources()
298 rc = ahci_platform_enable_phys(hpriv); in ahci_platform_enable_resources()
305 ahci_platform_assert_rsts(hpriv); in ahci_platform_enable_resources()
308 ahci_platform_disable_clks(hpriv); in ahci_platform_enable_resources()
311 ahci_platform_disable_regulators(hpriv); in ahci_platform_enable_resources()
328 void ahci_platform_disable_resources(struct ahci_host_priv *hpriv) in ahci_platform_disable_resources() argument
330 ahci_platform_disable_phys(hpriv); in ahci_platform_disable_resources()
332 ahci_platform_assert_rsts(hpriv); in ahci_platform_disable_resources()
334 ahci_platform_disable_clks(hpriv); in ahci_platform_disable_resources()
336 ahci_platform_disable_regulators(hpriv); in ahci_platform_disable_resources()
342 struct ahci_host_priv *hpriv = res; in ahci_platform_put_resources() local
345 if (hpriv->got_runtime_pm) { in ahci_platform_put_resources()
355 for (c = 0; c < hpriv->nports; c++) in ahci_platform_put_resources()
356 if (hpriv->target_pwrs && hpriv->target_pwrs[c]) in ahci_platform_put_resources()
357 regulator_put(hpriv->target_pwrs[c]); in ahci_platform_put_resources()
359 kfree(hpriv->target_pwrs); in ahci_platform_put_resources()
362 static int ahci_platform_get_phy(struct ahci_host_priv *hpriv, u32 port, in ahci_platform_get_phy() argument
367 hpriv->phys[port] = devm_of_phy_get(dev, node, NULL); in ahci_platform_get_phy()
369 if (!IS_ERR(hpriv->phys[port])) in ahci_platform_get_phy()
372 rc = PTR_ERR(hpriv->phys[port]); in ahci_platform_get_phy()
385 hpriv->phys[port] = NULL; in ahci_platform_get_phy()
403 static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port, in ahci_platform_get_regulator() argument
412 hpriv->target_pwrs[port] = target_pwr; in ahci_platform_get_regulator()
419 static int ahci_platform_get_firmware(struct ahci_host_priv *hpriv, in ahci_platform_get_firmware() argument
424 if (!of_property_read_u32(dev->of_node, "hba-cap", &hpriv->saved_cap)) in ahci_platform_get_firmware()
425 hpriv->saved_cap &= (HOST_CAP_SSS | HOST_CAP_MPS); in ahci_platform_get_firmware()
428 "ports-implemented", &hpriv->saved_port_map); in ahci_platform_get_firmware()
437 if (!of_property_read_u32(child, "hba-port-cap", &hpriv->saved_port_cap[port])) in ahci_platform_get_firmware()
438 hpriv->saved_port_cap[port] &= PORT_CMD_CAP; in ahci_platform_get_firmware()
482 struct ahci_host_priv *hpriv; in ahci_platform_get_resources() local
489 hpriv = devres_alloc(ahci_platform_put_resources, sizeof(*hpriv), in ahci_platform_get_resources()
491 if (!hpriv) in ahci_platform_get_resources()
494 devres_add(dev, hpriv); in ahci_platform_get_resources()
501 hpriv->mmio = devm_platform_ioremap_resource_byname(pdev, "ahci"); in ahci_platform_get_resources()
503 hpriv->mmio = devm_platform_ioremap_resource(pdev, 0); in ahci_platform_get_resources()
504 if (IS_ERR(hpriv->mmio)) { in ahci_platform_get_resources()
505 rc = PTR_ERR(hpriv->mmio); in ahci_platform_get_resources()
516 rc = devm_clk_bulk_get_all(dev, &hpriv->clks); in ahci_platform_get_resources()
522 hpriv->n_clks = rc; in ahci_platform_get_resources()
528 hpriv->clks = devm_kzalloc(dev, sizeof(*hpriv->clks), GFP_KERNEL); in ahci_platform_get_resources()
529 if (!hpriv->clks) { in ahci_platform_get_resources()
533 hpriv->clks->clk = devm_clk_get_optional(dev, NULL); in ahci_platform_get_resources()
534 if (IS_ERR(hpriv->clks->clk)) { in ahci_platform_get_resources()
535 rc = PTR_ERR(hpriv->clks->clk); in ahci_platform_get_resources()
537 } else if (hpriv->clks->clk) { in ahci_platform_get_resources()
538 hpriv->clks->id = "ahci"; in ahci_platform_get_resources()
539 hpriv->n_clks = 1; in ahci_platform_get_resources()
543 hpriv->ahci_regulator = devm_regulator_get(dev, "ahci"); in ahci_platform_get_resources()
544 if (IS_ERR(hpriv->ahci_regulator)) { in ahci_platform_get_resources()
545 rc = PTR_ERR(hpriv->ahci_regulator); in ahci_platform_get_resources()
550 hpriv->phy_regulator = devm_regulator_get(dev, "phy"); in ahci_platform_get_resources()
551 if (IS_ERR(hpriv->phy_regulator)) { in ahci_platform_get_resources()
552 rc = PTR_ERR(hpriv->phy_regulator); in ahci_platform_get_resources()
557 hpriv->rsts = devm_reset_control_array_get_optional_shared(dev); in ahci_platform_get_resources()
558 if (IS_ERR(hpriv->rsts)) { in ahci_platform_get_resources()
559 rc = PTR_ERR(hpriv->rsts); in ahci_platform_get_resources()
563 hpriv->f_rsts = flags & AHCI_PLATFORM_RST_TRIGGER; in ahci_platform_get_resources()
586 hpriv->nports = min(AHCI_MAX_PORTS, max_port + 1); in ahci_platform_get_resources()
588 hpriv->phys = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GFP_KERNEL); in ahci_platform_get_resources()
589 if (!hpriv->phys) { in ahci_platform_get_resources()
597 hpriv->target_pwrs = kcalloc(hpriv->nports, sizeof(*hpriv->target_pwrs), GFP_KERNEL); in ahci_platform_get_resources()
598 if (!hpriv->target_pwrs) { in ahci_platform_get_resources()
616 if (port >= hpriv->nports) { in ahci_platform_get_resources()
628 rc = ahci_platform_get_regulator(hpriv, port, in ahci_platform_get_resources()
635 rc = ahci_platform_get_phy(hpriv, port, dev, child); in ahci_platform_get_resources()
647 if (!hpriv->mask_port_map) in ahci_platform_get_resources()
648 hpriv->mask_port_map = mask_port_map; in ahci_platform_get_resources()
654 rc = ahci_platform_get_phy(hpriv, 0, dev, dev->of_node); in ahci_platform_get_resources()
658 rc = ahci_platform_get_regulator(hpriv, 0, dev); in ahci_platform_get_resources()
667 rc = ahci_platform_get_firmware(hpriv, dev); in ahci_platform_get_resources()
673 hpriv->got_runtime_pm = true; in ahci_platform_get_resources()
676 return hpriv; in ahci_platform_get_resources()
699 struct ahci_host_priv *hpriv, in ahci_platform_init_host() argument
715 hpriv->irq = irq; in ahci_platform_init_host()
718 pi.private_data = (void *)(unsigned long)hpriv->flags; in ahci_platform_init_host()
720 ahci_save_initial_config(dev, hpriv); in ahci_platform_init_host()
722 if (hpriv->cap & HOST_CAP_NCQ) in ahci_platform_init_host()
725 if (hpriv->cap & HOST_CAP_PMP) in ahci_platform_init_host()
728 ahci_set_em_messages(hpriv, &pi); in ahci_platform_init_host()
735 n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); in ahci_platform_init_host()
741 host->private_data = hpriv; in ahci_platform_init_host()
743 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) in ahci_platform_init_host()
760 ap->em_message_type = hpriv->em_msg_type; in ahci_platform_init_host()
763 if (!(hpriv->port_map & (1 << i))) in ahci_platform_init_host()
767 if (hpriv->cap & HOST_CAP_64) { in ahci_platform_init_host()
788 struct ahci_host_priv *hpriv = host->private_data; in ahci_host_stop() local
790 ahci_platform_disable_resources(hpriv); in ahci_host_stop()
804 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_shutdown() local
805 void __iomem *mmio = hpriv->mmio; in ahci_platform_shutdown()
842 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend_host() local
843 void __iomem *mmio = hpriv->mmio; in ahci_platform_suspend_host()
846 if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) { in ahci_platform_suspend_host()
861 if (hpriv->flags & AHCI_HFLAG_SUSPEND_PHYS) in ahci_platform_suspend_host()
862 ahci_platform_disable_phys(hpriv); in ahci_platform_suspend_host()
883 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_resume_host() local
894 if (hpriv->flags & AHCI_HFLAG_SUSPEND_PHYS) in ahci_platform_resume_host()
895 ahci_platform_enable_phys(hpriv); in ahci_platform_resume_host()
916 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend() local
923 ahci_platform_disable_resources(hpriv); in ahci_platform_suspend()
942 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_resume() local
945 rc = ahci_platform_enable_resources(hpriv); in ahci_platform_resume()
961 ahci_platform_disable_resources(hpriv); in ahci_platform_resume()