From: Arnd Bergmann <arnd@arndb.de>
To: Joachim Eastwood <manabian@gmail.com>
Cc: linux-arm-kernel@lists.infradead.org, peppe.cavallaro@st.com,
netdev@vger.kernel.org, davem@davemloft.net
Subject: Re: [PATCH 1/2] stmac: add dwmac glue for NXP 18xx/43xx family
Date: Mon, 04 May 2015 20:46:13 +0200 [thread overview]
Message-ID: <90049936.xgdXKqK565@wuerfel> (raw)
In-Reply-To: <1430691251-28119-1-git-send-email-manabian@gmail.com>
On Monday 04 May 2015 00:14:11 Joachim Eastwood wrote:
=> >It should be fairly straightforward to split the probe function
> >into two and export a function that takes a device and a stmmac_of_data
> >pointer as arguments, and declare a module_platform_driver in your
> >code.
>
> How about something like the patch below. All it does is to play a
> little trick with the of_match_device in the dt config function and
> export the probe/remove/pm stuff for the driver.
>
> The dwmac-lpc18xx would then become something like this:
>
> static const struct stmmac_of_data lpc18xx_dwmac_data = {
> .has_gmac = 1,
> .setup = lpc18xx_dwmac_setup,
> .init = lpc18xx_dwmac_init,
> };
>
> static const struct of_device_id lpc18xx_dwmac_match[] = {
> { .compatible = "nxp,lpc1850-dwmac", .data = &lpc18xx_dwmac_data },
> { }
> };
> MODULE_DEVICE_TABLE(of, lpc18xx_dwmac_match);
>
> static struct platform_driver lpc18xx_dwmac_driver = {
> .probe = stmmac_pltfr_probe,
> .remove = stmmac_pltfr_remove,
> .driver = {
> .name = "lpc18xx-dwmac",
> .pm = &stmmac_pltfr_pm_ops,
> .of_match_table = lpc18xx_dwmac_match,
> },
> };
> module_platform_driver(lpc18xx_dwmac_driver);
>
> All though this seem to work, stmmac_platform.c could benefit from
> some refactoring. But this patch and then fixing the other DT users
> could be a first step.
Sounds good, yes.
> - device = of_match_device(stmmac_dt_ids, &pdev->dev);
> + device = of_match_device(dev->driver->of_match_table, dev);
> if (!device)
> return -ENODEV;
Ah, that is a nice trick to avoid passing the various match tables
from a lot of duplicated probe functions.
I wonder if we could generalize that for use by any driver and
introduce a common helper
void *of_platform_match_data(struct device *dev)
{
struct of_device_id *id;
if (!dev || !dev->of_node)
return NULL;
id = of_match_device(dev->driver->of_match_table, dev);
if (!id)
return NULL;
return id->data;
}
EXPORT_SYMBOL_GPL(of_platform_match_data);
I think that could save a few lines from many drivers, and it had not
occurred to me that we can take this shortcut.
The rest of your patch also looks great to me.
Arnd
next prev parent reply other threads:[~2015-05-04 18:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-02 16:40 [PATCH 0/2] stmac: add glue for NXP LPC18xx family Joachim Eastwood
2015-05-02 16:40 ` [PATCH 1/2] stmac: add dwmac glue for NXP 18xx/43xx family Joachim Eastwood
2015-05-02 19:31 ` Arnd Bergmann
2015-05-02 20:48 ` Joachim Eastwood
2015-05-03 22:14 ` Joachim Eastwood
2015-05-04 18:46 ` Arnd Bergmann [this message]
2015-05-04 19:27 ` Joachim Eastwood
2015-05-02 16:40 ` [PATCH 2/2] doc: dt: add documentation for nxp,lpc1850-dwmac Joachim Eastwood
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=90049936.xgdXKqK565@wuerfel \
--to=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=manabian@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=peppe.cavallaro@st.com \
/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