leds: ledtrig-tty: add tty_led_mode xtension
Subsystems (2)
v3 cover leds: ledtrig-tty: add tty_led_mode xtension
Hello,
here commes v3 of this series to add additional tty_led_modes.
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'
ledtrg-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 (2):
tty: new helper function tty_get_mget
trigger: ledtrig-tty: add additional modes
.../ABI/testing/sysfs-class-led-trigger-tty | 16 ++ drivers/leds/trigger/ledtrig-tty.c | 146 ++++++++++++++++-- drivers/tty/tty_io.c | 28 +++- include/linux/tty.h | 1 + 4 files changed, 170 insertions(+), 21 deletions(-)
Signature · 1 line
2.30.2
PATCH v3 1/2 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 v3 2/2 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 | 16 ++ drivers/leds/trigger/ledtrig-tty.c | 146 ++++++++++++++++-- 2 files changed, 147 insertions(+), 15 deletions(-)
Documentation/ABI/testing/sysfs-class-led-trigger-tty +16 -0
@@ -4,3 +4,19 @@ 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 operating 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. + LED on if line is high. + DSR: DCE is ready to receive and send data. + LED on if line is high. + CAR: DCE is receiving a carrier from a remote DTE. + LED on if line is high. + RNG: DCE has detected an incoming ring signal. + LED on if line is high.
drivers/leds/trigger/ledtrig-tty.c +131 -15
188 lines not on this page · raw message
Signature · 1 line
2.30.2
Jiri Slaby
maintainerRe: [PATCH v3 2/2] trigger: ledtrig-tty: add additional modes
Quoted 20 lines · Florian Eckert
Add 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>/modeThis would turn on the LED, when the DTE(modem) signals the DCE that it is ready to accept data.
Signed-off-by Florian Eckert <[email protected]>
drivers/leds/trigger/ledtrig-tty.c line 15
Quoted 9 lines
drivers/leds/trigger/ledtrig-tty.c +6
-0@@ -7,6 +7,15 @@#include <linux/tty.h> #include <uapi/linux/serial.h> +enum tty_led_mode { +TTY_LED_CNT , +TTY_LED_CTS , +TTY_LED_DSR , +TTY_LED_CAR , +TTY_LED_RNG ,
I would do:
__TTY_LED_LAST = TTY_LED_RNG;
instead of:
Quoted 27 lines
drivers/leds/trigger/ledtrig-tty.c +3
-0+__TTY_LED_MAX +}; +struct ledtrig_tty_data {struct
led_classdev*led_cdev;
structdelayed_workdwork;drivers/leds/trigger/ledtrig-tty.c +9
-0@@ -14,6 +23,15 @@ struct ledtrig_tty_data {const char *ttyname;struct tty_struct *tty;int rx, tx; +enum tty_led_mode mode; +}; + +static const char *const mode[] = { + [TTY_LED_CNT ] ="Tx/Rx" ,// Trasmit Data / Receive Data + [TTY_LED_CTS ] ="CTS" ,// CTS Clear To Send + [TTY_LED_DSR ] ="DSR" ,// DSR Data Set Ready + [TTY_LED_CAR ] ="CAR" ,// CAR Data Carrier Detect (DCD) + [TTY_LED_RNG ] ="RNG" ,// RNG Ring Indicator (RI) };static void ledtrig_tty_restart (struct ledtrig_tty_data *trigger_data)@@ -21,6 +39,71 @@ static void ledtrig_tty_restart(struct ledtrig_tty_data *trigger_data)schedule_delayed_work (&trigger_data->dwork,0 ); }
drivers/leds/trigger/ledtrig-tty.c static void ledtrig_tty_restart(struct ledtrig_tty_data *trigger_data) · line 50
Quoted 10 lines
drivers/leds/trigger/ledtrig-tty.c +9
-0+static ssize_t ledtrig_tty_mode_show (char *buf,enum tty_led_mode tty_mode) +{ +int len =0 ; +int i; + +for (i =0 ; i < __TTY_LED_MAX; i++) { +bool hit; + + hit = tty_mode == i;
Both the decl and assignment can be on a single line.
drivers/leds/trigger/ledtrig-tty.c static void ledtrig_tty_restart(struct ledtrig_tty_data *trigger_data) · line 57
Quoted 7 lines
drivers/leds/trigger/ledtrig-tty.c +7
-0+ len +=sysfs_emit_at (buf, len,"%s%s%s" , + hit ?"[" :"" , + mode[i], + hit ?"]" :"" ); + +if (i < __TTY_LED_MAX -1 ) + len +=sysfs_emit_at (buf, len," " );
And all this could be then:
for (i = 0; i <= __TTY_LED_LAST; i++) {
bool hit = i == tty_mode;
bool last = i == __TTY_LED_LAST;
len += sysfs_emit_at(buf, len, "%s%s%s%s",
hit ? "[" : "", mode[i], hit ? "]" : "", last ? "" : " "); }
Quoted 6 lines
drivers/leds/trigger/ledtrig-tty.c +6
-0+ } + + len +=sysfs_emit_at (buf, len,"\n" ); + +return len; +}
...
Quoted 10 lines
drivers/leds/trigger/ledtrig-tty.c +10
-0+static ssize_t tty_led_mode_store (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t size) +{ +struct ledtrig_tty_data *trigger_data =led_trigger_get_drvdata (dev); +ssize_t ret = size; +enum tty_led_mode tty_mode = __TTY_LED_MAX; +int i; + +/* Check for new line in string*/
drivers/leds/trigger/ledtrig-tty.c static void ledtrig_tty_restart(struct ledtrig_tty_data *trigger_data) · line 97
Quoted 10 lines
drivers/leds/trigger/ledtrig-tty.c +10
-0+if (size >0 && buf[size -1 ] =='\n' ) + size -=1 ; + +for (i =0 ; i < __TTY_LED_MAX; i++) { +if (strncmp (buf, mode[i], size) ==0 ) + tty_mode = i; + } + +if (tty_mode == __TTY_LED_MAX) +return -EINVAL ;
Ah, you use __TTY_LED_MAX as an extra value. It doesn't look nice. So now, what about:
for (i = 0; i <= __TTY_LED_LAST; i++)
if (strncmp(buf, mode[i], size) == 0) {
tty_mode = i;
break;
}
if (i > __TTY_LED_LAST)
return -EINVAL;?
thanks,
Signature · 2 lines
js suse labs