1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright(c) 2020 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>
9 #include <linux/soundwire/sdw_registers.h>
12 static int regmap_sdw_mbq_write(void *context
, unsigned int reg
, unsigned int val
)
14 struct device
*dev
= context
;
15 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
18 ret
= sdw_write(slave
, SDW_SDCA_MBQ_CTL(reg
), (val
>> 8) & 0xff);
22 return sdw_write(slave
, reg
, val
& 0xff);
25 static int regmap_sdw_mbq_read(void *context
, unsigned int reg
, unsigned int *val
)
27 struct device
*dev
= context
;
28 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
32 read0
= sdw_read(slave
, reg
);
36 read1
= sdw_read(slave
, SDW_SDCA_MBQ_CTL(reg
));
40 *val
= (read1
<< 8) | read0
;
45 static struct regmap_bus regmap_sdw_mbq
= {
46 .reg_read
= regmap_sdw_mbq_read
,
47 .reg_write
= regmap_sdw_mbq_write
,
48 .reg_format_endian_default
= REGMAP_ENDIAN_LITTLE
,
49 .val_format_endian_default
= REGMAP_ENDIAN_LITTLE
,
52 static int regmap_sdw_mbq_config_check(const struct regmap_config
*config
)
54 /* MBQ-based controls are only 16-bits for now */
55 if (config
->val_bits
!= 16)
58 /* Registers are 32 bits wide */
59 if (config
->reg_bits
!= 32)
62 if (config
->pad_bits
!= 0)
68 struct regmap
*__regmap_init_sdw_mbq(struct sdw_slave
*sdw
,
69 const struct regmap_config
*config
,
70 struct lock_class_key
*lock_key
,
71 const char *lock_name
)
75 ret
= regmap_sdw_mbq_config_check(config
);
79 return __regmap_init(&sdw
->dev
, ®map_sdw_mbq
,
80 &sdw
->dev
, config
, lock_key
, lock_name
);
82 EXPORT_SYMBOL_GPL(__regmap_init_sdw_mbq
);
84 struct regmap
*__devm_regmap_init_sdw_mbq(struct sdw_slave
*sdw
,
85 const struct regmap_config
*config
,
86 struct lock_class_key
*lock_key
,
87 const char *lock_name
)
91 ret
= regmap_sdw_mbq_config_check(config
);
95 return __devm_regmap_init(&sdw
->dev
, ®map_sdw_mbq
,
96 &sdw
->dev
, config
, lock_key
, lock_name
);
98 EXPORT_SYMBOL_GPL(__devm_regmap_init_sdw_mbq
);
100 MODULE_DESCRIPTION("Regmap SoundWire MBQ Module");
101 MODULE_LICENSE("GPL v2");