From patchwork Sun Apr 7 16:23:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 13620238 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 DA12FCD128A for ; Sun, 7 Apr 2024 16:24: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=Oa7qocGOQtR2tSW7kU/kgsAFxvtcEgoE0Z5BBd99eY4=; b=iY+iW2TlJhdfOx hilhTePX4p7VUOr/ebjOM3lG5iW8FAI9tJQpf18ZJQCogiLWiXZYp/m/g0Mx0S012eF/sBuKrGEAM gHG0WMAJ7DEo3kaoivxZVt4W1a/mAacpklizTJMMrHHYkal1KbPmvv1zs++MwMZyjl60XZZmX+nfG fjNeIrc+XiwQEGew+9MtviloNB9jya+2iJGuKLovb4vwnx8j9wQl9YuvrkFHMbMM68tL58xN5dtQn 9IMdgbPO+uWw1HiN0qmexV0AxMfnx90sch4b6vMuuF/pfQgo1uffC8VYPKRQa2Em7+nbKZj/ixVk7 0i/yxTw/grDpNzbHT0sA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rtVJS-0000000CzdO-2yUd; Sun, 07 Apr 2024 16:24:10 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rtVJ8-0000000CzMS-02HH for linux-arm-kernel@lists.infradead.org; Sun, 07 Apr 2024 16:23:54 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-566e869f631so3656334a12.0 for ; Sun, 07 Apr 2024 09:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712507027; x=1713111827; 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=Z7Pnr6PoGhceBp/MkaACIjm9COgBNW2tpmbpLJHir3Y=; b=sXTC0hFtdmd2LaeChjqFQGLED+oZDswLfdlGLn0Jzc4OR5+PtmWHSFMbLAuK4gu8b9 AWq+zgf8Za3uxnCvMNcW+Ouf9WLA9X5kk9OZms9GwDevw+eNNcXBmklYei8bBPKXbp1q XwY2IIXt8mnyXAdpjHn+s99qy71fVMz5khpUtdkloFXO+0SDY409cPcU14EHqDZhWIdH tuBWCU5dG4SEZNLGtellXWFXrywPJG9sI9a9uIH6JCFc1SDsX5Q/jI07Z6Y2zUyew4Qq fABIpg+XLtMAaiU3rNi/Ty8V0tGudZWKcsPbssqA+AiZcdFVCaaOSuaG4iOSwXoS+2Vf QB7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712507027; x=1713111827; 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=Z7Pnr6PoGhceBp/MkaACIjm9COgBNW2tpmbpLJHir3Y=; b=aiJ4TlwTnfQubF4gfi6mvdWPF1PXWDx/e1ETp2y5F3c+gf/sHOyGpRndVwUF2vv6Z8 nQ3Dr6FR7l7WACGVt1iNvK4JksFeO6AXgQVnfSHoTw0xL5QHvVSzGWdSLHmDeRqgCbH8 VnLgffxPbTluFb89sRI0gyC02im1W+u5198/hsh9zA2xgJ4cV3UH8W5oKUBCDV7hTg4i ZbiY75B2HUjJezGOhU83VbCInx3G98uxGsippFRnRwA3/sMm6WGaZHQDNa5uZxS6E3/x nOoa72NH7DKCeAimTeo/5yPrxu3slx3MKwFFqOZqJlUHOk1YHSJQSRzLjFE0BId4mDhW Z5Bw== X-Forwarded-Encrypted: i=1; AJvYcCVkM69mO71DPWrz3N14uIV0/lrVQvwqg5So/lrQW8rlUS1hT7ckq2f5BQ6XlYD0JgmoF4EZJ79gMgJgXjhiNcT6KeNG3BCr4MD/wQ8j/ar96fZcvMs= X-Gm-Message-State: AOJu0YwShyis0fK8A4z7YA0I5fDhgGvzcCPg4veAduXGdeFy/PJhkbfs mSLx8ELKJzlO51bp23Uq9Z05t/FJe13h7x4XyHfwrP+EawkoBlouIhAw5ro58RQI6+09FC9qGQV E X-Google-Smtp-Source: AGHT+IFZWtUnWw29BR4yeXf4HxElvOUAsPby5qJeOfAnyq43ZffSXtzHQpoKbwA7KaOywvpFfVUV0Q== X-Received: by 2002:a17:906:298a:b0:a4e:6c21:6d5f with SMTP id x10-20020a170906298a00b00a4e6c216d5fmr4930065eje.72.1712507026781; Sun, 07 Apr 2024 09:23:46 -0700 (PDT) Received: from [127.0.1.1] ([79.114.172.194]) by smtp.gmail.com with ESMTPSA id qs28-20020a170906459c00b00a51bed388a4sm1811626ejc.139.2024.04.07.09.23.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 09:23:46 -0700 (PDT) From: Abel Vesa Date: Sun, 07 Apr 2024 19:23:24 +0300 Subject: [PATCH v9 4/7] spmi: pmic-arb: Make the APID init a version operation MIME-Version: 1.0 Message-Id: <20240407-spmi-multi-master-support-v9-4-fa151c1391f3@linaro.org> References: <20240407-spmi-multi-master-support-v9-0-fa151c1391f3@linaro.org> In-Reply-To: <20240407-spmi-multi-master-support-v9-0-fa151c1391f3@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 , David Collins , 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=9054; i=abel.vesa@linaro.org; h=from:subject:message-id; bh=0hIdOnPxC6/IlNZDC4oQnGBBsSrIsuVpzjKgCwMCAOo=; b=owEBbQKS/ZANAwAKARtfRMkAlRVWAcsmYgBmEsiGh3ocoPd/k70mrdgJR/+AMP0yOprRc6NzO QtJAh6MvGCJAjMEAAEKAB0WIQRO8+4RTnqPKsqn0bgbX0TJAJUVVgUCZhLIhgAKCRAbX0TJAJUV VlRFD/9g5mxY2j3xxFs004OQz51YNdXuFfyfPFbrR0G+TjXtsdhe40k38O7bcHFo3WnbbIjA5Uh fK5z0Y8+gWwHuaVwXahOEYQzVEdiilRIR7eiml7ayBDvex4+CbL16cKHXfmLnCovWXXsiT1UUoK e9X+CZIoccaYMDnucG/3hpy4Noz2PHe7u7xTBZoMtd/U23nGPbXpiki3/FKiervdCK581wsoDdd +nJbJdk+NGMXdHg0RfKzuheRv7JPQ2LE4J9faQ3HEK72bDBoJk3PkolO2bTaLLcVDYIEUPvGzlN 5DSSWt7A24T3K3II7j0RrR5YDONwkUiRgewcpF0hSxCA2MuEmN7Ppmlvn5P9YEs96jrJyGMFSBR xG9+mv/Fcl0Q5zqL6X+mnAU3BoueZDt7lp5oEQ4BMBl8l6ZeEFUoE7VidgrWWkZ6rpMFF/7AM44 WcVQwMB2GKnK8ptmqXAyK84+KpXqm5BOGm1sslkQ+RdblIHoe19uIlBborF+D6kMUV0IfyYgbxk 3FSZd37S9O4fhlerb8oWSnZ7C69nVgK1Yh/JTdyymD+42UZfL20kdetTAFrEnSr4UYBCR7nlcPD eyKxcs2hqY46ZHhN7C/t8i322OTQIHpWes3NdJdIzJ6QgNgKL01R8kPYo7SbRvc+s13HyRIvajS iCFptfS1ibHiWzg== 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-20240407_092350_149851_F0A6AE2B X-CRM114-Status: GOOD ( 20.34 ) 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 using conditionals in probe function, add the APID init as a version specific operation. Due to v7, which supports multiple buses, pass on the bus index to be used for sorting out the apid base and count. Reviewed-by: Neil Armstrong Signed-off-by: Abel Vesa --- drivers/spmi/spmi-pmic-arb.c | 144 +++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 75 deletions(-) diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 704fd4506971..dc969f8bed18 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -186,6 +186,7 @@ struct spmi_pmic_arb { * struct pmic_arb_ver_ops - version dependent functionality. * * @ver_str: version string. + * @init_apid: finds the apid base and count * @ppid_to_apid: finds the apid for a given ppid. * @non_data_cmd: on v1 issues an spmi non-data command. * on v2 no HW support, returns -EOPNOTSUPP. @@ -205,6 +206,7 @@ struct spmi_pmic_arb { */ struct pmic_arb_ver_ops { const char *ver_str; + int (*init_apid)(struct spmi_pmic_arb *pmic_arb); int (*ppid_to_apid)(struct spmi_pmic_arb *pmic_arb, u16 ppid); /* spmi commands (read_cmd, write_cmd, cmd) functionality */ int (*offset)(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr, @@ -947,6 +949,32 @@ static int qpnpint_irq_domain_alloc(struct irq_domain *domain, return 0; } +static int pmic_arb_init_apid_min_max(struct spmi_pmic_arb *pmic_arb) +{ + /* + * Initialize max_apid/min_apid to the opposite bounds, during + * the irq domain translation, we are sure to update these + */ + pmic_arb->max_apid = 0; + pmic_arb->min_apid = pmic_arb->max_periphs - 1; + + return 0; +} + +static int pmic_arb_init_apid_v1(struct spmi_pmic_arb *pmic_arb) +{ + u32 *mapping_table; + + mapping_table = devm_kcalloc(&pmic_arb->spmic->dev, pmic_arb->max_periphs, + sizeof(*mapping_table), GFP_KERNEL); + if (!mapping_table) + return -ENOMEM; + + pmic_arb->mapping_table = mapping_table; + + return pmic_arb_init_apid_min_max(pmic_arb); +} + static int pmic_arb_ppid_to_apid_v1(struct spmi_pmic_arb *pmic_arb, u16 ppid) { u32 *mapping_table = pmic_arb->mapping_table; @@ -1149,6 +1177,34 @@ static int pmic_arb_offset_v2(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr, return 0x1000 * pmic_arb->ee + 0x8000 * apid; } +static int pmic_arb_init_apid_v5(struct spmi_pmic_arb *pmic_arb) +{ + int ret; + + pmic_arb->base_apid = 0; + pmic_arb->apid_count = readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURES) & + PMIC_ARB_FEATURES_PERIPH_MASK; + + if (pmic_arb->base_apid + pmic_arb->apid_count > pmic_arb->max_periphs) { + dev_err(&pmic_arb->spmic->dev, "Unsupported APID count %d detected\n", + pmic_arb->base_apid + pmic_arb->apid_count); + return -EINVAL; + } + + ret = pmic_arb_init_apid_min_max(pmic_arb); + if (ret) + return ret; + + ret = pmic_arb_read_apid_map_v5(pmic_arb); + if (ret) { + dev_err(&pmic_arb->spmic->dev, "could not read APID->PPID mapping table, rc= %d\n", + ret); + return ret; + } + + return 0; +} + /* * v5 offset per ee and per apid for observer channels and per apid for * read/write channels. @@ -1363,6 +1419,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", + .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, .offset = pmic_arb_offset_v1, @@ -1377,6 +1434,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v1 = { static const struct pmic_arb_ver_ops pmic_arb_v2 = { .ver_str = "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, .offset = pmic_arb_offset_v2, @@ -1391,6 +1449,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v2 = { static const struct pmic_arb_ver_ops pmic_arb_v3 = { .ver_str = "v3", + .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, .offset = pmic_arb_offset_v2, @@ -1405,6 +1464,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v3 = { static const struct pmic_arb_ver_ops pmic_arb_v5 = { .ver_str = "v5", + .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, .offset = pmic_arb_offset_v5, @@ -1419,6 +1479,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v5 = { static const struct pmic_arb_ver_ops pmic_arb_v7 = { .ver_str = "v7", + .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, .offset = pmic_arb_offset_v7, @@ -1444,7 +1505,6 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) struct spmi_controller *ctrl; struct resource *res; void __iomem *core; - u32 *mapping_table; u32 channel, ee, hw_ver; int err; @@ -1472,12 +1532,6 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) pmic_arb->core_size = resource_size(res); - pmic_arb->ppid_to_apid = devm_kcalloc(&ctrl->dev, PMIC_ARB_MAX_PPID, - sizeof(*pmic_arb->ppid_to_apid), - GFP_KERNEL); - if (!pmic_arb->ppid_to_apid) - return -ENOMEM; - hw_ver = readl_relaxed(core + PMIC_ARB_VERSION); if (hw_ver < PMIC_ARB_VERSION_V2_MIN) { @@ -1511,58 +1565,17 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) return PTR_ERR(pmic_arb->wr_base); } - pmic_arb->max_periphs = PMIC_ARB_MAX_PERIPHS; + 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) { + 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; - /* Optional property for v7: */ - of_property_read_u32(pdev->dev.of_node, "qcom,bus-id", - &pmic_arb->bus_instance); - if (pmic_arb->bus_instance > 1) { - dev_err(&pdev->dev, "invalid bus instance (%u) specified\n", - pmic_arb->bus_instance); - return -EINVAL; - } - if (pmic_arb->bus_instance == 0) { - pmic_arb->base_apid = 0; - pmic_arb->apid_count = - readl_relaxed(core + PMIC_ARB_FEATURES) & - PMIC_ARB_FEATURES_PERIPH_MASK; - } else { - pmic_arb->base_apid = - readl_relaxed(core + PMIC_ARB_FEATURES) & - PMIC_ARB_FEATURES_PERIPH_MASK; - pmic_arb->apid_count = - readl_relaxed(core + PMIC_ARB_FEATURES1) & - PMIC_ARB_FEATURES_PERIPH_MASK; - } - - if (pmic_arb->base_apid + pmic_arb->apid_count > pmic_arb->max_periphs) { - dev_err(&pdev->dev, "Unsupported APID count %d detected\n", - pmic_arb->base_apid + pmic_arb->apid_count); - return -EINVAL; - } - } else if (hw_ver >= PMIC_ARB_VERSION_V5_MIN) { - pmic_arb->base_apid = 0; - pmic_arb->apid_count = readl_relaxed(core + PMIC_ARB_FEATURES) & - PMIC_ARB_FEATURES_PERIPH_MASK; - - if (pmic_arb->apid_count > pmic_arb->max_periphs) { - dev_err(&pdev->dev, "Unsupported APID count %d detected\n", - pmic_arb->apid_count); - return -EINVAL; - } - } - - pmic_arb->apid_data = devm_kcalloc(&ctrl->dev, pmic_arb->max_periphs, - sizeof(*pmic_arb->apid_data), - GFP_KERNEL); - if (!pmic_arb->apid_data) - return -ENOMEM; - - dev_info(&ctrl->dev, "PMIC arbiter version %s (0x%x)\n", - pmic_arb->ver_ops->ver_str, hw_ver); + err = pmic_arb->ver_ops->init_apid(pmic_arb); + if (err) + return err; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "intr"); pmic_arb->intr = devm_ioremap_resource(&ctrl->dev, res); @@ -1604,16 +1617,6 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) } pmic_arb->ee = ee; - mapping_table = devm_kcalloc(&ctrl->dev, pmic_arb->max_periphs, - sizeof(*mapping_table), GFP_KERNEL); - if (!mapping_table) - return -ENOMEM; - - pmic_arb->mapping_table = mapping_table; - /* Initialize max_apid/min_apid to the opposite bounds, during - * the irq domain translation, we are sure to update these */ - pmic_arb->max_apid = 0; - pmic_arb->min_apid = pmic_arb->max_periphs - 1; platform_set_drvdata(pdev, ctrl); raw_spin_lock_init(&pmic_arb->lock); @@ -1622,15 +1625,6 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) ctrl->read_cmd = pmic_arb_read_cmd; ctrl->write_cmd = pmic_arb_write_cmd; - if (hw_ver >= PMIC_ARB_VERSION_V5_MIN) { - err = pmic_arb_read_apid_map_v5(pmic_arb); - if (err) { - dev_err(&pdev->dev, "could not read APID->PPID mapping table, rc= %d\n", - err); - return err; - } - } - dev_dbg(&pdev->dev, "adding irq domain\n"); pmic_arb->domain = irq_domain_add_tree(pdev->dev.of_node, &pmic_arb_irq_domain_ops, pmic_arb);