From: Andy Green <andy.green-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
To: Alan Stern <stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>
Cc: Greg KH
<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
keshava_mgowda-l0cyMroinI0@public.gmane.org,
linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
balbi-l0cyMroinI0@public.gmane.org,
rogerq-l0cyMroinI0@public.gmane.org
Subject: Re: [RFC PATCH 1/5] drivers : introduce device_path api
Date: Wed, 28 Nov 2012 10:30:26 +0800 [thread overview]
Message-ID: <50B57742.2010107@linaro.org> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1211271446430.1489-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
On 11/28/2012 04:10 AM, the mail apparently from Alan Stern included:
> On Wed, 28 Nov 2012, Andy Green wrote:
>
>> OK. So I try to sketch it out iteractively to try to get in sync:
>>
>> device.h:
>>
>> enum asset_event {
>> AE_PROBED,
>> AE_REMOVED
>> };
>>
>> struct device_asset {
>> char *name; /* name of regulator, clock, etc */
>> void *asset; /* regulator, clock, etc */
>> int (*handler)(struct device *dev_owner, enum asset_event asset_event,
>> struct device_asset *asset);
>> };
>
> Another possibility is to have two handlers: one for pre-probe and the
> other for post-remove. Then of course asset_event wouldn't be needed.
> Linus tends to prefer this strategy -- separate functions for separate
> events. That's why struct dev_pm_ops has so many method pointers.
OK.
I wonder if this needs extending to PM ops passing in to the assets.
Regulator is usually self-sufficient but sometimes clocks at least need
meddling in suspend paths.
Maybe it's enough instead to offer a standalone api for drivers that
want to meddle with assets, like enable / disable an asset clock...
void *device_find_asset(struct device *device, const char *name);
...if it wants to touch anything like that it needs to mandate a
nonambiguous name for the asset like "reg-mydriver-ehci-omap.0".
This is also handy since the driver can then adapt around absence or
presence of optional assets if it wants.
>> struct device {
>> ...
>> struct device_asset *assets;
>
> Or a list instead of a NULL-terminated array. It depends on whether
> people will want to add or remove assets dynamically. For now an array
> would be fine.
OK.
>> ...
>> };
>>
>>
>> drivers/base/dd.c | really_probe():
>>
>> ...
>> struct device_asset *asset;
>> ...
>> asset = dev->assets;
>> while (asset && asset->name) {
>
> Maybe it would be better to test asset->handler. Some assets might not
> need names.
Good point.
>> if (asset->handler(dev, AE_PROBED, asset)) {
>> /* clean up and bail */
>> }
>> asset++;
>> }
>>
>> /* do probe */
>> ...
>>
>>
>> drivers/base/dd.c | __device_release_driver: (is this really the best
>> place to oppose probe()?)
>
> The right place is just after the remove method is called, so yes.
>
>> ...
>> struct device_asset *asset;
>> ...
>>
>> /* call device ->remove() */
>> ...
>> asset = dev->assets;
>> while (asset && asset->name) {
>> asset->handler(dev, AE_REMOVED, asset);
>> asset++;
>> }
>
> It would be slightly safer to iterate in reverse order.
Good point.
>> ...
>>
>>
>> board file:
>>
>> static struct regulator myreg = {
>> .name = "mydevice-regulator",
>> };
>>
>> static struct device_asset mydevice_assets[] = {
>> {
>> .name = "mydevice-regulator",
>> .handler = regulator_default_asset_handler,
>> },
>> { }
>> };
>>
>> static struct platform_device mydevice = {
>> ...
>> .dev = {
>> .assets = mydevice_assets,
>> },
>> ...
>> };
>>
>>
>> regulator code:
>>
>> int regulator_default_asset_handler(struct device *dev_owner, enum
>> asset_event asset_event, struct device_asset *asset)
>> {
>> struct regulator **reg = &asset->asset;
>> int n;
>>
>> switch (asset_event) {
>> case AE_PROBED:
>> *reg = regulator_get(dev_owner, asset->name);
>> if (IS_ERR(*reg))
>> return *reg;
>
> PTR_ERR.
Right.
I'll offer a series with these adaptations shortly.
-Andy
>> n = regulator_enable(*reg);
>> if (n < 0)
>> regulator_put(*reg);
>> return n;
>>
>> case AE_REMOVED:
>> regulator_put(*reg);
>> break;
>> }
>>
>> return 0;
>> }
>> EXPORT_SYMBOL_GPL(regulator_default_asset_handler);
>>
>>
>> The subsystems that can expect to get used (clock...) might each want to
>> define a default handler like the one for regulator. That'll be an end
>> to the code duplication issue. The user can still do his own handler if
>> he wants.
>>
>> I put a name field in so we can use regulator_get() nicely, we don't
>> need access to the object pointer or that it exists at boardfile-time
>> that way either. But I can see it's arguable.
>
> It hadn't occurred to me, but it seems like a good idea.
>
> Yes, overall this is almost exactly what I had in mind.
>
>>>> Throwing out the path stuff and limiting this to platform_device means
>>>> you cannot bind to dynamically created objects like hub or anything
>>>> downstream of a hub. So Felipe's identification of the hub as the
>>>> happening place to do this is out of luck.
>>>
>>> Greg pointed out that this could be useful for arbitrary devices, not
>>> just platform devices, so it could be applied to dynamically created
>>> objects.
>>
>> Well that is cool, but to exploit that in the dynamic object case
>> arrangements for identifying the appropriate object has appeared are
>> needed.
>
> For example, this scheme wouldn't lend itself easily to associating the
> regulator with the particular root-hub port that the LAN95xx is
> attached to. I can't think of any reasonable way to do that other than
> the approaches we have already considered.
>
>> We have a nice array of platform_devices nicely there in the
>> board file we can attach assets to like "pdev[1].dev.assets = xxx;" but
>> that's not there in dynamic device case. Anyway this sounds like what
>> we're discussing can be well worth establishing and might lead to that
>> later.
>
> Agreed.
>
> Alan Stern
>
--
Andy Green | TI Landing Team Leader
Linaro.org │ Open source software for ARM SoCs | Follow Linaro
http://facebook.com/pages/Linaro/155974581091106 -
http://twitter.com/#!/linaroorg - http://linaro.org/linaro-blog
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2012-11-28 2:30 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-26 12:45 [RFC PATCH 0/5] Device Paths introduced and applied to generic hub and panda Andy Green
2012-11-26 12:45 ` [RFC PATCH 1/5] drivers : introduce device_path api Andy Green
2012-11-26 19:12 ` Alan Stern
[not found] ` <Pine.LNX.4.44L0.1211261348310.2168-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-11-26 23:26 ` Andy Green
[not found] ` <20121126124534.18106.44137.stgit-Ak/hGR4SqtBG2qbu2SEcwgC/G2K4zDHf@public.gmane.org>
2012-11-26 19:16 ` Greg KH
[not found] ` <20121126191612.GA11239-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2012-11-26 23:28 ` Andy Green
2012-11-26 19:22 ` Greg KH
2012-11-26 19:27 ` Greg KH
2012-11-26 21:07 ` Alan Stern
2012-11-26 22:50 ` Greg KH
[not found] ` <Pine.LNX.4.44L0.1211261555400.2168-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-11-27 0:02 ` Andy Green
[not found] ` <50B40320.2020206-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-11-27 16:37 ` Alan Stern
2012-11-27 17:44 ` Andy Green
[not found] ` <50B4FBE9.5080301-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-11-27 18:09 ` Alan Stern
[not found] ` <Pine.LNX.4.44L0.1211271253230.1489-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-11-27 19:22 ` Andy Green
2012-11-27 20:10 ` Alan Stern
[not found] ` <Pine.LNX.4.44L0.1211271446430.1489-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-11-28 2:30 ` Andy Green [this message]
[not found] ` <50B51313.2060003-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-11-28 11:13 ` Roger Quadros
2012-11-28 11:47 ` Andy Green
2012-11-28 12:45 ` Roger Quadros
2012-11-28 16:43 ` Alan Stern
2012-11-29 2:05 ` Ming Lei
2012-11-29 17:05 ` Alan Stern
2012-11-27 3:41 ` Ming Lei
2012-11-27 16:30 ` Alan Stern
[not found] ` <Pine.LNX.4.44L0.1211271119380.1489-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-11-27 17:02 ` Greg KH
2012-12-01 7:49 ` Jassi Brar
2012-12-01 8:37 ` Andy Green
[not found] ` <50B9C1B0.3080605-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-12-01 18:08 ` Jassi Brar
[not found] ` <CABb+yY3TC3z+jRU91KGX+FKLtJ3ZXUp55-wM_KjxiYuVZ+LL+Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-12-05 14:09 ` Roger Quadros
[not found] ` <50BF55B3.1030205-l0cyMroinI0@public.gmane.org>
2012-12-06 14:34 ` Jassi Brar
2012-12-10 9:48 ` Roger Quadros
[not found] ` <50C5B003.9060904-l0cyMroinI0@public.gmane.org>
2012-12-10 14:36 ` Felipe Balbi
2012-12-11 9:12 ` Jassi Brar
[not found] ` <CABb+yY3u2QB0JqXrznDGHXqH3crkYk54whC0GTwkBHqjdEzhbg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-12-11 10:01 ` Roger Quadros
[not found] ` <50C70495.40500-l0cyMroinI0@public.gmane.org>
2012-12-11 10:09 ` Felipe Balbi
2012-11-27 17:22 ` Ming Lei
2012-11-27 17:55 ` Andy Green
[not found] ` <50B4FE7D.9030505-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-11-27 23:06 ` Ming Lei
2012-11-28 1:16 ` Ming Lei
2012-11-26 23:47 ` Andy Green
[not found] ` <20121126123427.18106.4112.stgit-Ak/hGR4SqtBG2qbu2SEcwgC/G2K4zDHf@public.gmane.org>
2012-11-26 12:45 ` [RFC PATCH 2/5] usb: omap ehci: remove all regulator control from ehci omap Andy Green
2012-11-26 12:45 ` [RFC PATCH 3/5] usb: hub: add device_path regulator control to generic hub Andy Green
2012-11-26 19:23 ` Greg KH
2012-11-26 12:45 ` [RFC PATCH 4/5] omap4: panda: add smsc95xx regulator and reset dependent on root hub Andy Green
2012-11-26 16:20 ` Roger Quadros
2012-11-27 0:17 ` Andy Green
2012-11-26 12:45 ` [RFC PATCH 5/5] config omap2plus add ehci bits Andy Green
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=50B57742.2010107@linaro.org \
--to=andy.green-qsej5fyqhm4dnm+yrofe0a@public.gmane.org \
--cc=balbi-l0cyMroinI0@public.gmane.org \
--cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
--cc=keshava_mgowda-l0cyMroinI0@public.gmane.org \
--cc=linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=rogerq-l0cyMroinI0@public.gmane.org \
--cc=stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org \
/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;
as well as URLs for NNTP newsgroup(s).