Linux 5.1.15
[linux/fpc-iii.git] / drivers / base / regmap / regmap-slimbus.c
blob0968059f1ef57be468c421865a23747fd958b30e
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2017, Linaro Ltd.
4 #include <linux/regmap.h>
5 #include <linux/slimbus.h>
6 #include <linux/module.h>
8 #include "internal.h"
10 static int regmap_slimbus_write(void *context, const void *data, size_t count)
12 struct slim_device *sdev = context;
14 return slim_write(sdev, *(u16 *)data, count - 2, (u8 *)data + 2);
17 static int regmap_slimbus_read(void *context, const void *reg, size_t reg_size,
18 void *val, size_t val_size)
20 struct slim_device *sdev = context;
22 return slim_read(sdev, *(u16 *)reg, val_size, val);
25 static struct regmap_bus regmap_slimbus_bus = {
26 .write = regmap_slimbus_write,
27 .read = regmap_slimbus_read,
28 .reg_format_endian_default = REGMAP_ENDIAN_LITTLE,
29 .val_format_endian_default = REGMAP_ENDIAN_LITTLE,
32 static const struct regmap_bus *regmap_get_slimbus(struct slim_device *slim,
33 const struct regmap_config *config)
35 if (config->val_bits == 8 && config->reg_bits == 16)
36 return &regmap_slimbus_bus;
38 return ERR_PTR(-ENOTSUPP);
41 struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
42 const struct regmap_config *config,
43 struct lock_class_key *lock_key,
44 const char *lock_name)
46 const struct regmap_bus *bus = regmap_get_slimbus(slimbus, config);
48 if (IS_ERR(bus))
49 return ERR_CAST(bus);
51 return __regmap_init(&slimbus->dev, bus, &slimbus->dev, config,
52 lock_key, lock_name);
54 EXPORT_SYMBOL_GPL(__regmap_init_slimbus);
56 struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus,
57 const struct regmap_config *config,
58 struct lock_class_key *lock_key,
59 const char *lock_name)
61 const struct regmap_bus *bus = regmap_get_slimbus(slimbus, config);
63 if (IS_ERR(bus))
64 return ERR_CAST(bus);
66 return __devm_regmap_init(&slimbus->dev, bus, &slimbus, config,
67 lock_key, lock_name);
69 EXPORT_SYMBOL_GPL(__devm_regmap_init_slimbus);
71 MODULE_LICENSE("GPL v2");