Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2544073rdb; Tue, 12 Sep 2023 05:28:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLuKURJs6BD3R1BCU0BiO1M30Gf1dyMOr9SF5iVbV4+4izhJvPPnRjq8R2Q6zS9hHXpe/G X-Received: by 2002:a05:6a20:7485:b0:12e:98a3:77b7 with SMTP id p5-20020a056a20748500b0012e98a377b7mr11237605pzd.59.1694521739245; Tue, 12 Sep 2023 05:28:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694521739; cv=none; d=google.com; s=arc-20160816; b=D4+N1LpJPA9oKLWB6PVFhh8hJ5d65xBuUguS8bwjQt//Zj+SccEjYKnNw8aY4v6jbB aY8vqG14nRW5Usl24JZEFxQnCbXIboG6+Sa8oC0GjD55Oa5knZsgf6SfTFn6s+eT9k7X ouxdN1zHtKKYrxi6TCb25E3sn91me77W9Et0RQiuBuTKnSywi5Ze/HSv4on5vPiyJU7g n56Djl5wYOD5aiqJ0K/x5dNCojTBzIX55tMeM4/YkFLjn3ynRtHrOPi0bj4uHPCkrxfF d2MVi9hQxCYRhm3xn/mQegl8p6AeOHSsU0uaKJd2ZgxW22nfsfKGJ4mDA/CgHe6MFsF7 +w8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=y1oawU0bYV2LD8U6dihdHbDgCZChx5QIA3SKqVndsSI=; fh=n7dM+f7LjYuLx+o4gzxXNkEWC9u7qeJi6cmcRDZcVew=; b=hOMmUq3UR4ioAAf+uPyg3EHzjzzTl8ED/Limul5F0OQzHIfkjQxoOquKmakxl8Ct77 49wr0XEX9/IJcctjEtFKaYxPsYYBD19luSuIeQ8vxuimRISHgSLTvthR1WFQtbwL/kPO Ll8y3Vuwscv/WkGMC+JciFcBvAmNlKRN+u2B/J9b3Z15k9qChVczIcCWTtnmfwFutneP mOlhmtETd3UG3BesecXkB8Na6UOaGpkwvxfNkTF8Xy0/zDGEcD4lhPfKc0/jl06kq8pZ t7f35E5VBXkEpygdALnJbWnkwlntpF3imzxqGsxJBtl5HU8Rm31t0IPqagQR5KL/av/q 7osQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id kk13-20020a170903070d00b001a6bb7b7a44si7688884plb.307.2023.09.12.05.28.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 05:28:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 5CA3280E60A2; Tue, 12 Sep 2023 04:04:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234116AbjILLEn (ORCPT + 99 others); Tue, 12 Sep 2023 07:04:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233899AbjILLEb (ORCPT ); Tue, 12 Sep 2023 07:04:31 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 72DFF10E2; Tue, 12 Sep 2023 04:04:27 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 461AF80FC; Tue, 12 Sep 2023 11:04:25 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby Cc: Andy Shevchenko , Dhruva Gole , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , John Ogness , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v2 3/3] serial: core: Add sysfs links for serial core port instances for ttys Date: Tue, 12 Sep 2023 14:03:45 +0300 Message-ID: <20230912110350.14482-4-tony@atomide.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230912110350.14482-1-tony@atomide.com> References: <20230912110350.14482-1-tony@atomide.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 12 Sep 2023 04:04:48 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Let's allow the userspace to find out the ttyS style name for a serial core port device if a tty exists. This can be done with: $ grep DEVNAME /sys/bus/serial-base/devices/*/tty/uevent /sys/bus/serial-base/devices/00:04:0.0/tty/uevent:DEVNAME=ttyS0 /sys/bus/serial-base/devices/serial8250:0.1/tty/uevent:DEVNAME=ttyS1 /sys/bus/serial-base/devices/serial8250:0.2/tty/uevent:DEVNAME=ttyS2 /sys/bus/serial-base/devices/serial8250:0.3/tty/uevent:DEVNAME=ttyS3 With this change, we can add /dev/serial/by-id symlinks for the serial core port device instances. This allows using hardware based port addressing in addition to the legacy ttyS style naming. The serial core port naming is DEVNAME:0.0, such as the 00:04:0.0 above. The 0.0 above are serial core controller id and port id. The port id and controller id are typically both zero unless the serial port hardware controller has multiple controllers or ports. Signed-off-by: Tony Lindgren --- drivers/tty/serial/serial_core.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -3328,6 +3328,8 @@ static int serial_core_port_device_add(struct serial_ctrl_device *ctrl_dev, int serial_core_register_port(struct uart_driver *drv, struct uart_port *port) { struct serial_ctrl_device *ctrl_dev, *new_ctrl_dev = NULL; + struct uart_match match = {port, drv}; + struct device *tty_dev; int ret; mutex_lock(&port_mutex); @@ -3368,10 +3370,22 @@ int serial_core_register_port(struct uart_driver *drv, struct uart_port *port) port->flags &= ~UPF_DEAD; + tty_dev = device_find_child(port->dev, &match, serial_match_port); + if (tty_dev) { + ret = sysfs_create_link(&port->port_dev->dev.kobj, &tty_dev->kobj, + "tty"); + put_device(tty_dev); + if (ret) + goto err_remove_port; + } + mutex_unlock(&port_mutex); return 0; +err_remove_port: + serial_core_remove_one_port(drv, port); + err_unregister_port_dev: serial_base_port_device_remove(port->port_dev); @@ -3393,12 +3407,20 @@ void serial_core_unregister_port(struct uart_driver *drv, struct uart_port *port struct device *phys_dev = port->dev; struct serial_port_device *port_dev = port->port_dev; struct serial_ctrl_device *ctrl_dev = serial_core_get_ctrl_dev(port_dev); + struct uart_match match = {port, drv}; int ctrl_id = port->ctrl_id; + struct device *tty_dev; mutex_lock(&port_mutex); port->flags |= UPF_DEAD; + tty_dev = device_find_child(port->dev, &match, serial_match_port); + if (tty_dev) { + sysfs_remove_link(&port->port_dev->dev.kobj, "tty"); + put_device(tty_dev); + } + serial_core_remove_one_port(drv, port); /* Note that struct uart_port *port is no longer valid at this point */ -- 2.42.0