From patchwork Thu Jun 18 08:02:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 191086 Delivered-To: patch@linaro.org Received: by 2002:a92:cf06:0:0:0:0:0 with SMTP id c6csp1183366ilo; Thu, 18 Jun 2020 01:03:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5qNC7DVOjnLPZANduibSGPkaqKaHXZvvBfdtL1HfhvUwnpFWtrSrZ3G4UQgTCL21wOxjy X-Received: by 2002:a17:906:c837:: with SMTP id dd23mr2951800ejb.272.1592467428768; Thu, 18 Jun 2020 01:03:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592467428; cv=none; d=google.com; s=arc-20160816; b=ezoDOim9bigNndLeIrc0i/uk3ezjSi2KPFnZRVN2DI8jDpZK4a+coNF9didOLJ3tFz EWXrmvjm7emsdt6yBuXP+j89ypzkSHaE32k8auSqtzW5FvZ90Q5FvYxbxcWXJDP5jk2+ BvhanK0DVFx/ZvjzZ3YYq/pb2e++GUDpOOAk0six8h+X9xN9s3xWZ7NiQXKPWrXEpmIO PiLOb2WVwI89ZSBNDTTnc1Ue419kRuVAZwjAb5TUExZUkrAB2HTiBXQtyex8c5Zbmg+i jXZ6AQY3lOxxdmJb/E3Z/aLgs8rrPb53MHGe0cbdnHsWYwnyz3R9MLTLB9BU97bFC5gi /aTQ== 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=snbtRNLKXE7yHksAGK/7/+6vOL8esqkdbmpVrdd/OU/gAVV6M7ljeHihtyFBzUAQAx 5h+1qC1RFo3ouaUrMQST+8F55X1TdD0a8LxknV2UdclIi9MCKkucenGpIbeAFloEGkEK +oD6sv11LL8Y2jOiOPP9cMtlsnL+tHPvOp1HbXV5+6h0v6tUfeTNWWS06YfekCshiar9 9G43nEIyW4VMHMoCsHL2NfvlIEUiXRea/gP0j95mWE9VoeOY+7Gg71T7NCHFQ2qGtS9J tDuPB2XCpKovimE4bv72W2jpeuFU7DLwLaO6Z8TmqrtcYJ+OoZMejGga0GKwhwNnmeQn rXPg== 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 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 z23si1393409ejw.331.2020.06.18.01.03.48; Thu, 18 Jun 2020 01:03:48 -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=DJkBYiuu; 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 S1728127AbgFRIDp (ORCPT + 6 others); Thu, 18 Jun 2020 04:03:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728210AbgFRID2 (ORCPT ); Thu, 18 Jun 2020 04:03:28 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C5D0C0613ED for ; Thu, 18 Jun 2020 01:03:27 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id c3so4959999wru.12 for ; Thu, 18 Jun 2020 01:03:27 -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=rKAVN+zgIcQcXRl1cdJ0ZmBO3g0T7UIb5HTsmSp3KZLPJgllj/7Gf8Fd1JswvQMGBM cxg7KzrjiQLUOvyUWQiS2UUuQwSrIRNsNj0ydJu3ALUnK5lbtCQs4ILW+meO6GUDiNHg kUEjG4T9UgHGNG2NQoUjDSySAGqU4A7r4NwifAxK6iLq8adax7TvNy8lOhO4l9A6fD27 shGZ5P2y+D/LXNDd1r1Mf2s0JMvRQG/4AGHWnyPbrxEN56lblGQtNRdHmQE29a07FaMd 4vgPt98Jp16jnmLmtLztcuAOxieKsaHl/RPAGzeuR63PHGeHxCjBu2Ncz/PPNteClVul BRVw== X-Gm-Message-State: AOAM530k6shrNrrpznxdyRZZ6afNiJ8bIGgN3NnzXfMmLfBV82SThrmX ymFMk/1+xDsc6J2dsgdsvY315Q== 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 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 --- 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 -- 2.25.1 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__ */