1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright(c) 2015-17 Intel Corporation.
4 #include <linux/device.h>
5 #include <linux/errno.h>
6 #include <linux/module.h>
7 #include <linux/regmap.h>
8 #include <linux/soundwire/sdw.h>
11 static int regmap_sdw_write(void *context
, unsigned int reg
, unsigned int val
)
13 struct device
*dev
= context
;
14 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
16 return sdw_write(slave
, reg
, val
);
19 static int regmap_sdw_read(void *context
, unsigned int reg
, unsigned int *val
)
21 struct device
*dev
= context
;
22 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
25 read
= sdw_read(slave
, reg
);
33 static struct regmap_bus regmap_sdw
= {
34 .reg_read
= regmap_sdw_read
,
35 .reg_write
= regmap_sdw_write
,
36 .reg_format_endian_default
= REGMAP_ENDIAN_LITTLE
,
37 .val_format_endian_default
= REGMAP_ENDIAN_LITTLE
,
40 static int regmap_sdw_config_check(const struct regmap_config
*config
)
42 /* All register are 8-bits wide as per MIPI Soundwire 1.0 Spec */
43 if (config
->val_bits
!= 8)
46 /* Registers are 32 bits wide */
47 if (config
->reg_bits
!= 32)
50 if (config
->pad_bits
!= 0)
56 struct regmap
*__regmap_init_sdw(struct sdw_slave
*sdw
,
57 const struct regmap_config
*config
,
58 struct lock_class_key
*lock_key
,
59 const char *lock_name
)
63 ret
= regmap_sdw_config_check(config
);
67 return __regmap_init(&sdw
->dev
, ®map_sdw
,
68 &sdw
->dev
, config
, lock_key
, lock_name
);
70 EXPORT_SYMBOL_GPL(__regmap_init_sdw
);
72 struct regmap
*__devm_regmap_init_sdw(struct sdw_slave
*sdw
,
73 const struct regmap_config
*config
,
74 struct lock_class_key
*lock_key
,
75 const char *lock_name
)
79 ret
= regmap_sdw_config_check(config
);
83 return __devm_regmap_init(&sdw
->dev
, ®map_sdw
,
84 &sdw
->dev
, config
, lock_key
, lock_name
);
86 EXPORT_SYMBOL_GPL(__devm_regmap_init_sdw
);
88 MODULE_DESCRIPTION("Regmap SoundWire Module");
89 MODULE_LICENSE("GPL v2");