From nobody Thu Sep 11 14:11:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91F47C61DA4 for ; Sat, 18 Feb 2023 08:33:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229793AbjBRIdG (ORCPT ); Sat, 18 Feb 2023 03:33:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbjBRIdB (ORCPT ); Sat, 18 Feb 2023 03:33:01 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C683C3B672 for ; Sat, 18 Feb 2023 00:32:59 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-536629fa4ceso25129197b3.16 for ; Sat, 18 Feb 2023 00:32:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Kp1QbPjY6w8y+NO/uU7s1tByY9HWUIkH8CY141/p1Bw=; b=rTZzHduXbHELGzBYp2cxb7eG1N/9akFJXJjXnGRACIXOuguCjzoX9z0hXDTI96wh+I JFzx+h++S/vEheLmbd9a1WHdaawwRSNzK+p8nZuK/E+A4VPcqspje6CYkI5ORiQVpKxK vWV8ljEeB6aJJbQNEDj+6l/ynEqsPtLZ4YZVQeaRaHkj+coBPO2V+Djgh47VH19ztR2L i/X4AcxYu2IzRmbvQUdTZMtfL4UyfS20FXeH2K0j7ji524mBNUnu8sEXBN1jo2n1Nkdl qtfNPJiBJP0hgXaF/LvbUraJFt0Il/nttBByjo3HROfGG+/UvQk9pvBgXPqZ6gMHrgYb G7/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Kp1QbPjY6w8y+NO/uU7s1tByY9HWUIkH8CY141/p1Bw=; b=YpgDyftNL7DROQzNy6icd/pXWjgAXusJBUeboZvmbU7UgxrRGsXfaUkBs7BIXhtv/y 9BxyJJdOAroUaEpnsdFGecY3+hIiumr5Agd/FfXDqASPet8Tg1tx0dleFx3+Vtj2l1tQ dKU7moKZY8gp8QdJJjck7nm+kJ05ptoUCHWqIae4IaQCbtaXDVSJ0djw2jSBaeqPtMxr T406V9v4RUEeRHbcAmHso8iwSn2KZPubv0kvRNRBCb0bfmLzfeEKkyUX0WgyheM9cdIB LYtOci0zlwwz2NZuMj8euZpKiTibJ9/o4oHRyIBXyTrxvUg21o1hpJZgOX/a3ArAbT4A gvOQ== X-Gm-Message-State: AO0yUKVDtF5sdG4CSzzu9j/02HxRrl/5wptgEAOJonxIVu7ttV8hWpM+ oPfktRdP6Mgt0t4LhED5+1OIiXAjwxGykiE= X-Google-Smtp-Source: AK7set8RfNZQIJa7rBKYqnPS1tC4ip0mPfPQINLGkRurPv1uWqBScGpYrPt9r4A/IMbwUqlqMTH/2YJbs7qhaec= X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:382:7632:f7fc:4737]) (user=saravanak job=sendgmr) by 2002:a5b:ec1:0:b0:905:372:12ad with SMTP id a1-20020a5b0ec1000000b00905037212admr1825699ybs.539.1676709179075; Sat, 18 Feb 2023 00:32:59 -0800 (PST) Date: Sat, 18 Feb 2023 00:32:48 -0800 In-Reply-To: <20230218083252.2044423-1-saravanak@google.com> Message-Id: <20230218083252.2044423-2-saravanak@google.com> Mime-Version: 1.0 References: <20230218083252.2044423-1-saravanak@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Subject: [RFC v1 1/4] regulator: core: Add regulator devices to bus instead of class From: Saravana Kannan To: Liam Girdwood , Mark Brown Cc: Saravana Kannan , Greg Kroah-Hartman , Geert Uytterhoeven , Marek Szyprowski , Bjorn Andersson , Sudeep Holla , Tony Lindgren , Doug Anderson , Guenter Roeck , Luca Weiss , kernel-team@android.com, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add regulator devices to a bus instead of a class. This allows us to probe these devices in later patches. Signed-off-by: Saravana Kannan --- drivers/regulator/core.c | 45 ++++++++++++++++---------------- drivers/regulator/internal.h | 2 +- drivers/regulator/of_regulator.c | 2 +- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index ae69e493913d..1a212edcf216 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1918,7 +1918,7 @@ static struct regulator_dev *regulator_lookup_by_name= (const char *name) { struct device *dev; =20 - dev =3D class_find_device(®ulator_class, NULL, name, regulator_match); + dev =3D bus_find_device(®ulator_bus, NULL, name, regulator_match); =20 return dev ? dev_to_rdev(dev) : NULL; } @@ -5539,7 +5539,7 @@ regulator_register(struct device *dev, rdev->supply_name =3D regulator_desc->supply_name; =20 /* register with sysfs */ - rdev->dev.class =3D ®ulator_class; + rdev->dev.bus =3D ®ulator_bus; rdev->dev.parent =3D config->dev; dev_set_name(&rdev->dev, "regulator.%lu", (unsigned long) atomic_inc_return(®ulator_no)); @@ -5644,8 +5644,8 @@ regulator_register(struct device *dev, mutex_unlock(®ulator_list_mutex); =20 /* try to resolve regulators supply since a new one was registered */ - class_for_each_device(®ulator_class, NULL, NULL, - regulator_register_resolve_supply); + bus_for_each_dev(®ulator_bus, NULL, NULL, + regulator_register_resolve_supply); kfree(config); return rdev; =20 @@ -5772,14 +5772,15 @@ static const struct dev_pm_ops __maybe_unused regul= ator_pm_ops =3D { }; #endif =20 -struct class regulator_class =3D { +struct bus_type regulator_bus =3D { .name =3D "regulator", - .dev_release =3D regulator_dev_release, + .remove =3D regulator_dev_release, .dev_groups =3D regulator_dev_groups, #ifdef CONFIG_PM .pm =3D ®ulator_pm_ops, #endif }; + /** * regulator_has_full_constraints - the system has fully specified constra= ints * @@ -5939,7 +5940,7 @@ static void regulator_summary_show_subtree(struct seq= _file *s, seq_puts(s, "\n"); =20 list_for_each_entry(consumer, &rdev->consumer_list, list) { - if (consumer->dev && consumer->dev->class =3D=3D ®ulator_class) + if (consumer->dev && consumer->dev->bus =3D=3D ®ulator_bus) continue; =20 seq_printf(s, "%*s%-*s ", @@ -5969,8 +5970,8 @@ static void regulator_summary_show_subtree(struct seq= _file *s, summary_data.level =3D level; summary_data.parent =3D rdev; =20 - class_for_each_device(®ulator_class, NULL, &summary_data, - regulator_summary_show_children); + bus_for_each_dev(®ulator_bus, NULL, &summary_data, + regulator_summary_show_children); } =20 struct summary_lock_data { @@ -6025,11 +6026,11 @@ static int regulator_summary_lock_all(struct ww_acq= uire_ctx *ww_ctx, lock_data.new_contended_rdev =3D new_contended_rdev; lock_data.old_contended_rdev =3D old_contended_rdev; =20 - ret =3D class_for_each_device(®ulator_class, NULL, &lock_data, - regulator_summary_lock_one); + ret =3D bus_for_each_dev(®ulator_bus, NULL, &lock_data, + regulator_summary_lock_one); if (ret) - class_for_each_device(®ulator_class, NULL, &lock_data, - regulator_summary_unlock_one); + bus_for_each_dev(®ulator_bus, NULL, &lock_data, + regulator_summary_unlock_one); =20 return ret; } @@ -6065,8 +6066,8 @@ static void regulator_summary_lock(struct ww_acquire_= ctx *ww_ctx) =20 static void regulator_summary_unlock(struct ww_acquire_ctx *ww_ctx) { - class_for_each_device(®ulator_class, NULL, NULL, - regulator_summary_unlock_one); + bus_for_each_dev(®ulator_bus, NULL, NULL, + regulator_summary_unlock_one); ww_acquire_fini(ww_ctx); =20 mutex_unlock(®ulator_list_mutex); @@ -6092,8 +6093,8 @@ static int regulator_summary_show(struct seq_file *s,= void *data) =20 regulator_summary_lock(&ww_ctx); =20 - class_for_each_device(®ulator_class, NULL, s, - regulator_summary_show_roots); + bus_for_each_dev(®ulator_bus, NULL, s, + regulator_summary_show_roots); =20 regulator_summary_unlock(&ww_ctx); =20 @@ -6106,7 +6107,7 @@ static int __init regulator_init(void) { int ret; =20 - ret =3D class_register(®ulator_class); + ret =3D bus_register(®ulator_bus); =20 debugfs_root =3D debugfs_create_dir("regulator", NULL); if (!debugfs_root) @@ -6182,16 +6183,16 @@ static void regulator_init_complete_work_function(s= truct work_struct *work) * bound yet. So attempt to resolve the input supplies for * pending regulators before trying to disable unused ones. */ - class_for_each_device(®ulator_class, NULL, NULL, - regulator_register_resolve_supply); + bus_for_each_dev(®ulator_bus, NULL, NULL, + regulator_register_resolve_supply); =20 /* If we have a full configuration then disable any regulators * we have permission to change the status for and which are * not in use or always_on. This is effectively the default * for DT and ACPI as they have full constraints. */ - class_for_each_device(®ulator_class, NULL, NULL, - regulator_late_cleanup); + bus_for_each_dev(®ulator_bus, NULL, NULL, + regulator_late_cleanup); } =20 static DECLARE_DELAYED_WORK(regulator_init_complete_work, diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h index fb4433068d29..6e489b3cffad 100644 --- a/drivers/regulator/internal.h +++ b/drivers/regulator/internal.h @@ -58,7 +58,7 @@ struct regulator { struct dentry *debugfs; }; =20 -extern struct class regulator_class; +extern struct bus_type regulator_bus; =20 static inline struct regulator_dev *dev_to_rdev(struct device *dev) { diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regula= tor.c index 1b65e5e4e40f..f0590e68f31d 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -545,7 +545,7 @@ struct regulator_dev *of_find_regulator_by_node(struct = device_node *np) { struct device *dev; =20 - dev =3D class_find_device_by_of_node(®ulator_class, np); + dev =3D bus_find_device_by_of_node(®ulator_bus, np); =20 return dev ? dev_to_rdev(dev) : NULL; } --=20 2.39.2.637.g21b0678d19-goog From nobody Thu Sep 11 14:11:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD7BBC636D7 for ; Sat, 18 Feb 2023 08:33:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229770AbjBRIdJ (ORCPT ); Sat, 18 Feb 2023 03:33:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229780AbjBRIdD (ORCPT ); Sat, 18 Feb 2023 03:33:03 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43D5D42BE1 for ; Sat, 18 Feb 2023 00:33:02 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5365a8dd33aso26531997b3.22 for ; Sat, 18 Feb 2023 00:33:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Qjy8cu1Mo/UjSfKWZ07U2cuwjaexJWXy+SB7TrdOfOk=; b=f53tiO60I7XJ6TYtB0DYyxwXSpcAe/3+SEcd0gpn65PwjUBmVPmeN9N9fDUOBYx5B4 +X7KrrUprexujhvtlkEgvIfjbcMWCznLWm9Q2HYqghq4BXq9y2mFTVxVx9jn5Y7y1eaZ ffgr0uY71tCr9u2eDrFwAts+aRI1E/vJIOLkcQ91jVmvN1VQrZjcdFFzvqqHIslrdbWF zE0iNSA99G7liBZMABYJlwRR+RuoBa0pi01AOq5G9xUZwbkpk56WZEVQz5Dhs1UiItM7 ns4h02cjsUESNq7Mu34jCsSe1nJzft00ohzoO6r6GKzCXjmwM8yYdk/4KBW9yf2aOPnQ Edxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Qjy8cu1Mo/UjSfKWZ07U2cuwjaexJWXy+SB7TrdOfOk=; b=Dz/LjpEo0lpa62nAwfMfQ3COzt+XGNLzmHodpi/utgV44vPTSjrVk/ovJywE2zwFuy CtOui4jb+Z0FYmt1sEb8PWgK24VDsFiD004pG6ekTzQWL5fBtXw/QHYIWZLx3TWE9Iqv ccaBCZijN+Scj3lsi41r1sIcF9pDnlkH+lvxWjkUhshaOriiJV32mH2+dvp0gI1AZLYg 93eiNlX55TSOAwYn21GedpXxZPhJha8VOo/QvOMYR74SIYzS46f8JcYkcLKsmbbYwy63 XBWP56Wa/TurR5ruwa9dRvKUSLXKtLtGOqdB51QprHKb7sVZkZrPdTwMVqNj2+SSd8AA HhXQ== X-Gm-Message-State: AO0yUKVGB80veUV+39yJqMbBuT699ob+JR1Z9CYs9WlndtZxAQKdtmD8 6ESe1+0lAUXPpFvMf4PAHj5iFKgfi7LqkmY= X-Google-Smtp-Source: AK7set+48hgPOTFKTqBSI90PC+RvCcTohAUN+b4zsz5OY4rILu8FJ6rmwMaDGyWWzun7reT7l5xJktc/c1ZgOb4= X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:382:7632:f7fc:4737]) (user=saravanak job=sendgmr) by 2002:a5b:688:0:b0:931:2b11:6584 with SMTP id j8-20020a5b0688000000b009312b116584mr1169840ybq.591.1676709181337; Sat, 18 Feb 2023 00:33:01 -0800 (PST) Date: Sat, 18 Feb 2023 00:32:49 -0800 In-Reply-To: <20230218083252.2044423-1-saravanak@google.com> Message-Id: <20230218083252.2044423-3-saravanak@google.com> Mime-Version: 1.0 References: <20230218083252.2044423-1-saravanak@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Subject: [RFC v1 2/4] regulator: core: Add sysfs class backward compatibility From: Saravana Kannan To: Liam Girdwood , Mark Brown Cc: Saravana Kannan , Greg Kroah-Hartman , Geert Uytterhoeven , Marek Szyprowski , Bjorn Andersson , Sudeep Holla , Tony Lindgren , Doug Anderson , Guenter Roeck , Luca Weiss , kernel-team@android.com, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A regulator device's sysfs directory used to be created under /sys/class/regulator when it is added to a class. Since the device is now moved to be under a bus, add symlinks from /sys/class/regulator to the real device sysfs directory. Signed-off-by: Saravana Kannan --- drivers/regulator/core.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 1a212edcf216..b6700d50d230 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -43,6 +43,7 @@ static LIST_HEAD(regulator_coupler_list); static bool has_full_constraints; =20 static struct dentry *debugfs_root; +static struct class_compat *regulator_compat_class; =20 /* * struct regulator_map @@ -5636,6 +5637,11 @@ regulator_register(struct device *dev, if (ret !=3D 0) goto unset_supplies; =20 + if (class_compat_create_link(regulator_compat_class, &rdev->dev, + rdev->dev.parent)) + dev_warn(&rdev->dev, + "Failed to create compatibility class link\n"); + rdev_init_debugfs(rdev); =20 /* try to resolve regulators coupling since a new one was registered */ @@ -5702,6 +5708,8 @@ void regulator_unregister(struct regulator_dev *rdev) unset_regulator_supplies(rdev); list_del(&rdev->list); regulator_ena_gpio_free(rdev); + class_compat_remove_link(regulator_compat_class, &rdev->dev, + rdev->dev.parent); device_unregister(&rdev->dev); =20 mutex_unlock(®ulator_list_mutex); @@ -6107,7 +6115,13 @@ static int __init regulator_init(void) { int ret; =20 + regulator_compat_class =3D class_compat_register("regulator"); + if (!regulator_compat_class) + return -ENOMEM; + ret =3D bus_register(®ulator_bus); + if (ret) + goto unreg_compat; =20 debugfs_root =3D debugfs_create_dir("regulator", NULL); if (!debugfs_root) @@ -6120,11 +6134,16 @@ static int __init regulator_init(void) debugfs_create_file("regulator_summary", 0444, debugfs_root, NULL, ®ulator_summary_fops); #endif + regulator_dummy_init(); =20 regulator_coupler_register(&generic_regulator_coupler); =20 return ret; + +unreg_compat: + class_compat_unregister(regulator_compat_class); + return ret; } =20 /* init early to allow our consumers to complete system booting */ --=20 2.39.2.637.g21b0678d19-goog From nobody Thu Sep 11 14:11:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D847CC64ED6 for ; Sat, 18 Feb 2023 08:33:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229824AbjBRIdM (ORCPT ); Sat, 18 Feb 2023 03:33:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbjBRIdF (ORCPT ); Sat, 18 Feb 2023 03:33:05 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E061547432 for ; Sat, 18 Feb 2023 00:33:04 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5367836c7e1so5418237b3.13 for ; Sat, 18 Feb 2023 00:33:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+eMvh/5RpB1yBDTApxHgHfIOTnGW3OoKdzhdswhPdc8=; b=IBwqlFD+FCaDqWg/idHuaAxR0CYrFVJMbtxMjDSvmEkNhayk8QbmlvNJQNqxg+alsM ZvC/mNmTjTx1Rbw1rctbABzwis4tAMyEDJwLoZrHPxngikDinW09R+TTuLG/2vWGLYQg 9T67C6HKuhhJHJQ0szi2JKR1/BxRvaw5zELhdmSWxcTbM846z2AHMpjIBLEKBqiQF1ns tQzQ5EBuAClKshZu3NT4MOAPtPQiEKgCwXBlT0OGTqyX0FoIWqHVUGy9lUN0Mf40iWcO UVhio5dw3Jr3hrTFlgm26scaAUGjdEGwTps4agz0k6HbkE47VOdhQFyCO+srFRnt/E6v 45ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+eMvh/5RpB1yBDTApxHgHfIOTnGW3OoKdzhdswhPdc8=; b=A2uvypY4LhLBSQUFfd2j/p1WfL2xeLZpYJv4goWYtQI0madhyzgD0+Te2k4Z/WOpcO 4Su/BegTiC+z7FBsJVmtoRBi0la5i12AvB8MRomQy6PPnkP3OBvz9/S6KZzKevB0xw71 msUfGgdb5YgEgGFVqudXklXR172COMuujLi4pAaGwNKP6rJw8Fe+W8Lg6mx9n7g1Ca9d zZcipQgDRmVs8M/J5OR7Hv+xqIN+V3lYQiwMNUCIxhMN3nci9gjb5wYxAk8M3Xh1iDrI T/pt40OENXhQkiIbrJ4VU3hzeyaQeI8b62K+bHNqDhObapzFZ0CWKkygYyxFXgkh/l9n Cl6g== X-Gm-Message-State: AO0yUKXK5hAPyIh7WkekOC+AfaamkOocB8sNouQk89w9/mkTKaSkDt8j gCgZ9NuTDbEA1MceJl3BOlQoJWrOzU8sLaQ= X-Google-Smtp-Source: AK7set9hRgiEvFBiFppHL8eT54ybwc2hZv7z3Blb0CFN5CcOP1YQbX8QCulFE4e/SFDWs0v35PqiJF0QK13gDmk= X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:382:7632:f7fc:4737]) (user=saravanak job=sendgmr) by 2002:a81:ca03:0:b0:52e:fb7a:94b7 with SMTP id p3-20020a81ca03000000b0052efb7a94b7mr349890ywi.7.1676709184201; Sat, 18 Feb 2023 00:33:04 -0800 (PST) Date: Sat, 18 Feb 2023 00:32:50 -0800 In-Reply-To: <20230218083252.2044423-1-saravanak@google.com> Message-Id: <20230218083252.2044423-4-saravanak@google.com> Mime-Version: 1.0 References: <20230218083252.2044423-1-saravanak@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Subject: [RFC v1 3/4] regulator: core: Probe regulator devices From: Saravana Kannan To: Liam Girdwood , Mark Brown Cc: Saravana Kannan , Greg Kroah-Hartman , Geert Uytterhoeven , Marek Szyprowski , Bjorn Andersson , Sudeep Holla , Tony Lindgren , Doug Anderson , Guenter Roeck , Luca Weiss , kernel-team@android.com, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since devices added to a bus can be probed, add a stub probe function for regulator devices. Signed-off-by: Saravana Kannan --- drivers/regulator/core.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index b6700d50d230..d5f9fdd79c14 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -5780,6 +5780,17 @@ static const struct dev_pm_ops __maybe_unused regula= tor_pm_ops =3D { }; #endif =20 +static int regulator_drv_probe(struct device *dev) +{ + return 0; +} + +static struct device_driver regulator_drv =3D { + .name =3D "regulator_drv", + .bus =3D ®ulator_bus, + .probe =3D regulator_drv_probe, +}; + struct bus_type regulator_bus =3D { .name =3D "regulator", .remove =3D regulator_dev_release, @@ -6123,6 +6134,10 @@ static int __init regulator_init(void) if (ret) goto unreg_compat; =20 + ret =3D driver_register(®ulator_drv); + if (ret) + goto unreg_bus; + debugfs_root =3D debugfs_create_dir("regulator", NULL); if (!debugfs_root) pr_warn("regulator: Failed to create debugfs directory\n"); @@ -6141,6 +6156,8 @@ static int __init regulator_init(void) =20 return ret; =20 +unreg_bus: + bus_unregister(®ulator_bus); unreg_compat: class_compat_unregister(regulator_compat_class); return ret; --=20 2.39.2.637.g21b0678d19-goog From nobody Thu Sep 11 14:11:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EE97C61DA4 for ; Sat, 18 Feb 2023 08:33:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229864AbjBRIdU (ORCPT ); Sat, 18 Feb 2023 03:33:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229536AbjBRIdJ (ORCPT ); Sat, 18 Feb 2023 03:33:09 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 832A1498A4 for ; Sat, 18 Feb 2023 00:33:07 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5365936facfso28247027b3.4 for ; Sat, 18 Feb 2023 00:33:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=wf3aa1fibAc7MkDg7PORyU7RaVXEoouFWua6YI0T5Hw=; b=r/CAEVeZKaF7JFTzJGZPssmJ2DIsZyZc9v5lclCdMbxrxNh2Q3QLMVp4pLNRuC/Q5o s27Bkv2TMKwmgM8oUoVvMvQEDvRGwftjSDp/ve6slRHgGsw5Ms0v43lU1FgwAhrBbFUe 35o2FkSyM0x9/CMG8wr9G7/tyB/xKWzUmAI6tpiI86269U3STCkvIy4CWA8W6S2SdtXS 95eDXAunOWuxhtEP+diSImXUFuEa0VFXp1IRPtl0LmzghMSuArwHNw5gdcwOcP5ghRmt Jtm9ur/C7VTni40wqDN76966yegfo02FQ3vpbSwRhwDhCS/71+WQUH1e/qqxm6JVCgxQ FjGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wf3aa1fibAc7MkDg7PORyU7RaVXEoouFWua6YI0T5Hw=; b=0ZaTWhUKZvAjtJ4OnYtDA3bE5SkbyYSfzl5xRXzXvlwtuyvPgY3FTvrdMPsOpybPTO lkyFSkBglA/b1nEeKt8H9z/R49H3IPYkplqG5IbxQY3++r2NGIjF9z/2Yb2f+Ki3W7Ls K5F4d7bnMuGqjNxSuRh2hLLJQx6DhHpTfFhdzRaNmM2/7Y0o3LwFgrdPelL3GCwEcVV7 /fgM5z4dti0CgckkLJlxvSq8uSGj3WnoOi0K5sxPY1mqzaBV0HogNQY/1PqhZzcM9f8T WuYu/uRACygDV4XAJdtoahml0hpjbkq0YH14CRvqg8luaMAu8gDz/DnmHs9UHPr5qkR1 Pkqw== X-Gm-Message-State: AO0yUKXyIaoRxJahLPDh4GRiZZ8RPD6PMh906B+8k00X4Ubr04xjcwSN ZbWOETL8BL9unDpzPzso9sU378wX0jcpzkc= X-Google-Smtp-Source: AK7set8PFya149sfYHXrlUe84h6TnpJuUyTxV/h5YVz8ypiqAHXvBdWcZs8G6zaahZ/K/pJIAwRpMfD2P80zE3A= X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:382:7632:f7fc:4737]) (user=saravanak job=sendgmr) by 2002:a81:6a41:0:b0:534:3fd:8403 with SMTP id f62-20020a816a41000000b0053403fd8403mr652502ywc.89.1676709186748; Sat, 18 Feb 2023 00:33:06 -0800 (PST) Date: Sat, 18 Feb 2023 00:32:51 -0800 In-Reply-To: <20230218083252.2044423-1-saravanak@google.com> Message-Id: <20230218083252.2044423-5-saravanak@google.com> Mime-Version: 1.0 References: <20230218083252.2044423-1-saravanak@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Subject: [RFC v1 4/4] regulator: core: Move regulator supply resolving to the probe function From: Saravana Kannan To: Liam Girdwood , Mark Brown Cc: Saravana Kannan , Greg Kroah-Hartman , Geert Uytterhoeven , Marek Szyprowski , Bjorn Andersson , Sudeep Holla , Tony Lindgren , Doug Anderson , Guenter Roeck , Luca Weiss , kernel-team@android.com, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We can simplify the regulator's supply resolving code if we resolve the supply in the regulator's probe function. This allows us to: - Consolidate the supply resolution code to one place. - Avoid the need for recursion by allow driver core to take care of handling dependencies. - Avoid races and simplify locking by reusing the guarantees provided by driver core. - Avoid last minute/lazy resolving during regulator_get(). - Simplify error handling because we can assume the supply has been resolved once a regulator is probed. - Allow driver core to use device links/fw_devlink, where available, to resolve the regulator supplies in the optimal order. Signed-off-by: Saravana Kannan --- drivers/regulator/core.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index d5f9fdd79c14..f3bf74d1a81d 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1952,7 +1952,7 @@ static struct regulator_dev *regulator_dev_lookup(str= uct device *dev, if (node) { r =3D of_find_regulator_by_node(node); of_node_put(node); - if (r) + if (r && r->dev.links.status =3D=3D DL_DEV_DRIVER_BOUND) return r; =20 /* @@ -1982,11 +1982,11 @@ static struct regulator_dev *regulator_dev_lookup(s= truct device *dev, } mutex_unlock(®ulator_list_mutex); =20 - if (r) + if (r && r->dev.links.status =3D=3D DL_DEV_DRIVER_BOUND) return r; =20 r =3D regulator_lookup_by_name(supply); - if (r) + if (r && r->dev.links.status =3D=3D DL_DEV_DRIVER_BOUND) return r; =20 return ERR_PTR(-ENODEV); @@ -2050,13 +2050,6 @@ static int regulator_resolve_supply(struct regulator= _dev *rdev) } } =20 - /* Recursively resolve the supply of the supply */ - ret =3D regulator_resolve_supply(r); - if (ret < 0) { - put_device(&r->dev); - goto out; - } - /* * Recheck rdev->supply with rdev->mutex lock held to avoid a race * between rdev->supply null check and setting rdev->supply in @@ -2178,13 +2171,6 @@ struct regulator *_regulator_get(struct device *dev,= const char *id, return regulator; } =20 - ret =3D regulator_resolve_supply(rdev); - if (ret < 0) { - regulator =3D ERR_PTR(ret); - put_device(&rdev->dev); - return regulator; - } - if (!try_module_get(rdev->owner)) { regulator =3D ERR_PTR(-EPROBE_DEFER); put_device(&rdev->dev); @@ -5649,9 +5635,6 @@ regulator_register(struct device *dev, regulator_resolve_coupling(rdev); mutex_unlock(®ulator_list_mutex); =20 - /* try to resolve regulators supply since a new one was registered */ - bus_for_each_dev(®ulator_bus, NULL, NULL, - regulator_register_resolve_supply); kfree(config); return rdev; =20 @@ -5782,7 +5765,9 @@ static const struct dev_pm_ops __maybe_unused regulat= or_pm_ops =3D { =20 static int regulator_drv_probe(struct device *dev) { - return 0; + struct regulator_dev *rdev =3D dev_to_rdev(dev); + + return regulator_resolve_supply(rdev); } =20 static struct device_driver regulator_drv =3D { --=20 2.39.2.637.g21b0678d19-goog