^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) // Copyright (c) 2018 Synopsys, Inc. and/or its affiliates.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/i3c/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/i3c/master.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) static int regmap_i3c_write(void *context, const void *data, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) struct device *dev = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) struct i3c_device *i3c = dev_to_i3cdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) struct i3c_priv_xfer xfers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) .rnw = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) .len = count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) .data.out = data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) return i3c_device_do_priv_xfers(i3c, xfers, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static int regmap_i3c_read(void *context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) const void *reg, size_t reg_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) void *val, size_t val_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct device *dev = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct i3c_device *i3c = dev_to_i3cdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct i3c_priv_xfer xfers[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) xfers[0].rnw = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) xfers[0].len = reg_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) xfers[0].data.out = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) xfers[1].rnw = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) xfers[1].len = val_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) xfers[1].data.in = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return i3c_device_do_priv_xfers(i3c, xfers, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static struct regmap_bus regmap_i3c = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .write = regmap_i3c_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .read = regmap_i3c_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) const struct regmap_config *config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct lock_class_key *lock_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) const char *lock_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return __devm_regmap_init(&i3c->dev, ®map_i3c, &i3c->dev, config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) lock_key, lock_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) EXPORT_SYMBOL_GPL(__devm_regmap_init_i3c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) MODULE_AUTHOR("Vitor Soares <vitor.soares@synopsys.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) MODULE_DESCRIPTION("Regmap I3C Module");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) MODULE_LICENSE("GPL v2");