From nobody Sun Nov 10 05:46:58 2024 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 A37F669DFF for ; Tue, 20 Feb 2024 12:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708433983; cv=none; b=WwxfLe5BD74Fc/i/yo3rHVUe4yuIxQsOP5lBBayTFjqPprsFvDBek3s++Y6p1nNW3H5MvUztZ/R5ib03XAO39jHQzUt6weBhcgUcpipue4N3wbcnuSkckL+D1i78EOg1UhfeZoXGeR8JPkttpaqRgT5I9UwFH5CiZy0x6ueSe0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708433983; c=relaxed/simple; bh=xUhXxEB1TSjaY+70YZslQBzXRf4SXFhFlW0PDrTOM4E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fLcXBnpbsHEpOPADExaJjP7z2fsJ1csbYROJ/q3XBmDwupvUk/zH+B+pbBIeMIkBPXELNWj57QFjUqCtAWw4PuH6iz/unJZvy7fhoXBZOWhvE8fiVHmc8nZ61co/0CIBdwHyTYiLJqpo/tsTn6bIvTAb1+hSDEFLDhUnmmqrwQw= 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=d3LiBksf; arc=none smtp.client-ip=209.85.218.46 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="d3LiBksf" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a3e7f7b3d95so274922666b.3 for ; Tue, 20 Feb 2024 04:59:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708433980; x=1709038780; 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=7oA0fmKcMGpa77tBwzlw1ahRCKvmpIwJPYwf28NyUZ4=; b=d3LiBksfN58nV2pMIHp2elUev8+P2ix/L5Kz5k0tLaJCz6WpDu53M6zL/NuZXvUkuX dFJ9oWPMMIE9uvbKuleC2THOZkPFqDYZf1S1pV0QtBRsYc0F5i7AoEqfyU/vk5RbNc42 dy36E5CvUDuhpnJ5HGcqWqeiLjGlFDv9IikczNQ1DFYanJxdCB1hSMkwVRHuaGj5iN3G 6w0wq6BJqjX9hwU8e4hYa0T/sHm0Rwa7v+qmsycLuI0kDmpRjGX6ZxHvVAdUm4SbwQS5 cbuYFREFVQ2lMBR+GMORkT0cgfS8j7pQpWCKcL2MDTMSXyKlbNKR/IM9u299KbMXi1Fh WOjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708433980; x=1709038780; 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=7oA0fmKcMGpa77tBwzlw1ahRCKvmpIwJPYwf28NyUZ4=; b=YS5P3sd8B+iTzMGnHsZZL0SIXKtw2Gz5zY1qEco0G5Lm2DVtnrPHFvNVuzieVECF/T urOE2rYeTq5reSFBTjdUcoOy9czEF3fNW6I8+OtHTUgF7Tal872EgsKmDQpbGdasGMkm QYiy1+UM3pcGM6PuLivHgCNqaxvNKN0Um0wTy5LE74Mx2Ck8htuwARQfEof2sZAJ1dvR GnmrcJ/WQ4mq6gWT977AFLcJVgmx73VPz6N1gKlNzscWo7lYIsCznClVToFo9CGQwjk3 7mPRh9kVIO3v1719zXrgmEKftpVKipKOtEEdns2cZqDzl6dNUKmqWMI5lWoMNJnrIBJB EmGw== X-Forwarded-Encrypted: i=1; AJvYcCWVDzxtxqWmrd2BkkwiLFvJ04fdAlq5JfosW0+vjcZ2My+6+lMo3pFncXOKDDT5yqW2HC/NnRyIgPt18M1Og6LF+lXlclfWCICVH0ps X-Gm-Message-State: AOJu0Yy9geWG5fSG3FwmjRxr1cvuEOp6LnvYkRRI1kurS58dmfp4sav+ AL+4eihV1Y8RdjB57qJh/8Ez/TF5OM2Km0ecrdnrbKyCv2iLqBCy1YU3BylYdlo= X-Google-Smtp-Source: AGHT+IEXxeEivaAtV4wwJy+MVYXjj4VEIZqysh0sxSO8vB7EK8AkzqrX4BzThzLYunH8JDgKi3tCTA== X-Received: by 2002:a17:906:37c2:b0:a3f:7e2:84cc with SMTP id o2-20020a17090637c200b00a3f07e284ccmr1263676ejc.6.1708433980072; Tue, 20 Feb 2024 04:59:40 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 04:59:39 -0800 (PST) From: Abel Vesa Date: Tue, 20 Feb 2024 14:59:22 +0200 Subject: [PATCH RFC v4 2/4] 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: <20240220-spmi-multi-master-support-v4-2-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=10831; i=abel.vesa@linaro.org; h=from:subject:message-id; bh=xUhXxEB1TSjaY+70YZslQBzXRf4SXFhFlW0PDrTOM4E=; b=owEBbQKS/ZANAwAKARtfRMkAlRVWAcsmYgBl1KI08mAp34eb6ANzbkcoyuZS1pCsJYxNzIhxn OZNGjCcR0KJAjMEAAEKAB0WIQRO8+4RTnqPKsqn0bgbX0TJAJUVVgUCZdSiNAAKCRAbX0TJAJUV VkatD/42KrOPJ4886muFDYdYkR0oGN/SeXM3bUNJuPG6ZbefnIhYw6oOXWqyDhC6Sq5XL1IxjRV SRrBzjCgUdIQK923MiDMKvsIf7VtXm/TnzAm0/sLbUM9NcrA0qTipqZWtEwcMESr/53bX4fiUxJ FQMLOqY0U3lb9XNgKXPRAo9wo917RiyYwUdmIUHqvNZdzS4NPJ+uByEGen9/RTqdhr+w40AB5UM W2MrHNc2JGR8P9vDGgAoRJaYBMQJRAwnKETodjjquhXmBJqK8k39q5Jb4x2nxcxySg5OzlRURbM 6DSk7u83s/NW9K25q0peImX99p8RhEMDPrZYttrG3UWLqxf8iJ91iJ0Vw+wTo46dAxRCKvnS/Q9 28X2A2IaXax6xXBNaIb0Co6hKUWa9Kjt6gygLjdKrpLMcXbSbahED82RgzvdX8Pk1iOyCXS2n4J +4P0bCccfoM/PR7an4nqQBOvVOTLc+8mN+JNcifu3fu8jZXpSWsIwQWubVLjrTyR7fuME1rNE7d VXvii7lQYA6hwqPsOgPopxjFW1/sB1lh3UAIGPq2MPbD1kZmIt/kwXZk69+Q/bKMKYwuz0utMpZ ckDeMUIR1Tm7IazNsF398zvMBbBNB4lBSC9iNDN4Wi7rXN+T+9tOG5hB4Cxga/l4ipOpPUfnxU7 8hth1sMyNRZwzXg== 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. Signed-off-by: Abel Vesa --- drivers/spmi/spmi-pmic-arb.c | 199 +++++++++++++++++++++++++++------------= ---- 1 file changed, 124 insertions(+), 75 deletions(-) diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 9ed1180fe31f..38fed8a585fe 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -183,6 +183,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. @@ -202,6 +203,7 @@ struct spmi_pmic_arb { */ struct pmic_arb_ver_ops { const char *ver_str; + 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 */ int (*offset)(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr, @@ -942,6 +944,38 @@ 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, int index) +{ + u32 *mapping_table; + + if (index) { + dev_err(&pmic_arb->spmic->dev, "Unsupported buses count %d detected\n", + index); + return -EINVAL; + } + + 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; @@ -1144,6 +1178,40 @@ 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 index) +{ + int ret; + + if (index) { + dev_err(&pmic_arb->spmic->dev, "Unsupported buses count %d detected\n", + index); + return -EINVAL; + } + + 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. @@ -1178,6 +1246,49 @@ static int pmic_arb_offset_v5(struct spmi_pmic_arb *= pmic_arb, u8 sid, u16 addr, return offset; } =20 +/* + * Only v7 supports 2 buses. Each bus will get a different apid count, read + * from different registers. + */ +static int pmic_arb_init_apid_v7(struct spmi_pmic_arb *pmic_arb, int index) +{ + int ret; + + if (index =3D=3D 0) { + pmic_arb->base_apid =3D 0; + pmic_arb->apid_count =3D readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURE= S) & + PMIC_ARB_FEATURES_PERIPH_MASK; + } else if (index =3D=3D 1) { + pmic_arb->base_apid =3D readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURES= ) & + PMIC_ARB_FEATURES_PERIPH_MASK; + pmic_arb->apid_count =3D readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURE= S1) & + PMIC_ARB_FEATURES_PERIPH_MASK; + } else { + dev_err(&pmic_arb->spmic->dev, "Unsupported buses count %d detected\n", + index); + return -EINVAL; + } + + 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; +} + /* * v7 offset per ee and per apid for observer channels and per apid for * read/write channels. @@ -1358,6 +1469,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, @@ -1372,6 +1484,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, @@ -1386,6 +1499,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, @@ -1400,6 +1514,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, @@ -1414,6 +1529,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_v7, .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, @@ -1439,7 +1555,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 @@ -1467,12 +1582,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) { @@ -1506,58 +1615,17 @@ static int spmi_pmic_arb_probe(struct platform_devi= ce *pdev) return PTR_ERR(pmic_arb->wr_base); } =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; - } - - 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; - } =20 - 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, 0); + 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); @@ -1599,16 +1667,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); @@ -1617,15 +1675,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