From patchwork Wed Jun 17 08:41:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 188130 Delivered-To: patch@linaro.org Received: by 2002:a92:cf06:0:0:0:0:0 with SMTP id c6csp255530ilo; Wed, 17 Jun 2020 01:41:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0eRGdW2RrwK4zK/WKyBDFweHs28kTSDJNO5NOfr8vWB1wrRIKS/zIocY9Er6DAKc5/eGg X-Received: by 2002:a17:906:2507:: with SMTP id i7mr6282547ejb.419.1592383306822; Wed, 17 Jun 2020 01:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592383306; cv=none; d=google.com; s=arc-20160816; b=0C/SAQDO0TofgwrL1n4/GK5/zbMXzCVxv7szIoRPEt27SZpAb5F3YupnuMZNDYmd5c /FAaUdrlBfYLrGD3QmVabv5ofE9mZM1yk+MK8KstvHA1hzzXPiWOdc95SAzEyw8q7V9K QpOhtpMDV6B9SuaEto9qlr/gAvNB1uyPIurvqDtaNHcsCendZmSoqdtA/gEZTYfUXcE/ PlWVmXi5l1a7CUiO9uHfeP379teKfPEnUYR8SSx2N5hL85TAX1WeYnqR2UDjdCLj8f7D YrJ5VD6QsTp2CzDJ1OK6hA51NOpnD6WfBA6NvJNeND0kFSwWl1TP71oE0PpcC3XmHsyl +DWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=DZMa6DET1qb3XpdgoNbeTgpSZ2dO/+nB5dNSP35ZNe0=; b=NscQIUB3SwHixl6lU1Pk/QK+nTJkEPIlMOmZ1lbPmP6xRGmWJPk+C61xzfvhgq72V1 fzf4+8QgI+RUsozcL079NlkOs1y8e4HDV4alLikGWAUCnDUtm+qKEoZgxYF6JSrCLprt yTL6jL2STouc4Fu0QvZdcZfk0fE+sWVnwe9AU18Uc61wl9kCypONxA11jk/N04rmexBi tVxrpFOiQSIBZ19VKAE/KOANr8xI8QnICOs2VY89+ap8FHI28r4LaD4HraUV/rDGlWn3 VH3CthLfIyBmtrn/3X4zbp+6MJLyuxBXzZvPhfH9jgPcelWj6XDUKsuszqTLo8fVcC0k CW6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TKxqhw0J; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-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. [23.128.96.18]) by mx.google.com with ESMTP id h7si13056746edn.14.2020.06.17.01.41.46; Wed, 17 Jun 2020 01:41:46 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TKxqhw0J; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-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 S1726573AbgFQIlq (ORCPT + 6 others); Wed, 17 Jun 2020 04:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725860AbgFQIlo (ORCPT ); Wed, 17 Jun 2020 04:41:44 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70140C061573 for ; Wed, 17 Jun 2020 01:41:44 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id l11so1425133wru.0 for ; Wed, 17 Jun 2020 01:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DZMa6DET1qb3XpdgoNbeTgpSZ2dO/+nB5dNSP35ZNe0=; b=TKxqhw0Jcu71I/x6Ep+yjYVaT07kQc900R6ef8apklQGlr/MjfDbo04wbE9kuS9Cs8 57EVYUFjBEMJs+BftJD3oD4bxmDMsrh5gyA1oVaDpGOuqQYutoBDtVd98ZmIZrl8KLVS z2/nJ5Kxyz7UD3mz0+jGd3YNysk/lab3vq0tzi8GUmPCd6ZGcKjb/jyD3mHkprZZQd8l /xuKRurE3oGyxNB4dVClC0QgyePKySvFsF1NJwl0U5E/XNJyNnyiowKWt8Knn0umPoFp 2Ib+0mEMgD8zSIQ/JWysGmWy9RncnoFwhJdvF79XKpEme2JIDlAn5mgjS0hpx5E+AIfg Opgw== 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:mime-version :content-transfer-encoding; bh=DZMa6DET1qb3XpdgoNbeTgpSZ2dO/+nB5dNSP35ZNe0=; b=OrMIipjMx+D7qPs1cYAtd1UwoHqlQtWmD5qDZxuMQbtr6CQ/ntCqbuCTDmEsrlcZm1 btDH3bKNBRQVykqb/1hs+5hKEsdkcR4YbdM0cZoUcrhwF5HNLDjRUKPNrRu2Y9uIgoY3 3KySn5/FeYyb/87YzaB9j+QBXS5B1N0swfmYaLnIrADSlcI1TqPk6BnLlC58JCmYUpgd H8uAMyInf5ECedHJPPe4S0k2nPS9n6e9N72LuXtlxFkreUVpmhHDBnPKRxMnm5Bv41EQ xamg/5Q3zJBxkoAy/2ddRcMHJ7DNsZ87qpTy6vKuu5rgwCsp/VwBNA2DXkknY7xcMQRP dPEA== X-Gm-Message-State: AOAM530Z3Kv7bx3pVWNctHdrm4DzDrCQ7RsE9mTmDeNevzTwO3wealBU 7eBBo4nrZ3C2/yTZS/pYzLEXVBMtiuI= X-Received: by 2002:adf:9ccf:: with SMTP id h15mr7360121wre.275.1592383303080; Wed, 17 Jun 2020 01:41:43 -0700 (PDT) Received: from localhost.localdomain ([2.27.167.65]) by smtp.gmail.com with ESMTPSA id k14sm31635998wrq.97.2020.06.17.01.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2020 01:41:42 -0700 (PDT) From: Lee Jones To: michael@walle.cc, robh+dt@kernel.org, broonie@kernel.org, gregkh@linuxfoundation.org, andriy.shevchenko@linux.intel.com, devicetree@vger.kernel.org, linus.walleij@linaro.org, bgolaszewski@baylibre.com, arnd@arndb.de, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Lee Jones Subject: [PATCH v2 1/1] mfd: Add I2C based System Configuaration (SYSCON) access Date: Wed, 17 Jun 2020 09:41:32 +0100 Message-Id: <20200617084132.704549-1-lee.jones@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The existing SYSCON implementation only supports MMIO (memory mapped) accesses, facilitated by Regmap. This extends support for registers held behind I2C busses. Signed-off-by: Lee Jones --- Change log: v1 => v2 - Remove legacy references to OF - Allow building as a module (fixes h8300 0-day issue) drivers/mfd/Kconfig | 7 +++ drivers/mfd/Makefile | 1 + drivers/mfd/syscon-i2c.c | 90 ++++++++++++++++++++++++++++++++++ include/linux/mfd/syscon-i2c.h | 26 ++++++++++ 4 files changed, 124 insertions(+) create mode 100644 drivers/mfd/syscon-i2c.c create mode 100644 include/linux/mfd/syscon-i2c.h -- 2.25.1 Reported-by: kernel test robot Reported-by: kernel test robot diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 0a59249198d34..f25f80f68edca 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -1300,6 +1300,13 @@ config MFD_SYSCON Select this option to enable accessing system control registers via regmap. +config MFD_SYSCON_I2C + tristate "System Controller Register R/W Based on I2C Regmap" + select REGMAP_I2C + help + Select this option to enable accessing system control registers + via I2C using regmap. + config MFD_DAVINCI_VOICECODEC tristate select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index f935d10cbf0fc..0aec1f42ac979 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -219,6 +219,7 @@ obj-$(CONFIG_MFD_RK808) += rk808.o obj-$(CONFIG_MFD_RN5T618) += rn5t618.o obj-$(CONFIG_MFD_SEC_CORE) += sec-core.o sec-irq.o obj-$(CONFIG_MFD_SYSCON) += syscon.o +obj-$(CONFIG_MFD_SYSCON_I2C) += syscon-i2c.o obj-$(CONFIG_MFD_LM3533) += lm3533-core.o lm3533-ctrlbank.o obj-$(CONFIG_MFD_VEXPRESS_SYSREG) += vexpress-sysreg.o obj-$(CONFIG_MFD_RETU) += retu-mfd.o diff --git a/drivers/mfd/syscon-i2c.c b/drivers/mfd/syscon-i2c.c new file mode 100644 index 0000000000000..be20ff45ece07 --- /dev/null +++ b/drivers/mfd/syscon-i2c.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * System Control Driver accessed over I2C + * + * Copyright (C) 2020 Linaro Ltd. + * + * Author: Lee Jones + */ + +#include +#include +#include +#include +#include +#include + +static DEFINE_SPINLOCK(syscon_i2c_list_slock); +static LIST_HEAD(syscon_i2c_list); + +struct syscon { + struct device *dev; + struct regmap *regmap; + struct list_head list; +}; + +static const struct regmap_config syscon_i2c_regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; + +static struct syscon *syscon_i2c_register(struct i2c_client *client) +{ + struct regmap_config syscon_config = syscon_i2c_regmap_config; + struct device *dev = &client->dev; + struct syscon *syscon; + struct regmap *regmap; + int ret; + + syscon = devm_kzalloc(dev, sizeof(*syscon), GFP_KERNEL); + if (!syscon) + return ERR_PTR(-ENOMEM); + + syscon_config.name = dev_name(dev); + + regmap = devm_regmap_init_i2c(client, &syscon_config); + if (IS_ERR(regmap)) { + dev_err(dev, "Failed to initialise Regmap I2C\n"); + ret = PTR_ERR(regmap); + return ERR_PTR(ret); + } + + syscon->regmap = regmap; + syscon->dev = dev; + + spin_lock(&syscon_i2c_list_slock); + list_add_tail(&syscon->list, &syscon_i2c_list); + spin_unlock(&syscon_i2c_list_slock); + + return syscon; +} + +static struct regmap *syscon_i2c_get_regmap(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct syscon *entry, *syscon = NULL; + + spin_lock(&syscon_i2c_list_slock); + + list_for_each_entry(entry, &syscon_i2c_list, list) + if (entry->dev == dev) { + syscon = entry; + break; + } + + spin_unlock(&syscon_i2c_list_slock); + + if (!syscon) + syscon = syscon_i2c_register(client); + + if (IS_ERR(syscon)) + return ERR_CAST(syscon); + + return syscon->regmap; +} + +struct regmap *syscon_i2c_to_regmap(struct i2c_client *client) +{ + return syscon_i2c_get_regmap(client); +} +EXPORT_SYMBOL_GPL(syscon_i2c_to_regmap); diff --git a/include/linux/mfd/syscon-i2c.h b/include/linux/mfd/syscon-i2c.h new file mode 100644 index 0000000000000..e9ded6a363234 --- /dev/null +++ b/include/linux/mfd/syscon-i2c.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * System Control Driver accessed via I2C + * + * Copyright (C) 2020 Linaro Ltd. + * + * Author: Lee Jones + */ + +#ifndef __LINUX_MFD_SYSCON_I2C_H__ +#define __LINUX_MFD_SYSCON_I2C_H__ + +#include +#include +#include + +#ifdef CONFIG_MFD_SYSCON_I2C +extern struct regmap *syscon_i2c_to_regmap(struct i2c_client *client); +#else +static inline struct regmap *syscon_i2c_to_regmap(struct i2c_client *client) +{ + return ERR_PTR(-ENOTSUPP); +} +#endif + +#endif /* __LINUX_MFD_SYSCON_I2C_H__ */