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