From patchwork Thu Nov 30 17:41:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 120261 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp89889qgn; Thu, 30 Nov 2017 09:46:07 -0800 (PST) X-Google-Smtp-Source: AGs4zMYD9dFlUUQo1ewI0xILuKcBp079OHy/01+jfNAWNZtOm2Fehj+8w6PMWGgPDQuiCCyLALCL X-Received: by 10.98.9.79 with SMTP id e76mr7455410pfd.70.1512063967809; Thu, 30 Nov 2017 09:46:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512063967; cv=none; d=google.com; s=arc-20160816; b=TUxo9IPzfy9BbcdnVRy32JSWxjSpUl/2w8VVXOCCRaj81TRsR7EDFuDmjRgZPhdfdy V2iK6xLdFnDTEqhjvNBRfzeISczjMBAGmtnFd0MpMT6Q9WvdsLV/9Sv0y+Kl+zn6QJXU vZlBqT/6Epgov27mvjMPxv4Kmt47zyLSVcsGcDf8FWrOgq0d8fEtZR1k+0CQiFTZFfyU LfYWyTGDMPdwqLH4CP2/k5aSMCVl8YucmI+7Nwh0754SVWqtp4a27n3/BT8QrRgLA54Y q+TPclchc0BkQxvKlbZDzK9+CDCCZ4+5FR8u+hOtYi7aUlLXl1YKXDznVAuNHdvEj8Fq yyPw== 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=D5RS1pCFHfcsAIAtzLWF96ELHAGl35GLoww5jp7azmk=; b=qQWjsf5nKE/AqK/EokkTGfzbzvu/tJz2hMzJE/WAPI90+MLnjobYV1kSdnkSPWl0PY beMNn9+BXeKVMTVPgOGWkmlRqoqZhCOdIAzQBXMB2L+tKZ/zwiFEOfmC3JDSLwxrujre gLvoXUQvFsAmfjd/2AcnYP16yAVZZI7EKCv/kGJ7litaVveTenVkyKWPm6qzHEP7gmuQ 885tMJGZCagOpqXAnFY1NyWBIAbZsM1zheagJ+meQMdFfmDwLjUk9fL1ePBEiRqslnnn IHcr2jXSEsOHL1uEhdp34ElOtl1US/uvWqKtx+cA0vutV5gDkEBoulKjZVNuGGdh1arS cWcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=L0ortLTu; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (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 x10si3577916pfk.208.2017.11.30.09.46.07; Thu, 30 Nov 2017 09:46:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=L0ortLTu; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753941AbdK3RqE (ORCPT + 10 others); Thu, 30 Nov 2017 12:46:04 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:44847 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753934AbdK3RqC (ORCPT ); Thu, 30 Nov 2017 12:46:02 -0500 Received: by mail-wr0-f193.google.com with SMTP id l22so7446911wrc.11 for ; Thu, 30 Nov 2017 09:46:01 -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=RYZkYlyya4ZD2MALaqdGFaSKYvHiBIqzgU2e1qveQQ4=; b=L0ortLTucfFOHdMMZkhd63roAOuyNjxI+7ZLuRHyvZ93Z03d6tO7jWHYIUG3WsVceu Ry3wJYljwp2+j1kwKc+SrSCKKe5PGnid3tu4A3S460qAGlogyhsoWLplp5pr7bVJxzgz nhuznQzTHOJoYunAfyZiydycMtWhQFq6feEfk= 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=RYZkYlyya4ZD2MALaqdGFaSKYvHiBIqzgU2e1qveQQ4=; b=YFF+mI2IXGz1A0QUChaKPZ0YI26af60Rb0itDysaSIf3F4iEd4wAtrpXdr3aGg9K1a xugQMMuXr3EZnvRgIu8rCmqoTr+ewrn/9cj0CbpvzgvSbkT5FINxQjryLrIswOdFKeW2 LEbpFaiTeYXGKaHXJfpCYbpvWxuFil596vwMh8jepdqKneiFwawYNT916S7vhnDsrCVM ItePms84N6Y70iaX9GKKVIfgtJ/iCO06W3nDoB5ZFbn4BjVUThWv8QRyGmDpSp4PHj6N KzdxCsibH3A5cxnYuxvEzEKLpFbzXPTy7nPOnwZAmbinvexnov00m1BnfhKy5+fiqS0K Fw5w== X-Gm-Message-State: AJaThX4/0fbOpwZkUDp5R5aYdY1piBsie1RgKhXtNc0xXwlw9h8Tngs0 hk0K+wO2jbxrqnchL95KwbI5bA== X-Received: by 10.223.144.41 with SMTP id h38mr2842408wrh.228.1512063960845; Thu, 30 Nov 2017 09:46:00 -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 189sm2412189wmu.3.2017.11.30.09.45.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Nov 2017 09:46:00 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org, broonie@kernel.org, alsa-devel@alsa-project.org Cc: sdharia@codeaurora.org, bp@suse.de, poeschel@lemonage.de, treding@nvidia.com, andreas.noever@gmail.com, alan@linux.intel.com, mathieu.poirier@linaro.org, daniel@ffwll.ch, jkosina@suse.cz, sharon.dvir1@mail.huji.ac.il, joe@perches.com, davem@davemloft.net, james.hogan@imgtec.com, michael.opdenacker@free-electrons.com, robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, vinod.koul@intel.com, arnd@arndb.de, srinivas.kandagatla@linaro.org Subject: [PATCH v8 08/13] regmap: add SLIMbus support Date: Thu, 30 Nov 2017 17:41:55 +0000 Message-Id: <20171130174200.6684-9-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> References: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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 | 89 ++++++++++++++++++++++++++++++++++++ include/linux/regmap.h | 18 ++++++++ 4 files changed, 112 insertions(+) create mode 100644 drivers/base/regmap/regmap-slimbus.c -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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..d0dab1c5b663 --- /dev/null +++ b/drivers/base/regmap/regmap-slimbus.c @@ -0,0 +1,89 @@ +/* + * Register map access API - SLIMbus support + * + * Copyright 2017 Linaro Inc + * + * Author: Srinivas Kandagatla + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#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 *