Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regmap: add i3c bus support

Add basic support for i3c bus.
This is a simple implementation that only give support
for SDR Read and Write commands.

Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Vitor Soares and committed by
Mark Brown
6445500b a188339c

+86 -1
+5 -1
drivers/base/regmap/Kconfig
··· 4 4 # subsystems should select the appropriate symbols. 5 5 6 6 config REGMAP 7 - default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ) 7 + default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ || REGMAP_I3C) 8 8 select IRQ_DOMAIN if REGMAP_IRQ 9 9 bool 10 10 ··· 49 49 config REGMAP_SCCB 50 50 tristate 51 51 depends on I2C 52 + 53 + config REGMAP_I3C 54 + tristate 55 + depends on I3C
+1
drivers/base/regmap/Makefile
··· 16 16 obj-$(CONFIG_REGMAP_W1) += regmap-w1.o 17 17 obj-$(CONFIG_REGMAP_SOUNDWIRE) += regmap-sdw.o 18 18 obj-$(CONFIG_REGMAP_SCCB) += regmap-sccb.o 19 + obj-$(CONFIG_REGMAP_I3C) += regmap-i3c.o
+60
drivers/base/regmap/regmap-i3c.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // Copyright (c) 2018 Synopsys, Inc. and/or its affiliates. 3 + 4 + #include <linux/regmap.h> 5 + #include <linux/i3c/device.h> 6 + #include <linux/i3c/master.h> 7 + #include <linux/module.h> 8 + 9 + static int regmap_i3c_write(void *context, const void *data, size_t count) 10 + { 11 + struct device *dev = context; 12 + struct i3c_device *i3c = dev_to_i3cdev(dev); 13 + struct i3c_priv_xfer xfers[] = { 14 + { 15 + .rnw = false, 16 + .len = count, 17 + .data.out = data, 18 + }, 19 + }; 20 + 21 + return i3c_device_do_priv_xfers(i3c, xfers, 1); 22 + } 23 + 24 + static int regmap_i3c_read(void *context, 25 + const void *reg, size_t reg_size, 26 + void *val, size_t val_size) 27 + { 28 + struct device *dev = context; 29 + struct i3c_device *i3c = dev_to_i3cdev(dev); 30 + struct i3c_priv_xfer xfers[2]; 31 + 32 + xfers[0].rnw = false; 33 + xfers[0].len = reg_size; 34 + xfers[0].data.out = reg; 35 + 36 + xfers[1].rnw = true; 37 + xfers[1].len = val_size; 38 + xfers[1].data.in = val; 39 + 40 + return i3c_device_do_priv_xfers(i3c, xfers, 2); 41 + } 42 + 43 + static struct regmap_bus regmap_i3c = { 44 + .write = regmap_i3c_write, 45 + .read = regmap_i3c_read, 46 + }; 47 + 48 + struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c, 49 + const struct regmap_config *config, 50 + struct lock_class_key *lock_key, 51 + const char *lock_name) 52 + { 53 + return __devm_regmap_init(&i3c->dev, &regmap_i3c, &i3c->dev, config, 54 + lock_key, lock_name); 55 + } 56 + EXPORT_SYMBOL_GPL(__devm_regmap_init_i3c); 57 + 58 + MODULE_AUTHOR("Vitor Soares <vitor.soares@synopsys.com>"); 59 + MODULE_DESCRIPTION("Regmap I3C Module"); 60 + MODULE_LICENSE("GPL v2");
+20
include/linux/regmap.h
··· 25 25 struct clk; 26 26 struct device; 27 27 struct i2c_client; 28 + struct i3c_device; 28 29 struct irq_domain; 29 30 struct slim_device; 30 31 struct spi_device; ··· 625 624 const struct regmap_config *config, 626 625 struct lock_class_key *lock_key, 627 626 const char *lock_name); 627 + struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c, 628 + const struct regmap_config *config, 629 + struct lock_class_key *lock_key, 630 + const char *lock_name); 628 631 /* 629 632 * Wrapper for regmap_init macros to include a unique lockdep key and name 630 633 * for each call. No-op if CONFIG_LOCKDEP is not set. ··· 987 982 #define devm_regmap_init_slimbus(slimbus, config) \ 988 983 __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config, \ 989 984 slimbus, config) 985 + 986 + /** 987 + * devm_regmap_init_i3c() - Initialise managed register map 988 + * 989 + * @i3c: Device that will be interacted with 990 + * @config: Configuration for register map 991 + * 992 + * The return value will be an ERR_PTR() on error or a valid pointer 993 + * to a struct regmap. The regmap will be automatically freed by the 994 + * device management code. 995 + */ 996 + #define devm_regmap_init_i3c(i3c, config) \ 997 + __regmap_lockdep_wrapper(__devm_regmap_init_i3c, #config, \ 998 + i3c, config) 999 + 990 1000 int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk); 991 1001 void regmap_mmio_detach_clk(struct regmap *map); 992 1002 void regmap_exit(struct regmap *map);