From nobody Thu Nov 14 16:38:05 2024 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 6CB845A115 for ; Wed, 17 Apr 2024 20:01:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713384096; cv=none; b=DospqS0oX4vtDiY5I7+kYeqCCWnLOdU8Y7NRHT88DH6M353gwJkvewDQSe+bGUYpU+0YoFVQIXTe0XHs2dfYuYGjpoejz+GuoK/Hdccbfrbr/O0gj4FvH0iR49j55TtfDWs5QP1Y2PIW3GVn+bSR15olnMf63r6cWcD/26N16/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713384096; c=relaxed/simple; bh=xmlabHfkblERj1InhHHP21kg4juqeMVaUpLbVHUxli4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AJU/FnJX37+o3dGJrxt6Auhmh0mxVdKqSEkaY1sN9najtMOPzCdKWCvrDY6H2GuYd9J/KUGaMih4yFxQ3D6PXFakxzhBcuhQZy5jY44ky51OgEEl4yWOcc37NgDkm6QeXZqEMwWEtbOXDn/lWhNMPtjS/YSI1YPjBpKdtqM0p+8= 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=qKt5QbBs; arc=none smtp.client-ip=209.85.218.53 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="qKt5QbBs" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a55323f2ef9so2634266b.1 for ; Wed, 17 Apr 2024 13:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713384093; x=1713988893; 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=rgaJ9SiihEkn5mbvQeAX1UQdZh1z/tHET5Ml8p7IStM=; b=qKt5QbBsQDuDiO5NrVYY6TzfmGKB5hsVNvPEF3sopr7Eb4o2jHyLK7zYiqObrzT2Dw zb2yBeBKZPOtHLgaWv671Y6rKPu26P5iDXeFzGBQhu1bK54nP+XwBBVUOAt+C76P3mlQ qDAm8VG6NeOTkmVh34Jn4ykeoxXpq8FxPMgLonJ13YhQNzRi4951yeWRAYXQtR7g9DcO CdnaYvB2+F3pRleXHdZh7CbCxB9TWKAZd0w8sfYyDk21pJ8yglf0QhSWJd04+Bi0DSBx QWjyYNxZuAa8mFU60AUeyap4W7Pdo+aw03Y7C6vhWzYzMPbQ9V/DTREQpHaPTEpw+G24 uc6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713384093; x=1713988893; 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=rgaJ9SiihEkn5mbvQeAX1UQdZh1z/tHET5Ml8p7IStM=; b=jV96QL4PBj4hCDEH/ocm/AVZkrOgQ0PuTOQ9owTTOb5QnRFDL38A5Smq4314u63sMk EUuumwiz08tezg0Vo6gjksAt6Zu40KHTCUMQk9IrwDNLs5bm4AYwBFXmqZeGZSdltTl1 xjgukByLbhyVdcahBks44WEzMErmwC83KmJD3qn8ntpaOSFBxJA/PQapArQPtHPiK/al CqYrPEOI7LbSonBKpUrTRdQJy+v7Au390tORCvl6NocjJir7yyRJ/h3sce+EcC9QkJRQ w/U5R72pd6FNeiT0t/tP2gpRutqPeXc76MLlgET3pJaDCzxlmlohMIFQs2tLuJJAP+yf U6Qw== X-Forwarded-Encrypted: i=1; AJvYcCVJxCV/l51tUBls31CLOdIW1eqqYQAXVnSCXvTXAbOxtuVtp3rX+V3Km/tMajiALOicZJ32wV8UW4gNH2MjxjpgPKqAi8auRJtC38Nq X-Gm-Message-State: AOJu0YzZkfHTK+qhIc0VUXy/u2AI4H16j2hovTCWgUzjz8WdmGCuEGMl vxKCAXfeco/nRYCS6qnusOkqEFXzjuRYoI7unuEaggwI9wpiliRIVf7PlJ+W3Vw= X-Google-Smtp-Source: AGHT+IGT/5KiTugzJZ34QuU4kW1G2canhZKORyynZvW6s58bLzpIsP0aHYm0/QwT0R1cPoyzqfTmHA== X-Received: by 2002:a17:906:f6d6:b0:a52:57ee:4464 with SMTP id jo22-20020a170906f6d600b00a5257ee4464mr373121ejb.19.1713384092655; Wed, 17 Apr 2024 13:01:32 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 13:01:32 -0700 (PDT) From: Abel Vesa Date: Wed, 17 Apr 2024 23:00:59 +0300 Subject: [PATCH v10 7/7] spmi: pmic-arb: Add multi bus support 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-7-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=9935; i=abel.vesa@linaro.org; h=from:subject:message-id; bh=xmlabHfkblERj1InhHHP21kg4juqeMVaUpLbVHUxli4=; b=owEBbQKS/ZANAwAKARtfRMkAlRVWAcsmYgBmICqNHC7m9PF22wqiTPqefESs7DT5FdxSunAhh tsC/owvMg2JAjMEAAEKAB0WIQRO8+4RTnqPKsqn0bgbX0TJAJUVVgUCZiAqjQAKCRAbX0TJAJUV Voo0D/0ZYeEHQqzvcOSg6P/1oNkaeSIp/76y1aW/RYJ8LnA01dZFewsk3BktEWHVRqL4pIlhDY/ sDjlK0Di4dFOJl4kcnqSXRWkiNd9l6kUsCCMw+zdgONNLdPEdUBHK86DVaykBp6fXnYIh6/PVZ8 mlp/dUrk5PDqek/e8rH8U68nuyzf460xj7VxepW4uybi9RY+kSbam8Pg/k91PmE2NY5bJAdejnv Yd1kkhrqwS31/IgvTKAuOOHZDW5vlrw7sdoPHueH5254+edCiskXiTbw5lwAkdPrWaeXfKo7GiL fiyKbU2q0P4ovgD2ju/9886xwy93OLYp2/jQHqYVJZsY/DWxffcYwPTvysTMyws/5G9HTlm+7Nv Zqeszsd8pRLmBtvoSNTKBVD7YQZyHZoRozQevraBQPDoedR3e9H+mv9czlUNpplwK12lxI1kTSk PPFK4KG4+zbRUoBxqN7R37zcCxfnqecmOVwnLeurB4K6kviNFlimtdwH9pRqFtzZmJ7+gBfEBKB d6c3/NukJgXAV+0DUcVYzJvPMv2y39iVpweYad/4f2jsnaHw7lkcwCND1pHZh+OJz3jbeSkxOhy xttLB8CLLODsu4vDk4fZaFlhib2jPlSWLifo9RNIWBAC798XmBT/6p6MG3ZAyUql8QKHE2PHaHz wECPhbIGJjh/mkw== X-Developer-Key: i=abel.vesa@linaro.org; a=openpgp; fpr=6AFF162D57F4223A8770EF5AF7BF214136F41FAE Starting with HW version 7, there are actually two separate buses (with two separate sets of wires). So add support for the second bus. The first platform that needs this support for the second bus is the Qualcomm X1 Elite, so add the compatible for it as well. Reviewed-by: Neil Armstrong Signed-off-by: Abel Vesa --- drivers/spmi/spmi-pmic-arb.c | 138 +++++++++++++++++++++++++++++++++++++--= ---- 1 file changed, 120 insertions(+), 18 deletions(-) diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 36599e952599..0a17ff02c827 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -95,6 +96,8 @@ enum pmic_arb_channel { PMIC_ARB_CHANNEL_OBS, }; =20 +#define PMIC_ARB_MAX_BUSES 2 + /* Maximum number of support PMIC peripherals */ #define PMIC_ARB_MAX_PERIPHS 512 #define PMIC_ARB_MAX_PERIPHS_V7 1024 @@ -149,6 +152,7 @@ struct spmi_pmic_arb; * @min_apid: minimum APID (used for bounding IRQ search) * @max_apid: maximum APID * @irq: PMIC ARB interrupt. + * @id: unique ID of the bus */ struct spmi_pmic_arb_bus { struct spmi_pmic_arb *pmic_arb; @@ -167,6 +171,7 @@ struct spmi_pmic_arb_bus { u16 min_apid; u16 max_apid; int irq; + u8 id; }; =20 /** @@ -180,7 +185,8 @@ struct spmi_pmic_arb_bus { * @ee: the current Execution Environment * @ver_ops: version dependent operations. * @max_periphs: Number of elements in apid_data[] - * @bus: per arbiter bus instance + * @buses: per arbiter buses instances + * @buses_available: number of buses registered */ struct spmi_pmic_arb { void __iomem *rd_base; @@ -191,7 +197,8 @@ struct spmi_pmic_arb { u8 ee; const struct pmic_arb_ver_ops *ver_ops; int max_periphs; - struct spmi_pmic_arb_bus *bus; + struct spmi_pmic_arb_bus *buses[PMIC_ARB_MAX_BUSES]; + int buses_available; }; =20 /** @@ -220,7 +227,7 @@ struct spmi_pmic_arb { struct pmic_arb_ver_ops { const char *ver_str; int (*get_core_resources)(struct platform_device *pdev, void __iomem *cor= e); - int (*init_apid)(struct spmi_pmic_arb_bus *bus); + int (*init_apid)(struct spmi_pmic_arb_bus *bus, int index); int (*ppid_to_apid)(struct spmi_pmic_arb_bus *bus, u16 ppid); /* spmi commands (read_cmd, write_cmd, cmd) functionality */ int (*offset)(struct spmi_pmic_arb_bus *bus, u8 sid, u16 addr, @@ -309,8 +316,8 @@ static int pmic_arb_wait_for_done(struct spmi_controlle= r *ctrl, } =20 if (status & PMIC_ARB_STATUS_FAILURE) { - dev_err(&ctrl->dev, "%s: %#x %#x: transaction failed (%#x)\n", - __func__, sid, addr, status); + dev_err(&ctrl->dev, "%s: %#x %#x: transaction failed (%#x) reg: 0x%x\n= ", + __func__, sid, addr, status, offset); WARN_ON(1); return -EIO; } @@ -326,8 +333,8 @@ static int pmic_arb_wait_for_done(struct spmi_controlle= r *ctrl, udelay(1); } =20 - dev_err(&ctrl->dev, "%s: %#x %#x: timeout, status %#x\n", - __func__, sid, addr, status); + dev_err(&ctrl->dev, "%s: %#x %#x %#x: timeout, status %#x\n", + __func__, bus->id, sid, addr, status); return -ETIMEDOUT; } =20 @@ -1003,11 +1010,17 @@ static int pmic_arb_get_core_resources_v1(struct pl= atform_device *pdev, return 0; } =20 -static int pmic_arb_init_apid_v1(struct spmi_pmic_arb_bus *bus) +static int pmic_arb_init_apid_v1(struct spmi_pmic_arb_bus *bus, int index) { struct spmi_pmic_arb *pmic_arb =3D bus->pmic_arb; u32 *mapping_table; =20 + if (index) { + dev_err(&bus->spmic->dev, "Unsupported buses count %d detected\n", + index); + return -EINVAL; + } + mapping_table =3D devm_kcalloc(&bus->spmic->dev, pmic_arb->max_periphs, sizeof(*mapping_table), GFP_KERNEL); if (!mapping_table) @@ -1250,11 +1263,17 @@ static int pmic_arb_offset_v2(struct spmi_pmic_arb_= bus *bus, u8 sid, u16 addr, return 0x1000 * pmic_arb->ee + 0x8000 * apid; } =20 -static int pmic_arb_init_apid_v5(struct spmi_pmic_arb_bus *bus) +static int pmic_arb_init_apid_v5(struct spmi_pmic_arb_bus *bus, int index) { struct spmi_pmic_arb *pmic_arb =3D bus->pmic_arb; int ret; =20 + if (index) { + dev_err(&bus->spmic->dev, "Unsupported buses count %d detected\n", + index); + return -EINVAL; + } + bus->base_apid =3D 0; bus->apid_count =3D readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURES) & PMIC_ARB_FEATURES_PERIPH_MASK; @@ -1326,6 +1345,50 @@ static int pmic_arb_get_core_resources_v7(struct pla= tform_device *pdev, return pmic_arb_get_obsrvr_chnls_v2(pdev); } =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_bus *bus, int index) +{ + struct spmi_pmic_arb *pmic_arb =3D bus->pmic_arb; + int ret; + + if (index =3D=3D 0) { + bus->base_apid =3D 0; + bus->apid_count =3D readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURES) & + PMIC_ARB_FEATURES_PERIPH_MASK; + } else if (index =3D=3D 1) { + bus->base_apid =3D readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURES) & + PMIC_ARB_FEATURES_PERIPH_MASK; + bus->apid_count =3D readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURES1) & + PMIC_ARB_FEATURES_PERIPH_MASK; + } else { + dev_err(&bus->spmic->dev, "Unsupported buses count %d detected\n", + bus->id); + return -EINVAL; + } + + if (bus->base_apid + bus->apid_count > pmic_arb->max_periphs) { + dev_err(&bus->spmic->dev, "Unsupported APID count %d detected\n", + bus->base_apid + bus->apid_count); + return -EINVAL; + } + + ret =3D pmic_arb_init_apid_min_max(bus); + if (ret) + return ret; + + ret =3D pmic_arb_read_apid_map_v5(bus); + if (ret) { + dev_err(&bus->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. @@ -1578,7 +1641,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v5 =3D { static const struct pmic_arb_ver_ops pmic_arb_v7 =3D { .ver_str =3D "v7", .get_core_resources =3D pmic_arb_get_core_resources_v7, - .init_apid =3D pmic_arb_init_apid_v5, + .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, @@ -1602,6 +1665,7 @@ static int spmi_pmic_arb_bus_init(struct platform_dev= ice *pdev, struct device_node *node, struct spmi_pmic_arb *pmic_arb) { + int bus_index =3D pmic_arb->buses_available; struct spmi_pmic_arb_bus *bus; struct device *dev =3D &pdev->dev; struct spmi_controller *ctrl; @@ -1620,7 +1684,7 @@ static int spmi_pmic_arb_bus_init(struct platform_dev= ice *pdev, =20 bus =3D spmi_controller_get_drvdata(ctrl); =20 - pmic_arb->bus =3D bus; + pmic_arb->buses[bus_index] =3D bus; =20 raw_spin_lock_init(&bus->lock); =20 @@ -1665,12 +1729,13 @@ static int spmi_pmic_arb_bus_init(struct platform_d= evice *pdev, bus->cnfg =3D cnfg; bus->irq =3D irq; bus->spmic =3D ctrl; + bus->id =3D bus_index; =20 - ret =3D pmic_arb->ver_ops->init_apid(bus); + ret =3D pmic_arb->ver_ops->init_apid(bus, bus_index); if (ret) return ret; =20 - dev_dbg(&pdev->dev, "adding irq domain\n"); + dev_dbg(&pdev->dev, "adding irq domain for bus %d\n", bus_index); =20 bus->domain =3D irq_domain_add_tree(dev->of_node, &pmic_arb_irq_domain_ops, bus); @@ -1683,14 +1748,53 @@ static int spmi_pmic_arb_bus_init(struct platform_d= evice *pdev, pmic_arb_chained_irq, bus); =20 ctrl->dev.of_node =3D node; + dev_set_name(&ctrl->dev, "spmi-%d", bus_index); =20 ret =3D devm_spmi_controller_add(dev, ctrl); if (ret) return ret; =20 + pmic_arb->buses_available++; + return 0; } =20 +static int spmi_pmic_arb_register_buses(struct spmi_pmic_arb *pmic_arb, + struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct device_node *node =3D dev->of_node; + struct device_node *child; + int ret; + + /* legacy mode doesn't provide child node for the bus */ + if (of_device_is_compatible(node, "qcom,spmi-pmic-arb")) + return spmi_pmic_arb_bus_init(pdev, node, pmic_arb); + + for_each_available_child_of_node(node, child) { + if (of_node_name_eq(child, "spmi")) { + ret =3D spmi_pmic_arb_bus_init(pdev, child, pmic_arb); + if (ret) + return ret; + } + } + + return ret; +} + +static void spmi_pmic_arb_deregister_buses(struct spmi_pmic_arb *pmic_arb) +{ + int i; + + for (i =3D 0; i < pmic_arb->buses_available; i++) { + struct spmi_pmic_arb_bus *bus =3D pmic_arb->buses[i]; + + irq_set_chained_handler_and_data(bus->irq, + NULL, NULL); + irq_domain_remove(bus->domain); + } +} + static int spmi_pmic_arb_probe(struct platform_device *pdev) { struct spmi_pmic_arb *pmic_arb; @@ -1760,21 +1864,19 @@ static int spmi_pmic_arb_probe(struct platform_devi= ce *pdev) =20 pmic_arb->ee =3D ee; =20 - return spmi_pmic_arb_bus_init(pdev, dev->of_node, pmic_arb); + return spmi_pmic_arb_register_buses(pmic_arb, pdev); } =20 static void spmi_pmic_arb_remove(struct platform_device *pdev) { struct spmi_pmic_arb *pmic_arb =3D platform_get_drvdata(pdev); - struct spmi_pmic_arb_bus *bus =3D pmic_arb->bus; =20 - irq_set_chained_handler_and_data(bus->irq, - NULL, NULL); - irq_domain_remove(bus->domain); + spmi_pmic_arb_deregister_buses(pmic_arb); } =20 static const struct of_device_id spmi_pmic_arb_match_table[] =3D { { .compatible =3D "qcom,spmi-pmic-arb", }, + { .compatible =3D "qcom,x1e80100-spmi-pmic-arb", }, {}, }; MODULE_DEVICE_TABLE(of, spmi_pmic_arb_match_table); --=20 2.34.1