From nobody Sat Oct 4 12:47:32 2025 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.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 9B558260592 for ; Mon, 18 Aug 2025 04:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755490250; cv=none; b=d9QveL70flPpADWnSUmeJ1gtOwLM4uUjY0NjyfRmfiMTWPKdtA2m05K2pTGdpeuXYuL5p8nBrBjTiTlGNN6/U/a3ANPW8sKTtgyEwpz01Phyc4KCRjRM0u1eiVWTDRKF90Ioef8SjqdMCM/4EA6XRYd7ltu7TKv/pq13oNZ92Uc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755490250; c=relaxed/simple; bh=2D2pCQzookgwdAAtHFuVK0XP30EwZIqIZ0Ic1dDvTa4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O98rdxaU9QWWmaHvSmzSE2y57djwRzQvBO0OmIfDFzep0jYbDdpP9lRz/pbikzwOyMUDiZ/Nr1hTnhu0vPMVoSTB2Vm9/SNhnh4lNki+VbOzkzK/h1wjosd58DYCMUSVlG2Y4MBiymmAugB7UMOPhV/8p1OQodRJp0/Guz4N2vQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=EAR7uB4B; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="EAR7uB4B" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-32326e202e0so2834086a91.2 for ; Sun, 17 Aug 2025 21:10:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1755490248; x=1756095048; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TIg/1GBTKsBFC54o9wzP/NH34EZtppmVu7UpxaXegaQ=; b=EAR7uB4B0uhBaptLQBBOYmlsjgoXfIWMehzY94FnA7VY6KzZAKjq67Rm+fzsxrN4S1 AN6L9uQOW3pIB2vVs/O5kdcqxHDqt/MTPXfqYAC7VTVczi1gk65t5WpYjJWLIxRrGOAR 3xJxJJhwv8CGHloHO7VKWN3BCsc5I68vX1qYdGVwAOFS8xy9HX+2UA4MktM9ysX4lD9M 2139uLSXSjAgc5RscTgvhyak9rV1GOv+dxt88LC57q0G8xmtW79k1R2o5LDHGwLfGIwc YSGxKO4hEg13Arv/TB+cK+PHiXsGlBcJZDBy+M0+aD4leFhb0pVJkxqiJVnrhKOyqghT hYQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755490248; x=1756095048; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TIg/1GBTKsBFC54o9wzP/NH34EZtppmVu7UpxaXegaQ=; b=o62IvAyeAO48qsKmqNmfYBPHy5BlJJCIxI9JSkfWqfMgqS3cpgVNYl1ziUnmTmmjyB fp1i2Sp4xN2/2UTr1t5vEgLR1koLrzKsjCSzf50AK8pQraESA6PeHkrSLaO8XwTNtIpc N/72sAhbXt+R+qfOkcZuGVHfnGb91JEr32sLRaLRqrf2YLsP/G8GKLXWZKJg2Uh0H13j fPX34xaKepo9uDPSKhMcGPlag2OTmPSP0npt/oLu5Dztcg9kpH62/sUtZlO9yLlUD1Ff SrnQju1oZGr3If+e5Cgdf3tOao5HXQckWSCx5tfeXgxoiFJIhvXQDb4pvrW2m5hzV4e6 tQYg== X-Forwarded-Encrypted: i=1; AJvYcCX+N4nOnRHa/p6OiqDmvlyO9pMNwM8owx8Mj/ldJob82pUfhG37a69UZmiROg67q+59AOKOgRzoJK9o5sk=@vger.kernel.org X-Gm-Message-State: AOJu0YzptHF6KW0ykidvvSzz8th5he0ZxZKaDGZJY+krk7FllDQBkYtJ 8ay8f+VrDuvmDCPD1EQI8dajv4EC36hsX3wN81panbktAF9C8rBPeGZfjD+eGjSoMMk= X-Gm-Gg: ASbGnctqVEWVRaP1Rwzx/sN58ZiB4I4uqwNZKTqYsbpDi14tvqlt1Pio+w3H2H5lbv4 j1jJgtXcADEJELjuwZJjx6qXBUxttRS/SpL6Bd0/znJ4IBZTJ4kfsSbF0pAEb+B/i0aegp7XPNr y7X+3z2Uuo0fC+d46PR4FnE0P30SPnIaxbN4tIN6L1NB8XZLpJvZWh3jCOwtjkcPAz9xSvY0adC 257ULOsviQOr5KH6HKuxlMcjwqqKGa9sgZgCId9okiCnZxSr+1AyLXJH3Tt5/Q1P7KYl6vb63X3 6uONDt3b3fQH164YV+bBR0G7ea06kWKWhYvBYSC2kdEWH54nzB515A2NwvKTdYbnN3sWdXazAJf PT+yG14SoivC22ATzVd3ZIGWmpOZbu/45QCIEv05GciNew9ZzrB1XGMuAVJd+IqaY X-Google-Smtp-Source: AGHT+IHJ3B7/FGCREPXx9KMsbgx8NNPqJm1e+gxc7+HhFbA/BztdLkupGr7S+vIlvSPnuVpfBIXkZw== X-Received: by 2002:a17:90b:1d05:b0:321:38e0:d591 with SMTP id 98e67ed59e1d1-3234dc3b068mr11877319a91.17.1755490247738; Sun, 17 Aug 2025 21:10:47 -0700 (PDT) Received: from localhost.localdomain ([122.171.17.53]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32343c70356sm6560972a91.25.2025.08.17.21.10.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Aug 2025 21:10:47 -0700 (PDT) From: Anup Patel To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jassi Brar , Thomas Gleixner , "Rafael J . Wysocki" , Mika Westerberg , Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Cc: Palmer Dabbelt , Paul Walmsley , Alexandre Ghiti , Len Brown , Sunil V L , Rahul Pathak , Leyfoon Tan , Atish Patra , Andrew Jones , Samuel Holland , Anup Patel , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH v10 05/24] mailbox: Allow controller specific mapping using fwnode Date: Mon, 18 Aug 2025 09:39:01 +0530 Message-ID: <20250818040920.272664-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250818040920.272664-1-apatel@ventanamicro.com> References: <20250818040920.272664-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce optional fw_node() callback which allows a mailbox controller driver to provide controller specific mapping using fwnode. The Linux OF framework already implements fwnode operations for the Linux DD framework so the fw_xlate() callback works fine with device tree as well. Acked-by: Jassi Brar Reviewed-by: Andy Shevchenko Signed-off-by: Anup Patel --- drivers/mailbox/mailbox.c | 65 ++++++++++++++++++------------ include/linux/mailbox_controller.h | 3 ++ 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 5cd8ae222073..2acc6ec229a4 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -15,6 +15,7 @@ #include #include #include +#include #include =20 #include "mailbox.h" @@ -383,34 +384,56 @@ EXPORT_SYMBOL_GPL(mbox_bind_client); */ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) { - struct device *dev =3D cl->dev; + struct fwnode_reference_args fwspec; + struct fwnode_handle *fwnode; struct mbox_controller *mbox; struct of_phandle_args spec; struct mbox_chan *chan; + struct device *dev; + unsigned int i; int ret; =20 - if (!dev || !dev->of_node) { - pr_debug("%s: No owner device node\n", __func__); + dev =3D cl->dev; + if (!dev) { + pr_debug("No owner device\n"); return ERR_PTR(-ENODEV); } =20 - ret =3D of_parse_phandle_with_args(dev->of_node, "mboxes", "#mbox-cells", - index, &spec); + fwnode =3D dev_fwnode(dev); + if (!fwnode) { + dev_dbg(dev, "No owner fwnode\n"); + return ERR_PTR(-ENODEV); + } + + ret =3D fwnode_property_get_reference_args(fwnode, "mboxes", "#mbox-cells= ", + 0, index, &fwspec); if (ret) { - dev_err(dev, "%s: can't parse \"mboxes\" property\n", __func__); + dev_err(dev, "%s: can't parse \"%s\" property\n", __func__, "mboxes"); return ERR_PTR(ret); } =20 + spec.np =3D to_of_node(fwspec.fwnode); + spec.args_count =3D fwspec.nargs; + for (i =3D 0; i < spec.args_count; i++) + spec.args[i] =3D fwspec.args[i]; + scoped_guard(mutex, &con_mutex) { chan =3D ERR_PTR(-EPROBE_DEFER); - list_for_each_entry(mbox, &mbox_cons, node) - if (mbox->dev->of_node =3D=3D spec.np) { - chan =3D mbox->of_xlate(mbox, &spec); - if (!IS_ERR(chan)) - break; + list_for_each_entry(mbox, &mbox_cons, node) { + if (device_match_fwnode(mbox->dev, fwspec.fwnode)) { + if (mbox->fw_xlate) { + chan =3D mbox->fw_xlate(mbox, &fwspec); + if (!IS_ERR(chan)) + break; + } else if (mbox->of_xlate) { + chan =3D mbox->of_xlate(mbox, &spec); + if (!IS_ERR(chan)) + break; + } } + } =20 - of_node_put(spec.np); + fwnode_handle_put(fwspec.fwnode); =20 if (IS_ERR(chan)) return chan; @@ -427,15 +450,8 @@ EXPORT_SYMBOL_GPL(mbox_request_channel); struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, const char *name) { - struct device_node *np =3D cl->dev->of_node; - int index; - - if (!np) { - dev_err(cl->dev, "%s() currently only supports DT\n", __func__); - return ERR_PTR(-EINVAL); - } + int index =3D device_property_match_string(cl->dev, "mbox-names", name); =20 - index =3D of_property_match_string(np, "mbox-names", name); if (index < 0) { dev_err(cl->dev, "%s() could not locate channel named \"%s\"\n", __func__, name); @@ -470,9 +486,8 @@ void mbox_free_channel(struct mbox_chan *chan) } EXPORT_SYMBOL_GPL(mbox_free_channel); =20 -static struct mbox_chan * -of_mbox_index_xlate(struct mbox_controller *mbox, - const struct of_phandle_args *sp) +static struct mbox_chan *fw_mbox_index_xlate(struct mbox_controller *mbox, + const struct fwnode_reference_args *sp) { int ind =3D sp->args[0]; =20 @@ -523,8 +538,8 @@ int mbox_controller_register(struct mbox_controller *mb= ox) spin_lock_init(&chan->lock); } =20 - if (!mbox->of_xlate) - mbox->of_xlate =3D of_mbox_index_xlate; + if (!mbox->fw_xlate && !mbox->of_xlate) + mbox->fw_xlate =3D fw_mbox_index_xlate; =20 scoped_guard(mutex, &con_mutex) list_add_tail(&mbox->node, &mbox_cons); diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_con= troller.h index ad01c4082358..80a427c7ca29 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -66,6 +66,7 @@ struct mbox_chan_ops { * no interrupt rises. Ignored if 'txdone_irq' is set. * @txpoll_period: If 'txdone_poll' is in effect, the API polls for * last TX's status after these many millisecs + * @fw_xlate: Controller driver specific mapping of channel via fwnode * @of_xlate: Controller driver specific mapping of channel via DT * @poll_hrt: API private. hrtimer used to poll for TXDONE on all * channels. @@ -79,6 +80,8 @@ struct mbox_controller { bool txdone_irq; bool txdone_poll; unsigned txpoll_period; + struct mbox_chan *(*fw_xlate)(struct mbox_controller *mbox, + const struct fwnode_reference_args *sp); struct mbox_chan *(*of_xlate)(struct mbox_controller *mbox, const struct of_phandle_args *sp); /* Internal to API */ --=20 2.43.0