From mboxrd@z Thu Jan 1 00:00:00 1970 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 E9616C4338F for ; Thu, 5 Aug 2021 08:57: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 9827661029 for ; Thu, 5 Aug 2021 08:57:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9827661029 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=F/7/6QXNe3n+7syrl/LM34OXFIV9oelS1W1EOZNG1n4=; b=0XCDq+0Xg6SlMU VnWD5X8li/kM+6+A/alqzvovEZUfGnTmNF7D3/hG7fRem3AfGc0Uz5T+7KhfpRrnNCPWMrMruCerT ZRPFJ17qnWvD4E+0aI/lDM/nxBs9U9c5yGui13idyPbqbNGPtkgRgygJd7vIwUVh+1BKVG9F9F68r PYrWOi6K9ZcOnnNyc8YVC/Zn0odTbwoGPD9WHhRI0UfeQliUNbPR90Ku/fEah2vjyFeD3v305pMZx 7ygKB+4AjfnJKqWXaqjoTwcGi4mZxzzIzo+16NG5e8GlBKORkWEXpdBg321H9PsXI4spBZMGzsnpm eKGbIljIlwvF5A/8NuEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBZAx-008jir-Ei; Thu, 05 Aug 2021 08:56:27 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mBZAs-008jhG-LR for linux-arm-kernel@lists.infradead.org; Thu, 05 Aug 2021 08:56:24 +0000 Received: by mail-wr1-x430.google.com with SMTP id d8so5502766wrm.4 for ; Thu, 05 Aug 2021 01:56:22 -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=ShTZj+HIAeLpiq9YvD+6pHmtdjVO68mn7AFkKA0+vc8=; b=aOHovJdNObp9K7lLrz3Ph4D1/eFfv+qkCoCGmptK5mt8SdusqOG/RJkxOtjJ9pCS25 gkCzloVHb4CpRhTLm0WP3TxavvhiNC4uxG+0KhEe65iBGIjFL+1JnAq9HN0AYEE424D6 fYjFl8fcAMsH2Rg3ehXeKU1z7ta25L4MnxVdywF/kSo9jlh78crDYIHCr4hLLx4OATRC D1SQbS5ugYw28NKwt71GDkNAM8jiVg52q4JIQI/kfptOg3a8zvA88PB+ZRIv4IwEAqpy M0mDQ1i6+dzL6stS6SASCivLb5+CuGmkLdgEkK9oCNu6fAelwfLYcsdGDwAqZOkOZr58 ydpw== 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=ShTZj+HIAeLpiq9YvD+6pHmtdjVO68mn7AFkKA0+vc8=; b=h2AnJ9TNlUYLre2PTEe246VzQFYOlV5Q2Yp9MZLMGJtRQ6fF+tFyYnNt6Y56U3Vv/W 7PbK3ZUuP3kquloe/T4KEuRlFaTTb+c2ZQ571cbuWfPNe9aqTZA4w42FbjoSpLCovju2 GRKmAzDxj9pqQZhGdnD6Ezy8TOAzSCbMzcKuyV4RDLpsJTY7rKF7aU1wDoGf8Q3aTaEI tb3HyuyBlbAtYy3phOOfjGEFby7jRHYAVgnOKiTvkPFIh6CQwoU+wPdRb4xTcGlLM4XG r9GoEi1UYVt5waoo/RWsDOd/TQdiBnPlb/ExK4fM32YhZQsjgRSTopV1mCAi029wOrhh EVKA== X-Gm-Message-State: AOAM5323AKVYKge3qmmkwBTrlOVzoMldOyJplA1BGNhIUSZUgc4DHc+b a8S/5wiQZuwAaLAAmzJUsiA4Iw== X-Google-Smtp-Source: ABdhPJybwz4TiJiuC7dy1v3KbuLmu60twVjOp2sL/z0tM65W9LwawmNRLQh/dX0Z0Yh6+TBiOJPAiA== X-Received: by 2002:adf:db07:: with SMTP id s7mr4078662wri.106.1628153780889; Thu, 05 Aug 2021 01:56:20 -0700 (PDT) Received: from localhost.localdomain ([109.180.115.228]) by smtp.gmail.com with ESMTPSA id o28sm1116144wms.14.2021.08.05.01.56.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 01:56:20 -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 , Alistair Francis Subject: [PATCH v2 1/1] mfd: simple-mfd-i2c: Add support for registering devices via MFD cells Date: Thu, 5 Aug 2021 09:56:11 +0100 Message-Id: <20210805085611.864188-1-lee.jones@linaro.org> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210805_015622_758767_F8F145E7 X-CRM114-Status: GOOD ( 22.87 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 Cc: Alistair Francis Signed-off-by: Lee Jones --- v2: - Check for empty of_device_id .data entry drivers/mfd/simple-mfd-i2c.c | 41 +++++++++++++++++++++++++++++------- drivers/mfd/simple-mfd-i2c.h | 32 ++++++++++++++++++++++++++++ 2 files changed, 65 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..583e8c7924af0 100644 --- a/drivers/mfd/simple-mfd-i2c.c +++ b/drivers/mfd/simple-mfd-i2c.c @@ -2,39 +2,64 @@ /* * 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 no regmap_config is specified, use the default 8reg and 8val bits */ + if (!simple_mfd_data || !simple_mfd_data->regmap_config) + regmap_config = ®map_config_8r_8v; + else + regmap_config = simple_mfd_data->regmap_config; - 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 no MFD cells are spedified, use register the DT child nodes instead */ + if (!simple_mfd_data || !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..7cb2bdd347d97 --- /dev/null +++ b/drivers/mfd/simple-mfd-i2c.h @@ -0,0 +1,32 @@ +// 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. + * + * 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 or via the MFD cells in the + * associated C file 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 */ -- 2.32.0.605.g8dce9f2422-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel