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