From patchwork Mon Sep 23 02:24:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ji-Ze Hong (Peter Hong)" X-Patchwork-Id: 11155985 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 643A713BD for ; Mon, 23 Sep 2019 02:25:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 433552133F for ; Mon, 23 Sep 2019 02:25:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mLnayBw3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391597AbfIWCY6 (ORCPT ); Sun, 22 Sep 2019 22:24:58 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:42664 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389942AbfIWCY6 (ORCPT ); Sun, 22 Sep 2019 22:24:58 -0400 Received: by mail-pg1-f195.google.com with SMTP id z12so7105909pgp.9; Sun, 22 Sep 2019 19:24:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aY/BKnDI/88NXwfuI9VMBOVirG9SdPdDsfV1k3v+hLY=; b=mLnayBw3yrjgoV4kgyUTkALYEhAoITnSQ7AAH6NKyRN7qa+4zsy4WW1qkA3MLVZ3r+ a1YUH1s4v/BATnwqzJDFLnzNrJDnfSGbMKqv3+2CHjNfxtywVWI9Pm/GJylVTNRrVszm +o7WBSFVBvVo0fkjmyNque+iU7+GvysvHWlE3cRxZWOdQJ000tzpUBoUgei9W8FF6HeL 63xn96Zue15ScgHuggJ7VbESf28TQh/J6teuXjqSTz3NuQ3KRV0M2f6tkiApguCDIsEZ OPzrY0NHRPocdN/jI7odRojfgpF+bvbXsLHkGshmID8Desi82E2J0mGCGGLb/vxU3fKE Cc+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aY/BKnDI/88NXwfuI9VMBOVirG9SdPdDsfV1k3v+hLY=; b=lJEZZmdlFNu4A2mCELjsQowkqS5ccwEXJdSxv97qFKqFk+PJcz48TMdgHFZbm+JI3o OgCJpvjs9ijMoy760RaHON37j2DVlP/ZAqqiIdo7kiIl2Leteijg5MoozZNYiQUlFlMX 7oM40algwL27aop0/wLrsVzWF67/k16gekivuowOvEIx3A7fy6n3UuQjOOKkRuSIXHkV 7N9lZsjwLYT1tmz7FaUY1TUbdDESCp7jLJ3gctBcdb/Eq3fTFowIqCs9UOfjCUJ/jxx6 RG8xtHTRdsMqiN0ozd6xE9f6Z3Br5WkGhTDTfYDcJZCuaGhlTmyouF3gbMcezFqggE9g 5UBA== X-Gm-Message-State: APjAAAVL7bD32rNXu3DxyCRivOkmuu4mUmXW9VD7RSYCEIXJ1TL08CYL KSWpOk0HfySL/scU5GdtEyuJ8X8e X-Google-Smtp-Source: APXvYqyc11+ML3LCRK9q6OJyAt8Kj6lnHbHIdfpDpWRXrhydB0oSUNszpJfYl9HHw5vsyshtt6kucg== X-Received: by 2002:a65:5186:: with SMTP id h6mr26981100pgq.304.1569205497619; Sun, 22 Sep 2019 19:24:57 -0700 (PDT) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id q30sm10348854pja.18.2019.09.22.19.24.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Sep 2019 19:24:57 -0700 (PDT) From: "Ji-Ze Hong (Peter Hong)" X-Google-Original-From: "Ji-Ze Hong (Peter Hong)" To: johan@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, peter_hong@fintek.com.tw, "Ji-Ze Hong (Peter Hong)" Subject: [PATCH V2 1/7] USB: serial: f81232: Extract LSR handler Date: Mon, 23 Sep 2019 10:24:43 +0800 Message-Id: <20190923022449.10952-2-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> References: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Extract LSR handler to function. Signed-off-by: Ji-Ze Hong (Peter Hong) --- drivers/usb/serial/f81232.c | 53 +++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index 43fa1f0716b7..c07d376c743d 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -322,10 +322,38 @@ static void f81232_read_int_callback(struct urb *urb) __func__, retval); } +static char f81232_handle_lsr(struct usb_serial_port *port, u8 lsr) +{ + struct f81232_private *priv = usb_get_serial_port_data(port); + char tty_flag = TTY_NORMAL; + + if (!(lsr & UART_LSR_BRK_ERROR_BITS)) + return tty_flag; + + if (lsr & UART_LSR_BI) { + tty_flag = TTY_BREAK; + port->icount.brk++; + usb_serial_handle_break(port); + } else if (lsr & UART_LSR_PE) { + tty_flag = TTY_PARITY; + port->icount.parity++; + } else if (lsr & UART_LSR_FE) { + tty_flag = TTY_FRAME; + port->icount.frame++; + } + + if (lsr & UART_LSR_OE) { + port->icount.overrun++; + schedule_work(&priv->lsr_work); + tty_insert_flip_char(&port->port, 0, TTY_OVERRUN); + } + + return tty_flag; +} + static void f81232_process_read_urb(struct urb *urb) { struct usb_serial_port *port = urb->context; - struct f81232_private *priv = usb_get_serial_port_data(port); unsigned char *data = urb->transfer_buffer; char tty_flag; unsigned int i; @@ -341,29 +369,8 @@ static void f81232_process_read_urb(struct urb *urb) /* bulk-in data: [LSR(1Byte)+DATA(1Byte)][LSR(1Byte)+DATA(1Byte)]... */ for (i = 0; i < urb->actual_length; i += 2) { - tty_flag = TTY_NORMAL; lsr = data[i]; - - if (lsr & UART_LSR_BRK_ERROR_BITS) { - if (lsr & UART_LSR_BI) { - tty_flag = TTY_BREAK; - port->icount.brk++; - usb_serial_handle_break(port); - } else if (lsr & UART_LSR_PE) { - tty_flag = TTY_PARITY; - port->icount.parity++; - } else if (lsr & UART_LSR_FE) { - tty_flag = TTY_FRAME; - port->icount.frame++; - } - - if (lsr & UART_LSR_OE) { - port->icount.overrun++; - schedule_work(&priv->lsr_work); - tty_insert_flip_char(&port->port, 0, - TTY_OVERRUN); - } - } + tty_flag = f81232_handle_lsr(port, lsr); if (port->port.console && port->sysrq) { if (usb_serial_handle_sysrq_char(port, data[i + 1])) From patchwork Mon Sep 23 02:24:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ji-Ze Hong (Peter Hong)" X-Patchwork-Id: 11155987 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F0021902 for ; Mon, 23 Sep 2019 02:25:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6DA8120820 for ; Mon, 23 Sep 2019 02:25:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eqPXj1vo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391736AbfIWCZB (ORCPT ); Sun, 22 Sep 2019 22:25:01 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:34021 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389942AbfIWCZA (ORCPT ); Sun, 22 Sep 2019 22:25:00 -0400 Received: by mail-pf1-f193.google.com with SMTP id b128so8195523pfa.1; Sun, 22 Sep 2019 19:25:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+hRV3PvqEAgfOnsE7U5CSmdgBj+kc3hqORfpzzvqnEI=; b=eqPXj1vohRUH7v65sepk/7m5P/sn13gC5QLljZajsGOmKmK4tb4pNVSJuyEg8Vdft1 WeE6eMICoqR4ot6Ig2Ai1zwlu0rffjaPCBc2Bla6BeoZjGQ4+G+itLAfM6MnUZDjD77j fZ1D/LTlJhtCb8EmKF1IHfZxOsIvRCB31EoWkBUdi5V9L8oHj/yrnLWCXg4bxcCNJsHD MBlaEKugmo2kML3avt5VW2ZL+5X2ki96CESDTj8U4WJ3Sd0gHzmNzIa9WO/DfDNsexPy zDVDFlwzICeazdeT54O5hGNMCGKLVZM4pphRVhoPwiLv9/r9KoyfWrm1oA3Fh7DVKfmB Cllg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+hRV3PvqEAgfOnsE7U5CSmdgBj+kc3hqORfpzzvqnEI=; b=TCXlau7B+tia0wkWLVn9Lqf/PqdKrqzJETzrrTZ9YuqLAKqRHbo8Js4IRBZ7JcJymN 00ZNkTbTiIf/8nQNb3jRKZuh2xO+t4Sv2UWtsZt9SiZ2s2ukJqGzEYHtFBhaWWneJvNP LVKisYRyFfnIvQoq2QLhELh1N+GuWSzJjITpfSeNO4YIZppVJaCvL12ZJRrYZmRHnGU4 m4aco66p34W+OXD8kXpO105waxsjky982vLyCajYMJ82f1i7NjkuXZYnGzAbdkbGm8yy x9C3iUYf/IUynguIQfVreF2xffLigevQRFJLrceLOLC3aQE8QlM8alDxx4U71+yb3fnj 5nXQ== X-Gm-Message-State: APjAAAVlbpKgCdKUds0hGN2wv68QkobEH0awOOwJgKZGc6FoPhsopMSM ibK9Y5S+q5frilq5kD8jUMA= X-Google-Smtp-Source: APXvYqwIsSuUpy2R1+0gp2ahpvK4IFIHEoSTWpksEK04GIv0C7Ga+EhHp+joNIeLO9+gRWslf1zmNg== X-Received: by 2002:a65:6550:: with SMTP id a16mr25351747pgw.115.1569205499830; Sun, 22 Sep 2019 19:24:59 -0700 (PDT) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id u5sm11564283pfl.25.2019.09.22.19.24.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Sep 2019 19:24:59 -0700 (PDT) From: "Ji-Ze Hong (Peter Hong)" X-Google-Original-From: "Ji-Ze Hong (Peter Hong)" To: johan@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, peter_hong@fintek.com.tw, "Ji-Ze Hong (Peter Hong)" Subject: [PATCH V2 2/7] USB: serial: f81232: Add tx_empty function Date: Mon, 23 Sep 2019 10:24:44 +0800 Message-Id: <20190923022449.10952-3-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> References: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add tx_empty() function for F81232. Signed-off-by: Ji-Ze Hong (Peter Hong) --- drivers/usb/serial/f81232.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index c07d376c743d..b42b3738a768 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -685,6 +685,23 @@ static void f81232_dtr_rts(struct usb_serial_port *port, int on) f81232_set_mctrl(port, 0, TIOCM_DTR | TIOCM_RTS); } +static bool f81232_tx_empty(struct usb_serial_port *port) +{ + int status; + u8 tmp; + + status = f81232_get_register(port, LINE_STATUS_REGISTER, &tmp); + if (status) { + dev_err(&port->dev, "get LSR status failed: %d\n", status); + return false; + } + + if ((tmp & UART_LSR_TEMT) != UART_LSR_TEMT) + return false; + + return true; +} + static int f81232_carrier_raised(struct usb_serial_port *port) { u8 msr; @@ -820,6 +837,7 @@ static struct usb_serial_driver f81232_device = { .tiocmget = f81232_tiocmget, .tiocmset = f81232_tiocmset, .tiocmiwait = usb_serial_generic_tiocmiwait, + .tx_empty = f81232_tx_empty, .process_read_urb = f81232_process_read_urb, .read_int_callback = f81232_read_int_callback, .port_probe = f81232_port_probe, From patchwork Mon Sep 23 02:24:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ji-Ze Hong (Peter Hong)" X-Patchwork-Id: 11155997 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 718B513BD for ; Mon, 23 Sep 2019 02:25:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4F9B62133F for ; Mon, 23 Sep 2019 02:25:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="njoTGX4w" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391830AbfIWCZD (ORCPT ); Sun, 22 Sep 2019 22:25:03 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:33599 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389942AbfIWCZD (ORCPT ); Sun, 22 Sep 2019 22:25:03 -0400 Received: by mail-pf1-f195.google.com with SMTP id q10so8205125pfl.0; Sun, 22 Sep 2019 19:25:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kqam0JDuiFgCeWwjWzay5+sVPUI3XqH00sjmb3q+iqY=; b=njoTGX4wRr8W9acQvSFkFjiiqh4lATfQTbTVG5qz1WImyEgKJI5JX9gBIk6x6P1X5j TnyYZaVclQ7vZDAu3hvrWliBUNgjNvHBs4p990ePYxSDxloWF7yNFy590E9/uM9rhNe6 MRA8+z8MSkJ+cNt4bEM4yDo3oEVXtEk/Vkjftd2PYWV8m1YMt4snY+8YQ5Tz/fN6aw/W XehvtL1JifbN9gnBEf3fD6bJVmNWHWYe7LW+kvbOH9jypLQpoV+ruZ3G3BnAUFr5++xX kdrqf70YArspXylYo5kTxL7AJWayU4NIrXgQh1Mwt8X/EH1C1UejhkkpB/jLrNdvnRFO LN6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kqam0JDuiFgCeWwjWzay5+sVPUI3XqH00sjmb3q+iqY=; b=bjLgLgXxwsgNffPZjcSib5SWYTfHEIie0XaQiAbQ/uuutTlLF7mvGroRVejgEUylf9 oeK2IMITQH+A/7MKt3PtSY0w9eRajowZR5g9vaPuETYaH+4GQ494EVvSPhaBsNGz0IMr FQJ24ABVjn9FinTYMPIMPPZRNwgrMvgltJZV+v7UQXvWjdP8Q6gjxJlVlOsGQV/lgUeT ZyxVrYt3TZcgB/LR0wBJDf84gUmXdHe2Rp4iENkxh7LpA9ob0UIQYnp8czbV/V9aEPrl kG9VrKT/weCKaJtV6zjT7kEvK8BqUErfeYomU0tyuBiRHG8nmF1g7ux4KtEbPyM4+QZc gHOQ== X-Gm-Message-State: APjAAAU4kyLvHk7fs2kR0Q0iWtAN/PXqZPms77eHRsK6VFC3DGdJ+sgz aUS2nale2ksabqQ+G6qwv20= X-Google-Smtp-Source: APXvYqy09O4Rz1jR1oouHUUvz88mjxntedSoXqnBH4c9NkdtZWqx2Fs6d4GRx1HK7Fqem+doaPxfjQ== X-Received: by 2002:a63:2943:: with SMTP id p64mr25648966pgp.98.1569205502194; Sun, 22 Sep 2019 19:25:02 -0700 (PDT) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id s17sm10580628pgg.77.2019.09.22.19.25.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Sep 2019 19:25:01 -0700 (PDT) From: "Ji-Ze Hong (Peter Hong)" X-Google-Original-From: "Ji-Ze Hong (Peter Hong)" To: johan@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, peter_hong@fintek.com.tw, "Ji-Ze Hong (Peter Hong)" Subject: [PATCH V2 3/7] USB: serial: f81232: Use devm_kzalloc Date: Mon, 23 Sep 2019 10:24:45 +0800 Message-Id: <20190923022449.10952-4-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> References: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use devm_kzalloc() to replace kzalloc(). Signed-off-by: Ji-Ze Hong (Peter Hong) --- drivers/usb/serial/f81232.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index b42b3738a768..e4db0aec9af0 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -756,7 +756,7 @@ static int f81232_port_probe(struct usb_serial_port *port) { struct f81232_private *priv; - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc(&port->dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; @@ -772,16 +772,6 @@ static int f81232_port_probe(struct usb_serial_port *port) return 0; } -static int f81232_port_remove(struct usb_serial_port *port) -{ - struct f81232_private *priv; - - priv = usb_get_serial_port_data(port); - kfree(priv); - - return 0; -} - static int f81232_suspend(struct usb_serial *serial, pm_message_t message) { struct usb_serial_port *port = serial->port[0]; @@ -841,7 +831,6 @@ static struct usb_serial_driver f81232_device = { .process_read_urb = f81232_process_read_urb, .read_int_callback = f81232_read_int_callback, .port_probe = f81232_port_probe, - .port_remove = f81232_port_remove, .suspend = f81232_suspend, .resume = f81232_resume, }; From patchwork Mon Sep 23 02:24:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ji-Ze Hong (Peter Hong)" X-Patchwork-Id: 11155995 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D6C0A14DB for ; Mon, 23 Sep 2019 02:25:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB837214AF for ; Mon, 23 Sep 2019 02:25:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GjWzis3U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404005AbfIWCZG (ORCPT ); Sun, 22 Sep 2019 22:25:06 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36117 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389942AbfIWCZF (ORCPT ); Sun, 22 Sep 2019 22:25:05 -0400 Received: by mail-pf1-f194.google.com with SMTP id y22so8189481pfr.3; Sun, 22 Sep 2019 19:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JGKuHnPmGZm1puHgATQylobqDcGcrhmJSBMIZlLK5Fw=; b=GjWzis3U17iJ8mc0+s8K1nlBfufJz9fM+FEJo+oHciX9FE8qSnM/SCsxggaZvqJcrj M5H9e4HOGV1ps6nZAazrXS+1D82v7a4ngHEoY414h9n9ISoWU89Na8kWb4ZGV2tomG3W iXf6oopdJcQhwONMc2x0Vy6s0n8qtxF39qknXL1vyPE2opaFem3XNrvNBiHo0x0axCHm zcqUhbbbZavOgIt7LFdyRf1jEaWRschi997YX3iGHkvIvZzRd7CEn34fP8kEeiW670c0 DIN4NqIEkhYtwPDfXOxjHEVfgHULH1PVQIQ20Tn9ENSQI5A5Cf6FMbP7XUXRvpISJGm/ Ju1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JGKuHnPmGZm1puHgATQylobqDcGcrhmJSBMIZlLK5Fw=; b=Q6IYFPu334VwlVQ/Npo0qJiOdpSvowRqisF7289JISJ+I3dIlSmNM66RQjitO/zp4o yY5s/ztEUAWdF7q0ElQDtsvHp5QXm/pJR3OHVk5zxAg5espVuRR94uhe7GJtvGFm0DkH Mp+UCM0Y9KWMSrbKBbl1/ab4wuRyBvvjwyDaFEho2t9fQU3Oum1rFrxzjm98geFQjOMh hp9Qj2WA0BSaKJcEAKK4kK/LAAS1/6U4JvoE9oGbnqcme09OOj9ynaRUO3yrG8k0jbvZ aZilnV4592enAPGTIubULTWwecJDobsP3/ENMjVdNBBonBdNdXqSqkGvopMpR7KNOA+/ 4F7w== X-Gm-Message-State: APjAAAVoeM+C7ld0nExX1qUymXyy35XdI4/0sTxkFoJZwo5NuQMn/+6x XyMqHc4sVtkOqX8FQO7NoCD/BoCt X-Google-Smtp-Source: APXvYqwOEHsfzWvR6/JdKc6IG9wULFtnFE6wrFxDpQc+OLT7BqRftqLvu8QhlW+1qdRCl/HB8RSh3g== X-Received: by 2002:a17:90a:c583:: with SMTP id l3mr17934540pjt.68.1569205504465; Sun, 22 Sep 2019 19:25:04 -0700 (PDT) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id v32sm10141215pga.38.2019.09.22.19.25.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Sep 2019 19:25:03 -0700 (PDT) From: "Ji-Ze Hong (Peter Hong)" X-Google-Original-From: "Ji-Ze Hong (Peter Hong)" To: johan@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, peter_hong@fintek.com.tw, "Ji-Ze Hong (Peter Hong)" Subject: [PATCH V2 4/7] USB: serial: f81232: Add F81534A support Date: Mon, 23 Sep 2019 10:24:46 +0800 Message-Id: <20190923022449.10952-5-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> References: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The Fintek F81532A/534A/535/536 is USB-to-2/4/8/12 serial ports device and the serial port is default disabled when plugin computer. The IC is contains devices as following: 1. HUB (all devices is connected with this hub) 2. GPIO/Control device. (enable serial port and control GPIOs) 3. serial port 1 to x (2/4/8/12) It's most same with F81232, the UART device is difference as follow: 1. TX/RX bulk size is 128/512bytes 2. RX bulk layout change: F81232: [LSR(1Byte)+DATA(1Byte)][LSR(1Byte)+DATA(1Byte)]... F81534A:[LEN][Data.....][LSR] Signed-off-by: Ji-Ze Hong (Peter Hong) --- drivers/usb/serial/f81232.c | 131 ++++++++++++++++++++++++++++++++++-- 1 file changed, 127 insertions(+), 4 deletions(-) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index e4db0aec9af0..36a17aedc2ae 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* * Fintek F81232 USB to serial adaptor driver + * Fintek F81532A/534A/535/536 USB to 2/4/8/12 serial adaptor driver * * Copyright (C) 2012 Greg Kroah-Hartman (gregkh@linuxfoundation.org) * Copyright (C) 2012 Linux Foundation @@ -21,11 +22,36 @@ #include #include +#define F81232_ID \ + { USB_DEVICE(0x1934, 0x0706) } /* 1 port UART device */ + +#define F81534A_SERIES_ID \ + { USB_DEVICE(0x2c42, 0x1602) }, /* In-Box 2 port UART device */ \ + { USB_DEVICE(0x2c42, 0x1604) }, /* In-Box 4 port UART device */ \ + { USB_DEVICE(0x2c42, 0x1605) }, /* In-Box 8 port UART device */ \ + { USB_DEVICE(0x2c42, 0x1606) }, /* In-Box 12 port UART device */ \ + { USB_DEVICE(0x2c42, 0x1608) }, /* Non-Flash type */ \ + { USB_DEVICE(0x2c42, 0x1632) }, /* 2 port UART device */ \ + { USB_DEVICE(0x2c42, 0x1634) }, /* 4 port UART device */ \ + { USB_DEVICE(0x2c42, 0x1635) }, /* 8 port UART device */ \ + { USB_DEVICE(0x2c42, 0x1636) } /* 12 port UART device */ + static const struct usb_device_id id_table[] = { - { USB_DEVICE(0x1934, 0x0706) }, + F81232_ID, + { } /* Terminating entry */ +}; + +static const struct usb_device_id f81534a_id_table[] = { + F81534A_SERIES_ID, + { } /* Terminating entry */ +}; + +static const struct usb_device_id all_serial_id_table[] = { + F81232_ID, + F81534A_SERIES_ID, { } /* Terminating entry */ }; -MODULE_DEVICE_TABLE(usb, id_table); +MODULE_DEVICE_TABLE(usb, all_serial_id_table); /* Maximum baudrate for F81232 */ #define F81232_MAX_BAUDRATE 1500000 @@ -35,6 +61,10 @@ MODULE_DEVICE_TABLE(usb, id_table); #define F81232_REGISTER_REQUEST 0xa0 #define F81232_GET_REGISTER 0xc0 #define F81232_SET_REGISTER 0x40 +#define F81534A_REGISTER_REQUEST F81232_REGISTER_REQUEST +#define F81534A_GET_REGISTER F81232_GET_REGISTER +#define F81534A_SET_REGISTER F81232_SET_REGISTER +#define F81534A_ACCESS_REG_RETRY 2 #define SERIAL_BASE_ADDRESS 0x0120 #define RECEIVE_BUFFER_REGISTER (0x00 + SERIAL_BASE_ADDRESS) @@ -61,6 +91,11 @@ MODULE_DEVICE_TABLE(usb, id_table); #define F81232_CLK_14_77_MHZ (BIT(1) | BIT(0)) #define F81232_CLK_MASK GENMASK(1, 0) +#define F81534A_MODE_CONF_REG 0x107 +#define F81534A_TRIGGER_MASK GENMASK(3, 2) +#define F81534A_TRIGGER_MULTPILE_4X BIT(3) +#define F81534A_FIFO_128BYTE (BIT(1) | BIT(0)) + struct f81232_private { struct mutex lock; u8 modem_control; @@ -383,6 +418,46 @@ static void f81232_process_read_urb(struct urb *urb) tty_flip_buffer_push(&port->port); } +static void f81534a_process_read_urb(struct urb *urb) +{ + struct usb_serial_port *port = urb->context; + unsigned char *data = urb->transfer_buffer; + char tty_flag; + unsigned int i; + u8 lsr; + u8 len; + + if (urb->actual_length < 3) { + dev_err(&port->dev, "error actual_length: %d\n", + urb->actual_length); + return; + } + + len = data[0]; + if (len != urb->actual_length) { + dev_err(&port->dev, "len(%d) != urb->actual_length(%d)\n", len, + urb->actual_length); + return; + } + + /* bulk-in data: [LEN][Data.....][LSR] */ + lsr = data[len - 1]; + tty_flag = f81232_handle_lsr(port, lsr); + + if (port->port.console && port->sysrq) { + for (i = 1; i < urb->actual_length - 1; ++i) + if (!usb_serial_handle_sysrq_char(port, data[i])) + tty_insert_flip_char(&port->port, data[i], + tty_flag); + } else { + tty_insert_flip_string_fixed_flag(&port->port, &data[1], + tty_flag, + urb->actual_length - 2); + } + + tty_flip_buffer_push(&port->port); +} + static void f81232_break_ctl(struct tty_struct *tty, int break_state) { struct usb_serial_port *port = tty->driver_data; @@ -666,6 +741,23 @@ static int f81232_open(struct tty_struct *tty, struct usb_serial_port *port) return 0; } +static int f81534a_open(struct tty_struct *tty, struct usb_serial_port *port) +{ + int status; + u8 val; + + val = F81534A_TRIGGER_MULTPILE_4X | F81534A_FIFO_128BYTE; + status = f81232_set_mask_register(port, F81534A_MODE_CONF_REG, + F81534A_TRIGGER_MASK | F81534A_FIFO_128BYTE, val); + if (status) { + dev_err(&port->dev, "failed to set MODE_CONF_REG: %d\n", + status); + return status; + } + + return f81232_open(tty, port); +} + static void f81232_close(struct usb_serial_port *port) { struct f81232_private *port_priv = usb_get_serial_port_data(port); @@ -772,6 +864,11 @@ static int f81232_port_probe(struct usb_serial_port *port) return 0; } +static int f81534a_port_probe(struct usb_serial_port *port) +{ + return f81232_port_probe(port); +} + static int f81232_suspend(struct usb_serial *serial, pm_message_t message) { struct usb_serial_port *port = serial->port[0]; @@ -835,14 +932,40 @@ static struct usb_serial_driver f81232_device = { .resume = f81232_resume, }; +static struct usb_serial_driver f81534a_device = { + .driver = { + .owner = THIS_MODULE, + .name = "f81534a", + }, + .id_table = f81534a_id_table, + .num_ports = 1, + .open = f81534a_open, + .close = f81232_close, + .dtr_rts = f81232_dtr_rts, + .carrier_raised = f81232_carrier_raised, + .get_serial = f81232_get_serial_info, + .break_ctl = f81232_break_ctl, + .set_termios = f81232_set_termios, + .tiocmget = f81232_tiocmget, + .tiocmset = f81232_tiocmset, + .tiocmiwait = usb_serial_generic_tiocmiwait, + .tx_empty = f81232_tx_empty, + .process_read_urb = f81534a_process_read_urb, + .read_int_callback = f81232_read_int_callback, + .port_probe = f81534a_port_probe, + .suspend = f81232_suspend, + .resume = f81232_resume, +}; + static struct usb_serial_driver * const serial_drivers[] = { &f81232_device, + &f81534a_device, NULL, }; -module_usb_serial_driver(serial_drivers, id_table); +module_usb_serial_driver(serial_drivers, all_serial_id_table); -MODULE_DESCRIPTION("Fintek F81232 USB to serial adaptor driver"); +MODULE_DESCRIPTION("Fintek F81232/532A/534A/535/536 USB to serial driver"); MODULE_AUTHOR("Greg Kroah-Hartman "); MODULE_AUTHOR("Peter Hong "); MODULE_LICENSE("GPL v2"); From patchwork Mon Sep 23 02:24:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ji-Ze Hong (Peter Hong)" X-Patchwork-Id: 11155991 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B7B0B13BD for ; Mon, 23 Sep 2019 02:25:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 948EC2133F for ; Mon, 23 Sep 2019 02:25:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oR7a+Arf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404057AbfIWCZI (ORCPT ); Sun, 22 Sep 2019 22:25:08 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:33606 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404042AbfIWCZH (ORCPT ); Sun, 22 Sep 2019 22:25:07 -0400 Received: by mail-pf1-f196.google.com with SMTP id q10so8205254pfl.0; Sun, 22 Sep 2019 19:25:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RtXh1F19FRrx1+dh9ZErv4CrcLDH1VpHTstJEgZnqvA=; b=oR7a+Arff/D/BXrTMogPjLPUoaBaJTjLaTypIqtrLhCvq06duqizyXI1wDN+agEUb0 vJB6JL8gZmvNISBKlYRpVMU753MlvmBnvdiBfEFKfZPcZKWGYryW90O3PGQGLjEQyTh7 LfZqkhrr+9Hk8C/Jynu+Tk2F5gHPXO9vUHoxEXNu2GA4y0tz5UR4MsUU+89gb30HNIBw taQzoInPBUMC83j9MuofAdoFfNZrejIIIM8ysGsnHG0ePid1zFS/uTcJDYt/9Qup92ox oVdG8dqt5QLpyGJXDQsX4kj1kNcDYOfRwcJgfh/OmBqbxtpnib2kY4BpB922cr0eEoW2 qJVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RtXh1F19FRrx1+dh9ZErv4CrcLDH1VpHTstJEgZnqvA=; b=tIvPeh+ig0hY1DcKUiJLPzwoart/RBfrKY43QOrBJj616seLBkhV1f1jyVRWOPYdSB 4E7MeyrN5Zr3sdtcAPzFTVgRL6Tjuf+tvREXAwSLhiePFT/p6xuHNpnzwoc6qc9BkRJ+ 91eUJBRu5ktbMjfVV/JQOxvdrBKn+p1Razibf2nwJAWPlzEGXjWH/gqeO332GsD4KVjY pdU5jsI7wxXaU7THMJNfr3FO/NDO7Sa9yddhjHsb8TOtZF4R0xT+NMx5NR4nUhfHMPra YlDxmQHrdRuXe6iJyPeHOsoU9uL4qwhBzkenHD6l5LRFJnmZRYGJX1FzE/+7WMxJVcjk coWw== X-Gm-Message-State: APjAAAVE3p6raEgbkd/ffeQXAWyQSI6lZ08eJsuzxgfTYpSRW6/yf7yy neonM0YOeNXfAE0ErgVtihQ= X-Google-Smtp-Source: APXvYqxuaCMRhoaztt2AFxtv9Jjsw1wdZebHeK+oHlCcqae63+/OU7waV4DTZP9fTcGHyqAkW6EmfA== X-Received: by 2002:a63:304:: with SMTP id 4mr27085028pgd.13.1569205506755; Sun, 22 Sep 2019 19:25:06 -0700 (PDT) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id a18sm8342106pgm.25.2019.09.22.19.25.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Sep 2019 19:25:05 -0700 (PDT) From: "Ji-Ze Hong (Peter Hong)" X-Google-Original-From: "Ji-Ze Hong (Peter Hong)" To: johan@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, peter_hong@fintek.com.tw, "Ji-Ze Hong (Peter Hong)" Subject: [PATCH V2 5/7] USB: serial: f81232: Set F81534A serial port with RS232 mode Date: Mon, 23 Sep 2019 10:24:47 +0800 Message-Id: <20190923022449.10952-6-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> References: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The Fintek F81532A/534A/535/536 is USB-to-2/4/8/12 serial ports device and the serial ports are default disabled. Each port contains max 3 pins GPIO and the 3 pins are default pull high with input mode. When the serial port had activated (running probe()), we'll transform the 3 pins from GPIO function publicly to control Tranceiver privately use. We'll default set to 0/0/1 for control transceiver to RS232 mode. Otherwise, If the serial port is not active, the 3 pins is in GPIO mode and controlled by global GPIO device with VID/PID: 2c42/16f8. Signed-off-by: Ji-Ze Hong (Peter Hong) --- drivers/usb/serial/f81232.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index 36a17aedc2ae..01cb5a5ea1d2 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -96,6 +96,15 @@ MODULE_DEVICE_TABLE(usb, all_serial_id_table); #define F81534A_TRIGGER_MULTPILE_4X BIT(3) #define F81534A_FIFO_128BYTE (BIT(1) | BIT(0)) +/* Serial port self GPIO control, 2bytes [control&output data][input data] */ +#define F81534A_GPIO_REG 0x10e +#define F81534A_GPIO_MODE2_DIR BIT(6) /* 1: input, 0: output */ +#define F81534A_GPIO_MODE1_DIR BIT(5) +#define F81534A_GPIO_MODE0_DIR BIT(4) +#define F81534A_GPIO_MODE2_OUTPUT BIT(2) +#define F81534A_GPIO_MODE1_OUTPUT BIT(1) +#define F81534A_GPIO_MODE0_OUTPUT BIT(0) + struct f81232_private { struct mutex lock; u8 modem_control; @@ -866,6 +875,14 @@ static int f81232_port_probe(struct usb_serial_port *port) static int f81534a_port_probe(struct usb_serial_port *port) { + int status; + + /* tri-state with pull-high, default RS232 Mode */ + status = f81232_set_register(port, F81534A_GPIO_REG, + F81534A_GPIO_MODE2_DIR); + if (status) + return status; + return f81232_port_probe(port); } From patchwork Mon Sep 23 02:24:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ji-Ze Hong (Peter Hong)" X-Patchwork-Id: 11155989 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5A7613BD for ; Mon, 23 Sep 2019 02:25:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 99E9A2133F for ; Mon, 23 Sep 2019 02:25:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vCCaaKEA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404150AbfIWCZM (ORCPT ); Sun, 22 Sep 2019 22:25:12 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:37481 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404127AbfIWCZK (ORCPT ); Sun, 22 Sep 2019 22:25:10 -0400 Received: by mail-pf1-f195.google.com with SMTP id y5so8185335pfo.4; Sun, 22 Sep 2019 19:25:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=m2Jm8H+k+T9Y9bpQG3jtDNyGk+0U+Plvy/NdnRGLxT0=; b=vCCaaKEA15fTyVj6g3hsk+I78MOez77YEMhwJbxgTWTrF9nQHRzliKL1sZ8mAQgWpT OWdVsa0T27Ym/ic62FY4O7elCq3EyvFWz1BUXLgX60HxYMizNNgw5cdCweuI1seYPQJS q0KJwe6poBBFPfW6dEFpp+yo0o/2OX3/X7Am//j7YtpPtfjiVsPVxlVWV810OoiYCPMe /RhSBWoiP16BVgjndIvyOB6pj1bb7T5wXcFBrwRhJdK6CnvM4fndo2DJ1QSfgZMtYOEe hOTTCMO0iaKwWZo3KfpdoG/xu6l1px/V4rMLqk2hCV3Qughmitq69c8A0qX59Npt1rUb XNEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=m2Jm8H+k+T9Y9bpQG3jtDNyGk+0U+Plvy/NdnRGLxT0=; b=PZdw1N/1y1aZ17aejhwOV5Xt+bzhOo8HoXsO2OSjYkWJuk9eO5/qnUlrHWklWyfMuO B1crVt/vnsbNnf2DM0gvc1zasKBAeQ/yzh78E7JeePzsOUOz7orL9KDrcn2RMFGpeS/8 7Qqnf44A1v66wR4C3q4LLZ2OxXsGYhGP+g8QxSllAUfP5SSn4Msa50S2FmmG7cAFYREN 0nJne9fJ4cbBRtN7zFRn6Em8+8PGbtdwue/m669BF1tmzgkeuv+qlvpkxMW8eHdN0jJb TPpC+G1zE1vwdSk9EhfeGNwxdY+bz8AXsP5ZzFJXCtCc/j1zStZYD5plO0SlRGR87580 SJxA== X-Gm-Message-State: APjAAAXezEmsuK5psBwKqRpj2wozLEWwS1Cc0qs6wf8aiaxBozMxX3K/ uucMpriiPFhPJpxY3q2kggo= X-Google-Smtp-Source: APXvYqznEq2X3ueRTvigAoVd36h8hWhaaqpD/3VxLXGmXk4aUOwisrAxoWcM32nXRyNI9fVdZeyZKQ== X-Received: by 2002:a63:3c08:: with SMTP id j8mr26477024pga.72.1569205509548; Sun, 22 Sep 2019 19:25:09 -0700 (PDT) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id 20sm9759647pfp.153.2019.09.22.19.25.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Sep 2019 19:25:08 -0700 (PDT) From: "Ji-Ze Hong (Peter Hong)" X-Google-Original-From: "Ji-Ze Hong (Peter Hong)" To: johan@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, peter_hong@fintek.com.tw, "Ji-Ze Hong (Peter Hong)" Subject: [PATCH V2 6/7] USB: serial: f81232: Add generator for F81534A Date: Mon, 23 Sep 2019 10:24:48 +0800 Message-Id: <20190923022449.10952-7-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> References: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The Fintek F81534A series is contains 1 HUB / 1 GPIO device / n UARTs, but the UART is default disable and need enabled by GPIO device(2c42/16F8). When F81534A plug to host, we can only see 1 HUB & 1 GPIO device and we need write 0x8fff to GPIO device register F81534A_CMD_ENABLE_PORT(116h) to enable all available serial ports. Signed-off-by: Ji-Ze Hong (Peter Hong) --- drivers/usb/serial/f81232.c | 135 +++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index 01cb5a5ea1d2..82cc1e6cff62 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -36,6 +36,9 @@ { USB_DEVICE(0x2c42, 0x1635) }, /* 8 port UART device */ \ { USB_DEVICE(0x2c42, 0x1636) } /* 12 port UART device */ +#define F81534A_CTRL_ID \ + { USB_DEVICE(0x2c42, 0x16f8) } /* Global control device */ + static const struct usb_device_id id_table[] = { F81232_ID, { } /* Terminating entry */ @@ -46,6 +49,11 @@ static const struct usb_device_id f81534a_id_table[] = { { } /* Terminating entry */ }; +static const struct usb_device_id f81534a_ctrl_id_table[] = { + F81534A_CTRL_ID, + { } /* Terminating entry */ +}; + static const struct usb_device_id all_serial_id_table[] = { F81232_ID, F81534A_SERIES_ID, @@ -105,6 +113,8 @@ MODULE_DEVICE_TABLE(usb, all_serial_id_table); #define F81534A_GPIO_MODE1_OUTPUT BIT(1) #define F81534A_GPIO_MODE0_OUTPUT BIT(0) +#define F81534A_CMD_ENABLE_PORT 0x116 + struct f81232_private { struct mutex lock; u8 modem_control; @@ -853,6 +863,95 @@ static void f81232_lsr_worker(struct work_struct *work) dev_warn(&port->dev, "read LSR failed: %d\n", status); } +static int f81534a_ctrl_set_register(struct usb_device *dev, u16 reg, u16 size, + void *val) +{ + int retry = F81534A_ACCESS_REG_RETRY; + int status; + u8 *tmp; + + tmp = kmalloc(size, GFP_KERNEL); + if (!tmp) + return -ENOMEM; + + memcpy(tmp, val, size); + + while (retry--) { + status = usb_control_msg(dev, + usb_sndctrlpipe(dev, 0), + F81534A_REGISTER_REQUEST, + F81534A_SET_REGISTER, + reg, + 0, + tmp, + size, + USB_CTRL_SET_TIMEOUT); + if (status != size) { + status = usb_translate_errors(status); + if (status == -EIO) + continue; + + status = -EIO; + } else { + status = 0; + } + + break; + } + + if (status) { + dev_err(&dev->dev, "set ctrl reg: %x, failed status: %d\n", reg, + status); + } + + kfree(tmp); + return status; +} + +static int f81534a_ctrl_enable_all_ports(struct usb_interface *intf) +{ + struct usb_device *dev = interface_to_usbdev(intf); + unsigned char enable[2]; + int status; + + /* enable all available serial ports */ + enable[0] = 0xff; + enable[1] = 0x8f; + + status = f81534a_ctrl_set_register(dev, F81534A_CMD_ENABLE_PORT, + sizeof(enable), enable); + if (status) + dev_warn(&dev->dev, "set CMD_ENABLE_PORT failed: %d\n", status); + + return status; +} + +static int f81534a_ctrl_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + struct usb_device *dev = interface_to_usbdev(intf); + int status; + + status = f81534a_ctrl_enable_all_ports(intf); + if (status) + return status; + + dev = usb_get_dev(dev); + return 0; +} + +static void f81534a_ctrl_disconnect(struct usb_interface *intf) +{ + struct usb_device *dev = interface_to_usbdev(intf); + + usb_put_dev(dev); +} + +static int f81534a_ctrl_resume(struct usb_interface *intf) +{ + return f81534a_ctrl_enable_all_ports(intf); +} + static int f81232_port_probe(struct usb_serial_port *port) { struct f81232_private *priv; @@ -980,7 +1079,41 @@ static struct usb_serial_driver * const serial_drivers[] = { NULL, }; -module_usb_serial_driver(serial_drivers, all_serial_id_table); +static struct usb_driver f81534a_ctrl_driver = { + .name = "f81534a_ctrl", + .id_table = f81534a_ctrl_id_table, + .probe = f81534a_ctrl_probe, + .disconnect = f81534a_ctrl_disconnect, + .resume = f81534a_ctrl_resume, +}; + +static int __init f81232_init(void) +{ + int status; + + status = usb_register_driver(&f81534a_ctrl_driver, THIS_MODULE, + KBUILD_MODNAME); + if (status) + return status; + + status = usb_serial_register_drivers(serial_drivers, KBUILD_MODNAME, + all_serial_id_table); + if (status) { + usb_deregister(&f81534a_ctrl_driver); + return status; + } + + return 0; +} + +static void __exit f81232_exit(void) +{ + usb_serial_deregister_drivers(serial_drivers); + usb_deregister(&f81534a_ctrl_driver); +} + +module_init(f81232_init); +module_exit(f81232_exit); MODULE_DESCRIPTION("Fintek F81232/532A/534A/535/536 USB to serial driver"); MODULE_AUTHOR("Greg Kroah-Hartman "); From patchwork Mon Sep 23 02:24:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ji-Ze Hong (Peter Hong)" X-Patchwork-Id: 11155993 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8930214DB for ; Mon, 23 Sep 2019 02:25:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5E2E8214D9 for ; Mon, 23 Sep 2019 02:25:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JQb2Ef8H" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404216AbfIWCZV (ORCPT ); Sun, 22 Sep 2019 22:25:21 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41956 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404136AbfIWCZN (ORCPT ); Sun, 22 Sep 2019 22:25:13 -0400 Received: by mail-pf1-f194.google.com with SMTP id q7so8169522pfh.8; Sun, 22 Sep 2019 19:25:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aYTIb5+HeXvcNODzGlkiruxjeMT6SF7+WnXVgect7+c=; b=JQb2Ef8HDbkf2q+B56wFJAtwl43uTQ/7YjMyMie5A0OUkG5NV2j1LBRAXpk3uI76Im 0yH6WI2CMzuBdFdqzwk7URfj71sYpE9offwa6gIXqNqIiWtYO6/1DJqOGUSJX9CyOIZM eHzofP4gDUvH14hXFztPN3ShQrYsjk2nXKL1LqZ4ERbyfV3PBFFLh7pAS8ySLr3zZuHO yC80CAEUQYdDnlbkwnoJQe20fdiOM7dK4CxqiqhOrqXxTNDF2GOUED6Gv40Irm3ixSSZ xa2JV3EegnsM253skPuP+/n7meKwAUBlhgWHvZ5SkVGym9/Lv5i9sc6LRd8goZ9L/AGy Jc7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aYTIb5+HeXvcNODzGlkiruxjeMT6SF7+WnXVgect7+c=; b=d+lMZsBJ+MJUZCnLyJnxiaB0qsJFonMB2IE22kqhpjlnwBzGGs+DDVcZ32ze3WthDT hO3ounYpfphw0vEluq4jsBNIiOUMGpYIwUxUsm4OQAIudtjcMnI70VQRDm1R7VMu7xtv vEUDU4kLfoApS9u6nvObcgAMiGqUAwmUlcZC7zcg6gpN6wknU//gO37b40kTnzuFdMx0 YxWnk4OPInKvRr/sNFp2tfwAGJQcIlT/A9UBSuALImTJYiyOVls/SL+ljRBHbzdk+H8D rhUUNR1ggxX99sWXthoSb7Fsz2dnnVGpWs39g+rU3JF89aSNmuPQAjrzApy8CpOnItRZ DlAg== X-Gm-Message-State: APjAAAWtW1wPeYf9ak0TbAbr9DYHOKa0kzBYIYTrjlhWum+AS4Jv/ck8 IyAHKpR5yW3leb5G+I2oF9iY+mVK X-Google-Smtp-Source: APXvYqyO6FF61b2fEjY4lrea5JdKPhIY1Vn9x+3qqiapoACQpFLE9nkfJucV5PK8GtNlid4dZwaTBw== X-Received: by 2002:a17:90a:bf0e:: with SMTP id c14mr17660886pjs.69.1569205512042; Sun, 22 Sep 2019 19:25:12 -0700 (PDT) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id a17sm9305366pfi.178.2019.09.22.19.25.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Sep 2019 19:25:11 -0700 (PDT) From: "Ji-Ze Hong (Peter Hong)" X-Google-Original-From: "Ji-Ze Hong (Peter Hong)" To: johan@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, peter_hong@fintek.com.tw, "Ji-Ze Hong (Peter Hong)" Subject: [PATCH V2 7/7] USB: serial: f81232: Add gpiolib to GPIO device Date: Mon, 23 Sep 2019 10:24:49 +0800 Message-Id: <20190923022449.10952-8-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> References: <20190923022449.10952-1-hpeter+linux_kernel@gmail.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The Fintek F81534A series contains 3 GPIOs per UART and The max GPIOs is 12x3 = 36 GPIOs and this patch will implements GPIO device as a gpiochip to control all GPIO pins even transforms to transceiver pins. Signed-off-by: Ji-Ze Hong (Peter Hong) --- drivers/usb/serial/f81232.c | 249 ++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index 82cc1e6cff62..dc9b28738b80 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -104,6 +105,8 @@ MODULE_DEVICE_TABLE(usb, all_serial_id_table); #define F81534A_TRIGGER_MULTPILE_4X BIT(3) #define F81534A_FIFO_128BYTE (BIT(1) | BIT(0)) +#define F81534A_MAX_PORT 12 + /* Serial port self GPIO control, 2bytes [control&output data][input data] */ #define F81534A_GPIO_REG 0x10e #define F81534A_GPIO_MODE2_DIR BIT(6) /* 1: input, 0: output */ @@ -115,6 +118,13 @@ MODULE_DEVICE_TABLE(usb, all_serial_id_table); #define F81534A_CMD_ENABLE_PORT 0x116 +/* + * Control device global GPIO control, + * 2bytes [control&output data][input data] + */ +#define F81534A_CTRL_GPIO_REG 0x1601 +#define F81534A_CTRL_GPIO_MAX_PIN 3 + struct f81232_private { struct mutex lock; u8 modem_control; @@ -126,6 +136,12 @@ struct f81232_private { struct usb_serial_port *port; }; +struct f81534a_ctrl_private { + struct usb_interface *intf; + struct gpio_chip chip; + struct mutex lock; +}; + static u32 const baudrate_table[] = { 115200, 921600, 1152000, 1500000 }; static u8 const clock_table[] = { F81232_CLK_1_846_MHZ, F81232_CLK_14_77_MHZ, F81232_CLK_18_46_MHZ, F81232_CLK_24_MHZ }; @@ -863,6 +879,50 @@ static void f81232_lsr_worker(struct work_struct *work) dev_warn(&port->dev, "read LSR failed: %d\n", status); } +static int f81534a_ctrl_get_register(struct usb_device *dev, u16 reg, u16 size, + void *val) +{ + int retry = F81534A_ACCESS_REG_RETRY; + int status; + u8 *tmp; + + tmp = kmalloc(size, GFP_KERNEL); + if (!tmp) + return -ENOMEM; + + while (retry--) { + status = usb_control_msg(dev, + usb_rcvctrlpipe(dev, 0), + F81534A_REGISTER_REQUEST, + F81534A_GET_REGISTER, + reg, + 0, + tmp, + size, + USB_CTRL_GET_TIMEOUT); + if (status != size) { + status = usb_translate_errors(status); + if (status == -EIO) + continue; + + status = -EIO; + } else { + status = 0; + memcpy(val, tmp, size); + } + + break; + } + + if (status) { + dev_err(&dev->dev, "get reg: %x, failed status: %d\n", reg, + status); + } + + kfree(tmp); + return status; +} + static int f81534a_ctrl_set_register(struct usb_device *dev, u16 reg, u16 size, void *val) { @@ -908,6 +968,182 @@ static int f81534a_ctrl_set_register(struct usb_device *dev, u16 reg, u16 size, return status; } +#ifdef CONFIG_GPIOLIB +static int f81534a_ctrl_set_mask_register(struct usb_device *dev, u16 reg, + u8 mask, u8 val) +{ + int status; + u8 tmp; + + status = f81534a_ctrl_get_register(dev, reg, 1, &tmp); + if (status) + return status; + + + tmp = (tmp & ~mask) | (val & mask); + + status = f81534a_ctrl_set_register(dev, reg, 1, &tmp); + if (status) + return status; + + return 0; +} + +static int f81534a_gpio_get(struct gpio_chip *chip, unsigned int gpio_num) +{ + struct f81534a_ctrl_private *priv = gpiochip_get_data(chip); + struct usb_interface *intf = priv->intf; + struct usb_device *dev = interface_to_usbdev(intf); + int status; + u8 tmp[2]; + int set; + int idx; + int reg; + + set = gpio_num / F81534A_CTRL_GPIO_MAX_PIN; + idx = gpio_num % F81534A_CTRL_GPIO_MAX_PIN; + reg = F81534A_CTRL_GPIO_REG + set; + + mutex_lock(&priv->lock); + + status = f81534a_ctrl_get_register(dev, reg, sizeof(tmp), tmp); + if (status) { + mutex_unlock(&priv->lock); + return status; + } + + mutex_unlock(&priv->lock); + + return !!(tmp[1] & BIT(idx)); +} + +static int f81534a_gpio_direction_in(struct gpio_chip *chip, + unsigned int gpio_num) +{ + struct f81534a_ctrl_private *priv = gpiochip_get_data(chip); + struct usb_interface *intf = priv->intf; + struct usb_device *dev = interface_to_usbdev(intf); + int status; + int set; + int idx; + int reg; + u8 mask; + + set = gpio_num / F81534A_CTRL_GPIO_MAX_PIN; + idx = gpio_num % F81534A_CTRL_GPIO_MAX_PIN; + mask = F81534A_GPIO_MODE0_DIR << idx; + reg = F81534A_CTRL_GPIO_REG + set; + + mutex_lock(&priv->lock); + status = f81534a_ctrl_set_mask_register(dev, reg, mask, mask); + mutex_unlock(&priv->lock); + + return status; +} + +static int f81534a_gpio_direction_out(struct gpio_chip *chip, + unsigned int gpio_num, int val) +{ + struct f81534a_ctrl_private *priv = gpiochip_get_data(chip); + struct usb_interface *intf = priv->intf; + struct usb_device *dev = interface_to_usbdev(intf); + int status; + int set; + int idx; + int reg; + u8 mask; + u8 data; + + set = gpio_num / F81534A_CTRL_GPIO_MAX_PIN; + idx = gpio_num % F81534A_CTRL_GPIO_MAX_PIN; + mask = (F81534A_GPIO_MODE0_DIR << idx) | BIT(idx); + reg = F81534A_CTRL_GPIO_REG + set; + data = val ? BIT(idx) : 0; + + mutex_lock(&priv->lock); + status = f81534a_ctrl_set_mask_register(dev, reg, mask, data); + mutex_unlock(&priv->lock); + + return status; +} + +static void f81534a_gpio_set(struct gpio_chip *chip, unsigned int gpio_num, + int val) +{ + f81534a_gpio_direction_out(chip, gpio_num, val); +} + +static int f81534a_gpio_get_direction(struct gpio_chip *chip, + unsigned int gpio_num) +{ + struct f81534a_ctrl_private *priv = gpiochip_get_data(chip); + struct usb_interface *intf = priv->intf; + struct usb_device *dev = interface_to_usbdev(intf); + int status; + u8 tmp[2]; + int set; + int idx; + int reg; + u8 mask; + + set = gpio_num / F81534A_CTRL_GPIO_MAX_PIN; + idx = gpio_num % F81534A_CTRL_GPIO_MAX_PIN; + mask = F81534A_GPIO_MODE0_DIR << idx; + reg = F81534A_CTRL_GPIO_REG + set; + + mutex_lock(&priv->lock); + + status = f81534a_ctrl_get_register(dev, reg, sizeof(tmp), tmp); + if (status) { + mutex_unlock(&priv->lock); + return status; + } + + mutex_unlock(&priv->lock); + + if (tmp[0] & mask) + return GPIOF_DIR_IN; + + return GPIOF_DIR_OUT; +} + +static int f81534a_prepare_gpio(struct usb_interface *intf) +{ + struct f81534a_ctrl_private *priv = usb_get_intfdata(intf); + int status; + + priv->chip.parent = &intf->dev; + priv->chip.owner = THIS_MODULE; + priv->chip.get_direction = f81534a_gpio_get_direction, + priv->chip.get = f81534a_gpio_get; + priv->chip.direction_input = f81534a_gpio_direction_in; + priv->chip.set = f81534a_gpio_set; + priv->chip.direction_output = f81534a_gpio_direction_out; + priv->chip.label = "f81534a"; + priv->chip.can_sleep = true; + /* M0(SD)/M1/M2 */ + priv->chip.ngpio = F81534A_CTRL_GPIO_MAX_PIN * F81534A_MAX_PORT; + priv->chip.base = -1; + + priv->intf = intf; + mutex_init(&priv->lock); + + status = devm_gpiochip_add_data(&intf->dev, &priv->chip, priv); + if (status) { + dev_err(&intf->dev, "failed to register gpiochip: %d\n", + status); + return status; + } + + return 0; +} +#else +static int f81534a_prepare_gpio(struct usb_interface *intf) +{ + return 0; +} +#endif + static int f81534a_ctrl_enable_all_ports(struct usb_interface *intf) { struct usb_device *dev = interface_to_usbdev(intf); @@ -930,8 +1166,21 @@ static int f81534a_ctrl_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_device *dev = interface_to_usbdev(intf); + struct f81534a_ctrl_private *priv; int status; + priv = devm_kzalloc(&intf->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + mutex_init(&priv->lock); + usb_set_intfdata(intf, priv); + priv->intf = intf; + + status = f81534a_prepare_gpio(intf); + if (status) + return status; + status = f81534a_ctrl_enable_all_ports(intf); if (status) return status;