18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2017 BayLibre, SAS 38c2ecf20Sopenharmony_ci * Author: Neil Armstrong <narmstrong@baylibre.com> 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * SPDX-License-Identifier: GPL-2.0+ 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/of_address.h> 98c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 108c2ecf20Sopenharmony_ci#include <linux/pm_domain.h> 118c2ecf20Sopenharmony_ci#include <linux/bitfield.h> 128c2ecf20Sopenharmony_ci#include <linux/regmap.h> 138c2ecf20Sopenharmony_ci#include <linux/mfd/syscon.h> 148c2ecf20Sopenharmony_ci#include <linux/of_device.h> 158c2ecf20Sopenharmony_ci#include <linux/reset.h> 168c2ecf20Sopenharmony_ci#include <linux/clk.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/* AO Offsets */ 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define AO_RTI_GEN_PWR_SLEEP0 (0x3a << 2) 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define GEN_PWR_VPU_HDMI BIT(8) 238c2ecf20Sopenharmony_ci#define GEN_PWR_VPU_HDMI_ISO BIT(9) 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* HHI Offsets */ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define HHI_MEM_PD_REG0 (0x40 << 2) 288c2ecf20Sopenharmony_ci#define HHI_VPU_MEM_PD_REG0 (0x41 << 2) 298c2ecf20Sopenharmony_ci#define HHI_VPU_MEM_PD_REG1 (0x42 << 2) 308c2ecf20Sopenharmony_ci#define HHI_VPU_MEM_PD_REG2 (0x4d << 2) 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cistruct meson_gx_pwrc_vpu { 338c2ecf20Sopenharmony_ci struct generic_pm_domain genpd; 348c2ecf20Sopenharmony_ci struct regmap *regmap_ao; 358c2ecf20Sopenharmony_ci struct regmap *regmap_hhi; 368c2ecf20Sopenharmony_ci struct reset_control *rstc; 378c2ecf20Sopenharmony_ci struct clk *vpu_clk; 388c2ecf20Sopenharmony_ci struct clk *vapb_clk; 398c2ecf20Sopenharmony_ci}; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic inline 428c2ecf20Sopenharmony_cistruct meson_gx_pwrc_vpu *genpd_to_pd(struct generic_pm_domain *d) 438c2ecf20Sopenharmony_ci{ 448c2ecf20Sopenharmony_ci return container_of(d, struct meson_gx_pwrc_vpu, genpd); 458c2ecf20Sopenharmony_ci} 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistatic int meson_gx_pwrc_vpu_power_off(struct generic_pm_domain *genpd) 488c2ecf20Sopenharmony_ci{ 498c2ecf20Sopenharmony_ci struct meson_gx_pwrc_vpu *pd = genpd_to_pd(genpd); 508c2ecf20Sopenharmony_ci int i; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_ao, AO_RTI_GEN_PWR_SLEEP0, 538c2ecf20Sopenharmony_ci GEN_PWR_VPU_HDMI_ISO, GEN_PWR_VPU_HDMI_ISO); 548c2ecf20Sopenharmony_ci udelay(20); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci /* Power Down Memories */ 578c2ecf20Sopenharmony_ci for (i = 0; i < 32; i += 2) { 588c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_VPU_MEM_PD_REG0, 598c2ecf20Sopenharmony_ci 0x3 << i, 0x3 << i); 608c2ecf20Sopenharmony_ci udelay(5); 618c2ecf20Sopenharmony_ci } 628c2ecf20Sopenharmony_ci for (i = 0; i < 32; i += 2) { 638c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_VPU_MEM_PD_REG1, 648c2ecf20Sopenharmony_ci 0x3 << i, 0x3 << i); 658c2ecf20Sopenharmony_ci udelay(5); 668c2ecf20Sopenharmony_ci } 678c2ecf20Sopenharmony_ci for (i = 8; i < 16; i++) { 688c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_MEM_PD_REG0, 698c2ecf20Sopenharmony_ci BIT(i), BIT(i)); 708c2ecf20Sopenharmony_ci udelay(5); 718c2ecf20Sopenharmony_ci } 728c2ecf20Sopenharmony_ci udelay(20); 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_ao, AO_RTI_GEN_PWR_SLEEP0, 758c2ecf20Sopenharmony_ci GEN_PWR_VPU_HDMI, GEN_PWR_VPU_HDMI); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci msleep(20); 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci clk_disable_unprepare(pd->vpu_clk); 808c2ecf20Sopenharmony_ci clk_disable_unprepare(pd->vapb_clk); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci return 0; 838c2ecf20Sopenharmony_ci} 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_cistatic int meson_g12a_pwrc_vpu_power_off(struct generic_pm_domain *genpd) 868c2ecf20Sopenharmony_ci{ 878c2ecf20Sopenharmony_ci struct meson_gx_pwrc_vpu *pd = genpd_to_pd(genpd); 888c2ecf20Sopenharmony_ci int i; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_ao, AO_RTI_GEN_PWR_SLEEP0, 918c2ecf20Sopenharmony_ci GEN_PWR_VPU_HDMI_ISO, GEN_PWR_VPU_HDMI_ISO); 928c2ecf20Sopenharmony_ci udelay(20); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci /* Power Down Memories */ 958c2ecf20Sopenharmony_ci for (i = 0; i < 32; i += 2) { 968c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_VPU_MEM_PD_REG0, 978c2ecf20Sopenharmony_ci 0x3 << i, 0x3 << i); 988c2ecf20Sopenharmony_ci udelay(5); 998c2ecf20Sopenharmony_ci } 1008c2ecf20Sopenharmony_ci for (i = 0; i < 32; i += 2) { 1018c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_VPU_MEM_PD_REG1, 1028c2ecf20Sopenharmony_ci 0x3 << i, 0x3 << i); 1038c2ecf20Sopenharmony_ci udelay(5); 1048c2ecf20Sopenharmony_ci } 1058c2ecf20Sopenharmony_ci for (i = 0; i < 32; i += 2) { 1068c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_VPU_MEM_PD_REG2, 1078c2ecf20Sopenharmony_ci 0x3 << i, 0x3 << i); 1088c2ecf20Sopenharmony_ci udelay(5); 1098c2ecf20Sopenharmony_ci } 1108c2ecf20Sopenharmony_ci for (i = 8; i < 16; i++) { 1118c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_MEM_PD_REG0, 1128c2ecf20Sopenharmony_ci BIT(i), BIT(i)); 1138c2ecf20Sopenharmony_ci udelay(5); 1148c2ecf20Sopenharmony_ci } 1158c2ecf20Sopenharmony_ci udelay(20); 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_ao, AO_RTI_GEN_PWR_SLEEP0, 1188c2ecf20Sopenharmony_ci GEN_PWR_VPU_HDMI, GEN_PWR_VPU_HDMI); 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci msleep(20); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci clk_disable_unprepare(pd->vpu_clk); 1238c2ecf20Sopenharmony_ci clk_disable_unprepare(pd->vapb_clk); 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci return 0; 1268c2ecf20Sopenharmony_ci} 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistatic int meson_gx_pwrc_vpu_setup_clk(struct meson_gx_pwrc_vpu *pd) 1298c2ecf20Sopenharmony_ci{ 1308c2ecf20Sopenharmony_ci int ret; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci ret = clk_prepare_enable(pd->vpu_clk); 1338c2ecf20Sopenharmony_ci if (ret) 1348c2ecf20Sopenharmony_ci return ret; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci ret = clk_prepare_enable(pd->vapb_clk); 1378c2ecf20Sopenharmony_ci if (ret) 1388c2ecf20Sopenharmony_ci clk_disable_unprepare(pd->vpu_clk); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci return ret; 1418c2ecf20Sopenharmony_ci} 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistatic int meson_gx_pwrc_vpu_power_on(struct generic_pm_domain *genpd) 1448c2ecf20Sopenharmony_ci{ 1458c2ecf20Sopenharmony_ci struct meson_gx_pwrc_vpu *pd = genpd_to_pd(genpd); 1468c2ecf20Sopenharmony_ci int ret; 1478c2ecf20Sopenharmony_ci int i; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_ao, AO_RTI_GEN_PWR_SLEEP0, 1508c2ecf20Sopenharmony_ci GEN_PWR_VPU_HDMI, 0); 1518c2ecf20Sopenharmony_ci udelay(20); 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci /* Power Up Memories */ 1548c2ecf20Sopenharmony_ci for (i = 0; i < 32; i += 2) { 1558c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_VPU_MEM_PD_REG0, 1568c2ecf20Sopenharmony_ci 0x3 << i, 0); 1578c2ecf20Sopenharmony_ci udelay(5); 1588c2ecf20Sopenharmony_ci } 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci for (i = 0; i < 32; i += 2) { 1618c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_VPU_MEM_PD_REG1, 1628c2ecf20Sopenharmony_ci 0x3 << i, 0); 1638c2ecf20Sopenharmony_ci udelay(5); 1648c2ecf20Sopenharmony_ci } 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci for (i = 8; i < 16; i++) { 1678c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_MEM_PD_REG0, 1688c2ecf20Sopenharmony_ci BIT(i), 0); 1698c2ecf20Sopenharmony_ci udelay(5); 1708c2ecf20Sopenharmony_ci } 1718c2ecf20Sopenharmony_ci udelay(20); 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci ret = reset_control_assert(pd->rstc); 1748c2ecf20Sopenharmony_ci if (ret) 1758c2ecf20Sopenharmony_ci return ret; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_ao, AO_RTI_GEN_PWR_SLEEP0, 1788c2ecf20Sopenharmony_ci GEN_PWR_VPU_HDMI_ISO, 0); 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci ret = reset_control_deassert(pd->rstc); 1818c2ecf20Sopenharmony_ci if (ret) 1828c2ecf20Sopenharmony_ci return ret; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci ret = meson_gx_pwrc_vpu_setup_clk(pd); 1858c2ecf20Sopenharmony_ci if (ret) 1868c2ecf20Sopenharmony_ci return ret; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci return 0; 1898c2ecf20Sopenharmony_ci} 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_cistatic int meson_g12a_pwrc_vpu_power_on(struct generic_pm_domain *genpd) 1928c2ecf20Sopenharmony_ci{ 1938c2ecf20Sopenharmony_ci struct meson_gx_pwrc_vpu *pd = genpd_to_pd(genpd); 1948c2ecf20Sopenharmony_ci int ret; 1958c2ecf20Sopenharmony_ci int i; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_ao, AO_RTI_GEN_PWR_SLEEP0, 1988c2ecf20Sopenharmony_ci GEN_PWR_VPU_HDMI, 0); 1998c2ecf20Sopenharmony_ci udelay(20); 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci /* Power Up Memories */ 2028c2ecf20Sopenharmony_ci for (i = 0; i < 32; i += 2) { 2038c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_VPU_MEM_PD_REG0, 2048c2ecf20Sopenharmony_ci 0x3 << i, 0); 2058c2ecf20Sopenharmony_ci udelay(5); 2068c2ecf20Sopenharmony_ci } 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci for (i = 0; i < 32; i += 2) { 2098c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_VPU_MEM_PD_REG1, 2108c2ecf20Sopenharmony_ci 0x3 << i, 0); 2118c2ecf20Sopenharmony_ci udelay(5); 2128c2ecf20Sopenharmony_ci } 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci for (i = 0; i < 32; i += 2) { 2158c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_VPU_MEM_PD_REG2, 2168c2ecf20Sopenharmony_ci 0x3 << i, 0); 2178c2ecf20Sopenharmony_ci udelay(5); 2188c2ecf20Sopenharmony_ci } 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci for (i = 8; i < 16; i++) { 2218c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_hhi, HHI_MEM_PD_REG0, 2228c2ecf20Sopenharmony_ci BIT(i), 0); 2238c2ecf20Sopenharmony_ci udelay(5); 2248c2ecf20Sopenharmony_ci } 2258c2ecf20Sopenharmony_ci udelay(20); 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci ret = reset_control_assert(pd->rstc); 2288c2ecf20Sopenharmony_ci if (ret) 2298c2ecf20Sopenharmony_ci return ret; 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci regmap_update_bits(pd->regmap_ao, AO_RTI_GEN_PWR_SLEEP0, 2328c2ecf20Sopenharmony_ci GEN_PWR_VPU_HDMI_ISO, 0); 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci ret = reset_control_deassert(pd->rstc); 2358c2ecf20Sopenharmony_ci if (ret) 2368c2ecf20Sopenharmony_ci return ret; 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci ret = meson_gx_pwrc_vpu_setup_clk(pd); 2398c2ecf20Sopenharmony_ci if (ret) 2408c2ecf20Sopenharmony_ci return ret; 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci return 0; 2438c2ecf20Sopenharmony_ci} 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_cistatic bool meson_gx_pwrc_vpu_get_power(struct meson_gx_pwrc_vpu *pd) 2468c2ecf20Sopenharmony_ci{ 2478c2ecf20Sopenharmony_ci u32 reg; 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci regmap_read(pd->regmap_ao, AO_RTI_GEN_PWR_SLEEP0, ®); 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci return (reg & GEN_PWR_VPU_HDMI); 2528c2ecf20Sopenharmony_ci} 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_cistatic struct meson_gx_pwrc_vpu vpu_hdmi_pd = { 2558c2ecf20Sopenharmony_ci .genpd = { 2568c2ecf20Sopenharmony_ci .name = "vpu_hdmi", 2578c2ecf20Sopenharmony_ci .power_off = meson_gx_pwrc_vpu_power_off, 2588c2ecf20Sopenharmony_ci .power_on = meson_gx_pwrc_vpu_power_on, 2598c2ecf20Sopenharmony_ci }, 2608c2ecf20Sopenharmony_ci}; 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_cistatic struct meson_gx_pwrc_vpu vpu_hdmi_pd_g12a = { 2638c2ecf20Sopenharmony_ci .genpd = { 2648c2ecf20Sopenharmony_ci .name = "vpu_hdmi", 2658c2ecf20Sopenharmony_ci .power_off = meson_g12a_pwrc_vpu_power_off, 2668c2ecf20Sopenharmony_ci .power_on = meson_g12a_pwrc_vpu_power_on, 2678c2ecf20Sopenharmony_ci }, 2688c2ecf20Sopenharmony_ci}; 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_cistatic int meson_gx_pwrc_vpu_probe(struct platform_device *pdev) 2718c2ecf20Sopenharmony_ci{ 2728c2ecf20Sopenharmony_ci const struct meson_gx_pwrc_vpu *vpu_pd_match; 2738c2ecf20Sopenharmony_ci struct regmap *regmap_ao, *regmap_hhi; 2748c2ecf20Sopenharmony_ci struct meson_gx_pwrc_vpu *vpu_pd; 2758c2ecf20Sopenharmony_ci struct reset_control *rstc; 2768c2ecf20Sopenharmony_ci struct clk *vpu_clk; 2778c2ecf20Sopenharmony_ci struct clk *vapb_clk; 2788c2ecf20Sopenharmony_ci bool powered_off; 2798c2ecf20Sopenharmony_ci int ret; 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci vpu_pd_match = of_device_get_match_data(&pdev->dev); 2828c2ecf20Sopenharmony_ci if (!vpu_pd_match) { 2838c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "failed to get match data\n"); 2848c2ecf20Sopenharmony_ci return -ENODEV; 2858c2ecf20Sopenharmony_ci } 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci vpu_pd = devm_kzalloc(&pdev->dev, sizeof(*vpu_pd), GFP_KERNEL); 2888c2ecf20Sopenharmony_ci if (!vpu_pd) 2898c2ecf20Sopenharmony_ci return -ENOMEM; 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci memcpy(vpu_pd, vpu_pd_match, sizeof(*vpu_pd)); 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci regmap_ao = syscon_node_to_regmap(of_get_parent(pdev->dev.of_node)); 2948c2ecf20Sopenharmony_ci if (IS_ERR(regmap_ao)) { 2958c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "failed to get regmap\n"); 2968c2ecf20Sopenharmony_ci return PTR_ERR(regmap_ao); 2978c2ecf20Sopenharmony_ci } 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci regmap_hhi = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, 3008c2ecf20Sopenharmony_ci "amlogic,hhi-sysctrl"); 3018c2ecf20Sopenharmony_ci if (IS_ERR(regmap_hhi)) { 3028c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "failed to get HHI regmap\n"); 3038c2ecf20Sopenharmony_ci return PTR_ERR(regmap_hhi); 3048c2ecf20Sopenharmony_ci } 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci rstc = devm_reset_control_array_get(&pdev->dev, false, false); 3078c2ecf20Sopenharmony_ci if (IS_ERR(rstc)) { 3088c2ecf20Sopenharmony_ci if (PTR_ERR(rstc) != -EPROBE_DEFER) 3098c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "failed to get reset lines\n"); 3108c2ecf20Sopenharmony_ci return PTR_ERR(rstc); 3118c2ecf20Sopenharmony_ci } 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci vpu_clk = devm_clk_get(&pdev->dev, "vpu"); 3148c2ecf20Sopenharmony_ci if (IS_ERR(vpu_clk)) { 3158c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "vpu clock request failed\n"); 3168c2ecf20Sopenharmony_ci return PTR_ERR(vpu_clk); 3178c2ecf20Sopenharmony_ci } 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci vapb_clk = devm_clk_get(&pdev->dev, "vapb"); 3208c2ecf20Sopenharmony_ci if (IS_ERR(vapb_clk)) { 3218c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "vapb clock request failed\n"); 3228c2ecf20Sopenharmony_ci return PTR_ERR(vapb_clk); 3238c2ecf20Sopenharmony_ci } 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci vpu_pd->regmap_ao = regmap_ao; 3268c2ecf20Sopenharmony_ci vpu_pd->regmap_hhi = regmap_hhi; 3278c2ecf20Sopenharmony_ci vpu_pd->rstc = rstc; 3288c2ecf20Sopenharmony_ci vpu_pd->vpu_clk = vpu_clk; 3298c2ecf20Sopenharmony_ci vpu_pd->vapb_clk = vapb_clk; 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, vpu_pd); 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci powered_off = meson_gx_pwrc_vpu_get_power(vpu_pd); 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci /* If already powered, sync the clock states */ 3368c2ecf20Sopenharmony_ci if (!powered_off) { 3378c2ecf20Sopenharmony_ci ret = meson_gx_pwrc_vpu_setup_clk(vpu_pd); 3388c2ecf20Sopenharmony_ci if (ret) 3398c2ecf20Sopenharmony_ci return ret; 3408c2ecf20Sopenharmony_ci } 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci vpu_pd->genpd.flags = GENPD_FLAG_ALWAYS_ON; 3438c2ecf20Sopenharmony_ci pm_genpd_init(&vpu_pd->genpd, NULL, powered_off); 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci return of_genpd_add_provider_simple(pdev->dev.of_node, 3468c2ecf20Sopenharmony_ci &vpu_pd->genpd); 3478c2ecf20Sopenharmony_ci} 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_cistatic void meson_gx_pwrc_vpu_shutdown(struct platform_device *pdev) 3508c2ecf20Sopenharmony_ci{ 3518c2ecf20Sopenharmony_ci struct meson_gx_pwrc_vpu *vpu_pd = platform_get_drvdata(pdev); 3528c2ecf20Sopenharmony_ci bool powered_off; 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci powered_off = meson_gx_pwrc_vpu_get_power(vpu_pd); 3558c2ecf20Sopenharmony_ci if (!powered_off) 3568c2ecf20Sopenharmony_ci vpu_pd->genpd.power_off(&vpu_pd->genpd); 3578c2ecf20Sopenharmony_ci} 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_cistatic const struct of_device_id meson_gx_pwrc_vpu_match_table[] = { 3608c2ecf20Sopenharmony_ci { .compatible = "amlogic,meson-gx-pwrc-vpu", .data = &vpu_hdmi_pd }, 3618c2ecf20Sopenharmony_ci { 3628c2ecf20Sopenharmony_ci .compatible = "amlogic,meson-g12a-pwrc-vpu", 3638c2ecf20Sopenharmony_ci .data = &vpu_hdmi_pd_g12a 3648c2ecf20Sopenharmony_ci }, 3658c2ecf20Sopenharmony_ci { /* sentinel */ } 3668c2ecf20Sopenharmony_ci}; 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_cistatic struct platform_driver meson_gx_pwrc_vpu_driver = { 3698c2ecf20Sopenharmony_ci .probe = meson_gx_pwrc_vpu_probe, 3708c2ecf20Sopenharmony_ci .shutdown = meson_gx_pwrc_vpu_shutdown, 3718c2ecf20Sopenharmony_ci .driver = { 3728c2ecf20Sopenharmony_ci .name = "meson_gx_pwrc_vpu", 3738c2ecf20Sopenharmony_ci .of_match_table = meson_gx_pwrc_vpu_match_table, 3748c2ecf20Sopenharmony_ci }, 3758c2ecf20Sopenharmony_ci}; 3768c2ecf20Sopenharmony_cibuiltin_platform_driver(meson_gx_pwrc_vpu_driver); 377