From: Johan Hovold <johan@kernel.org>
To: Charles Yeh <charlesyeh522@gmail.com>
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
charles-yeh@prolific.com.tw, joy-yeh@prolific.com.tw
Subject: Re: [PATCH] USB: serial: pl2303: add PL2303G GPIO_A and GPIO_B functions
Date: Wed, 18 Jun 2025 14:57:53 +0200 [thread overview]
Message-ID: <aFK30fcz0ujRbKBj@hovoldconsulting.com> (raw)
In-Reply-To: <20250618123513.12-1-charlesyeh522@gmail.com>
On Wed, Jun 18, 2025 at 08:35:13PM +0800, Charles Yeh wrote:
> PL2303G (TYPE_HXN) series ICs: PL2303GC, PL2303GS, PL2303GT, PL2303GR,.. etc.
>
> For example:
> PL2303GC can provide up to 16 GPIO (general purpose input/output) signals.
> they are composed of GPIO_A0~A7 and GPIO_B0~B7 respectively.
>
> In addition to the original UART functions such as Tx, Rx, RTS, CTS, etc.,
> users can also use GPIO to implement certain applications,
> such as turning on/off the LED power.
>
> Users can download the PL2303G Linux GPIO app: PL2303G_Linux_GPIO_Test.c
> from the Prolific website.
>
> Signed-off-by: Charles Yeh <charlesyeh522@gmail.com>
> ---
> drivers/usb/serial/pl2303.c | 182 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 182 insertions(+)
>
> diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
> index 22579d0d8ab8..be7e695bea60 100644
> --- a/drivers/usb/serial/pl2303.c
> +++ b/drivers/usb/serial/pl2303.c
> @@ -175,6 +175,37 @@ MODULE_DEVICE_TABLE(usb, id_table);
> #define PL2303_HXN_FLOWCTRL_RTS_CTS 0x18
> #define PL2303_HXN_FLOWCTRL_XON_XOFF 0x0c
>
> +
> +struct PL2303G_GPIO {
> + u8 GP_Branch;
> + u8 Number;
> + u8 Value;
We use lower case symbol names in the kernel.
> +};
> +
> +
> +#define GPIO_AB_CONTROL_MODE _IOW(0x81, 10, struct PL2303G_GPIO)
> +#define GPIO_AB_OUTPUT_MODE _IOW(0x81, 11, struct PL2303G_GPIO)
> +#define GPIO_AB_SET_VALUE _IOW(0x81, 12, struct PL2303G_GPIO)
> +#define GPIO_AB_GET_VALUE _IOR(0x81, 13, struct PL2303G_GPIO)
No, custom ioctls won't do. We have a standard interface for accessing
GPIOs so you need to model this as gpio chips similar to what the
ftdi_sio and cp210x drivers do.
> +static int pl2303_ioctl(struct tty_struct *tty,
> + unsigned int cmd, unsigned long arg)
> +{
> + int retval = 0;
> + struct serial_struct ser;
> + struct usb_serial_port *port = tty->driver_data;
> + struct usb_serial *serial = port->serial;
> +
> + switch (cmd) {
> + case TIOCGSERIAL:
> + memset(&ser, 0, sizeof(ser));
> + ser.type = PORT_16654;
> + ser.line = port->minor;
> + ser.port = port->port_number;
> + ser.baud_base = 460800;
> +
> + if (copy_to_user((void __user *)arg, &ser, sizeof(ser)))
> + return -EFAULT;
> +
> + return 0;
This looks unrelated.
> + case GPIO_AB_CONTROL_MODE:
> + retval = pl2303N_gpio_set(serial, (void __user *) arg,
> + PL2303N_CE_MODE);
> + break;
> + case GPIO_AB_OUTPUT_MODE:
> + retval = pl2303N_gpio_set(serial, (void __user *) arg,
> + PL2303N_OE_MODE);
> + break;
> + case GPIO_AB_SET_VALUE:
> + retval = pl2303N_gpio_set(serial, (void __user *) arg,
> + PL2303N_SET_MODE);
> + break;
> + case GPIO_AB_GET_VALUE:
> + retval = pl2303N_gpio_get(serial, (void __user *) arg,
> + PL2303N_GET_MODE);
> + break;
> + default:
> + retval = -ENOIOCTLCMD;
> + break;
> + }
> +
> + return retval;
> +
> +}
Johan
next prev parent reply other threads:[~2025-06-18 12:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-18 12:35 [PATCH] USB: serial: pl2303: add PL2303G GPIO_A and GPIO_B functions Charles Yeh
2025-06-18 12:57 ` Johan Hovold [this message]
2025-06-18 12:58 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aFK30fcz0ujRbKBj@hovoldconsulting.com \
--to=johan@kernel.org \
--cc=charles-yeh@prolific.com.tw \
--cc=charlesyeh522@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=joy-yeh@prolific.com.tw \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox