Skip to content

Commit 7d6f7fb

Browse files
Srinivas-Kandagatlagregkh
authored andcommitted
regmap: add SLIMbus support
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 <[email protected]> Reviwed-by: Mark Brown <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4b14e62 commit 7d6f7fb

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

drivers/base/regmap/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ config REGMAP_I2C
2121
tristate
2222
depends on I2C
2323

24+
config REGMAP_SLIMBUS
25+
tristate
26+
depends on SLIMBUS
27+
2428
config REGMAP_SPI
2529
tristate
2630
depends on SPI

drivers/base/regmap/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ obj-$(CONFIG_REGCACHE_COMPRESSED) += regcache-lzo.o
88
obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o
99
obj-$(CONFIG_REGMAP_AC97) += regmap-ac97.o
1010
obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o
11+
obj-$(CONFIG_REGMAP_SLIMBUS) += regmap-slimbus.o
1112
obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o
1213
obj-$(CONFIG_REGMAP_SPMI) += regmap-spmi.o
1314
obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (c) 2017, Linaro Ltd.
3+
4+
#include <linux/regmap.h>
5+
#include <linux/slimbus.h>
6+
#include <linux/module.h>
7+
8+
#include "internal.h"
9+
10+
static int regmap_slimbus_byte_reg_read(void *context, unsigned int reg,
11+
unsigned int *val)
12+
{
13+
struct slim_device *sdev = context;
14+
int v;
15+
16+
v = slim_readb(sdev, reg);
17+
18+
if (v < 0)
19+
return v;
20+
21+
*val = v;
22+
23+
return 0;
24+
}
25+
26+
static int regmap_slimbus_byte_reg_write(void *context, unsigned int reg,
27+
unsigned int val)
28+
{
29+
struct slim_device *sdev = context;
30+
31+
return slim_writeb(sdev, reg, val);
32+
}
33+
34+
static struct regmap_bus regmap_slimbus_bus = {
35+
.reg_write = regmap_slimbus_byte_reg_write,
36+
.reg_read = regmap_slimbus_byte_reg_read,
37+
.reg_format_endian_default = REGMAP_ENDIAN_LITTLE,
38+
.val_format_endian_default = REGMAP_ENDIAN_LITTLE,
39+
};
40+
41+
static const struct regmap_bus *regmap_get_slimbus(struct slim_device *slim,
42+
const struct regmap_config *config)
43+
{
44+
if (config->val_bits == 8 && config->reg_bits == 8)
45+
return &regmap_slimbus_bus;
46+
47+
return ERR_PTR(-ENOTSUPP);
48+
}
49+
50+
struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
51+
const struct regmap_config *config,
52+
struct lock_class_key *lock_key,
53+
const char *lock_name)
54+
{
55+
const struct regmap_bus *bus = regmap_get_slimbus(slimbus, config);
56+
57+
if (IS_ERR(bus))
58+
return ERR_CAST(bus);
59+
60+
return __regmap_init(&slimbus->dev, bus, &slimbus->dev, config,
61+
lock_key, lock_name);
62+
}
63+
EXPORT_SYMBOL_GPL(__regmap_init_slimbus);
64+
65+
struct regmap *__devm_regmap_init_slimbus(struct slim_device *slimbus,
66+
const struct regmap_config *config,
67+
struct lock_class_key *lock_key,
68+
const char *lock_name)
69+
{
70+
const struct regmap_bus *bus = regmap_get_slimbus(slimbus, config);
71+
72+
if (IS_ERR(bus))
73+
return ERR_CAST(bus);
74+
75+
return __devm_regmap_init(&slimbus->dev, bus, &slimbus, config,
76+
lock_key, lock_name);
77+
}
78+
EXPORT_SYMBOL_GPL(__devm_regmap_init_slimbus);
79+
80+
MODULE_LICENSE("GPL v2");

include/linux/regmap.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct module;
2424
struct device;
2525
struct i2c_client;
2626
struct irq_domain;
27+
struct slim_device;
2728
struct spi_device;
2829
struct spmi_device;
2930
struct regmap;
@@ -499,6 +500,10 @@ struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
499500
const struct regmap_config *config,
500501
struct lock_class_key *lock_key,
501502
const char *lock_name);
503+
struct regmap *__regmap_init_slimbus(struct slim_device *slimbus,
504+
const struct regmap_config *config,
505+
struct lock_class_key *lock_key,
506+
const char *lock_name);
502507
struct regmap *__regmap_init_spi(struct spi_device *dev,
503508
const struct regmap_config *config,
504509
struct lock_class_key *lock_key,
@@ -615,6 +620,19 @@ int regmap_attach_dev(struct device *dev, struct regmap *map,
615620
__regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
616621
i2c, config)
617622

623+
/**
624+
* regmap_init_slimbus() - Initialise register map
625+
*
626+
* @slimbus: Device that will be interacted with
627+
* @config: Configuration for register map
628+
*
629+
* The return value will be an ERR_PTR() on error or a valid pointer to
630+
* a struct regmap.
631+
*/
632+
#define regmap_init_slimbus(slimbus, config) \
633+
__regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \
634+
slimbus, config)
635+
618636
/**
619637
* regmap_init_spi() - Initialise register map
620638
*

0 commit comments

Comments
 (0)