uart: update the sysfs handler to use uart_get_info
PATCH 1/3 uart: update the sysfs handler to use uart_get_info
From: Alan Cox <[email protected]>
The two patches needed are now in the tree. The first added the sysfs interface and directly accesses the uartclk. The second provides a proper interface for getting the values.
Wire them together.
This formes a basis for both get and set methods for any of the other uart properties and we can now fill them out further.
---
drivers/tty/serial/serial_core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/tty/serial/serial_core.c +5 -5
@@ -2329,15 +2329,15 @@ struct tty_driver *uart_console_device(struct console *co, int *index)static ssize_t uart_get_attr_uartclk (struct device *dev,struct device_attribute *attr,char *buf) { -int ret; +struct serial_struct tmp;struct tty_port *port =dev_get_drvdata (dev); struct uart_state *state = container_of(port, struct uart_state, port); -mutex_lock (&state->port.mutex); - ret =snprintf (buf,PAGE_SIZE ,"%d\n" , state->uart_port->uartclk); -mutex_unlock (&state->port.mutex); +mutex_lock (&port->mutex); +uart_get_info (port, state, &tmp); +mutex_unlock (&port->mutex); -return ret; +return snprintf (buf,PAGE_SIZE ,"%d\n" , tmp.baud_base *16 ); } static DEVICE_ATTR(uartclk, S_IRUSR | S_IRGRP, uart_get_attr_uartclk, NULL);
PATCH 2/3 uart: tidy the uart_get_info API
From: Alan Cox <[email protected]>
We pass both port and state because the original caller had both to hand. With all the attribute callers this won't be true so do the conversion in the function itself.
The current callers all do lock/query/unlock. This won't be true for future set based cases but there are plenty of get ones that will exist so split the code with a helper for the future cases.
---
drivers/tty/serial/serial_core.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
drivers/tty/serial/serial_core.c +15 -14
@@ -634,10 +634,10 @@ static void uart_unthrottle(struct tty_struct *tty)uart_set_mctrl (port,TIOCM_RTS ); } -static void uart_get_info (struct tty_port *port, -struct uart_state *state, +static void do_uart_get_info (struct tty_port *port,struct serial_struct *retinfo) { + struct uart_state *state = container_of(port, struct uart_state, port);struct uart_port *uport = state->uart_port;memset (retinfo,0 ,sizeof (*retinfo));
@@ -662,17 +662,21 @@ static void uart_get_info(struct tty_port *port, retinfo->iomem_base = (void *)(unsigned long )uport->mapbase; } -static int uart_get_info_user (struct uart_state *state, -struct serial_struct __user *retinfo) +static void uart_get_info (struct tty_port *port, +struct serial_struct *retinfo) { -struct tty_port *port = &state->port; -struct serial_struct tmp; -/* Ensure the state we copy is consistent and no hardware changes occur as we go */ mutex_lock (&port->mutex); -uart_get_info (port, state, &tmp); +do_uart_get_info (port, retinfo);mutex_unlock (&port->mutex); +} + +static int uart_get_info_user (struct tty_port *port, +struct serial_struct __user *retinfo) +{ +struct serial_struct tmp; +uart_get_info (port, &tmp);if (copy_to_user (retinfo, &tmp,sizeof (*retinfo)))return -EFAULT ;
@@ -1131,7 +1135,7 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd,*/ switch (cmd) {case TIOCGSERIAL : - ret =uart_get_info_user (state, uarg); + ret =uart_get_info_user (port, uarg);break ;case TIOCSSERIAL :
@@ -2331,12 +2335,8 @@ static ssize_t uart_get_attr_uartclk(struct device *dev, {struct serial_struct tmp;struct tty_port *port =dev_get_drvdata (dev); - struct uart_state *state = container_of(port, struct uart_state, port); - -mutex_lock (&port->mutex); -uart_get_info (port, state, &tmp); -mutex_unlock (&port->mutex); +uart_get_info (port, &tmp);return snprintf (buf,PAGE_SIZE ,"%d\n" , tmp.baud_base *16 ); }
@@ -2356,6 +2356,7 @@ static const struct attribute_group *tty_dev_attr_groups[] = { NULL }; +/** * uart_add_one_port - attach a driver-defined port structure * @drv: pointer to the uart low level driver structure for this port
PATCH 3/3 uart: add other serial core layer get attributes
In reply to Alan CoxFrom: Alan Cox <[email protected]>
---
Documentation/ABI/testing/sysfs-tty | 112 +++++++++++++++++++++++++++ drivers/tty/serial/serial_core.c | 145 +++++++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+)
Documentation/ABI/testing/sysfs-tty +112 -0
@@ -26,3 +26,115 @@ Description: UART port in serial_core, that is bound to TTY like ttyS0. uartclk = 16 * baud_base + These sysfs values expose the TIOCGSERIAL interface via + sysfs rather than via ioctls. + +What: /sys/class/tty/ttyS0/type +Date: October 2012 +Contact: Alan Cox <[email protected]> +Description: + Shows the current tty type for this port. + + These sysfs values expose the TIOCGSERIAL interface via + sysfs rather than via ioctls. + +What: /sys/class/tty/ttyS0/line +Date: October 2012 +Contact: Alan Cox <[email protected]> +Description: + Shows the current tty line number for this port. + + These sysfs values expose the TIOCGSERIAL interface via + sysfs rather than via ioctls. + +What: /sys/class/tty/ttyS0/port +Date: October 2012 +Contact: Alan Cox <[email protected]> +Description: + Shows the current tty port I/O address for this port. + + These sysfs values expose the TIOCGSERIAL interface via + sysfs rather than via ioctls. + +What: /sys/class/tty/ttyS0/irq +Date: October 2012 +Contact: Alan Cox <[email protected]> +Description: + Shows the current primary interrupt for this port. + + These sysfs values expose the TIOCGSERIAL interface via + sysfs rather than via ioctls. + +What: /sys/class/tty/ttyS0/flags +Date: October 2012 +Contact: Alan Cox <[email protected]> +Description: + Show the tty port status flags for this port. + + These sysfs values expose the TIOCGSERIAL interface via + sysfs rather than via ioctls. + +What: /sys/class/tty/ttyS0/xmit_fifo_size +Date: October 2012 +Contact: Alan Cox <[email protected]> +Description: + Show the transmit FIFO size for this port. + + These sysfs values expose the TIOCGSERIAL interface via + sysfs rather than via ioctls. + +What: /sys/class/tty/ttyS0/close_delay +Date: October 2012 +Contact: Alan Cox <[email protected]> +Description: + Show the closing delay time for this port in ms. + + These sysfs values expose the TIOCGSERIAL interface via + sysfs rather than via ioctls. + +What: /sys/class/tty/ttyS0/closing_wait +Date: October 2012 +Contact: Alan Cox <[email protected]> +Description: + Show the close wait time for this port in ms. + + These sysfs values expose the TIOCGSERIAL interface via + sysfs rather than via ioctls. + +What: /sys/class/tty/ttyS0/custom_divisor +Date: October 2012 +Contact: Alan Cox <[email protected]> +Description: + Show the custom divisor if any that is set on this port. + + These sysfs values expose the TIOCGSERIAL interface via + sysfs rather than via ioctls. + +What: /sys/class/tty/ttyS0/io_type +Date: October 2012 +Contact: Alan Cox <[email protected]> +Description: + Show the I/O type that is to be used with the iomem base + address. + + These sysfs values expose the TIOCGSERIAL interface via + sysfs rather than via ioctls. + +What: /sys/class/tty/ttyS0/iomem_base +Date: October 2012 +Contact: Alan Cox <[email protected]> +Description: + The I/O memory base for this port. + + These sysfs values expose the TIOCGSERIAL interface via + sysfs rather than via ioctls. + +What: /sys/class/tty/ttyS0/iomem_reg_shift +Date: October 2012 +Contact: Alan Cox <[email protected]> +Description: + Show the register shift indicating the spacing to be used + for accesses on this iomem address. + + These sysfs values expose the TIOCGSERIAL interface via + sysfs rather than via ioctls.
drivers/tty/serial/serial_core.c +145 -0
155 lines not on this page · raw message