From: Chen-Yu Tsai <wens@kernel.org>
To: Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej@kernel.org>,
Samuel Holland <samuel@sholland.org>
Cc: devicetree@vger.kernel.org, linux-sunxi@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 5/7] soc: sunxi: sram: Support claiming multiple regions per device
Date: Wed, 25 Mar 2026 00:43:53 +0800 [thread overview]
Message-ID: <20260324164357.1607247-6-wens@kernel.org> (raw)
In-Reply-To: <20260324164357.1607247-1-wens@kernel.org>
On the H616, the video engine needs to claim two SRAM regions.
Support claiming multiple regions per device.
Signed-off-by: Chen-Yu Tsai <wens@kernel.org>
---
drivers/soc/sunxi/sunxi_sram.c | 164 +++++++++++++++++++--------------
1 file changed, 96 insertions(+), 68 deletions(-)
diff --git a/drivers/soc/sunxi/sunxi_sram.c b/drivers/soc/sunxi/sunxi_sram.c
index aba155379ccc..4d81897179e7 100644
--- a/drivers/soc/sunxi/sunxi_sram.c
+++ b/drivers/soc/sunxi/sunxi_sram.c
@@ -165,79 +165,48 @@ static inline struct sunxi_sram_desc *to_sram_desc(const struct sunxi_sram_data
return container_of(data, struct sunxi_sram_desc, data);
}
-static const struct sunxi_sram_data *sunxi_sram_of_parse(struct device_node *node,
- unsigned int *reg_value)
+static const struct sunxi_sram_data *sunxi_sram_get_match(struct device_node *np, u8 val,
+ unsigned int *reg_value)
{
const struct of_device_id *match;
const struct sunxi_sram_data *data;
const struct sunxi_sram_func *func;
- struct of_phandle_args args;
- u8 val;
- int ret;
-
- ret = of_parse_phandle_with_fixed_args(node, "allwinner,sram", 1, 0,
- &args);
- if (ret)
- return ERR_PTR(ret);
- if (!of_device_is_available(args.np)) {
- ret = -EBUSY;
- goto err;
- }
+ if (!of_device_is_available(np))
+ return ERR_PTR(-ENODEV);
- val = args.args[0];
-
- match = of_match_node(sunxi_sram_dt_ids, args.np);
- if (!match) {
- ret = -EINVAL;
- goto err;
- }
+ match = of_match_node(sunxi_sram_dt_ids, np);
+ if (!match)
+ return ERR_PTR(-ENODEV);
data = match->data;
- if (!data) {
- ret = -EINVAL;
- goto err;
- }
-
- for (func = data->func; func->func; func++) {
- if (val == func->val) {
- if (reg_value)
- *reg_value = func->reg_val;
+ if (!data)
+ return ERR_PTR(-EINVAL);
+ for (func = data->func; func->func; func++)
+ if (val == func->val)
break;
- }
- }
- if (!func->func) {
- ret = -EINVAL;
- goto err;
- }
+ if (!func->func)
+ return ERR_PTR(-EINVAL);
- of_node_put(args.np);
- return match->data;
+ if (reg_value)
+ *reg_value = func->reg_val;
-err:
- of_node_put(args.np);
- return ERR_PTR(ret);
+ return data;
}
-int sunxi_sram_claim(struct device *dev)
+#define SUNXI_SRAM_PROP "allwinner,sram"
+#define SUNXI_SRAM_CELLS 1
+
+static int sunxi_sram_claim_one(struct device_node *np, u8 arg)
{
const struct sunxi_sram_data *sram_data;
struct sunxi_sram_desc *sram_desc;
unsigned int device;
u32 val, mask;
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- if (!base)
- return -EPROBE_DEFER;
-
- if (!dev || !dev->of_node)
- return -EINVAL;
-
- sram_data = sunxi_sram_of_parse(dev->of_node, &device);
+ sram_data = sunxi_sram_get_match(np, arg, &device);
if (IS_ERR(sram_data))
return PTR_ERR(sram_data);
@@ -248,33 +217,28 @@ int sunxi_sram_claim(struct device *dev)
if (sram_desc->claim_cnt) {
if (!WARN_ON(sram_desc->claim_cnt == U8_MAX))
sram_desc->claim_cnt++;
- spin_unlock(&sram_lock);
- return 0;
+ } else {
+ mask = GENMASK(sram_data->offset + sram_data->width - 1,
+ sram_data->offset);
+ val = readl(base + sram_data->reg);
+ val &= ~mask;
+ writel(val | ((device << sram_data->offset) & mask),
+ base + sram_data->reg);
+
+ sram_desc->claim_cnt++;
}
- mask = GENMASK(sram_data->offset + sram_data->width - 1,
- sram_data->offset);
- val = readl(base + sram_data->reg);
- val &= ~mask;
- writel(val | ((device << sram_data->offset) & mask),
- base + sram_data->reg);
-
- sram_desc->claim_cnt++;
spin_unlock(&sram_lock);
return 0;
}
-EXPORT_SYMBOL(sunxi_sram_claim);
-void sunxi_sram_release(struct device *dev)
+static void sunxi_sram_release_one(struct device_node *np, u8 arg)
{
const struct sunxi_sram_data *sram_data;
struct sunxi_sram_desc *sram_desc;
- if (!dev || !dev->of_node)
- return;
-
- sram_data = sunxi_sram_of_parse(dev->of_node, NULL);
+ sram_data = sunxi_sram_get_match(np, arg, NULL);
if (IS_ERR(sram_data))
return;
@@ -285,6 +249,70 @@ void sunxi_sram_release(struct device *dev)
sram_desc->claim_cnt--;
spin_unlock(&sram_lock);
}
+
+int sunxi_sram_claim(struct device *dev)
+{
+ struct of_phandle_iterator it;
+ int err;
+ int count = 0;
+
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+
+ if (!base)
+ return -EPROBE_DEFER;
+
+ if (!dev || !dev->of_node)
+ return -EINVAL;
+
+ of_for_each_phandle(&it, err, dev->of_node, SUNXI_SRAM_PROP,
+ NULL, SUNXI_SRAM_CELLS) {
+ u32 args[SUNXI_SRAM_CELLS];
+
+ of_phandle_iterator_args(&it, args, SUNXI_SRAM_CELLS);
+
+ err = sunxi_sram_claim_one(it.node, args[0]);
+ if (err)
+ goto err;
+
+ count++;
+ }
+
+ if (count == 0)
+ return -ENOENT;
+
+ return 0;
+
+err:
+ while (count--) {
+ struct of_phandle_args args;
+
+ of_parse_phandle_with_fixed_args(dev->of_node, SUNXI_SRAM_PROP,
+ SUNXI_SRAM_CELLS, count, &args);
+ sunxi_sram_release_one(args.np, args.args[0]);
+ }
+
+ return err;
+}
+EXPORT_SYMBOL(sunxi_sram_claim);
+
+void sunxi_sram_release(struct device *dev)
+{
+ struct of_phandle_iterator it;
+ int err;
+
+ if (!dev || !dev->of_node)
+ return;
+
+ of_for_each_phandle(&it, err, dev->of_node, SUNXI_SRAM_PROP,
+ NULL, SUNXI_SRAM_CELLS) {
+ u32 args[SUNXI_SRAM_CELLS];
+
+ of_phandle_iterator_args(&it, args, SUNXI_SRAM_CELLS);
+
+ sunxi_sram_release_one(it.node, args[0]);
+ }
+}
EXPORT_SYMBOL(sunxi_sram_release);
struct sunxi_sramc_variant {
--
2.47.3
next prev parent reply other threads:[~2026-03-24 16:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-24 16:43 [PATCH 0/7] soc: sunxi: sram: Add H616 SRAM support Chen-Yu Tsai
2026-03-24 16:43 ` [PATCH 1/7] dt-bindings: sram: Document Allwinner H616 VE SRAM Chen-Yu Tsai
2026-03-25 0:22 ` Jernej Škrabec
2026-03-24 16:43 ` [PATCH 2/7] dt-bindings: sram: sunxi-sram: Add H616 SRAM regions Chen-Yu Tsai
2026-03-25 0:23 ` Jernej Škrabec
2026-03-24 16:43 ` [PATCH 3/7] soc: sunxi: sram: Const-ify sunxi_sram_func data and references Chen-Yu Tsai
2026-03-25 0:24 ` Jernej Škrabec
2026-03-24 16:43 ` [PATCH 4/7] soc: sunxi: sram: Allow SRAM to be claimed multiple times Chen-Yu Tsai
2026-03-25 0:25 ` Jernej Škrabec
2026-03-24 16:43 ` Chen-Yu Tsai [this message]
2026-03-25 0:28 ` [PATCH 5/7] soc: sunxi: sram: Support claiming multiple regions per device Jernej Škrabec
2026-03-24 16:43 ` [PATCH 6/7] soc: sunxi: sram: Add H616 SRAM regions Chen-Yu Tsai
2026-03-25 0:29 ` Jernej Škrabec
2026-03-24 16:43 ` [PATCH 7/7] arm64: dts: allwinner: sun50i-h616: Add SRAM nodes Chen-Yu Tsai
2026-03-25 0:30 ` Jernej Škrabec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260324164357.1607247-6-wens@kernel.org \
--to=wens@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jernej@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=robh@kernel.org \
--cc=samuel@sholland.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox