Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <srinivas.kandagatla@linaro.org>
Reviwed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Srinivas Kandagatla and committed by
Greg Kroah-Hartman
7d6f7fb0 4b14e62a

+103
+4
drivers/base/regmap/Kconfig
··· 21 21 tristate 22 22 depends on I2C 23 23 24 + config REGMAP_SLIMBUS 25 + tristate 26 + depends on SLIMBUS 27 + 24 28 config REGMAP_SPI 25 29 tristate 26 30 depends on SPI
+1
drivers/base/regmap/Makefile
··· 8 8 obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o 9 9 obj-$(CONFIG_REGMAP_AC97) += regmap-ac97.o 10 10 obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o 11 + obj-$(CONFIG_REGMAP_SLIMBUS) += regmap-slimbus.o 11 12 obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o 12 13 obj-$(CONFIG_REGMAP_SPMI) += regmap-spmi.o 13 14 obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o
+80
drivers/base/regmap/regmap-slimbus.c
··· 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");
+18
include/linux/regmap.h
··· 24 24 struct device; 25 25 struct i2c_client; 26 26 struct irq_domain; 27 + struct slim_device; 27 28 struct spi_device; 28 29 struct spmi_device; 29 30 struct regmap; ··· 500 499 const struct regmap_config *config, 501 500 struct lock_class_key *lock_key, 502 501 const char *lock_name); 502 + struct regmap *__regmap_init_slimbus(struct slim_device *slimbus, 503 + const struct regmap_config *config, 504 + struct lock_class_key *lock_key, 505 + const char *lock_name); 503 506 struct regmap *__regmap_init_spi(struct spi_device *dev, 504 507 const struct regmap_config *config, 505 508 struct lock_class_key *lock_key, ··· 619 614 #define regmap_init_i2c(i2c, config) \ 620 615 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \ 621 616 i2c, config) 617 + 618 + /** 619 + * regmap_init_slimbus() - Initialise register map 620 + * 621 + * @slimbus: Device that will be interacted with 622 + * @config: Configuration for register map 623 + * 624 + * The return value will be an ERR_PTR() on error or a valid pointer to 625 + * a struct regmap. 626 + */ 627 + #define regmap_init_slimbus(slimbus, config) \ 628 + __regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \ 629 + slimbus, config) 622 630 623 631 /** 624 632 * regmap_init_spi() - Initialise register map