From: Alexander Shiyan <eagle.alexander923@gmail.com>
To: barebox@lists.infradead.org
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>
Subject: [PATCH v2 2/3] aiodev: rockchip_saradc: Prepare driver to add support for other SARADC variants
Date: Tue, 21 Jan 2025 15:17:59 +0300 [thread overview]
Message-ID: <20250121121800.2806881-2-eagle.alexander923@gmail.com> (raw)
In-Reply-To: <20250121121800.2806881-1-eagle.alexander923@gmail.com>
Let's make separate hardware-dependent calls to allow adding
different SARADC variants.
Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
drivers/aiodev/rockchip_saradc.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/drivers/aiodev/rockchip_saradc.c b/drivers/aiodev/rockchip_saradc.c
index 2e77d79290..aac4a65218 100644
--- a/drivers/aiodev/rockchip_saradc.c
+++ b/drivers/aiodev/rockchip_saradc.c
@@ -24,9 +24,13 @@
#define SARADC_TIMEOUT_NS (100 * MSECOND)
+struct rockchip_saradc_data;
+
struct rockchip_saradc_cfg {
unsigned int num_bits;
unsigned int num_channels;
+ void (*init)(struct rockchip_saradc_data *data);
+ int (*read)(struct aiochannel *chan, int *val);
};
struct rockchip_saradc_data {
@@ -60,7 +64,12 @@ static void rockchip_saradc_reset_controller(struct reset_control *reset)
reset_control_deassert(reset);
}
-static int rockchip_saradc_read(struct aiochannel *chan, int *val)
+static void rockchip_saradc_init_v1(struct rockchip_saradc_data *data)
+{
+ rockchip_saradc_reg_wr(data, 0, SARADC_CTRL);
+};
+
+static int rockchip_saradc_read_v1(struct aiochannel *chan, int *val)
{
struct rockchip_saradc_data *data;
u32 value = 0;
@@ -103,7 +112,7 @@ static int rockchip_saradc_probe(struct device *dev)
data->config = device_get_match_data(dev);
data->aiodev.hwdev = dev;
- data->aiodev.read = rockchip_saradc_read;
+ data->aiodev.read = data->config->read;
data->base = dev_request_mem_region(dev, 0);
if (IS_ERR(data->base)) {
@@ -170,7 +179,8 @@ static int rockchip_saradc_probe(struct device *dev)
data->channels[i].unit = "mV";
}
- rockchip_saradc_reg_wr(data, 0, SARADC_CTRL);
+ if (data->config->init)
+ data->config->init(data);
data->reset = reset_control_get(dev, "saradc-apb");
if (IS_ERR(data->reset))
@@ -199,6 +209,8 @@ static int rockchip_saradc_probe(struct device *dev)
static const struct rockchip_saradc_cfg rk3568_saradc_cfg = {
.num_bits = 10,
.num_channels = 8,
+ .init = rockchip_saradc_init_v1,
+ .read = rockchip_saradc_read_v1,
};
static const struct of_device_id of_rockchip_saradc_match[] = {
--
2.38.2
next prev parent reply other threads:[~2025-01-21 12:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-21 12:17 [PATCH v2 1/3] aiodev: rockchip_saradc: Add reset control support Alexander Shiyan
2025-01-21 12:17 ` Alexander Shiyan [this message]
2025-01-21 12:18 ` [PATCH v2 3/3] aiodev: rockchip_saradc: Add support for RK3588 Alexander Shiyan
2025-01-22 7:41 ` [PATCH v2 1/3] aiodev: rockchip_saradc: Add reset control support Sascha Hauer
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=20250121121800.2806881-2-eagle.alexander923@gmail.com \
--to=eagle.alexander923@gmail.com \
--cc=barebox@lists.infradead.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