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_byte_reg_read(void *context
, unsigned int reg
,
13 struct slim_device
*sdev
= context
;
16 v
= slim_readb(sdev
, reg
);
26 static int regmap_slimbus_byte_reg_write(void *context
, unsigned int reg
,
29 struct slim_device
*sdev
= context
;
31 return slim_writeb(sdev
, reg
, val
);
34 static struct regmap_bus regmap_slimbus_bus
= {
35 .reg_write
= regmap_slimbus_byte_reg_write
,
36 .reg_read
= regmap_slimbus_byte_reg_read
,
37 .reg_format_endian_default
= REGMAP_ENDIAN_LITTLE
,
38 .val_format_endian_default
= REGMAP_ENDIAN_LITTLE
,
41 static const struct regmap_bus
*regmap_get_slimbus(struct slim_device
*slim
,
42 const struct regmap_config
*config
)
44 if (config
->val_bits
== 8 && config
->reg_bits
== 8)
45 return ®map_slimbus_bus
;
47 return ERR_PTR(-ENOTSUPP
);
50 struct regmap
*__regmap_init_slimbus(struct slim_device
*slimbus
,
51 const struct regmap_config
*config
,
52 struct lock_class_key
*lock_key
,
53 const char *lock_name
)
55 const struct regmap_bus
*bus
= regmap_get_slimbus(slimbus
, config
);
60 return __regmap_init(&slimbus
->dev
, bus
, &slimbus
->dev
, config
,
63 EXPORT_SYMBOL_GPL(__regmap_init_slimbus
);
65 struct regmap
*__devm_regmap_init_slimbus(struct slim_device
*slimbus
,
66 const struct regmap_config
*config
,
67 struct lock_class_key
*lock_key
,
68 const char *lock_name
)
70 const struct regmap_bus
*bus
= regmap_get_slimbus(slimbus
, config
);
75 return __devm_regmap_init(&slimbus
->dev
, bus
, &slimbus
, config
,
78 EXPORT_SYMBOL_GPL(__devm_regmap_init_slimbus
);
80 MODULE_LICENSE("GPL v2");