All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] Add strong pullup emulation to w1-gpio master driver.
@ 2013-11-11 14:36 Evgeny Boger
  2013-11-11 23:09 ` Evgeniy Polyakov
  0 siblings, 1 reply; 9+ messages in thread
From: Evgeny Boger @ 2013-11-11 14:36 UTC (permalink / raw)
  To: Evgeniy Polyakov; +Cc: linux-kernel, Evgeny Boger, Evgeny Boger

 Strong pullup is emulated by driving pin logic high after write command when
 using tri-state push-pull GPIO.


Signed-off-by: Evgeny Boger <boger@contactless.ru>
---
 drivers/w1/masters/w1-gpio.c | 22 ++++++++++++++++++++++
 drivers/w1/w1_int.c          | 12 ------------
 include/linux/w1-gpio.h      |  1 +
 3 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
index f54ece2..cb7f89b 100644
--- a/drivers/w1/masters/w1-gpio.c
+++ b/drivers/w1/masters/w1-gpio.c
@@ -18,10 +18,31 @@
 #include <linux/of_gpio.h>
 #include <linux/err.h>
 #include <linux/of.h>
+#include <linux/delay.h>

 #include "../w1.h"
 #include "../w1_int.h"

+static u8 w1_gpio_set_pullup(void *data, int delay)
+{
+	struct w1_gpio_platform_data *pdata = data;
+
+	if (delay) {
+		pdata->pullup_duration = delay;
+	} else {
+		if (pdata->pullup_duration) {
+			gpio_direction_output(pdata->pin, 1);
+
+			msleep(pdata->pullup_duration);
+
+			gpio_direction_input(pdata->pin);
+		}
+		pdata->pullup_duration = 0;
+	}
+
+	return 0;
+}
+
 static void w1_gpio_write_bit_dir(void *data, u8 bit)
 {
	struct w1_gpio_platform_data *pdata = data;
@@ -125,6 +146,7 @@ static int w1_gpio_probe(struct platform_device *pdev)
	} else {
		gpio_direction_input(pdata->pin);
		master->write_bit = w1_gpio_write_bit_dir;
+		master->set_pullup = w1_gpio_set_pullup;
	}

	err = w1_add_master_device(master);
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index 5a98649..590bd8a 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -117,18 +117,6 @@ int w1_add_master_device(struct w1_bus_master *master)
		printk(KERN_ERR "w1_add_master_device: invalid function set\n");
		return(-EINVAL);
         }
-	/* While it would be electrically possible to make a device that
-	 * generated a strong pullup in bit bang mode, only hardware that
-	 * controls 1-wire time frames are even expected to support a strong
-	 * pullup.  w1_io.c would need to support calling set_pullup before
-	 * the last write_bit operation of a w1_write_8 which it currently
-	 * doesn't.
-	 */
-	if (!master->write_byte && !master->touch_bit && master->set_pullup) {
-		printk(KERN_ERR "w1_add_master_device: set_pullup requires "
-			"write_byte or touch_bit, disabling\n");
-		master->set_pullup = NULL;
-	}

	/* Lock until the device is added (or not) to w1_masters. */
	mutex_lock(&w1_mlock);
diff --git a/include/linux/w1-gpio.h b/include/linux/w1-gpio.h
index 065e3ae..d58594a 100644
--- a/include/linux/w1-gpio.h
+++ b/include/linux/w1-gpio.h
@@ -20,6 +20,7 @@ struct w1_gpio_platform_data {
	unsigned int is_open_drain:1;
	void (*enable_external_pullup)(int enable);
	unsigned int ext_pullup_enable_pin;
+	unsigned int pullup_duration;
 };

 #endif /* _LINUX_W1_GPIO_H */
--
1.8.1.2

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

* Re: [PATCH 1/1] Add strong pullup emulation to w1-gpio master driver.
  2013-11-11 14:36 [PATCH 1/1] Add strong pullup emulation to w1-gpio master driver Evgeny Boger
@ 2013-11-11 23:09 ` Evgeniy Polyakov
       [not found]   ` <5281691F.4060604@gmail.com>
  0 siblings, 1 reply; 9+ messages in thread
From: Evgeniy Polyakov @ 2013-11-11 23:09 UTC (permalink / raw)
  To: Evgeny Boger; +Cc: linux-kernel, Evgeny Boger

Hi

11.11.2013, 18:37, "Evgeny Boger" <eugenyboger@gmail.com>:
>  Strong pullup is emulated by driving pin logic high after write command when
>  using tri-state push-pull GPIO.
>
> Signed-off-by: Evgeny Boger <boger@contactless.ru>
> ---
>  drivers/w1/masters/w1-gpio.c | 22 ++++++++++++++++++++++
>  drivers/w1/w1_int.c          | 12 ------------
>  include/linux/w1-gpio.h      |  1 +
>  3 files changed, 23 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
> index f54ece2..cb7f89b 100644
> --- a/drivers/w1/masters/w1-gpio.c
> +++ b/drivers/w1/masters/w1-gpio.c
> @@ -18,10 +18,31 @@
>  #include <linux/of_gpio.h>
>  #include <linux/err.h>
>  #include <linux/of.h>
> +#include <linux/delay.h>
>
>  #include "../w1.h"
>  #include "../w1_int.h"
>
> +static u8 w1_gpio_set_pullup(void *data, int delay)
> +{
> + struct w1_gpio_platform_data *pdata = data;
> +
> + if (delay) {
> + pdata->pullup_duration = delay;
> + } else {
> + if (pdata->pullup_duration) {
> + gpio_direction_output(pdata->pin, 1);
> +
> + msleep(pdata->pullup_duration);

This doesn't look like a good idea - kernel will sleep for that long not doing usual w1 job

> --- a/drivers/w1/w1_int.c
> +++ b/drivers/w1/w1_int.c
> @@ -117,18 +117,6 @@ int w1_add_master_device(struct w1_bus_master *master)
>                 printk(KERN_ERR "w1_add_master_device: invalid function set\n");
>                 return(-EINVAL);
>          }
> - /* While it would be electrically possible to make a device that
> - * generated a strong pullup in bit bang mode, only hardware that
> - * controls 1-wire time frames are even expected to support a strong
> - * pullup.  w1_io.c would need to support calling set_pullup before
> - * the last write_bit operation of a w1_write_8 which it currently
> - * doesn't.
> - */
> - if (!master->write_byte && !master->touch_bit && master->set_pullup) {
> - printk(KERN_ERR "w1_add_master_device: set_pullup requires "
> - "write_byte or touch_bit, disabling\n");
> - master->set_pullup = NULL;
> - }
>

Why did you drop this check? It has nothing with w1-gpio driver

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

* Re: [PATCH 1/1] Add strong pullup emulation to w1-gpio master driver.
       [not found]   ` <5281691F.4060604@gmail.com>
@ 2013-11-12  1:03     ` Evgeniy Polyakov
  2013-11-12  1:07       ` Evgeny Boger
  0 siblings, 1 reply; 9+ messages in thread
From: Evgeniy Polyakov @ 2013-11-12  1:03 UTC (permalink / raw)
  To: Evgeny Boger; +Cc: linux-kernel

Hi

12.11.2013, 03:32, "Evgeny Boger" <eugenyboger@gmail.com>:
>> Why did you drop this check? It has nothing with w1-gpio driver
> This check prevents master from implementing "set_pullup"  provided it does support only "write_bit" method.
> The comment above states that
>>  w1_io.c would need to support calling set_pullup before - * the last write_bit operation of a w1_write_8 which it currently - * doesn't.
> which is kind of strange, since it describes what w1_io.c actually does support.
>
> w1_write_8 (w1_io.c:154, https://github.com/torvalds/linux/blob/master/drivers/w1/w1_io.c#L154):
>>                 for (i = 0; i < 8; ++i) {
>>                         if (i == 7)
>>                                 w1_pre_write(dev);
>>                         w1_touch_bit(dev, (byte >> i) & 0x1);
>>                 }
>
> It seems like w1_write_8() calls w1_pre_write(), which in turn calls set_pullup() just before the last write_bit().
>
> I'm not sure why this check was there in the first place.

Please add author of those lines to clarify things.
This doesn't look obvious to me

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

* Re: [PATCH 1/1] Add strong pullup emulation to w1-gpio master driver.
  2013-11-12  1:03     ` Evgeniy Polyakov
@ 2013-11-12  1:07       ` Evgeny Boger
  2013-11-12  8:01         ` David Fries
  0 siblings, 1 reply; 9+ messages in thread
From: Evgeny Boger @ 2013-11-12  1:07 UTC (permalink / raw)
  To: Evgeniy Polyakov; +Cc: linux-kernel, David Fries

+David Fries <david@fries.net>

Hi David,

Would you please comment on this?


11/12/2013 05:03 AM, Evgeniy Polyakov:
> Hi
>
> 12.11.2013, 03:32, "Evgeny Boger" <eugenyboger@gmail.com>:
>>> Why did you drop this check? It has nothing with w1-gpio driver
>> This check prevents master from implementing "set_pullup"  provided it does support only "write_bit" method.
>> The comment above states that
>>>   w1_io.c would need to support calling set_pullup before - * the last write_bit operation of a w1_write_8 which it currently - * doesn't.
>> which is kind of strange, since it describes what w1_io.c actually does support.
>>
>> w1_write_8 (w1_io.c:154, https://github.com/torvalds/linux/blob/master/drivers/w1/w1_io.c#L154):
>>>                  for (i = 0; i < 8; ++i) {
>>>                          if (i == 7)
>>>                                  w1_pre_write(dev);
>>>                          w1_touch_bit(dev, (byte >> i) & 0x1);
>>>                  }
>> It seems like w1_write_8() calls w1_pre_write(), which in turn calls set_pullup() just before the last write_bit().
>>
>> I'm not sure why this check was there in the first place.
> Please add author of those lines to clarify things.
> This doesn't look obvious to me


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

* Re: [PATCH 1/1] Add strong pullup emulation to w1-gpio master driver.
  2013-11-12  1:07       ` Evgeny Boger
@ 2013-11-12  8:01         ` David Fries
  2013-11-13  1:15           ` Evgeny Boger
  0 siblings, 1 reply; 9+ messages in thread
From: David Fries @ 2013-11-12  8:01 UTC (permalink / raw)
  To: Evgeny Boger; +Cc: Evgeniy Polyakov, linux-kernel

On Tue, Nov 12, 2013 at 05:07:14AM +0400, Evgeny Boger wrote:
> +David Fries <david@fries.net>
> 
> Hi David,
> 
> Would you please comment on this?


On Mon, Nov 11, 2013 at 06:36:54PM +0400, Evgeny Boger wrote:
>  Strong pullup is emulated by driving pin logic high after write
>  command when
>  using tri-state push-pull GPIO.

Not knowing the hardware involved, is driving the logic high a
stronger pullup than the normal weak pullup input high?  Meaning it
was already being left high, just with a lessor pullup and this will
provide a stronger one?

On Tue, Nov 12, 2013 at 03:09:36AM +0400, Evgeniy Polyakov wrote:
> > + msleep(pdata->pullup_duration);
> 
> This doesn't look like a good idea - kernel will sleep for that long
> not doing usual w1 job

Not speaking for Evgeny Boger, but I'm thinking that's intended here.
The original strong pullup code change 6a158c0de791a81 I wrote will
msleep in w1_post_write when a hardware pullup isn't available, while
the hardware ds2490 ds9490r_set_pullup sleeps for the strong pullup
using spu_sleep variable.  The user requests a strong pullup for a
given time and any other operations on the bus will interrupt the
strong pullup, so locking any other operations sounds desired.

> 11/12/2013 05:03 AM, Evgeniy Polyakov:
> >Hi
> >
> >12.11.2013, 03:32, "Evgeny Boger" <eugenyboger@gmail.com>:
> >>>Why did you drop this check? It has nothing with w1-gpio driver
> >>This check prevents master from implementing "set_pullup"  provided it does support only "write_bit" method.
> >>The comment above states that
> >>>  w1_io.c would need to support calling set_pullup before - * the last write_bit operation of a w1_write_8 which it currently - * doesn't.
> >>which is kind of strange, since it describes what w1_io.c actually does support.
> >>
> >>w1_write_8 (w1_io.c:154, https://github.com/torvalds/linux/blob/master/drivers/w1/w1_io.c#L154):
> >>>                 for (i = 0; i < 8; ++i) {
> >>>                         if (i == 7)
> >>>                                 w1_pre_write(dev);
> >>>                         w1_touch_bit(dev, (byte >> i) & 0x1);
> >>>                 }
> >>It seems like w1_write_8() calls w1_pre_write(), which in turn calls set_pullup() just before the last write_bit().

I'm not seeing any harm in removing this check and clear
master->set_pullup.  It doesn't seem correct for this code to override
a master that claims to provide something of a stronger pullup.  It's
been about five years since I wrote that code, I think it was just to
protect against a stupid master.

With this patch the last w1_write_bit will go logic 1, for 64 or 10 us
before returning, then w1_gpio_set_pullup is called to enable the
strong pullup.  What I wouldn't know is if in that last bit if the
logic 1 would be a go up to the strong pullup, or if it would finish
that time slot with a weak pullup and then go to a strong pullup.  I
would have to dig into the timing specifications much more than I have
time to right now to say what is supposed to happen.  The 18b20
datasheet lists, "The DQ line must be switched over to the strong
pullup within 10 us maximum after issuing any protocol that involves
copying the E2 memory or initiates temperature conversions."  It isn't
clear where that 10 us starts from.  You might try to dig around and
see if that last bit written should go to weak pullup 1 or strong
pullup 1.  It would take more changes if it should go right to a
strong pullup.

> >>I'm not sure why this check was there in the first place.
> >Please add author of those lines to clarify things.
> >This doesn't look obvious to me

-- 
David Fries <david@fries.net>    PGP pub CB1EE8F0
http://fries.net/~david/

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

* Re: [PATCH 1/1] Add strong pullup emulation to w1-gpio master driver.
  2013-11-12  8:01         ` David Fries
@ 2013-11-13  1:15           ` Evgeny Boger
  2013-11-13  4:07             ` David Fries
  0 siblings, 1 reply; 9+ messages in thread
From: Evgeny Boger @ 2013-11-13  1:15 UTC (permalink / raw)
  To: David Fries; +Cc: Evgeniy Polyakov, linux-kernel

11/12/2013 12:01 PM, David Fries:
> On Tue, Nov 12, 2013 at 05:07:14AM +0400, Evgeny Boger wrote:
>> +David Fries <david@fries.net>
>>
>> Hi David,
>>
>> Would you please comment on this?
>
> On Mon, Nov 11, 2013 at 06:36:54PM +0400, Evgeny Boger wrote:
>>   Strong pullup is emulated by driving pin logic high after write
>>   command when
>>   using tri-state push-pull GPIO.
> Not knowing the hardware involved, is driving the logic high a
> stronger pullup than the normal weak pullup input high?  Meaning it
> was already being left high, just with a lessor pullup and this will
> provide a stronger one?




Sure. The push-pull GPIO on common SoC's are usually able to provide up 
to 10 mA of current.




>
> On Tue, Nov 12, 2013 at 03:09:36AM +0400, Evgeniy Polyakov wrote:
>>> + msleep(pdata->pullup_duration);
>> This doesn't look like a good idea - kernel will sleep for that long
>> not doing usual w1 job
> Not speaking for Evgeny Boger, but I'm thinking that's intended here.
> The original strong pullup code change 6a158c0de791a81 I wrote will
> msleep in w1_post_write when a hardware pullup isn't available, while
> the hardware ds2490 ds9490r_set_pullup sleeps for the strong pullup
> using spu_sleep variable.  The user requests a strong pullup for a
> given time and any other operations on the bus will interrupt the
> strong pullup, so locking any other operations sounds desired.
>
>> 11/12/2013 05:03 AM, Evgeniy Polyakov:
>>> Hi
>>>
>>> 12.11.2013, 03:32, "Evgeny Boger" <eugenyboger@gmail.com>:
>>>>> Why did you drop this check? It has nothing with w1-gpio driver
>>>> This check prevents master from implementing "set_pullup"  provided it does support only "write_bit" method.
>>>> The comment above states that
>>>>>   w1_io.c would need to support calling set_pullup before - * the last write_bit operation of a w1_write_8 which it currently - * doesn't.
>>>> which is kind of strange, since it describes what w1_io.c actually does support.
>>>>
>>>> w1_write_8 (w1_io.c:154, https://github.com/torvalds/linux/blob/master/drivers/w1/w1_io.c#L154):
>>>>>                  for (i = 0; i < 8; ++i) {
>>>>>                          if (i == 7)
>>>>>                                  w1_pre_write(dev);
>>>>>                          w1_touch_bit(dev, (byte >> i) & 0x1);
>>>>>                  }
>>>> It seems like w1_write_8() calls w1_pre_write(), which in turn calls set_pullup() just before the last write_bit().
> I'm not seeing any harm in removing this check and clear
> master->set_pullup.  It doesn't seem correct for this code to override
> a master that claims to provide something of a stronger pullup.  It's
> been about five years since I wrote that code, I think it was just to
> protect against a stupid master.
>
> With this patch the last w1_write_bit will go logic 1, for 64 or 10 us
> before returning, then w1_gpio_set_pullup is called to enable the
> strong pullup.  What I wouldn't know is if in that last bit if the
> logic 1 would be a go up to the strong pullup, or if it would finish
> that time slot with a weak pullup and then go to a strong pullup.  I
> would have to dig into the timing specifications much more than I have
> time to right now to say what is supposed to happen.  The 18b20
> datasheet lists, "The DQ line must be switched over to the strong
> pullup within 10 us maximum after issuing any protocol that involves
> copying the E2 memory or initiates temperature conversions."  It isn't
> clear where that 10 us starts from.  You might try to dig around and
> see if that last bit written should go to weak pullup 1 or strong
> pullup 1.  It would take more changes if it should go right to a
> strong pullup.


I wasn't able to find any support for the latter statement.
It looks like the strong pull-up should be enabled *after* the last bit 
has been sent
so no need to set strong pull-up there.

However setting strong pullup for last bit makes sense just to ensure we
fit to 10us time window.

On the other hand, I didn't experienced any problems with the proposed
implementation.





>
>>>> I'm not sure why this check was there in the first place.
>>> Please add author of those lines to clarify things.
>>> This doesn't look obvious to me

--
  Evgeny

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

* Re: [PATCH 1/1] Add strong pullup emulation to w1-gpio master driver.
  2013-11-13  1:15           ` Evgeny Boger
@ 2013-11-13  4:07             ` David Fries
  2013-11-13 22:42               ` Evgeniy Polyakov
  0 siblings, 1 reply; 9+ messages in thread
From: David Fries @ 2013-11-13  4:07 UTC (permalink / raw)
  To: Evgeny Boger; +Cc: Evgeniy Polyakov, linux-kernel

On Wed, Nov 13, 2013 at 05:15:52AM +0400, Evgeny Boger wrote:
> 11/12/2013 12:01 PM, David Fries:
> >On Tue, Nov 12, 2013 at 05:07:14AM +0400, Evgeny Boger wrote:
> >>+David Fries <david@fries.net>
> >>
> >>Hi David,
> >>
> >>Would you please comment on this?
> >
> >On Mon, Nov 11, 2013 at 06:36:54PM +0400, Evgeny Boger wrote:
> >>  Strong pullup is emulated by driving pin logic high after write
> >>  command when
> >>  using tri-state push-pull GPIO.

Acked-by: David Fries <david@fries.net>

Looks good to me.

> >Not knowing the hardware involved, is driving the logic high a
> >stronger pullup than the normal weak pullup input high?  Meaning it
> >was already being left high, just with a lessor pullup and this will
> >provide a stronger one?
> 
> 
> 
> 
> Sure. The push-pull GPIO on common SoC's are usually able to provide
> up to 10 mA of current.
> 
> 
> 
> 
> >
> >On Tue, Nov 12, 2013 at 03:09:36AM +0400, Evgeniy Polyakov wrote:
> >>>+ msleep(pdata->pullup_duration);
> >>This doesn't look like a good idea - kernel will sleep for that long
> >>not doing usual w1 job
> >Not speaking for Evgeny Boger, but I'm thinking that's intended here.
> >The original strong pullup code change 6a158c0de791a81 I wrote will
> >msleep in w1_post_write when a hardware pullup isn't available, while
> >the hardware ds2490 ds9490r_set_pullup sleeps for the strong pullup
> >using spu_sleep variable.  The user requests a strong pullup for a
> >given time and any other operations on the bus will interrupt the
> >strong pullup, so locking any other operations sounds desired.
> >
> >>11/12/2013 05:03 AM, Evgeniy Polyakov:
> >>>Hi
> >>>
> >>>12.11.2013, 03:32, "Evgeny Boger" <eugenyboger@gmail.com>:
> >>>>>Why did you drop this check? It has nothing with w1-gpio driver
> >>>>This check prevents master from implementing "set_pullup"  provided it does support only "write_bit" method.
> >>>>The comment above states that
> >>>>>  w1_io.c would need to support calling set_pullup before - * the last write_bit operation of a w1_write_8 which it currently - * doesn't.
> >>>>which is kind of strange, since it describes what w1_io.c actually does support.
> >>>>
> >>>>w1_write_8 (w1_io.c:154, https://github.com/torvalds/linux/blob/master/drivers/w1/w1_io.c#L154):
> >>>>>                 for (i = 0; i < 8; ++i) {
> >>>>>                         if (i == 7)
> >>>>>                                 w1_pre_write(dev);
> >>>>>                         w1_touch_bit(dev, (byte >> i) & 0x1);
> >>>>>                 }
> >>>>It seems like w1_write_8() calls w1_pre_write(), which in turn calls set_pullup() just before the last write_bit().
> >I'm not seeing any harm in removing this check and clear
> >master->set_pullup.  It doesn't seem correct for this code to override
> >a master that claims to provide something of a stronger pullup.  It's
> >been about five years since I wrote that code, I think it was just to
> >protect against a stupid master.
> >
> >With this patch the last w1_write_bit will go logic 1, for 64 or 10 us
> >before returning, then w1_gpio_set_pullup is called to enable the
> >strong pullup.  What I wouldn't know is if in that last bit if the
> >logic 1 would be a go up to the strong pullup, or if it would finish
> >that time slot with a weak pullup and then go to a strong pullup.  I
> >would have to dig into the timing specifications much more than I have
> >time to right now to say what is supposed to happen.  The 18b20
> >datasheet lists, "The DQ line must be switched over to the strong
> >pullup within 10 us maximum after issuing any protocol that involves
> >copying the E2 memory or initiates temperature conversions."  It isn't
> >clear where that 10 us starts from.  You might try to dig around and
> >see if that last bit written should go to weak pullup 1 or strong
> >pullup 1.  It would take more changes if it should go right to a
> >strong pullup.
> 
> 
> I wasn't able to find any support for the latter statement.
> It looks like the strong pull-up should be enabled *after* the last
> bit has been sent
> so no need to set strong pull-up there.

It think that is correct, the 2480b data sheet "Strong Pullup to 5V,
armed, predefined duration", the strong pullup starts after the
timeslot of the last bit completes.

> However setting strong pullup for last bit makes sense just to ensure we
> fit to 10us time window.

They'll be just a couple function calls apart and it would complicate
the code to do so.  I think what you have is good.

> On the other hand, I didn't experienced any problems with the proposed
> implementation.

-- 
David Fries <david@fries.net>    PGP pub CB1EE8F0
http://fries.net/~david/

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

* Re: [PATCH 1/1] Add strong pullup emulation to w1-gpio master driver.
  2013-11-13  4:07             ` David Fries
@ 2013-11-13 22:42               ` Evgeniy Polyakov
  0 siblings, 0 replies; 9+ messages in thread
From: Evgeniy Polyakov @ 2013-11-13 22:42 UTC (permalink / raw)
  To: David Fries, Evgeny Boger; +Cc: linux-kernel, GregKH

Hi

13.11.2013, 08:07, "David Fries" <david@fries.net>:
>>>>   Strong pullup is emulated by driving pin logic high after write
>>>>   command when
>>>>   using tri-state push-pull GPIO.
>
> Acked-by: David Fries <david@fries.net>
>
> Looks good to me.

Ok, thank you

Acked-by: Evgeniy Polyakov <zbr@ioremap.net>

Evgeny, can you please resend the whole patch to Greg <greg@kroah.com>,
he will pick it up and push into upstream

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

* [PATCH 1/1] Add strong pullup emulation to w1-gpio master driver.
@ 2013-11-10 23:27 Evgeny Boger
  0 siblings, 0 replies; 9+ messages in thread
From: Evgeny Boger @ 2013-11-10 23:27 UTC (permalink / raw)
  To: Evgeny Boger, Evgeniy Polyakov, linux-kernel

 Strong pullup is emulated by driving pin logic high after write command when
 using tri-state push-pull GPIO.


Signed-off-by: Evgeny Boger <boger@contactless.ru>
---
 drivers/w1/masters/w1-gpio.c | 22 ++++++++++++++++++++++
 drivers/w1/w1_int.c          | 12 ------------
 include/linux/w1-gpio.h      |  1 +
 3 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
index f54ece2..cb7f89b 100644
--- a/drivers/w1/masters/w1-gpio.c
+++ b/drivers/w1/masters/w1-gpio.c
@@ -18,10 +18,31 @@
 #include <linux/of_gpio.h>
 #include <linux/err.h>
 #include <linux/of.h>
+#include <linux/delay.h>

 #include "../w1.h"
 #include "../w1_int.h"

+static u8 w1_gpio_set_pullup(void *data, int delay)
+{
+	struct w1_gpio_platform_data *pdata = data;
+
+	if (delay) {
+		pdata->pullup_duration = delay;
+	} else {
+		if (pdata->pullup_duration) {
+			gpio_direction_output(pdata->pin, 1);
+
+			msleep(pdata->pullup_duration);
+
+			gpio_direction_input(pdata->pin);
+		}
+		pdata->pullup_duration = 0;
+	}
+
+	return 0;
+}
+
 static void w1_gpio_write_bit_dir(void *data, u8 bit)
 {
	struct w1_gpio_platform_data *pdata = data;
@@ -125,6 +146,7 @@ static int w1_gpio_probe(struct platform_device *pdev)
	} else {
		gpio_direction_input(pdata->pin);
		master->write_bit = w1_gpio_write_bit_dir;
+		master->set_pullup = w1_gpio_set_pullup;
	}

	err = w1_add_master_device(master);
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index 5a98649..590bd8a 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -117,18 +117,6 @@ int w1_add_master_device(struct w1_bus_master *master)
		printk(KERN_ERR "w1_add_master_device: invalid function set\n");
		return(-EINVAL);
         }
-	/* While it would be electrically possible to make a device that
-	 * generated a strong pullup in bit bang mode, only hardware that
-	 * controls 1-wire time frames are even expected to support a strong
-	 * pullup.  w1_io.c would need to support calling set_pullup before
-	 * the last write_bit operation of a w1_write_8 which it currently
-	 * doesn't.
-	 */
-	if (!master->write_byte && !master->touch_bit && master->set_pullup) {
-		printk(KERN_ERR "w1_add_master_device: set_pullup requires "
-			"write_byte or touch_bit, disabling\n");
-		master->set_pullup = NULL;
-	}

	/* Lock until the device is added (or not) to w1_masters. */
	mutex_lock(&w1_mlock);
diff --git a/include/linux/w1-gpio.h b/include/linux/w1-gpio.h
index 065e3ae..d58594a 100644
--- a/include/linux/w1-gpio.h
+++ b/include/linux/w1-gpio.h
@@ -20,6 +20,7 @@ struct w1_gpio_platform_data {
	unsigned int is_open_drain:1;
	void (*enable_external_pullup)(int enable);
	unsigned int ext_pullup_enable_pin;
+	unsigned int pullup_duration;
 };

 #endif /* _LINUX_W1_GPIO_H */
--
1.8.1.2

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

end of thread, other threads:[~2013-11-13 22:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-11 14:36 [PATCH 1/1] Add strong pullup emulation to w1-gpio master driver Evgeny Boger
2013-11-11 23:09 ` Evgeniy Polyakov
     [not found]   ` <5281691F.4060604@gmail.com>
2013-11-12  1:03     ` Evgeniy Polyakov
2013-11-12  1:07       ` Evgeny Boger
2013-11-12  8:01         ` David Fries
2013-11-13  1:15           ` Evgeny Boger
2013-11-13  4:07             ` David Fries
2013-11-13 22:42               ` Evgeniy Polyakov
  -- strict thread matches above, loose matches on Subject: below --
2013-11-10 23:27 Evgeny Boger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.