Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1136291ybt; Thu, 18 Jun 2020 01:08:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUUKGvHdO9v+DuHTfvPvDZMkkSlTgZncQ+41p7v+InklG70Cz5gwnvpa+xhh6XcjGFGOKw X-Received: by 2002:a17:906:8401:: with SMTP id n1mr2760481ejx.479.1592467701248; Thu, 18 Jun 2020 01:08:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592467701; cv=none; d=google.com; s=arc-20160816; b=TuY9CEghdzqjTLlKyzZ/CynFz7KjCZ60Gzrxq+IaUQ8uW0wra9wR8u90B6y2qh01SM hDnx+UrdJqYmJljO1ZXuAHeJlYj34zLCqyk4rz7kHjOD4im5fn85rWM1XOAKAx7e79kQ 1HMNISra3dD/IQ387Yr6dsbTWEND9Ln0ZbNG25rD5y2dZULYwArAp+P/WEKW7QxYP1u5 GwAT905B/py6Ik7he4ce5R1bLDYp38OGc9IePypzSw85+EKfr1rhxp4aaO90Tr+YLJmV tMd0W9OhHRoUSdVX4i6NVPWK7uKvzYOOdJkzMMorJZckEVNCQbNNCDzx1V6M2wpsAmCo jvSQ== 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=/SU7W2GJKeHJvbcABLTspqPlvuU+fo28Kd5ODOQRwk4=; b=JuCrLoa+ODgbkO2BCPjhaON2drkw0OHMna+Cd6PRk6YHcMFWGFjTbBp30t+jdC1lyp WASR94PpCxJvffJ1+b8Iv+UMRy7rk+B5ErorGgNVFjbVnYPm7GIr5/R2kf/wwjNLVsCu 6k7i2darrb1nO6sZ3g9eqR6cyH5dMrl3YfWzCOpUPwdxuES22E71l6OIV+6s7+bMzsXb 8GA3RBsRpMQjzgkhznLlHUaxFGJBqx33zZtoREtxxviWhy5JmU3kgLwIOY+Gsem9k0fV 3ZzWxWnVMlNPqIZocH6afnwXNwyuEJkPV4iqdqrpZVJvDzr9JrbVuIn8lB4ErmMsvo2J JM2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DJkBYiuu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id dp9si1895500ejc.698.2020.06.18.01.07.56; Thu, 18 Jun 2020 01:08:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=DJkBYiuu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728255AbgFRIEI (ORCPT + 99 others); Thu, 18 Jun 2020 04:04:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728308AbgFRIDo (ORCPT ); Thu, 18 Jun 2020 04:03:44 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62B7EC06174E for ; Thu, 18 Jun 2020 01:03:28 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id t13so2567292wrs.2 for ; Thu, 18 Jun 2020 01:03:28 -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=/SU7W2GJKeHJvbcABLTspqPlvuU+fo28Kd5ODOQRwk4=; b=DJkBYiuucTO/DfAGSZdUlUh8cxXQmxceh05pT+8VxUyh3WiCS0DCPC7LZ5NI6Ts/lN ZhnlA2qGFXvIZcbpPEG8dmsGeQxWAA9sGmdLO3ShUJWOvyMq5yPT98Yq0f76kvRbs7bc LY+bMF5DiUWSG1frJcxziEiCdsIF11rMVLxDxmlvPTDJZwYiVwaZqNsIkS6BPnlot8o+ Jv1xk+pOLWxVlgZQR213Enj1kOYdDufZXejqZ/Jurpzz5SnHQzQr593iQo/X+jwgAKK7 EoHW2PG2twbHH7PZIAMHbZOejjilvUV5AEAS0ojmpCTXcar399OfEiR47tS22udQfgfK A2MQ== 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=/SU7W2GJKeHJvbcABLTspqPlvuU+fo28Kd5ODOQRwk4=; b=F58ChryAdYhLpvfX00ex1S8E+T5RgHgU+DucYLT4S/1Ycj4Fw7//P4XEWclJtbk4OQ jWF0oIc36kkbpu2HG78m7/nhswXs6IANy6ePoTnv/hMWxz1NGeP69GErRYSJan+q1YUA IVlmzYaFP9yUBLFUR0CyIKL5hTgj8cIZIKhDI2bbQDwelC4elkOWkx3HwuBjSUJgJJw0 1Nsz9ej4OM4Neg5CuhdDMkZYSthsCxReBS2wnxiUiTUilyEX4gwaw0XxRSYn1Kbr1h60 OJoHCrfmLDh2rt/Qp3wIWUi5qVSlcddVil58ERRkEmV+RsC+Tczh7Droq27PyTkrgB53 FBzw== X-Gm-Message-State: AOAM533cn29Ert0z976X85a4Wn0oBO0OUMT8/2/K6JMEBji+LC+f9D8W mFH4JhNdRTiGq+CFNsXQCizC2Q== X-Received: by 2002:a5d:6087:: with SMTP id w7mr3603718wrt.158.1592467405816; Thu, 18 Jun 2020 01:03:25 -0700 (PDT) Received: from localhost.localdomain ([95.149.164.118]) by smtp.gmail.com with ESMTPSA id z16sm2425174wrm.70.2020.06.18.01.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2020 01:03:25 -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 Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Lee Jones Subject: [PATCH v3 1/1] mfd: Add I2C based System Configuaration (SYSCON) access Date: Thu, 18 Jun 2020 09:02:23 +0100 Message-Id: <20200618080223.951737-1-lee.jones@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- Changelog: v2 => v3 - Change 'is CONFIG' present check to include loadable modules - s/#ifdef CONFIG_MFD_SYSCON_I2C/#if IS_ENABLED(CONFIG_MFD_SYSCON_I2C)/ 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 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..490bc37b603cb --- /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 + +#if IS_ENABLED(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__ */ -- 2.25.1