Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp324479rda; Sat, 21 Oct 2023 09:07:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDc2+sE02+T2lb4U8kPjJ9ew1pEmpzdvVI7c4xEqateujmohBeq1aPzFHUonmzLIGT4eOk X-Received: by 2002:a05:6a00:b47:b0:68f:f650:3035 with SMTP id p7-20020a056a000b4700b0068ff6503035mr4914978pfo.12.1697904459736; Sat, 21 Oct 2023 09:07:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697904459; cv=none; d=google.com; s=arc-20160816; b=BIDIHzTiYnUQCoW+v1Juo9kv7UeS3NQXedg5jvkiSRExl6cFEakIFPYHNoSJ9fIhOb YpA3qkkUHRJNKSnjylIWQXI0EGHkhw9Y4C5Z8FHxbfb8QZm7hhbLRddMw421XAKKemSp Xs8E0zhEQXMsIUzEMn6qjllV21AyE2lsH3M9J0cgaKs1NBlx73BXAKRUybeK3ntq8rIv 6XxwUrzWkOSySI/bDIYhbsM1L5PMDc3DbW18FXvsLeWL5zRPLF8j58rmrO01m3623nj/ i5wbmuUir/eGfO8NUj8OGgqvqOEKRtm5BSe6OgqSlKz5XEJuwbCjTmsDlbTAbjuGH2fD kJ7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=CRXYlUqCSO0uML2Rx057chvUvmw+267u4n5ZwabCGpQ=; fh=S+PsTUXQYGUb9tMl8Cvnf0FTXf/ZfzJAh0MRMtojqTU=; b=bW8fULmXWmJi82mcaiABG6BVxWB7zCQdRBaablyvRf20nv7TeLgBs2ixlKPN5s9IJF SBk+rcofm+5c/0t45vgEKTygciuTNkiGcColDViaDRSNlCsgeht8RXFQ2o5i2eSIet6e AojzfTkxFCZAhM8Ny/JEmdFdXxe750aMtgXakkim9vgc1gy8R3e18lAKcyoduK4+OM7R R+3gDiumhEviW847mkUWVx+LDTtYq+9KmV3NLsXbkLLBG6AkBKIAB6QTCRinN6znG4sq 1M7B3+t7iGxEawnx0V9bnjJaFGh3le0D/6oMzZ4ofwFxpIGdbhIxIXnQMAegUaK+ULBY ipFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EEXT7xVW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id u13-20020a056a00124d00b0068e256c6366si3945807pfi.352.2023.10.21.09.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Oct 2023 09:07:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EEXT7xVW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id DF86580A9AA1; Sat, 21 Oct 2023 09:07:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231721AbjJUQHS (ORCPT + 99 others); Sat, 21 Oct 2023 12:07:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231372AbjJUQHS (ORCPT ); Sat, 21 Oct 2023 12:07:18 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EAA91A4; Sat, 21 Oct 2023 09:07:13 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33D10C433C8; Sat, 21 Oct 2023 16:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1697904432; bh=ZD4gnNZ4sd1nQ6aNB8FAQiCnaG/10E18+QxR7q3dmZY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EEXT7xVWscHDKwBRbWZ6RY4BLI0cAnkl7Y4DaZ5t/cMA876i5KndYfNIWQTZRy/hr FWKS7hk8a7WlrUdPgbAOaGjEfRzlYV+Z0Gq3k6KceJ+GjPNG28sOgimtmkjYT50/aV 3ZouC08j9Fim5gosmDAuMLrcWmaMSLDVoQwEjrlI= Date: Sat, 21 Oct 2023 18:07:09 +0200 From: Greg KH To: Florian Eckert Cc: Eckert.Florian@googlemail.com, jirislaby@kernel.org, pavel@ucw.cz, lee@kernel.org, kabel@kernel.org, u.kleine-koenig@pengutronix.de, ansuelsmth@gmail.com, m.brock@vanmierlo.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-leds@vger.kernel.org Subject: Re: [PATCH v4 3/3] leds: ledtrig-tty: add new line mode evaluation Message-ID: <2023102136-reenact-cash-7295@gregkh> References: <20231019112809.881730-1-fe@dev.tdt.de> <20231019112809.881730-4-fe@dev.tdt.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231019112809.881730-4-fe@dev.tdt.de> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 howler.vger.email 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 (howler.vger.email [0.0.0.0]); Sat, 21 Oct 2023 09:07:35 -0700 (PDT) On Thu, Oct 19, 2023 at 01:28:09PM +0200, Florian Eckert wrote: > Until now, the LED blinks when data is sent via the tty (rx/tx). > The serial tty interface also supports additional input signals, that can > also be evaluated within this trigger. This change is adding the following > additional input sources, which could be controlled > via the '/sys/class//' sysfs interface. > > - line_cts: > DCE is ready to accept data from the DTE (CTS = Clear To Send). If the > line state is detected, the LED is switched on. > If set to 0 (default), the LED will not evaluate CTS. > If set to 1, the LED will evaluate CTS. > > - line_dsr: > DCE is ready to receive and send data (DSR = Data Set Ready). If the line > state is detected, the LED is switched on. > If set to 0 (default), the LED will not evaluate DSR. > If set to 1, the LED will evaluate DSR. > > - line_car: > DTE is receiving a carrier from the DCE (DCD = Data Carrier Detect). If > the line state is detected, the LED is switched on. > If set to 0 (default), the LED will not evaluate CAR (DCD). > If set to 1, the LED will evaluate CAR (DCD). > > - line_rng: > DCE has detected an incoming ring signal on the telephone line > (RI = Ring Indicator). If the line state is detected, the LED is > switched on. > If set to 0 (default), the LED will not evaluate RNG (RI). > If set to 1, the LED will evaluate RNG (RI). > > Explanation: > DCE = Data Communication Equipment (Modem) > DTE = Data Terminal Equipment (Computer) > > In addition to the new line_* entries in sysfs, the indication for the > direction of the transmitted data is independently controllable via the > new rx and tx sysfs entrie now too. These are on by default. Thus the > trigger behaves as before this change. > > - rx: > Signal reception (rx) of data on the named tty device. > If set to 0, the LED will not blink on reception. > If set to 1 (default), the LED will blink on reception. > > - tx: > Signal transmission (tx) of data on the named tty device. > If set to 0, the LED will not blink on transmission. > If set to 1 (default), the LED will blink on transmission. > > Signed-off-by: Florian Eckert > --- > .../ABI/testing/sysfs-class-led-trigger-tty | 54 +++++ > drivers/leds/trigger/ledtrig-tty.c | 192 +++++++++++++++++- > 2 files changed, 235 insertions(+), 11 deletions(-) > > diff --git a/Documentation/ABI/testing/sysfs-class-led-trigger-tty b/Documentation/ABI/testing/sysfs-class-led-trigger-tty > index 2bf6b24e781b..08127b1a4602 100644 > --- a/Documentation/ABI/testing/sysfs-class-led-trigger-tty > +++ b/Documentation/ABI/testing/sysfs-class-led-trigger-tty > @@ -4,3 +4,57 @@ KernelVersion: 5.10 > Contact: linux-leds@vger.kernel.org > Description: > Specifies the tty device name of the triggering tty > + > +What: /sys/class/leds//rx > +Date: October 2023 > +KernelVersion: 6.7 > +Description: > + Signal reception (rx) of data on the named tty device. > + If set to 0, the LED will not blink on reception. > + If set to 1 (default), the LED will blink on reception. > + > +What: /sys/class/leds//tx > +Date: October 2023 > +KernelVersion: 6.7 > +Description: > + Signal transmission (tx) of data on the named tty device. > + If set to 0, the LED will not blink on transmission. > + If set to 1 (default), the LED will blink on transmission. > + > +car rng > +What: /sys/class/leds//line_cts > +Date: October 2023 > +KernelVersion: 6.7 > +Description: > + DCE is ready to accept data from the DTE (Clear To Send). If > + the line state is detected, the LED is switched on. > + If set to 0 (default), the LED will not evaluate CTS. > + If set to 1, the LED will evaluate CTS. > + > +What: /sys/class/leds//line_dsr > +Date: October 2023 > +KernelVersion: 6.7 > +Description: > + DCE is ready to receive and send data (Data Set Ready). If > + the line state is detected, the LED is switched on. > + If set to 0 (default), the LED will not evaluate DSR. > + If set to 1, the LED will evaluate DSR. > + > +What: /sys/class/leds//line_car > +Date: October 2023 > +KernelVersion: 6.7 > +Description: > + DTE is receiving a carrier from the DCE (Data Carrier Detect). > + If the line state is detected, the LED is switched on. > + If set to 0 (default), the LED will not evaluate CAR (DCD). > + If set to 1, the LED will evaluate CAR (DCD). > + > +What: /sys/class/leds//line_cts > +Date: October 2023 > +KernelVersion: 6.7 > +Description: > + DCE has detected an incoming ring signal on the telephone > + line (Ring Indicator). If the line state is detected, the > + LED is switched on. > + If set to 0 (default), the LED will not evaluate RNG (RI). > + If set to 1, the LED will evaluate RNG (RI). > diff --git a/drivers/leds/trigger/ledtrig-tty.c b/drivers/leds/trigger/ledtrig-tty.c > index 8ae0d2d284af..6a96439a7e55 100644 > --- a/drivers/leds/trigger/ledtrig-tty.c > +++ b/drivers/leds/trigger/ledtrig-tty.c > @@ -16,6 +16,24 @@ struct ledtrig_tty_data { > const char *ttyname; > struct tty_struct *tty; > int rx, tx; > + unsigned long mode; Why is mode "unsigned long" when the tty layer treats it as an int? And really, this should be set to an explit size, u32 perhaps? Or am I confused as to exactly what this is? > +}; > + > +enum led_trigger_tty_state { > + TTY_LED_BLINK, > + TTY_LED_ENABLE, > + TTY_LED_DISABLE, > +}; > + > +enum led_trigger_tty_modes { > + TRIGGER_TTY_RX = 0, > + TRIGGER_TTY_TX, > + TRIGGER_TTY_CTS, > + TRIGGER_TTY_DSR, > + TRIGGER_TTY_CAR, > + TRIGGER_TTY_RNG, > + /* Keep last */ > + __TRIGGER_TTY_MAX, > }; > Oh wait, is "mode" this? If so, why not define it as an enum? Or if not, I'm totally confused as to what is going on here, sorry. > static void ledtrig_tty_restart(struct ledtrig_tty_data *trigger_data) > @@ -78,13 +96,106 @@ static ssize_t ttyname_store(struct device *dev, > } > static DEVICE_ATTR_RW(ttyname); > > +static ssize_t ledtrig_tty_attr_show(struct device *dev, char *buf, > + enum led_trigger_tty_modes attr) > +{ > + struct ledtrig_tty_data *trigger_data = led_trigger_get_drvdata(dev); > + int bit; > + > + switch (attr) { > + case TRIGGER_TTY_RX: > + case TRIGGER_TTY_TX: > + case TRIGGER_TTY_CTS: > + case TRIGGER_TTY_DSR: > + case TRIGGER_TTY_CAR: > + case TRIGGER_TTY_RNG: > + bit = attr; > + break; > + default: > + return -EINVAL; > + } > + > + return sprintf(buf, "%u\n", test_bit(bit, &trigger_data->mode)); sysfs_emit() for all new sysfs attributes please. > +} > + > +static ssize_t ledtrig_tty_attr_store(struct device *dev, const char *buf, > + size_t size, enum led_trigger_tty_modes attr) > +{ > + struct ledtrig_tty_data *trigger_data = led_trigger_get_drvdata(dev); > + unsigned long state; > + int ret; > + int bit; > + > + ret = kstrtoul(buf, 0, &state); > + if (ret) > + return ret; > + > + switch (attr) { > + case TRIGGER_TTY_RX: > + case TRIGGER_TTY_TX: > + case TRIGGER_TTY_CTS: > + case TRIGGER_TTY_DSR: > + case TRIGGER_TTY_CAR: > + case TRIGGER_TTY_RNG: > + bit = attr; > + break; > + default: > + return -EINVAL; > + } > + > + if (state) > + set_bit(bit, &trigger_data->mode); > + else > + clear_bit(bit, &trigger_data->mode); I think your test of "state" here is wrong, if you write in "40000" you are treating it as "1", which I don't think you want, right? thanks, greg k-h