From patchwork Sun Sep 30 12:27:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 10621425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 22835188F for ; Sun, 30 Sep 2018 12:30:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12A0A294DE for ; Sun, 30 Sep 2018 12:30:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 069E7294D0; Sun, 30 Sep 2018 12:30:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89FE8294BD for ; Sun, 30 Sep 2018 12:30:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728496AbeI3TCg (ORCPT ); Sun, 30 Sep 2018 15:02:36 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:42632 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728299AbeI3TCg (ORCPT ); Sun, 30 Sep 2018 15:02:36 -0400 Received: by mail-lf1-f66.google.com with SMTP id s10-v6so444864lfc.9; Sun, 30 Sep 2018 05:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rVyblo+VQ+yESTzADioS2/MobtKe4/7BSVHQtoGYLrc=; b=OfnEeRH3hMPGYrN8oxRDB0yNZd2SYWUyaME0cj0i2+MEEcaGXljeYbA5YATrcZC12A pLRLZ7Cn2lk48xICp1pADV9vUwO08iA5Vu+jEl/HUmQvxwB2t1kQhkA2k0FIt3Z0y7pB 7YIoArp9+nWabXceRtGfbDDuuKFOZViUoTM7jFWN0LgIUw7nr2rGfTfMS11mFSib4wGF 6ZJ6rckvZGLJhcPeybKZ1o6KHKT7T4Ws6mZS8Kyb6JXyQI1TeKOsozw0tT1gWzBXrq0j NQNgl3JRetzWM6E//H2LJEXAaXHgWHx23L7AgXzwAQ4P3lS8WQjCrM+IzlFurchQr5yf sc7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=rVyblo+VQ+yESTzADioS2/MobtKe4/7BSVHQtoGYLrc=; b=Xgw0UuhW4kZ0RvrhIhwD2q5h7urK8Dwd/gSknJnK2/DtKjtKApcAmNrpkgg81A+mIE U1z85ES1CFDgpzeskrvYCdX+yN+Rjs1g43ZWR49YQGRm2RsuHjtkikv1nAEf3vFG/cT5 //Gf9mjGk5FJ27SIv/U9PlJNcaRt7ksrZ0fOMVYdgVZp736+Qdn8ubu/t0DdKMZHuBH0 PtKsrhwk9orw8Q+5WVy2mIZ7tNlBkObwxio38oJHOooo/YHG6AQ7EQqSau/F/gLx5wlm rEfqdRHU9M1DxrDgDB329e2G1zLEZOOEH5XNXMaTaqQiPRP5BRGG9gnfkbIgeNxHDg63 Y73A== X-Gm-Message-State: ABuFfogOsusHl6F27fhWFZIW42O++dW9LinUlNaxhfz4jX1McoqZ8qI/ jDIPWtsAqlPV0WtWOqquNBP7NiEB X-Google-Smtp-Source: ACcGV60xWq5m3vsbqoj0xi1n05s7EjM4U6NHDJS6FxCWyzKH1yIJp9tOY1sGfRTvhYVPJQg0j1Jyqw== X-Received: by 2002:a19:2a12:: with SMTP id f18-v6mr3356455lfl.28.1538310584482; Sun, 30 Sep 2018 05:29:44 -0700 (PDT) Received: from xi.terra (c-74bee655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.190.116]) by smtp.gmail.com with ESMTPSA id g68-v6sm890337lje.44.2018.09.30.05.29.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 05:29:42 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1g6aqz-0001sT-Bj; Sun, 30 Sep 2018 14:29:41 +0200 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Karoly Pados , Loic Poulain , Linus Walleij , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 2/2] USB: serial: ftdi_sio: add support for FT232R CBUS gpios Date: Sun, 30 Sep 2018 14:27:03 +0200 Message-Id: <20180930122703.7115-3-johan@kernel.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180930122703.7115-1-johan@kernel.org> References: <20180930122703.7115-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Enable support for cbus gpios on FT232R. The cbus configuration is stored in one word in the EEPROM at offset 0x0a (byte-offset 0x14) with the mux config for CBUS0, CBUS1, CBUS2 and CBUS3 in bits 0..3, 4..7, 8..11 and 12..15, respectively. Tested using FT232RL by configuring one cbus pin at a time. Signed-off-by: Johan Hovold --- drivers/usb/serial/ftdi_sio.c | 40 +++++++++++++++++++++++++++++++++-- drivers/usb/serial/ftdi_sio.h | 3 ++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index be50b2a200aa..f1eb20acb3bb 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -2007,7 +2007,40 @@ static int ftdi_read_eeprom(struct usb_serial *serial, void *dst, u16 addr, return 0; } -static int ftx_gpioconf_init(struct usb_serial_port *port) +static int ftdi_gpio_init_ft232r(struct usb_serial_port *port) +{ + struct ftdi_private *priv = usb_get_serial_port_data(port); + u16 cbus_config; + u8 *buf; + int ret; + int i; + + buf = kmalloc(2, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + ret = ftdi_read_eeprom(port->serial, buf, 0x14, 2); + if (ret < 0) + goto out_free; + + cbus_config = le16_to_cpup((__le16 *)buf); + dev_dbg(&port->dev, "cbus_config = 0x%04x\n", cbus_config); + + priv->gc.ngpio = 4; + + priv->gpio_altfunc = 0xff; + for (i = 0; i < priv->gc.ngpio; ++i) { + if ((cbus_config & 0xf) == FTDI_FT232R_CBUS_MUX_GPIO) + priv->gpio_altfunc &= ~BIT(i); + cbus_config >>= 4; + } +out_free: + kfree(buf); + + return ret; +} + +static int ftdi_gpio_init_ftx(struct usb_serial_port *port) { struct ftdi_private *priv = usb_get_serial_port_data(port); struct usb_serial *serial = port->serial; @@ -2049,8 +2082,11 @@ static int ftdi_gpio_init(struct usb_serial_port *port) int result; switch (priv->chip_type) { + case FT232RL: + result = ftdi_gpio_init_ft232r(port); + break; case FTX: - result = ftx_gpioconf_init(port); + result = ftdi_gpio_init_ftx(port); break; default: return 0; diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h index 6cfe682f8348..a79a1325b4d9 100644 --- a/drivers/usb/serial/ftdi_sio.h +++ b/drivers/usb/serial/ftdi_sio.h @@ -457,7 +457,8 @@ enum ftdi_sio_baudrate { #define FTDI_SIO_READ_EEPROM_REQUEST_TYPE 0xc0 #define FTDI_SIO_READ_EEPROM_REQUEST FTDI_SIO_READ_EEPROM -#define FTDI_FTX_CBUS_MUX_GPIO 8 +#define FTDI_FTX_CBUS_MUX_GPIO 0x8 +#define FTDI_FT232R_CBUS_MUX_GPIO 0xa /* Descriptors returned by the device