Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2558116rdb; Wed, 4 Oct 2023 05:10:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG86wUntvwZpalIHA83H+fX+YUVle60VfSPdwKEd0T73tKvz09iL22nXPEJugcqMaJ5VA6c X-Received: by 2002:a05:6830:18dc:b0:6b9:5b04:8cb0 with SMTP id v28-20020a05683018dc00b006b95b048cb0mr2038223ote.9.1696421439002; Wed, 04 Oct 2023 05:10:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696421438; cv=none; d=google.com; s=arc-20160816; b=pG0blNMHSIQ8NKwPGyNM5vGB4i8qdzTd2rs2ANpbN0Kirm/GVeWbe/j3PrxuWQoF7m o9qP3eRsvDpUJGurWgOBT3jW3tyx3xOSr7ZqUtbSvF5qCdOwMFVD2bgAxp8v8o9s+ODV mIpAuj0+Zo+cDGg6EEGk+g6CQK3eHMdJwdScAplIXPvhljrMRIrqgY/4+Q9Ydzta3Jdm 6VxdUg48iU1ua9nGWXq5zCiY3jnbhPfzN1INMYRaNBGnJT1rZ8eScRB2WRPqd488sg0p ltUe0s1xexfI09P13xMixGKuAS60aekc/WcD7RXDbwxqvh+6DrRA+Of+HqbP82pTZ2W2 bKqw== 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=PDAx+WeaAfeMTk0iyLZZaQojNWk87fXDiAYeAoWRhyA=; fh=8KXh4pBEmy+NtF/opnUgUmKV+7RocDF9urRJBwd73MA=; b=tBn1dW6Ixk0F0lqWvKyDenkqHDUGlvQfWVsc2mFEdU2iSnpU4vzZ4nOx+wDDpIUSpd tQBpmBnD03NFw6idMzvsHtvdS2DhWSOCOYPOAfj7I/L/OfbGdyF5Fld9hgIj3mX754Rk 2GVVme16t4sg78kiywXw1JiiI9rHnnQC1noKr7lvlcGDiT4f9CJ0Xcalf+hkzSCPWETs rwbxq7JeyJV2OfE0p6RP3MxIcAKt7BH/VVi8LO9VqZxgN14KAmf3UFnGWoS//r4Y3ZDt UbGb6CrtFwqLndr/LItBSCUVKWhshL8zJlMlJZbk/lV/QKcqyUPMFvrnlNkKhi5SLOzb FfMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=UHZm4+pt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=9elements.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id o15-20020a656a4f000000b0056ba5e3f604si4109041pgu.352.2023.10.04.05.10.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 05:10:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=UHZm4+pt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=9elements.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id C608880DBAC4; Wed, 4 Oct 2023 05:10:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242310AbjJDMKV (ORCPT + 99 others); Wed, 4 Oct 2023 08:10:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233033AbjJDMKT (ORCPT ); Wed, 4 Oct 2023 08:10:19 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9665A1 for ; Wed, 4 Oct 2023 05:10:15 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9b64b98656bso391951566b.0 for ; Wed, 04 Oct 2023 05:10:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1696421414; x=1697026214; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PDAx+WeaAfeMTk0iyLZZaQojNWk87fXDiAYeAoWRhyA=; b=UHZm4+ptLtwHZrCy4sbUWMmi+RFNBU4b0OdlF941O4z5synKR4xgn/MapkXP7xWChA Z0RHX2txBYtwAOGMx8k1c3OE8Lv98TRNoeCPGTNGmHqt8MMmzoJiYU97Z68MJM4SyTOh 1E9ui2qG5qlq0TLZNdV/w5RuULqokJXnWaAegADJxTqTzex7VB9W5hxEbZTexrD5N1Lf lL+X5yHK+8zekNV2A+Ob7Nail9RktVPARkqQAnVWfSwRTLL31YgWZX0wkjVgwTsq23cs kcO3T831y/IRDZ+VE5548ghGzypzFp3Qm7YANlFG1ea2zfxV9hk2wSCIt/UYNMMEa3/Y 0sMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696421414; x=1697026214; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PDAx+WeaAfeMTk0iyLZZaQojNWk87fXDiAYeAoWRhyA=; b=DcQ6C5u9/Li7RZbU/zLyUSs7fSwrfKIPHkRjYL02gxDEOJdUiZPfW9J4p4quMA5GXq oB0t1maHyBloSQfycmU3XP066J9nKHmnIIeJlDPF0raAy5m/8kDAua1V+ClCcPEBlbJq uAJYb+7kif4OPBg4DYPZMJUr8R0ZDiqZCfub9MGkQJVKXAgoJhM9Kz0CWmTQX0iRpNH6 LZcLTcHf+v+Gk3H31shgq3LA/LGPyfEpR3lRS4e0ZAQWK8mjFTWTaA0PZ1qgpj1Kvatp u+k2LNzTyUgWii1+OTVOv352ALeOQh50nHI/XGqaWjBFuOm888ggdyGvIJ3x8Fl/Y70d vZdw== X-Gm-Message-State: AOJu0Yxy24sFApVQh2pO8zbZtLp1ioBBEL+uTu+UbTy0wWuBJOOVXBQ5 FprxdCs8bv2Fax0tiik09vRA/bQQzAa7xFvmeB/8cw== X-Received: by 2002:a17:906:4d2:b0:9ae:5212:e3b with SMTP id g18-20020a17090604d200b009ae52120e3bmr1578847eja.5.1696421414138; Wed, 04 Oct 2023 05:10:14 -0700 (PDT) Received: from stroh80.sec.9e.network (ip-078-094-000-051.um19.pools.vodafone-ip.de. [78.94.0.51]) by smtp.gmail.com with ESMTPSA id d10-20020aa7ce0a000000b005288f0e547esm2354627edv.55.2023.10.04.05.10.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 05:10:13 -0700 (PDT) From: Naresh Solanki To: broonie@kernel.org, zev@bewilderbeest.net, Liam Girdwood Cc: Naresh Solanki , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] regulator: userspace-consumer: Retrieve supplies from DT Date: Wed, 4 Oct 2023 14:10:08 +0200 Message-ID: <20231004121010.1192344-2-naresh.solanki@9elements.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231004121010.1192344-1-naresh.solanki@9elements.com> References: <20231004121010.1192344-1-naresh.solanki@9elements.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 04 Oct 2023 05:10:29 -0700 (PDT) From: Naresh Solanki Instead of hardcoding a single supply, retrieve supplies from DT. Signed-off-by: Naresh Solanki --- Changes in V2: - Use strlen for SUPPLY_SUFFIX_LEN, - Remove bracket for single line statements in if statement. - Remove extra space in variable declaration. - Simplify multi line statement by calculating size in seperate variable. - Add function prop_supply_name & simplify code. - Use devm_kstrdup instead to simplify code further. - Update DT binding to align with changes. --- drivers/regulator/userspace-consumer.c | 51 ++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c index 97f075ed68c9..13c0a86ab32c 100644 --- a/drivers/regulator/userspace-consumer.c +++ b/drivers/regulator/userspace-consumer.c @@ -115,12 +115,41 @@ static const struct attribute_group attr_group = { .is_visible = attr_visible, }; +#define SUPPLY_SUFFIX "-supply" +#define SUPPLY_SUFFIX_LEN strlen(SUPPLY_SUFFIX) + +static size_t prop_supply_name(char *prop_name) +{ + int len = strlen(prop_name); + + if (len <= SUPPLY_SUFFIX_LEN) + return 0; + + if (strcmp(prop_name + len - SUPPLY_SUFFIX_LEN, SUPPLY_SUFFIX) == 0) + return len - SUPPLY_SUFFIX_LEN; + + return 0; +} + +static int get_num_supplies(struct platform_device *pdev) +{ + struct property *prop; + int num_supplies = 0; + + for_each_property_of_node(pdev->dev.of_node, prop) { + if (prop_supply_name(prop->name)) + num_supplies++; + } + return num_supplies; +} + static int regulator_userspace_consumer_probe(struct platform_device *pdev) { struct regulator_userspace_consumer_data tmpdata; struct regulator_userspace_consumer_data *pdata; struct userspace_consumer_data *drvdata; - int ret; + struct property *prop; + int ret, supplies_size; pdata = dev_get_platdata(&pdev->dev); if (!pdata) { @@ -131,11 +160,25 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev) memset(pdata, 0, sizeof(*pdata)); pdata->no_autoswitch = true; - pdata->num_supplies = 1; - pdata->supplies = devm_kzalloc(&pdev->dev, sizeof(*pdata->supplies), GFP_KERNEL); + pdata->num_supplies = get_num_supplies(pdev); + + supplies_size = pdata->num_supplies * sizeof(*pdata->supplies); + pdata->supplies = devm_kzalloc(&pdev->dev, supplies_size, GFP_KERNEL); if (!pdata->supplies) return -ENOMEM; - pdata->supplies[0].supply = "vout"; + + for_each_property_of_node(pdev->dev.of_node, prop) { + const char *prop_name = prop->name; + size_t supply_len = prop_supply_name(prop->name); + + if (!supply_len) + continue; + + char *supply_name = devm_kstrdup(&pdev->dev, prop_name, GFP_KERNEL); + + supply_name[supply_len] = '\0'; + pdata->supplies[0].supply = supply_name; + } } if (pdata->num_supplies < 1) { -- 2.41.0