Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 // Copyright (c) 2018 Synopsys, Inc. and/or its affiliates.
0003 
0004 #include <linux/regmap.h>
0005 #include <linux/i3c/device.h>
0006 #include <linux/i3c/master.h>
0007 #include <linux/module.h>
0008 
0009 static int regmap_i3c_write(void *context, const void *data, size_t count)
0010 {
0011     struct device *dev = context;
0012     struct i3c_device *i3c = dev_to_i3cdev(dev);
0013     struct i3c_priv_xfer xfers[] = {
0014         {
0015             .rnw = false,
0016             .len = count,
0017             .data.out = data,
0018         },
0019     };
0020 
0021     return i3c_device_do_priv_xfers(i3c, xfers, 1);
0022 }
0023 
0024 static int regmap_i3c_read(void *context,
0025                const void *reg, size_t reg_size,
0026                void *val, size_t val_size)
0027 {
0028     struct device *dev = context;
0029     struct i3c_device *i3c = dev_to_i3cdev(dev);
0030     struct i3c_priv_xfer xfers[2];
0031 
0032     xfers[0].rnw = false;
0033     xfers[0].len = reg_size;
0034     xfers[0].data.out = reg;
0035 
0036     xfers[1].rnw = true;
0037     xfers[1].len = val_size;
0038     xfers[1].data.in = val;
0039 
0040     return i3c_device_do_priv_xfers(i3c, xfers, 2);
0041 }
0042 
0043 static const struct regmap_bus regmap_i3c = {
0044     .write = regmap_i3c_write,
0045     .read = regmap_i3c_read,
0046 };
0047 
0048 struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c,
0049                       const struct regmap_config *config,
0050                       struct lock_class_key *lock_key,
0051                       const char *lock_name)
0052 {
0053     return __devm_regmap_init(&i3c->dev, &regmap_i3c, &i3c->dev, config,
0054                   lock_key, lock_name);
0055 }
0056 EXPORT_SYMBOL_GPL(__devm_regmap_init_i3c);
0057 
0058 MODULE_AUTHOR("Vitor Soares <vitor.soares@synopsys.com>");
0059 MODULE_DESCRIPTION("Regmap I3C Module");
0060 MODULE_LICENSE("GPL v2");