From: Alexander Shiyan <eagle.alexander923@gmail.com>
To: barebox@lists.infradead.org
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>
Subject: [PATCH v2 3/3] aiodev: rockchip_saradc: Add support for RK3588
Date: Tue, 21 Jan 2025 15:18:00 +0300 [thread overview]
Message-ID: <20250121121800.2806881-3-eagle.alexander923@gmail.com> (raw)
In-Reply-To: <20250121121800.2806881-1-eagle.alexander923@gmail.com>
This adds RK3588 SARADC support to the driver.
Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
drivers/aiodev/rockchip_saradc.c | 81 +++++++++++++++++++++++++++-----
1 file changed, 69 insertions(+), 12 deletions(-)
diff --git a/drivers/aiodev/rockchip_saradc.c b/drivers/aiodev/rockchip_saradc.c
index aac4a65218..152d38ecc5 100644
--- a/drivers/aiodev/rockchip_saradc.c
+++ b/drivers/aiodev/rockchip_saradc.c
@@ -9,18 +9,30 @@
#include <common.h>
#include <aiodev.h>
#include <regulator.h>
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/reset.h>
-#define SARADC_DATA 0x00
-
-#define SARADC_CTRL 0x08
-#define SARADC_CTRL_IRQ_STATUS (1 << 6)
-#define SARADC_CTRL_IRQ_ENABLE (1 << 5)
-#define SARADC_CTRL_POWER_CTRL (1 << 3)
-#define SARADC_CTRL_CHN_MASK 0x07
-
-#define SARADC_DLY_PU_SOC 0x0c
+/* v1 registers */
+#define SARADC_DATA 0x00
+#define SARADC_CTRL 0x08
+# define SARADC_CTRL_IRQ_STATUS (1 << 6)
+# define SARADC_CTRL_IRQ_ENABLE (1 << 5)
+# define SARADC_CTRL_POWER_CTRL (1 << 3)
+#define SARADC_CTRL_CHN_MASK 0x07
+#define SARADC_DLY_PU_SOC 0x0c
+
+/* v2 registers */
+#define SARADC2_CONV_CON 0x000
+# define SARADC2_CONV_CHANNELS GENMASK(3, 0)
+# define SARADC2_START BIT(4)
+# define SARADC2_SINGLE_MODE BIT(5)
+#define SARADC_T_PD_SOC 0x004
+#define SARADC_T_DAS_SOC 0x00c
+#define SARADC2_END_INT_EN 0x104
+# define SARADC2_EN_END_INT BIT(0)
+#define SARADC2_END_INT_ST 0x110
+#define SARADC2_DATA_BASE 0x120
#define SARADC_TIMEOUT_NS (100 * MSECOND)
@@ -72,9 +84,7 @@ static void rockchip_saradc_init_v1(struct rockchip_saradc_data *data)
static int rockchip_saradc_read_v1(struct aiochannel *chan, int *val)
{
struct rockchip_saradc_data *data;
- u32 value = 0;
- u32 control = 0;
- u32 mask;
+ u32 value, control, mask;
u64 start;
data = container_of(chan->aiodev, struct rockchip_saradc_data, aiodev);
@@ -103,6 +113,46 @@ static int rockchip_saradc_read_v1(struct aiochannel *chan, int *val)
return 0;
}
+static int rockchip_saradc_read_v2(struct aiochannel *chan, int *val)
+{
+ struct rockchip_saradc_data *data;
+ u32 value, status, mask;
+ u64 start;
+
+ data = container_of(chan->aiodev, struct rockchip_saradc_data, aiodev);
+
+ rockchip_saradc_reset_controller(data->reset);
+
+ rockchip_saradc_reg_wr(data, 0xc, SARADC_T_DAS_SOC);
+ rockchip_saradc_reg_wr(data, 0x20, SARADC_T_PD_SOC);
+ value = FIELD_PREP(SARADC2_EN_END_INT, 1);
+ value |= SARADC2_EN_END_INT << 16;
+ rockchip_saradc_reg_wr(data, value, SARADC2_END_INT_EN);
+ value = FIELD_PREP(SARADC2_START, 1) |
+ FIELD_PREP(SARADC2_SINGLE_MODE, 1) |
+ FIELD_PREP(SARADC2_CONV_CHANNELS, chan->index);
+ value |= (SARADC2_START | SARADC2_SINGLE_MODE | SARADC2_CONV_CHANNELS) << 16;
+ rockchip_saradc_reg_wr(data, value, SARADC2_CONV_CON);
+
+ start = get_time_ns();
+ do {
+ status = rockchip_saradc_reg_rd(data, SARADC2_END_INT_ST);
+
+ if (is_timeout(start, SARADC_TIMEOUT_NS))
+ return -ETIMEDOUT;
+ } while (!(status & SARADC2_EN_END_INT));
+
+ mask = (1 << data->config->num_bits) - 1;
+ value = rockchip_saradc_reg_rd(data, SARADC2_DATA_BASE + chan->index * 4);
+ value &= mask;
+
+ rockchip_saradc_reg_wr(data, SARADC2_EN_END_INT, SARADC2_END_INT_ST);
+
+ *val = (value * data->ref_voltage_mv) / mask;
+
+ return 0;
+}
+
static int rockchip_saradc_probe(struct device *dev)
{
struct rockchip_saradc_data *data;
@@ -213,8 +263,15 @@ static const struct rockchip_saradc_cfg rk3568_saradc_cfg = {
.read = rockchip_saradc_read_v1,
};
+static const struct rockchip_saradc_cfg rk3588_saradc_cfg = {
+ .num_bits = 12,
+ .num_channels = 8,
+ .read = rockchip_saradc_read_v2,
+};
+
static const struct of_device_id of_rockchip_saradc_match[] = {
{ .compatible = "rockchip,rk3568-saradc", .data = &rk3568_saradc_cfg },
+ { .compatible = "rockchip,rk3588-saradc", .data = &rk3588_saradc_cfg },
{ /* end */ }
};
MODULE_DEVICE_TABLE(of, 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 ` [PATCH v2 2/3] aiodev: rockchip_saradc: Prepare driver to add support for other SARADC variants Alexander Shiyan
2025-01-21 12:18 ` Alexander Shiyan [this message]
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-3-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