From patchwork Wed Aug 4 14:37:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 12419145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99099C4320A for ; Wed, 4 Aug 2021 14:39:50 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6B3C460F01 for ; Wed, 4 Aug 2021 14:39:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6B3C460F01 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=9xMLqig0/OXxNvuMydqCEWNRWHZhwQuJcgqWLQJ0q5k=; b=gpqgxXpqCks2sA R9rt5AWtLQ/NkdXNHTx6iryvmP9VRUIVCZDKyCX+LYtDjfZL2NoVeY16w0evREVvRtv+e34lOrkOx jq0yD1K/PE8WXHICmHkn2ny1EF5e+t3XOPzEIXCgUio8bLKujtw1QLxfibfwbKwIRX1Ql5qFgIwf1 WXlnBGuTvTt33Olb+qE8nDKDAJ0bvX56w6JxLKXIghDE8dEO+EFmWtLWtykpDtezQOAZMkjCxLnkD jYq/3qqbYuQ9d1SPcFLrPRvN4IJ90K8wYC5+9vgGBfjhpGhJ+u2FlCQ2m2mL4TzOAdE1MoGm3Zwvk iOh3XHXjbhLTgAMtFXmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBI1s-006T5Q-VE; Wed, 04 Aug 2021 14:37:57 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBI1o-006T44-66 for linux-arm-kernel@lists.infradead.org; Wed, 04 Aug 2021 14:37:53 +0000 Received: by mail-wr1-x42b.google.com with SMTP id k4so2569005wrc.0 for ; Wed, 04 Aug 2021 07:37:51 -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=5ZWPk7+tHwwQUoVBZmKXeuGPCR5jkfcKlPCiW0KLOiM=; b=Auz3Sqxy9OiRA7eMF6erDlUjpzk6k7FCOJQ/Ia6d8SiDfIvqQqzfqAMefWq+n2IsC4 HnXKWTRyZrv5iupQo/zZJmiIYwhxIAzNG9NYCgp0TOb5AzKK6V2Z1MpGtZSj0gzWi2y9 2/HfTd+ZM4A23c3lEYcSNqwBox8k8UeZ4LvxoepWjiqXacBOtYHO9F34hiIKoBK2Eztd +el3PvuCH94AZrd27hPdTD6jTTiN6THlezFhLnMA31iU63jQTjIaMUsVkwWiqfYqt1nr NL2v/NrNWDLnIRw300aoU87OdR8z3YLKCfS+uQ6Aw45k5C2aKaHHiXffyrmx50i7IDrV z3qw== 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=5ZWPk7+tHwwQUoVBZmKXeuGPCR5jkfcKlPCiW0KLOiM=; b=otNtv5F2g5ru1Nj8IOR3kGB4YLOV6ELOTaRgE2dRQIuV+uhB8+jvov/1o+vZFFVMZY tCdTtD6H07d5JPrF4YYNRoc5njHBPb/xbB+ZTvmKpwDCZcT6Nu0pCXh2fCaVM0HSzWio lGFoPzPCa+yAIuBlLnf/lCKKi6GHZ80mlYPmSBbqzAfvRCvuKn/zO3Mi45y1E4wJh7eN GvRlkjPMYpEewiRYRnqRtGJPvZzD4j7W1x2rb9x8B95oCbwoBn+aEXJ0egDdeGHvzNcB 79OAqVw4JWD6FG/JfpNCZkPviZTQlaZavli+Yu9cSqLnlmDKKAzOADzqivv4yb29gnp4 HTwA== X-Gm-Message-State: AOAM532PYpB/6b2h0s4bbtmJNr38IfT0MMiovpffa9JrGzm5K3IoFs7q KcKwzM0PpdMPk8o6kHxG20PK9Q== X-Google-Smtp-Source: ABdhPJznqTDQnE3lHtVT3M5ocBtDeSwhIDmqRg3Cym1DowVfbY6vQ6j1tHU5GNvgaL0yQx507T+y6g== X-Received: by 2002:a5d:6184:: with SMTP id j4mr29617399wru.340.1628087870408; Wed, 04 Aug 2021 07:37:50 -0700 (PDT) Received: from localhost.localdomain ([109.180.115.228]) by smtp.gmail.com with ESMTPSA id f17sm3362958wrt.18.2021.08.04.07.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Aug 2021 07:37:49 -0700 (PDT) From: Lee Jones To: lee.jones@linaro.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Michael Walle , Mark Brown Subject: [PATCH 1/1] mfd: simple-mfd-i2c: Add support for registering devices via MFD cells Date: Wed, 4 Aug 2021 15:37:44 +0100 Message-Id: <20210804143744.689238-1-lee.jones@linaro.org> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210804_073752_278285_45AF7527 X-CRM114-Status: GOOD ( 22.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org More devices are cropping up requiring only Regmap initialisation and child registration functionality. We currently only support that if all required devices are represented by their own Device Tree nodes complete with compatible strings. However, not everyone is happy with adding empty nodes that provide no additional device information into the Device Tree. Rather than have a plethora of mostly empty, function-less drivers in MFD, we'll support those simple cases in here instead via MFD cells. Cc: Michael Walle Cc: Mark Brown Signed-off-by: Lee Jones --- Michael, could you please test this on your platform to ensure I didn't break anything please? drivers/mfd/simple-mfd-i2c.c | 39 ++++++++++++++++++++++++++++-------- drivers/mfd/simple-mfd-i2c.h | 27 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 drivers/mfd/simple-mfd-i2c.h diff --git a/drivers/mfd/simple-mfd-i2c.c b/drivers/mfd/simple-mfd-i2c.c index 87f684cff9a17..fec3f002a9119 100644 --- a/drivers/mfd/simple-mfd-i2c.c +++ b/drivers/mfd/simple-mfd-i2c.c @@ -2,39 +2,62 @@ /* * Simple MFD - I2C * + * Author(s): + * Michael Walle + * Lee Jones + * * This driver creates a single register map with the intention for it to be * shared by all sub-devices. Children can use their parent's device structure * (dev.parent) in order to reference it. * * Once the register map has been successfully initialised, any sub-devices - * represented by child nodes in Device Tree will be subsequently registered. + * represented by child nodes in Device Tree or via the MFD cells in this file + * will be subsequently registered. */ #include #include +#include #include #include #include -static const struct regmap_config simple_regmap_config = { +#include "simple-mfd-i2c.h" + +static const struct regmap_config regmap_config_8r_8v = { .reg_bits = 8, .val_bits = 8, }; static int simple_mfd_i2c_probe(struct i2c_client *i2c) { - const struct regmap_config *config; + const struct simple_mfd_data *simple_mfd_data; + const struct regmap_config *regmap_config; struct regmap *regmap; + int ret; + + simple_mfd_data = device_get_match_data(&i2c->dev); - config = device_get_match_data(&i2c->dev); - if (!config) - config = &simple_regmap_config; + if (simple_mfd_data->regmap_config) + regmap_config = simple_mfd_data->regmap_config; + else + regmap_config = ®map_config_8r_8v; - regmap = devm_regmap_init_i2c(i2c, config); + regmap = devm_regmap_init_i2c(i2c, regmap_config); if (IS_ERR(regmap)) return PTR_ERR(regmap); - return devm_of_platform_populate(&i2c->dev); + if (!simple_mfd_data->mfd_cell) + return devm_of_platform_populate(&i2c->dev); + + ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO, + simple_mfd_data->mfd_cell, + simple_mfd_data->mfd_cell_size, + NULL, 0, NULL); + if (!ret) + dev_err(&i2c->dev, "Failed to add child devices\n"); + + return ret; } static const struct of_device_id simple_mfd_i2c_of_match[] = { diff --git a/drivers/mfd/simple-mfd-i2c.h b/drivers/mfd/simple-mfd-i2c.h new file mode 100644 index 0000000000000..a2a0bc45b4e3b --- /dev/null +++ b/drivers/mfd/simple-mfd-i2c.h @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Simple MFD - I2C + * + * Author: Lee Jones + * + * This driver creates a single register map with the intention for it to be + * shared by all sub-devices. Children can use their parent's device structure + * (dev.parent) in order to reference it. + * + * Once the register map has been successfully initialised, any sub-devices + * represented by child nodes in Device Tree will be subsequently registered. + */ + +#ifndef __MFD_SIMPLE_MFD_I2C_H +#define __MFD_SIMPLE_MFD_I2C_H + +#include +#include + +struct simple_mfd_data { + const struct regmap_config *regmap_config; + const struct mfd_cell *mfd_cell; + size_t mfd_cell_size; +}; + +#endif /* __MFD_SIMPLE_MFD_I2C_H */