linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] w1-gpio: add external pull-up enable callback
@ 2009-05-05 12:43 Daniel Mack
  2009-05-06  9:33 ` Ville Syrjälä
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Daniel Mack @ 2009-05-05 12:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: Daniel Mack, Ville Syrjala

On embedded devices, sleep mode conditions can be tricky to handle,
Especially when processors tend to pull-down the w1 bus during sleep.
Bus slaves (such as the ds2760) may interpret this as a reason for
power-down conditions and entirely switch off the device.

This patch adds a callback function pointer to let users switch on and
off the external pull-up resistor. This lets the outside world know
whether the processor is currently actively driving the bus or not.

When this callback is not provided, the code behaviour won't change.

Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: Ville Syrjala <syrjala@sci.fi>
---
 drivers/w1/masters/w1-gpio.c |   35 +++++++++++++++++++++++++++++++++++
 include/linux/w1-gpio.h      |    1 +
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
index a411702..6f8866d 100644
--- a/drivers/w1/masters/w1-gpio.c
+++ b/drivers/w1/masters/w1-gpio.c
@@ -74,6 +74,9 @@ static int __init w1_gpio_probe(struct platform_device *pdev)
 	if (err)
 		goto free_gpio;
 
+	if (pdata->enable_external_pullup)
+		pdata->enable_external_pullup(1);
+
 	platform_set_drvdata(pdev, master);
 
 	return 0;
@@ -91,6 +94,9 @@ static int __exit 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;
 
+	if (pdata->enable_external_pullup)
+		pdata->enable_external_pullup(0);
+
 	w1_remove_master_device(master);
 	gpio_free(pdata->pin);
 	kfree(master);
@@ -98,12 +104,41 @@ static int __exit w1_gpio_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM
+
+static int w1_gpio_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
+
+	if (pdata->enable_external_pullup)
+		pdata->enable_external_pullup(0);
+
+	return 0;
+}
+
+static int w1_gpio_resume(struct platform_device *pdev)
+{
+	struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
+
+	if (pdata->enable_external_pullup)
+		pdata->enable_external_pullup(1);
+
+	return 0;
+}
+
+#else
+#define w1_gpio_suspend	NULL
+#define w1_gpio_resume	NULL
+#endif
+
 static struct platform_driver w1_gpio_driver = {
 	.driver = {
 		.name	= "w1-gpio",
 		.owner	= THIS_MODULE,
 	},
 	.remove	= __exit_p(w1_gpio_remove),
+	.suspend = w1_gpio_suspend,
+	.resume = w1_gpio_resume,
 };
 
 static int __init w1_gpio_init(void)
diff --git a/include/linux/w1-gpio.h b/include/linux/w1-gpio.h
index 9797fec..3adeff8 100644
--- a/include/linux/w1-gpio.h
+++ b/include/linux/w1-gpio.h
@@ -18,6 +18,7 @@
 struct w1_gpio_platform_data {
 	unsigned int pin;
 	unsigned int is_open_drain:1;
+	void (*enable_external_pullup)(int enable);
 };
 
 #endif /* _LINUX_W1_GPIO_H */
-- 
1.6.2.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] w1-gpio: add external pull-up enable callback
  2009-05-05 12:43 [PATCH] w1-gpio: add external pull-up enable callback Daniel Mack
@ 2009-05-06  9:33 ` Ville Syrjälä
  2009-05-06  9:34   ` Daniel Mack
  2009-05-08 20:13 ` Daniel Mack
  2009-05-12 13:56 ` Daniel Mack
  2 siblings, 1 reply; 9+ messages in thread
From: Ville Syrjälä @ 2009-05-06  9:33 UTC (permalink / raw)
  To: Daniel Mack; +Cc: linux-kernel

On Tue, May 05, 2009 at 02:43:33PM +0200, Daniel Mack wrote:
> On embedded devices, sleep mode conditions can be tricky to handle,
> Especially when processors tend to pull-down the w1 bus during sleep.
> Bus slaves (such as the ds2760) may interpret this as a reason for
> power-down conditions and entirely switch off the device.
> 
> This patch adds a callback function pointer to let users switch on and
> off the external pull-up resistor. This lets the outside world know
> whether the processor is currently actively driving the bus or not.

Looks simple enough but I wonder if you could just do this from the
platform code. I suppose the downside would be that you would enable the
pullup even if w1-gpio is not loaded.

-- 
Ville Syrjälä
syrjala@sci.fi
http://www.sci.fi/~syrjala/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] w1-gpio: add external pull-up enable callback
  2009-05-06  9:33 ` Ville Syrjälä
@ 2009-05-06  9:34   ` Daniel Mack
  2009-05-06 20:28     ` Ville Syrjälä
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Mack @ 2009-05-06  9:34 UTC (permalink / raw)
  To: Ville Syrjälä, linux-kernel

On Wed, May 06, 2009 at 12:33:07PM +0300, Ville Syrjälä wrote:
> On Tue, May 05, 2009 at 02:43:33PM +0200, Daniel Mack wrote:
> > On embedded devices, sleep mode conditions can be tricky to handle,
> > Especially when processors tend to pull-down the w1 bus during sleep.
> > Bus slaves (such as the ds2760) may interpret this as a reason for
> > power-down conditions and entirely switch off the device.
> > 
> > This patch adds a callback function pointer to let users switch on and
> > off the external pull-up resistor. This lets the outside world know
> > whether the processor is currently actively driving the bus or not.
> 
> Looks simple enough but I wonder if you could just do this from the
> platform code. I suppose the downside would be that you would enable the
> pullup even if w1-gpio is not loaded.

That's right. Hence I put it where I believe it belongs to.

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] w1-gpio: add external pull-up enable callback
  2009-05-06  9:34   ` Daniel Mack
@ 2009-05-06 20:28     ` Ville Syrjälä
  2009-05-07  1:30       ` Daniel Mack
  0 siblings, 1 reply; 9+ messages in thread
From: Ville Syrjälä @ 2009-05-06 20:28 UTC (permalink / raw)
  To: Daniel Mack; +Cc: linux-kernel

On Wed, May 06, 2009 at 11:34:45AM +0200, Daniel Mack wrote:
> On Wed, May 06, 2009 at 12:33:07PM +0300, Ville Syrjälä wrote:
> > On Tue, May 05, 2009 at 02:43:33PM +0200, Daniel Mack wrote:
> > > On embedded devices, sleep mode conditions can be tricky to handle,
> > > Especially when processors tend to pull-down the w1 bus during sleep.
> > > Bus slaves (such as the ds2760) may interpret this as a reason for
> > > power-down conditions and entirely switch off the device.
> > > 
> > > This patch adds a callback function pointer to let users switch on and
> > > off the external pull-up resistor. This lets the outside world know
> > > whether the processor is currently actively driving the bus or not.
> > 
> > Looks simple enough but I wonder if you could just do this from the
> > platform code. I suppose the downside would be that you would enable the
> > pullup even if w1-gpio is not loaded.
> 
> That's right. Hence I put it where I believe it belongs to.

Well, if you think you need it who am I to argue :)

Acked-by: Ville Syrjälä <syrjala@sci.fi>

-- 
Ville Syrjälä
syrjala@sci.fi
http://www.sci.fi/~syrjala/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] w1-gpio: add external pull-up enable callback
  2009-05-06 20:28     ` Ville Syrjälä
@ 2009-05-07  1:30       ` Daniel Mack
  2009-05-08 18:19         ` Ville Syrjälä
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Mack @ 2009-05-07  1:30 UTC (permalink / raw)
  To: Ville Syrjälä, linux-kernel

On Wed, May 06, 2009 at 11:28:18PM +0300, Ville Syrjälä wrote:
> > > > This patch adds a callback function pointer to let users switch on and
> > > > off the external pull-up resistor. This lets the outside world know
> > > > whether the processor is currently actively driving the bus or not.
> > > 
> > > Looks simple enough but I wonder if you could just do this from the
> > > platform code. I suppose the downside would be that you would enable the
> > > pullup even if w1-gpio is not loaded.
> > 
> > That's right. Hence I put it where I believe it belongs to.
> 
> Well, if you think you need it who am I to argue :)
> 
> Acked-by: Ville Syrjälä <syrjala@sci.fi>

Thanks :)

Daniel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] w1-gpio: add external pull-up enable callback
  2009-05-07  1:30       ` Daniel Mack
@ 2009-05-08 18:19         ` Ville Syrjälä
  0 siblings, 0 replies; 9+ messages in thread
From: Ville Syrjälä @ 2009-05-08 18:19 UTC (permalink / raw)
  To: Daniel Mack; +Cc: linux-kernel

On Thu, May 07, 2009 at 03:30:32AM +0200, Daniel Mack wrote:
> On Wed, May 06, 2009 at 11:28:18PM +0300, Ville Syrjälä wrote:
> > > > > This patch adds a callback function pointer to let users switch on and
> > > > > off the external pull-up resistor. This lets the outside world know
> > > > > whether the processor is currently actively driving the bus or not.
> > > > 
> > > > Looks simple enough but I wonder if you could just do this from the
> > > > platform code. I suppose the downside would be that you would enable the
> > > > pullup even if w1-gpio is not loaded.
> > > 
> > > That's right. Hence I put it where I believe it belongs to.
> > 
> > Well, if you think you need it who am I to argue :)
> > 
> > Acked-by: Ville Syrjälä <syrjala@sci.fi>
> 
> Thanks :)

BTW you should probably send this via Evgeniy Polyakov if you want it
included in the kernel at some point.

-- 
Ville Syrjälä
syrjala@sci.fi
http://www.sci.fi/~syrjala/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] w1-gpio: add external pull-up enable callback
  2009-05-05 12:43 [PATCH] w1-gpio: add external pull-up enable callback Daniel Mack
  2009-05-06  9:33 ` Ville Syrjälä
@ 2009-05-08 20:13 ` Daniel Mack
  2009-05-08 20:53   ` Evgeniy Polyakov
  2009-05-12 13:56 ` Daniel Mack
  2 siblings, 1 reply; 9+ messages in thread
From: Daniel Mack @ 2009-05-08 20:13 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ville Syrjala, Evgeniy Polyakov

(cc Evgeniy Polyakov)

Evgeniy, could you give some feedback on this? Ville Syrjala gave his
Acked-by already.

Thanks,
Daniel


On Tue, May 05, 2009 at 02:43:33PM +0200, Daniel Mack wrote:
> On embedded devices, sleep mode conditions can be tricky to handle,
> Especially when processors tend to pull-down the w1 bus during sleep.
> Bus slaves (such as the ds2760) may interpret this as a reason for
> power-down conditions and entirely switch off the device.
> 
> This patch adds a callback function pointer to let users switch on and
> off the external pull-up resistor. This lets the outside world know
> whether the processor is currently actively driving the bus or not.
> 
> When this callback is not provided, the code behaviour won't change.
> 
> Signed-off-by: Daniel Mack <daniel@caiaq.de>
> Cc: Ville Syrjala <syrjala@sci.fi>
> ---
>  drivers/w1/masters/w1-gpio.c |   35 +++++++++++++++++++++++++++++++++++
>  include/linux/w1-gpio.h      |    1 +
>  2 files changed, 36 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
> index a411702..6f8866d 100644
> --- a/drivers/w1/masters/w1-gpio.c
> +++ b/drivers/w1/masters/w1-gpio.c
> @@ -74,6 +74,9 @@ static int __init w1_gpio_probe(struct platform_device *pdev)
>  	if (err)
>  		goto free_gpio;
>  
> +	if (pdata->enable_external_pullup)
> +		pdata->enable_external_pullup(1);
> +
>  	platform_set_drvdata(pdev, master);
>  
>  	return 0;
> @@ -91,6 +94,9 @@ static int __exit 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;
>  
> +	if (pdata->enable_external_pullup)
> +		pdata->enable_external_pullup(0);
> +
>  	w1_remove_master_device(master);
>  	gpio_free(pdata->pin);
>  	kfree(master);
> @@ -98,12 +104,41 @@ static int __exit w1_gpio_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +#ifdef CONFIG_PM
> +
> +static int w1_gpio_suspend(struct platform_device *pdev, pm_message_t state)
> +{
> +	struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
> +
> +	if (pdata->enable_external_pullup)
> +		pdata->enable_external_pullup(0);
> +
> +	return 0;
> +}
> +
> +static int w1_gpio_resume(struct platform_device *pdev)
> +{
> +	struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
> +
> +	if (pdata->enable_external_pullup)
> +		pdata->enable_external_pullup(1);
> +
> +	return 0;
> +}
> +
> +#else
> +#define w1_gpio_suspend	NULL
> +#define w1_gpio_resume	NULL
> +#endif
> +
>  static struct platform_driver w1_gpio_driver = {
>  	.driver = {
>  		.name	= "w1-gpio",
>  		.owner	= THIS_MODULE,
>  	},
>  	.remove	= __exit_p(w1_gpio_remove),
> +	.suspend = w1_gpio_suspend,
> +	.resume = w1_gpio_resume,
>  };
>  
>  static int __init w1_gpio_init(void)
> diff --git a/include/linux/w1-gpio.h b/include/linux/w1-gpio.h
> index 9797fec..3adeff8 100644
> --- a/include/linux/w1-gpio.h
> +++ b/include/linux/w1-gpio.h
> @@ -18,6 +18,7 @@
>  struct w1_gpio_platform_data {
>  	unsigned int pin;
>  	unsigned int is_open_drain:1;
> +	void (*enable_external_pullup)(int enable);
>  };
>  
>  #endif /* _LINUX_W1_GPIO_H */
> -- 
> 1.6.2.1
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] w1-gpio: add external pull-up enable callback
  2009-05-08 20:13 ` Daniel Mack
@ 2009-05-08 20:53   ` Evgeniy Polyakov
  0 siblings, 0 replies; 9+ messages in thread
From: Evgeniy Polyakov @ 2009-05-08 20:53 UTC (permalink / raw)
  To: Daniel Mack; +Cc: linux-kernel, Ville Syrjala

Hi Daniel.

On Fri, May 08, 2009 at 10:13:02PM +0200, Daniel Mack (daniel@caiaq.de) wrote:
> (cc Evgeniy Polyakov)
> 
> Evgeniy, could you give some feedback on this? Ville Syrjala gave his
> Acked-by already.

Looks good! Feel free to add mine too and submit through Andrew Morton
or via other path.

-- 
	Evgeniy Polyakov

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] w1-gpio: add external pull-up enable callback
  2009-05-05 12:43 [PATCH] w1-gpio: add external pull-up enable callback Daniel Mack
  2009-05-06  9:33 ` Ville Syrjälä
  2009-05-08 20:13 ` Daniel Mack
@ 2009-05-12 13:56 ` Daniel Mack
  2 siblings, 0 replies; 9+ messages in thread
From: Daniel Mack @ 2009-05-12 13:56 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ville Syrjala, Evgeniy Polyakov, Andrew Morton

(cc Andrew Morton)

Andrew,

could you add this to your patch queue? It's been acked by Ville Syrjala
and Evgeniy Polyakov.

Thanks,
Daniel


>From 6a99f9453d9b0ad2dd705c012014063977781bf3 Mon Sep 17 00:00:00 2001
From: Daniel Mack <daniel@caiaq.de>
Date: Tue, 5 May 2009 14:35:04 +0200
Subject: [PATCH] w1-gpio: add external pull-up enable callback

On embedded devices, sleep mode conditions can be tricky to handle,
Especially when processors tend to pull-down the w1 bus during sleep.
Bus slaves (such as the ds2760) may interpret this as a reason for
power-down conditions and entirely switch off the device.

This patch adds a callback function pointer to let users switch on and
off the external pull-up resistor. This lets the outside world know
whether the processor is currently actively driving the bus or not.

When this callback is not provided, the code behaviour won't change.

Signed-off-by: Daniel Mack <daniel@caiaq.de>
Acked-by: Ville Syrjala <syrjala@sci.fi>
Acked-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
---
 drivers/w1/masters/w1-gpio.c |   35 +++++++++++++++++++++++++++++++++++
 include/linux/w1-gpio.h      |    1 +
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
index a411702..6f8866d 100644
--- a/drivers/w1/masters/w1-gpio.c
+++ b/drivers/w1/masters/w1-gpio.c
@@ -74,6 +74,9 @@ static int __init w1_gpio_probe(struct platform_device *pdev)
 	if (err)
 		goto free_gpio;
 
+	if (pdata->enable_external_pullup)
+		pdata->enable_external_pullup(1);
+
 	platform_set_drvdata(pdev, master);
 
 	return 0;
@@ -91,6 +94,9 @@ static int __exit 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;
 
+	if (pdata->enable_external_pullup)
+		pdata->enable_external_pullup(0);
+
 	w1_remove_master_device(master);
 	gpio_free(pdata->pin);
 	kfree(master);
@@ -98,12 +104,41 @@ static int __exit w1_gpio_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM
+
+static int w1_gpio_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
+
+	if (pdata->enable_external_pullup)
+		pdata->enable_external_pullup(0);
+
+	return 0;
+}
+
+static int w1_gpio_resume(struct platform_device *pdev)
+{
+	struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
+
+	if (pdata->enable_external_pullup)
+		pdata->enable_external_pullup(1);
+
+	return 0;
+}
+
+#else
+#define w1_gpio_suspend	NULL
+#define w1_gpio_resume	NULL
+#endif
+
 static struct platform_driver w1_gpio_driver = {
 	.driver = {
 		.name	= "w1-gpio",
 		.owner	= THIS_MODULE,
 	},
 	.remove	= __exit_p(w1_gpio_remove),
+	.suspend = w1_gpio_suspend,
+	.resume = w1_gpio_resume,
 };
 
 static int __init w1_gpio_init(void)
diff --git a/include/linux/w1-gpio.h b/include/linux/w1-gpio.h
index 9797fec..3adeff8 100644
--- a/include/linux/w1-gpio.h
+++ b/include/linux/w1-gpio.h
@@ -18,6 +18,7 @@
 struct w1_gpio_platform_data {
 	unsigned int pin;
 	unsigned int is_open_drain:1;
+	void (*enable_external_pullup)(int enable);
 };
 
 #endif /* _LINUX_W1_GPIO_H */
-- 
1.6.2.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-05-12 13:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-05 12:43 [PATCH] w1-gpio: add external pull-up enable callback Daniel Mack
2009-05-06  9:33 ` Ville Syrjälä
2009-05-06  9:34   ` Daniel Mack
2009-05-06 20:28     ` Ville Syrjälä
2009-05-07  1:30       ` Daniel Mack
2009-05-08 18:19         ` Ville Syrjälä
2009-05-08 20:13 ` Daniel Mack
2009-05-08 20:53   ` Evgeniy Polyakov
2009-05-12 13:56 ` Daniel Mack

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).