net: DCB: Validate DCB_ATTR_DCB_BUFFER argument
[linux/fpc-iii.git] / drivers / base / regmap / regmap-sdw.c
blob50a66382d87d09734bc427e7c1b8af4e376684f7
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>
8 #include "internal.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);
22 int read;
24 read = sdw_read(slave, reg);
25 if (read < 0)
26 return read;
28 *val = read;
29 return 0;
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)
43 return -ENOTSUPP;
45 /* Registers are 32 bits wide */
46 if (config->reg_bits != 32)
47 return -ENOTSUPP;
49 if (config->pad_bits != 0)
50 return -ENOTSUPP;
52 return 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)
60 int ret;
62 ret = regmap_sdw_config_check(config);
63 if (ret)
64 return ERR_PTR(ret);
66 return __regmap_init(&sdw->dev, &regmap_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)
76 int ret;
78 ret = regmap_sdw_config_check(config);
79 if (ret)
80 return ERR_PTR(ret);
82 return __devm_regmap_init(&sdw->dev, &regmap_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");