Skip to contentSkip to conversation

imx: serial: add IrDA support to serial driver

PATCH In review Oskar Schirmer 2 participants 14 messages Jun 10, 2009 – Jun 16, 2009

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Using the iMX serial driver with an IrDA device needs extra peripheral settings and specific timing depending on the transmitter circuitry used.

The first five patches fix minor problems in the
generic part of the iMX serial driver

The sixth introduces a generic function to calculate optimum numerator denominator value pairs for PLL and clock register settings, the seventh patch uses this function in the iMX serial driver.

The eighth patch adds IrDA support to the iMX serial driver, the last one sets the real baud rate thru tty_encode_baud_rate, as suggested by Alan Cox.

#1 lore raw

PATCH 1/9 imx: serial: fix whitespaces (no changes in functionality)

---
 drivers/serial/imx.c |   48 +++++++++++++++++++++++-------------------------
 1 files changed, 23 insertions(+), 25 deletions(-)
drivers/serial/imx.c +23 -25
index 9f460b1..424f679 100644
@@ -302,8 +302,7 @@ static inline void imx_transmit_buffer(struct imx_port *sport)
 		/* send xmit->buf[xmit->tail]
 		 * out the port here */
 		writel(xmit->buf[xmit->tail], sport->port.membase + URTX0);
-		xmit->tail = (xmit->tail + 1) &
-		         (UART_XMIT_SIZE - 1);
+		xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
 		sport->port.icount.tx++;
 		if (uart_circ_empty(xmit))
 			break;
@@ -395,8 +394,7 @@ static irqreturn_t imx_rxint(int irq, void *dev_id)
 				continue;
 		}
 
-		if (uart_handle_sysrq_char
-		            (&sport->port, (unsigned char)rx))
+		if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx))
 			continue;
 
 		if (rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) ) {
@@ -471,26 +469,26 @@ static unsigned int imx_tx_empty(struct uart_port *port)
  */
 static unsigned int imx_get_mctrl(struct uart_port *port)
 {
-        struct imx_port *sport = (struct imx_port *)port;
-        unsigned int tmp = TIOCM_DSR | TIOCM_CAR;
+	struct imx_port *sport = (struct imx_port *)port;
+	unsigned int tmp = TIOCM_DSR | TIOCM_CAR;
 
-        if (readl(sport->port.membase + USR1) & USR1_RTSS)
-                tmp |= TIOCM_CTS;
+	if (readl(sport->port.membase + USR1) & USR1_RTSS)
+		tmp |= TIOCM_CTS;
 
-        if (readl(sport->port.membase + UCR2) & UCR2_CTS)
-                tmp |= TIOCM_RTS;
+	if (readl(sport->port.membase + UCR2) & UCR2_CTS)
+		tmp |= TIOCM_RTS;
 
-        return tmp;
+	return tmp;
 }
 
 static void imx_set_mctrl(struct uart_port *port, unsigned int mctrl)
 {
-        struct imx_port *sport = (struct imx_port *)port;
+	struct imx_port *sport = (struct imx_port *)port;
 	unsigned long temp;
 
 	temp = readl(sport->port.membase + UCR2) & ~UCR2_CTS;
 
-        if (mctrl & TIOCM_RTS)
+	if (mctrl & TIOCM_RTS)
 		temp |= UCR2_CTS;
 
 	writel(temp, sport->port.membase + UCR2);
@@ -1070,22 +1068,22 @@ static struct uart_driver imx_reg = {
 
 static int serial_imx_suspend(struct platform_device *dev, pm_message_t state)
 {
-        struct imx_port *sport = platform_get_drvdata(dev);
+	struct imx_port *sport = platform_get_drvdata(dev);
 
-        if (sport)
-                uart_suspend_port(&imx_reg, &sport->port);
+	if (sport)
+		uart_suspend_port(&imx_reg, &sport->port);
 
-        return 0;
+	return 0;
 }
 
 static int serial_imx_resume(struct platform_device *dev)
 {
-        struct imx_port *sport = platform_get_drvdata(dev);
+	struct imx_port *sport = platform_get_drvdata(dev);
 
-        if (sport)
-                uart_resume_port(&imx_reg, &sport->port);
+	if (sport)
+		uart_resume_port(&imx_reg, &sport->port);
 
-        return 0;
+	return 0;
 }
 
 static int serial_imx_probe(struct platform_device *pdev)
@@ -1141,7 +1139,7 @@ static int serial_imx_probe(struct platform_device *pdev)
 	imx_ports[pdev->id] = sport;
 
 	pdata = pdev->dev.platform_data;
-	if(pdata && (pdata->flags & IMXUART_HAVE_RTSCTS))
+	if (pdata && (pdata->flags & IMXUART_HAVE_RTSCTS))
 		sport->have_rtscts = 1;
 
 	if (pdata->init) {
@@ -1191,13 +1189,13 @@ static int serial_imx_remove(struct platform_device *pdev)
 }
 
 static struct platform_driver serial_imx_driver = {
-        .probe          = serial_imx_probe,
-        .remove         = serial_imx_remove,
+	.probe		= serial_imx_probe,
+	.remove		= serial_imx_remove,
 
 	.suspend	= serial_imx_suspend,
 	.resume		= serial_imx_resume,
 	.driver		= {
-	        .name	= "imx-uart",
+		.name	= "imx-uart",
 		.owner	= THIS_MODULE,
 	},
 };
Signature · 1 line
1.5.3.7
#2 lore raw

PATCH 2/9 imx: serial: fix one bit field type

In reply to Oskar Schirmer

From: Daniel Glöckner <[email protected]>

"have_rtscts" is assigned 1, while it is declared int:1, two's complement, which can hold 0 and -1 only. The code works, as the upper bits are cut off, and tests are done against 0 only.

Nonetheless, correctly declaring the bit field as unsigned int:1 renders the code more robust.

---
 drivers/serial/imx.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/serial/imx.c +1 -1
index 424f679..5ee325f 100644
@@ -211,7 +211,7 @@ struct imx_port {
 	struct timer_list	timer;
 	unsigned int		old_status;
 	int			txirq,rxirq,rtsirq;
-	int			have_rtscts:1;
+	unsigned int		have_rtscts:1;
 	struct clk		*clk;
 };
 
Signature · 1 line
1.5.3.7
#3 lore raw

PATCH 3/9 imx: serial: notify higher layers in case xmit IRQ was not called

In reply to Oskar Schirmer

From: Fabian Godehardt <[email protected]>

upper layers, namely line discipline, need to be notified when transmission of more data is possible. For spurious cases, where IRQ handling does not supply notification for sure, it is given additionally here, when data has just been transmitted and space in the buffer will most probably be available.

---
 drivers/serial/imx.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/serial/imx.c +3 -0
index 5ee325f..afcec9e 100644
@@ -308,6 +308,9 @@ static inline void imx_transmit_buffer(struct imx_port *sport)
 			break;
 	}
 
+	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
+		uart_write_wakeup(&sport->port);
+
 	if (uart_circ_empty(xmit))
 		imx_stop_tx(&sport->port);
 }
Signature · 1 line
1.5.3.7
#4 lore raw

PATCH 4/9 imx: serial: be sure to stop xmit upon shutdown

In reply to Oskar Schirmer

From: Fabian Godehardt <[email protected]>

needed to avoid continued transmission by hardware while software already shuts down, which might cause dangling characters to show up in hardware queues when restarting the device.

---
 drivers/serial/imx.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/serial/imx.c +4 -0
index afcec9e..3fa07a9 100644
@@ -634,6 +634,10 @@ static void imx_shutdown(struct uart_port *port)
 	struct imx_port *sport = (struct imx_port *)port;
 	unsigned long temp;
 
+	temp = readl(sport->port.membase + UCR2);
+	temp &= ~(UCR2_TXEN);
+	writel(temp, sport->port.membase + UCR2);
+
 	/*
 	 * Stop our timer.
 	 */
Signature · 1 line
1.5.3.7
#5 lore raw

PATCH 5/9 imx: serial: handle initialisation failure correctly

In reply to Oskar Schirmer

From: Daniel Glöckner <[email protected]>

correctly de-initialise device when setting up failed, call to pdata->exit() was missing.

---
 drivers/serial/imx.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
drivers/serial/imx.c +6 -1
index 3fa07a9..60892a2 100644
@@ -1155,10 +1155,15 @@ static int serial_imx_probe(struct platform_device *pdev)
 			goto clkput;
 	}
 
-	uart_add_one_port(&imx_reg, &sport->port);
+	ret = uart_add_one_port(&imx_reg, &sport->port);
+	if (ret)
+		goto deinit;
 	platform_set_drvdata(pdev, &sport->port);
 
 	return 0;
+deinit:
+	if (pdata->exit)
+		pdata->exit(pdev);
 clkput:
 	clk_put(sport->clk);
 	clk_disable(sport->clk);
Signature · 1 line
1.5.3.7
#6 lore raw

PATCH 6/9 lib: isolate rational fractions helper function

In reply to Oskar Schirmer

Provide a helper function to determine optimum numerator denominator value pairs taking into account restricted register size. Useful especially with PLL and other clock configurations.

---
 include/linux/rational.h |   19 ++++++++++++++
 lib/Kconfig              |    3 ++
 lib/Makefile             |    1 +
 lib/rational.c           |   62 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 85 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/rational.h
 create mode 100644 lib/rational.c
include/linux/rational.h new file +19 -0
new file mode 100644
index 0000000..4f532fc
@@ -0,0 +1,19 @@
+/*
+ * rational fractions
+ *
+ * Copyright (C) 2009 emlix GmbH, Oskar Schirmer <[email protected]>
+ *
+ * helper functions when coping with rational numbers,
+ * e.g. when calculating optimum numerator/denominator pairs for
+ * pll configuration taking into account restricted register size
+ */
+
+#ifndef _LINUX_RATIONAL_H
+#define _LINUX_RATIONAL_H
+
+void rational_best_approximation(
+	unsigned long given_numerator, unsigned long given_denominator,
+	unsigned long max_numerator, unsigned long max_denominator,
+	unsigned long *best_numerator, unsigned long *best_denominator);
+
+#endif /* _LINUX_RATIONAL_H */
lib/Kconfig +3 -0
index 8ade0a7..9960be0 100644
@@ -10,6 +10,9 @@ menu "Library routines"
 config BITREVERSE
 	tristate
 
+config RATIONAL
+	boolean
+
 config GENERIC_FIND_FIRST_BIT
 	bool
 
lib/Makefile +1 -0
index 33a40e4..1f6edef 100644
@@ -50,6 +50,7 @@ ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
 endif
 
 obj-$(CONFIG_BITREVERSE) += bitrev.o
+obj-$(CONFIG_RATIONAL)	+= rational.o
 obj-$(CONFIG_CRC_CCITT)	+= crc-ccitt.o
 obj-$(CONFIG_CRC16)	+= crc16.o
 obj-$(CONFIG_CRC_T10DIF)+= crc-t10dif.o
lib/rational.c new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
1.5.3.7
#7 lore raw

PATCH 7/9 imx: serial: use rational library function

In reply to Oskar Schirmer

for calculation of numerator and denominator used in baud rate setting, use generic library function for optimum settings.

---
 drivers/serial/Kconfig |    1 +
 drivers/serial/imx.c   |   30 ++++++++++--------------------
 2 files changed, 11 insertions(+), 20 deletions(-)
drivers/serial/Kconfig +1 -0
index 343e3a3..0ecb4c4 100644
@@ -833,6 +833,7 @@ config SERIAL_IMX
 	bool "IMX serial port support"
 	depends on ARM && (ARCH_IMX || ARCH_MXC)
 	select SERIAL_CORE
+	select RATIONAL
 	help
 	  If you have a machine based on a Motorola IMX CPU you
 	  can enable its onboard serial port by enabling this option.
drivers/serial/imx.c +10 -20
index 60892a2..11f93e2 100644
@@ -41,6 +41,7 @@
 #include <linux/serial_core.h>
 #include <linux/serial.h>
 #include <linux/clk.h>
+#include <linux/rational.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -670,7 +671,8 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
 	unsigned long flags;
 	unsigned int ucr2, old_ucr1, old_txrxen, baud, quot;
 	unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
-	unsigned int div, num, denom, ufcr;
+	unsigned int div, ufcr;
+	unsigned long num, denom;
 
 	/*
 	 * If we don't support modem control lines, don't allow
@@ -772,32 +774,20 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
 	if (!div)
 		div = 1;
 
-	num = baud;
-	denom = port->uartclk / div / 16;
+	rational_best_approximation(16 * div * baud, sport->port.uartclk,
+		1 << 16, 1 << 16, &num, &denom);
 
-	/* shift num and denom right until they fit into 16 bits */
-	while (num > 0x10000 || denom > 0x10000) {
-		num >>= 1;
-		denom >>= 1;
-	}
-	if (num > 0)
-		num -= 1;
-	if (denom > 0)
-		denom -= 1;
-
-	writel(num, sport->port.membase + UBIR);
-	writel(denom, sport->port.membase + UBMR);
-
-	if (div == 7)
-		div = 6; /* 6 in RFDIV means divide by 7 */
-	else
-		div = 6 - div;
+	num -= 1;
+	denom -= 1;
 
 	ufcr = readl(sport->port.membase + UFCR);
 	ufcr = (ufcr & (~UFCR_RFDIV)) |
 	    (div << 7);
 	writel(ufcr, sport->port.membase + UFCR);
 
+	writel(num, sport->port.membase + UBIR);
+	writel(denom, sport->port.membase + UBMR);
+
 #ifdef ONEMS
 	writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS);
 #endif
Signature · 1 line
1.5.3.7
maintainer
#8 lore raw

Re: [PATCH 7/9 -v2] imx: serial: use rational library function

Hi Oskar,

Quoted 45 lines · Oskar Schirmer

for calculation of numerator and denominator used in baud rate setting, use generic library function for optimum settings.

---
 drivers/serial/Kconfig |    1 +
 drivers/serial/imx.c   |   30 ++++++++++--------------------
 2 files changed, 11 insertions(+), 20 deletions(-)
drivers/serial/Kconfig +1 -0
index 343e3a3..0ecb4c4 100644
@@ -833,6 +833,7 @@ config SERIAL_IMX
 	bool "IMX serial port support"
 	depends on ARM && (ARCH_IMX || ARCH_MXC)
 	select SERIAL_CORE
+	select RATIONAL
 	help
 	  If you have a machine based on a Motorola IMX CPU you
 	  can enable its onboard serial port by enabling this option.
drivers/serial/imx.c +3 -1
index 60892a2..11f93e2 100644
@@ -41,6 +41,7 @@
 #include <linux/serial_core.h>
 #include <linux/serial.h>
 #include <linux/clk.h>
+#include <linux/rational.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -670,7 +671,8 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
 	unsigned long flags;
 	unsigned int ucr2, old_ucr1, old_txrxen, baud, quot;
 	unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
-	unsigned int div, num, denom, ufcr;
+	unsigned int div, ufcr;
+	unsigned long num, denom;
 
 	/*
 	 * If we don't support modem control lines, don't allow

drivers/serial/imx.c imx_set_termios(struct uart_port *port, struct ktermios *termios, · line 778

Quoted 7 lines
drivers/serial/imx.c +2 -2
@@ -772,32 +774,20 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
 	if (!div)
 		div = 1;
 
-	num = baud;
-	denom = port->uartclk / div / 16;
+	rational_best_approximation(16 * div * baud, sport->port.uartclk,
+		1 << 16, 1 << 16, &num, &denom);

Reading the example you have given for rational_best_approximation() in the last patch this should be (1 << 16) - 1, right?

Quoted 36 lines
drivers/serial/imx.c +5 -17
-	/* shift num and denom right until they fit into 16 bits */
-	while (num > 0x10000 || denom > 0x10000) {
-		num >>= 1;
-		denom >>= 1;
-	}
-	if (num > 0)
-		num -= 1;
-	if (denom > 0)
-		denom -= 1;
-
-	writel(num, sport->port.membase + UBIR);
-	writel(denom, sport->port.membase + UBMR);
-
-	if (div == 7)
-		div = 6; /* 6 in RFDIV means divide by 7 */
-	else
-		div = 6 - div;
+	num -= 1;
+	denom -= 1;
 
 	ufcr = readl(sport->port.membase + UFCR);
 	ufcr = (ufcr & (~UFCR_RFDIV)) |
 	    (div << 7);
 	writel(ufcr, sport->port.membase + UFCR);
 
+	writel(num, sport->port.membase + UBIR);
+	writel(denom, sport->port.membase + UBMR);
+
 #ifdef ONEMS
 	writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS);
 #endif
Signature · 1 line
1.5.3.7
Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#9 lore raw

Re: [PATCH 7/9 -v2] imx: serial: use rational library function

Quoted 51 lines · Sascha Hauer

Hi Oskar,

Quoted 48 lines · Oskar Schirmer

for calculation of numerator and denominator used in baud rate setting, use generic library function for optimum settings.

---
 drivers/serial/Kconfig |    1 +
 drivers/serial/imx.c   |   30 ++++++++++--------------------
 2 files changed, 11 insertions(+), 20 deletions(-)
drivers/serial/Kconfig +1 -0
index 343e3a3..0ecb4c4 100644
@@ -833,6 +833,7 @@ config SERIAL_IMX
 	bool "IMX serial port support"
 	depends on ARM && (ARCH_IMX || ARCH_MXC)
 	select SERIAL_CORE
+	select RATIONAL
 	help
 	  If you have a machine based on a Motorola IMX CPU you
 	  can enable its onboard serial port by enabling this option.
drivers/serial/imx.c +3 -1
index 60892a2..11f93e2 100644
@@ -41,6 +41,7 @@
 #include <linux/serial_core.h>
 #include <linux/serial.h>
 #include <linux/clk.h>
+#include <linux/rational.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -670,7 +671,8 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
 	unsigned long flags;
 	unsigned int ucr2, old_ucr1, old_txrxen, baud, quot;
 	unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
-	unsigned int div, num, denom, ufcr;
+	unsigned int div, ufcr;
+	unsigned long num, denom;
 
 	/*
 	 * If we don't support modem control lines, don't allow
@@ -772,32 +774,20 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
 	if (!div)
 		div = 1;
 
Quoted 7 lines

drivers/serial/imx.c imx_set_termios(struct uart_port *port, struct ktermios *termios, · line 778

Quoted 4 lines
drivers/serial/imx.c +2 -2
-	num = baud;
-	denom = port->uartclk / div / 16;
+	rational_best_approximation(16 * div * baud, sport->port.uartclk,
+		1 << 16, 1 << 16, &num, &denom);

Reading the example you have given for rational_best_approximation() in the last patch this should be (1 << 16) - 1, right?

No, the registers hold values minus one, e.g. to select numerator = 14, set UBIR = 13. Thus, the maximum value for rate calculation is 1 << 16, not 0xFFFF. For the "minus 1", see below.

Quoted 13 lines
Quoted 13 lines
drivers/serial/imx.c +0 -11
-	/* shift num and denom right until they fit into 16 bits */
-	while (num > 0x10000 || denom > 0x10000) {
-		num >>= 1;
-		denom >>= 1;
-	}
-	if (num > 0)
-		num -= 1;
-	if (denom > 0)
-		denom -= 1;
-
-	writel(num, sport->port.membase + UBIR);
Quoted 8 lines

drivers/serial/imx.c imx_set_termios(struct uart_port *port, struct ktermios *termios, · line 781

Quoted 8 lines
drivers/serial/imx.c +2 -6
-	writel(denom, sport->port.membase + UBMR);
-
-	if (div == 7)
-		div = 6; /* 6 in RFDIV means divide by 7 */
-	else
-		div = 6 - div;
+	num -= 1;
+	denom -= 1;

This is where rate calculation values are
decreased for register purpose.

Quoted 23 lines
Quoted 16 lines
drivers/serial/imx.c +3 -0
 	ufcr = readl(sport->port.membase + UFCR);
 	ufcr = (ufcr & (~UFCR_RFDIV)) |
 	    (div << 7);
 	writel(ufcr, sport->port.membase + UFCR);
 
+	writel(num, sport->port.membase + UBIR);
+	writel(denom, sport->port.membase + UBMR);
+
 #ifdef ONEMS
 	writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS);
 #endif
Signature · 1 line
1.5.3.7
Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
Signature · 6 lines
oskar schirmer, emlix gmbh, http://www.emlix.com
fon +49 551 30664-0, fax -11, bahnhofsallee 1b, 37081 göttingen, germany
geschäftsführung: dr. uwe kracke, dr. cord seele, ust-idnr.: de 205 198 055
sitz der gesellschaft: göttingen, amtsgericht göttingen hr b 3160

emlix - your embedded linux partner
maintainer
#10 lore raw

Re: [PATCH 7/9 -v2] imx: serial: use rational library function

Quoted 60 lines · Oskar Schirmer
Quoted 51 lines · Sascha Hauer

Hi Oskar,

Quoted 48 lines · Oskar Schirmer

for calculation of numerator and denominator used in baud rate setting, use generic library function for optimum settings.

---
 drivers/serial/Kconfig |    1 +
 drivers/serial/imx.c   |   30 ++++++++++--------------------
 2 files changed, 11 insertions(+), 20 deletions(-)
drivers/serial/Kconfig +1 -0
index 343e3a3..0ecb4c4 100644
@@ -833,6 +833,7 @@ config SERIAL_IMX
 	bool "IMX serial port support"
 	depends on ARM && (ARCH_IMX || ARCH_MXC)
 	select SERIAL_CORE
+	select RATIONAL
 	help
 	  If you have a machine based on a Motorola IMX CPU you
 	  can enable its onboard serial port by enabling this option.
drivers/serial/imx.c +3 -1
index 60892a2..11f93e2 100644
@@ -41,6 +41,7 @@
 #include <linux/serial_core.h>
 #include <linux/serial.h>
 #include <linux/clk.h>
+#include <linux/rational.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -670,7 +671,8 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
 	unsigned long flags;
 	unsigned int ucr2, old_ucr1, old_txrxen, baud, quot;
 	unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
-	unsigned int div, num, denom, ufcr;
+	unsigned int div, ufcr;
+	unsigned long num, denom;
 
 	/*
 	 * If we don't support modem control lines, don't allow
@@ -772,32 +774,20 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
 	if (!div)
 		div = 1;
 
Quoted 7 lines

drivers/serial/imx.c imx_set_termios(struct uart_port *port, struct ktermios *termios, · line 778

Quoted 4 lines
drivers/serial/imx.c +2 -2
-	num = baud;
-	denom = port->uartclk / div / 16;
+	rational_best_approximation(16 * div * baud, sport->port.uartclk,
+		1 << 16, 1 << 16, &num, &denom);

Reading the example you have given for rational_best_approximation() in the last patch this should be (1 << 16) - 1, right?

Quoted 4 lines

No, the registers hold values minus one, e.g. to select numerator = 14, set UBIR = 13. Thus, the maximum value for rate calculation is 1 << 16, not 0xFFFF. For the "minus 1", see below.

Ah, I see.
I'm fine with this patch and the rest of the series. so applied to mxc-master.

Sascha

Quoted 58 lines
Quoted 14 lines
Quoted 14 lines
drivers/serial/imx.c +0 -11
-	/* shift num and denom right until they fit into 16 bits */
-	while (num > 0x10000 || denom > 0x10000) {
-		num >>= 1;
-		denom >>= 1;
-	}
-	if (num > 0)
-		num -= 1;
-	if (denom > 0)
-		denom -= 1;
-
-	writel(num, sport->port.membase + UBIR);
Quoted 8 lines

drivers/serial/imx.c imx_set_termios(struct uart_port *port, struct ktermios *termios, · line 781

Quoted 8 lines
drivers/serial/imx.c +2 -6
-	writel(denom, sport->port.membase + UBMR);
-
-	if (div == 7)
-		div = 6; /* 6 in RFDIV means divide by 7 */
-	else
-		div = 6 - div;
+	num -= 1;
+	denom -= 1;

This is where rate calculation values are
decreased for register purpose.

Quoted 23 lines
Quoted 16 lines
drivers/serial/imx.c +3 -0
 	ufcr = readl(sport->port.membase + UFCR);
 	ufcr = (ufcr & (~UFCR_RFDIV)) |
 	    (div << 7);
 	writel(ufcr, sport->port.membase + UFCR);
 
+	writel(num, sport->port.membase + UBIR);
+	writel(denom, sport->port.membase + UBMR);
+
 #ifdef ONEMS
 	writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS);
 #endif
Signature · 1 line
1.5.3.7
Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
Signature · 6 lines
oskar schirmer, emlix gmbh, http://www.emlix.com
fon +49 551 30664-0, fax -11, bahnhofsallee 1b, 37081 göttingen, germany
geschäftsführung: dr. uwe kracke, dr. cord seele, ust-idnr.: de 205 198 055
sitz der gesellschaft: göttingen, amtsgericht göttingen hr b 3160

emlix - your embedded linux partner
Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#11 lore raw

PATCH 8/9 imx: serial: add IrDA support to serial driver

In reply to Oskar Schirmer

From: Fabian Godehardt <[email protected]>

Using the iMX serial driver with an IrDA device needs extra peripheral settings and specific timing depending on the transmitter circuitry used.

---
 arch/arm/plat-mxc/include/mach/imx-uart.h |    5 +
 drivers/serial/imx.c                      |  195 ++++++++++++++++++++++++++---
 2 files changed, 181 insertions(+), 19 deletions(-)
arch/arm/plat-mxc/include/mach/imx-uart.h +5 -0
index 599217b..f9bd17d 100644
@@ -20,11 +20,16 @@
 #define ASMARM_ARCH_UART_H
 
 #define IMXUART_HAVE_RTSCTS (1<<0)
+#define IMXUART_IRDA        (1<<1)
 
 struct imxuart_platform_data {
 	int (*init)(struct platform_device *pdev);
 	int (*exit)(struct platform_device *pdev);
 	unsigned int flags;
+	void (*irda_enable)(int enable);
+	unsigned int irda_inv_rx:1;
+	unsigned int irda_inv_tx:1;
+	unsigned short transceiver_delay;
 };
 
 #endif
drivers/serial/imx.c +176 -19

318 lines not on this page · raw message

Signature · 1 line
1.5.3.7
#12 lore raw

PATCH 9/9 imx: serial: use tty_encode_baud_rate to set true rate

In reply to Oskar Schirmer

real baud rate may be different from the one requested. for upper layers, set the nearest value to the real rate in favour of the rate previously requested.

---
 drivers/serial/imx.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
drivers/serial/imx.c +7 -0
index 1c00e2a..c367160 100644
@@ -818,6 +818,7 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
 	unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
 	unsigned int div, ufcr;
 	unsigned long num, denom;
+	uint64_t tdiv64;
 
 	/*
 	 * If we don't support modem control lines, don't allow
@@ -930,6 +931,12 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
 	rational_best_approximation(16 * div * baud, sport->port.uartclk,
 		1 << 16, 1 << 16, &num, &denom);
 
+	tdiv64 = sport->port.uartclk;
+	tdiv64 *= num;
+	do_div(tdiv64, denom * 16 * div);
+	tty_encode_baud_rate(sport->port.info->port.tty,
+		(speed_t)tdiv64, (speed_t)tdiv64);
+
 	num -= 1;
 	denom -= 1;
 
Signature · 1 line
1.5.3.7
maintainer
#13 lore raw

Re: [PATCH 9/9 -v2] imx: serial: use tty_encode_baud_rate to set true rate

Hi,

Quoted 24 lines · Oskar Schirmer

real baud rate may be different from the one requested. for upper layers, set the nearest value to the real rate in favour of the rate previously requested.

---
 drivers/serial/imx.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
drivers/serial/imx.c +1 -0
index 1c00e2a..c367160 100644
@@ -818,6 +818,7 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
 	unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
 	unsigned int div, ufcr;
 	unsigned long num, denom;
+	uint64_t tdiv64;
 
 	/*
 	 * If we don't support modem control lines, don't allow
@@ -930,6 +931,12 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
 	rational_best_approximation(16 * div * baud, sport->port.uartclk,
 		1 << 16, 1 << 16, &num, &denom);

drivers/serial/imx.c imx_set_termios(struct uart_port *port, struct ktermios *termios, · line 942

Quoted 10 lines
drivers/serial/imx.c +6 -0
 
+	tdiv64 = sport->port.uartclk;
+	tdiv64 *= num;
+	do_div(tdiv64, denom * 16 * div);
+	tty_encode_baud_rate(sport->port.info->port.tty,
+		(speed_t)tdiv64, (speed_t)tdiv64);
+
 	num -= 1;
 	denom -= 1;
 

This patch breaks booting with a serial console on i.MX UARTs. The following patch fixes this. Alan, please consider applying it.

Sascha

Quoted 1 line

From 4ac2e4dbb3bd31d67a395740b1d4f8206441141b Mon Sep 17 00:00:00 2001

From: Sascha Hauer <[email protected]>
Date: Tue, 16 Jun 2009 09:24:57 +0200
Subject: [PATCH] i.MX serial driver: Check for NULL pointer deref before calling tty_encode_baud_rate

---
 drivers/serial/imx.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
drivers/serial/imx.c +7 -5
index 285b414..5d7b58f 100644
@@ -924,11 +924,13 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
 	rational_best_approximation(16 * div * baud, sport->port.uartclk,
 		1 << 16, 1 << 16, &num, &denom);
 
-	tdiv64 = sport->port.uartclk;
-	tdiv64 *= num;
-	do_div(tdiv64, denom * 16 * div);
-	tty_encode_baud_rate(sport->port.info->port.tty,
-		(speed_t)tdiv64, (speed_t)tdiv64);
+	if (port->info && port->info->port.tty) {
+		tdiv64 = sport->port.uartclk;
+		tdiv64 *= num;
+		do_div(tdiv64, denom * 16 * div);
+		tty_encode_baud_rate(sport->port.info->port.tty,
+				(speed_t)tdiv64, (speed_t)tdiv64);
+	}
 
 	num -= 1;
 	denom -= 1;
Signature · 8 lines
1.6.3.1


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |