From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Evgeniy Polyakov <zbr@ioremap.net>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Ville Syrjala <syrjala@sci.fi>, Daniel Mack <zonque@gmail.com>,
Matt Ranostay <mranostay@gmail.com>,
panto@antoniou-consulting.com, koen@dominion.thruhere.net
Subject: [PATCH 4/5] W1: w1-gpio - rework handling of platform data
Date: Sun, 24 Feb 2013 22:59:36 -0800 [thread overview]
Message-ID: <1361775577-4578-4-git-send-email-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <1361775577-4578-1-git-send-email-dmitry.torokhov@gmail.com>
The platform data in the dveice structure does not belong to the driver
and so it should not be trying to alter it, but instead use a local pointer
and populate it with a local copy in case we are dealing with device tree
setup.
Also allow mixed setups where platform data coexists with device tree and
prefer kernel-supplied data (it may be easier to fiddle in kernel structure
before committing final result to device tree).
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/w1/masters/w1-gpio.c | 44 +++++++++++++++++++++++++-------------------
1 file changed, 25 insertions(+), 19 deletions(-)
diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
index aa97a96..465ce52 100644
--- a/drivers/w1/masters/w1-gpio.c
+++ b/drivers/w1/masters/w1-gpio.c
@@ -55,30 +55,34 @@ static struct of_device_id w1_gpio_dt_ids[] = {
};
MODULE_DEVICE_TABLE(of, w1_gpio_dt_ids);
-static int w1_gpio_probe_dt(struct platform_device *pdev)
+static struct w1_gpio_platform_data *
+w1_gpio_probe_dt(struct platform_device *pdev)
{
- struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
+ struct w1_gpio_platform_data *pdata;
struct device_node *np = pdev->dev.of_node;
+ if (!np)
+ return ERR_PTR(-ENOENT);
+
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
if (of_get_property(np, "linux,open-drain", NULL))
pdata->is_open_drain = 1;
pdata->pin = of_get_gpio(np, 0);
pdata->ext_pullup_enable_pin = of_get_gpio(np, 1);
- pdev->dev.platform_data = pdata;
- return 0;
+ return pdata;
}
#else
-static inline int w1_gpio_probe_dt(struct platform_device *pdev)
+static inline struct w1_gpio_platform_data *
+w1_gpio_probe_dt(struct platform_device *pdev)
{
- return -ENOSYS;
+ return NULL;
}
#endif
@@ -94,19 +98,17 @@ static int w1_gpio_probe(struct platform_device *pdev)
if (IS_ERR(pinctrl))
dev_warn(&pdev->dev, "unable to select pin group\n");
- if (of_have_populated_dt()) {
- err = w1_gpio_probe_dt(pdev);
- if (err < 0) {
- dev_err(&pdev->dev, "Failed to parse DT\n");
- return err;
- }
- }
-
- pdata = pdev->dev.platform_data;
+ pdata = dev_get_platdata(&pdev->dev);
+ if (!pdata)
+ pdata = w1_gpio_probe_dt(pdev);
if (!pdata) {
dev_err(&pdev->dev, "No configuration data\n");
return -ENXIO;
+ } else if (IS_ERR(pdata)) {
+ err = PTR_ERR(pdata);
+ dev_err(&pdev->dev, "Failed to parse DT\n");
+ return err;
}
master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL);
@@ -172,7 +174,7 @@ static int w1_gpio_probe(struct platform_device *pdev)
static int w1_gpio_remove(struct platform_device *pdev)
{
struct w1_bus_master *master = platform_get_drvdata(pdev);
- struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
+ const struct w1_gpio_platform_data *pdata = master->data;
if (pdata->enable_external_pullup)
pdata->enable_external_pullup(0);
@@ -190,7 +192,9 @@ static int w1_gpio_remove(struct platform_device *pdev)
#ifdef CONFIG_PM_SLEEP
static int w1_gpio_suspend(struct device *dev)
{
- const struct w1_gpio_platform_data *pdata = dev_get_platdata(dev);
+ struct platform_device *pdev = to_platform_device(dev);
+ struct w1_bus_master *master = platform_get_drvdata(pdev);
+ const struct w1_gpio_platform_data *pdata = master->data;
if (pdata->enable_external_pullup)
pdata->enable_external_pullup(0);
@@ -200,7 +204,9 @@ static int w1_gpio_suspend(struct device *dev)
static int w1_gpio_resume(struct device *dev)
{
- const struct w1_gpio_platform_data *pdata = dev_get_platdata(dev);
+ struct platform_device *pdev = to_platform_device(dev);
+ struct w1_bus_master *master = platform_get_drvdata(pdev);
+ const struct w1_gpio_platform_data *pdata = master->data;
if (pdata->enable_external_pullup)
pdata->enable_external_pullup(1);
--
1.7.11.7
next prev parent reply other threads:[~2013-02-25 7:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-23 7:58 [PATCH 1/5] W1: w1-gpio - fix incorrect __init/__exit markups Dmitry Torokhov
2013-02-23 7:58 ` [PATCH 2/5] W1: w1-gpio - switch to using dev_pm_ops Dmitry Torokhov
2013-02-23 7:58 ` [PATCH 3/5] W1: w1-gpio - guard DT IDs with CONFIG_OF Dmitry Torokhov
2013-02-23 7:58 ` [PATCH 4/5] W1: w1-gpio - rework handling of platform data Dmitry Torokhov
2013-02-23 16:55 ` Ville Syrjälä
2013-02-23 20:06 ` Dmitry Torokhov
2013-02-23 7:58 ` [PATCH 5/5] W1: w1-gpio - switch to using managed resources (devm) Dmitry Torokhov
2013-02-25 6:59 ` [PATCH v2 1/5] W1: w1-gpio - fix incorrect __init/__exit markups Dmitry Torokhov
2013-02-25 6:59 ` [PATCH 2/5] W1: w1-gpio - switch to using dev_pm_ops Dmitry Torokhov
2013-02-25 6:59 ` [PATCH 3/5] W1: w1-gpio - guard DT IDs with CONFIG_OF Dmitry Torokhov
2013-03-12 23:23 ` Greg Kroah-Hartman
2013-02-25 6:59 ` Dmitry Torokhov [this message]
2013-02-25 6:59 ` [PATCH 5/5] W1: w1-gpio - switch to using managed resources (devm) Dmitry Torokhov
2013-03-12 23:23 ` [PATCH v2 1/5] W1: w1-gpio - fix incorrect __init/__exit markups Greg Kroah-Hartman
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=1361775577-4578-4-git-send-email-dmitry.torokhov@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=koen@dominion.thruhere.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mranostay@gmail.com \
--cc=panto@antoniou-consulting.com \
--cc=syrjala@sci.fi \
--cc=zbr@ioremap.net \
--cc=zonque@gmail.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