1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright(c) 2015-17 Intel Corporation.
4 #include <linux/device.h>
5 #include <linux/mod_devicetable.h>
6 #include <linux/module.h>
7 #include <linux/soundwire/sdw.h>
10 static int regmap_sdw_write(void *context
, unsigned int reg
, unsigned int val
)
12 struct device
*dev
= context
;
13 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
15 return sdw_write(slave
, reg
, val
);
18 static int regmap_sdw_read(void *context
, unsigned int reg
, unsigned int *val
)
20 struct device
*dev
= context
;
21 struct sdw_slave
*slave
= dev_to_sdw_dev(dev
);
24 read
= sdw_read(slave
, reg
);
32 static struct regmap_bus regmap_sdw
= {
33 .reg_read
= regmap_sdw_read
,
34 .reg_write
= regmap_sdw_write
,
35 .reg_format_endian_default
= REGMAP_ENDIAN_LITTLE
,
36 .val_format_endian_default
= REGMAP_ENDIAN_LITTLE
,
39 static int regmap_sdw_config_check(const struct regmap_config
*config
)
41 /* All register are 8-bits wide as per MIPI Soundwire 1.0 Spec */
42 if (config
->val_bits
!= 8)
45 /* Registers are 32 bits wide */
46 if (config
->reg_bits
!= 32)
49 if (config
->pad_bits
!= 0)
55 struct regmap
*__regmap_init_sdw(struct sdw_slave
*sdw
,
56 const struct regmap_config
*config
,
57 struct lock_class_key
*lock_key
,
58 const char *lock_name
)
62 ret
= regmap_sdw_config_check(config
);
66 return __regmap_init(&sdw
->dev
, ®map_sdw
,
67 &sdw
->dev
, config
, lock_key
, lock_name
);
69 EXPORT_SYMBOL_GPL(__regmap_init_sdw
);
71 struct regmap
*__devm_regmap_init_sdw(struct sdw_slave
*sdw
,
72 const struct regmap_config
*config
,
73 struct lock_class_key
*lock_key
,
74 const char *lock_name
)
78 ret
= regmap_sdw_config_check(config
);
82 return __devm_regmap_init(&sdw
->dev
, ®map_sdw
,
83 &sdw
->dev
, config
, lock_key
, lock_name
);
85 EXPORT_SYMBOL_GPL(__devm_regmap_init_sdw
);
87 MODULE_DESCRIPTION("Regmap SoundWire Module");
88 MODULE_LICENSE("GPL v2");