Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp4127442pxm; Tue, 1 Mar 2022 11:50:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwg/NKEaPFDLGj1QnLiOKX9DpjYB+k54FnWYhLk349fl3dbcutha1w1ztuprlsMDWkkjjGM X-Received: by 2002:a17:907:765a:b0:6d1:bc6:df10 with SMTP id kj26-20020a170907765a00b006d10bc6df10mr19530326ejc.254.1646164215805; Tue, 01 Mar 2022 11:50:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646164215; cv=none; d=google.com; s=arc-20160816; b=uTmITasjeWqn/wR9LYxBEGbImKky5SHJGdnW6dnZt291im+3/TPsDsbzIc+sfFVL5W zT1r8EBn/pnYyuGAXaZbNPhqpSR5brneFw/TyitdKqD6Kw3zj0j/xruKO7rcND8PzcKJ 0TOtSAIygM6L/Sxg7r/HT7K5O0VUUdKOfvXYa5noX9GN0mgnoOA8Vxs0uxK5rWfshq+S 7jbEwCEEKUTLLV+BViCOmkTTfDTqPOgm5TMRcwXL4uBzU3VRjf8uQ+9djKGQIiYVbqAY rjEtZj7KIlYHWkLD4Z4r0zWJG/j+EgsIG3G2VTHAlzbG4tVtFyLbLnMCz2vBbajF4KsP ZoEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KAoobEf0FgmH/phyTwuBEP9MQR4VO/sSwTaKsDfFC5Q=; b=giaqgntGg4azhenhcAr3QWlVbMpHe8+MVFUDBhfudapMep2kf4EVmSevVjd/OrziUf S5oPckv3QkPpMjlZqzavnGL2rHtCVYNhxKDULUff3knqPdSBeziNrllsQqWlW9OqCDHJ OZbfHtozZKgCxQCMhbti61C/WT3IkjJNUEC0921b4aEgsFyBLAzSRXneMcJVW19FZuN6 w0613OO/ODXKTJ+EEBh615dOS6UU6LlteCXYCbTx4GHL7sVYqwM+KTXMIqwIh6DCn4pU Dkzg4Xf6ruFMXsgQfSZwzcwhRbaus3XIj/Ljlx+RAXThTNaYxk7zpcdtsQwRZdUzOUGW +bxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=SUAAsqaS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w3-20020a170906480300b006d5904de1b7si8200325ejq.576.2022.03.01.11.49.52; Tue, 01 Mar 2022 11:50:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=SUAAsqaS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234559AbiCALTi (ORCPT + 99 others); Tue, 1 Mar 2022 06:19:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234484AbiCALT0 (ORCPT ); Tue, 1 Mar 2022 06:19:26 -0500 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A5A92253C; Tue, 1 Mar 2022 03:18:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1646133526; x=1677669526; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KAoobEf0FgmH/phyTwuBEP9MQR4VO/sSwTaKsDfFC5Q=; b=SUAAsqaSBWYEmuv7bWXIZEcC0p8L1gZvwMLwCgOoQCyJsZ4Bi6IeRlU5 y9vPHAn7ge5t9eQh5lN1x3qQOH+mv5yYAV+gIjGDvO7WnQlbdRhEOyDhO V3VkBVD9YbgWDfpwuCns9Q+wBTjR5pAiZei7lNhD1h1l0DK/coJCRM8eh nHPeOQ/iv9YP40QnMwZBE6h1pWw57VaXefar7E1XyPQDaIN4lwjBYFgdx 3CTR+ggUKtbkpf8UaIFTLLtlVVp3+e2S4NXEBZeXvriqURwP33Gsasclh Gx3fRE7gqP4b8GvdlvBH0fgJQqZ9qPtyH4zeV0SamZFFT+Hi65svHrZdj A==; From: Vincent Whitchurch To: , CC: , , , Vincent Whitchurch Subject: [PATCH v2 3/3] regulator: virtual: add devicetree support Date: Tue, 1 Mar 2022 12:18:31 +0100 Message-ID: <20220301111831.3742383-4-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220301111831.3742383-1-vincent.whitchurch@axis.com> References: <20220301111831.3742383-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The reg-virt-consumer is very useful for development and testing of regulator drivers since it allows voltages and modes to be set from userspace. However, it currently requires platform data so it cannot be used without patching the kernel. Add support for probing it from the devicetree to remedy this. Since this driver is only meant for testing and is a purely software construct, no binding documentation is added. Signed-off-by: Vincent Whitchurch --- Notes: v2: - Only use the "default" supply name if dt - Add a comment explaining the "default" supply name drivers/regulator/virtual.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/regulator/virtual.c b/drivers/regulator/virtual.c index 9e0abbee1df5..5d32628a5011 100644 --- a/drivers/regulator/virtual.c +++ b/drivers/regulator/virtual.c @@ -13,6 +13,7 @@ #include #include #include +#include struct virtual_consumer_data { struct mutex lock; @@ -281,6 +282,14 @@ static const struct attribute_group regulator_virtual_attr_group = { .attrs = regulator_virtual_attributes, }; +#ifdef CONFIG_OF +static const struct of_device_id regulator_virtual_consumer_of_match[] = { + { .compatible = "regulator-virtual-consumer" }, + {}, +}; +MODULE_DEVICE_TABLE(of, regulator_virtual_consumer_of_match); +#endif + static int regulator_virtual_probe(struct platform_device *pdev) { char *reg_id = dev_get_platdata(&pdev->dev); @@ -305,6 +314,14 @@ static int regulator_virtual_probe(struct platform_device *pdev) if (drvdata == NULL) return -ENOMEM; + /* + * This virtual consumer does not have any hardware-defined supply + * name, so just allow the regulator to be specified in a property + * named "default-supply" when we're being probed from devicetree. + */ + if (!reg_id && pdev->dev.of_node) + reg_id = "default"; + mutex_init(&drvdata->lock); drvdata->regulator = devm_regulator_get(&pdev->dev, reg_id); @@ -345,6 +362,7 @@ static struct platform_driver regulator_virtual_consumer_driver = { .remove = regulator_virtual_remove, .driver = { .name = "reg-virt-consumer", + .of_match_table = of_match_ptr(regulator_virtual_consumer_of_match), }, }; -- 2.34.1