From nobody Thu Nov 14 16:46:43 2024 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 26CCB3C6AC for ; Wed, 17 Apr 2024 20:01:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713384091; cv=none; b=m2VxS8kqS2+eGDbbSPUEQWoMoai+bJmt0S8zsQOnJOtAqdmt0EUnxVKFXV1s3VZdbi4A7Lw+RhThGbZw2cgV/w0+L0BrkbpF5TeKB+LQSyFNh9n/Jg1nhWJ5aczpENz5RBZNYpOYCnkmsi/IPaCb5EdY8bLOqN0UMEw4Bk8cg9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713384091; c=relaxed/simple; bh=nDUGRMtAX6AaUNrI4RsW85nuAecGS2OuKESyiWtIJd0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Kka5T7LGANf+86VIL6Gm5xo5xeHev0KumrdI+brwiJA3Zs+gLJqntiqXHhKJ2Ma58gCPyVQW8fUKBdMiyElbFoy5EW3mYlr6A0ygk32NCmcbP2VEW1ppuU12jIwaPQYT6r5h0f6FZCFxViXH1uLtM7IfToZHVahY9kP6ia3IQNQ= 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=mH16MU3B; arc=none smtp.client-ip=209.85.208.43 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="mH16MU3B" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-56c5d05128dso87046a12.0 for ; Wed, 17 Apr 2024 13:01:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713384087; x=1713988887; 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=JPbCq+oOUcmq2IMBiN6gCV1jsU1Thi9sfqYTDJv76Mk=; b=mH16MU3BC7Th6GcJ9o1CLpBAfdK1s7wTnONpP3bfE7dgj3kvFOyoIO0VuyKhEdHiDS P7BsqzGQ/G2PYYmFDipJYsI43malwsVlXXOmLrH2gh4W3Pkf++in+PoItUsi/g9Amv63 r4epYcfm4yfWFY6JkVhDSPoDgCtwOp73RiOxHxFTYhe+CuqylUmc1Uz+F1FQt6LqwEMD itWTW1HIXIl4Fc3Zma9/G0m69suhrvuZrV/tRRLqXFB7lJLt+B3283bT76fi+9n5FRYH xSFo8VYpR2pxya7GT1AAex2YIOBfF1XpYqhIzdfsacjGdD8VtgPeTQuheV3nd8HSXKl/ WR7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713384087; x=1713988887; 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=JPbCq+oOUcmq2IMBiN6gCV1jsU1Thi9sfqYTDJv76Mk=; b=gtVw9AnfDeMG8YdQXU6A5DAIbyQ7Xs5mjLBv+YExJhfa3WHp/qxvWg75EPf88eZ2u6 +KIX0FBHr7/fd80lZqK3GBL42XAlSl4CWasjIb2XRewNowrFjA6baFxzEIOZLr3xdBmo A6UHO4Tr8Aw7NkD8yJLFk2FcIEbqfGhrJlrRfHrXi73eyIVpGq/zeEeJWFYd7OJu9PDQ GpQ+cO84H+FLliF7tocI5up/WPYQ1MoA2pUUY3zM8rm8po9hEPDsLL9nL4YQDPefphrf 29h1yzSCJ0FtKXOSlWYSuuWYj/cMvw8NkbneGYiAbuwu3iUhtm4zJgogmG1KbJxrm2aQ stmA== X-Forwarded-Encrypted: i=1; AJvYcCW+efl4AlNsPvxFK2qgJuWIa3WRqcXy1AFRB3naoV9mBDGtn6PeI/FzT27ZzWivMOD8RmVmNOb4QBssuLDU1rwgeL7DH8/9AFWS/Orn X-Gm-Message-State: AOJu0YzuOEKeyHO5jXITLqIsI+Pg3CTsLI7t1lkURH/gk1LQEOL48PUi ZercHA1OjTuLmuUqOQE4tC3++d7uXNF8aOG4NzM9KwvGHc8+ryzEYiLQ0H2q7TY= X-Google-Smtp-Source: AGHT+IGua8+m5t8v6T12y+RuGXYF3KFnzmkDgbe1oqMkbVQmx5XTKjDvs0Gfd1slqTTZRF4rKL/5FA== X-Received: by 2002:a17:906:144d:b0:a55:6600:b33 with SMTP id q13-20020a170906144d00b00a5566000b33mr324872ejc.23.1713384087256; Wed, 17 Apr 2024 13:01:27 -0700 (PDT) Received: from [127.0.1.1] ([79.114.172.194]) by smtp.gmail.com with ESMTPSA id gs6-20020a170906f18600b00a555ef55ab5sm939981ejb.218.2024.04.17.13.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 13:01:26 -0700 (PDT) From: Abel Vesa Date: Wed, 17 Apr 2024 23:00:56 +0300 Subject: [PATCH v10 4/7] spmi: pmic-arb: Make the APID init a version operation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240417-spmi-multi-master-support-v10-4-5bc6d322e266@linaro.org> References: <20240417-spmi-multi-master-support-v10-0-5bc6d322e266@linaro.org> In-Reply-To: <20240417-spmi-multi-master-support-v10-0-5bc6d322e266@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=9035; i=abel.vesa@linaro.org; h=from:subject:message-id; bh=nDUGRMtAX6AaUNrI4RsW85nuAecGS2OuKESyiWtIJd0=; b=owEBbQKS/ZANAwAKARtfRMkAlRVWAcsmYgBmICqFwbGUbq2PsX2eGqy4maYPsUKhfMAH9YNeZ hSfhupI27aJAjMEAAEKAB0WIQRO8+4RTnqPKsqn0bgbX0TJAJUVVgUCZiAqhQAKCRAbX0TJAJUV Vgs2D/45SZ5NUEJDVdxBMiV9kzH8CJQr93noiG+lFPDHLKKkTziW7zif/LC4O98LiIMxuYAo8wR SzW4CZ2En/Yb0+60WUyF1UZuG4VnqM6f3AL+mSSlreZdWXPCkTpwoLzQGRzmCNwMQekAM1HA+P0 TbQM8Z0p/+wgIz2iaQU2G2dX2NoWrjhHxycxE51GF0sT5Z0Fqmcrg0yHhmxz9Fkt0fU5Prk43ci dlfMjuaPeGRZ8Ev+cz0VBqCBAsVygmESpTRd3bXs1Om9xRBqSPN+K0Gy2YJitQEaL1qUBTcRmil 9cqGvlHzKp8nwGb0nzEOsZM6hHNepyUtD5FmtoI/i8nKzyo1CSLGBv/dSzH6RGbUh5Te0aA1OYA 1dowLr2hdYTu094I+ULnZ4VXV3/O7sh9GpvDVY9BhdfMAiWX7r8tflSL8Nq9D37Kc+tgG+pFibJ c/q8AeZNYTUgqCkqETJED66VRA4/Zq4mwVYE5MJiyhibXRBdAe7v17oW1N2ndc1xTu7TqmcTiOJ LON6QkfGzjjA20cxRJfTPVaL7/IWn2TI6PyoDy6N6vHJN1QkPyuiS5ygKdwQVobqKAPBsTC4/+g HNwcRQjreWxhSGRFd/cZSnXs7GI3Ksr45LtO7Divi6YaZ8a9iCljrKJnkgI7BcMItVD4e6FKsgM EKCA3BfqxIwsZuQ== X-Developer-Key: i=abel.vesa@linaro.org; a=openpgp; fpr=6AFF162D57F4223A8770EF5AF7BF214136F41FAE 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 12c0efd744c2..fe45d62a42e2 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; } =20 +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 =3D 0; + pmic_arb->min_apid =3D 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 =3D devm_kcalloc(&pmic_arb->spmic->dev, pmic_arb->max_perip= hs, + sizeof(*mapping_table), GFP_KERNEL); + if (!mapping_table) + return -ENOMEM; + + pmic_arb->mapping_table =3D 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 pp= id) { u32 *mapping_table =3D 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; } =20 +static int pmic_arb_init_apid_v5(struct spmi_pmic_arb *pmic_arb) +{ + int ret; + + pmic_arb->base_apid =3D 0; + pmic_arb->apid_count =3D 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 =3D pmic_arb_init_apid_min_max(pmic_arb); + if (ret) + return ret; + + ret =3D pmic_arb_read_apid_map_v5(pmic_arb); + if (ret) { + dev_err(&pmic_arb->spmic->dev, "could not read APID->PPID mapping table,= rc=3D %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) =20 static const struct pmic_arb_ver_ops pmic_arb_v1 =3D { .ver_str =3D "v1", + .init_apid =3D pmic_arb_init_apid_v1, .ppid_to_apid =3D pmic_arb_ppid_to_apid_v1, .non_data_cmd =3D pmic_arb_non_data_cmd_v1, .offset =3D pmic_arb_offset_v1, @@ -1377,6 +1434,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v1 =3D { =20 static const struct pmic_arb_ver_ops pmic_arb_v2 =3D { .ver_str =3D "v2", + .init_apid =3D pmic_arb_init_apid_v1, .ppid_to_apid =3D pmic_arb_ppid_to_apid_v2, .non_data_cmd =3D pmic_arb_non_data_cmd_v2, .offset =3D pmic_arb_offset_v2, @@ -1391,6 +1449,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v2 =3D { =20 static const struct pmic_arb_ver_ops pmic_arb_v3 =3D { .ver_str =3D "v3", + .init_apid =3D pmic_arb_init_apid_v1, .ppid_to_apid =3D pmic_arb_ppid_to_apid_v2, .non_data_cmd =3D pmic_arb_non_data_cmd_v2, .offset =3D pmic_arb_offset_v2, @@ -1405,6 +1464,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v3 =3D { =20 static const struct pmic_arb_ver_ops pmic_arb_v5 =3D { .ver_str =3D "v5", + .init_apid =3D pmic_arb_init_apid_v5, .ppid_to_apid =3D pmic_arb_ppid_to_apid_v5, .non_data_cmd =3D pmic_arb_non_data_cmd_v2, .offset =3D pmic_arb_offset_v5, @@ -1419,6 +1479,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v5 =3D { =20 static const struct pmic_arb_ver_ops pmic_arb_v7 =3D { .ver_str =3D "v7", + .init_apid =3D pmic_arb_init_apid_v5, .ppid_to_apid =3D pmic_arb_ppid_to_apid_v5, .non_data_cmd =3D pmic_arb_non_data_cmd_v2, .offset =3D 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; =20 @@ -1472,12 +1532,6 @@ static int spmi_pmic_arb_probe(struct platform_devic= e *pdev) =20 pmic_arb->core_size =3D resource_size(res); =20 - pmic_arb->ppid_to_apid =3D 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 =3D readl_relaxed(core + PMIC_ARB_VERSION); =20 if (hw_ver < PMIC_ARB_VERSION_V2_MIN) { @@ -1511,58 +1565,17 @@ static int spmi_pmic_arb_probe(struct platform_devi= ce *pdev) return -ENOMEM; } =20 - pmic_arb->max_periphs =3D PMIC_ARB_MAX_PERIPHS; + dev_info(&ctrl->dev, "PMIC arbiter version %s (0x%x)\n", + pmic_arb->ver_ops->ver_str, hw_ver); =20 - if (hw_ver >=3D PMIC_ARB_VERSION_V7_MIN) { + if (hw_ver < PMIC_ARB_VERSION_V7_MIN) + pmic_arb->max_periphs =3D PMIC_ARB_MAX_PERIPHS; + else pmic_arb->max_periphs =3D 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; - } =20 - if (pmic_arb->bus_instance =3D=3D 0) { - pmic_arb->base_apid =3D 0; - pmic_arb->apid_count =3D - readl_relaxed(core + PMIC_ARB_FEATURES) & - PMIC_ARB_FEATURES_PERIPH_MASK; - } else { - pmic_arb->base_apid =3D - readl_relaxed(core + PMIC_ARB_FEATURES) & - PMIC_ARB_FEATURES_PERIPH_MASK; - pmic_arb->apid_count =3D - 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 >=3D PMIC_ARB_VERSION_V5_MIN) { - pmic_arb->base_apid =3D 0; - pmic_arb->apid_count =3D 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 =3D 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 =3D pmic_arb->ver_ops->init_apid(pmic_arb); + if (err) + return err; =20 res =3D platform_get_resource_byname(pdev, IORESOURCE_MEM, "intr"); pmic_arb->intr =3D devm_ioremap_resource(&ctrl->dev, res); @@ -1604,16 +1617,6 @@ static int spmi_pmic_arb_probe(struct platform_devic= e *pdev) } =20 pmic_arb->ee =3D ee; - mapping_table =3D devm_kcalloc(&ctrl->dev, pmic_arb->max_periphs, - sizeof(*mapping_table), GFP_KERNEL); - if (!mapping_table) - return -ENOMEM; - - pmic_arb->mapping_table =3D 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 =3D 0; - pmic_arb->min_apid =3D pmic_arb->max_periphs - 1; =20 platform_set_drvdata(pdev, ctrl); raw_spin_lock_init(&pmic_arb->lock); @@ -1622,15 +1625,6 @@ static int spmi_pmic_arb_probe(struct platform_devic= e *pdev) ctrl->read_cmd =3D pmic_arb_read_cmd; ctrl->write_cmd =3D pmic_arb_write_cmd; =20 - if (hw_ver >=3D PMIC_ARB_VERSION_V5_MIN) { - err =3D pmic_arb_read_apid_map_v5(pmic_arb); - if (err) { - dev_err(&pdev->dev, "could not read APID->PPID mapping table, rc=3D %d\= n", - err); - return err; - } - } - dev_dbg(&pdev->dev, "adding irq domain\n"); pmic_arb->domain =3D irq_domain_add_tree(pdev->dev.of_node, &pmic_arb_irq_domain_ops, pmic_arb); --=20 2.34.1