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>
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 ®map_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
);
51 return __regmap_init(&slimbus
->dev
, bus
, &slimbus
->dev
, config
,
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
);
66 return __devm_regmap_init(&slimbus
->dev
, bus
, &slimbus
, config
,
69 EXPORT_SYMBOL_GPL(__devm_regmap_init_slimbus
);
71 MODULE_LICENSE("GPL v2");