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 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()
73 phy_power_off(hpriv->phys[i]); in ahci_platform_enable_phys()
74 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
86 void ahci_platform_disable_phys(struct ahci_host_priv *hpriv) in ahci_platform_disable_phys() argument
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()
108 struct clk *ahci_platform_find_clk(struct ahci_host_priv *hpriv, const char *con_id) in ahci_platform_find_clk() argument
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()
130 int ahci_platform_enable_clks(struct ahci_host_priv *hpriv) in ahci_platform_enable_clks() argument
132 return clk_bulk_prepare_enable(hpriv->n_clks, hpriv->clks); in ahci_platform_enable_clks()
144 void ahci_platform_disable_clks(struct ahci_host_priv *hpriv) in ahci_platform_disable_clks() argument
146 clk_bulk_disable_unprepare(hpriv->n_clks, hpriv->clks); in ahci_platform_disable_clks()
160 int ahci_platform_deassert_rsts(struct ahci_host_priv *hpriv) in ahci_platform_deassert_rsts() argument
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()
179 int ahci_platform_assert_rsts(struct ahci_host_priv *hpriv) in ahci_platform_assert_rsts() argument
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()
200 int ahci_platform_enable_regulators(struct ahci_host_priv *hpriv) in ahci_platform_enable_regulators() argument
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()
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()
242 void ahci_platform_disable_regulators(struct ahci_host_priv *hpriv) in ahci_platform_disable_regulators() argument
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()
273 int ahci_platform_enable_resources(struct ahci_host_priv *hpriv) in ahci_platform_enable_resources() argument
277 rc = ahci_platform_enable_regulators(hpriv); in ahci_platform_enable_resources()
281 rc = ahci_platform_enable_clks(hpriv); in ahci_platform_enable_resources()
285 rc = ahci_platform_deassert_rsts(hpriv); in ahci_platform_enable_resources()
289 rc = ahci_platform_enable_phys(hpriv); in ahci_platform_enable_resources()
296 ahci_platform_assert_rsts(hpriv); in ahci_platform_enable_resources()
299 ahci_platform_disable_clks(hpriv); in ahci_platform_enable_resources()
302 ahci_platform_disable_regulators(hpriv); in ahci_platform_enable_resources()
319 void ahci_platform_disable_resources(struct ahci_host_priv *hpriv) in ahci_platform_disable_resources() argument
321 ahci_platform_disable_phys(hpriv); in ahci_platform_disable_resources()
323 ahci_platform_assert_rsts(hpriv); in ahci_platform_disable_resources()
325 ahci_platform_disable_clks(hpriv); in ahci_platform_disable_resources()
327 ahci_platform_disable_regulators(hpriv); in ahci_platform_disable_resources()
333 struct ahci_host_priv *hpriv = res; in ahci_platform_put_resources() local
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()
353 static int ahci_platform_get_phy(struct ahci_host_priv *hpriv, u32 port, in ahci_platform_get_phy() argument
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()
376 hpriv->phys[port] = NULL; in ahci_platform_get_phy()
394 static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port, in ahci_platform_get_regulator() argument
403 hpriv->target_pwrs[port] = target_pwr; in ahci_platform_get_regulator()
410 static int ahci_platform_get_firmware(struct ahci_host_priv *hpriv, in ahci_platform_get_firmware() argument
415 if (!of_property_read_u32(dev->of_node, "hba-cap", &hpriv->saved_cap)) in ahci_platform_get_firmware()
416 hpriv->saved_cap &= (HOST_CAP_SSS | HOST_CAP_MPS); in ahci_platform_get_firmware()
419 "ports-implemented", &hpriv->saved_port_map); in ahci_platform_get_firmware()
428 if (!of_property_read_u32(child, "hba-port-cap", &hpriv->saved_port_cap[port])) in ahci_platform_get_firmware()
429 hpriv->saved_port_cap[port] &= PORT_CMD_CAP; in ahci_platform_get_firmware()
459 struct ahci_host_priv *hpriv; in ahci_platform_get_resources() local
465 hpriv = devres_alloc(ahci_platform_put_resources, sizeof(*hpriv), in ahci_platform_get_resources()
467 if (!hpriv) in ahci_platform_get_resources()
470 devres_add(dev, hpriv); in ahci_platform_get_resources()
477 hpriv->mmio = devm_platform_ioremap_resource_byname(pdev, "ahci"); in ahci_platform_get_resources()
479 hpriv->mmio = devm_platform_ioremap_resource(pdev, 0); in ahci_platform_get_resources()
480 if (IS_ERR(hpriv->mmio)) { in ahci_platform_get_resources()
481 rc = PTR_ERR(hpriv->mmio); in ahci_platform_get_resources()
492 rc = devm_clk_bulk_get_all(dev, &hpriv->clks); in ahci_platform_get_resources()
498 hpriv->n_clks = rc; in ahci_platform_get_resources()
504 hpriv->clks = devm_kzalloc(dev, sizeof(*hpriv->clks), GFP_KERNEL); in ahci_platform_get_resources()
505 if (!hpriv->clks) { in ahci_platform_get_resources()
509 hpriv->clks->clk = devm_clk_get_optional(dev, NULL); in ahci_platform_get_resources()
510 if (IS_ERR(hpriv->clks->clk)) { in ahci_platform_get_resources()
511 rc = PTR_ERR(hpriv->clks->clk); in ahci_platform_get_resources()
513 } else if (hpriv->clks->clk) { in ahci_platform_get_resources()
514 hpriv->clks->id = "ahci"; in ahci_platform_get_resources()
515 hpriv->n_clks = 1; in ahci_platform_get_resources()
519 hpriv->ahci_regulator = devm_regulator_get(dev, "ahci"); in ahci_platform_get_resources()
520 if (IS_ERR(hpriv->ahci_regulator)) { in ahci_platform_get_resources()
521 rc = PTR_ERR(hpriv->ahci_regulator); in ahci_platform_get_resources()
526 hpriv->phy_regulator = devm_regulator_get(dev, "phy"); in ahci_platform_get_resources()
527 if (IS_ERR(hpriv->phy_regulator)) { in ahci_platform_get_resources()
528 rc = PTR_ERR(hpriv->phy_regulator); in ahci_platform_get_resources()
533 hpriv->rsts = devm_reset_control_array_get_optional_shared(dev); in ahci_platform_get_resources()
534 if (IS_ERR(hpriv->rsts)) { in ahci_platform_get_resources()
535 rc = PTR_ERR(hpriv->rsts); in ahci_platform_get_resources()
539 hpriv->f_rsts = flags & AHCI_PLATFORM_RST_TRIGGER; in ahci_platform_get_resources()
558 hpriv->nports = child_nodes; in ahci_platform_get_resources()
560 hpriv->nports = 1; in ahci_platform_get_resources()
562 hpriv->phys = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GFP_KERNEL); in ahci_platform_get_resources()
563 if (!hpriv->phys) { in ahci_platform_get_resources()
571 hpriv->target_pwrs = kcalloc(hpriv->nports, sizeof(*hpriv->target_pwrs), GFP_KERNEL); in ahci_platform_get_resources()
572 if (!hpriv->target_pwrs) { in ahci_platform_get_resources()
590 if (port >= hpriv->nports) { in ahci_platform_get_resources()
602 rc = ahci_platform_get_regulator(hpriv, port, in ahci_platform_get_resources()
609 rc = ahci_platform_get_phy(hpriv, port, dev, child); in ahci_platform_get_resources()
621 if (!hpriv->mask_port_map) in ahci_platform_get_resources()
622 hpriv->mask_port_map = mask_port_map; in ahci_platform_get_resources()
628 rc = ahci_platform_get_phy(hpriv, 0, dev, dev->of_node); in ahci_platform_get_resources()
632 rc = ahci_platform_get_regulator(hpriv, 0, dev); in ahci_platform_get_resources()
641 rc = ahci_platform_get_firmware(hpriv, dev); in ahci_platform_get_resources()
647 hpriv->got_runtime_pm = true; in ahci_platform_get_resources()
650 return hpriv; in ahci_platform_get_resources()
673 struct ahci_host_priv *hpriv, in ahci_platform_init_host() argument
689 hpriv->irq = irq; in ahci_platform_init_host()
692 pi.private_data = (void *)(unsigned long)hpriv->flags; in ahci_platform_init_host()
694 ahci_save_initial_config(dev, hpriv); in ahci_platform_init_host()
696 if (hpriv->cap & HOST_CAP_NCQ) in ahci_platform_init_host()
699 if (hpriv->cap & HOST_CAP_PMP) in ahci_platform_init_host()
702 ahci_set_em_messages(hpriv, &pi); in ahci_platform_init_host()
709 n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); in ahci_platform_init_host()
715 host->private_data = hpriv; in ahci_platform_init_host()
717 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) in ahci_platform_init_host()
734 ap->em_message_type = hpriv->em_msg_type; in ahci_platform_init_host()
737 if (!(hpriv->port_map & (1 << i))) in ahci_platform_init_host()
741 if (hpriv->cap & HOST_CAP_64) { in ahci_platform_init_host()
762 struct ahci_host_priv *hpriv = host->private_data; in ahci_host_stop() local
764 ahci_platform_disable_resources(hpriv); in ahci_host_stop()
778 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_shutdown() local
779 void __iomem *mmio = hpriv->mmio; in ahci_platform_shutdown()
816 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend_host() local
817 void __iomem *mmio = hpriv->mmio; in ahci_platform_suspend_host()
820 if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) { in ahci_platform_suspend_host()
835 if (hpriv->flags & AHCI_HFLAG_SUSPEND_PHYS) in ahci_platform_suspend_host()
836 ahci_platform_disable_phys(hpriv); in ahci_platform_suspend_host()
857 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_resume_host() local
868 if (hpriv->flags & AHCI_HFLAG_SUSPEND_PHYS) in ahci_platform_resume_host()
869 ahci_platform_enable_phys(hpriv); in ahci_platform_resume_host()
890 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend() local
897 ahci_platform_disable_resources(hpriv); in ahci_platform_suspend()
916 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_resume() local
919 rc = ahci_platform_enable_resources(hpriv); in ahci_platform_resume()
935 ahci_platform_disable_resources(hpriv); in ahci_platform_resume()