Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp856183ybl; Tue, 13 Aug 2019 03:48:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzE0oyBT0qceHHFLcdlBUQ1NCZYmu7RSkNWEfwL9c35G9BtsDnTZZa35/f3enJqddxTOsJf X-Received: by 2002:a17:902:2bc8:: with SMTP id l66mr2540011plb.222.1565693306142; Tue, 13 Aug 2019 03:48:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565693306; cv=none; d=google.com; s=arc-20160816; b=W8qynpcc4aC/PqCLyCzwIBM6eNRtrK/gtQZyM3T+QWSnE3uhxVWa1R5LlB/mxK6j9y l7y/3zlU4sKfI1KsKWYykxEkiul9y9pyWGX0qybkdKvZfuCgJ6opQpQ2jjowBGttx9HA JWZzmJ7qgvYPcLZFLmwZnEgcYUnCdi8jst1CLcpCIFhKCzpMcenFAaWsIlurcwXg+8PV 3tHOeeVFfM0bpdbb5i3Si1EsIlTWnmEUA6u2jE+ny+WUryPKmbbSjHuCDrpgMDCrlKV6 nY1b6guu4YfcCE6kmDQXt+d9AievJO820ZlMgvBAhkvb6UjRy45tQIsttEFghpBjv03H 9ACA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=upmBb2mGlv4gnwaZ2+hM8WM31wXuR9CSfXjTJTQ+4O4=; b=eOw3NBNaRs7sTm7+q84UWFBh62u54fIpsMguwyR90MA8957CZkw+9c85O6BoROP724 sDF9mns+xcKmpsnF+vNg4yth6EviEQRxTdN1GHFh2k135wTrSq5HsWCdEgfCKI/IflEH 5eGYL8jYOETHH1sPWD3m19JbbSut3iGi3fXGd9tXZDzJNIUfUlEMC1iReSrNTY5J8ZTX FQHGEJ4PfbbT5YS8CzeynugVMXtzqviL1wR9dOauedysmyH1eqbLO1WRlAP/+cxWU3Ov hY/9vJaCv7DvusUGDC4j8pG+j+rnr0Fk5V38WGzSM+JOpjr4LvkXBcizd7LdPM1Xi16Y KfsA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o19si740891pjs.54.2019.08.13.03.48.10; Tue, 13 Aug 2019 03:48:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727875AbfHMJAQ (ORCPT + 99 others); Tue, 13 Aug 2019 05:00:16 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:46480 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726769AbfHMJAQ (ORCPT ); Tue, 13 Aug 2019 05:00:16 -0400 Received: by mail-lj1-f193.google.com with SMTP id f9so2307715ljc.13; Tue, 13 Aug 2019 02:00:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=upmBb2mGlv4gnwaZ2+hM8WM31wXuR9CSfXjTJTQ+4O4=; b=scvVUb1oAq5IcYEBsWX9icptKi2OO2W4UaQJBzq9A+5/DGpnEPj/9MpfCxUNs3iv41 9XpHg+BAHwAMvC7opFT/EHL5qRjw0hHpnmxhCg8/GFuxD6q+WxBJwV9kafMx6ndwy1wu ZiuBiuftm0vIXdDCz0aanP9WCZcp2EnrOob8R8Thv4deIGIFX1OZRZuyoxr/RS0rCZAP ISNdazDQ4OrbjWvpsP+zoD/6QXasbj8oJghfGC5y/mqj9o/Y34HIMXpCDIqqxU/05KrV ti3kSOIirZHrqcO3x8JSpGFDY3ZacnxAJFH9chdd0+EEzqENsAJ78oyLQzBaaNMugr4+ dMMQ== X-Gm-Message-State: APjAAAXCAIjLQPBJ3JP/Dm1pyr0xJJ8IASeGrKFkw4K6Lfoxb9RvaEM1 k8VTjjkM3q9WOjKdsw+PmNs= X-Received: by 2002:a2e:99d5:: with SMTP id l21mr9162464ljj.205.1565686814334; Tue, 13 Aug 2019 02:00:14 -0700 (PDT) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id s21sm21644943ljm.28.2019.08.13.02.00.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Aug 2019 02:00:13 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.92) (envelope-from ) id 1hxSf3-0002xn-Aa; Tue, 13 Aug 2019 11:00:09 +0200 Date: Tue, 13 Aug 2019 11:00:09 +0200 From: Johan Hovold To: Matthew Michilot Cc: Johan Hovold , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Matthew Michilot Subject: Re: [PATCH] USB: serial: ftdi_sio: add support for FT232H CBUS gpios Message-ID: <20190813090009.GB15556@localhost> References: <20190808222348.4428-1-matthew.michilot@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190808222348.4428-1-matthew.michilot@gmail.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 08, 2019 at 10:23:48PM +0000, Matthew Michilot wrote: > Enable support for cbus gpios on FT232H. The cbus configuration is > stored in one word in the EEPROM at byte-offset 0x1a with the mux It seems to be stored in two words. > config for ACBUS5, ACBUS6, ACBUS8 and ACBUS9 (only pins that can be > configured as I/O mode). > > Tested using FT232H by configuring one ACBUS pin at a time. > > Review-by: Tim Harvey typo: Reviewed-by > Signed-off-by: Matthew Michilot > --- > drivers/usb/serial/ftdi_sio.c | 43 +++++++++++++++++++++++++++++++++++ > 1 file changed, 43 insertions(+) > > diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c > index 4b3a049561f3..c8d35faa8f61 100644 > --- a/drivers/usb/serial/ftdi_sio.c > +++ b/drivers/usb/serial/ftdi_sio.c > @@ -2023,6 +2023,46 @@ static int ftdi_read_eeprom(struct usb_serial *serial, void *dst, u16 addr, > return 0; > } > > +static int ftdi_gpio_init_ft232h(struct usb_serial_port *port) > +{ > + struct ftdi_private *priv = usb_get_serial_port_data(port); > + u8 *buf; > + u16 cbus_config; > + int ret; > + int i; > + > + buf = kmalloc(2, GFP_KERNEL); > + if (!buf) > + return -ENOMEM; > + > + ret = ftdi_read_eeprom(port->serial, buf, 0x1A, 4); You allocate 2 byte above, but write 4 bytes into buf here. Please also use lower-case hex notation consistently throughout. > + if (ret < 0) > + goto out_free; > + > + /* > + * FT232H CBUS Memory Map > + * > + * 0x1A: 8X (upper nibble -> AC5) > + * 0x1B: X8 (lower nibble -> AC6) > + * 0x1C: 88 (upper nibble -> AC8 | lower nibble -> AC9) > + */ > + cbus_config = (((buf[0] & 0xf0) | (buf[1] & 0xf)) << 8 | buf[2]); Have you verified the order you use here by enabling one gpio at a time and toggling it? The reason I ask is that the above would give a mapping of gpio0 -> AC9 gpio1 -> AC8 gpio2 -> AC6 gpio4 -> AC5 which looks backwards but may be correct. Also please drop the outer parentheses in the above expression. > + > + priv->gc.ngpio = 4; > + priv->gpio_altfunc = 0xff; > + > + for (i = 0; i < priv->gc.ngpio; ++i) { > + if ((cbus_config & 0xf) == FTDI_FTX_CBUS_MUX_GPIO) > + priv->gpio_altfunc &= ~BIT(i); > + cbus_config >>= 4; > + } > + > +out_free: > + kfree(buf); > + > + return ret; > +} > + > static int ftdi_gpio_init_ft232r(struct usb_serial_port *port) > { > struct ftdi_private *priv = usb_get_serial_port_data(port); > @@ -2104,6 +2144,9 @@ static int ftdi_gpio_init(struct usb_serial_port *port) > case FTX: > result = ftdi_gpio_init_ftx(port); > break; > + case FT232H: > + result = ftdi_gpio_init_ft232h(port); > + break; Please keep the case labels sorted alphabetically. > default: > return 0; > } Johan