u-boot-amlogic.groups.io archive mirror
 help / color / mirror / Atom feed
From: Alexey Romanov <avromanov@salutedevices.com>
To: neil.armstrong@linaro.org, narmstrong@baylibre.com,
	sjg@google.com, lukma@denx.de, marex@denx.de
Cc: u-boot-amlogic@groups.io, u-boot@lists.denx.de,
	kernel@sberdevices.ru,
	Alexey Romanov <avromanov@salutedevices.com>
Subject: [PATCH v3 2/8] reset: add support for Amlogic A1 family
Date: Thu, 5 Oct 2023 11:54:23 +0300	[thread overview]
Message-ID: <20231005085434.74755-3-avromanov@salutedevices.com> (raw)
In-Reply-To: <20231005085434.74755-1-avromanov@salutedevices.com>

This patch adds reset support for the Amlogic A1 family.
We add the structure meson_reset_drvdata, which in the future
will allow this driver to be used for other families by declaring
only the correct parameters reg_count and level_offset.

Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 drivers/reset/reset-meson.c | 42 +++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/drivers/reset/reset-meson.c b/drivers/reset/reset-meson.c
index 64bc696f13..9d0c8b354f 100644
--- a/drivers/reset/reset-meson.c
+++ b/drivers/reset/reset-meson.c
@@ -13,18 +13,26 @@
 #include <reset-uclass.h>
 #include <regmap.h>
 #include <linux/bitops.h>
+#include <linux/delay.h>
 
-#define REG_COUNT	8
 #define BITS_PER_REG	32
-#define LEVEL_OFFSET	0x7c
+
+struct meson_reset_drvdata {
+	unsigned int reg_count;
+	unsigned int level_offset;
+};
 
 struct meson_reset_priv {
 	struct regmap *regmap;
+	struct meson_reset_drvdata *drvdata;
 };
 
 static int meson_reset_request(struct reset_ctl *reset_ctl)
 {
-	if (reset_ctl->id > (REG_COUNT * BITS_PER_REG))
+	struct meson_reset_priv *priv = dev_get_priv(reset_ctl->dev);
+	struct meson_reset_drvdata *data = priv->drvdata;
+
+	if (reset_ctl->id > (data->reg_count * BITS_PER_REG))
 		return -EINVAL;
 
 	return 0;
@@ -33,9 +41,10 @@ static int meson_reset_request(struct reset_ctl *reset_ctl)
 static int meson_reset_level(struct reset_ctl *reset_ctl, bool assert)
 {
 	struct meson_reset_priv *priv = dev_get_priv(reset_ctl->dev);
+	struct meson_reset_drvdata *data = priv->drvdata;
 	uint bank = reset_ctl->id / BITS_PER_REG;
 	uint offset = reset_ctl->id % BITS_PER_REG;
-	uint reg_offset = LEVEL_OFFSET + (bank << 2);
+	uint reg_offset = data->level_offset + (bank << 2);
 	uint val;
 
 	regmap_read(priv->regmap, reg_offset, &val);
@@ -64,15 +73,36 @@ struct reset_ops meson_reset_ops = {
 	.rst_deassert = meson_reset_deassert,
 };
 
+static const struct meson_reset_drvdata meson_gxbb_data = {
+	.reg_count = 8,
+	.level_offset = 0x7c,
+};
+
+static const struct meson_reset_drvdata meson_a1_data = {
+	.reg_count = 3,
+	.level_offset = 0x40,
+};
+
 static const struct udevice_id meson_reset_ids[] = {
-	{ .compatible = "amlogic,meson-gxbb-reset" },
-	{ .compatible = "amlogic,meson-axg-reset" },
+	{
+		.compatible = "amlogic,meson-gxbb-reset",
+		.data = (ulong)&meson_gxbb_data,
+	},
+	{
+		.compatible = "amlogic,meson-axg-reset",
+		.data = (ulong)&meson_gxbb_data,
+	},
+	{
+		.compatible = "amlogic,meson-a1-reset",
+		.data = (ulong)&meson_a1_data,
+	},
 	{ }
 };
 
 static int meson_reset_probe(struct udevice *dev)
 {
 	struct meson_reset_priv *priv = dev_get_priv(dev);
+	priv->drvdata = (struct meson_reset_drvdata *)dev_get_driver_data(dev);
 
 	return regmap_init_mem(dev_ofnode(dev), &priv->regmap);
 }
-- 
2.25.1


  parent reply	other threads:[~2023-10-05  8:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-05  8:54 [PATCH v3 0/8] Support USB for Meson A1 Alexey Romanov
2023-10-05  8:54 ` [PATCH v3 1/8] dt-bindings: reset: add Meson A1 reset bindings Alexey Romanov
2023-10-05  8:54 ` Alexey Romanov [this message]
2023-10-05  8:54 ` [PATCH v3 3/8] phy: get rid of raw hex values Alexey Romanov
2023-10-05  8:54 ` [PATCH v3 4/8] phy: move clk enable/disable in init/exit Alexey Romanov
2023-10-05  8:54 ` [PATCH v3 5/8] phy: support Amlogic A1 family Alexey Romanov
2023-10-05  8:54 ` [PATCH v3 6/8] a1: clk: Add missing USB_PHY_IN and USB_PHY gates Alexey Romanov
2023-10-05  8:54 ` [PATCH v3 7/8] dwc3: add support for Amlogic A1 family Alexey Romanov
2023-10-05  8:54 ` [PATCH v3 8/8] ad401: enable USB stack Alexey Romanov
2023-10-05 12:37 ` [PATCH v3 0/8] Support USB for Meson A1 Neil Armstrong

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=20231005085434.74755-3-avromanov@salutedevices.com \
    --to=avromanov@salutedevices.com \
    --cc=kernel@sberdevices.ru \
    --cc=lukma@denx.de \
    --cc=marex@denx.de \
    --cc=narmstrong@baylibre.com \
    --cc=neil.armstrong@linaro.org \
    --cc=sjg@google.com \
    --cc=u-boot-amlogic@groups.io \
    --cc=u-boot@lists.denx.de \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).