From patchwork Tue Sep 12 11:03:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 138133 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp361035vqx; Tue, 12 Sep 2023 05:13:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/iDh2Wo9wKGUl8IrkKYqL0xtCTk91S+cWB7tJzRZ8fl9J8Tkgq94SP3wy7/TRTr/vjt3H X-Received: by 2002:a17:903:41cd:b0:1c0:c174:3695 with SMTP id u13-20020a17090341cd00b001c0c1743695mr13450087ple.13.1694520806230; Tue, 12 Sep 2023 05:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694520806; cv=none; d=google.com; s=arc-20160816; b=kpRvJEUdkWizBQ3UttI9SXf6xa7YbMrLbAMScRq2VtxaJ+ohlubIq2LR13t9vwOhZy Ppyg0g8cu+rxXoRgRVZBey5ffjWNqnjf1KcJwSwdsqBa5kJrGfatikhgEAHkyzs7bSAI inH+999PO31jlvzIJSL4KAFLBZPljzsL21d4nu7jxaRx65n6PVk9vNQd/B8KoVMfqHyo fVsw+U7qUaS+GXWfEIymjuSeMZ8c65/iVWlXjIMUpOVMmUjTUmnzepP1IYQ/6cY+d5dC LoTMr4M/AIIRM0ni+iarAmySan2vF58NSlp9/HmFd7I3aq4RHQNOtM2liIZ5ZSlvYhVg 6wVg== 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 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id u7-20020a170903124700b001b7fee7d5f0si8138642plh.25.2023.09.12.05.13.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 05:13:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 088F580BD5F1; Tue, 12 Sep 2023 04:05:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234179AbjILLEo (ORCPT + 37 others); Tue, 12 Sep 2023 07:04:44 -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_J=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 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 (groat.vger.email [0.0.0.0]); Tue, 12 Sep 2023 04:05:02 -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 groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776833848948502921 X-GMAIL-MSGID: 1776833848948502921 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 */