Hello! I have encountered quite a lot PCI cards with many different oscillator speeds while having no differences in PCI IDs (i.e. vendor and subsystem IDs were chip-dafault). Namely I own several no-name cards with OX16PCI954 and various speeds. These cards need different baud_base (= uartclk*16) settings but it can not be autodetected/pre-set because there is no way to distinguish them. Although there is a way to set baud_base via setserial(8) I was wandering whether it would be possible to expose uartclk in sysfs for read/write. I have created a following proof-of-concept experimental patch: >From 12c7e940c978da6cca9a6d51f499e7c5b53ec4b1 Mon Sep 17 00:00:00 2001 From: Tomas Hlavacek <tmshlvck@xxxxxxxxx> Date: Fri, 10 Aug 2012 23:43:17 +0200 Subject: [PATCH 1/1] [RFC] [experimental]: uartclk exposed to sysfs. TODO: * Get opinions on the whole idea of exposing uartclk to sysfs. * Get opinions on getting struct uart_port pointer in the get_attr_uart routine by changing driver data of the tty device. * Correct removal of the file (problem: How to get the device handle?) * Synchronization. * Add write routine. Signed-off-by: Tomas Hlavacek <tmshlvck@xxxxxxxxx> --- drivers/tty/serial/serial_core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index a21dc8e..2cb6ed5 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2293,6 +2293,17 @@ struct tty_driver *uart_console_device(struct console *co, int *index) return p->tty_driver; } +static ssize_t get_attr_uartclk(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct uart_port *port = (struct uart_port *)(dev_get_drvdata(dev)); + return snprintf(buf, PAGE_SIZE, "%d\n", port->uartclk); +} + +static DEVICE_ATTR(uartclk, S_IRUGO, get_attr_uartclk, NULL); + /** * uart_add_one_port - attach a driver-defined port structure * @drv: pointer to the uart low level driver structure for this port @@ -2354,6 +2365,12 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) uport->line); } + dev_set_drvdata(tty_dev, uport); + int sret = device_create_file(tty_dev, &dev_attr_uartclk); + if (sret < 0) + dev_err(tty_dev, "failed to add uartclk attr.\n"); + /* * Ensure UPF_DEAD is not set. */ -- 1.7.10.4 Tomas -- Tomáš Hlaváček <tmshlvck@xxxxxxxxx> -- To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html