Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2583263rdh; Mon, 30 Oct 2023 01:16:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMalTnMydfT7Rlx3znGSK03cG0iWqYdvUmAhqN1LEkfjzbp5C0VRICewvUGwgUDo7MLWOP X-Received: by 2002:a17:90a:d497:b0:27d:4282:e3d2 with SMTP id s23-20020a17090ad49700b0027d4282e3d2mr6048015pju.30.1698653781980; Mon, 30 Oct 2023 01:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698653781; cv=none; d=google.com; s=arc-20160816; b=jgcQfZwicmcSO9rbpib8cJJLiUrsJipCqf6wpxMMxFq9cevAn2wJNR88s47ygs8SgQ nYfayrcv7kIj1K89tndxlpjdGWD4BTZ6uAZoN7v9cl26oPzGIbmha2eF/Hmv2khxzCb1 4zdVFLZTtDUL1oiAj+v4ksJN9k5EQAaLa8QX0A9Q/NA/Ims4ElWfNNsAoVExxQQVDqNq HDNlwlCsbGEYSD2PtlhEqYLf8r46b71w61SlckHMtuBc7ovBgHzGffcruyCFWrjUZEn8 jqFrU0wyIMHpAx0Lf+XZxumN8IQyedoEb7xia9nAaKSYMf6BzL8ipZtiwBLLrNfuNBEC erLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version; bh=kwpmiI9Xsj9opIITk3tUAPMOPJgyyz2veKUHbsGaS5g=; fh=Vqxj3KNuirN7Y0642ExgvxWEXmNnt+orcXA4OzDlyts=; b=fsfy4PeVmAr3IEXxyr2UCONknEBCe2mgKqvMYl+wybrlg7+TFXM9X+2XD+RAdjmlit qM7XRAmG0VBKGt853Vxb2pZdfIv7dWSzoMkH0+7h1+5T3XxkV8IUYa3hC8ramrHXYQtv JcfG8vNWnpq1WaHVYdN3qTlZzsJRaj2nLWizv1EBWxBaMYVP6bojCKzWCU37b4BcnXPo e/6PRrxNfaI6Zn9vs7lV/W/goneBM4uSgvo53UGlXZsCDgQi3l8hdxKW5rF2hShUXWR3 3l7l2sHCn5YfM0d9Q1aboupke8Xff1FMfIHT19rKXbbSzVdZNcvdREeEuPyUq4r4LYSq iXCg== 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:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id kk4-20020a17090b4a0400b0027fe3e7ba6dsi1543543pjb.25.2023.10.30.01.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 01:16:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 341F98083ABA; Mon, 30 Oct 2023 01:16:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232041AbjJ3IPt (ORCPT + 99 others); Mon, 30 Oct 2023 04:15:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231970AbjJ3IPs (ORCPT ); Mon, 30 Oct 2023 04:15:48 -0400 Received: from mxout70.expurgate.net (mxout70.expurgate.net [91.198.224.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 974E4BD; Mon, 30 Oct 2023 01:15:45 -0700 (PDT) Received: from [127.0.0.1] (helo=localhost) by relay.expurgate.net with smtp (Exim 4.92) (envelope-from ) id 1qxNQq-00GSKG-5Q; Mon, 30 Oct 2023 09:15:32 +0100 Received: from [195.243.126.94] (helo=securemail.tdt.de) by relay.expurgate.net with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qxNQp-000Zs3-1p; Mon, 30 Oct 2023 09:15:31 +0100 Received: from securemail.tdt.de (localhost [127.0.0.1]) by securemail.tdt.de (Postfix) with ESMTP id A3726240049; Mon, 30 Oct 2023 09:15:30 +0100 (CET) Received: from mail.dev.tdt.de (unknown [10.2.4.42]) by securemail.tdt.de (Postfix) with ESMTP id 01A4E240040; Mon, 30 Oct 2023 09:15:29 +0100 (CET) Received: from mail.dev.tdt.de (localhost [IPv6:::1]) by mail.dev.tdt.de (Postfix) with ESMTP id 2BE07215D4; Mon, 30 Oct 2023 09:15:28 +0100 (CET) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 30 Oct 2023 09:15:28 +0100 From: Florian Eckert To: m.brock@vanmierlo.com Cc: Eckert.Florian@googlemail.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, pavel@ucw.cz, lee@kernel.org, kabel@kernel.org, u.kleine-koenig@pengutronix.de, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-leds@vger.kernel.org Subject: Re: [PATCH v5 2/2] leds: ledtrig-tty: add new line mode evaluation In-Reply-To: References: <20231023094205.2706812-1-fe@dev.tdt.de> <20231023094205.2706812-3-fe@dev.tdt.de> Message-ID: <2951fd563fc6a364d8cddfb7ec17808b@dev.tdt.de> X-Sender: fe@dev.tdt.de User-Agent: Roundcube Webmail/1.3.17 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 pete.vger.email X-purgate-ID: 151534::1698653731-DCC6A3D8-37093731/0/0 X-purgate: clean X-purgate-type: clean 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 (pete.vger.email [0.0.0.0]); Mon, 30 Oct 2023 01:16:07 -0700 (PDT) On 2023-10-28 12:43, m.brock@vanmierlo.com wrote: > Florian Eckert wrote on 2023-10-23 11:42: > >> @@ -16,6 +16,28 @@ struct ledtrig_tty_data { >> const char *ttyname; >> struct tty_struct *tty; >> int rx, tx; >> + unsigned long ttytrigger; >> +}; > > ttytriggers ? Yes that would be nicer name. thanks > [...] > >> static void ledtrig_tty_work(struct work_struct *work) >> { >> struct ledtrig_tty_data *trigger_data = >> container_of(work, struct ledtrig_tty_data, dwork.work); >> + struct led_classdev *led_cdev = trigger_data->led_cdev; >> + unsigned long interval = LEDTRIG_TTY_INTERVAL; >> struct serial_icounter_struct icount; >> + enum led_trigger_tty_state state; >> + int current_brightness; >> + int status; >> int ret; >> >> + state = TTY_LED_DISABLE; >> mutex_lock(&trigger_data->mutex); >> >> if (!trigger_data->ttyname) { >> @@ -115,22 +218,74 @@ static void ledtrig_tty_work(struct work_struct >> *work) >> trigger_data->tty = tty; >> } >> >> - ret = tty_get_icount(trigger_data->tty, &icount); >> - if (ret) { >> - dev_info(trigger_data->tty->dev, "Failed to get icount, stopped >> polling\n"); >> - mutex_unlock(&trigger_data->mutex); >> - return; >> + status = tty_get_tiocm(trigger_data->tty); >> + if (status > 0) { >> + if (test_bit(TRIGGER_TTY_CTS, &trigger_data->ttytrigger)) { >> + if (status & TIOCM_CTS) >> + state = TTY_LED_ENABLE; >> + } >> + >> + if (test_bit(TRIGGER_TTY_DSR, &trigger_data->ttytrigger)) { >> + if (status & TIOCM_DSR) >> + state = TTY_LED_ENABLE; >> + } >> + >> + if (test_bit(TRIGGER_TTY_CAR, &trigger_data->ttytrigger)) { >> + if (status & TIOCM_CAR) >> + state = TTY_LED_ENABLE; >> + } >> + >> + if (test_bit(TRIGGER_TTY_RNG, &trigger_data->ttytrigger)) { >> + if (status & TIOCM_RNG) >> + state = TTY_LED_ENABLE; >> + } >> + } >> + >> + /* The rx/tx handling must come after the evaluation of TIOCM_*, >> + * since the display for rx/tx has priority >> + */ >> + if (test_bit(TRIGGER_TTY_RX, &trigger_data->ttytrigger) || >> + test_bit(TRIGGER_TTY_TX, &trigger_data->ttytrigger)) { >> + ret = tty_get_icount(trigger_data->tty, &icount); >> + if (ret) { >> + dev_info(trigger_data->tty->dev, "Failed to get icount, stopped >> polling\n"); >> + mutex_unlock(&trigger_data->mutex); >> + return; >> + } >> + >> + if (test_bit(TRIGGER_TTY_RX, &trigger_data->ttytrigger) && >> + (icount.tx != trigger_data->tx)) { > > You check for TRIGGER_TTY_RX and then compare icount.tx, is that > correct? I would say this is correct. At first I check if the tx path should be evaluated and if this is correct I check if there was a tx transmission during the last run. >> + trigger_data->tx = icount.tx; >> + state = TTY_LED_BLINK; >> + } >> + >> + if (test_bit(TRIGGER_TTY_TX, &trigger_data->ttytrigger) && >> + (icount.rx != trigger_data->rx)) { > > You check for TRIGGER_TTY_TX and then compare icount.rx, is that > correct? I would say this is correct. At first I check if the rx path should be evaluated and if this is correct I check if there was a rx transmission during the last run. >> + trigger_data->rx = icount.rx; >> + state = TTY_LED_BLINK; >> + } >> } >> >> - if (icount.rx != trigger_data->rx || >> - icount.tx != trigger_data->tx) { >> - unsigned long interval = LEDTRIG_TTY_INTERVAL; >> + current_brightness = led_cdev->brightness; >> + if (current_brightness) >> + led_cdev->blink_brightness = current_brightness; >> >> + if (!led_cdev->blink_brightness) >> + led_cdev->blink_brightness = led_cdev->max_brightness; > > Is it OK to override the chosen brightness here? In my setup my brightness in the sysfs path of the LED ist set to '0'. Even though the tty trigger was configured correctly the LED was not turned on. If I set max_brightness in this path the LED works correctly. I would check this a gain if this is still needed. >> + >> + switch (state) { >> + case TTY_LED_BLINK: >> led_blink_set_oneshot(trigger_data->led_cdev, &interval, >> &interval, 0); > > Change trigger_data->led_cdev to simply led_cdev Thanks for the hint. I will change this. > Shouldn't the led return to the line controlled steady state? Sorry I do not understand your question. > Set an invert variable to true if state was TTY_LED_ENABLE before it > got set > to TTY_LED_BLINK No matter whether the LED is on or off beforehand. I understand that the LED is always on for the first half of the period and off for the rest of the period. I think that is correct and I don't need to make a distinction via invert here. I hope I have understood your comment correctly here. > How do interval and the frequency of ledtrig_tty_work() relate? The work is twice as long as of the interval. So the variable LEDTRIG_TTY_INTERVAL = 50 and the work is scheduled LEDTRIG_TTY_INTERVAL * 2. But that was also before my change. >> - >> - trigger_data->rx = icount.rx; >> - trigger_data->tx = icount.tx; >> + break; >> + case TTY_LED_ENABLE: >> + led_set_brightness(led_cdev, led_cdev->blink_brightness); >> + break; >> + case TTY_LED_DISABLE: >> + fallthrough; >> + default: >> + led_set_brightness(led_cdev, LED_OFF); >> + break; >> } > > Maarten Thank you for your feedback. I must say, however, that I am currently in the process of preparing v6, which will implement the comments and change requests from 'greg k-h' [1]. The big change here in v6 is, that I have switched to completion and split the change in more reviewable commits. I will see if your comments can also be incorporated into the new approach. --- Florian [1] https://lore.kernel.org/linux-leds/2023102341-jogger-matching-dded@gregkh/