linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Regulator] Request for clarification - GPIO controlled regulator, USB VBUS,
@ 2017-10-03 16:58 Łukasz Majewski
  2017-10-03 19:16 ` Dmitry Torokhov
  2017-10-04 10:32 ` Mark Brown
  0 siblings, 2 replies; 8+ messages in thread
From: Łukasz Majewski @ 2017-10-03 16:58 UTC (permalink / raw)
  To: linux-input; +Cc: linux-kernel@vger.kernel.org, Liam Girdwood, Mark Brown

Dear All,

Maybe somebody could shed some light to following issue:

On my setup I do have USB connected touchscreen powered from VBUS.

The VBUS power is controlled by a GPIO pin, which in turn is governed by 
regulator API:

	reg_usbh1_vbus: usb-h1-vbus {
		compatible = "regulator-fixed";
		gpio = <&gpio3 31 GPIO_ACTIVE_LOW>;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_usbh1_vbus>;
		regulator-name = "usb_h1_vbus";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		regulator-settling-time-us = <100000>;
	};


This regulator is then passed to USB controller:

&usbh1 {
	vbus-supply = <&reg_usbh1_vbus>;

}

The regulator API starts VBUS -> USB host get info about the VBUS 
present and starts enumeration of the USB device.


I would like to ask if there is any recommended way to remove VBUS power 
and have a way to force from user space the touchscreen (re-)enumeration?

As fair as I know the Regulator API is RO on purpose, so I cannot toggle 
vbus from there.

I could use hacks presented here (the userspace-regulator API):
https://patchwork.ozlabs.org/patch/374912/
https://lkml.org/lkml/2014/7/30/357

but for some reason they did not find the way to the upstream. Also it 
seems like such approach is for testing, not for production system.


I could write a "dummy" regulator driver, which would export control API 
to /dev/sys/proc.
Something like:
http://elixir.free-electrons.com/linux/latest/source/drivers/usb/phy/phy-fsl-usb.c

(but with opposite way).

or ./drivers/input/misc/regulator-haptic.c


I've also tried the "usb" power control tricks;

echo "0" > /sys/bus/usb/devices/usb1/power/autosuspend_delay_ms
echo "auto" > /sys/bus/usb/devices/usb1/power/control

But without any effect (probably because of above dependencies).



Have I overlooked something? Maybe there is any other mainline code, 
which I could reuse?


My goal is to reuse as much as possible from ML and avoid developing any 
new code :-)

Thanks in advance,

-- 
Best regards.

Łukasz Majewski

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

* Re: [Regulator] Request for clarification - GPIO controlled regulator, USB VBUS,
  2017-10-03 16:58 [Regulator] Request for clarification - GPIO controlled regulator, USB VBUS, Łukasz Majewski
@ 2017-10-03 19:16 ` Dmitry Torokhov
  2017-10-03 20:25   ` Łukasz Majewski
  2017-10-04 10:32 ` Mark Brown
  1 sibling, 1 reply; 8+ messages in thread
From: Dmitry Torokhov @ 2017-10-03 19:16 UTC (permalink / raw)
  To: Łukasz Majewski
  Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	Liam Girdwood, Mark Brown

Hi Łukasz,

On Tue, Oct 3, 2017 at 9:58 AM, Łukasz Majewski <l.majewski@majess.pl> wrote:
> Dear All,
>
> Maybe somebody could shed some light to following issue:
>
> On my setup I do have USB connected touchscreen powered from VBUS.
>
> The VBUS power is controlled by a GPIO pin, which in turn is governed by
> regulator API:
>
>         reg_usbh1_vbus: usb-h1-vbus {
>                 compatible = "regulator-fixed";
>                 gpio = <&gpio3 31 GPIO_ACTIVE_LOW>;
>                 pinctrl-names = "default";
>                 pinctrl-0 = <&pinctrl_usbh1_vbus>;
>                 regulator-name = "usb_h1_vbus";
>                 regulator-min-microvolt = <5000000>;
>                 regulator-max-microvolt = <5000000>;
>                 regulator-settling-time-us = <100000>;
>         };
>
>
> This regulator is then passed to USB controller:
>
> &usbh1 {
>         vbus-supply = <&reg_usbh1_vbus>;
>
> }
>
> The regulator API starts VBUS -> USB host get info about the VBUS present
> and starts enumeration of the USB device.
>
>
> I would like to ask if there is any recommended way to remove VBUS power and
> have a way to force from user space the touchscreen (re-)enumeration?
>
> As fair as I know the Regulator API is RO on purpose, so I cannot toggle
> vbus from there.
>
> I could use hacks presented here (the userspace-regulator API):
> https://patchwork.ozlabs.org/patch/374912/
> https://lkml.org/lkml/2014/7/30/357
>
> but for some reason they did not find the way to the upstream. Also it seems
> like such approach is for testing, not for production system.
>
>
> I could write a "dummy" regulator driver, which would export control API to
> /dev/sys/proc.
> Something like:
> http://elixir.free-electrons.com/linux/latest/source/drivers/usb/phy/phy-fsl-usb.c
>
> (but with opposite way).
>
> or ./drivers/input/misc/regulator-haptic.c
>
>
> I've also tried the "usb" power control tricks;
>
> echo "0" > /sys/bus/usb/devices/usb1/power/autosuspend_delay_ms
> echo "auto" > /sys/bus/usb/devices/usb1/power/control
>
> But without any effect (probably because of above dependencies).
>
>
>
> Have I overlooked something? Maybe there is any other mainline code, which I
> could reuse?
>
>
> My goal is to reuse as much as possible from ML and avoid developing any new
> code :-)
>

Please start from the beginning: it is not quite clear why you want
the touchscreen to be re-enumerated.

Thanks.

-- 
Dmitry

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

* Re: [Regulator] Request for clarification - GPIO controlled regulator, USB VBUS,
  2017-10-03 19:16 ` Dmitry Torokhov
@ 2017-10-03 20:25   ` Łukasz Majewski
  0 siblings, 0 replies; 8+ messages in thread
From: Łukasz Majewski @ 2017-10-03 20:25 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	Liam Girdwood, Mark Brown

Hi Dmitry,

> Hi Łukasz,
> 
> On Tue, Oct 3, 2017 at 9:58 AM, Łukasz Majewski <l.majewski@majess.pl> wrote:
>> Dear All,
>>
>> Maybe somebody could shed some light to following issue:
>>
>> On my setup I do have USB connected touchscreen powered from VBUS.
>>
>> The VBUS power is controlled by a GPIO pin, which in turn is governed by
>> regulator API:
>>
>>          reg_usbh1_vbus: usb-h1-vbus {
>>                  compatible = "regulator-fixed";
>>                  gpio = <&gpio3 31 GPIO_ACTIVE_LOW>;
>>                  pinctrl-names = "default";
>>                  pinctrl-0 = <&pinctrl_usbh1_vbus>;
>>                  regulator-name = "usb_h1_vbus";
>>                  regulator-min-microvolt = <5000000>;
>>                  regulator-max-microvolt = <5000000>;
>>                  regulator-settling-time-us = <100000>;
>>          };
>>
>>
>> This regulator is then passed to USB controller:
>>
>> &usbh1 {
>>          vbus-supply = <&reg_usbh1_vbus>;
>>
>> }
>>
>> The regulator API starts VBUS -> USB host get info about the VBUS present
>> and starts enumeration of the USB device.
>>
>>
>> I would like to ask if there is any recommended way to remove VBUS power and
>> have a way to force from user space the touchscreen (re-)enumeration?
>>
>> As fair as I know the Regulator API is RO on purpose, so I cannot toggle
>> vbus from there.
>>
>> I could use hacks presented here (the userspace-regulator API):
>> https://patchwork.ozlabs.org/patch/374912/
>> https://lkml.org/lkml/2014/7/30/357
>>
>> but for some reason they did not find the way to the upstream. Also it seems
>> like such approach is for testing, not for production system.
>>
>>
>> I could write a "dummy" regulator driver, which would export control API to
>> /dev/sys/proc.
>> Something like:
>> http://elixir.free-electrons.com/linux/latest/source/drivers/usb/phy/phy-fsl-usb.c
>>
>> (but with opposite way).
>>
>> or ./drivers/input/misc/regulator-haptic.c
>>
>>
>> I've also tried the "usb" power control tricks;
>>
>> echo "0" > /sys/bus/usb/devices/usb1/power/autosuspend_delay_ms
>> echo "auto" > /sys/bus/usb/devices/usb1/power/control
>>
>> But without any effect (probably because of above dependencies).
>>
>>
>>
>> Have I overlooked something? Maybe there is any other mainline code, which I
>> could reuse?
>>
>>
>> My goal is to reuse as much as possible from ML and avoid developing any new
>> code :-)
>>
> 
> Please start from the beginning: it is not quite clear why you want
> the touchscreen to be re-enumerated.

The above setup generally works.

However, from time to time I do encounter some HID multi-touch driver 
initialization errors, which render the touchscreen unusable - e.g:

usb 1-1: input irq status -75 received
usb 1-1: reset low-speed USB device number 2 using ci_hdrc
expected 16 bytes, got -1

or

hid-generic 0003:19E2:2533.0002: unknown main item tag 0x0
hid-generic 0003:19E2:2533.0002: unknown main item tag 0x0
hid-generic 0003:19E2:2533.0002: unbalanced collection at end of report 
description
hid-generic: probe of 0003:19E2:2533.0002 failed with error -22


I've added 100 ms settle time for the VBUS regulator, but I'm not sure 
if it will fix this issue (I'm going to inspect VBUS voltage with 
oscilloscope).

Since I do have above errors, I thought that it would be feasible to 
have a "mean" to re-set VBUS voltage and force enumeration of the device.

I'm quite curious how USB connected touchscreens are controlled with 
USB's VBUS not accessible from user-space out of the box?

> 
> Thanks.
> 


-- 
Best regards.

Łukasz Majewski

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

* Re: [Regulator] Request for clarification - GPIO controlled regulator, USB VBUS,
  2017-10-03 16:58 [Regulator] Request for clarification - GPIO controlled regulator, USB VBUS, Łukasz Majewski
  2017-10-03 19:16 ` Dmitry Torokhov
@ 2017-10-04 10:32 ` Mark Brown
  2017-10-04 10:45   ` Łukasz Majewski
  1 sibling, 1 reply; 8+ messages in thread
From: Mark Brown @ 2017-10-04 10:32 UTC (permalink / raw)
  To: Łukasz Majewski
  Cc: linux-input, linux-kernel@vger.kernel.org, Liam Girdwood

[-- Attachment #1: Type: text/plain, Size: 481 bytes --]

On Tue, Oct 03, 2017 at 06:58:00PM +0200, Łukasz Majewski wrote:

> Have I overlooked something? Maybe there is any other mainline code, which I
> could reuse?

No, we don't support randomly toggling power for devices without their
cooperation - it's not generally going to end well.  The reason it's
difficult to do this is that it's a bad idea.  Perhaps this is something
that could be implemented generically for USB as it's a hotpluggable bus
but I'm not convinced.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [Regulator] Request for clarification - GPIO controlled regulator, USB VBUS,
  2017-10-04 10:32 ` Mark Brown
@ 2017-10-04 10:45   ` Łukasz Majewski
  2017-10-04 11:27     ` Mark Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Łukasz Majewski @ 2017-10-04 10:45 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-input, linux-kernel@vger.kernel.org, Liam Girdwood

Hi Mark,

Thank you for your reply.

> On Tue, Oct 03, 2017 at 06:58:00PM +0200, Łukasz Majewski wrote:
> 
>> Have I overlooked something? Maybe there is any other mainline code, which I
>> could reuse?
> 
> No, we don't support randomly toggling power for devices without their
> cooperation - it's not generally going to end well.  The reason it's
> difficult to do this is that it's a bad idea.

I do understand the rationale. No issues with this.

>  Perhaps this is something
> that could be implemented generically for USB as it's a hotpluggable bus

In this case we use VBUS as a power supply voltage. The problem with 
regulator API used in this case is that we enable it on boot-up, but 
then we cannot "symulate hotplug" anymore.

> but I'm not convinced.
> 

Maybe, I can look into USB driver and see if the VBUS is manageable from 
there (so I could add some sysfs entry to control it if needed).


-- 
Best regards.

Łukasz Majewski

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

* Re: [Regulator] Request for clarification - GPIO controlled regulator, USB VBUS,
  2017-10-04 10:45   ` Łukasz Majewski
@ 2017-10-04 11:27     ` Mark Brown
  2017-10-04 11:54       ` Łukasz Majewski
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Brown @ 2017-10-04 11:27 UTC (permalink / raw)
  To: Łukasz Majewski
  Cc: linux-input, linux-kernel@vger.kernel.org, Liam Girdwood

[-- Attachment #1: Type: text/plain, Size: 592 bytes --]

On Wed, Oct 04, 2017 at 12:45:39PM +0200, Łukasz Majewski wrote:
> > On Tue, Oct 03, 2017 at 06:58:00PM +0200, Łukasz Majewski wrote:

> >  Perhaps this is something
> > that could be implemented generically for USB as it's a hotpluggable bus

> In this case we use VBUS as a power supply voltage. The problem with
> regulator API used in this case is that we enable it on boot-up, but then we
> cannot "symulate hotplug" anymore.

I don't really understand what you mean there, sorry.  The majority of
regulator usage is to supply power, use as reference voltages or
similar.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [Regulator] Request for clarification - GPIO controlled regulator, USB VBUS,
  2017-10-04 11:27     ` Mark Brown
@ 2017-10-04 11:54       ` Łukasz Majewski
  2017-10-04 14:57         ` Mark Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Łukasz Majewski @ 2017-10-04 11:54 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-input, linux-kernel@vger.kernel.org, Liam Girdwood

Hi Mark,

> On Wed, Oct 04, 2017 at 12:45:39PM +0200, Łukasz Majewski wrote:
>>> On Tue, Oct 03, 2017 at 06:58:00PM +0200, Łukasz Majewski wrote:
> 
>>>   Perhaps this is something
>>> that could be implemented generically for USB as it's a hotpluggable bus
> 
>> In this case we use VBUS as a power supply voltage. The problem with
>> regulator API used in this case is that we enable it on boot-up, but then we
>> cannot "symulate hotplug" anymore.
> 
> I don't really understand what you mean there, sorry. 

I do use "regulator-fixed" to control VBUS.

The USB driver used regulator_enable/disable to supply power of VBUS.


What I do want to achieve:

For testing purpose I would like to enable/disable this supply (VBUS) 
and force/restart of re-enumeration.

> The majority of
> regulator usage is to supply power, use as reference voltages or
> similar.
> 


-- 
Best regards.

Łukasz Majewski

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

* Re: [Regulator] Request for clarification - GPIO controlled regulator, USB VBUS,
  2017-10-04 11:54       ` Łukasz Majewski
@ 2017-10-04 14:57         ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2017-10-04 14:57 UTC (permalink / raw)
  To: Łukasz Majewski
  Cc: linux-input, linux-kernel@vger.kernel.org, Liam Girdwood

[-- Attachment #1: Type: text/plain, Size: 881 bytes --]

On Wed, Oct 04, 2017 at 01:54:49PM +0200, Łukasz Majewski wrote:
> > On Wed, Oct 04, 2017 at 12:45:39PM +0200, Łukasz Majewski wrote:
> > > > On Tue, Oct 03, 2017 at 06:58:00PM +0200, Łukasz Majewski wrote:

> > > In this case we use VBUS as a power supply voltage. The problem with
> > > regulator API used in this case is that we enable it on boot-up, but then we
> > > cannot "symulate hotplug" anymore.

> > I don't really understand what you mean there, sorry.

> I do use "regulator-fixed" to control VBUS.

> The USB driver used regulator_enable/disable to supply power of VBUS.

> What I do want to achieve:

> For testing purpose I would like to enable/disable this supply (VBUS) and
> force/restart of re-enumeration.

I'm having a hard time connecting that with what you wrote above or with
the suggestion to do this in the USB framework, sorry.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2017-10-04 14:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-03 16:58 [Regulator] Request for clarification - GPIO controlled regulator, USB VBUS, Łukasz Majewski
2017-10-03 19:16 ` Dmitry Torokhov
2017-10-03 20:25   ` Łukasz Majewski
2017-10-04 10:32 ` Mark Brown
2017-10-04 10:45   ` Łukasz Majewski
2017-10-04 11:27     ` Mark Brown
2017-10-04 11:54       ` Łukasz Majewski
2017-10-04 14:57         ` Mark Brown

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