linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: claudio@evidence.eu.com
To: linux-serial@vger.kernel.org
Cc: nicolas.ferre@atmel.com, clagix@gmail.com,
	Claudio Scordino <claudio@evidence.eu.com>
Subject: [PATCH 3/3] atmel_serial: add generic TTGR support
Date: Mon, 11 Feb 2013 16:54:26 +0100	[thread overview]
Message-ID: <1360598067-3577-4-git-send-email-claudio@evidence.eu.com> (raw)
In-Reply-To: <CAJa4H3fQ_khDVNcSu+39C+oZyc268YUgq9ahzt2ugk1_6eqYfw@mail.gmail.com>

From: Claudio Scordino <claudio@evidence.eu.com>

This patch adds an entry in sys/ to get/set the TTGR register for this specific
driver.

When set greater than zero the driver will insert gaps between the sent
characters. The length of the gaps will be specified in bit times. The feature
can be used either in RS232 and RS485 mode to slow down transmission if the
receiving device is not capable to process incoming characters at line speed.

Signed-off-by: Claudio Scordino <claudio@evidence.eu.com>
Signed-off-by: Guido Classen <clagix@gmail.com>
Tested-by: Guido Classen <clagix@gmail.com>
---
 drivers/tty/serial/atmel_serial.c |   53 +++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index 52648ec..df3d871 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -59,6 +59,9 @@
 #define SUPPORT_SYSRQ
 #endif
 
+/* Maximum value of TTGR according to Atmel datasheet */
+#define MAX_TTGR_VALUE		255
+
 #include <linux/serial_core.h>
 
 static void atmel_start_rx(struct uart_port *port);
@@ -99,6 +102,7 @@ static void atmel_stop_rx(struct uart_port *port);
 #define UART_PUT_BRGR(port,v)	__raw_writel(v, (port)->membase + ATMEL_US_BRGR)
 #define UART_PUT_RTOR(port,v)	__raw_writel(v, (port)->membase + ATMEL_US_RTOR)
 #define UART_PUT_TTGR(port, v)	__raw_writel(v, (port)->membase + ATMEL_US_TTGR)
+#define UART_GET_TTGR(port)	__raw_readl((port)->membase + ATMEL_US_TTGR)
 
  /* PDC registers */
 #define UART_PUT_PTCR(port,v)	__raw_writel(v, (port)->membase + ATMEL_PDC_PTCR)
@@ -181,6 +185,14 @@ to_atmel_uart_port(struct uart_port *uart)
 	return container_of(uart, struct atmel_uart_port, uart);
 }
 
+static inline bool is_uart_port_dbgu(struct uart_port *uart)
+{
+	struct atmel_uart_data *atmel_uart_data =
+	    to_platform_device((uart)->dev)->dev.platform_data;
+	return atmel_uart_data->use_dma_tx == 0
+	    && atmel_uart_data->use_dma_rx == 0;
+}
+
 #ifdef CONFIG_SERIAL_ATMEL_PDC
 static bool atmel_use_dma_rx(struct uart_port *port)
 {
@@ -1420,6 +1432,41 @@ static struct uart_ops atmel_pops = {
 #endif
 };
 
+/* Entry in sys/ to get/set TTGR register */
+
+static ssize_t set_ttgr(struct device *dev, struct device_attribute *attr,
+			const char *buf, size_t len)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct atmel_uart_data *pdata = pdev->dev.platform_data;
+	int id = pdata->num;
+	struct atmel_uart_port *atmel_port = &atmel_ports[id];
+	struct uart_port *port = &(atmel_port->uart);
+	unsigned int value;
+	if (kstrtouint(buf, 10, &value))
+		return 0;
+	if (value > MAX_TTGR_VALUE)
+		value = MAX_TTGR_VALUE;
+	UART_PUT_TTGR(port, value);
+	return strnlen(buf, PAGE_SIZE);
+}
+
+static ssize_t get_ttgr(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct atmel_uart_data *pdata = pdev->dev.platform_data;
+	int id = pdata->num;
+	struct atmel_uart_port *atmel_port = &atmel_ports[id];
+	struct uart_port *port = &(atmel_port->uart);
+	unsigned int value;
+	value = UART_GET_TTGR(port);
+	return snprintf(buf, PAGE_SIZE, "%u\n", value);
+}
+
+static DEVICE_ATTR(ttgr, 0644, get_ttgr, set_ttgr);
+
+
 static void atmel_of_init_port(struct atmel_uart_port *atmel_port,
 					 struct device_node *np)
 {
@@ -1824,6 +1871,9 @@ static int atmel_serial_probe(struct platform_device *pdev)
 		UART_PUT_CR(&port->uart, ATMEL_US_RTSEN);
 	}
 
+	if (!is_uart_port_dbgu(&port->uart))
+		device_create_file(&(pdev->dev), &dev_attr_ttgr);
+
 	return 0;
 
 err_add_port:
@@ -1858,6 +1908,9 @@ static int atmel_serial_remove(struct platform_device *pdev)
 
 	clk_put(atmel_port->clk);
 
+	if (!is_uart_port_dbgu(port))
+		device_remove_file(&(pdev->dev), &dev_attr_ttgr);
+
 	return ret;
 }
 
-- 
1.7.9.5


      parent reply	other threads:[~2013-02-11 16:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAJa4H3cYT6QOaacWEy2yZjb0hM3m4p+0L2_fXBYv8tWajYkmGw@mail.gmail.com>
2013-01-30 10:30 ` RS485 implementation questions (primarly in atmel_serial.c) Claudio Scordino
     [not found]   ` <510A3740.6060809@evidence.eu.com>
     [not found]     ` <CAJa4H3dG4V6viRbVQBgHQKtJr4Sz26mkhj8-kT7RFaLGRFXW1g@mail.gmail.com>
     [not found]       ` <51125488.7090408@evidence.eu.com>
     [not found]         ` <CAJa4H3eNAS7B+aGnN0D3WJMPVtE=sxp5HhRMutq-TrBOmXb7dw@mail.gmail.com>
     [not found]           ` <5114B500.7050007@evidence.eu.com>
2013-02-08 12:12             ` Guido Classen
2013-02-11 15:54               ` [PATCH] atmel_serial: general fixes for RS485 and TTGR claudio
2013-02-11 17:05                 ` Guido Classen
2013-02-11 15:54               ` [PATCH 1/3] RS485: add unit of measure for delays claudio
2013-02-11 15:54               ` [PATCH 2/3] atmel_serial: use msleep " claudio
2013-02-11 15:54               ` claudio [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1360598067-3577-4-git-send-email-claudio@evidence.eu.com \
    --to=claudio@evidence.eu.com \
    --cc=clagix@gmail.com \
    --cc=linux-serial@vger.kernel.org \
    --cc=nicolas.ferre@atmel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).