From patchwork Wed Feb 21 12:52:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 775287 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 933BA69D2B for ; Wed, 21 Feb 2024 12:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708519977; cv=none; b=ppMv0mzXSiDOlD9R6voKwqgLu1Uexe9c9LhRjXAXCoENdtfq2uswCcnZv46+FSDo5gRp0W9EEnhe1D4ea5tvJ2YgZcgruo11YX1tFOHnzX8asqe2vEPQeTRLqFZ4bAHJs3ThxAVPBcpu+iBYJETJshwYW4wbjXijbWkMV1SlZb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708519977; c=relaxed/simple; bh=BMjyfCYiK4XOXFgvoI4oZtTuPAW/B6RJ1erAWAohJjQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=REm7B9cnE9lk+EieKV7IExnFlwVytx+uNKvf6VT9cTh7yCUUp+K1g/tgwxcXxUY4asTo5axKYpR7vNBczsjWxxYH9gI4u1RqosL2avWny1Xg0ckSXuITJ9UZQrZ8RZHr5ju7O78p+zQs0vaZw0f7dyJl4bH5b1V4cv00jgWI2jM= 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=HrXba5/y; arc=none smtp.client-ip=209.85.218.41 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="HrXba5/y" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a3e4765c86eso494003566b.0 for ; Wed, 21 Feb 2024 04:52:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708519974; x=1709124774; 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=nJWCFRrkjZXs2WI32Il+ppCE1cfB8jGTI/OTy71gmgo=; b=HrXba5/yWj9jyQhkp6DkIOWvI0SAHKJIIdRy3etH3BenZhDjRce1xjiU9++E3RHpr2 tNmvUgnwi7Vw0XI8D+m2C6Mb2r77X8mtHOcyriG+u93Fg7wFnFiLOkEozI+YjM28DR/V +wrijtAW6GPliB6HppLQgxZ0vQhJnT+rzH91ZUHjX8PXGIi/YQRWcyzcSJqyLRBK+qMv qCBY/vBG9/bXraXoJLGXIIiR3th88h/TNdqLxp0GpKmG8wFWIW1/hIGiCXgP0w3HG9S7 eS3mubclmZ5rbPIzkxKnXa/WHPU9AQ5bIWThGwnFqNFPV8CCG9sUP+SclxVZPBBwM2Ps Er0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708519974; x=1709124774; 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=SAj0V7ky3lOV+fNANAfFE3dxt8bMVrSJzXGx0RbLlRje2l37aPVTeDaiESjWXiBbnI tWez5aTm3EntunXHrC/ecV7z/kZF+vROGxFs8YjRKvMMJsBXFazQvXdrf7V3D51AtzNH YTpKL+lA95ydOaYWgcA38omLhMseZ0vXQSYpnz6o4+MqKBfT18qXBkv7M2AlOvZ9fyyZ COrn+0rTPiGdmCM91TVBZ8NUPOU08u3B4yY3AJAAfxZurVmmFHJaU2XWwjPGoGoZ86CX yNy2+RM4G1r2pxzo89BBZ56WsB18+YLEI2O5OYKPz1OIyCwvmkWtJdPk5meYx2cN3VTm umDw== X-Forwarded-Encrypted: i=1; AJvYcCWJTbi0NMdw51VDSCePD1KGcboO/Fdde7piJBEwFUyFjh9prwQKMzLwOUrpUKVB8yhBsCTdbf1Uzv1gqYASwwnGBInE6CLmmSsNVo2I+Q== X-Gm-Message-State: AOJu0Ywvcd78lifIsFIoFyRrK8yO1aTx7Og/gHPSaz1CAHxr2Awpz7E6 e8MEDgjx1cnjgxfQSdK4z54RqX6YHY8ijAkoL3VeHoznnFcg629tecMzK/6VLzUrMqdmvV3zZDe P X-Google-Smtp-Source: AGHT+IGWuiYDZQnZv7k8NSx8kDgKiR98jgkc7kQV7Q8X179RvlTIMFh8AgiFrXJ9C6SQs9Gz+Rrqhg== X-Received: by 2002:a17:906:2b53:b0:a3e:5adb:cb21 with SMTP id b19-20020a1709062b5300b00a3e5adbcb21mr6741071ejg.59.1708519973858; Wed, 21 Feb 2024 04:52:53 -0800 (PST) Received: from [127.0.1.1] ([188.24.162.93]) by smtp.gmail.com with ESMTPSA id tl23-20020a170907c31700b00a3da5bf34absm4930392ejc.207.2024.02.21.04.52.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 04:52:53 -0800 (PST) From: Abel Vesa Date: Wed, 21 Feb 2024 14:52:39 +0200 Subject: [PATCH v5 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: <20240221-spmi-multi-master-support-v5-3-3255ca413a0b@linaro.org> References: <20240221-spmi-multi-master-support-v5-0-3255ca413a0b@linaro.org> In-Reply-To: <20240221-spmi-multi-master-support-v5-0-3255ca413a0b@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/ZANAwAKARtfRMkAlRVWAcsmYgBl1fIdHibzQ+Jjjc8jNSuux/G34CPe3rNbfTzQp 8ARjlhyG8aJAjMEAAEKAB0WIQRO8+4RTnqPKsqn0bgbX0TJAJUVVgUCZdXyHQAKCRAbX0TJAJUV VtwQD/4oWs1npr+DBf9g/6zf37WLcDJhiyvwCiiaAc4Aztq0x89Kzd2KTGQYX2Ihglv55KDkS06 4eiymg3It4dCXcyRb+O6+RkIh58/dCqtY/ev1MaWrpoJhH0Iypl0hnLFMjsFwYZfgbHwHIRj7iD Lgiy2MZGx3JcLaZCzk6BoToZ+JiUTA7vsJ7cJ1ZaiRfz7XOxkSx+EC+58TAJb06cNOgRzv3jv3y vzkYPppTvw2/xzKcBugQG4IhZpKZKpe5pc6h4xB5F6bkeiCO6uaGjDaL3BTPq+MfxTUppXtouOH dFEH978wIgwayq2aqKLbIRrXTrbdHm6JVsbm25HfOCKi5PDpCvWQNDHGDgfPTmsrWHGp6jadkPE XVAVkvG3Xw8vik2OP2iyi/Wa8NTrgwWz5MVRiggmvmb73l3C+42ECW6ZYAqlEx6VBnRAwRF0qE0 AJmAjgovZ3oiPd/6zxz4fpMJl+qsgysoFcJikhGEYdEw2X+FD5DYo30s8ue+38tqPFcZXIuxUBL d7MDKE739S8ITwvwHSYCC/6mkpXWKBEB5WWxntpApugJLbIooyULFGFvXo8irewPysDJBFzOzTE tdbErOIrmrTyPUYN4etaaWdtQQ8jOAeSPL5Yq1eg61EMNTwxmNv3FFID2YpsWsSKiLLTKQl2gVx 7oaSEDIWQL3ByQQ== 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 | 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)