From patchwork Thu Jan 30 05:47:47 2020 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: 11357435 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 03CB7139A for ; Thu, 30 Jan 2020 05:48:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D63052083E for ; Thu, 30 Jan 2020 05:48:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MtQJQL1r" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727133AbgA3FsA (ORCPT ); Thu, 30 Jan 2020 00:48:00 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38584 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725798AbgA3FsA (ORCPT ); Thu, 30 Jan 2020 00:48:00 -0500 Received: by mail-pf1-f193.google.com with SMTP id x185so910258pfc.5; Wed, 29 Jan 2020 21:47:58 -0800 (PST) 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=RM4StqYp6528LuZxqUQeQTeN+yjjb6Yypxjs3dilWF4=; b=MtQJQL1riGhO0J3oNnkxjTOkdAw7nIV+ZEJDEd3JHw8zO6QY/7Ot+CdLuwSkWPIvxd fgYjHwn2xYoa6qa8z8qYjmOWEeImUE7nVlSBqSrXNmYnAEPm0mwOoFOHCOBtlwSzMC82 MS9ZQwqBV/GSzkL7Z4bItURDxCOjoE0wXR+6W+wpcmt+CbtHNu+NzUkOyuxhVoOorcrd fSP4f5lvaNmR4AipWtdTFpkOklT/tVt+sDAEPEIkeSNaEQPUy6i3fYmQkdibmaTVkp3c uhcrDIN5NiRtAaXYo8Cp1o7evB0U5n/+j7cjnt9YasBuGrnR8dg6I/lkrWeIue9iW/s6 7ePA== 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=RM4StqYp6528LuZxqUQeQTeN+yjjb6Yypxjs3dilWF4=; b=G5YC5ab3oBSrDFcMuCxuqRHboL+1PJ4UYA+Pq8/RIS2oOUryT2gPytKtDMV0bFCrnZ LJqnXbfSywuqIAHxDh30fzk64s7nr5Pj5X4hoLjfssjMyiy+6HyqZ39VlkGUAcdjR0YT njt/9Wd2JrqNrWc+e3St1J+/Zo90d16tRknq5dpyrIrR54QRu8j7FlkSbmLFBYB9s3KQ hn0ct86QU7egLFmsuQKqdR7VQxjoNZQPvWBITh4EpDfWieUTwhuZBhhyNfypjDgG92wi cyOzF6d1SC2DlQWG0FAflqkevzYc2low56FTReG2Cwe+JT8ybFw+wiSpNzMf1j9me7m/ RPfQ== X-Gm-Message-State: APjAAAU62b21j6p2aSIvPMziBEzSqwVp+IKekAQr9TjUzJZa+xgx1vQA U5DQn9boKDduSpPqFdbgSBM= X-Google-Smtp-Source: APXvYqwTWUb9YVBt9SWre6ugobNtU2BjmBbD7TafH+st/hqQdxAI+SvTl5FeIhGohZXLpYLQsEPjbA== X-Received: by 2002:aa7:93a4:: with SMTP id x4mr3375345pff.42.1580363278593; Wed, 29 Jan 2020 21:47:58 -0800 (PST) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id w26sm4690392pfj.119.2020.01.29.21.47.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Jan 2020 21:47:57 -0800 (PST) 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 V3 1/6] USB: serial: f81232: Extract LSR handler Date: Thu, 30 Jan 2020 13:47:47 +0800 Message-Id: <20200130054752.9368-2-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200130054752.9368-1-hpeter+linux_kernel@gmail.com> References: <20200130054752.9368-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 that can be re-used by F81532A/534A/535/536. Signed-off-by: Ji-Ze Hong (Peter Hong) --- Changelog: v3: 1. Change git comment for describe more information. v2: 1: Separate LSR handler from original combined driver. 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 Thu Jan 30 05:47:48 2020 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: 11357433 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 9480814B4 for ; Thu, 30 Jan 2020 05:48:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7272D2083E for ; Thu, 30 Jan 2020 05:48:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bdiiNJKS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727179AbgA3FsC (ORCPT ); Thu, 30 Jan 2020 00:48:02 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:39165 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727139AbgA3FsB (ORCPT ); Thu, 30 Jan 2020 00:48:01 -0500 Received: by mail-pj1-f66.google.com with SMTP id e9so857081pjr.4; Wed, 29 Jan 2020 21:48:01 -0800 (PST) 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=d2SIm3bhYZ5Yw954kj7k/SsJk8xges7EqsF+eWSvkxA=; b=bdiiNJKSxMT0YkQNhlu41/94uAHaM9o8M8stTDHu/07g3sUzklnZGkpx00Wgk4iLsC 6poUW/b/eXdXX4mveA93Wb3CT7b67sYk5FOv9b5ATpo1s1DHdZd4nPkp0QgWMDobObQc lVel2g5GUG0BM0LdcMQB4KqlTfteCvo539UjPcuUJrotnej1YjkuoFye7G/l8ZUJ7VHr s6wtvqLKmj3TmqupQutezgpj5m+cF8bqCVqAMXzTL3fYoNJyNo0HaySng1NCnB6SIguu 23YxN0WWe9ETbGMGnUrNTfWJQvQ8q+uAiDH41dBuse6jMz6Z4GqJuJ9tkjPsv+i0lW10 PZow== 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=d2SIm3bhYZ5Yw954kj7k/SsJk8xges7EqsF+eWSvkxA=; b=NarLXFjIw1fBXNMjsDUiTkAfa83fmeUjRWI+Ents59e3l2iu5kkKrPdlkt91PgYIwH fxuQGSYWjYXGH/jFI42XGhW21hweZr07VJX2GND2Rj/1RCe2qSvIoRQXqhaMTQsDEyVV +fYQZoVqE9GNAYVrX/U0ywweVY2I781z4bq/X5IbMjsyYJg8OhTz7oJYiptah3wV8mCY bDSJDZvRRN1L3ezfVwlzs77xpEZnvvK3Pz3Cjza/SstqBn+v/OdKSd3W7E77Y7D1jRAw K1qtLMcGf2zo4L66HqjyyKbDVB3uR93qDQcvYuRb8kN+NGZcpy4Zc7+JLpi8Qam9ALcv RkfA== X-Gm-Message-State: APjAAAVR1vSxaePmgU6Yz8ZWHDaUGSAVnwObJxIS8zxUvJO8e+xd/XCC lqUrPwWxKz210uPMkAfSNgM= X-Google-Smtp-Source: APXvYqy+LGMQMX9zIimIH8jeuezSkrFoRBlJPJLR2ZTT0XTtftIuOCrTpQXdTRzjtzdjZks/T2qwfQ== X-Received: by 2002:a17:902:e789:: with SMTP id cp9mr3125780plb.85.1580363280762; Wed, 29 Jan 2020 21:48:00 -0800 (PST) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id o184sm4621315pgo.62.2020.01.29.21.47.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Jan 2020 21:48:00 -0800 (PST) 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 V3 2/6] USB: serial: f81232: Add tx_empty function Date: Thu, 30 Jan 2020 13:47:48 +0800 Message-Id: <20200130054752.9368-3-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200130054752.9368-1-hpeter+linux_kernel@gmail.com> References: <20200130054752.9368-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. Without this, console redirection will get garbage data. Signed-off-by: Ji-Ze Hong (Peter Hong) --- Changelog: v3: 1. Modify return true when accessing device with error. v2: 1: Change check tx empty from UART_LSR_TEMT | UART_LSR_THRE to UART_LSR_TEMT only. drivers/usb/serial/f81232.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index c07d376c743d..793d0b30e347 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -685,6 +685,20 @@ 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) { + 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 +834,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 Thu Jan 30 05:47:49 2020 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: 11357425 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 F0DAE139A for ; Thu, 30 Jan 2020 05:48:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF3382067C for ; Thu, 30 Jan 2020 05:48:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="frqJfbE5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727216AbgA3FsF (ORCPT ); Thu, 30 Jan 2020 00:48:05 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:55317 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727139AbgA3FsE (ORCPT ); Thu, 30 Jan 2020 00:48:04 -0500 Received: by mail-pj1-f66.google.com with SMTP id d5so830780pjz.5; Wed, 29 Jan 2020 21:48:03 -0800 (PST) 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=XoH0RfUkniLuJnauhCFjE5IH2zqdDE1G34DQoDUOnqE=; b=frqJfbE5yLwlFVkGlxhJjNDjm0lIOAMLJRcO3mPrGlkiDxN257Dcy+ItuctomokBT+ d/pOxztJbcvpouu/H7DfD9jJP16GPWBgkivWoOg67TdArBtcrEGLPotyflIRynLld060 k6JjwzWx6imTj+ZO82YaQh7p3uybw23u4XSX3Hjd+QuUapQuuWMwVGfAEaRCgRZfBddz EJZuYnH133gF+6T9ON3MUp7lE8i2wukpQYw2E/OPNyUVFjK7iPWqI4iH1SQ9+ySzLsIv HYovdcuFkw+iJ1Fk+bvpfMariiJYyao/LNZUKEhkr4TwnGOKh1jw5KgmbmUgRobqiQVK S4YQ== 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=XoH0RfUkniLuJnauhCFjE5IH2zqdDE1G34DQoDUOnqE=; b=bWfukq3gw6kmEeJtbt6We4y87oVgrxixMY4dlH78W2S4Kyv9BJNouMsr9kOzQnlVRy erIRsQH9Wm13zNvEzP4EteQDWyXVVE+4asBv4WsgV6flMdSdBG+sqIK9VyCTOxS6ukOd fRjbTOG3AzM9QrO7bjwMc9YEaXYjMgPFE0gfqEZt78uAIXuAQIgHSB1kPeclYpZ8LvUw Tc6+Isr70jnMyWYEwTxllUSbkU9f3OTYP0F09QAhxtAQyNdL5pcCc8JhH/gTRX+718xr DRb3Htab51B0+E7NvHtYpiecLLxem28wWAZWj5sD1yiCbSTlRlqUhmrQzQj6rdAAUZQl LRuA== X-Gm-Message-State: APjAAAUqkNtz9DaxS3PBnYpxfrcy7sY/wRnKoIxVDrDrqYLGEJ/iAka6 5MT0dXBD36FP11Lh/de2VC0= X-Google-Smtp-Source: APXvYqyyESOFCByzFV64RJ14lD2ByRUAv9ouA7/BUL55xT7D1Lsxl/cUJexworbknI5wV88apgBlJw== X-Received: by 2002:a17:90a:f84:: with SMTP id 4mr4055495pjz.74.1580363282931; Wed, 29 Jan 2020 21:48:02 -0800 (PST) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id x25sm4868990pfp.30.2020.01.29.21.48.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Jan 2020 21:48:02 -0800 (PST) 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 V3 3/6] USB: serial: f81232: Use devm_kzalloc Date: Thu, 30 Jan 2020 13:47:49 +0800 Message-Id: <20200130054752.9368-4-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200130054752.9368-1-hpeter+linux_kernel@gmail.com> References: <20200130054752.9368-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) --- Changelog: v3: 1. No change. v2: 1: No change. 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 793d0b30e347..e080d678b0c2 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -753,7 +753,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; @@ -769,16 +769,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]; @@ -838,7 +828,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 Thu Jan 30 05:47:50 2020 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: 11357431 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 5DB36139A for ; Thu, 30 Jan 2020 05:48:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 312512083E for ; Thu, 30 Jan 2020 05:48:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CMxVyHV5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727280AbgA3FsS (ORCPT ); Thu, 30 Jan 2020 00:48:18 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:51861 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727217AbgA3FsF (ORCPT ); Thu, 30 Jan 2020 00:48:05 -0500 Received: by mail-pj1-f65.google.com with SMTP id fa20so839340pjb.1; Wed, 29 Jan 2020 21:48:05 -0800 (PST) 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=L/+zfhhce+MGmNAWfBlnOWr6kzS8jMspJdiLQOshnKs=; b=CMxVyHV5lCpKyxnYThhtaUb68Rx1d8RT2yhJ7aafTFC0w/x/MY+RislEMMDoIitjFS u5HLLbABUC+tmC68/uDslAS9gZXfzFK+RSBGbEE/yuAvYQUSz8pCfqJzvrCbRIBfaRGx 7Xt5zL9bflkjjBvdAa+gUSuNNNzTOW/nARJsFDbe9lqSy3/O8+gsmEh1QXV5Yih0uWkY 91CcvdHsWIACtXiiXpQDkcTpUk7jQBIILbwiCRJzEFqzkR2gfsLdlJGmkirgq3U0LI9O VFJTlBCgWyXyuMTqzPixuHxU0JI998iaKQNhiLzBIdxxmtThzkjIYFHExvcVw7/4f7el 445g== 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=L/+zfhhce+MGmNAWfBlnOWr6kzS8jMspJdiLQOshnKs=; b=gG4FXa/hZmCI8D8hcgMhGHK/SDEA9z6fyqiwlZEmWtnvBPP4UpYbUrz1RjSF+Nfpel gt3Bt++l1LAuhwRIBo49WFBvECi0vC2vjACWdfj9mQHCrO2e9lz0iHVowrnIBhKbZjHU w9+YVDYOstqgWc+ncXkqPZ8cY2grn7BoiJVogAplc+vdkXg5HljTe0/lCG4Fnyw0lmph tQVfj2r/xVih5QE8f4GNbrWTnjlBdWlcwUbxG7B8KnaTyFv5wRze3drtDjZxJB/ZnPyI QUdszIUj6747mjW7GVFmVNYbl+ZKym7CYx3CLmkm63VGrpPHt7pj4EQ+BqC8pe+otT/k izqg== X-Gm-Message-State: APjAAAXX5WlJg1R3HLbkQASDbzaPE7TH/W0qZyqVHelzWjUVM7faAKNW KGnREnNDCxAExt27rDhN2LM= X-Google-Smtp-Source: APXvYqw4Z1nPu1acLeJJxhbNjn5y1Lu4JiHDYY9IdH6/ww/syNe0Y6AM6x5tcv9giDagxSB9vG9/DA== X-Received: by 2002:a17:90b:309:: with SMTP id ay9mr3851975pjb.22.1580363285069; Wed, 29 Jan 2020 21:48:05 -0800 (PST) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id e1sm4983931pfl.98.2020.01.29.21.48.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Jan 2020 21:48:04 -0800 (PST) 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 V3 4/6] USB: serial: f81232: Add F81534A support Date: Thu, 30 Jan 2020 13:47:50 +0800 Message-Id: <20200130054752.9368-5-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200130054752.9368-1-hpeter+linux_kernel@gmail.com> References: <20200130054752.9368-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) --- Changelog: v3: 1. Add prefix f81232 to original id_table[]. 2. Change all_serial_id_table[] to combined_id_table[]. 3. Remove non-used defines. 4. Fix typos. 5. Change some error message more reable. 6. Change urb->actual_length to len in f81534a_process_read_urb(). 7. Remove f81534a_port_probe() and add it to next patch. v2: 1: Separate LSR handler to prior patch. 2: Use tty_insert_flip_string_fixed_char() when not a console. 3. Remove proxy function f81232_read_urb_proxy() and change it to usb-serial subdriver. 4. Change some error message more reable. drivers/usb/serial/f81232.c | 128 ++++++++++++++++++++++++++++++++++-- 1 file changed, 122 insertions(+), 6 deletions(-) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index e080d678b0c2..df197c723273 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 -static const struct usb_device_id id_table[] = { - { USB_DEVICE(0x1934, 0x0706) }, +#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 f81232_id_table[] = { + F81232_ID, { } /* Terminating entry */ }; -MODULE_DEVICE_TABLE(usb, id_table); + +static const struct usb_device_id f81534a_id_table[] = { + F81534A_SERIES_ID, + { } /* Terminating entry */ +}; + +static const struct usb_device_id combined_id_table[] = { + F81232_ID, + F81534A_SERIES_ID, + { } /* Terminating entry */ +}; +MODULE_DEVICE_TABLE(usb, combined_id_table); /* Maximum baudrate for F81232 */ #define F81232_MAX_BAUDRATE 1500000 @@ -61,6 +87,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_REG 0x107 +#define F81534A_TRIGGER_MASK GENMASK(3, 2) +#define F81534A_TRIGGER_MULTIPLE_4X BIT(3) +#define F81534A_FIFO_128BYTE (BIT(1) | BIT(0)) + struct f81232_private { struct mutex lock; u8 modem_control; @@ -383,6 +414,47 @@ 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, "short message received: %d\n", + urb->actual_length); + return; + } + + len = data[0]; + if (len != urb->actual_length) { + dev_err(&port->dev, "unexpected length: %d %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 < len - 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, len - 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 +738,24 @@ 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 mask; + u8 val; + + val = F81534A_TRIGGER_MULTIPLE_4X | F81534A_FIFO_128BYTE; + mask = F81534A_TRIGGER_MASK | F81534A_FIFO_128BYTE; + + status = f81232_set_mask_register(port, F81534A_MODE_REG, mask, val); + if (status) { + dev_err(&port->dev, "failed to set MODE_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); @@ -810,7 +900,7 @@ static struct usb_serial_driver f81232_device = { .owner = THIS_MODULE, .name = "f81232", }, - .id_table = id_table, + .id_table = f81232_id_table, .num_ports = 1, .bulk_in_size = 256, .bulk_out_size = 256, @@ -832,14 +922,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 = f81232_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, combined_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 Thu Jan 30 05:47:51 2020 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: 11357429 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 8702B139A for ; Thu, 30 Jan 2020 05:48:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 63BF22082E for ; Thu, 30 Jan 2020 05:48:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ax1JbQ7M" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727259AbgA3FsJ (ORCPT ); Thu, 30 Jan 2020 00:48:09 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:38835 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727244AbgA3FsH (ORCPT ); Thu, 30 Jan 2020 00:48:07 -0500 Received: by mail-pg1-f196.google.com with SMTP id a33so1062359pgm.5; Wed, 29 Jan 2020 21:48:07 -0800 (PST) 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=RNIHU9mN9Ks4aq3EHKBboyo0GBYUlwX2Stua3O4Tvyo=; b=ax1JbQ7MvV8mimz2X2+WCD9JVHHoa9G6Fi0Zin38dhxIKnAxz31YvTlIAh4Y/LZeSq P0nE3viEQ1pKWEL6n8yGOfKAE12Gn7P4dKI8QEvbXsmf8z9JBlkWA5Xn/eJdpL+FmSf7 YlyJpoGZNUAzRIa9oYX6Yprd6Kw7c+MMF9ovZrqDtu5e3CCuHewMwIplTcqUMup/KIuW Oz9z1R+iDRg7kCgyseF8dby7XjjFY8X9agWjsK7Z0VFnzJfwQFaEwV5TZGV9me0FmX+A ruTy5d4S4s+agwMuEI25h7X+TDDzur189yuTXtDWjMUBmK/IN57nlTtauNU9UbEV8N33 Kh/A== 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=RNIHU9mN9Ks4aq3EHKBboyo0GBYUlwX2Stua3O4Tvyo=; b=Lir1UE43A0+UnLg67I6vB5jOTtPSrQ10kTisHXjk9MYa8lCp0fiOz+OeKgDy66610E cx4Bv4HJBc0li6puJZ8jiUnnBFwfovCWEMhExj0leFjRnPB/7wmlz7pBtox+G4Q5PG/S zTvfFFYNxBUcLqKoBH2ducmRp/Xh11YZEGMVKggFDYYWvaizgYxrDvKnkoJ5yNKiUKvk yH0pWNHyORQ0RMw7QsR7QlLlsGYIm+Bj9hZQspz1LzODxcHP9btUmGp0JRNDhpRfT3wg bBhJ4souYtfYd2bJg1YYwbvjR0mRJOuyo5VQuNrI1zQ7ejyf+Q5I952jkt/Hb4xDs95N LrGg== X-Gm-Message-State: APjAAAUu1rU3tA7+tsQNNWf9UV2KGuCYgRM6miVADNSfI+0eh/7KeXWW ZsVRQaF0zjGhfsZ6pq0IFTM= X-Google-Smtp-Source: APXvYqxlzpL6z7P/cFa6NzQ9bfbpklq/LDHKdK9nsiWoAyiBP0BQV90J6bbaR7bduDnsf9LQ/8w8Rg== X-Received: by 2002:a63:7145:: with SMTP id b5mr2849049pgn.409.1580363287190; Wed, 29 Jan 2020 21:48:07 -0800 (PST) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id b65sm4793790pgc.18.2020.01.29.21.48.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Jan 2020 21:48:06 -0800 (PST) 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 V3 5/6] USB: serial: f81232: Set F81534A serial port with RS232 mode Date: Thu, 30 Jan 2020 13:47:51 +0800 Message-Id: <20200130054752.9368-6-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200130054752.9368-1-hpeter+linux_kernel@gmail.com> References: <20200130054752.9368-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) --- Changelog: v3: 1. Add f81534a_port_probe(). v2: 1: Add more describe in git comment message. 2: Remove non-used gpio_mode. drivers/usb/serial/f81232.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index df197c723273..21410a7f3a8b 100644 --- a/drivers/usb/serial/f81232.c +++ b/drivers/usb/serial/f81232.c @@ -92,6 +92,15 @@ MODULE_DEVICE_TABLE(usb, combined_id_table); #define F81534A_TRIGGER_MULTIPLE_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; @@ -859,6 +868,19 @@ static int f81232_port_probe(struct usb_serial_port *port) return 0; } +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); +} + static int f81232_suspend(struct usb_serial *serial, pm_message_t message) { struct usb_serial_port *port = serial->port[0]; @@ -942,7 +964,7 @@ static struct usb_serial_driver f81534a_device = { .tx_empty = f81232_tx_empty, .process_read_urb = f81534a_process_read_urb, .read_int_callback = f81232_read_int_callback, - .port_probe = f81232_port_probe, + .port_probe = f81534a_port_probe, .suspend = f81232_suspend, .resume = f81232_resume, }; From patchwork Thu Jan 30 05:47:52 2020 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: 11357427 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 8E5E2139A for ; Thu, 30 Jan 2020 05:48:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 61E01215A4 for ; Thu, 30 Jan 2020 05:48:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nxSLi57g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727300AbgA3FsL (ORCPT ); Thu, 30 Jan 2020 00:48:11 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:43049 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727280AbgA3FsK (ORCPT ); Thu, 30 Jan 2020 00:48:10 -0500 Received: by mail-pf1-f193.google.com with SMTP id s1so895587pfh.10; Wed, 29 Jan 2020 21:48:09 -0800 (PST) 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=pGnME5UnUSmVYH39WRYxMH/ihOy5W05BZhs06G3EBa4=; b=nxSLi57gFvKusz8rO/jUyE8wbgODnZnpaz04OktxEOyilqGNNxChmJDw14JKehV5gI 9rqDYr0+O0JPlQxljPPJMo05vzjovPL0Gr5W4frf/l1oo4ED4KxPy0XgBJh5NKgLHXKN Cu8nmCngL3tpp72WSmBPJdrjzoDgYg8Y/RfJhy5zqHSf4j4+fvRK0NRYw9QaciyR1CrA HlU190Bbq7zF0EHveprSnR5KEzBVhjM5vTBme+MlAg0+T8WijSW59nBCxSjn9Sxnn6xD ZsFFWVvyI8QBsPhFrYQE+l9d1JbV2CgGLq2yuZ2uG4/Z+yCOYNt3j4sPm+4cMRawyLrZ 9zxQ== 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=pGnME5UnUSmVYH39WRYxMH/ihOy5W05BZhs06G3EBa4=; b=UTCytgrVGDpLGIYoph9q40K4W09PEtKS/Bdkx/lJStM8mAweiyBhZBTlOQ46UxecWP mucYoTF4oXnsQIbphQRnhBWqnOF2z9PLzpFtrp/7c9yusvd6r+G6lbzshTOrEKVmH9LQ O2BsIgA+SBBQHO9j3klvWqo2lvXjoejyS3js6ssTgMXiKMXplUwKm3l3iQoF608ARNNM TaMPsetRgyc07VcIaiIvRh3GqOfFKsMC7yglRsCTMQh1/yCjBwFdlof2V274in3/qmhv 0TQ/puDLqfGacSlahjXOyJXTAbKjvvUjjzR8AHmC6ueRE7uKNELPVxBCD0fKMiduIJhp CDTw== X-Gm-Message-State: APjAAAWBh+RrxrqKJygknHKk6m15TZZQcCmscYWGl6moFyoDGwU9GHa+ DEFMyD5zmGBA+pKc1Gov8dc= X-Google-Smtp-Source: APXvYqz5OQQr0+Ro5uzdR+/E3kWp/tLDU8CJOh0uO4GFLt6IDOX7Wgfg6nHW0rjgl7P2FMrNqfjvig== X-Received: by 2002:a63:484b:: with SMTP id x11mr3022258pgk.148.1580363289305; Wed, 29 Jan 2020 21:48:09 -0800 (PST) Received: from localhost (59-120-186-245.HINET-IP.hinet.net. [59.120.186.245]) by smtp.gmail.com with ESMTPSA id q4sm4871495pfl.175.2020.01.29.21.48.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Jan 2020 21:48:08 -0800 (PST) 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 V3 6/6] USB: serial: f81232: Add generator for F81534A Date: Thu, 30 Jan 2020 13:47:52 +0800 Message-Id: <20200130054752.9368-7-hpeter+linux_kernel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200130054752.9368-1-hpeter+linux_kernel@gmail.com> References: <20200130054752.9368-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 write 0x8fff to GPIO device register F81534A_CTRL_CMD_ENABLE_PORT(116h) to enable all available serial ports. Signed-off-by: Ji-Ze Hong (Peter Hong) --- Changelog: v3: 1. Modify some define with prefix F81534A_CTRL_. 2. Use kmemdup() in f81534a_ctrl_set_register(). 3. Not accpet with short transfers in f81534a_ctrl_set_register(). 4. Add comment in f81534a_ctrl_enable_all_ports() to describe magic constants. 5. Remove non-need usb_get_dev()/usb_put_dev(). 6. Add F81534A_CTRL_ID in MODULE_DEVICE_TABLE(). v2: 1: Simplify the generator behavior. 2: Change multiply MODULE_DEVICE_TABLE() to 1 only. drivers/usb/serial/f81232.c | 134 +++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c index 21410a7f3a8b..0303f94b2521 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 f81232_id_table[] = { F81232_ID, { } /* Terminating entry */ @@ -46,9 +49,15 @@ 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 combined_id_table[] = { F81232_ID, F81534A_SERIES_ID, + F81534A_CTRL_ID, { } /* Terminating entry */ }; MODULE_DEVICE_TABLE(usb, combined_id_table); @@ -61,6 +70,7 @@ MODULE_DEVICE_TABLE(usb, combined_id_table); #define F81232_REGISTER_REQUEST 0xa0 #define F81232_GET_REGISTER 0xc0 #define F81232_SET_REGISTER 0x40 +#define F81534A_ACCESS_REG_RETRY 2 #define SERIAL_BASE_ADDRESS 0x0120 #define RECEIVE_BUFFER_REGISTER (0x00 + SERIAL_BASE_ADDRESS) @@ -92,6 +102,8 @@ MODULE_DEVICE_TABLE(usb, combined_id_table); #define F81534A_TRIGGER_MULTIPLE_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 */ @@ -101,6 +113,9 @@ MODULE_DEVICE_TABLE(usb, combined_id_table); #define F81534A_GPIO_MODE1_OUTPUT BIT(1) #define F81534A_GPIO_MODE0_OUTPUT BIT(0) +#define F81534A_CTRL_CMD_ENABLE_PORT 0x116 + + struct f81232_private { struct mutex lock; u8 modem_control; @@ -848,6 +863,89 @@ 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 = kmemdup(val, size, GFP_KERNEL); + if (!tmp) + return -ENOMEM; + + while (retry--) { + status = usb_control_msg(dev, + usb_sndctrlpipe(dev, 0), + F81232_REGISTER_REQUEST, + F81232_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, define as following: + * bit 15 : Reset behavior (when HUB got soft reset) + * 0: maintain all serial port enabled state. + * 1: disable all serial port. + * bit 0~11 : Serial port enable bit. + */ + enable[0] = 0xff; + enable[1] = 0x8f; + + status = f81534a_ctrl_set_register(dev, F81534A_CTRL_CMD_ENABLE_PORT, + sizeof(enable), enable); + if (status) + dev_warn(&dev->dev, "set ENABLE_PORT failed: %d\n", status); + + return status; +} + +static int f81534a_ctrl_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + + return f81534a_ctrl_enable_all_ports(intf); +} + +static void f81534a_ctrl_disconnect(struct usb_interface *intf) +{ +} + +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; @@ -975,7 +1073,41 @@ static struct usb_serial_driver * const serial_drivers[] = { NULL, }; -module_usb_serial_driver(serial_drivers, combined_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, + combined_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 ");