From patchwork Tue Feb 20 12:59:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 13564001 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15C5E6A037 for ; Tue, 20 Feb 2024 12:59:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708433985; cv=none; b=SNZ8GGhQPxQ3MKsMqqMGt+kDuRsQOCkxpE3z6OSgZfZHRDv6uKnwp0iuQGO6N1wvmjb0fgsj9WAmM+uW5AAJTcl9Ny3QZ++rmkRppuRCNNa/IOoJeIzMbjDV7WmHdfzN7ow0rlKcak4YPx/45Y4UMtyj6fMZ6s3Y7apk4GWBZHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708433985; c=relaxed/simple; bh=eoBqasf2Lf4kUVh5GoF8UMFjxTzmG4XIhpcZ+yy2rOQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VvROI5/dFDHYMcXUzhDuwKXjcwvwRoHh+9HWjsl8VB3S6vWDvWB6XpA0zahslMSnpHtsEDDJPdHqcIhHAf30Ss/99P3RlOZTtIWfvmQoctQHHHcJP220SN45AGHr16TH8SdXJ2M1nMsKn0O88EcEUyQ4MgaRZa7tacpXmyLrUHQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ErXJ9GPd; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ErXJ9GPd" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-563fe793e1cso5194114a12.3 for ; Tue, 20 Feb 2024 04:59:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708433981; x=1709038781; darn=vger.kernel.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=MJU+qiLfShMKFnClWJ+LsA155QSh6V5eijJEbScCWrE=; b=ErXJ9GPdY2vCmdZZR65DgGzv4xGBcCIw41YwESt5pfLLNVT04z6FHsgse8/sMPZ20q uhEz9+GG9P5bqBhhbIesflY3YGaFlEiUv8R14d6FKuXCnXB89V1bSs3HCMvrGhjxjq0k E/4CqZUU03qqxl/B1vhiek1mDhKTtrFY63mFinobwCUTNfnHneK1eWXVspSfcRy+VDhj w3rNU8X4vAdyCb4aECTJLnGOlHMjv/qK6tSUDGIlTQng9tiWvk2TmeB7uvHEXiVNMfjj gTSg9NADViJSwuP6JQ7hzHavlRlHeYro2ogM0xWXOpO74ti+Cymzx7nAq2wrm+KtFXie w/xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708433981; x=1709038781; 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=MJU+qiLfShMKFnClWJ+LsA155QSh6V5eijJEbScCWrE=; b=YHyrzfeqSSbLBGJZ2MmTxiZT0aV6W0ERPPJI8LpmacAxi3FcgajRRMS+P2aL+IAgjP 94nN5RDEgk4qRtXPh79gBN0FVYREeeakwf4wJDczpxdhNqWVUnZov4yXpgGdMGOIEBCw E7/uUuU0vEdA6rHeajfXH8CEBxIWNL0ka1wrARcZwOWN2A0Q5BuAiSKybECCzjvlFwcO zDfCSp4cXvWtsMP5jhDUnVBojPg5NqJjDbyC9upNCkX/duqzSiBu6cC6T5RTp/xXU2JR FGzC/GvkyvMSoqNTZIhvyU2st4JXCHLU30wgx/08NP1LOrRHp7qSWTiYROplyZj65dfv MSaw== X-Forwarded-Encrypted: i=1; AJvYcCUQDZuI+2YhpxE5qb7O6BhelKWZAnKZzK0FaxmdU7tv+/Q3t7jfoMWEELgXuMawCEABlWVNS27PYIjcWzcYXjQR9Bd/7yqSxAUBpqpHGA== X-Gm-Message-State: AOJu0Yyx7TQpKLOtBWjyu6wnvuSIh1wQ1VuyMAQW3uUGL669fPreiIog FYU/7fbI2Z8ZxJw3xRPhwZF7T17bwrSX572F7g3hoodWeEZgP2Im5gvsT09QDMY= X-Google-Smtp-Source: AGHT+IFTU8HAkI+y8TBkvHijTzj0OheeS453Vyx4i6YSIs28n7KxAwTO8JZie2ZimftOVibbFLy0Iw== X-Received: by 2002:a17:906:ae9b:b0:a3e:e84b:232 with SMTP id md27-20020a170906ae9b00b00a3ee84b0232mr1571112ejb.75.1708433981473; Tue, 20 Feb 2024 04:59:41 -0800 (PST) Received: from [127.0.1.1] ([188.24.162.93]) by smtp.gmail.com with ESMTPSA id rf23-20020a1709076a1700b00a3ce36ce4f9sm3948802ejc.83.2024.02.20.04.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 04:59:41 -0800 (PST) From: Abel Vesa Date: Tue, 20 Feb 2024 14:59:23 +0200 Subject: [PATCH RFC v4 3/4] spmi: pmic-arb: Make core resources acquiring a version operation Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240220-spmi-multi-master-support-v4-3-dc813c878ba8@linaro.org> References: <20240220-spmi-multi-master-support-v4-0-dc813c878ba8@linaro.org> In-Reply-To: <20240220-spmi-multi-master-support-v4-0-dc813c878ba8@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=7622; i=abel.vesa@linaro.org; h=from:subject:message-id; bh=eoBqasf2Lf4kUVh5GoF8UMFjxTzmG4XIhpcZ+yy2rOQ=; b=owEBbQKS/ZANAwAKARtfRMkAlRVWAcsmYgBl1KI1j15AdL3iObZKp8qMphgZYSKDsh31QNQGz 5Y2y/XmNEeJAjMEAAEKAB0WIQRO8+4RTnqPKsqn0bgbX0TJAJUVVgUCZdSiNQAKCRAbX0TJAJUV VqvlEACaWqBY3l0w5nJxEJWtUZlGVcc8i5vgbq9Ncmz8w4q5pUhhuIS/3b6W5hGZ4TL+tP/mg2q 6S789JPyXknh5/qovzv+uz+pOjxrRzEFKYRvTZDhzs1YXYbWEQKVI5OyxQ+bh7Rt957cYOkoqYG mHCndlJn19SfnHO936OBxfRdgBFtaScKy/AUdjcojLUPzkYpPORLiGf3/MEEk3MAtXj4IrTmosw da2mW5zL6nLvt7G2aLO/bKJgy273QHrx9fel3AsS2cuQ7KxNsg8ZLdFOiWiT1RyqGOK7XlxpKw1 qq1bYsd3lrRUhu4X0mIcv/cwwoPWNaWJyrhzFhy5NjIaYORHfPG/gR0m/HSwNmA+tuCCt+HlmFf dSOw1R1dzYWb/6+OwpjxrhRfGh1xSnAUzGegb6OPgxYI+LiBbtr6Xb8/t7L+m9nv/Iemz4lw3di WKxSiYOMUgty84gLbjOr2Jpz0lklzSiqLo0YByvdh0J8rX0p1fUKnw+aDfZXK6e6yil0IHi2IN2 WGQRW9ylhdxQLg9ucGvOZ9LvJX7FVXYDLN84atY5i0CRzjitKvtpnBIu63ciXDKB/Tvi5MPC5uk KPXcaABYYhJ5/jtiRnv+Pd6oWfBYsiMViXaMlgsKwduSOE9KZ1rofsPy2R8Mrxel98nAZ8P0A2z sb6iQ/31pk0uj/g== X-Developer-Key: i=abel.vesa@linaro.org; a=openpgp; fpr=6AFF162D57F4223A8770EF5AF7BF214136F41FAE 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 | 115 +++++++++++++++++++++++++++---------------- 1 file changed, 72 insertions(+), 43 deletions(-) diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 38fed8a585fe..5aad188a3db2 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,35 @@ 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); + struct device *dev = &pdev->dev; + struct resource *res; + + 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 +1289,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 +1524,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 +1540,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 +1556,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 +1572,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 +1588,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 +1625,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 +1634,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)