Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5094256rwl; Mon, 10 Apr 2023 23:51:35 -0700 (PDT) X-Google-Smtp-Source: AKy350Zl4k1AzeAAFuUGF/nah/Rz5M9gQ8gfStpzZHD64wOq0gfb2eP0o6+jTrR5aMu+iosh/1mj X-Received: by 2002:a17:906:6a0b:b0:931:b34:4172 with SMTP id qw11-20020a1709066a0b00b009310b344172mr11423405ejc.3.1681195895269; Mon, 10 Apr 2023 23:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681195895; cv=none; d=google.com; s=arc-20160816; b=ZuBHegNQ7kiHQ5E0xUhd8JY6QVTHtpYgNhyjW70d15hEB4GcDEhfZlFNeEgODT3OFZ x6PAm9OfjE+F7wp3fZDSqCtnD6ZKzWTkmNPgd/I2l8bslcUCXHgMuqrUO3+XafNO8VtQ 56ff4YNZ/AYJiSQ1tvKmLhoriTBttEcH7Fsf9fIqD6YQ0gt53lwBeuLztFuOs8nNRPcf 4sWTeDhHhVQTTA1A7AZiGQUWGB4aXA5X37jLK2tZLjNh71Jl5OUUrZpcYFwKGnGTUHNj C9iubPghn+MmQqtrkp7FzsGO2yEPWyY//3PEoxjKXmvmLYZ+Ku5RO9KM5Bk77Nzlr8gS iNfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UmNIX1X0FfFg0zyiDl3WusctbA2X7Ru3tHalHWljmSY=; b=rAJwW5iAdZeu6fyY7X2KRA6N+YeU7PlqAojHIFcvPdFyUwjZkCPumruMmxYSe9ySW4 9dxgkTMsTxz9J9PHGLTWSTo4lBeWFt4wl/epmNuBh7WgA+WyxWUCbX/gPLQSVlI7R5YI +evxpx6tI46ECaNVIxy09iwGO2QYvztrtEjoD1i3ZMNdxA/G2u5BOICZDz62cihJcFi9 2tAOOtukhD3EUc/9//pPPhKFEYM+stz2XklsTfc6IFcGKLrrFm/VrZjWj0hC/3Yh9wNJ IP38U0JkG6qAiWYzmeGMsIfmXWujqW6UfwFvvhI9Lst59Bp18D60SZsNSeN6jWMja9nH EAxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z18-20020a1709063ad200b00947bf51effbsi8896479ejd.580.2023.04.10.23.51.09; Mon, 10 Apr 2023 23:51:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230345AbjDKGsO convert rfc822-to-8bit (ORCPT + 99 others); Tue, 11 Apr 2023 02:48:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230235AbjDKGry (ORCPT ); Tue, 11 Apr 2023 02:47:54 -0400 Received: from fd01.gateway.ufhost.com (fd01.gateway.ufhost.com [61.152.239.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7043530E0; Mon, 10 Apr 2023 23:47:49 -0700 (PDT) Received: from EXMBX166.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX166", Issuer "EXMBX166" (not verified)) by fd01.gateway.ufhost.com (Postfix) with ESMTP id F336D24E2B9; Tue, 11 Apr 2023 14:47:47 +0800 (CST) Received: from EXMBX162.cuchost.com (172.16.6.72) by EXMBX166.cuchost.com (172.16.6.76) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Tue, 11 Apr 2023 14:47:48 +0800 Received: from ubuntu.localdomain (113.72.145.176) by EXMBX162.cuchost.com (172.16.6.72) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Tue, 11 Apr 2023 14:47:47 +0800 From: Changhuang Liang To: Rob Herring , Krzysztof Kozlowski , Emil Renner Berthing , Conor Dooley , Paul Walmsley , Palmer Dabbelt , Albert Ou CC: Walker Chen , Changhuang Liang , , , Subject: [PATCH v1 4/7] soc: starfive: Add pmu type operation Date: Mon, 10 Apr 2023 23:47:40 -0700 Message-ID: <20230411064743.273388-5-changhuang.liang@starfivetech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230411064743.273388-1-changhuang.liang@starfivetech.com> References: <20230411064743.273388-1-changhuang.liang@starfivetech.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [113.72.145.176] X-ClientProxiedBy: EXCAS064.cuchost.com (172.16.6.24) To EXMBX162.cuchost.com (172.16.6.72) X-YovoleRuleAgent: yovoleflag Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add pmu type, make a distinction between different PMU. Signed-off-by: Changhuang Liang --- drivers/soc/starfive/jh71xx_pmu.c | 55 ++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/drivers/soc/starfive/jh71xx_pmu.c b/drivers/soc/starfive/jh71xx_pmu.c index 306218c83691..98f6849d61de 100644 --- a/drivers/soc/starfive/jh71xx_pmu.c +++ b/drivers/soc/starfive/jh71xx_pmu.c @@ -45,6 +45,12 @@ */ #define JH71XX_PMU_TIMEOUT_US 100 +/* pmu type */ +enum pmu_type { + JH71XX_PMU_GENERAL, + JH71XX_PMU_DPHY, +}; + struct jh71xx_domain_info { const char * const name; unsigned int flags; @@ -54,6 +60,7 @@ struct jh71xx_domain_info { struct jh71xx_pmu_match_data { const struct jh71xx_domain_info *domain_info; int num_domains; + u8 pmu_type; }; struct jh71xx_pmu { @@ -75,19 +82,23 @@ struct jh71xx_pmu_dev { static int jh71xx_pmu_get_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool *is_on) { struct jh71xx_pmu *pmu = pmd->pmu; + unsigned int offset = 0; unsigned int val; if (!mask) return -EINVAL; - regmap_read(pmu->base, JH71XX_PMU_CURR_POWER_MODE, &val); + if (pmu->match_data->pmu_type == JH71XX_PMU_GENERAL) + offset = JH71XX_PMU_CURR_POWER_MODE; + + regmap_read(pmu->base, offset, &val); *is_on = val & mask; return 0; } -static int jh71xx_pmu_set_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool on) +static int jh71xx_pmu_general_set_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool on) { struct jh71xx_pmu *pmu = pmd->pmu; unsigned long flags; @@ -95,22 +106,8 @@ static int jh71xx_pmu_set_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool on) u32 mode; u32 encourage_lo; u32 encourage_hi; - bool is_on; int ret; - ret = jh71xx_pmu_get_state(pmd, mask, &is_on); - if (ret) { - dev_dbg(pmu->dev, "unable to get current state for %s\n", - pmd->genpd.name); - return ret; - } - - if (is_on == on) { - dev_dbg(pmu->dev, "pm domain [%s] is already %sable status.\n", - pmd->genpd.name, on ? "en" : "dis"); - return 0; - } - spin_lock_irqsave(&pmu->lock, flags); /* @@ -169,6 +166,31 @@ static int jh71xx_pmu_set_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool on) return 0; } +static int jh71xx_pmu_set_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool on) +{ + struct jh71xx_pmu *pmu = pmd->pmu; + bool is_on; + int ret = 0; + + ret = jh71xx_pmu_get_state(pmd, mask, &is_on); + if (ret) { + dev_dbg(pmu->dev, "unable to get current state for %s\n", + pmd->genpd.name); + return ret; + } + + if (is_on == on) { + dev_dbg(pmu->dev, "pm domain [%s] is already %sable status.\n", + pmd->genpd.name, on ? "en" : "dis"); + return 0; + } + + if (pmu->match_data->pmu_type == JH71XX_PMU_GENERAL) + ret = jh71xx_pmu_general_set_state(pmd, mask, on); + + return ret; +} + static int jh71xx_pmu_on(struct generic_pm_domain *genpd) { struct jh71xx_pmu_dev *pmd = container_of(genpd, @@ -360,6 +382,7 @@ static const struct jh71xx_domain_info jh7110_power_domains[] = { static const struct jh71xx_pmu_match_data jh7110_pmu = { .num_domains = ARRAY_SIZE(jh7110_power_domains), .domain_info = jh7110_power_domains, + .pmu_type = JH71XX_PMU_GENERAL, }; static const struct of_device_id jh71xx_pmu_of_match[] = { -- 2.25.1