serial: add dynamic control for console write
Vaibhav Shinde [Thu, 30 Jul 2015 07:34:55 +0000 (12:34 +0530)]
provides a sysfs interface to control console writes
of a respective terminal.
(/sys/class/tty/ttyS0/console_write_enable)

bug 200105105

Change-Id: I4df7efdf18b4949ee93b34fb75360c3471018569
(cherry picked from commit 6ecbf6656530a062c5cdc82d6dc47da65b308819)
Signed-off-by: Vaibhav Shinde <vashinde@nvidia.com>
Reviewed-on: http://git-master/r/776665
Reviewed-on: http://git-master/r/826896
Reviewed-by: Dhiren Parmar <dparmar@nvidia.com>
Tested-by: Dhiren Parmar <dparmar@nvidia.com>
Reviewed-by: Gagan Grover <ggrover@nvidia.com>

drivers/tty/serial/Kconfig
drivers/tty/serial/serial_core.c

index d32a601..1b337a7 100644 (file)
@@ -1493,6 +1493,14 @@ config TEGRA_HV_COMM
          To compile this driver as a module, choose M here: the
          module will be called tegra_hv_comm.
 
+config CONTROL_CONSOLE_WRITE
+       bool "Control Console Write"
+       depends on SERIAL_8250_CONSOLE
+       default n
+       help
+         This will provide a sysfs interface to control console write
+         dynamically.
+
 endmenu
 
 endif # TTY
index 293ac21..3522631 100644 (file)
@@ -2526,6 +2526,38 @@ static ssize_t uart_get_attr_iomem_reg_shift(struct device *dev,
        return snprintf(buf, PAGE_SIZE, "%d\n", tmp.iomem_reg_shift);
 }
 
+#ifdef CONFIG_CONTROL_CONSOLE_WRITE
+static ssize_t uart_get_attr_con_write_enable(struct device *dev,
+       struct device_attribute *attr, char *buf)
+{
+       struct tty_port *port = dev_get_drvdata(dev);
+       struct uart_state *state = container_of(port, struct uart_state, port);
+       int status = state->uart_port->cons->flags & CON_ENABLED ? 1:0;
+       return snprintf(buf, PAGE_SIZE, "%d\n", status);
+}
+
+static ssize_t uart_set_attr_con_write_enable(struct device *dev,
+                               struct device_attribute *attr,
+                               const char *buf, size_t count)
+{
+       int enable;
+       struct tty_port *port = dev_get_drvdata(dev);
+       struct uart_state *state = container_of(port, struct uart_state, port);
+
+       if(sscanf(buf, "%u", &enable) != 1)
+               return -EINVAL;
+
+       if(enable)
+               state->uart_port->cons->flags |= CON_ENABLED;
+       else
+               state->uart_port->cons->flags &= ~CON_ENABLED;
+
+       return count;
+}
+
+static DEVICE_ATTR(console_write_enable, S_IWUSR | S_IRUSR | S_IRGRP,
+               uart_get_attr_con_write_enable, uart_set_attr_con_write_enable);
+#endif
 static DEVICE_ATTR(type, S_IRUSR | S_IRGRP, uart_get_attr_type, NULL);
 static DEVICE_ATTR(line, S_IRUSR | S_IRGRP, uart_get_attr_line, NULL);
 static DEVICE_ATTR(port, S_IRUSR | S_IRGRP, uart_get_attr_port, NULL);
@@ -2554,6 +2586,9 @@ static struct attribute *tty_dev_attrs[] = {
        &dev_attr_io_type.attr,
        &dev_attr_iomem_base.attr,
        &dev_attr_iomem_reg_shift.attr,
+#ifdef CONFIG_CONTROL_CONSOLE_WRITE
+       &dev_attr_console_write_enable.attr,
+#endif
        NULL,
        };