linux/drivers/base/regmap/regmap-sdw.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2// Copyright(c) 2015-17 Intel Corporation.
   3
   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"
   9
  10static int regmap_sdw_write(void *context, unsigned int reg, unsigned int val)
  11{
  12        struct device *dev = context;
  13        struct sdw_slave *slave = dev_to_sdw_dev(dev);
  14
  15        return sdw_write(slave, reg, val);
  16}
  17
  18static int regmap_sdw_read(void *context, unsigned int reg, unsigned int *val)
  19{
  20        struct device *dev = context;
  21        struct sdw_slave *slave = dev_to_sdw_dev(dev);
  22        int read;
  23
  24        read = sdw_read(slave, reg);
  25        if (read < 0)
  26                return read;
  27
  28        *val = read;
  29        return 0;
  30}
  31
  32static 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,
  37};
  38
  39static int regmap_sdw_config_check(const struct regmap_config *config)
  40{
  41        /* All register are 8-bits wide as per MIPI Soundwire 1.0 Spec */
  42        if (config->val_bits != 8)
  43                return -ENOTSUPP;
  44
  45        /* Registers are 32 bits wide */
  46        if (config->reg_bits != 32)
  47                return -ENOTSUPP;
  48
  49        if (config->pad_bits != 0)
  50                return -ENOTSUPP;
  51
  52        return 0;
  53}
  54
  55struct 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)
  59{
  60        int ret;
  61
  62        ret = regmap_sdw_config_check(config);
  63        if (ret)
  64                return ERR_PTR(ret);
  65
  66        return __regmap_init(&sdw->dev, &regmap_sdw,
  67                        &sdw->dev, config, lock_key, lock_name);
  68}
  69EXPORT_SYMBOL_GPL(__regmap_init_sdw);
  70
  71struct 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)
  75{
  76        int ret;
  77
  78        ret = regmap_sdw_config_check(config);
  79        if (ret)
  80                return ERR_PTR(ret);
  81
  82        return __devm_regmap_init(&sdw->dev, &regmap_sdw,
  83                        &sdw->dev, config, lock_key, lock_name);
  84}
  85EXPORT_SYMBOL_GPL(__devm_regmap_init_sdw);
  86
  87MODULE_DESCRIPTION("Regmap SoundWire Module");
  88MODULE_LICENSE("GPL v2");
  89