Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp162313lqz; Fri, 29 Mar 2024 11:55:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVsERr4mq4Ow7MKq8UDqkWsNmddAYQ1k8jC2qrBgOzEN6CwcH6+rqG9b//cGXCb+BRAwAEnVNX7X9Yh/+c9K4pNrFtUobCIsqzIQSFynA== X-Google-Smtp-Source: AGHT+IF/lWnhesto3TR4yqGDKQPT4WGCEBbe36r4EJLoc9HqEBuOW+uTF9bk1Bc8FvuNDIl0H1dl X-Received: by 2002:a05:622a:14:b0:431:6208:82b4 with SMTP id x20-20020a05622a001400b00431620882b4mr3918677qtw.11.1711738536987; Fri, 29 Mar 2024 11:55:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711738536; cv=pass; d=google.com; s=arc-20160816; b=ZR8vXV627f3d2N+Dr1WHDlXPlo+K/iGIYeJCas22bpdb6sERdCNspKbjaLuQxwV2Zb HkOM5GC9mJiHHWVC/2vu5tV5bC9NNNDlPmIGh8I785UNzQvxORxUMwp1/JHawAZuwUMt 8qgvgPSUQQoripkiAY0Umtp2nu6f//dUbMlncwzG37M9KiAffseWE7u8krAUTfIzF8mw 8QLFp6a3GAqZUjzeaL7mu89aD8dNjvr2XAGSMf1Iu+jtl8Fr709leK1HL7ZwaSS5dO9Z 38PgOWJBJMzBIMg1uEXUKqQImvM9JPXliZOPo8KlLY35tVrw6F5IhWHBxbdd3XRmaqH8 3VBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=7oA0fmKcMGpa77tBwzlw1ahRCKvmpIwJPYwf28NyUZ4=; fh=GFNsxS34Zvh2QiIJpNSvWaet+a7P3QdaPOV+IM4qSBg=; b=SELC3CP03Ad21MkebxmVfwaVO4lLY0C6cXEhF4kSEJ43OHz/GqZXfmOasYpm6Rjr8/ 2Jc8FoNU1sstTPAir3/Y8W0KikYYwjh9eU3dL4CWggRwaSM00Hu95oTgLSPtK/FVRxM2 R6CILSJ2+/YTpcX7qY0quKnzNyw06Xs200BNTpBeDjN43zGgeCuBuDlOYAwX8GQNj7lE O21FysaDF9DaNgf5EDfrlTwQL9FiDULtIoaXIDS/LWUCTasWOCCBAZf5w+5E1s7lYNQ5 gL3V3F+XZqao0QQTEh2+4WdZh12ag0zGVTf0y6yGlqNZivXbl6s8b/bOsVNmvX86lnKI LD8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yTUgngPO; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-125298-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125298-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d6-20020a05622a100600b00432ccd50e56si121531qte.307.2024.03.29.11.55.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 11:55:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-125298-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yTUgngPO; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-125298-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125298-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A494B1C22266 for ; Fri, 29 Mar 2024 18:55:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E80013AA3C; Fri, 29 Mar 2024 18:54:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="yTUgngPO" Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 B433A1369A4 for ; Fri, 29 Mar 2024 18:54:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711738491; cv=none; b=dMMvJjY0aryzAE8iMBJMboYmi/L3sWIPYoM45FzGpc/hbQtwsLY+1s7nsMIPKbQXlMdgOGC5b4nHtI5N7ElnhVu3POD/l0vEbAn2avBEn6iOD73OGcGCviuLJ1PhrsWJQo/WjHzLI/tIVPhz4sVUkebpOHvz/zX6NzvyL1kXN2s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711738491; c=relaxed/simple; bh=xUhXxEB1TSjaY+70YZslQBzXRf4SXFhFlW0PDrTOM4E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kIw4xl4LwBdMMnElpPaopbYwFmodq7Cc6Rw5HO2yHmE+ZTuXXc+jIkCiggzPiyAFXTu312vtdxoObvZcseWMbETK1/FkiLFCQI3EAf4oJsSpvFTcCfphABk2CbAGfoHnju+2zHUS7QCtsEiLbFvuEsORNmKEyVhq60mMVEuptWQ= 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=yTUgngPO; arc=none smtp.client-ip=209.85.167.54 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 Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-515a86daf09so2763061e87.3 for ; Fri, 29 Mar 2024 11:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711738488; x=1712343288; 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=yTUgngPONiMfA/nNXQYB0HnXOp+pOgFGRtFPIwrSKArVhgpFboHX3nHip/eLNShZ/J oDCCU/sVmgpkvOIFMzNo9AmLmWTAKhMIQzSpNXDKxeRi2yLMkiOZsACO1iQK2u5AkHsO GbwroKOwSYIpaRjmqEfE4QT1qP7EvRDmtqzJIupgAxca43/nadMd/XzoC/e2Jc1qgDv7 xI0JJfm83QFG7FeR826wmBwSk+JpoZoRvfNebQmf/pZGaRN3DauvnYco/2LnsFtMRJAK 9WKGTtZbjUfCDKhXgqUhEZ2QZSZN3Kh/4x+d/VIiYZ08qkQ4a2wPn7emtcQLl4/BQKbh MGdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711738488; x=1712343288; 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=D/FxoycQSO3Jei/KjBKdFfwJSyUkx8AvETRfwMPz2IXQA7qKgLRPc//yAmuWvo1zOY DjfKXpwr7lvG500X3WhjXJgIxSudqo6plpXM0w59Y9nCmu5LOH0CVz2GBz18fkk3o0so YScNaRn/k4z3HdfIwzt5MisFuQ3s2hktMJ8uLD6SgqaGTJWqRY7LaqYCExkXRpNGUdpC oCFxujXANpkQRMgZ8ka+f8GVCJGBRr2JkTdmW4Vx8nurNuXv1sTAFe+k0mHZEzj9+w5Y eXMB3yYkP2+NC3j19IyS6crCRVIXV6WIaAQghmHG6rW1D2b5p/S7yLeNekylxqX8lAD9 d8lQ== X-Forwarded-Encrypted: i=1; AJvYcCXQUhQXDdLncYqXunEw/IGrCFvEsn8lEwzxLdadGuMnUuA5MqrnLXtiuwRckecQz0dNmz+NSkhNwHfdtLORV9W7xudgQowQWCKUei/C X-Gm-Message-State: AOJu0YzsB79END+XnOnDCIXgAIyys/DIa2tb5LMtY8O1P0GZ0YEexKp6 Ou7aBwlwtKASwgtKk2Sx5Iida5LwjrS8lMPapeJ8eew95zG9W/aI53y8rNL0OSA= X-Received: by 2002:ac2:5de9:0:b0:515:d196:6d4c with SMTP id z9-20020ac25de9000000b00515d1966d4cmr1561650lfq.34.1711738487458; Fri, 29 Mar 2024 11:54:47 -0700 (PDT) Received: from [127.0.1.1] ([79.114.172.194]) by smtp.gmail.com with ESMTPSA id gl20-20020a170906e0d400b00a46c39e6a47sm2235618ejb.148.2024.03.29.11.54.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 11:54:47 -0700 (PDT) From: Abel Vesa Date: Fri, 29 Mar 2024 20:54:20 +0200 Subject: [PATCH v7 3/6] 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: 7bit Message-Id: <20240329-spmi-multi-master-support-v7-3-7b902824246c@linaro.org> References: <20240329-spmi-multi-master-support-v7-0-7b902824246c@linaro.org> In-Reply-To: <20240329-spmi-multi-master-support-v7-0-7b902824246c@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/ZANAwAKARtfRMkAlRVWAcsmYgBmBw5s23qOSsIxlAnplYOuCgDQz8cJDmpB/PyCi PAF5WUaBCGJAjMEAAEKAB0WIQRO8+4RTnqPKsqn0bgbX0TJAJUVVgUCZgcObAAKCRAbX0TJAJUV Vq5gEACC7/hCIYxDB6ozwcnTIt+YcvsR4u8feKZTImGAZfanhwVlKHpluVysT7WIQLIwYOsTE45 Gis1DGOpXfx4sSKRGQ1OXY0tAhh80VKsi9b482xv5cHM6ukZuQwbfYtZil/Mge3kNkHPHxGNC3E EtEI6Riyj2a/foe4mWPm5/O6YT6dkZxbnIoh4B2H2lxTOuQF4/neBS9XFHZ0t+MxzI3Rd9J6Fgb +FoMVYj9xM/AurtIcvQOShUwIq06hnSVtohEGZAu2IsOj+7BH0+5Oya4wx4OnxLiRykhV/hNEOY E2sJD9OQj4RnwqsZabGaYdRPD71PvIQnHRyXmK17DPOmegZHILkigV7EBiVsMict7THn/X9F4wW Agx1rX9isa6qDXvu2yxlzGM10w439gHA2HkNU9ArCxJAuwaQiR6IVxEg2270q1K2E3R/YILMl/B /j0A5gbVv3BdPcqUvVSfKozCzB1LXOPQvFZTDZsqVctCwnQMrvVLDpcpoPbV354DRF8s988BPts HWkpz6OvQpRkwJXaFPR6prwh5l2Cj8Y+CDEmi1vuypbElcyhAvLLE0Yvy3O8/nkvGMOD3MoHmiK VSoyMDUaMB2RDbpFAQnGTpfVkC6SFYfo1mdvs+xgNVHJ3b8BtLASX+p5vfZhFSkDD9HTXF1sEF9 rMxtdpVLnhllnOA== 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; } +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, int index) +{ + u32 *mapping_table; + + if (index) { + dev_err(&pmic_arb->spmic->dev, "Unsupported buses count %d detected\n", + index); + return -EINVAL; + } + + 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; @@ -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; } +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 = 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. @@ -1178,6 +1246,49 @@ static int pmic_arb_offset_v5(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr, return offset; } +/* + * 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 == 0) { + pmic_arb->base_apid = 0; + pmic_arb->apid_count = readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURES) & + PMIC_ARB_FEATURES_PERIPH_MASK; + } else if (index == 1) { + pmic_arb->base_apid = readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURES) & + PMIC_ARB_FEATURES_PERIPH_MASK; + pmic_arb->apid_count = readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURES1) & + 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 = 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; +} + /* * 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) 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, @@ -1372,6 +1484,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, @@ -1386,6 +1499,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, @@ -1400,6 +1514,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, @@ -1414,6 +1529,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_v7, .ppid_to_apid = pmic_arb_ppid_to_apid_v5, .non_data_cmd = pmic_arb_non_data_cmd_v2, .offset = 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; @@ -1467,12 +1582,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) { @@ -1506,58 +1615,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, 0); + if (err) + return err; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "intr"); pmic_arb->intr = devm_ioremap_resource(&ctrl->dev, res); @@ -1599,16 +1667,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); @@ -1617,15 +1675,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); -- 2.34.1