From: Guenter Roeck <linux@roeck-us.net>
To: Hans de Goede <hdegoede@redhat.com>,
Darren Hart <dvhart@infradead.org>,
Andy Shevchenko <andy@infradead.org>,
Wolfram Sang <wsa@the-dreams.de>,
Sebastian Reichel <sre@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
Liam Breck <liam@networkimprov.net>,
Tony Lindgren <tony@atomide.com>,
linux-pm@vger.kernel.org, devel@driverdev.osuosl.org
Subject: Re: [PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property
Date: Sun, 6 Aug 2017 08:20:31 -0700 [thread overview]
Message-ID: <17739181-0553-d622-4c71-4cf91efb0de0@roeck-us.net> (raw)
In-Reply-To: <6df731a5-9dc8-ae5b-dc14-d7ea5eb3890b@redhat.com>
On 08/06/2017 07:52 AM, Hans de Goede wrote:
> Hi,
>
> On 06-08-17 16:30, Guenter Roeck wrote:
>> On 08/06/2017 05:35 AM, Hans de Goede wrote:
>>> On devicetree platforms the fusb302 dt-node will have a vbus regulator
>>> property with a phandle to the regulator.
>>>
>>> On ACPI platforms, there are no phandles and we need to get the vbus by a
>>> system wide unique name. Add support for a new "fcs,vbus-regulator-name"
>>> device-property which ACPI platform code can set to pass the name.
>>>
>>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>>> ---
>>> drivers/staging/typec/fusb302/fusb302.c | 28 ++++++++++++++++++++++------
>>> 1 file changed, 22 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/staging/typec/fusb302/fusb302.c b/drivers/staging/typec/fusb302/fusb302.c
>>> index e1e08f57af99..c3bcc5484ade 100644
>>> --- a/drivers/staging/typec/fusb302/fusb302.c
>>> +++ b/drivers/staging/typec/fusb302/fusb302.c
>>> @@ -1722,6 +1722,28 @@ static int fusb302_probe(struct i2c_client *client,
>>> return -EPROBE_DEFER;
>>> }
>>> + /*
>>> + * Devicetree platforms should get vbus from their dt-node.
>>> + * On ACPI platforms, we need to get the vbus by a system wide unique
>>> + * name, which is set in a device prop by the platform code.
>>> + */
>>> + if (device_property_read_string(dev, "fcs,vbus-regulator-name",
>>> + &name) == 0) {
>>
>> Another property to be documented and approved.
>
> Again this is for kernel internal use on non-dt platforms only, so documenting
> it in the devicetree bindings is not necessary.
Ok.
>> Also, isn't there a better way to get regulator names for dt- and non-dt systems ?
>> This would apply to every driver supporting both and using regulators, which seems
>> awkward.
>
> While working on this I noticed that it is possible to add a regulator_match
> table entry when registering a regulator, but that requires describing this
> in regulator_init_data. Which would mean passing regulator_init_data from the
> place where it is instantiated to where it gets registered, which would
> mean passing a pointer through a device-property, given that this is purely kernel
> internal that is possible, but not really how device-props are supposed to be used.
>
> Also since the regulator-core only adds the mapping when registering the
> regulator, this means that if we try to get the regulator before it has been
> registered; and there is another regulator with the rather generic "vbus"
> name then that will be returned instead.
>
> Basically regulators are practically almost unused on x86 systems. I had to
> add CONFIG_REGULATOR=y to my .config which is based on the Fedora 26 kernel
> .config, so it has pretty much everything under the sun enabled. So it seems
> that we are covering new ground here.
>
We have some in hwmon, but they get by with using devm_regulator_get_optional()
for both dt and non-dt systems. Only problem with that is that it returns
-ENODEV if regulators are not configured, which by itself is weird/odd
(and there have been endless discussions about it).
> An alternative would be to not use the regulator subsys for this at all, but
> it does seem the logical thing to use and using get-by-name is no different
> then what we've doing for setting the the "fusb302-typec-source" psy as supplier
> for the charger psy class device registered by the bq24190_charger driver.
>
> TL;DR: It seems that on x86, at least for existing devices where we cannot
> control the ACPI tables that getting things by name is the thing to do.
>
Messy :-(. I don't have a better idea, unfortunately.
>>> + /*
>>> + * Use regulator_get_optional so that we can detect if we need
>>> + * to defer the probe rather then getting the dummy-regulator.
>>> + */
>>
>> Wouldn't this apply to dt systems as well ?
>
> No because there will be a property named "vbus-supply" in the fusb302
> node containing a phandle to the regulator, if the regulator to which the phandle
> points has not been registered yet regulator_get will automatically return
> -EPROBE_DEFER because there is a "vbus-supply" property, only if there is
> no such property at all will it return a dummy regulator.
>
More messy. Again, I don't have a better idea, but it is really weird that we
need all this code. There should really be some generic code handling all those
differences.
>>> + chip->vbus = devm_regulator_get_optional(dev, name);
>>> + if (IS_ERR(chip->vbus)) {
>>> + ret = PTR_ERR(chip->vbus);
>>> + return (ret == -ENODEV) ? -EPROBE_DEFER : ret;
This will be stuck in returning -EPROBE_DEFER if the regulator subsystem
is disabled. Is this acceptable ?
>>> + }
>>> + } else {
>>> + chip->vbus = devm_regulator_get(dev, "vbus");
>>> + if (IS_ERR(chip->vbus))
>>> + return PTR_ERR(chip->vbus);
>>> + }
>>> +
>>
>> You might also want to explain why you moved this code.
>
> Right, I did that because it may fail with -EPROBE_DEFER and
> I wanted to do that before the register_psy. But as I just
> explained the old code could do that too, so I properly should
> just put the register_psy later.
>
> Regards,
>
> Hans
>
>
>
>>> ret = tcpm_register_psy(chip->dev, &chip->tcpc_dev,
>>> "fusb302-typec-source");
>>> if (ret < 0)
>>> @@ -1739,12 +1761,6 @@ static int fusb302_probe(struct i2c_client *client,
>>> INIT_DELAYED_WORK(&chip->bc_lvl_handler, fusb302_bc_lvl_handler_work);
>>> init_tcpc_dev(&chip->tcpc_dev);
>>> - chip->vbus = devm_regulator_get(chip->dev, "vbus");
>>> - if (IS_ERR(chip->vbus)) {
>>> - ret = PTR_ERR(chip->vbus);
>>> - goto destroy_workqueue;
>>> - }
>>> -
>>> if (client->irq) {
>>> chip->gpio_int_n_irq = client->irq;
>>> } else {
>>>
>>
>
next prev parent reply other threads:[~2017-08-06 15:20 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-06 12:35 [PATCH 00/18] Hookup typec power-negotation to the PMIC and charger Hans de Goede
2017-08-06 12:35 ` [PATCH 01/18] staging: typec: tcpm: Add get_usb2_current_limit tcpc_dev callback Hans de Goede
2017-08-06 14:18 ` Guenter Roeck
2017-08-06 14:29 ` Hans de Goede
2017-08-06 14:52 ` Guenter Roeck
2017-08-06 12:35 ` [PATCH 02/18] staging: typec: tcpm: Add extcon helper functions for USB2 current limit detect Hans de Goede
2017-08-06 14:07 ` Guenter Roeck
2017-08-06 12:35 ` [PATCH 03/18] staging: typec: tcpm: Split tcpm code into tcpm-core.c and tcpm-helpers.c Hans de Goede
2017-08-06 12:35 ` [PATCH 04/18] staging: typec: tcpm: Add helpers for exporting current-limit through a psy Hans de Goede
2017-08-06 14:13 ` Guenter Roeck
2017-08-06 14:21 ` Hans de Goede
2017-08-06 14:41 ` Guenter Roeck
2017-08-06 12:35 ` [PATCH 05/18] staging: typec: fusb302: Set max supply voltage to 5V Hans de Goede
2017-08-06 12:35 ` [PATCH 06/18] staging: typec: fusb302: Get max snk mv/ma/mw from device-properties Hans de Goede
2017-08-06 14:03 ` Guenter Roeck
2017-08-06 12:35 ` [PATCH 07/18] staging: typec: fusb302: Use client->irq as irq if set Hans de Goede
2017-08-06 12:35 ` [PATCH 08/18] staging: typec: fusb302: Add support for USB2 charger detection through extcon Hans de Goede
2017-08-06 14:22 ` Guenter Roeck
2017-08-06 14:36 ` Hans de Goede
2017-08-06 14:58 ` Guenter Roeck
2017-08-06 12:35 ` [PATCH 09/18] staging: typec: fusb302: Use tcpm_set_current_limit_psy Hans de Goede
2017-08-06 14:24 ` Guenter Roeck
2017-08-06 12:35 ` [PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property Hans de Goede
2017-08-06 14:30 ` Guenter Roeck
2017-08-06 14:52 ` Hans de Goede
2017-08-06 15:20 ` Guenter Roeck [this message]
2017-08-06 15:44 ` Hans de Goede
2017-08-07 11:10 ` Mark Brown
2017-08-07 14:41 ` Hans de Goede
2017-08-07 15:41 ` Mark Brown
2017-08-07 19:20 ` Hans de Goede
2017-08-08 9:39 ` Mark Brown
[not found] ` <0b75c318-0f71-c536-7c7f-9ba16b215690@redhat.com>
[not found] ` <20170808144217.c2fm25uge75p4lo2@sirena.org.uk>
2017-08-08 20:53 ` Hans de Goede
2017-08-06 12:35 ` [PATCH 11/18] power: supply: Fix power_supply_am_i_supplied to return -ENODEV when apropriate Hans de Goede
2017-08-06 14:31 ` Guenter Roeck
2017-08-06 14:54 ` Hans de Goede
2017-08-06 12:35 ` [PATCH 12/18] power: supply: Add power_supply_set_input_current_limit_from_supplier helper Hans de Goede
2017-08-06 12:35 ` [PATCH 13/18] power: supply: bq24190_charger: Export 5V boost converter as regulator Hans de Goede
2017-08-08 4:15 ` Tony Lindgren
2017-08-08 8:39 ` Liam Breck
2017-08-08 9:00 ` Hans de Goede
2017-08-08 18:57 ` Liam Breck
2017-08-08 21:09 ` Hans de Goede
2017-08-06 12:35 ` [PATCH 14/18] power: supply: bq24190_charger: Add input_current_limit property Hans de Goede
2017-08-06 12:35 ` [PATCH 15/18] power: supply: bq24190_charger: Get input_current_limit from our supplier Hans de Goede
2017-08-08 8:24 ` Liam Breck
2017-08-08 9:11 ` Hans de Goede
2017-08-06 12:35 ` [PATCH 16/18] power: supply: bq24190_charger: Remove extcon handling Hans de Goede
2017-08-08 8:27 ` Liam Breck
2017-08-08 9:12 ` Hans de Goede
2017-08-06 12:35 ` [PATCH 17/18] platform/x86: intel_cht_int33fe Update fusb302 type string, add properties Hans de Goede
2017-08-06 12:35 ` [PATCH 18/18] i2c-cht-wc: Add device-properties for fusb302 integration Hans de Goede
2017-08-06 14:35 ` Guenter Roeck
2017-08-06 15:05 ` Hans de Goede
2017-08-06 16:29 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=17739181-0553-d622-4c71-4cf91efb0de0@roeck-us.net \
--to=linux@roeck-us.net \
--cc=andy@infradead.org \
--cc=devel@driverdev.osuosl.org \
--cc=dvhart@infradead.org \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=liam@networkimprov.net \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=sre@kernel.org \
--cc=tony@atomide.com \
--cc=wsa@the-dreams.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®