From patchwork Mon Sep 19 13:24:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12980443 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68E6FC6FA8B for ; Mon, 19 Sep 2022 13:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230443AbiISNZj (ORCPT ); Mon, 19 Sep 2022 09:25:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230265AbiISNZb (ORCPT ); Mon, 19 Sep 2022 09:25:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4072ECE3E; Mon, 19 Sep 2022 06:25:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7D473B81BE2; Mon, 19 Sep 2022 13:25:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A6F8C433B5; Mon, 19 Sep 2022 13:25:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663593926; bh=Tff0msRmVXjswmkJrDQx5mdytkeF8V7Bwkf1RbtpykA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F9Z1IH4/jlUoM1g1n73j9vu07Jo2fx2KBmmmwxjwVv9D2BXeackQe+Ay+pr6uAEKN ph3jJwj7eXyjwpMNz4ZuSpH1cGpV0Fjeo5XRE5yL5oz56NfE01OwdR1xJuNS7GwPCf 28GI7ySSfulNUV3dQ2t7yVAJS1wV/oCsBozyelbT2AlrIg7jTtBnzixBjX02FjNKXI +9KWXqGvz8VzaSZCJypY5S3IgMC0c+vUKMrZ3ZVnT0CdUi5MDx92VrbPSetd7xRIXd q21cKV4yhHjmH0SoYNeRCrL8OU2idzVyEI9CHRuT3g4Ip2idFPUNasL7pWXx71SvU1 rdHaHv/1uSzLA== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oaGmB-0005R5-27; Mon, 19 Sep 2022 15:25:31 +0200 From: Johan Hovold To: Johan Hovold Cc: Jiasheng Jiang , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] USB: serial: ftdi_sio: clean up attribute visibility logic Date: Mon, 19 Sep 2022 15:24:54 +0200 Message-Id: <20220919132456.20851-2-johan@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220919132456.20851-1-johan@kernel.org> References: <20220919132456.20851-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Clean up the attribute visibility logic by defaulting to attributes being visible and explicitly listing the exceptions. Signed-off-by: Johan Hovold --- drivers/usb/serial/ftdi_sio.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 147b5e80595a..a5fc199cde0b 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -1775,19 +1775,18 @@ static umode_t ftdi_is_visible(struct kobject *kobj, struct attribute *attr, int struct usb_serial_port *port = to_usb_serial_port(dev); struct ftdi_private *priv = usb_get_serial_port_data(port); enum ftdi_chip_type type = priv->chip_type; - umode_t mode = attr->mode; - if (type != SIO) { - if (attr == &dev_attr_event_char.attr) - return mode; + if (attr == &dev_attr_event_char.attr) { + if (type == SIO) + return 0; } - if (type != SIO && type != FT232A) { - if (attr == &dev_attr_latency_timer.attr) - return mode; + if (attr == &dev_attr_latency_timer.attr) { + if (type == SIO || type == FT232A) + return 0; } - return 0; + return attr->mode; } static const struct attribute_group ftdi_group = { From patchwork Mon Sep 19 13:24:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12980440 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA2B8ECAAD3 for ; Mon, 19 Sep 2022 13:25:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230350AbiISNZd (ORCPT ); Mon, 19 Sep 2022 09:25:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230112AbiISNZb (ORCPT ); Mon, 19 Sep 2022 09:25:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40842D10F; Mon, 19 Sep 2022 06:25:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 71312B81BD9; Mon, 19 Sep 2022 13:25:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 256DAC433C1; Mon, 19 Sep 2022 13:25:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663593926; bh=YaeRxWbt+/MWcq8tF2wVcj1FK8OAKg3UKPDh2LMI0H8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oGDaRJJbV5AY9AJdcBpa5yc4VlrZD3NtG4Na7iZu/uG9K6jI8438B9TjZi9Qi3IIa IVmiU4yxKVKdrT5ISZ3ZJejM1CReitaxL+KbyKFPekdUwO8IKKfHdwHtWmcyQ6L6F4 qRjU2wWzdpj6CuDj6mwP9DFgqO9B4Xq4yOgixiUntCTgRXyh2HV+sSsUyokmMD/3d/ aXbXCjExPzEn8yIuKoGN0ImIyBbfPU9MBGIs6isB6qW0RGhm27HlKxzdMz6Z7b1fJN 4XnSXUgtSJ64RqH3tgdxGC2fuLftkDwZLFbA79jrsK8JegLOn0/2VkqRp22TxahObe Pv8o6KCrvuDzA== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oaGmB-0005R7-50; Mon, 19 Sep 2022 15:25:31 +0200 From: Johan Hovold To: Johan Hovold Cc: Jiasheng Jiang , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] USB: serial: ftdi_sio: move driver structure Date: Mon, 19 Sep 2022 15:24:55 +0200 Message-Id: <20220919132456.20851-3-johan@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220919132456.20851-1-johan@kernel.org> References: <20220919132456.20851-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Move the definition of the USB serial driver structure to the end of the file where it is used and drop the now redundant forward declarations. Signed-off-by: Johan Hovold --- drivers/usb/serial/ftdi_sio.c | 101 ++++++++++++---------------------- 1 file changed, 35 insertions(+), 66 deletions(-) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index a5fc199cde0b..cd594937b0e6 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -1108,77 +1108,11 @@ static const char *ftdi_chip_name[] = { #define FTDI_STATUS_B1_MASK (FTDI_RS_BI) /* End TIOCMIWAIT */ -/* function prototypes for a FTDI serial converter */ -static int ftdi_sio_probe(struct usb_serial *serial, - const struct usb_device_id *id); -static int ftdi_sio_port_probe(struct usb_serial_port *port); -static void ftdi_sio_port_remove(struct usb_serial_port *port); -static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port); -static void ftdi_dtr_rts(struct usb_serial_port *port, int on); -static void ftdi_process_read_urb(struct urb *urb); -static int ftdi_prepare_write_buffer(struct usb_serial_port *port, - void *dest, size_t size); static void ftdi_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old); -static int ftdi_tiocmget(struct tty_struct *tty); -static int ftdi_tiocmset(struct tty_struct *tty, - unsigned int set, unsigned int clear); -static int ftdi_ioctl(struct tty_struct *tty, - unsigned int cmd, unsigned long arg); -static void get_serial_info(struct tty_struct *tty, struct serial_struct *ss); -static int set_serial_info(struct tty_struct *tty, - struct serial_struct *ss); -static void ftdi_break_ctl(struct tty_struct *tty, int break_state); -static bool ftdi_tx_empty(struct usb_serial_port *port); static int ftdi_get_modem_status(struct usb_serial_port *port, unsigned char status[2]); -static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base); -static unsigned short int ftdi_232am_baud_to_divisor(int baud); -static u32 ftdi_232bm_baud_base_to_divisor(int baud, int base); -static u32 ftdi_232bm_baud_to_divisor(int baud); -static u32 ftdi_2232h_baud_base_to_divisor(int baud, int base); -static u32 ftdi_2232h_baud_to_divisor(int baud); - -static const struct attribute_group *ftdi_groups[]; - -static struct usb_serial_driver ftdi_sio_device = { - .driver = { - .owner = THIS_MODULE, - .name = "ftdi_sio", - .dev_groups = ftdi_groups, - }, - .description = "FTDI USB Serial Device", - .id_table = id_table_combined, - .num_ports = 1, - .bulk_in_size = 512, - .bulk_out_size = 256, - .probe = ftdi_sio_probe, - .port_probe = ftdi_sio_port_probe, - .port_remove = ftdi_sio_port_remove, - .open = ftdi_open, - .dtr_rts = ftdi_dtr_rts, - .throttle = usb_serial_generic_throttle, - .unthrottle = usb_serial_generic_unthrottle, - .process_read_urb = ftdi_process_read_urb, - .prepare_write_buffer = ftdi_prepare_write_buffer, - .tiocmget = ftdi_tiocmget, - .tiocmset = ftdi_tiocmset, - .tiocmiwait = usb_serial_generic_tiocmiwait, - .get_icount = usb_serial_generic_get_icount, - .ioctl = ftdi_ioctl, - .get_serial = get_serial_info, - .set_serial = set_serial_info, - .set_termios = ftdi_set_termios, - .break_ctl = ftdi_break_ctl, - .tx_empty = ftdi_tx_empty, -}; - -static struct usb_serial_driver * const serial_drivers[] = { - &ftdi_sio_device, NULL -}; - - #define WDR_TIMEOUT 5000 /* default urb timeout */ #define WDR_SHORT_TIMEOUT 1000 /* shorter urb timeout */ @@ -2931,6 +2865,41 @@ static int ftdi_ioctl(struct tty_struct *tty, return -ENOIOCTLCMD; } +static struct usb_serial_driver ftdi_sio_device = { + .driver = { + .owner = THIS_MODULE, + .name = "ftdi_sio", + .dev_groups = ftdi_groups, + }, + .description = "FTDI USB Serial Device", + .id_table = id_table_combined, + .num_ports = 1, + .bulk_in_size = 512, + .bulk_out_size = 256, + .probe = ftdi_sio_probe, + .port_probe = ftdi_sio_port_probe, + .port_remove = ftdi_sio_port_remove, + .open = ftdi_open, + .dtr_rts = ftdi_dtr_rts, + .throttle = usb_serial_generic_throttle, + .unthrottle = usb_serial_generic_unthrottle, + .process_read_urb = ftdi_process_read_urb, + .prepare_write_buffer = ftdi_prepare_write_buffer, + .tiocmget = ftdi_tiocmget, + .tiocmset = ftdi_tiocmset, + .tiocmiwait = usb_serial_generic_tiocmiwait, + .get_icount = usb_serial_generic_get_icount, + .ioctl = ftdi_ioctl, + .get_serial = get_serial_info, + .set_serial = set_serial_info, + .set_termios = ftdi_set_termios, + .break_ctl = ftdi_break_ctl, + .tx_empty = ftdi_tx_empty, +}; + +static struct usb_serial_driver * const serial_drivers[] = { + &ftdi_sio_device, NULL +}; module_usb_serial_driver(serial_drivers, id_table_combined); MODULE_AUTHOR(DRIVER_AUTHOR); From patchwork Mon Sep 19 13:24:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12980441 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7AECC54EE9 for ; Mon, 19 Sep 2022 13:25:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230323AbiISNZe (ORCPT ); Mon, 19 Sep 2022 09:25:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230161AbiISNZb (ORCPT ); Mon, 19 Sep 2022 09:25:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40342CE0C; Mon, 19 Sep 2022 06:25:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6BF5FB81AE8; Mon, 19 Sep 2022 13:25:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22B8EC433D6; Mon, 19 Sep 2022 13:25:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663593926; bh=BGhrQD7LEio4Kzy/pFpU7z6uraCfbjuQ8M4hk6gm7kY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m/ge5JnI9Za+mApsbGZjOYiNxGuPzMaNK9x7zigNnuawK+GG7x3j2YVsxXP4bXoN8 4hkWvjFmJyBpIsa+bytJb46UEjPMfd34GZ8K773UlysZBy9sbmTgSQwqOf8JKemA5L W3wxagytkIyG57jOLptQ87ev/Lg4xYtetLlCw+pBEJ5AYA7YFY9yRpTrwIvOGtNNbh SYgI0bHaMHl0I/lb0F4EYa6ctGJCgOFsSM5HWgmNqBX6hAbm21sfr9lgNYy4lLBM8F FR5hEztjXh27NaTV6f/3jA9B4cUC5futvJpOHgLx0Wute7K6FK1233ZnAMsJBVshaE NaG9tW8uB++NQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oaGmB-0005RA-7V; Mon, 19 Sep 2022 15:25:31 +0200 From: Johan Hovold To: Johan Hovold Cc: Jiasheng Jiang , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] USB: serial: ftdi_sio: clean up driver prefix Date: Mon, 19 Sep 2022 15:24:56 +0200 Message-Id: <20220919132456.20851-4-johan@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220919132456.20851-1-johan@kernel.org> References: <20220919132456.20851-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop the "sio" infix from the few remaining definitions and symbol names that still had it. Signed-off-by: Johan Hovold --- drivers/usb/serial/ftdi_sio.c | 38 ++++++++++++++++------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index cd594937b0e6..f584ce29fc9f 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -100,8 +100,7 @@ struct ftdi_private { #endif }; -/* struct ftdi_sio_quirk is used by devices requiring special attention. */ -struct ftdi_sio_quirk { +struct ftdi_quirk { int (*probe)(struct usb_serial *); /* Special settings for probed ports. */ void (*port_probe)(struct ftdi_private *); @@ -114,27 +113,27 @@ static int ftdi_8u2232c_probe(struct usb_serial *serial); static void ftdi_USB_UIRT_setup(struct ftdi_private *priv); static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv); -static const struct ftdi_sio_quirk ftdi_jtag_quirk = { +static const struct ftdi_quirk ftdi_jtag_quirk = { .probe = ftdi_jtag_probe, }; -static const struct ftdi_sio_quirk ftdi_NDI_device_quirk = { +static const struct ftdi_quirk ftdi_NDI_device_quirk = { .probe = ftdi_NDI_device_setup, }; -static const struct ftdi_sio_quirk ftdi_USB_UIRT_quirk = { +static const struct ftdi_quirk ftdi_USB_UIRT_quirk = { .port_probe = ftdi_USB_UIRT_setup, }; -static const struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = { +static const struct ftdi_quirk ftdi_HE_TIRA1_quirk = { .port_probe = ftdi_HE_TIRA1_setup, }; -static const struct ftdi_sio_quirk ftdi_stmclite_quirk = { +static const struct ftdi_quirk ftdi_stmclite_quirk = { .probe = ftdi_stmclite_probe, }; -static const struct ftdi_sio_quirk ftdi_8u2232c_quirk = { +static const struct ftdi_quirk ftdi_8u2232c_quirk = { .probe = ftdi_8u2232c_probe, }; @@ -2170,12 +2169,9 @@ static void ftdi_gpio_remove(struct usb_serial_port *port) { } * *************************************************************************** */ -/* Probe function to check for special devices */ -static int ftdi_sio_probe(struct usb_serial *serial, - const struct usb_device_id *id) +static int ftdi_probe(struct usb_serial *serial, const struct usb_device_id *id) { - const struct ftdi_sio_quirk *quirk = - (struct ftdi_sio_quirk *)id->driver_info; + const struct ftdi_quirk *quirk = (struct ftdi_quirk *)id->driver_info; if (quirk && quirk->probe) { int ret = quirk->probe(serial); @@ -2188,10 +2184,10 @@ static int ftdi_sio_probe(struct usb_serial *serial, return 0; } -static int ftdi_sio_port_probe(struct usb_serial_port *port) +static int ftdi_port_probe(struct usb_serial_port *port) { + const struct ftdi_quirk *quirk = usb_get_serial_data(port->serial); struct ftdi_private *priv; - const struct ftdi_sio_quirk *quirk = usb_get_serial_data(port->serial); int result; priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL); @@ -2337,7 +2333,7 @@ static int ftdi_stmclite_probe(struct usb_serial *serial) return 0; } -static void ftdi_sio_port_remove(struct usb_serial_port *port) +static void ftdi_port_remove(struct usb_serial_port *port) { struct ftdi_private *priv = usb_get_serial_port_data(port); @@ -2865,7 +2861,7 @@ static int ftdi_ioctl(struct tty_struct *tty, return -ENOIOCTLCMD; } -static struct usb_serial_driver ftdi_sio_device = { +static struct usb_serial_driver ftdi_device = { .driver = { .owner = THIS_MODULE, .name = "ftdi_sio", @@ -2876,9 +2872,9 @@ static struct usb_serial_driver ftdi_sio_device = { .num_ports = 1, .bulk_in_size = 512, .bulk_out_size = 256, - .probe = ftdi_sio_probe, - .port_probe = ftdi_sio_port_probe, - .port_remove = ftdi_sio_port_remove, + .probe = ftdi_probe, + .port_probe = ftdi_port_probe, + .port_remove = ftdi_port_remove, .open = ftdi_open, .dtr_rts = ftdi_dtr_rts, .throttle = usb_serial_generic_throttle, @@ -2898,7 +2894,7 @@ static struct usb_serial_driver ftdi_sio_device = { }; static struct usb_serial_driver * const serial_drivers[] = { - &ftdi_sio_device, NULL + &ftdi_device, NULL }; module_usb_serial_driver(serial_drivers, id_table_combined);