Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8197913ybi; Thu, 6 Jun 2019 08:14:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqziQDV88JhKoiK9XobpekUZR2YdS4bogu9lO/4kEe08RZmZXOtbH+tWK6BERV53VF0HNwO/ X-Received: by 2002:a63:9dcc:: with SMTP id i195mr3697097pgd.183.1559834067778; Thu, 06 Jun 2019 08:14:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559834067; cv=none; d=google.com; s=arc-20160816; b=X5EWb/bEHFbt14KnpP4+VDKakAjFaE2Q3ok6h+bC/skXYu3zUts8zzR+L/ee+pr3b7 RSyxKD8jwzEXY6JIUsDZmZ/8V+OLfa7GlRbdohsLWq/ySD6YqLU87H13Z3WTKTBgB8Vg rA3VdHbgbtMT2PRocPZDK+JnegFN9Br8PIIZzWdXaQFkKbX4xq3qfJfZCaM1B6r6n5k9 tdmiS3hOpKmCfdqMieusPmxX5Ncyfpbxp2ta6TyleTYnYu3kBVKnKY+SsoD56bZyxARY bPcUSasJKW79DmPiXFrAqN7SVeLnMdfe3dSrqeOUox014zsQ6w1MgKcJVyQnoofvEa2S UqUA== 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=PQs6VvtPQ2KFV/HYHazh/untPhhSiL+w2RUbykQUWzI=; b=lOYo546SaPCgUo6K43KxtFBuMUolDM7D+MzzTYCik2teA9puM1JvjqzoMIcqRaXX7T xo8m+9GB/WFtkstPZPx73nVasHzGaOH5D/9n/cdzscWlKnE47d1x0mBFcUyXrAk1cEuO 7Y97swX2e60q1+/IS3LZTKHO+5fZO8yhoTz8bUI04Bpy0yCERnq/Z9icc3BBxAH6Hmjo 3tPhA53ki/7nJU05IOOSqJJxrhzUdqdpAxISae+gNYfoYAFC/SwyynLMyDHwbl0W4Bb9 XqrVsmkO7S4zXxuN3eWTR96ParG0Aw0QeUH1Jq1v5QtYgy9JCbcm7gSy7AZT7AOKQa2v u++w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=MoUVLOyv; 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 132si1959111pfu.263.2019.06.06.08.14.09; Thu, 06 Jun 2019 08:14:27 -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=MoUVLOyv; 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 S1729171AbfFFPMK (ORCPT + 99 others); Thu, 6 Jun 2019 11:12:10 -0400 Received: from smtprelay-out1.synopsys.com ([198.182.61.142]:50662 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728812AbfFFPMJ (ORCPT ); Thu, 6 Jun 2019 11:12:09 -0400 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 14B86C0BA6; Thu, 6 Jun 2019 15:11:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1559833908; bh=3f7/q2BglQTljnvAoJoA7QvsI9bDMDsZY3M0zTPkEu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=MoUVLOyvqY8XckBqcY8qZMv7wHegsXlDpLf0Y84Jjs7pAz91nF1EXHC5WJaJiNb6g a+vdtyYg3AJy+CzFeH6Tvx/bVxatFZ2UwzVnO56ZiCk94LaekjIOVKy/53Drb9PU1d v2/5k8j8uiDj/HQPePE7nxfqUUGzg0dzyaC9u1Nq018tn67X4W6s21d+A/SRJApenv Ti2WjzzaVlYWE8YJUulsLS6juY3LAsQ0I5Sz+Kpdal75S/kvbkxhyzFdwBm+KsrqBZ ADjDTziwQCNVM9bnRHaF7FZ7m2irKgm1dS2RJrsNiJM3YeXCzklm/roohbCXjmIYoZ qHZ1XixS0f6xQ== Received: from de02.synopsys.com (germany.internal.synopsys.com [10.225.17.21]) by mailhost.synopsys.com (Postfix) with ESMTP id C2282A005F; Thu, 6 Jun 2019 15:12:07 +0000 (UTC) Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by de02.synopsys.com (Postfix) with ESMTP id AC9823FECF; Thu, 6 Jun 2019 17:12:07 +0200 (CEST) From: Vitor Soares To: linux-iio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Cc: broonie@kernel.org, gregkh@linuxfoundation.org, rafael@kernel.org, bbrezillon@kernel.org, Joao.Pinto@synopsys.com, lorenzo.bianconi83@gmail.com, Vitor Soares Subject: [PATCH v2 1/3] regmap: add i3c bus support Date: Thu, 6 Jun 2019 17:12:02 +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 SDR Read and Write commands. Signed-off-by: Vitor Soares --- Changes in v2: None drivers/base/regmap/Kconfig | 6 +++- drivers/base/regmap/Makefile | 1 + drivers/base/regmap/regmap-i3c.c | 60 ++++++++++++++++++++++++++++++++++++++++ include/linux/regmap.h | 20 ++++++++++++++ 4 files changed, 86 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..1578fb5 --- /dev/null +++ b/drivers/base/regmap/regmap-i3c.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2018 Synopsys, Inc. and/or its affiliates. + +#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_AUTHOR("Vitor Soares "); +MODULE_DESCRIPTION("Regmap I3C Module"); +MODULE_LICENSE("GPL v2"); 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