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
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()
420 "ports-implemented", &hpriv->saved_port_map); 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()
462 struct ahci_host_priv *hpriv; in ahci_platform_get_resources() local
469 hpriv = devres_alloc(ahci_platform_put_resources, sizeof(*hpriv), in ahci_platform_get_resources()
471 if (!hpriv) in ahci_platform_get_resources()
474 devres_add(dev, hpriv); 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()
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()
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()
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()
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()
595 if (port >= hpriv->nports) { in ahci_platform_get_resources()
607 rc = ahci_platform_get_regulator(hpriv, port, in ahci_platform_get_resources()
616 rc = ahci_platform_get_phy(hpriv, port, dev, child); 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()
637 rc = ahci_platform_get_phy(hpriv, 0, dev, dev->of_node); in ahci_platform_get_resources()
641 rc = ahci_platform_get_regulator(hpriv, 0, dev); in ahci_platform_get_resources()
650 rc = ahci_platform_get_firmware(hpriv, dev); in ahci_platform_get_resources()
656 hpriv->got_runtime_pm = true; in ahci_platform_get_resources()
659 return hpriv; in ahci_platform_get_resources()
682 struct ahci_host_priv *hpriv, in ahci_platform_init_host() argument
698 hpriv->irq = irq; in ahci_platform_init_host()
701 pi.private_data = (void *)(unsigned long)hpriv->flags; in ahci_platform_init_host()
703 ahci_save_initial_config(dev, hpriv); 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()
711 ahci_set_em_messages(hpriv, &pi); in ahci_platform_init_host()
718 n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); 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()
743 ap->em_message_type = hpriv->em_msg_type; in ahci_platform_init_host()
746 if (!(hpriv->port_map & (1 << i))) in ahci_platform_init_host()
750 if (hpriv->cap & HOST_CAP_64) { in ahci_platform_init_host()
771 struct ahci_host_priv *hpriv = host->private_data; in ahci_host_stop() local
773 ahci_platform_disable_resources(hpriv); in ahci_host_stop()
787 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_shutdown() local
788 void __iomem *mmio = hpriv->mmio; in ahci_platform_shutdown()
825 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend_host() local
826 void __iomem *mmio = hpriv->mmio; in ahci_platform_suspend_host()
829 if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) { in ahci_platform_suspend_host()
844 if (hpriv->flags & AHCI_HFLAG_SUSPEND_PHYS) in ahci_platform_suspend_host()
845 ahci_platform_disable_phys(hpriv); in ahci_platform_suspend_host()
866 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_resume_host() local
877 if (hpriv->flags & AHCI_HFLAG_SUSPEND_PHYS) in ahci_platform_resume_host()
878 ahci_platform_enable_phys(hpriv); in ahci_platform_resume_host()
899 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend() local
906 ahci_platform_disable_resources(hpriv); in ahci_platform_suspend()
925 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_resume() local
928 rc = ahci_platform_enable_resources(hpriv); in ahci_platform_resume()
944 ahci_platform_disable_resources(hpriv); in ahci_platform_resume()