WIP FPC-III support
[linux/fpc-iii.git] / drivers / base / regmap / regmap-sdw.c
blobc83be26434e7621d49bacc34386690afff766fa3
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>
9 #include "internal.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);
23 int read;
25 read = sdw_read(slave, reg);
26 if (read < 0)
27 return read;
29 *val = read;
30 return 0;
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)
44 return -ENOTSUPP;
46 /* Registers are 32 bits wide */
47 if (config->reg_bits != 32)
48 return -ENOTSUPP;
50 if (config->pad_bits != 0)
51 return -ENOTSUPP;
53 return 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)
61 int ret;
63 ret = regmap_sdw_config_check(config);
64 if (ret)
65 return ERR_PTR(ret);
67 return __regmap_init(&sdw->dev, &regmap_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)
77 int ret;
79 ret = regmap_sdw_config_check(config);
80 if (ret)
81 return ERR_PTR(ret);
83 return __devm_regmap_init(&sdw->dev, &regmap_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");