From: Johan Hovold <johan@kernel.org>
To: Frank Zago <frank@zago.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org,
Jan-Niklas Burfeind <kernel@aiyionpri.me>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
Wolfram Sang <wsa@kernel.org>,
linux-usb@vger.kernel.org, gunar@schorcht.net
Subject: Re: [PATCH v2 2/2] USB: misc: Add driver for the WCH CH341 in I2C/GPIO mode
Date: Mon, 10 May 2021 09:53:33 +0200 [thread overview]
Message-ID: <YJjmfce0WKoFx35z@hovoldconsulting.com> (raw)
In-Reply-To: <20210423002852.3904-2-frank@zago.net>
On Thu, Apr 22, 2021 at 07:28:52PM -0500, Frank Zago wrote:
> From: frank zago <frank@zago.net>
>
> The CH341 is a multifunction chip, presenting 3 different USB PID. One
> of these functions is for I2C/SPI/GPIO. This new driver manages I2C
> and GPIO. A future update will manage the SPI part as well.
>
> The I2C interface can run at 4 different speeds. This driver currently
> only offer 100MHz. Tested with a variety of I2C sensors, and the IIO
> subsystem.
>
> The GPIO interface offers 8 GPIOs. 6 are read/write, and 2 are
> rea-only. However the SPI interface will use 6 of them, leaving 2
> available GPIOs.
>
> Signed-off-by: frank zago <frank@zago.net>
> ---
>
> Changes from v1:
> - Removed double Signed-off-by
> - Move Kconfig into the same directory as the driver
>
> MAINTAINERS | 6 +
> drivers/usb/misc/Kconfig | 2 +
> drivers/usb/misc/Makefile | 1 +
> drivers/usb/misc/ch341/Kconfig | 17 ++
> drivers/usb/misc/ch341/Makefile | 3 +
> drivers/usb/misc/ch341/ch341-core.c | 87 +++++++++
> drivers/usb/misc/ch341/ch341-gpio.c | 249 ++++++++++++++++++++++++++
> drivers/usb/misc/ch341/ch341-i2c.c | 267 ++++++++++++++++++++++++++++
> drivers/usb/misc/ch341/ch341.h | 50 ++++++
> 9 files changed, 682 insertions(+)
Not sure about sticking this in usb/misc. We already have an MFD driver
(dln2) for something like this with i2c and spi iirc. The difference
from regular MFDs here is that these modes are mutually exclusive.
If it was just an i2c driver with some pins to toggle, I'd say just add
it to drivers/i2c but that would probably make it harder to reuse code
for the SPI driver.
I'm not really reviewing the rest of the driver, just pointing out a few
more things that stood out below.
> +static void ch341_usb_free_device(struct ch341_device *dev)
> +{
> + ch341_gpio_remove(dev);
> + ch341_i2c_remove(dev);
Have you verified that the i2c subsystem can handle a device being
removed like this while in use. That wasn't the case a few years back.
> +
> + usb_set_intfdata(dev->iface, NULL);
> + usb_put_dev(dev->usb_dev);
> +
> + kfree(dev);
> +}
> +
> +static int ch341_usb_probe(struct usb_interface *iface,
> + const struct usb_device_id *usb_id)
> +{
> + struct ch341_device *dev;
> + int error;
> +
> + dev = kzalloc(sizeof(struct ch341_device), GFP_KERNEL);
> + if (!dev)
> + return -ENOMEM;
> +
> + dev->usb_dev = usb_get_dev(interface_to_usbdev(iface));
> + dev->iface = iface;
> + mutex_init(&dev->usb_lock);
> + dev->ep_out = iface->cur_altsetting->endpoint[1].desc.bEndpointAddress;
> + dev->ep_in = iface->cur_altsetting->endpoint[0].desc.bEndpointAddress;
NULL-deref in case a device lacks the expected endpoints.
> +
> + usb_set_intfdata(iface, dev);
> +
> + error = ch341_i2c_init(dev);
> + if (error) {
> + ch341_usb_free_device(dev);
> + return error;
> + }
> +
> + error = ch341_gpio_init(dev);
> + if (error) {
> + ch341_usb_free_device(dev);
> + return error;
> + }
> +
> + return 0;
> +}
> +
> +static void ch341_usb_disconnect(struct usb_interface *usb_if)
> +{
> + struct ch341_device *dev = usb_get_intfdata(usb_if);
> +
> + ch341_usb_free_device(dev);
> +}
> +int ch341_gpio_init(struct ch341_device *dev)
> +{
> + struct gpio_chip *gpio = &dev->gpio;
> + int result;
> +
> + gpio->label = "ch341";
> + gpio->parent = &dev->usb_dev->dev;
> + gpio->owner = THIS_MODULE;
> + gpio->get_direction = ch341_gpio_get_direction;
> + gpio->direction_input = ch341_gpio_direction_input;
> + gpio->direction_output = ch341_gpio_direction_output;
> + gpio->get = ch341_gpio_get;
> + gpio->get_multiple = ch341_gpio_get_multiple;
> + gpio->set = ch341_gpio_set;
> + gpio->set_multiple = ch341_gpio_set_multiple;
> + gpio->dbg_show = ch341_gpio_dbg_show;
> + gpio->base = -1;
> + gpio->ngpio = CH341_GPIO_NUM_PINS;
> + gpio->names = gpio_names;
Last time I checked (a few weeks ago) you could still not set names for
hotpluggable devices of which there could be more than one or you'd get
a warning when plugging a second device in. Not sure if Linus W fixed
that yet.
Johan
next prev parent reply other threads:[~2021-05-10 7:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-23 0:28 [PATCH v2 1/2] Revert "USB: serial: ch341: add new Product ID for CH341A" Frank Zago
2021-04-23 0:28 ` [PATCH v2 2/2] USB: misc: Add driver for the WCH CH341 in I2C/GPIO mode Frank Zago
2021-05-10 7:53 ` Johan Hovold [this message]
2021-05-10 7:40 ` [PATCH v2 1/2] Revert "USB: serial: ch341: add new Product ID for CH341A" Johan Hovold
2021-05-12 1:07 ` Frank Zago
2021-05-12 9:55 ` Johan Hovold
2021-05-13 1:00 ` Frank Zago
2021-05-13 11:31 ` Johan Hovold
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=YJjmfce0WKoFx35z@hovoldconsulting.com \
--to=johan@kernel.org \
--cc=bgolaszewski@baylibre.com \
--cc=frank@zago.net \
--cc=gregkh@linuxfoundation.org \
--cc=gunar@schorcht.net \
--cc=kernel@aiyionpri.me \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=wsa@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
all inboxes | Powered by JetHome®