From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8464FC433EF for ; Mon, 27 Jun 2022 14:43:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237696AbiF0OnZ (ORCPT ); Mon, 27 Jun 2022 10:43:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237583AbiF0OnY (ORCPT ); Mon, 27 Jun 2022 10:43:24 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58EC56429 for ; Mon, 27 Jun 2022 07:43:22 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id w17so13389474wrg.7 for ; Mon, 27 Jun 2022 07:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=I3nC8B6be2rJKcDVylzZNDnz/D1EgBd9lnRAuMjTZ0A=; b=OflRcSKTk5KJCsJhl/OOpbqhK8lJUAG5ameoeZ6v2VCXjDvoRSiavCQ3R1SeKuwP7R KbeemSWZj0FBD0BGYqlJ9zS8r30ytnBo+ZfnhbBnEGCCqGR3VFgmCBFbM2Ri1w9nKmD3 Puk4NGy6VbGJKlsvbgETb7enuUR4hHJxrlL9u/Sn+TdoGHt16rM9rdRt04CQ42UTxvO6 Kzxmo/2csAxoA6QVmMiAYzHNH4FzLTzgjs6VRdFBeRRrEEdOz6cKDRINsq4la0W19ECu u9sf6CUJIC8M2wLb+kZTBI0plSWsnXdcymHtHQ14ks2Lqp8b0msjqo9WP4H8G6nqd6wR LRdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=I3nC8B6be2rJKcDVylzZNDnz/D1EgBd9lnRAuMjTZ0A=; b=OI6NLescQ7LvwLtJeNupVNwETjWK+1jzPWCmKrenlxeumNA70BXrYxvI2k5FaO7U5d F75imaaaq5MBFFrS9jNQHT8mLln+Sy/d3JJuM44aB75OQRGbQNRyZzAGQnHTcmbe1bW5 xt/Vmk0eQKKkGAg6D5XAZtSZN7X8UG8qDS+GEH/oZNJpbcNGKPlHO3AVNHVG1px3CrlP zgdIcFcnWwifU3CnEFPsmhaT5vQBGPiAtPJ+VQhMrVfPdNz3E3dct5XRknTV6u7xOOyN Y9mw2BkVR77zAFHvPbW8x5Vfgp+tCQd9lq648isU4jkN+dv0gcQrtW4URs9Mj0heTmaj Djuw== X-Gm-Message-State: AJIora9HuouarQMytjwnDUhFHq9eZ3P2Z7Ne7iBwU/HTtoJlkO7p0A7x k4MwURBZCvA3DzYYbUHUmP1UrQ== X-Google-Smtp-Source: AGRyM1tP0/3e0jF/X+My1isKflET6012raahzAfSWgsOfNodPOmlFfVxCEOpkadCal8x3313vLkjhQ== X-Received: by 2002:a5d:5a19:0:b0:21b:8eb8:f54b with SMTP id bq25-20020a5d5a19000000b0021b8eb8f54bmr12266223wrb.663.1656341000915; Mon, 27 Jun 2022 07:43:20 -0700 (PDT) Received: from google.com (cpc155339-bagu17-2-0-cust87.1-3.cable.virginm.net. [86.27.177.88]) by smtp.gmail.com with ESMTPSA id e7-20020adfe7c7000000b0021b9100b844sm10943277wrn.91.2022.06.27.07.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 07:43:20 -0700 (PDT) Date: Mon, 27 Jun 2022 15:43:18 +0100 From: Lee Jones To: Greg Kroah-Hartman Cc: frank zago , linux-kernel@vger.kernel.org, Bartosz Golaszewski , Wolfram Sang , Johan Hovold , linux-usb@vger.kernel.org, Linus Walleij , linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org Subject: Re: [PATCH v6 1/4] mfd: ch341: add core driver for the WCH CH341 in I2C/SPI/GPIO mode Message-ID: References: <20220616013747.126051-1-frank@zago.net> <20220616013747.126051-2-frank@zago.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org On Mon, 27 Jun 2022, Greg Kroah-Hartman wrote: > On Mon, Jun 27, 2022 at 03:04:32PM +0100, Lee Jones wrote: > > USB review please. > > > > > 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 > > > --- > > > MAINTAINERS | 7 +++ > > > drivers/mfd/Kconfig | 10 +++++ > > > drivers/mfd/Makefile | 1 + > > > drivers/mfd/ch341-core.c | 90 +++++++++++++++++++++++++++++++++++++++ > > > include/linux/mfd/ch341.h | 18 ++++++++ > > > 5 files changed, 126 insertions(+) > > > create mode 100644 drivers/mfd/ch341-core.c > > > create mode 100644 include/linux/mfd/ch341.h > > > > > > diff --git a/MAINTAINERS b/MAINTAINERS > > > index 43d3d07afccd..628eeaa9bf68 100644 > > > --- a/MAINTAINERS > > > +++ b/MAINTAINERS > > > @@ -21475,6 +21475,13 @@ M: David Härdeman > > > S: Maintained > > > F: drivers/media/rc/winbond-cir.c > > > > > > +WINCHIPHEAD CH341 I2C/GPIO MFD DRIVER > > > +M: Frank Zago > > > +L: linux-usb@vger.kernel.org > > > +S: Maintained > > > +F: drivers/mfd/ch341-core.c > > > +F: include/linux/mfd/ch341.h > > > + > > > WINSYSTEMS EBC-C384 WATCHDOG DRIVER > > > M: William Breathitt Gray > > > L: linux-watchdog@vger.kernel.org > > > diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig > > > index 3b59456f5545..893acc821a42 100644 > > > --- a/drivers/mfd/Kconfig > > > +++ b/drivers/mfd/Kconfig > > > @@ -1784,6 +1784,16 @@ config MFD_LOCHNAGAR > > > help > > > Support for Cirrus Logic Lochnagar audio development board. > > > > > > +config MFD_CH341 > > > + tristate "WinChipHead CH341 in I2C/SPI/GPIO mode" > > > + depends on USB > > > + help > > > + If you say yes to this option, support for the CH341 series > > > + of chips, running in I2C/SPI/GPIO mode will be included. > > > + > > > + This driver can also be built as a module. If so, the > > > + module will be called ch341-core. > > > + > > > config MFD_ARIZONA > > > select REGMAP > > > select REGMAP_IRQ > > > diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile > > > index 858cacf659d6..fd615ab3929f 100644 > > > --- a/drivers/mfd/Makefile > > > +++ b/drivers/mfd/Makefile > > > @@ -13,6 +13,7 @@ obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o > > > obj-$(CONFIG_ARCH_BCM2835) += bcm2835-pm.o > > > obj-$(CONFIG_MFD_BCM590XX) += bcm590xx.o > > > obj-$(CONFIG_MFD_BD9571MWV) += bd9571mwv.o > > > +obj-$(CONFIG_MFD_CH341) += ch341-core.o > > > obj-$(CONFIG_MFD_CROS_EC_DEV) += cros_ec_dev.o > > > obj-$(CONFIG_MFD_ENE_KB3930) += ene-kb3930.o > > > obj-$(CONFIG_MFD_EXYNOS_LPASS) += exynos-lpass.o > > > diff --git a/drivers/mfd/ch341-core.c b/drivers/mfd/ch341-core.c > > > new file mode 100644 > > > index 000000000000..f08a67dd6074 > > > --- /dev/null > > > +++ b/drivers/mfd/ch341-core.c > > > @@ -0,0 +1,90 @@ > > > +// SPDX-License-Identifier: GPL-2.0 > > > +/* > > > + * Core driver for the CH341A, CH341B and CH341T in I2C/SPI/GPIO > > > + * mode. There are cell drivers available for I2C and GPIO. SPI is not > > > + * yet supported. > > > + * > > > + * Copyright 2022, Frank Zago > > > + * Copyright (c) 2017 Gunar Schorcht (gunar@schorcht.net) > > > + * Copyright (c) 2016 Tse Lun Bien > > > + * Copyright (c) 2014 Marco Gittler > > > + * Copyright (c) 2006-2007 Till Harbaum (Till@Harbaum.org) > > > + */ > > > + > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > + > > > +static const struct mfd_cell ch341_devs[] = { > > > + { > > > + .name = "ch341-gpio", > > > + }, > > > + { > > > + .name = "ch341-i2c", > > > + }, > > > +}; > > > + > > > +static int ch341_usb_probe(struct usb_interface *iface, > > > + const struct usb_device_id *usb_id) > > > +{ > > > + struct usb_endpoint_descriptor *bulk_out; > > > + struct usb_endpoint_descriptor *bulk_in; > > > + struct usb_endpoint_descriptor *intr_in; > > > + struct ch341_ddata *ddata; > > > + int ret; > > > + > > > + ddata = devm_kzalloc(&iface->dev, sizeof(*ddata), GFP_KERNEL); > > > + if (!ddata) > > > + return -ENOMEM; > > > + > > > + ddata->usb_dev = interface_to_usbdev(iface); > > > + mutex_init(&ddata->usb_lock); > > > + > > > + ret = usb_find_common_endpoints(iface->cur_altsetting, &bulk_in, > > > + &bulk_out, &intr_in, NULL); > > > + if (ret) { > > > + dev_err(&iface->dev, "Could not find all endpoints\n"); > > > + return -ENODEV; > > > + } > > > + > > > + ddata->ep_in = bulk_in->bEndpointAddress; > > > + ddata->ep_out = bulk_out->bEndpointAddress; > > > + ddata->ep_intr = intr_in->bEndpointAddress; > > > + ddata->ep_intr_interval = intr_in->bInterval; > > > + > > > + usb_set_intfdata(iface, ddata); > > > + > > > + ret = mfd_add_devices(&iface->dev, PLATFORM_DEVID_AUTO, ch341_devs, > > > + ARRAY_SIZE(ch341_devs), NULL, 0, NULL); > > > + if (ret) > > > + return dev_err_probe(&iface->dev, ret, > > > + "Failed to register child devices\n"); > > > + > > > + return 0; > > > +} > > > + > > > +static void ch341_usb_disconnect(struct usb_interface *usb_if) > > > +{ > > > + mfd_remove_devices(&usb_if->dev); > > > +} > > > + > > > +static const struct usb_device_id ch341_usb_table[] = { > > > + { USB_DEVICE(0x1a86, 0x5512) }, > > > + { } > > > +}; > > > +MODULE_DEVICE_TABLE(usb, ch341_usb_table); > > > + > > > +static struct usb_driver ch341_usb_driver = { > > > + .name = "ch341-mfd", > > > + .id_table = ch341_usb_table, > > > + .probe = ch341_usb_probe, > > > + .disconnect = ch341_usb_disconnect, > > > +}; > > > +module_usb_driver(ch341_usb_driver); > > > + > > > +MODULE_AUTHOR("Frank Zago "); > > > +MODULE_DESCRIPTION("CH341 USB to I2C/SPI/GPIO adapter"); > > > +MODULE_LICENSE("GPL"); > > > diff --git a/include/linux/mfd/ch341.h b/include/linux/mfd/ch341.h > > > new file mode 100644 > > > index 000000000000..44f5da0720bd > > > --- /dev/null > > > +++ b/include/linux/mfd/ch341.h > > > @@ -0,0 +1,18 @@ > > > +/* SPDX-License-Identifier: GPL-2.0 */ > > > +/* Definitions for the CH341 driver */ > > > + > > > +#include > > > +#include > > > + > > > +struct usb_device; > > > +struct usb_interface; > > > + > > > +struct ch341_ddata { > > > + struct usb_device *usb_dev; > > > + struct mutex usb_lock; > > > + > > > + int ep_in; > > > + int ep_out; > > > + int ep_intr; > > > + u8 ep_intr_interval; > > > +}; > > > Looks sane enough, but doesn't actually do any USB data transfers, maybe > that happens somewhere else... I expect those to happen in *both* of these: static const struct mfd_cell ch341_devs[] = { { .name = "ch341-gpio", }, { .name = "ch341-i2c", }, }; Is that correct Frank? > Acked-by: Greg Kroah-Hartman Thanks. -- Lee Jones [李琼斯] Principal Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog