Re: [PATCH v2 2/2] i3c: master: Add driver for Analog Devices I3C Controller IP
From: ALOK TIWARI <hidden>
Date: 2025-06-06 20:34:06
Also in:
linux-i3c, lkml
quoted hunk ↗ jump to hunk
new file mode 100644 index 0000000000000000000000000000000000000000..b3799071573f4066eb14123c94ee599cc6331b3d--- /dev/null +++ b/drivers/i3c/master/adi-i3c-master.c@@ -0,0 +1,1037 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * I3C Controller driver + * Copyright 2025 Analog Devices Inc. + * Author: Jorge Marques <jorge.marques@analog.com> + */ + +#include <linux/bitops.h> +#include <linux/bitfield.h> +#include <linux/clk.h> +#include <linux/err.h> +#include <linux/errno.h> +#include <linux/i3c/master.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> + +#define VERSION_MAJOR(x) ((u32)FIELD_GET(GENMASK(23, 16), (x))) +#define VERSION_MINOR(x) ((u32)FIELD_GET(GENMASK(15, 8), (x))) +#define VERSION_PATCH(x) ((u32)FIELD_GET(GENMASK(7, 0), (x))) + +#define MAX_DEVS 16 + +#define REG_VERSION 0x000 +#define REG_ENABLE 0x040 +#define REG_IRQ_MASK 0x080 +#define REG_IRQ_PENDING 0x084 +#define REG_IRQ_PEDING_CMDR BIT(5) +#define REG_IRQ_PEDING_IBI ((u32)BIT(6)) +#define REG_IRQ_PEDING_DAA BIT(7)
typo PEDING -> PENDING
+#define REG_CMD_FIFO 0x0d4 +#define REG_CMD_FIFO_0_IS_CCC BIT(22) +#define REG_CMD_FIFO_0_BCAST BIT(21) +#define REG_CMD_FIFO_0_SR BIT(20) +#define REG_CMD_FIFO_0_LEN(l) FIELD_PREP(GENMASK(19, 8), (l)) +#define REG_CMD_FIFO_0_LEN_MAX 4095 +#define REG_CMD_FIFO_0_DEV_ADDR(a) FIELD_PREP(GENMASK(7, 1), a) +#define REG_CMD_FIFO_0_RNW BIT(0) +#define REG_CMD_FIFO_1_CCC(id) FIELD_PREP(GENMASK(7, 0), (id))
[snip]
+
+static int adi_i3c_master_priv_xfers(struct i3c_dev_desc *dev,
+ struct i3c_priv_xfer *xfers,
+ int nxfers)
+{
+ struct i3c_master_controller *m = i3c_dev_get_master(dev);
+ struct adi_i3c_master *master = to_adi_i3c_master(m);
+ struct adi_i3c_xfer *xfer;
+ int i, ret;
+
+ for (i = 0; i < nxfers; i++) {
+ if (xfers[i].len > REG_CMD_FIFO_0_LEN_MAX)
+ return -EOPNOTSUPP;
+ }
+
+ if (!nxfers)
+ return 0;this can move before for
+ + xfer = adi_i3c_master_alloc_xfer(master, nxfers); + if (!xfer) + return -ENOMEM;
Thanks alok