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 
regmap_i3c_write(void * context,const void * data,size_t count)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 
regmap_i3c_read(void * context,const void * reg,size_t reg_size,void * val,size_t val_size)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 const struct regmap_bus regmap_i3c = {
44 	.write = regmap_i3c_write,
45 	.read = regmap_i3c_read,
46 };
47 
__devm_regmap_init_i3c(struct i3c_device * i3c,const struct regmap_config * config,struct lock_class_key * lock_key,const char * lock_name)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");
61