Re: [PATCH v8] usb:serial:pl2303: add GPIOs interface on PL2303

2014-09-10 Thread Johan Hovold
On Sun, Aug 31, 2014 at 11:24:56PM +0800, Wang YanQing wrote:
 PL2303 USB Serial devices may has GPIOs, this patch add
 basic PL2303 gpio support.
 
 Known issue:
 If gpios are in use(export to userspace through sysfs interface, etc),
 then call pl2303_release(unplug usb-serial convertor, modprobe -r, etc),
 will cause trouble, so we need to make sure there is no gpio user before
 call pl2303_release.
 
 Signed-off-by: Wang YanQing udkni...@gmail.com
 ---
  Note: I sniffed office HXD gpio test program to get 
gpios control protocol with PL2303 RA, so I only
test it with PL2303 RA and HXA, I don't have HXD,
but because it is *office* HXD gpio test program,
so if it doesn't work with HXD, I will feel surprise.

Nice.

That should be ok as long as you can test it with RA and the official
driver treats them the same (and perhaps someone else could do the HXD
testing?).

 
  Changes
  v7-v8:
  1: add support for four dedicated gpios on HXD and RA
  2: fix problem reported by Johan Hovold in v7
  3: fix checkpatch.pl's warning
 
  v6-v7:
  1: add generic gpio support interfaces for pl2303 USB Serial devices
 in pl2303_type_data and pl2303_serial_private suggested by Andreas Mohr.
  2: drop different label names for different pl2303 instance suggested by 
 Johan Hovold.
  3: fix missing lock corrected by Johan Hovold.
  4: use prefix pl2303hx_gpio instead pl2303_gpio, pl2303_gpio is over generic 
 for current code,
 and now we move gpio_startup|gpio_release into type-specified data 
 structure, so pl2303hx_gpio
 is a better prefix.
  5: make words in Kconfig a little more useful and clarified.
  6: many misc code quality enhancement suggested by Johan Hovold.
 
  v5-v6:
  1: fix typo error in Kconfig reported by Andreas Mohr 
  2: add const qulification to gpio_dir_mask and gpio_value_mask suggested by 
 Andreas Mohr
 
  v4-v5:
  1: fix gpio_chip.lable been overwrited by template_chip. 
  2: use idr to manage minor instead of crude monotonous atomic increment. 
 
  v3-v4:
  1: fix missing static for gpio_dir_mask and gpio_value_mask 
  2: reduce unneeded compile macro defined suggested by 
 gno...@lxorguk.ukuu.org.uk 
  3: use true instead of 1 corrected by Linus Walleij
  4: ignore return value of gpiochip_remove suggested by Linus Walleij
  5: fix multi gpio_chips registered by pl2303 can't be distinguished in 
 kernel space. 
 
  v2-v3:
  1: fix errors and warnings reported by Daniele Forsi checked with 
 checkpatch.pl 
  2: fix missing GPIOLIB dependence in Kconfig 
  3: fix pl2303_gpio_get can't work 
 
  v1-v2:  
  1:drop gpio-pl2303.c and relation stuff 
  2:hang gpio stuff off of pl2303.c  
 
  drivers/usb/serial/Kconfig  |  11 ++
  drivers/usb/serial/pl2303.c | 250 
 
  2 files changed, 261 insertions(+)
 
 diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
 index 3ce5c74..b4e0cf9 100644
 --- a/drivers/usb/serial/Kconfig
 +++ b/drivers/usb/serial/Kconfig
 @@ -516,6 +516,17 @@ config USB_SERIAL_PL2303
 To compile this driver as a module, choose M here: the
 module will be called pl2303.
  
 +config USB_SERIAL_PL2303_GPIO
 + bool USB Prolific 2303 Single Port GPIOs support
 + depends on USB_SERIAL_PL2303  GPIOLIB
 + ---help---
 +   Say Y here if you want to use GPIOs on PL2303 USB Serial single port
 +   adapter from Prolific.
 +
 +   It supports 2 dedicated GPIOs on PL2303HXA, 4 dedicated GPIOs on
 +   PL2303HXD and PL2303RA currently.
 +   If unsure, say N.
 +
  config USB_SERIAL_OTI6858
   tristate USB Ours Technology Inc. OTi-6858 USB To RS232 Bridge 
 Controller
   help
 diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
 index e9bad92..a3f8411 100644
 --- a/drivers/usb/serial/pl2303.c
 +++ b/drivers/usb/serial/pl2303.c
 @@ -28,6 +28,8 @@
  #include linux/usb.h
  #include linux/usb/serial.h
  #include asm/unaligned.h
 +#include linux/gpio.h
 +#include linux/mutex.h
  #include pl2303.h
  
  
 @@ -132,6 +134,22 @@ MODULE_DEVICE_TABLE(usb, id_table);
  #define UART_OVERRUN_ERROR   0x40
  #define UART_CTS 0x80
  
 +#define HXD_GPIO_01_CTRL 0x0001
 +#define HXD_GPIO_01_VALUE0x0081
 +#define HXD_GPIO_23_DIR_CTRL 0x0c0c
 +#define HXD_GPIO_23_VALUE_CTRL   0x0d0d
 +#define HXD_GPIO_23_VALUE0x8d8d

These three new wValues look odd. Perhaps the most-significant byte is
ignored? Doesn't matter. :)

I would also suggest naming these registers differently, for example:

PL2303_GPIO_01_CTRL
PL2303_GPIO_01_STATUS
PL2303_GPIO_23_OUTPUT_ENABLE
PL2303_GPIO_23_OUTPUT
PL2303_GPIO_23_STATUS

in order to reflect the different semantics for the two sets of
registers (and to use more standardised names).

 +
 +#define HXD_GPIO0_DIR_MASK   0x10
 +#define HXD_GPIO1_DIR_MASK   0x20
 +#define HXD_GPIO2_DIR_MASK   

Re: [PATCH v8] usb:serial:pl2303: add GPIOs interface on PL2303

2014-09-09 Thread Johan Hovold
On Fri, Sep 05, 2014 at 09:30:11AM +0800, Wang YanQing wrote:
 On Thu, Sep 04, 2014 at 06:44:31PM +0200, Benjamin Henrion wrote:
  On Thu, Sep 4, 2014 at 6:14 PM, Benjamin Henrion zoo...@gmail.com wrote:
   I have subscribed to the lkml.
  
   Can you make me a favour, send me your email as you posted on the LKML
   in mbox format attached to an email?
  
   I am trying to reply to it, but I cannot find an mbox archive, outside
   of gmane which rewrites all the email addresses.
  
   Otherwise, I made a page here:
  
   http://www.zoobab.com/pl2303hxd-gpio
  
   I will also try with other adapters to see if the 2 GPIOs show up.
  
   Any idea how to test the GPIO sysfs speed?
  
  Also tested with an HXA laying around, I could export the 2 GPIOS in
  /sys/class/gpio, but I could not change the status of the pins via
  echo.
  
  Any idea why?
 
 It is strange, I have tested again with my two HXA adapters, they work well.
 How do you test? check cat value or check voltage change? I check cat value,
 and they work good.

So you haven't verified that the voltage actually changes?

Johan
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8] usb:serial:pl2303: add GPIOs interface on PL2303

2014-09-09 Thread Wang YanQing
On Tue, Sep 09, 2014 at 12:08:56PM +0200, Johan Hovold wrote:
 On Fri, Sep 05, 2014 at 09:30:11AM +0800, Wang YanQing wrote:
  On Thu, Sep 04, 2014 at 06:44:31PM +0200, Benjamin Henrion wrote:
   On Thu, Sep 4, 2014 at 6:14 PM, Benjamin Henrion zoo...@gmail.com wrote:
I have subscribed to the lkml.
   
Can you make me a favour, send me your email as you posted on the LKML
in mbox format attached to an email?
   
I am trying to reply to it, but I cannot find an mbox archive, outside
of gmane which rewrites all the email addresses.
   
Otherwise, I made a page here:
   
http://www.zoobab.com/pl2303hxd-gpio
   
I will also try with other adapters to see if the 2 GPIOs show up.
   
Any idea how to test the GPIO sysfs speed?
   
   Also tested with an HXA laying around, I could export the 2 GPIOS in
   /sys/class/gpio, but I could not change the status of the pins via
   echo.
   
   Any idea why?
  
  It is strange, I have tested again with my two HXA adapters, they work well.
  How do you test? check cat value or check voltage change? I check cat value,
  and they work good.
 
 So you haven't verified that the voltage actually changes?
 
 Johan

I have verified the voltage actually changes in previous patch version,
but I haven't verified that with v8.
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8] usb:serial:pl2303: add GPIOs interface on PL2303

2014-09-09 Thread Johan Hovold
On Tue, Sep 09, 2014 at 06:21:31PM +0800, Wang YanQing wrote:
 On Tue, Sep 09, 2014 at 12:08:56PM +0200, Johan Hovold wrote:
  On Fri, Sep 05, 2014 at 09:30:11AM +0800, Wang YanQing wrote:
   On Thu, Sep 04, 2014 at 06:44:31PM +0200, Benjamin Henrion wrote:
On Thu, Sep 4, 2014 at 6:14 PM, Benjamin Henrion zoo...@gmail.com 
wrote:
 I have subscribed to the lkml.

 Can you make me a favour, send me your email as you posted on the LKML
 in mbox format attached to an email?

 I am trying to reply to it, but I cannot find an mbox archive, outside
 of gmane which rewrites all the email addresses.

 Otherwise, I made a page here:

 http://www.zoobab.com/pl2303hxd-gpio

 I will also try with other adapters to see if the 2 GPIOs show up.

 Any idea how to test the GPIO sysfs speed?

Also tested with an HXA laying around, I could export the 2 GPIOS in
/sys/class/gpio, but I could not change the status of the pins via
echo.

Any idea why?
   
   It is strange, I have tested again with my two HXA adapters, they work 
   well.
   How do you test? check cat value or check voltage change? I check cat 
   value,
   and they work good.
  
  So you haven't verified that the voltage actually changes?
  
  Johan
 
 I have verified the voltage actually changes in previous patch version,
 but I haven't verified that with v8.

Ok, good. I'll get back to you with some comments on v8 shortly.

Thanks,
Johan
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8] usb:serial:pl2303: add GPIOs interface on PL2303

2014-09-09 Thread Johan Hovold
On Tue, Sep 09, 2014 at 12:43:56PM +0200, Johan Hovold wrote:
 On Tue, Sep 09, 2014 at 06:21:31PM +0800, Wang YanQing wrote:
  On Tue, Sep 09, 2014 at 12:08:56PM +0200, Johan Hovold wrote:
   On Fri, Sep 05, 2014 at 09:30:11AM +0800, Wang YanQing wrote:
On Thu, Sep 04, 2014 at 06:44:31PM +0200, Benjamin Henrion wrote:
 On Thu, Sep 4, 2014 at 6:14 PM, Benjamin Henrion zoo...@gmail.com 
 wrote:
  I have subscribed to the lkml.
 
  Can you make me a favour, send me your email as you posted on the 
  LKML
  in mbox format attached to an email?
 
  I am trying to reply to it, but I cannot find an mbox archive, 
  outside
  of gmane which rewrites all the email addresses.
 
  Otherwise, I made a page here:
 
  http://www.zoobab.com/pl2303hxd-gpio
 
  I will also try with other adapters to see if the 2 GPIOs show up.
 
  Any idea how to test the GPIO sysfs speed?
 
 Also tested with an HXA laying around, I could export the 2 GPIOS in
 /sys/class/gpio, but I could not change the status of the pins via
 echo.
 
 Any idea why?

It is strange, I have tested again with my two HXA adapters, they work 
well.
How do you test? check cat value or check voltage change? I check cat 
value,
and they work good.
   
   So you haven't verified that the voltage actually changes?
   
   Johan
  
  I have verified the voltage actually changes in previous patch version,
  but I haven't verified that with v8.
 
 Ok, good. I'll get back to you with some comments on v8 shortly.

Wait a minute. You restructured the driver, added support for two new
gpios as well as another device type, so you need to verify the voltage
on the pins (on both device types) as well.

Thanks,
Johan
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8] usb:serial:pl2303: add GPIOs interface on PL2303

2014-09-09 Thread Wang YanQing
On Tue, Sep 09, 2014 at 04:02:04PM +0200, Johan Hovold wrote:
 On Tue, Sep 09, 2014 at 12:43:56PM +0200, Johan Hovold wrote:
  On Tue, Sep 09, 2014 at 06:21:31PM +0800, Wang YanQing wrote:
   On Tue, Sep 09, 2014 at 12:08:56PM +0200, Johan Hovold wrote:
On Fri, Sep 05, 2014 at 09:30:11AM +0800, Wang YanQing wrote:
 On Thu, Sep 04, 2014 at 06:44:31PM +0200, Benjamin Henrion wrote:
  On Thu, Sep 4, 2014 at 6:14 PM, Benjamin Henrion zoo...@gmail.com 
  wrote:
   I have subscribed to the lkml.
  
   Can you make me a favour, send me your email as you posted on the 
   LKML
   in mbox format attached to an email?
  
   I am trying to reply to it, but I cannot find an mbox archive, 
   outside
   of gmane which rewrites all the email addresses.
  
   Otherwise, I made a page here:
  
   http://www.zoobab.com/pl2303hxd-gpio
  
   I will also try with other adapters to see if the 2 GPIOs show up.
  
   Any idea how to test the GPIO sysfs speed?
  
  Also tested with an HXA laying around, I could export the 2 GPIOS in
  /sys/class/gpio, but I could not change the status of the pins via
  echo.
  
  Any idea why?
 
 It is strange, I have tested again with my two HXA adapters, they 
 work well.
 How do you test? check cat value or check voltage change? I check cat 
 value,
 and they work good.

So you haven't verified that the voltage actually changes?

Johan
   
   I have verified the voltage actually changes in previous patch version,
   but I haven't verified that with v8.
  
  Ok, good. I'll get back to you with some comments on v8 shortly.
 
 Wait a minute. You restructured the driver, added support for two new
 gpios as well as another device type, so you need to verify the voltage
 on the pins (on both device types) as well.

Benjamin Henrion had verified voltage on pins of HXD, see

http://www.zoobab.com/pl2303hxd-gpio

Sorry I don't have pinout version of PL2303 RA, so I can't verified voltage on 
it,
I only can test it by echo  cat.

Thanks.
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8] usb:serial:pl2303: add GPIOs interface on PL2303

2014-09-09 Thread Wang YanQing
On Tue, Sep 09, 2014 at 04:02:04PM +0200, Johan Hovold wrote:
 On Tue, Sep 09, 2014 at 12:43:56PM +0200, Johan Hovold wrote:
  On Tue, Sep 09, 2014 at 06:21:31PM +0800, Wang YanQing wrote:
   On Tue, Sep 09, 2014 at 12:08:56PM +0200, Johan Hovold wrote:
On Fri, Sep 05, 2014 at 09:30:11AM +0800, Wang YanQing wrote:
 On Thu, Sep 04, 2014 at 06:44:31PM +0200, Benjamin Henrion wrote:
  On Thu, Sep 4, 2014 at 6:14 PM, Benjamin Henrion zoo...@gmail.com 
  wrote:
   I have subscribed to the lkml.
  
   Can you make me a favour, send me your email as you posted on the 
   LKML
   in mbox format attached to an email?
  
   I am trying to reply to it, but I cannot find an mbox archive, 
   outside
   of gmane which rewrites all the email addresses.
  
   Otherwise, I made a page here:
  
   http://www.zoobab.com/pl2303hxd-gpio
  
   I will also try with other adapters to see if the 2 GPIOs show up.
  
   Any idea how to test the GPIO sysfs speed?
  
  Also tested with an HXA laying around, I could export the 2 GPIOS in
  /sys/class/gpio, but I could not change the status of the pins via
  echo.
  
  Any idea why?
 
 It is strange, I have tested again with my two HXA adapters, they 
 work well.
 How do you test? check cat value or check voltage change? I check cat 
 value,
 and they work good.

So you haven't verified that the voltage actually changes?

Johan
   
   I have verified the voltage actually changes in previous patch version,
   but I haven't verified that with v8.
  
  Ok, good. I'll get back to you with some comments on v8 shortly.
 
 Wait a minute. You restructured the driver, added support for two new
 gpios as well as another device type, so you need to verify the voltage
 on the pins (on both device types) as well.

Benjamin Henrion had verified voltage on pins of HXD, see

http://www.zoobab.com/pl2303hxd-gpio

Sorry I don't have pinout version of PL2303 RA, so I can't verified voltage on 
it,
I only can test it by echo  cat.

Thanks.
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8] usb:serial:pl2303: add GPIOs interface on PL2303

2014-09-05 Thread Linus Walleij
On Thu, Sep 4, 2014 at 11:57 PM, Benjamin Henrion zoo...@gmail.com wrote:
 On Thu, Sep 4, 2014 at 7:35 PM, Wang YanQing udkni...@gmail.com wrote:
 On Sun, Aug 31, 2014 at 11:24:56PM +0800, Wang YanQing wrote:
 PL2303 USB Serial devices may has GPIOs, this patch add
 basic PL2303 gpio support.

 Known issue:
 If gpios are in use(export to userspace through sysfs interface, etc),
 then call pl2303_release(unplug usb-serial convertor, modprobe -r, etc),
 will cause trouble, so we need to make sure there is no gpio user before
 call pl2303_release.

 Signed-off-by: Wang YanQing udkni...@gmail.com
 ---
  Note: I sniffed office HXD gpio test program to get
gpios control protocol with PL2303 RA, so I only
test it with PL2303 RA and HXA, I don't have HXD,
but because it is *office* HXD gpio test program,
so if it doesn't work with HXD, I will feel surprise.

 I can confirm your patch is working fine on the HXD:

 http://www.zoobab.com/pl2303hxd-gpio

 I am still hunting for a simple C program to test the speed of the
 GPIOs and sysfs, if you have a good reference.

The exercise of the GPIO sysfs interface should be discouraged.
I would put emphasis on in-kernel tests and working on a better
userspace GPIO interface than the sysfs thing.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8] usb:serial:pl2303: add GPIOs interface on PL2303

2014-09-04 Thread Linus Walleij
On Sun, Aug 31, 2014 at 5:24 PM, Wang YanQing udkni...@gmail.com wrote:

 PL2303 USB Serial devices may has GPIOs, this patch add
 basic PL2303 gpio support.

 Known issue:
 If gpios are in use(export to userspace through sysfs interface, etc),
 then call pl2303_release(unplug usb-serial convertor, modprobe -r, etc),
 will cause trouble, so we need to make sure there is no gpio user before
 call pl2303_release.

 Signed-off-by: Wang YanQing udkni...@gmail.com
 ---
  Note: I sniffed office HXD gpio test program to get
gpios control protocol with PL2303 RA, so I only
test it with PL2303 RA and HXA, I don't have HXD,
but because it is *office* HXD gpio test program,
so if it doesn't work with HXD, I will feel surprise.

  Changes
  v7-v8:
  1: add support for four dedicated gpios on HXD and RA
  2: fix problem reported by Johan Hovold in v7
  3: fix checkpatch.pl's warning

This has been looking nice from the GPIO side of things
for a while so:
Acked-by: Linus Walleij linus.wall...@linaro.org

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8] usb:serial:pl2303: add GPIOs interface on PL2303

2014-09-04 Thread Wang YanQing
On Sun, Aug 31, 2014 at 11:24:56PM +0800, Wang YanQing wrote:
 PL2303 USB Serial devices may has GPIOs, this patch add
 basic PL2303 gpio support.
 
 Known issue:
 If gpios are in use(export to userspace through sysfs interface, etc),
 then call pl2303_release(unplug usb-serial convertor, modprobe -r, etc),
 will cause trouble, so we need to make sure there is no gpio user before
 call pl2303_release.
 
 Signed-off-by: Wang YanQing udkni...@gmail.com
 ---
  Note: I sniffed office HXD gpio test program to get 
gpios control protocol with PL2303 RA, so I only
test it with PL2303 RA and HXA, I don't have HXD,
but because it is *office* HXD gpio test program,
so if it doesn't work with HXD, I will feel surprise.
 
  Changes
  v7-v8:
  1: add support for four dedicated gpios on HXD and RA
  2: fix problem reported by Johan Hovold in v7
  3: fix checkpatch.pl's warning
 
  v6-v7:
  1: add generic gpio support interfaces for pl2303 USB Serial devices
 in pl2303_type_data and pl2303_serial_private suggested by Andreas Mohr.
  2: drop different label names for different pl2303 instance suggested by 
 Johan Hovold.
  3: fix missing lock corrected by Johan Hovold.
  4: use prefix pl2303hx_gpio instead pl2303_gpio, pl2303_gpio is over generic 
 for current code,
 and now we move gpio_startup|gpio_release into type-specified data 
 structure, so pl2303hx_gpio
 is a better prefix.
  5: make words in Kconfig a little more useful and clarified.
  6: many misc code quality enhancement suggested by Johan Hovold.
 
  v5-v6:
  1: fix typo error in Kconfig reported by Andreas Mohr 
  2: add const qulification to gpio_dir_mask and gpio_value_mask suggested by 
 Andreas Mohr
 
  v4-v5:
  1: fix gpio_chip.lable been overwrited by template_chip. 
  2: use idr to manage minor instead of crude monotonous atomic increment. 
 
  v3-v4:
  1: fix missing static for gpio_dir_mask and gpio_value_mask 
  2: reduce unneeded compile macro defined suggested by 
 gno...@lxorguk.ukuu.org.uk 
  3: use true instead of 1 corrected by Linus Walleij
  4: ignore return value of gpiochip_remove suggested by Linus Walleij
  5: fix multi gpio_chips registered by pl2303 can't be distinguished in 
 kernel space. 
 
  v2-v3:
  1: fix errors and warnings reported by Daniele Forsi checked with 
 checkpatch.pl 
  2: fix missing GPIOLIB dependence in Kconfig 
  3: fix pl2303_gpio_get can't work 
 
  v1-v2:  
  1:drop gpio-pl2303.c and relation stuff 
  2:hang gpio stuff off of pl2303.c  
 
  drivers/usb/serial/Kconfig  |  11 ++
  drivers/usb/serial/pl2303.c | 250 
 
  2 files changed, 261 insertions(+)
 
 diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
 index 3ce5c74..b4e0cf9 100644
 --- a/drivers/usb/serial/Kconfig
 +++ b/drivers/usb/serial/Kconfig
 @@ -516,6 +516,17 @@ config USB_SERIAL_PL2303
 To compile this driver as a module, choose M here: the
 module will be called pl2303.
  
 +config USB_SERIAL_PL2303_GPIO
 + bool USB Prolific 2303 Single Port GPIOs support
 + depends on USB_SERIAL_PL2303  GPIOLIB
 + ---help---
 +   Say Y here if you want to use GPIOs on PL2303 USB Serial single port
 +   adapter from Prolific.
 +
 +   It supports 2 dedicated GPIOs on PL2303HXA, 4 dedicated GPIOs on
 +   PL2303HXD and PL2303RA currently.
 +   If unsure, say N.
 +
  config USB_SERIAL_OTI6858
   tristate USB Ours Technology Inc. OTi-6858 USB To RS232 Bridge 
 Controller
   help
 diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
 index e9bad92..a3f8411 100644
 --- a/drivers/usb/serial/pl2303.c
 +++ b/drivers/usb/serial/pl2303.c
 @@ -28,6 +28,8 @@
  #include linux/usb.h
  #include linux/usb/serial.h
  #include asm/unaligned.h
 +#include linux/gpio.h
 +#include linux/mutex.h
  #include pl2303.h
  
  
 @@ -132,6 +134,22 @@ MODULE_DEVICE_TABLE(usb, id_table);
  #define UART_OVERRUN_ERROR   0x40
  #define UART_CTS 0x80
  
 +#define HXD_GPIO_01_CTRL 0x0001
 +#define HXD_GPIO_01_VALUE0x0081
 +#define HXD_GPIO_23_DIR_CTRL 0x0c0c
 +#define HXD_GPIO_23_VALUE_CTRL   0x0d0d
 +#define HXD_GPIO_23_VALUE0x8d8d
 +
 +#define HXD_GPIO0_DIR_MASK   0x10
 +#define HXD_GPIO1_DIR_MASK   0x20
 +#define HXD_GPIO2_DIR_MASK   0x03
 +#define HXD_GPIO3_DIR_MASK   0x0c
 +
 +#define HXD_GPIO0_VALUE_MASK 0x40
 +#define HXD_GPIO1_VALUE_MASK 0x80
 +#define HXD_GPIO2_VALUE_MASK 0x01
 +#define HXD_GPIO3_VALUE_MASK 0x02
 +
  
  enum pl2303_type {
   TYPE_01,/* Type 0 and 1 (difference unknown) */
 @@ -144,9 +162,12 @@ struct pl2303_type_data {
   unsigned long quirks;
  };
  
 +struct pl2303_gpio;
  struct pl2303_serial_private {
   const struct pl2303_type_data *type;
   unsigned long quirks;
 + u8 ngpio;
 + struct pl2303_gpio *gpio;
  };
  
  

Re: [PATCH v8] usb:serial:pl2303: add GPIOs interface on PL2303

2014-09-04 Thread Benjamin Henrion
On Thu, Sep 4, 2014 at 7:35 PM, Wang YanQing udkni...@gmail.com wrote:
 On Sun, Aug 31, 2014 at 11:24:56PM +0800, Wang YanQing wrote:
 PL2303 USB Serial devices may has GPIOs, this patch add
 basic PL2303 gpio support.

 Known issue:
 If gpios are in use(export to userspace through sysfs interface, etc),
 then call pl2303_release(unplug usb-serial convertor, modprobe -r, etc),
 will cause trouble, so we need to make sure there is no gpio user before
 call pl2303_release.

 Signed-off-by: Wang YanQing udkni...@gmail.com
 ---
  Note: I sniffed office HXD gpio test program to get
gpios control protocol with PL2303 RA, so I only
test it with PL2303 RA and HXA, I don't have HXD,
but because it is *office* HXD gpio test program,
so if it doesn't work with HXD, I will feel surprise.

I can confirm your patch is working fine on the HXD:

http://www.zoobab.com/pl2303hxd-gpio

I am still hunting for a simple C program to test the speed of the
GPIOs and sysfs, if you have a good reference.

Best,

-- 
Benjamin Henrion bhenrion at ffii.org
FFII Brussels - +32-484-566109 - +32-2-4148403
In July 2005, after several failed attempts to legalise software
patents in Europe, the patent establishment changed its strategy.
Instead of explicitly seeking to sanction the patentability of
software, they are now seeking to create a central European patent
court, which would establish and enforce patentability rules in their
favor, without any possibility of correction by competing courts or
democratically elected legislators.
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8] usb:serial:pl2303: add GPIOs interface on PL2303

2014-09-04 Thread Wang YanQing
On Thu, Sep 04, 2014 at 06:44:31PM +0200, Benjamin Henrion wrote:
 On Thu, Sep 4, 2014 at 6:14 PM, Benjamin Henrion zoo...@gmail.com wrote:
  I have subscribed to the lkml.
 
  Can you make me a favour, send me your email as you posted on the LKML
  in mbox format attached to an email?
 
  I am trying to reply to it, but I cannot find an mbox archive, outside
  of gmane which rewrites all the email addresses.
 
  Otherwise, I made a page here:
 
  http://www.zoobab.com/pl2303hxd-gpio
 
  I will also try with other adapters to see if the 2 GPIOs show up.
 
  Any idea how to test the GPIO sysfs speed?
 
 Also tested with an HXA laying around, I could export the 2 GPIOS in
 /sys/class/gpio, but I could not change the status of the pins via
 echo.
 
 Any idea why?

It is strange, I have tested again with my two HXA adapters, they work well.
How do you test? check cat value or check voltage change? I check cat value,
and they work good.


 
 -- 
 Benjamin Henrion bhenrion at ffii.org
 FFII Brussels - +32-484-566109 - +32-2-4148403
 In July 2005, after several failed attempts to legalise software
 patents in Europe, the patent establishment changed its strategy.
 Instead of explicitly seeking to sanction the patentability of
 software, they are now seeking to create a central European patent
 court, which would establish and enforce patentability rules in their
 favor, without any possibility of correction by competing courts or
 democratically elected legislators.
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8] usb:serial:pl2303: add GPIOs interface on PL2303

2014-08-31 Thread Wang YanQing
PL2303 USB Serial devices may has GPIOs, this patch add
basic PL2303 gpio support.

Known issue:
If gpios are in use(export to userspace through sysfs interface, etc),
then call pl2303_release(unplug usb-serial convertor, modprobe -r, etc),
will cause trouble, so we need to make sure there is no gpio user before
call pl2303_release.

Signed-off-by: Wang YanQing udkni...@gmail.com
---
 Note: I sniffed office HXD gpio test program to get 
   gpios control protocol with PL2303 RA, so I only
   test it with PL2303 RA and HXA, I don't have HXD,
   but because it is *office* HXD gpio test program,
   so if it doesn't work with HXD, I will feel surprise.

 Changes
 v7-v8:
 1: add support for four dedicated gpios on HXD and RA
 2: fix problem reported by Johan Hovold in v7
 3: fix checkpatch.pl's warning

 v6-v7:
 1: add generic gpio support interfaces for pl2303 USB Serial devices
in pl2303_type_data and pl2303_serial_private suggested by Andreas Mohr.
 2: drop different label names for different pl2303 instance suggested by Johan 
Hovold.
 3: fix missing lock corrected by Johan Hovold.
 4: use prefix pl2303hx_gpio instead pl2303_gpio, pl2303_gpio is over generic 
for current code,
and now we move gpio_startup|gpio_release into type-specified data 
structure, so pl2303hx_gpio
is a better prefix.
 5: make words in Kconfig a little more useful and clarified.
 6: many misc code quality enhancement suggested by Johan Hovold.

 v5-v6:
 1: fix typo error in Kconfig reported by Andreas Mohr 
 2: add const qulification to gpio_dir_mask and gpio_value_mask suggested by 
Andreas Mohr

 v4-v5:
 1: fix gpio_chip.lable been overwrited by template_chip. 
 2: use idr to manage minor instead of crude monotonous atomic increment. 

 v3-v4:
 1: fix missing static for gpio_dir_mask and gpio_value_mask 
 2: reduce unneeded compile macro defined suggested by 
gno...@lxorguk.ukuu.org.uk 
 3: use true instead of 1 corrected by Linus Walleij
 4: ignore return value of gpiochip_remove suggested by Linus Walleij
 5: fix multi gpio_chips registered by pl2303 can't be distinguished in kernel 
space. 

 v2-v3:
 1: fix errors and warnings reported by Daniele Forsi checked with 
checkpatch.pl 
 2: fix missing GPIOLIB dependence in Kconfig 
 3: fix pl2303_gpio_get can't work 

 v1-v2:  
 1:drop gpio-pl2303.c and relation stuff 
 2:hang gpio stuff off of pl2303.c  

 drivers/usb/serial/Kconfig  |  11 ++
 drivers/usb/serial/pl2303.c | 250 
 2 files changed, 261 insertions(+)

diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 3ce5c74..b4e0cf9 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -516,6 +516,17 @@ config USB_SERIAL_PL2303
  To compile this driver as a module, choose M here: the
  module will be called pl2303.
 
+config USB_SERIAL_PL2303_GPIO
+   bool USB Prolific 2303 Single Port GPIOs support
+   depends on USB_SERIAL_PL2303  GPIOLIB
+   ---help---
+ Say Y here if you want to use GPIOs on PL2303 USB Serial single port
+ adapter from Prolific.
+
+ It supports 2 dedicated GPIOs on PL2303HXA, 4 dedicated GPIOs on
+ PL2303HXD and PL2303RA currently.
+ If unsure, say N.
+
 config USB_SERIAL_OTI6858
tristate USB Ours Technology Inc. OTi-6858 USB To RS232 Bridge 
Controller
help
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index e9bad92..a3f8411 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -28,6 +28,8 @@
 #include linux/usb.h
 #include linux/usb/serial.h
 #include asm/unaligned.h
+#include linux/gpio.h
+#include linux/mutex.h
 #include pl2303.h
 
 
@@ -132,6 +134,22 @@ MODULE_DEVICE_TABLE(usb, id_table);
 #define UART_OVERRUN_ERROR 0x40
 #define UART_CTS   0x80
 
+#define HXD_GPIO_01_CTRL   0x0001
+#define HXD_GPIO_01_VALUE  0x0081
+#define HXD_GPIO_23_DIR_CTRL   0x0c0c
+#define HXD_GPIO_23_VALUE_CTRL 0x0d0d
+#define HXD_GPIO_23_VALUE  0x8d8d
+
+#define HXD_GPIO0_DIR_MASK 0x10
+#define HXD_GPIO1_DIR_MASK 0x20
+#define HXD_GPIO2_DIR_MASK 0x03
+#define HXD_GPIO3_DIR_MASK 0x0c
+
+#define HXD_GPIO0_VALUE_MASK   0x40
+#define HXD_GPIO1_VALUE_MASK   0x80
+#define HXD_GPIO2_VALUE_MASK   0x01
+#define HXD_GPIO3_VALUE_MASK   0x02
+
 
 enum pl2303_type {
TYPE_01,/* Type 0 and 1 (difference unknown) */
@@ -144,9 +162,12 @@ struct pl2303_type_data {
unsigned long quirks;
 };
 
+struct pl2303_gpio;
 struct pl2303_serial_private {
const struct pl2303_type_data *type;
unsigned long quirks;
+   u8 ngpio;
+   struct pl2303_gpio *gpio;
 };
 
 struct pl2303_private {
@@ -157,6 +178,14 @@ struct pl2303_private {
u8 line_settings[7];
 };
 
+#ifdef CONFIG_USB_SERIAL_PL2303_GPIO
+static