linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RFC: exposing uartclk value to sysfs
@ 2012-08-10 22:28 Tomas Hlavacek
  2012-08-10 22:48 ` Alan Cox
  2012-08-14  7:35 ` [PATCH 1/1] [RFC] uartclk from serial_core exposed " Tomas Hlavacek
  0 siblings, 2 replies; 30+ messages in thread
From: Tomas Hlavacek @ 2012-08-10 22:28 UTC (permalink / raw)
  To: linux-serial; +Cc: Greg Kroah-Hartman, Alan Cox

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@gmail.com>
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@gmail.com>
---
 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@gmail.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2012-09-06 19:47 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-10 22:28 RFC: exposing uartclk value to sysfs Tomas Hlavacek
2012-08-10 22:48 ` Alan Cox
2012-08-11  8:18   ` Tomas Hlavacek
2012-08-14  7:35 ` [PATCH 1/1] [RFC] uartclk from serial_core exposed " Tomas Hlavacek
2012-08-14 12:50   ` Marek Vasut
2012-08-15 17:09     ` Tomas Hlavacek
2012-08-15 17:12   ` [PATCHv2 " Tomas Hlavacek
2012-08-16 10:31   ` [PATCH " Alan Cox
2012-08-17 14:43   ` [PATCHv3 " Tomas Hlavacek
2012-08-17 15:06     ` Greg KH
2012-08-17 16:30       ` Tomas Hlavacek
2012-08-17 16:54         ` Greg KH
2012-08-17 18:44           ` Marek Vasut
2012-08-17 19:01             ` Greg KH
2012-08-17 20:25               ` Tomas Hlavacek
2012-08-17 15:07     ` Alan Cox
2012-08-19 18:34   ` [PATCHv4 " Tomas Hlavacek
2012-08-21 13:24     ` Tomas Hlavacek
2012-08-21 13:44       ` Alan Cox
2012-09-05 20:36     ` Greg KH
2012-09-05 23:16   ` [PATCHv5 1/1] uartclk value " Tomas Hlavacek
2012-09-05 23:42     ` Greg KH
2012-09-06  1:01       ` Tomas Hlavacek
2012-09-06  1:17   ` [PATCH v6] " Tomas Hlavacek
2012-09-06 16:23     ` [PATCH v6] tty: " Greg KH
2012-09-06 17:54     ` [PATCH v6] " Jiri Slaby
2012-09-06 18:39       ` Tomas Hlavacek
2012-09-06 18:54         ` Jiri Slaby
2012-09-06 19:41           ` Tomas Hlavacek
2012-09-06 19:47             ` Jiri Slaby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).