Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp892035pxj; Wed, 16 Jun 2021 16:28:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCpY5/m294luCzepK0QvyzNKNhbjlJ9uwZ+im+WItNVWWQtLPnZPD+6V6IvT/QOBukc91G X-Received: by 2002:a50:ff0a:: with SMTP id a10mr2644107edu.273.1623886131282; Wed, 16 Jun 2021 16:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623886131; cv=none; d=google.com; s=arc-20160816; b=BcJP2J4lC5Sw9L/dQbnkWPGOLYqLTD0GXPPTsprottHKcq4EGx1hZAZNhNLU5tkfxV 7z3HdjMROC/xyYkq1BUuPtZ06KGB2DAmWkJWSPAcoOagVcOMCmKI8qIgKiMBUXDqXBgo PGqzUdfnx1Tc4Nno7RmrlAVKDTjzVxV7FNVyvo+DdeRse25dDpRFNI54BnT+RC7zuzr/ iYaRWQapZKhjPhKhKPSPWylRpC1SN5KJ9mAmCxsE4LKA/Y7S6hXyhePiC575IuZkp82B y8JB5mTYkwlSEMA19MFOahXv0RyUsooYquXsw5L+UtbIZTzJ/gLpCKSbtJbrMicakfJv slRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date:dkim-signature; bh=ke2vJFirAconFBhx0jR52uUwUcwhEwGm3ER7UOZjIlw=; b=r1gf+G8UwNpLGK7rrCZ+CF1tZl0h7p4jqPe1mvw6tjSzuD32R0I3mGctBbf7D9P+Zd lQHr1fnQwFUgan75M66wmj73p8MBozrqnFkgat+x6ouBe/JF3UD0/RKNfcrg5phK+gXx rKDxmbgrkRl3E2DTjmkPjsuv6oeHe2uYcPh7uhUYH/YW7WT9M3ym97udGfGwhwDnyq6T rCVLX9So1fX0GNzdBg/xSMR7m+FMpxSG/YGkTZ3DeU+ZlLUWMx9evMVcxHJ7a8evlAR4 3ZpksqTkZB+5xhQ+HHvBFnvDppfZPA0h4qSgOWZhFn883xV4niiT454aZ5WVhspMx0KN 5IDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="coTe9lX/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si3596229ejo.269.2021.06.16.16.28.28; Wed, 16 Jun 2021 16:28:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="coTe9lX/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235031AbhFPPr4 (ORCPT + 99 others); Wed, 16 Jun 2021 11:47:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:58406 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235806AbhFPPq5 (ORCPT ); Wed, 16 Jun 2021 11:46:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3BCED6101A; Wed, 16 Jun 2021 15:44:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623858286; bh=f/xcAG1IRmaGtuCoW1IWbSMqwmbcXKq1LV28L5Ej9dA=; h=Date:From:To:Subject:References:In-Reply-To:From; b=coTe9lX/le3kVOq3qM/BKv1R8u4AgSuv9TvLVgHCO4i7Fh463q2tZFa2g5XasDZiH 0vKjWqJOcLIHU7DMy+XeI3yZK9qqoH1jjDUgU1ZwFGG+K8NwnaD3e6ibqtyU5ceF3U DJF0Ro6AWT0y9LIH6YYmWSRDjPx73BDJc2lwYYc8hnd8bvVA6kcoq1WjEQU2dRCCZG 58sDvra/DwrMQ8QoEy+CPK2MGBVl/+9u4sRsM45pRymhPiSzV3fsbK6S0jOITxsrCh qNShz4iQvbUopOqMjPSqtvAi8bgwGgC9RPGixXKbsmDloD/BomVLM0Kh9j/aRj3THt Mvv4fXorR2qeA== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1ltXid-0000Jt-RZ; Wed, 16 Jun 2021 17:44:43 +0200 Date: Wed, 16 Jun 2021 17:44:43 +0200 From: Johan Hovold To: tu pham , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Hung.Nguyen@silabs.com, Tung.Pham@silabs.com, Pho Tran Subject: Re: [PATCH v13] USB: serial: cp210x: add support for GPIOs on CP2108 Message-ID: References: <20210610132844.25495-1-johan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210610132844.25495-1-johan@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 10, 2021 at 03:28:44PM +0200, Johan Hovold wrote: > From: Pho Tran > > Similar to some other CP210x device types, CP2108 has a number of GPIO > pins that can be exposed through gpiolib. > > CP2108 has four serial interfaces but only one set of GPIO pins, which > is modelled as a single gpio chip and registered as a child of the first > interface. > > CP2108 has 16 GPIOs so the width of the state variables needs to be > extended to 16 bits and this is also reflected in the control requests. > > Like CP2104, CP2108 have GPIO pins with configurable alternate > functions and pins unavailable for GPIO use are determined and reported > to gpiolib at probe. > > Signed-off-by: Pho Tran > Co-developed-by: Tung Pham > Signed-off-by: Tung Pham > [ johan: rewrite gpio get() and set(); misc cleanups; amend commit > message ] > Signed-off-by: Johan Hovold > --- > > Tested using CP2108 and CP2102N. > > Changes in v13 > - rewrite cp210x_gpio_get() using a shared 16 bit mask and > le16_to_cpus() > - rewrite cp210x_gpio_set() using shared 16-bit mask and state > variables > - drop pointless no-op shift and mask operations during initialisation > - reorder defines > - reword some comments > - fix some style issues > - amend commit message > > v12 can be found here: > - https://lore.kernel.org/r/20210426091244.19994-1-tupham@silabs.com > > > drivers/usb/serial/cp210x.c | 189 ++++++++++++++++++++++++++++++++---- > 1 file changed, 170 insertions(+), 19 deletions(-) > @@ -1414,52 +1468,84 @@ static int cp210x_gpio_get(struct gpio_chip *gc, unsigned int gpio) > { > struct usb_serial *serial = gpiochip_get_data(gc); > struct cp210x_serial_private *priv = usb_get_serial_data(serial); > - u8 req_type = REQTYPE_DEVICE_TO_HOST; > + u8 req_type; > + u16 mask; > int result; > - u8 buf; > - > - if (priv->partnum == CP210X_PARTNUM_CP2105) > - req_type = REQTYPE_INTERFACE_TO_HOST; > + int len; > > result = usb_autopm_get_interface(serial->interface); > if (result) > return result; > > - result = cp210x_read_vendor_block(serial, req_type, > - CP210X_READ_LATCH, &buf, sizeof(buf)); > + switch (priv->partnum) { > + case CP210X_PARTNUM_CP2105: > + req_type = REQTYPE_INTERFACE_TO_HOST; > + len = 1; > + break; > + case CP210X_PARTNUM_CP2108: > + req_type = REQTYPE_INTERFACE_TO_HOST; > + len = 2; > + break; > + default: > + req_type = REQTYPE_DEVICE_TO_HOST; > + len = 1; > + break; > + } > + > + mask = 0; > + result = cp210x_read_vendor_block(serial, req_type, CP210X_READ_LATCH, > + &mask, len); > + > usb_autopm_put_interface(serial->interface); > + > if (result < 0) > return result; > > - return !!(buf & BIT(gpio)); > + le16_to_cpus((__le16 *)&mask); Now applied after removing the (__le16 *) cast here. > + > + return !!(mask & BIT(gpio)); > } Johan