Lines Matching refs:hpriv

46 int ahci_platform_enable_phys(struct ahci_host_priv *hpriv)  in ahci_platform_enable_phys()  argument
50 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_enable_phys()
51 rc = phy_init(hpriv->phys[i]); in ahci_platform_enable_phys()
55 rc = phy_set_mode(hpriv->phys[i], PHY_MODE_SATA); in ahci_platform_enable_phys()
57 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
61 rc = phy_power_on(hpriv->phys[i]); in ahci_platform_enable_phys()
63 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
72 phy_power_off(hpriv->phys[i]); in ahci_platform_enable_phys()
73 phy_exit(hpriv->phys[i]); in ahci_platform_enable_phys()
85 void ahci_platform_disable_phys(struct ahci_host_priv *hpriv) in ahci_platform_disable_phys() argument
89 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_disable_phys()
90 phy_power_off(hpriv->phys[i]); in ahci_platform_disable_phys()
91 phy_exit(hpriv->phys[i]); in ahci_platform_disable_phys()
107 struct clk *ahci_platform_find_clk(struct ahci_host_priv *hpriv, const char *con_id) in ahci_platform_find_clk() argument
111 for (i = 0; i < hpriv->n_clks; i++) { in ahci_platform_find_clk()
112 if (hpriv->clks[i].id && !strcmp(hpriv->clks[i].id, con_id)) in ahci_platform_find_clk()
113 return hpriv->clks[i].clk; in ahci_platform_find_clk()
129 int ahci_platform_enable_clks(struct ahci_host_priv *hpriv) in ahci_platform_enable_clks() argument
131 return clk_bulk_prepare_enable(hpriv->n_clks, hpriv->clks); in ahci_platform_enable_clks()
143 void ahci_platform_disable_clks(struct ahci_host_priv *hpriv) in ahci_platform_disable_clks() argument
145 clk_bulk_disable_unprepare(hpriv->n_clks, hpriv->clks); in ahci_platform_disable_clks()
159 int ahci_platform_deassert_rsts(struct ahci_host_priv *hpriv) in ahci_platform_deassert_rsts() argument
161 if (hpriv->f_rsts & AHCI_PLATFORM_RST_TRIGGER) in ahci_platform_deassert_rsts()
162 return reset_control_reset(hpriv->rsts); in ahci_platform_deassert_rsts()
164 return reset_control_deassert(hpriv->rsts); in ahci_platform_deassert_rsts()
178 int ahci_platform_assert_rsts(struct ahci_host_priv *hpriv) in ahci_platform_assert_rsts() argument
180 if (hpriv->f_rsts & AHCI_PLATFORM_RST_TRIGGER) in ahci_platform_assert_rsts()
181 return reset_control_rearm(hpriv->rsts); in ahci_platform_assert_rsts()
183 return reset_control_assert(hpriv->rsts); in ahci_platform_assert_rsts()
199 int ahci_platform_enable_regulators(struct ahci_host_priv *hpriv) in ahci_platform_enable_regulators() argument
203 rc = regulator_enable(hpriv->ahci_regulator); in ahci_platform_enable_regulators()
207 rc = regulator_enable(hpriv->phy_regulator); in ahci_platform_enable_regulators()
211 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_enable_regulators()
212 if (!hpriv->target_pwrs[i]) in ahci_platform_enable_regulators()
215 rc = regulator_enable(hpriv->target_pwrs[i]); in ahci_platform_enable_regulators()
224 if (hpriv->target_pwrs[i]) in ahci_platform_enable_regulators()
225 regulator_disable(hpriv->target_pwrs[i]); in ahci_platform_enable_regulators()
227 regulator_disable(hpriv->phy_regulator); in ahci_platform_enable_regulators()
229 regulator_disable(hpriv->ahci_regulator); in ahci_platform_enable_regulators()
241 void ahci_platform_disable_regulators(struct ahci_host_priv *hpriv) in ahci_platform_disable_regulators() argument
245 for (i = 0; i < hpriv->nports; i++) { in ahci_platform_disable_regulators()
246 if (!hpriv->target_pwrs[i]) in ahci_platform_disable_regulators()
248 regulator_disable(hpriv->target_pwrs[i]); in ahci_platform_disable_regulators()
251 regulator_disable(hpriv->ahci_regulator); in ahci_platform_disable_regulators()
252 regulator_disable(hpriv->phy_regulator); in ahci_platform_disable_regulators()
272 int ahci_platform_enable_resources(struct ahci_host_priv *hpriv) in ahci_platform_enable_resources() argument
276 rc = ahci_platform_enable_regulators(hpriv); in ahci_platform_enable_resources()
280 rc = ahci_platform_enable_clks(hpriv); in ahci_platform_enable_resources()
284 rc = ahci_platform_deassert_rsts(hpriv); in ahci_platform_enable_resources()
288 rc = ahci_platform_enable_phys(hpriv); in ahci_platform_enable_resources()
295 ahci_platform_assert_rsts(hpriv); in ahci_platform_enable_resources()
298 ahci_platform_disable_clks(hpriv); in ahci_platform_enable_resources()
301 ahci_platform_disable_regulators(hpriv); in ahci_platform_enable_resources()
318 void ahci_platform_disable_resources(struct ahci_host_priv *hpriv) in ahci_platform_disable_resources() argument
320 ahci_platform_disable_phys(hpriv); in ahci_platform_disable_resources()
322 ahci_platform_assert_rsts(hpriv); in ahci_platform_disable_resources()
324 ahci_platform_disable_clks(hpriv); in ahci_platform_disable_resources()
326 ahci_platform_disable_regulators(hpriv); in ahci_platform_disable_resources()
332 struct ahci_host_priv *hpriv = res; in ahci_platform_put_resources() local
335 if (hpriv->got_runtime_pm) { in ahci_platform_put_resources()
345 for (c = 0; c < hpriv->nports; c++) in ahci_platform_put_resources()
346 if (hpriv->target_pwrs && hpriv->target_pwrs[c]) in ahci_platform_put_resources()
347 regulator_put(hpriv->target_pwrs[c]); in ahci_platform_put_resources()
349 kfree(hpriv->target_pwrs); in ahci_platform_put_resources()
352 static int ahci_platform_get_phy(struct ahci_host_priv *hpriv, u32 port, in ahci_platform_get_phy() argument
357 hpriv->phys[port] = devm_of_phy_get(dev, node, NULL); in ahci_platform_get_phy()
359 if (!IS_ERR(hpriv->phys[port])) in ahci_platform_get_phy()
362 rc = PTR_ERR(hpriv->phys[port]); in ahci_platform_get_phy()
375 hpriv->phys[port] = NULL; in ahci_platform_get_phy()
393 static int ahci_platform_get_regulator(struct ahci_host_priv *hpriv, u32 port, in ahci_platform_get_regulator() argument
402 hpriv->target_pwrs[port] = target_pwr; in ahci_platform_get_regulator()
409 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()
430 if (!of_property_read_u32(child, "hba-port-cap", &hpriv->saved_port_cap[port])) in ahci_platform_get_firmware()
431 hpriv->saved_port_cap[port] &= PORT_CMD_CAP; in ahci_platform_get_firmware()
461 struct ahci_host_priv *hpriv; in ahci_platform_get_resources() local
468 hpriv = devres_alloc(ahci_platform_put_resources, sizeof(*hpriv), in ahci_platform_get_resources()
470 if (!hpriv) in ahci_platform_get_resources()
473 devres_add(dev, hpriv); in ahci_platform_get_resources()
480 hpriv->mmio = devm_platform_ioremap_resource_byname(pdev, "ahci"); in ahci_platform_get_resources()
482 hpriv->mmio = devm_platform_ioremap_resource(pdev, 0); in ahci_platform_get_resources()
483 if (IS_ERR(hpriv->mmio)) { in ahci_platform_get_resources()
484 rc = PTR_ERR(hpriv->mmio); in ahci_platform_get_resources()
495 rc = devm_clk_bulk_get_all(dev, &hpriv->clks); in ahci_platform_get_resources()
501 hpriv->n_clks = rc; in ahci_platform_get_resources()
507 hpriv->clks = devm_kzalloc(dev, sizeof(*hpriv->clks), GFP_KERNEL); in ahci_platform_get_resources()
508 if (!hpriv->clks) { in ahci_platform_get_resources()
512 hpriv->clks->clk = devm_clk_get_optional(dev, NULL); in ahci_platform_get_resources()
513 if (IS_ERR(hpriv->clks->clk)) { in ahci_platform_get_resources()
514 rc = PTR_ERR(hpriv->clks->clk); in ahci_platform_get_resources()
516 } else if (hpriv->clks->clk) { in ahci_platform_get_resources()
517 hpriv->clks->id = "ahci"; in ahci_platform_get_resources()
518 hpriv->n_clks = 1; in ahci_platform_get_resources()
522 hpriv->ahci_regulator = devm_regulator_get(dev, "ahci"); in ahci_platform_get_resources()
523 if (IS_ERR(hpriv->ahci_regulator)) { in ahci_platform_get_resources()
524 rc = PTR_ERR(hpriv->ahci_regulator); in ahci_platform_get_resources()
529 hpriv->phy_regulator = devm_regulator_get(dev, "phy"); in ahci_platform_get_resources()
530 if (IS_ERR(hpriv->phy_regulator)) { in ahci_platform_get_resources()
531 rc = PTR_ERR(hpriv->phy_regulator); in ahci_platform_get_resources()
536 hpriv->rsts = devm_reset_control_array_get_optional_shared(dev); in ahci_platform_get_resources()
537 if (IS_ERR(hpriv->rsts)) { in ahci_platform_get_resources()
538 rc = PTR_ERR(hpriv->rsts); in ahci_platform_get_resources()
542 hpriv->f_rsts = flags & AHCI_PLATFORM_RST_TRIGGER; in ahci_platform_get_resources()
561 hpriv->nports = child_nodes; in ahci_platform_get_resources()
563 hpriv->nports = 1; in ahci_platform_get_resources()
565 hpriv->phys = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GFP_KERNEL); in ahci_platform_get_resources()
566 if (!hpriv->phys) { in ahci_platform_get_resources()
574 hpriv->target_pwrs = kcalloc(hpriv->nports, sizeof(*hpriv->target_pwrs), GFP_KERNEL); in ahci_platform_get_resources()
575 if (!hpriv->target_pwrs) { in ahci_platform_get_resources()
594 if (port >= hpriv->nports) { in ahci_platform_get_resources()
606 rc = ahci_platform_get_regulator(hpriv, port, in ahci_platform_get_resources()
615 rc = ahci_platform_get_phy(hpriv, port, dev, child); in ahci_platform_get_resources()
629 if (!hpriv->mask_port_map) in ahci_platform_get_resources()
630 hpriv->mask_port_map = mask_port_map; in ahci_platform_get_resources()
636 rc = ahci_platform_get_phy(hpriv, 0, dev, dev->of_node); in ahci_platform_get_resources()
640 rc = ahci_platform_get_regulator(hpriv, 0, dev); in ahci_platform_get_resources()
649 rc = ahci_platform_get_firmware(hpriv, dev); in ahci_platform_get_resources()
655 hpriv->got_runtime_pm = true; in ahci_platform_get_resources()
658 return hpriv; in ahci_platform_get_resources()
681 struct ahci_host_priv *hpriv, in ahci_platform_init_host() argument
697 hpriv->irq = irq; in ahci_platform_init_host()
700 pi.private_data = (void *)(unsigned long)hpriv->flags; in ahci_platform_init_host()
702 ahci_save_initial_config(dev, hpriv); in ahci_platform_init_host()
704 if (hpriv->cap & HOST_CAP_NCQ) in ahci_platform_init_host()
707 if (hpriv->cap & HOST_CAP_PMP) in ahci_platform_init_host()
710 ahci_set_em_messages(hpriv, &pi); in ahci_platform_init_host()
717 n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); in ahci_platform_init_host()
723 host->private_data = hpriv; in ahci_platform_init_host()
725 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) in ahci_platform_init_host()
742 ap->em_message_type = hpriv->em_msg_type; in ahci_platform_init_host()
745 if (!(hpriv->port_map & (1 << i))) in ahci_platform_init_host()
749 if (hpriv->cap & HOST_CAP_64) { in ahci_platform_init_host()
770 struct ahci_host_priv *hpriv = host->private_data; in ahci_host_stop() local
772 ahci_platform_disable_resources(hpriv); in ahci_host_stop()
786 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_shutdown() local
787 void __iomem *mmio = hpriv->mmio; in ahci_platform_shutdown()
824 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend_host() local
825 void __iomem *mmio = hpriv->mmio; in ahci_platform_suspend_host()
828 if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) { in ahci_platform_suspend_host()
843 if (hpriv->flags & AHCI_HFLAG_SUSPEND_PHYS) in ahci_platform_suspend_host()
844 ahci_platform_disable_phys(hpriv); in ahci_platform_suspend_host()
865 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_resume_host() local
876 if (hpriv->flags & AHCI_HFLAG_SUSPEND_PHYS) in ahci_platform_resume_host()
877 ahci_platform_enable_phys(hpriv); in ahci_platform_resume_host()
898 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_suspend() local
905 ahci_platform_disable_resources(hpriv); in ahci_platform_suspend()
924 struct ahci_host_priv *hpriv = host->private_data; in ahci_platform_resume() local
927 rc = ahci_platform_enable_resources(hpriv); in ahci_platform_resume()
943 ahci_platform_disable_resources(hpriv); in ahci_platform_resume()