From patchwork Thu Dec 7 10:27:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 120959 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8181202qgn; Thu, 7 Dec 2017 02:33:25 -0800 (PST) X-Google-Smtp-Source: AGs4zMYDzi+AsSdwi6wzqv0Dm6SQkodne1zAlIfJfAs3oYhZ6S51QmdgKufn6qUx5P1y1Cyx8xnb X-Received: by 10.99.136.198 with SMTP id l189mr25475965pgd.307.1512642805416; Thu, 07 Dec 2017 02:33:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512642805; cv=none; d=google.com; s=arc-20160816; b=WpLELD0jOrp+4BqxTtElmxDcJgheUABNj0vzn8WnrHorQQBQSZK+pQJeLueoTLclpy KLYNBD2B7T7tiZduw5d1YXRMe5aAJH/NAiGnFPRtDCQwcQUMsi0adYVCH4KARBab20mG 5hrsHOAX4l07BgUpKXw1GrpLpzC5dCnJ2MefwzGtWGZb7t9NV4TI0Cq8ATchKUxWqA4y GJamq2Ne8t2fkpOqrRvREyuB4lm/yIqHtow7+V35oT9mdNcHf+4bhtuOdZHovfT1s9gS sWviw9CmT9lc2TK+k7WoXxY+FsPxIQ6WCO6p+QK5oYzHBYjBfeODj08pztPrAGVXLSZx nLMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=SZXq628LwAI/zssq5oA1vcFcJ1pJBiBd9MS5mT7xUDU=; b=QI+UGKA0WdwvuPZ6+O1jA4endA1OpZf7SH3dqIhmzaDah3iG2WiRoh05loUHF489qs 9wNK4NrLFFU5XksRuvc7IC/up4uxCkuAfV55BbJXvsuKDbdwzD6jMDnAFBBT0xDXdD6y 6xOMivgEDfhgFzF6v0txgnouFc4Rlq8bQyuu50XHS7kC44FKDWWCjurpFvPbVVvM9Wf5 LxCeltY0LJwk0U7jfqlBhCSVm2n4jZSNXfj4MZiWWXCy8zmMuqcqM987HjVi+cjwM4Iw H42wWq6m6wMy/Mp+KvKr3L6OV/WHOcsRsUUp6Y7L5kOSIfREgYHst7bLcHorRyJBuI6Q I0Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O/U5Rt6t; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r11si3479519pgs.685.2017.12.07.02.33.24; Thu, 07 Dec 2017 02:33:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O/U5Rt6t; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752960AbdLGKdW (ORCPT + 21 others); Thu, 7 Dec 2017 05:33:22 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:37366 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752806AbdLGKap (ORCPT ); Thu, 7 Dec 2017 05:30:45 -0500 Received: by mail-wm0-f66.google.com with SMTP id f140so11909069wmd.2 for ; Thu, 07 Dec 2017 02:30:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SZXq628LwAI/zssq5oA1vcFcJ1pJBiBd9MS5mT7xUDU=; b=O/U5Rt6tMgaCfR6QC7fw/DQYXEDCY+pu/PMIac6vXh7HUHQxh4C8d/KsvYACBwN8oN IP5vZR/9RciSkn0B8q/t+Mncm65fADmiN5c0Sg3BvhGkU2tM/pKOcwMCUTzs7dEBM0ag 2NoYBeppi7AiW3aWGOr44c12YzvL/BvUsuUb0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SZXq628LwAI/zssq5oA1vcFcJ1pJBiBd9MS5mT7xUDU=; b=Sq6xP0uy1PZ0a5Vbmh0tn1Th3MFpt87cXxDB/YlEpu0CMZqDlnkH6sHek9pWvDABXe oCkXmowVQoAb3cb/lKJeF5kS6COhlrvATwJf555en/xmIkcNs8EGSJR3kbvlAi26xOma RjqkaJoivcHP6WWqovEX4o22LQEyc8gjp3EKD3e9I4KT1nbVscUCYAMtw4gK4JZcSS5N shmP6uBgGQPAda0kvaNqfXslivg78IgJX4e5Q4ejdbs81/zEHlSNNwZy7vifypBi6SBE XJGXPb3uJ30DLDsWa0zDzWSkm/d4eC/VcmDimBbzwPF7EeZ9PjIScCIomCpf/WepYTdJ 2OdQ== X-Gm-Message-State: AKGB3mKWkGzHNk02fbgHjfjlgiFcCgK68KIo5/pDx446wLEz5AI6F3Zt 9/7ZvsgWBXg6JeFe8KoPr4ieCQ== X-Received: by 10.28.127.22 with SMTP id a22mr693982wmd.12.1512642644050; Thu, 07 Dec 2017 02:30:44 -0800 (PST) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id k2sm4837734wrg.4.2017.12.07.02.30.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Dec 2017 02:30:43 -0800 (PST) From: srinivas.kandagatla@linaro.org To: Mark Brown , Greg Kroah-Hartman , alsa-devel@alsa-project.org Cc: sdharia@codeaurora.org, Rob Herring , Mark Rutland , Jonathan Corbet , pombredanne@nexb.com, j.neuschaefer@gmx.net, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH v9 08/13] regmap: add SLIMbus support Date: Thu, 7 Dec 2017 10:27:15 +0000 Message-Id: <20171207102720.21071-9-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171207102720.21071-1-srinivas.kandagatla@linaro.org> References: <20171207102720.21071-1-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Srinivas Kandagatla 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 --- drivers/base/regmap/Kconfig | 4 ++ drivers/base/regmap/Makefile | 1 + drivers/base/regmap/regmap-slimbus.c | 80 ++++++++++++++++++++++++++++++++++++ include/linux/regmap.h | 18 ++++++++ 4 files changed, 103 insertions(+) create mode 100644 drivers/base/regmap/regmap-slimbus.c -- 2.15.0 diff --git a/drivers/base/regmap/Kconfig b/drivers/base/regmap/Kconfig index 3a1535d812d8..cc162b48c6d7 100644 --- a/drivers/base/regmap/Kconfig +++ b/drivers/base/regmap/Kconfig @@ -21,6 +21,10 @@ config REGMAP_I2C tristate depends on I2C +config REGMAP_SLIMBUS + tristate + depends on SLIMBUS + config REGMAP_SPI tristate depends on SPI diff --git a/drivers/base/regmap/Makefile b/drivers/base/regmap/Makefile index 0d298c446108..63dec9222892 100644 --- a/drivers/base/regmap/Makefile +++ b/drivers/base/regmap/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_REGCACHE_COMPRESSED) += regcache-lzo.o obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o obj-$(CONFIG_REGMAP_AC97) += regmap-ac97.o obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o +obj-$(CONFIG_REGMAP_SLIMBUS) += regmap-slimbus.o obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o obj-$(CONFIG_REGMAP_SPMI) += regmap-spmi.o obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o diff --git a/drivers/base/regmap/regmap-slimbus.c b/drivers/base/regmap/regmap-slimbus.c new file mode 100644 index 000000000000..c90bee81d954 --- /dev/null +++ b/drivers/base/regmap/regmap-slimbus.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2017, Linaro Ltd. + +#include +#include +#include + +#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"); diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 15eddc1353ba..b2207737a159 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -24,6 +24,7 @@ struct module; struct device; struct i2c_client; struct irq_domain; +struct slim_device; struct spi_device; struct spmi_device; struct regmap; @@ -499,6 +500,10 @@ struct regmap *__regmap_init_i2c(struct i2c_client *i2c, const struct regmap_config *config, struct lock_class_key *lock_key, const char *lock_name); +struct regmap *__regmap_init_slimbus(struct slim_device *slimbus, + const struct regmap_config *config, + struct lock_class_key *lock_key, + const char *lock_name); struct regmap *__regmap_init_spi(struct spi_device *dev, const struct regmap_config *config, struct lock_class_key *lock_key, @@ -615,6 +620,19 @@ int regmap_attach_dev(struct device *dev, struct regmap *map, __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \ i2c, config) +/** + * regmap_init_slimbus() - Initialise register map + * + * @slimbus: Device that will be interacted with + * @config: Configuration for register map + * + * The return value will be an ERR_PTR() on error or a valid pointer to + * a struct regmap. + */ +#define regmap_init_slimbus(slimbus, config) \ + __regmap_lockdep_wrapper(__regmap_init_slimbus, #config, \ + slimbus, config) + /** * regmap_init_spi() - Initialise register map *