-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch adds support to read/write SLIMbus value elements. Currently it only supports byte read/write. Adding this support in regmap would give codec drivers more flexibility when there are more than 2 control interfaces like SLIMbus, i2c. Without this patch each codec driver has to directly call SLIMbus value element apis, and this could would get messy once we want to add i2c interface to it. Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Reviwed-by: Mark Brown <broonie@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
- Loading branch information
Srinivas Kandagatla
authored and
Greg Kroah-Hartman
committed
Dec 19, 2017
1 parent
4b14e62
commit 7d6f7fb
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
// Copyright (c) 2017, Linaro Ltd. | ||
|
||
#include <linux/regmap.h> | ||
#include <linux/slimbus.h> | ||
#include <linux/module.h> | ||
|
||
#include "internal.h" | ||
|
||
static int regmap_slimbus_byte_reg_read(void *context, unsigned int reg, | ||
unsigned int *val) | ||
{ | ||
struct slim_device *sdev = context; | ||
int v; | ||
|
||
v = slim_readb(sdev, reg); | ||
|
||
if (v < 0) | ||
return v; | ||
|
||
*val = v; | ||
|
||
return 0; | ||
} | ||
|
||
static int regmap_slimbus_byte_reg_write(void *context, unsigned int reg, | ||
unsigned int val) | ||
{ | ||
struct slim_device *sdev = context; | ||
|
||
return slim_writeb(sdev, reg, val); | ||
} | ||
|
||
static struct regmap_bus regmap_slimbus_bus = { | ||
.reg_write = regmap_slimbus_byte_reg_write, | ||
.reg_read = regmap_slimbus_byte_reg_read, | ||
.reg_format_endian_default = REGMAP_ENDIAN_LITTLE, | ||
.val_format_endian_default = REGMAP_ENDIAN_LITTLE, | ||
}; | ||
|
||
static const struct regmap_bus *regmap_get_slimbus(struct slim_device *slim, | ||
const struct regmap_config *config) | ||
{ | ||
if (config->val_bits == 8 && config->reg_bits == 8) | ||
return ®map_slimbus_bus; | ||
|
||
return ERR_PTR(-ENOTSUPP); | ||
} | ||
|
||
struct regmap *__regmap_init_slimbus(struct slim_device *slimbus, | ||
const struct regmap_config *config, | ||
struct lock_class_key *lock_key, | ||
const char *lock_name) | ||
{ | ||
const struct regmap_bus *bus = regmap_get_slimbus(slimbus, config); | ||
|
||
if (IS_ERR(bus)) | ||
return ERR_CAST(bus); | ||
|
||
return __regmap_init(&slimbus->dev, bus, &slimbus->dev, config, | ||
lock_key, lock_name); | ||
} | ||
EXPORT_SYMBOL_GPL(__regmap_init_slimbus); | ||
|
||
struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus, | ||
const struct regmap_config *config, | ||
struct lock_class_key *lock_key, | ||
const char *lock_name) | ||
{ | ||
const struct regmap_bus *bus = regmap_get_slimbus(slimbus, config); | ||
|
||
if (IS_ERR(bus)) | ||
return ERR_CAST(bus); | ||
|
||
return __devm_regmap_init(&slimbus->dev, bus, &slimbus, config, | ||
lock_key, lock_name); | ||
} | ||
EXPORT_SYMBOL_GPL(__devm_regmap_init_slimbus); | ||
|
||
MODULE_LICENSE("GPL v2"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters