From patchwork Thu Feb 22 13:52:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 13567374 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6A062C48BF8 for ; Thu, 22 Feb 2024 13:53:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tLaf48zgVhHhAvvAHj5cThfOn70wjM56AcyAUPEtzJA=; b=MzZdu/iBJ0oCRT 5m6UReSTFzaytA3f+vVW61hiJ9tkGGigFNXIwLKjlA493mVZyY4k9ddexs1iPRoZMZdPwdZxfvJNd 7/VcyqthMb9JCIo69ChXGPz1xYXIggLdmkrT4BGPn4khzJijCIv79C/F1f56flFjcDbN39KBU3mm6 ouiKbdNDN1IiKt5EW1+CQC2hyYK14NHB/W2SJPtwHhDUpJSVr7yY2YkiMDik5J33hN+tciu3YMN8J bEwt32kTOOBEWwhUY7bGXjrIIA+LfwQm245HvGEkNNdMfJL+Nuipg2dUUeWO8ACjgnDQXHHK6fXYu 4hK32B3j3OHbW727flIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd9Vd-000000057HU-0W83; Thu, 22 Feb 2024 13:53:09 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd9Uy-000000056t0-1CSn for linux-arm-kernel@lists.infradead.org; Thu, 22 Feb 2024 13:52:29 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-564fc495d83so2342724a12.0 for ; Thu, 22 Feb 2024 05:52:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708609946; x=1709214746; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=nJWCFRrkjZXs2WI32Il+ppCE1cfB8jGTI/OTy71gmgo=; b=Rr0NU+tNVjAaD3cUbH6dI/of9M2K9CoMctxttXQaHQcwBq/X6Ws2ESOg40g1tJ5+1x RaQtK6J8Xjjn2Ox29Qdt/f7WuKeKC+l5qIJX5qFtwOfYyAM5Kn6ErCiyPgDk75aIreZt eIVo8hXjH7JWgmfifiopG1qCxuX3tJkNnvhMC1vGL1RrNmZA6r/zvt3dtKSMxVSZYpHR 09EfH7HX2uOy2yXKyya1shqSKNKhgznV+dl41OpAshjpPRJLPPm9Sr48A/OgEDOjIkvD 7ZQUWzdU3ya2zqJiUCmI3CIvXKdkXUhP5Zxs9E5HRnHsou6taoD0pp0IjyhdsFthakOA kYgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708609946; x=1709214746; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nJWCFRrkjZXs2WI32Il+ppCE1cfB8jGTI/OTy71gmgo=; b=vXEQQQVlykaBpyjh70afBCtXmbNjDhWXlZ9Gwd/WpMBOH9mAynyu5R0ej+K0nHKNYl 8H48+oC72CoyHprie8k0LXLZc9buYwdzbhWwYUA9bCfkhsaww9INYnA8a3i2lXgb9JlV VeDOSfj/bRoAUlyne3g2ZSNmqqmKV5C+3LNKeUwOw4PDhyzjKKx9V/oJ46FN5mJqKcwN F6PYo54bBZXyy7FfV5P3ixT5mLgu7VsRDDo2AXUwlvpTDtJIa64t7bRjl3RYf3zaXlEy EEe4U8kCUZfJH07FxqhxIE7CaBhN4OsMhRweulXKZapVSjrD9ZY9xmLhaeCFWaf9qmWT uF9g== X-Forwarded-Encrypted: i=1; AJvYcCU7sNdqtuGjMgYWAMnnTOurwYTEfTNZuXfVqB3BZ0/tc1zC4blwo6N4XfN/IBk5WePsraanlWkjVInDBriD2F3UofUNWBQG/ZHu2WH3LXdqWrH7uoA= X-Gm-Message-State: AOJu0Ywpm8D84Pg8HPzWh4zuB+wCj05XoOyyrlwowDjwbmQPwaD3IJtU /R5r3exknPRmqyR11Q8SxI+uXNl9/oLF3C4QlPGrb+VEYjsYpmhTNdLnJtcM6zM= X-Google-Smtp-Source: AGHT+IHlxVdalqDdwsr7gEFKPVEArdpqD5xUhEGnoCsJUb54y4Y4j6X2yKXQUwijk6hYxJlFpUN72Q== X-Received: by 2002:a17:906:f202:b0:a3d:bb58:bb2e with SMTP id gt2-20020a170906f20200b00a3dbb58bb2emr14185494ejb.36.1708609946492; Thu, 22 Feb 2024 05:52:26 -0800 (PST) Received: from [127.0.1.1] ([188.24.162.93]) by smtp.gmail.com with ESMTPSA id ot18-20020a170906ccd200b00a3ecdd0ba23sm3382839ejb.52.2024.02.22.05.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:52:25 -0800 (PST) From: Abel Vesa Date: Thu, 22 Feb 2024 15:52:05 +0200 Subject: [PATCH v6 4/5] spmi: pmic-arb: Make core resources acquiring a version operation MIME-Version: 1.0 Message-Id: <20240222-spmi-multi-master-support-v6-4-bc34ea9561da@linaro.org> References: <20240222-spmi-multi-master-support-v6-0-bc34ea9561da@linaro.org> In-Reply-To: <20240222-spmi-multi-master-support-v6-0-bc34ea9561da@linaro.org> To: Stephen Boyd , Matthias Brugger , Bjorn Andersson , Konrad Dybcio , Dmitry Baryshkov , Neil Armstrong , AngeloGioacchino Del Regno , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Srini Kandagatla , Johan Hovold , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, devicetree@vger.kernel.org, Abel Vesa X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=7561; i=abel.vesa@linaro.org; h=from:subject:message-id; bh=BMjyfCYiK4XOXFgvoI4oZtTuPAW/B6RJ1erAWAohJjQ=; b=owEBbQKS/ZANAwAKARtfRMkAlRVWAcsmYgBl11GQsJAq5JoYUjP3457dL3Hvlcy1pHbroVd8Q SlrTDzLh3eJAjMEAAEKAB0WIQRO8+4RTnqPKsqn0bgbX0TJAJUVVgUCZddRkAAKCRAbX0TJAJUV VvN/D/9Yc0KHBpeVd0FHImWcxrvFjxhdCuMnuXhtNPxNZcPG9ZHdCBdzQ24eTUbOosEX2ASbLbE SYs8+35QNAt/BxsrtYrRYklIkW4B5ckSfOIaRV2Z19+W3rNTzn17xgwHdqnCdVZX28Fn6G1IJ4Y znk0wFmZ1F3X4zj05ohtZxoAsbICREXkHryKu1a0pUtJe7ZKuB/OfNYgDPUL7EHk+fb27UKw1TX OGOH7VyWaCofl6y+Bn73lvt1zCD3tO4r2MPeaPGx8chmQvVIjyLzUX9/BTQllk5dCbZ0+FLEYMH 2Xp4op3f9LbLuY75PfwC7GsvRGxz+w1EA4zWYPynpFyDb+w56pM5HZjvZROap7IeOLIqnYe14xp 2yaIIb9jT3SVac3IZF2EG9jLyWQEJ5ugDtHjWoyQcLvhuxyftv7R460np5249zzL6JVm7T6tQfk OgdwP6/QPf0M5NFGV1ktJrRb+h5YzFKaLRCZs3MAhe7YKTR6xB93ZEiuvJT0OS1SJ6C0gNECMKR 056b2rNLh3frCiBN8YdZs5BWZENNInoACuS5gekRycebETvwyuZ+Twfe6Ng+DGRJ9YObZaLZ5WI jTPxFmjDL66DEBHLqpSoSAJ4y7GiblWEHDoD5fHPFRAZ6v2frmDtAyT5nfk4SfvGTiTxXu5saBE IEI2iXNgzTETE6A== X-Developer-Key: i=abel.vesa@linaro.org; a=openpgp; fpr=6AFF162D57F4223A8770EF5AF7BF214136F41FAE X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240222_055228_467307_2C5FEA7E X-CRM114-Status: GOOD ( 18.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rather than setting up the core, obsrv and chnls in probe by using version specific conditionals, add a dedicated "get_core_resources" version specific op and move the acquiring in there. Signed-off-by: Abel Vesa --- drivers/spmi/spmi-pmic-arb.c | 113 +++++++++++++++++++++++++++---------------- 1 file changed, 70 insertions(+), 43 deletions(-) diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 38fed8a585fe..188252bfb95f 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -203,6 +203,7 @@ struct spmi_pmic_arb { */ struct pmic_arb_ver_ops { const char *ver_str; + int (*get_core_resources)(struct platform_device *pdev, void __iomem *core); int (*init_apid)(struct spmi_pmic_arb *pmic_arb, int index); int (*ppid_to_apid)(struct spmi_pmic_arb *pmic_arb, u16 ppid); /* spmi commands (read_cmd, write_cmd, cmd) functionality */ @@ -956,6 +957,19 @@ static int pmic_arb_init_apid_min_max(struct spmi_pmic_arb *pmic_arb) return 0; } +static int pmic_arb_get_core_resources_v1(struct platform_device *pdev, + void __iomem *core) +{ + struct spmi_pmic_arb *pmic_arb = platform_get_drvdata(pdev); + + pmic_arb->wr_base = core; + pmic_arb->rd_base = core; + + pmic_arb->max_periphs = PMIC_ARB_MAX_PERIPHS; + + return 0; +} + static int pmic_arb_init_apid_v1(struct spmi_pmic_arb *pmic_arb, int index) { u32 *mapping_table; @@ -1063,6 +1077,33 @@ static u16 pmic_arb_find_apid(struct spmi_pmic_arb *pmic_arb, u16 ppid) return apid; } +static int pmic_arb_get_obsrvr_chnls_v2(struct platform_device *pdev) +{ + struct spmi_pmic_arb *pmic_arb = platform_get_drvdata(pdev); + + pmic_arb->rd_base = devm_platform_ioremap_resource_byname(pdev, "obsrvr"); + if (IS_ERR(pmic_arb->rd_base)) + return PTR_ERR(pmic_arb->rd_base); + + pmic_arb->wr_base = devm_platform_ioremap_resource_byname(pdev, "chnls"); + if (IS_ERR(pmic_arb->wr_base)) + return PTR_ERR(pmic_arb->wr_base); + + return 0; +} + +static int pmic_arb_get_core_resources_v2(struct platform_device *pdev, + void __iomem *core) +{ + struct spmi_pmic_arb *pmic_arb = platform_get_drvdata(pdev); + + pmic_arb->core = core; + + pmic_arb->max_periphs = PMIC_ARB_MAX_PERIPHS; + + return pmic_arb_get_obsrvr_chnls_v2(pdev); +} + static int pmic_arb_ppid_to_apid_v2(struct spmi_pmic_arb *pmic_arb, u16 ppid) { u16 apid_valid; @@ -1246,6 +1287,18 @@ static int pmic_arb_offset_v5(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr, return offset; } +static int pmic_arb_get_core_resources_v7(struct platform_device *pdev, + void __iomem *core) +{ + struct spmi_pmic_arb *pmic_arb = platform_get_drvdata(pdev); + + pmic_arb->core = core; + + pmic_arb->max_periphs = PMIC_ARB_MAX_PERIPHS_V7; + + return pmic_arb_get_obsrvr_chnls_v2(pdev); +} + /* * Only v7 supports 2 buses. Each bus will get a different apid count, read * from different registers. @@ -1469,6 +1522,7 @@ pmic_arb_apid_owner_v7(struct spmi_pmic_arb *pmic_arb, u16 n) static const struct pmic_arb_ver_ops pmic_arb_v1 = { .ver_str = "v1", + .get_core_resources = pmic_arb_get_core_resources_v1, .init_apid = pmic_arb_init_apid_v1, .ppid_to_apid = pmic_arb_ppid_to_apid_v1, .non_data_cmd = pmic_arb_non_data_cmd_v1, @@ -1484,6 +1538,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v1 = { static const struct pmic_arb_ver_ops pmic_arb_v2 = { .ver_str = "v2", + .get_core_resources = pmic_arb_get_core_resources_v2, .init_apid = pmic_arb_init_apid_v1, .ppid_to_apid = pmic_arb_ppid_to_apid_v2, .non_data_cmd = pmic_arb_non_data_cmd_v2, @@ -1499,6 +1554,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v2 = { static const struct pmic_arb_ver_ops pmic_arb_v3 = { .ver_str = "v3", + .get_core_resources = pmic_arb_get_core_resources_v2, .init_apid = pmic_arb_init_apid_v1, .ppid_to_apid = pmic_arb_ppid_to_apid_v2, .non_data_cmd = pmic_arb_non_data_cmd_v2, @@ -1514,6 +1570,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v3 = { static const struct pmic_arb_ver_ops pmic_arb_v5 = { .ver_str = "v5", + .get_core_resources = pmic_arb_get_core_resources_v2, .init_apid = pmic_arb_init_apid_v5, .ppid_to_apid = pmic_arb_ppid_to_apid_v5, .non_data_cmd = pmic_arb_non_data_cmd_v2, @@ -1529,6 +1586,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v5 = { static const struct pmic_arb_ver_ops pmic_arb_v7 = { .ver_str = "v7", + .get_core_resources = pmic_arb_get_core_resources_v7, .init_apid = pmic_arb_init_apid_v7, .ppid_to_apid = pmic_arb_ppid_to_apid_v5, .non_data_cmd = pmic_arb_non_data_cmd_v2, @@ -1565,16 +1623,6 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) pmic_arb = spmi_controller_get_drvdata(ctrl); pmic_arb->spmic = ctrl; - /* - * Please don't replace this with devm_platform_ioremap_resource() or - * devm_ioremap_resource(). These both result in a call to - * devm_request_mem_region() which prevents multiple mappings of this - * register address range. SoCs with PMIC arbiter v7 may define two - * arbiter devices, for the two physical SPMI interfaces, which share - * some register address ranges (i.e. "core", "obsrvr", and "chnls"). - * Ensure that both devices probe successfully by calling devm_ioremap() - * which does not result in a devm_request_mem_region() call. - */ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); core = devm_ioremap(&ctrl->dev, res->start, resource_size(res)); if (IS_ERR(core)) @@ -1584,44 +1632,23 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) hw_ver = readl_relaxed(core + PMIC_ARB_VERSION); - if (hw_ver < PMIC_ARB_VERSION_V2_MIN) { + if (hw_ver < PMIC_ARB_VERSION_V2_MIN) pmic_arb->ver_ops = &pmic_arb_v1; - pmic_arb->wr_base = core; - pmic_arb->rd_base = core; - } else { - pmic_arb->core = core; - - if (hw_ver < PMIC_ARB_VERSION_V3_MIN) - pmic_arb->ver_ops = &pmic_arb_v2; - else if (hw_ver < PMIC_ARB_VERSION_V5_MIN) - pmic_arb->ver_ops = &pmic_arb_v3; - else if (hw_ver < PMIC_ARB_VERSION_V7_MIN) - pmic_arb->ver_ops = &pmic_arb_v5; - else - pmic_arb->ver_ops = &pmic_arb_v7; - - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, - "obsrvr"); - pmic_arb->rd_base = devm_ioremap(&ctrl->dev, res->start, - resource_size(res)); - if (IS_ERR(pmic_arb->rd_base)) - return PTR_ERR(pmic_arb->rd_base); - - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, - "chnls"); - pmic_arb->wr_base = devm_ioremap(&ctrl->dev, res->start, - resource_size(res)); - if (IS_ERR(pmic_arb->wr_base)) - return PTR_ERR(pmic_arb->wr_base); - } + else if (hw_ver < PMIC_ARB_VERSION_V3_MIN) + pmic_arb->ver_ops = &pmic_arb_v2; + else if (hw_ver < PMIC_ARB_VERSION_V5_MIN) + pmic_arb->ver_ops = &pmic_arb_v3; + else if (hw_ver < PMIC_ARB_VERSION_V7_MIN) + pmic_arb->ver_ops = &pmic_arb_v5; + else + pmic_arb->ver_ops = &pmic_arb_v7; dev_info(&ctrl->dev, "PMIC arbiter version %s (0x%x)\n", pmic_arb->ver_ops->ver_str, hw_ver); - if (hw_ver < PMIC_ARB_VERSION_V7_MIN) - pmic_arb->max_periphs = PMIC_ARB_MAX_PERIPHS; - else - pmic_arb->max_periphs = PMIC_ARB_MAX_PERIPHS_V7; + err = pmic_arb->ver_ops->get_core_resources(pdev, core); + if (err) + return err; err = pmic_arb->ver_ops->init_apid(pmic_arb, 0); if (err)