leds: ledtrig-tty: add tty_led_mode xtension
Subsystems (2)
v8 cover leds: ledtrig-tty: add tty_led_mode xtension
Hello,
here commes v8 of this series to add additional tty_led_modes.
v8:
Changes compared to the v7 patchset with
[email protected] are.
* Update 'Documentation/ABI/testing/sysfs-class-led-trigger-tty' with the suggested changes.
* Use a meaningfull name for the Rx/Tx enum.
* Do not use C++ comments style
Add a new patch 'ledtrig-tty-fix-brightness-set' to fix an issue with LEDs that are connected via GPIOs to the SOC with the device driver 'leds-gpio'. In my view, the wrong function is being used here. LEDs that do not need and do not have a delayed call do not work with the current implementation. Therefore, the 'led_set_brightness_nosleep' function must be used.
v7:
Changes compared to the v5 patchset with
[email protected] are.
Addressed review comments by Jiri Slaby are:
Thanks for the hint with the command 'make htmldocs SPHINXDIRS="admin-guide"'. Unfortunately, I did not know that. I have now verified it also in the browser. In my opinion, the list is now also displayed correctly in the documentation.
v6:
Changes compared to the v5 patchset with
[email protected] are.
Addressed review comments by kernel test robot are:
* fix Documentation/ABI/testing/sysfs-class-led-trigger-tty:9:
WARNING: Unexpected indentation.
* fix Documentation/ABI/testing/sysfs-class-led-trigger-tty:9:
WARNING: Block quote ends without a blank line; unexpected unindent.
Thanks to Jiri Slaby, who gave me the crucial hint of what I need to fix, to possibly make the 'Kernel test robot' happy.
v5:
Changes compared to the v4 patchset with
[email protected] are.
Sorry for the inconvenience, but I sent the wrong patch for ledtrig-tty.c in v4. The v5 patchset now includes all the changes I specified in the v4 patchset.
v4:
Changes compared to the v3 patchset with
[email protected] are.
Addressed review comments by Jiri Slaby are:
ledtrig-tty.c:
- Do not use __TTY_LED_MAX pattern us instead __TTY_LED_LAST = TTY_LED_RNG
- Move declartion and assignment into one singel line
- Use __TTY_LED_LAST pattern, to simplify tty_mode_show and tty_mode_store handling
v3:
Changes compared to the v2 patchset with
[email protected] are.
Addressed review comments by Greg K-H are:
tty.h:
- Fix first comment line and remark -%ENOTTY for the new function 'tty_get_mget' to make a proper kernel doc.
- Add the return value -%ENOTTY again, I thought it was no longer needed.
v2:
Changes compared to the initial patchset with
[email protected] are.
Addressed review comments by Jiri Slaby are:
tty.h:
- Fix compilation error because of wrong rebaseing
- Remove empty lines
- Use new 'tty_get_mget' in 'tty_tiocmget'
ledtrig-tty.c:
- Update commit description
- Use enum for tty_led_mod in struct ledtrig_tty_date
- Rename sysfs file from 'mode' to 'tty_led_mode'
- Change tty_led_mode show function to use loop instead of switch/case
- Change tty_led_mode store function to use loop instead of switch/case
- Check return value of function tty_get_mget
Florian Eckert (3):
tty: new helper function tty_get_mget
trigger: ledtrig-tty: add additional modes
ledtrig-tty: call correct brightness set function
.../ABI/testing/sysfs-class-led-trigger-tty | 18 +++ drivers/leds/trigger/ledtrig-tty.c | 145 ++++++++++++++++-- drivers/tty/tty_io.c | 28 +++- include/linux/tty.h | 1 + 4 files changed, 171 insertions(+), 21 deletions(-)
Signature · 1 line
2.30.2
PATCH v8 1/3 tty: new helper function tty_get_mget
For a given struct tty_struct, this provides the appropriate tty line state flags needed to add more modes to the ledtrig-tty trigger.
The new function is then used to get via tty_tiocmget() the different tty line states.
--- drivers/tty/tty_io.c | 28 ++++++++++++++++++++++------ include/linux/tty.h | 1 + 2 files changed, 23 insertions(+), 6 deletions(-)
drivers/tty/tty_io.c +22 -6
@@ -2493,6 +2493,24 @@ static int send_break(struct tty_struct *tty, unsigned int duration)return retval; } +/** +* tty_get_mget - get modem status +* @tty: tty device +* +* Obtain the modem status bits from the tty driver if the feature +* is supported. Return -%ENOTTY if it is not available. +*/ +int tty_get_mget (struct tty_struct *tty) +{ +int retval = -ENOTTY ; + +if (tty->ops->tiocmget) + retval = tty->ops->tiocmget (tty); + +return retval; +} +EXPORT_SYMBOL_GPL (tty_get_mget); +/** * tty_tiocmget - get modem status * @tty: tty device
@@ -2505,14 +2523,12 @@ static int send_break(struct tty_struct *tty, unsigned int duration)*/ static int tty_tiocmget (struct tty_struct *tty,int __user *p) { -int retval = -ENOTTY ; +int retval; -if (tty->ops->tiocmget) { - retval = tty->ops->tiocmget (tty); + retval =tty_get_mget (tty); +if (retval >=0 ) + retval =put_user (retval, p); -if (retval >=0 ) - retval =put_user (retval, p); - }return retval; }
include/linux/tty.h +1 -0
@@ -421,6 +421,7 @@ int tty_unthrottle_safe(struct tty_struct *tty);int tty_do_resize (struct tty_struct *tty,struct winsize *ws);int tty_get_icount (struct tty_struct *tty,struct serial_icounter_struct *icount); +int tty_get_mget (struct tty_struct *tty);int is_current_pgrp_orphaned (void );void tty_hangup (struct tty_struct *tty);void tty_vhangup (struct tty_struct *tty);
Signature · 1 line
2.30.2
PATCH v8 2/3 trigger: ledtrig-tty: add additional modes
In reply to Florian EckertAdd additional modes to trigger the selected LED.
The following modes are supported:
Tx/Rx: Flash LED on data transmission (default)
CTS: DCE Ready to accept data from the DTE.
DSR: DCE is ready to receive and send data.
CAR: DCE is receiving a carrier from a remote DTE.
RNG: DCE has detected an incoming ring signal.
The mode can be changed for example with the following command:
echo "CTS" > /sys/class/leds/<led>/mode
This would turn on the LED, when the DTE(modem) signals the DCE that it is ready to accept data.
--- .../ABI/testing/sysfs-class-led-trigger-tty | 18 +++ drivers/leds/trigger/ledtrig-tty.c | 143 ++++++++++++++++-- 2 files changed, 146 insertions(+), 15 deletions(-)
Documentation/ABI/testing/sysfs-class-led-trigger-tty +18 -0
@@ -4,3 +4,21 @@ KernelVersion: 5.10 Contact: [email protected] Description: Specifies the tty device name of the triggering tty + +What: /sys/class/leds/<led>/mode +Date: January 2023 +KernelVersion: 6.3 +Description: + Specifies the mode to trigger the LED. + The following operating modes are supported: + + ===== ============================================ + Tx/Rx Flash LED on data transmission (default) + CTS DCE Ready to accept data from the DTE + DSR DCE is ready to receive and send data + CAR DCE is receiving a carrier from a remote DTE + RNG DCE has detected an incoming ring signal + ===== ============================================ + + In CTS/DSR/CAR/RNG modes, the LED is enabled when the + tty line is high.
drivers/leds/trigger/ledtrig-tty.c +128 -15
185 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v8 3/3 ledtrig-tty: call correct brightness set function
In reply to Florian EckertThe problem is, however, that with LEDs that are connected directly to the SOC via a GPIO, the LED cannot be switched on or off. Because the 'leds-gpio' device driver does not need a delayed work.
If we look at the callstack for the function 'led_set_brightness_sync', then at the end it is checked whether the LED device driver has the function 'brightness_set_blocking' implemented. This is not the case for the 'leds-gpio' device.
The function 'brightness_set_blocking' returns LED devices -ENOTSUPP. This is not evaluated in 'ledtrig-tty' trigger.
In order for the trigger to also work with LED that does not have the 'brightness_set_blocking' function implemented, we must therefore use the internal API of the LED subsystem and use the function 'led_set_brightness_nosleep'.
--- drivers/leds/trigger/ledtrig-tty.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/leds/trigger/ledtrig-tty.c +6 -4
@@ -7,6 +7,8 @@#include <linux/tty.h> #include <uapi/linux/serial.h> +#include "../leds.h" +enum tty_led_mode {TTY_LED_RXTX ,TTY_LED_CTS ,
@@ -164,9 +166,9 @@ static void ledtrig_tty_flags(struct ledtrig_tty_data *trigger_data, unsigned in status =tty_get_mget (trigger_data->tty);if (status & flag) -led_set_brightness_sync (trigger_data->led_cdev,LED_ON ); +led_set_brightness_nosleep (trigger_data->led_cdev,LED_ON );else -led_set_brightness_sync (trigger_data->led_cdev,LED_OFF ); +led_set_brightness_nosleep (trigger_data->led_cdev,LED_OFF ); }static void ledtrig_tty_work (struct work_struct *work)
@@ -229,12 +231,12 @@ static void ledtrig_tty_work(struct work_struct *work) }if (icount.rx != trigger_data->rx || icount.tx != trigger_data->tx) { -led_set_brightness_sync (trigger_data->led_cdev,LED_ON ); +led_set_brightness_nosleep (trigger_data->led_cdev,LED_ON ); trigger_data->rx = icount.rx; trigger_data->tx = icount.tx; }else { -led_set_brightness_sync (trigger_data->led_cdev,LED_OFF ); +led_set_brightness_nosleep (trigger_data->led_cdev,LED_OFF ); }break ; }
Signature · 1 line
2.30.2
Jiri Slaby
maintainerQuoted 3 lines · Florian Eckert
Hello,
here commes v8 of this series to add additional
tty_led_modes.
I think u r 2 fast. Uwe had some more comments on v7.
Don't be afraid to wait some days after the last comments ;). As it is, it makes the review harder...
Quoted 108 lines
v8:
Changes compared to the v7 patchset with
[email protected] are.* Update '
Documentation/ABI/testing/sysfs-class-led-trigger-tty' with the suggested changes.
* Use a meaningfull name for the Rx/Tx enum.
* Do not use C++ comments styleAdd a new patch 'ledtrig-tty-fix-brightness-set' to fix an issue with LEDs that are connected via GPIOs to the SOC with the device driver 'leds-gpio'. In my view, the wrong function is being used here. LEDs that do not need and do not have a delayed call do not work with the current implementation. Therefore, the '
led_set_brightness_nosleep' function must be used.v7:
Changes compared to the v5 patchset with
[email protected] are.Addressed review comments by Jiri Slaby are:
Thanks for the hint with the command 'make htmldocs SPHINXDIRS="admin-guide"'. Unfortunately, I did not know that. I have now verified it also in the browser. In my opinion, the list is now also displayed correctly in the documentation.
v6:
Changes compared to the v5 patchset with
[email protected] are.Addressed review comments by kernel test robot are:
* fix
Documentation/ABI/testing/sysfs-class-led-trigger-tty:9:
WARNING: Unexpected indentation.
* fixDocumentation/ABI/testing/sysfs-class-led-trigger-tty:9:
WARNING: Block quote ends without a blank line; unexpected unindent.Thanks to Jiri Slaby, who gave me the crucial hint of what I need to fix, to possibly make the 'Kernel test robot' happy.
v5:
Changes compared to the v4 patchset with
[email protected] are.Sorry for the inconvenience, but I sent the wrong patch for
ledtrig-tty.cin v4. The v5 patchset now includes all the changes I specified in the v4 patchset.v4:
Changes compared to the v3 patchset with
[email protected] are.Addressed review comments by Jiri Slaby are:
ledtrig-tty.c:
- Do not use__TTY_LED_MAXpattern us instead__TTY_LED_LAST=TTY_LED_RNG
- Move declartion and assignment into one singel line
- Use__TTY_LED_LASTpattern, to simplifytty_mode_showandtty_mode_storehandlingv3:
Changes compared to the v2 patchset with
[email protected] are.Addressed review comments by Greg K-H are:
tty.h:
- Fix first comment line and remark -%ENOTTY for the new function 'tty_get_mget' to make a proper kernel doc.
- Add the return value -%ENOTTY again, I thought it was no longer needed.v2:
Changes compared to the initial patchset with
[email protected] are.Addressed review comments by Jiri Slaby are:
tty.h:
- Fix compilation error because of wrong rebaseing
- Remove empty lines
- Use new 'tty_get_mget' in 'tty_tiocmget'
ledtrig-tty.c:
- Update commit description
- Use enum fortty_led_modin structledtrig_tty_date
- Rename sysfs file from 'mode' to 'tty_led_mode'
- Changetty_led_modeshow function to use loop instead of switch/case
- Changetty_led_modestore function to use loop instead of switch/case
- Check return value of functiontty_get_mgetFlorian Eckert (3):
tty: new helper functiontty_get_mget
trigger: ledtrig-tty: add additional modes
ledtrig-tty: call correct brightness set function.../ABI/testing/sysfs-class-led-trigger-tty | 18 +++ drivers/leds/trigger/ledtrig-tty.c | 145 ++++++++++++++++-- drivers/tty/tty_io.c | 28 +++- include/linux/tty.h | 1 + 4 files changed, 171 insertions(+), 21 deletions(-)
Signature · 2 lines
js suse labs
Quoted 9 lines
Quoted 3 lines
here commes v8 of this series to add additional
tty_led_modes.I think u r 2 fast. Uwe had some more comments on v7.
Don't be afraid to wait some days after the last comments ;). As it is, it makes the review harder...
That was probably a race condition ;-) This must have been received when I sent the v8.