Skip to contentSkip to conversation

leds: ledtrig-tty: add tty_led_mode xtension

PATCH Superseded Florian Eckert 2 participants 4 messages Feb 22, 2023

Subsystems (2)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v6 cover leds: ledtrig-tty: add tty_led_mode xtension

Hello,

here commes v6 of this series to add additional tty_led_modes.

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 (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            | 145 ++++++++++++++++--
 drivers/tty/tty_io.c                          |  28 +++-
 include/linux/tty.h                           |   1 +
 4 files changed, 169 insertions(+), 21 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v6 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
index 3149114bf130..a068b03a0828 100644
@@ -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
index 730c3301d710..825186c0fec1 100644
@@ -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
#2 lore raw

PATCH v6 2/2 trigger: ledtrig-tty: add additional modes

In reply to 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>/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            | 145 ++++++++++++++++--
 2 files changed, 146 insertions(+), 15 deletions(-)
Documentation/ABI/testing/sysfs-class-led-trigger-tty +16 -0
index 2bf6b24e781b..4023585d3acf 100644
@@ -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 has detected 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 +130 -15

187 lines not on this page · raw message

Signature · 1 line
2.30.2
maintainer
#3 lore raw

Re: [PATCH v6 2/2] trigger: ledtrig-tty: add additional modes

Quoted 26 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>/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            | 145 ++++++++++++++++--
  2 files changed, 146 insertions(+), 15 deletions(-)
Documentation/ABI/testing/sysfs-class-led-trigger-tty +0 -0
index 2bf6b24e781b..4023585d3acf 100644

Documentation/ABI/testing/sysfs-class-led-trigger-tty KernelVersion: 5.10 · line 13

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-led-trigger-tty +7 -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:

Here, you should add a \n. Otherwise it won't start the list properly. Check the output e.g. by:
make htmldocs SPHINXDIRS="admin-guide"

then open the built result in a browser:
Documentation/output/admin-guide/abi-testing.html#abi-sys-class-leds-led-mode

Quoted 9 lines
Documentation/ABI/testing/sysfs-class-led-trigger-tty +9 -0
+		* 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 has detected 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.
Signature · 2 lines
js
suse labs