From: Johan Hovold <johan@kernel.org>
To: frank zago <frank@zago.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
Wolfram Sang <wsa@kernel.org>,
linux-usb@vger.kernel.org, Lee Jones <lee.jones@linaro.org>,
Linus Walleij <linus.walleij@linaro.org>,
linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org
Subject: Re: [PATCH v5 1/3] mfd: ch341: add core driver for the WCH CH341 in I2C/SPI/GPIO mode
Date: Mon, 23 May 2022 17:56:03 +0200 [thread overview]
Message-ID: <Youukx+7oieeDVCE@hovoldconsulting.com> (raw)
In-Reply-To: <20220401023306.79532-2-frank@zago.net>
On Thu, Mar 31, 2022 at 09:33:04PM -0500, frank zago wrote:
> The CH341 is a multifunction chip, presenting 3 different USB PID. One
> of these functions is for I2C/SPI/GPIO. This new set of drivers will
> manage I2C and GPIO.
>
> Signed-off-by: frank zago <frank@zago.net>
> ---
> +static int ch341_usb_probe(struct usb_interface *iface,
> + const struct usb_device_id *usb_id)
> +{
> + struct usb_host_endpoint *endpoints;
> + struct ch341_device *dev;
> + int rc;
> +
> + dev = devm_kzalloc(&iface->dev, sizeof(*dev), GFP_KERNEL);
> + if (!dev)
> + return -ENOMEM;
> +
> + dev->usb_dev = usb_get_dev(interface_to_usbdev(iface));
No need to grab a reference unless you're going to hold on to it past
disconnect().
> + dev->iface = iface;
> + mutex_init(&dev->usb_lock);
> +
> + if (iface->cur_altsetting->desc.bNumEndpoints != 3) {
> + rc = -ENODEV;
> + goto free_dev;
> + }
> +
> + endpoints = iface->cur_altsetting->endpoint;
> + if (!usb_endpoint_is_bulk_in(&endpoints[0].desc) ||
> + !usb_endpoint_is_bulk_out(&endpoints[1].desc) ||
> + !usb_endpoint_xfer_int(&endpoints[2].desc)) {
> + rc = -ENODEV;
> + goto free_dev;
> + }
Please use usb_find_common_endpoints() for the above.
> +
> + dev->ep_in = endpoints[0].desc.bEndpointAddress;
> + dev->ep_out = endpoints[1].desc.bEndpointAddress;
> + dev->ep_intr = endpoints[2].desc.bEndpointAddress;
> + dev->ep_intr_interval = endpoints[2].desc.bInterval;
> +
> + usb_set_intfdata(iface, dev);
> +
> + rc = mfd_add_hotplug_devices(&iface->dev, ch341_devs,
> + ARRAY_SIZE(ch341_devs));
> + if (rc) {
> + rc = dev_err_probe(&iface->dev, rc,
> + "Failed to add mfd devices to core\n");
> + goto free_dev;
> + }
> +
> + return 0;
> +
> +free_dev:
> + usb_put_dev(dev->usb_dev);
> +
> + return rc;
> +}
> +
> +static void ch341_usb_disconnect(struct usb_interface *usb_if)
> +{
> + struct ch341_device *dev = usb_get_intfdata(usb_if);
> +
> + mfd_remove_devices(&usb_if->dev);
> + usb_put_dev(dev->usb_dev);
> +}
Johan
next prev parent reply other threads:[~2022-05-23 15:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-01 2:33 [PATCH v5 0/3] WCH CH341 GPIO and SPI support frank zago
2022-04-01 2:33 ` [PATCH v5 1/3] mfd: ch341: add core driver for the WCH CH341 in I2C/SPI/GPIO mode frank zago
2022-04-26 14:35 ` Lee Jones
2022-06-16 1:18 ` Frank Zago
2022-05-23 15:56 ` Johan Hovold [this message]
2022-06-16 1:24 ` Frank Zago
2022-04-01 2:33 ` [PATCH v5 2/3] gpio: ch341: add GPIO MFD cell driver for the CH341 frank zago
2022-04-19 22:52 ` Linus Walleij
2022-05-23 16:16 ` Johan Hovold
2022-06-16 1:29 ` Frank Zago
2022-06-20 10:04 ` Johan Hovold
2022-04-01 2:33 ` [PATCH v5 3/3] i2c: ch341: add I2C " frank zago
2022-04-01 11:49 ` Sergey Shtylyov
2022-05-21 12:03 ` Wolfram Sang
2022-05-23 15:51 ` Johan Hovold
2022-05-23 17:09 ` Wolfram Sang
2022-06-16 1:22 ` Frank Zago
2022-05-23 16:00 ` Lee Jones
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=Youukx+7oieeDVCE@hovoldconsulting.com \
--to=johan@kernel.org \
--cc=bgolaszewski@baylibre.com \
--cc=frank@zago.net \
--cc=gregkh@linuxfoundation.org \
--cc=lee.jones@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--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 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.