Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2472973yba; Mon, 15 Apr 2019 12:22:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIznqdYkFEKon7gpjcd81z1DBriksY81ZW0ek8led/0OQINIaD5BmCoR7fS7gPHPX5DAbm X-Received: by 2002:a17:902:2a4b:: with SMTP id i69mr21723799plb.292.1555356121445; Mon, 15 Apr 2019 12:22:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555356121; cv=none; d=google.com; s=arc-20160816; b=l8nB8yuQzHX7G3kuoINENGQYQXoem7kBot/bmeTcnHoE7I7//3dXIdHF9pe8BkJQcW nej3f7dRt/a8UJYwesaECZzO1q+AaCjHOQ3yIOt1ELT1+F8WTp2gZtbotrq7mNxr4YPr N7FTowvLg2tuVQ1TuDs90uGnFR5LQIIRTq36ZsAPvxBozj3vPyNjqAJLlG7sG9alZXEw 4kpG1UJH4IX9Gl5u0ovVjXLbUDJOn7YAlrqNdO4PPMHg0rINJLHFwU+djeH9CbT9TzIs lWzROLVprZvQdf1YY2TYRP7hVz3pZUTDYf+V84DMftCqBPKwtz6VygosEqNFqoP/jiL+ kV8Q== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=e8a4isUPr2wLVso52VOLLrevjkSoiU9tLUf12kheeCc=; b=hpWADP9LJIVZX4w304Rl1A/O/zlwwUEBd5OfKre8W9UqrW14i/eGn+YwxWhDwgVSap 7l2kkdOzOGvAtp8fxOZMdrViid08bMZeSFZEUY26HXIFtNi5F/w30LL2fIXLSRGgLGxp o9Fub3JaJCtDoKBw22XW/SELn8E+q2Qth0ZUDCggxVJ+AJGExxW5AFH8aAvqZ57EZyUh u8kUHKNxOYAHY2Jk+byUIp5IsORrzOTprdpnbICL9uaFkKXanBmzlKGUW5Ht8I0OoDkQ DcGhUr9lg0VvgcnYPdrQPQAc+EJptxwPi6+WP1mHN0nKazTHDNxiX94im/tmin30kF+E gHKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=D5SdTRYt; 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=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 19si44451614pgl.402.2019.04.15.12.21.45; Mon, 15 Apr 2019 12:22:01 -0700 (PDT) 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=@synopsys.com header.s=mail header.b=D5SdTRYt; 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=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731513AbfDOTU0 (ORCPT + 99 others); Mon, 15 Apr 2019 15:20:26 -0400 Received: from smtprelay2.synopsys.com ([198.182.60.111]:57352 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728289AbfDOTUY (ORCPT ); Mon, 15 Apr 2019 15:20:24 -0400 Received: from mailhost1.synopsys.com (mailhost1.synopsys.com [10.12.238.239]) by smtprelay.synopsys.com (Postfix) with ESMTP id C502D10C12A7; Mon, 15 Apr 2019 12:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1555356023; bh=XE5KlxeBcaMGeU9oOTfynmEvKq//ui0hxk9gOzVB3Eg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=D5SdTRYtiO+kOXffAiHnBKZq2L2kxq2xUsZz2li1FdjcplgyPTEd87I7TlhHCMk89 tqcxVSlTmzqztL9wh7KaRnvGR0EBlKh75QCm69HOA8Rflgzig2ITRMyJZo0l7GivuD cB4HBTR4ipiiywbnE8V/Mpl/RvkcugKqWz8U+sUEI0bqTofQl3g4T2e5rAfIenL6i0 77tvlptykrj34xf9WpfKQHk3CybxmrBgZ+FdxJeOSuNnSY0JvMJgPu5R5RpCWzS3I9 ga1zt1udot3FD/PfqZElz3YjPNrS/GpRNqeSUTPpyPIjP8WEs6UfscVGNxoRVZhUnG mZM3b+zqwalYw== Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by mailhost1.synopsys.com (Postfix) with ESMTP id DAA0B546A; Mon, 15 Apr 2019 12:19:50 -0700 (PDT) From: Vitor Soares To: linux-iio@vger.kernel.org, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Cc: pmeerw@pmeerw.net, lars@metafoo.de, knaack.h@gmx.de, jic23@kernel.org, lorenzo.bianconi83@gmail.com, bbrezillon@kernel.org, rafael@kernel.org, gregkh@linuxfoundation.org, broonie@kernel.org, joao.pinto@synopsys.com, Vitor Soares Subject: [PATCH 1/3] remap: Add I3C bus support Date: Mon, 15 Apr 2019 21:19:39 +0200 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add basic support for I3C bus. This is a simple implementation that only give support for Read and Write commands. Signed-off-by: Vitor Soares --- drivers/base/regmap/Kconfig | 6 +++- drivers/base/regmap/Makefile | 1 + drivers/base/regmap/regmap-i3c.c | 62 ++++++++++++++++++++++++++++++++++++++++ include/linux/regmap.h | 20 +++++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 drivers/base/regmap/regmap-i3c.c diff --git a/drivers/base/regmap/Kconfig b/drivers/base/regmap/Kconfig index 6ad5ef4..c8bbf53 100644 --- a/drivers/base/regmap/Kconfig +++ b/drivers/base/regmap/Kconfig @@ -4,7 +4,7 @@ # subsystems should select the appropriate symbols. config REGMAP - default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ) + default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ || REGMAP_I3C) select IRQ_DOMAIN if REGMAP_IRQ bool @@ -49,3 +49,7 @@ config REGMAP_SOUNDWIRE config REGMAP_SCCB tristate depends on I2C + +config REGMAP_I3C + tristate + depends on I3C diff --git a/drivers/base/regmap/Makefile b/drivers/base/regmap/Makefile index f5b4e88..ff6c7d8 100644 --- a/drivers/base/regmap/Makefile +++ b/drivers/base/regmap/Makefile @@ -16,3 +16,4 @@ obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o obj-$(CONFIG_REGMAP_W1) += regmap-w1.o obj-$(CONFIG_REGMAP_SOUNDWIRE) += regmap-sdw.o obj-$(CONFIG_REGMAP_SCCB) += regmap-sccb.o +obj-$(CONFIG_REGMAP_I3C) += regmap-i3c.o diff --git a/drivers/base/regmap/regmap-i3c.c b/drivers/base/regmap/regmap-i3c.c new file mode 100644 index 0000000..565997b --- /dev/null +++ b/drivers/base/regmap/regmap-i3c.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2018 Synopsys, Inc. and/or its affiliates. + * + * Author: Vitor Soares + */ + +#include +#include +#include +#include + +static int regmap_i3c_write(void *context, const void *data, size_t count) +{ + struct device *dev = context; + struct i3c_device *i3c = dev_to_i3cdev(dev); + struct i3c_priv_xfer xfers[] = { + { + .rnw = false, + .len = count, + .data.out = data, + }, + }; + + return i3c_device_do_priv_xfers(i3c, xfers, 1); +} + +static int regmap_i3c_read(void *context, + const void *reg, size_t reg_size, + void *val, size_t val_size) +{ + struct device *dev = context; + struct i3c_device *i3c = dev_to_i3cdev(dev); + struct i3c_priv_xfer xfers[2]; + + xfers[0].rnw = false; + xfers[0].len = reg_size; + xfers[0].data.out = reg; + + xfers[1].rnw = true; + xfers[1].len = val_size; + xfers[1].data.in = val; + + return i3c_device_do_priv_xfers(i3c, xfers, 2); +} + +static struct regmap_bus regmap_i3c = { + .write = regmap_i3c_write, + .read = regmap_i3c_read, +}; + +struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c, + const struct regmap_config *config, + struct lock_class_key *lock_key, + const char *lock_name) +{ + return __devm_regmap_init(&i3c->dev, ®map_i3c, &i3c->dev, config, + lock_key, lock_name); +} +EXPORT_SYMBOL_GPL(__devm_regmap_init_i3c); + +MODULE_LICENSE("GPL"); diff --git a/include/linux/regmap.h b/include/linux/regmap.h index daeec7d..f65984d 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -25,6 +25,7 @@ struct module; struct clk; struct device; struct i2c_client; +struct i3c_device; struct irq_domain; struct slim_device; struct spi_device; @@ -624,6 +625,10 @@ 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); +struct regmap *__devm_regmap_init_i3c(struct i3c_device *i3c, + const struct regmap_config *config, + struct lock_class_key *lock_key, + const char *lock_name); /* * Wrapper for regmap_init macros to include a unique lockdep key and name * for each call. No-op if CONFIG_LOCKDEP is not set. @@ -982,6 +987,21 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg); #define devm_regmap_init_slimbus(slimbus, config) \ __regmap_lockdep_wrapper(__devm_regmap_init_slimbus, #config, \ slimbus, config) + +/** + * devm_regmap_init_i3c() - Initialise managed register map + * + * @i3c: 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. The regmap will be automatically freed by the + * device management code. + */ +#define devm_regmap_init_i3c(i3c, config) \ + __regmap_lockdep_wrapper(__devm_regmap_init_i3c, #config, \ + i3c, config) + int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk); void regmap_mmio_detach_clk(struct regmap *map); void regmap_exit(struct regmap *map); -- 2.7.4