* [PATCH v2 2/5] tty/serial: atmel_serial: change platform_data variable name
2011-10-12 16:06 ` [PATCH v2 1/5] tty/serial: RS485 bindings for device tree Nicolas Ferre
@ 2011-10-12 16:06 ` Nicolas Ferre
2011-10-13 1:01 ` Grant Likely
2011-10-12 16:06 ` [PATCH v2 3/5] tty/serial: atmel_serial: whitespace and braces modifications Nicolas Ferre
` (3 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Nicolas Ferre @ 2011-10-12 16:06 UTC (permalink / raw)
To: linux-arm-kernel, grant.likely, devicetree-discuss, robherring2,
claudio, jesper.nilsson, alan
Cc: linux-kernel, linux-serial, Nicolas Ferre
Easier to follow if platform_data name is pdata.
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
drivers/tty/serial/atmel_serial.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index c7232a9..a507daa 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -1417,13 +1417,13 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
struct platform_device *pdev)
{
struct uart_port *port = &atmel_port->uart;
- struct atmel_uart_data *data = pdev->dev.platform_data;
+ struct atmel_uart_data *pdata = pdev->dev.platform_data;
port->iotype = UPIO_MEM;
port->flags = UPF_BOOT_AUTOCONF;
port->ops = &atmel_pops;
port->fifosize = 1;
- port->line = data->num;
+ port->line = pdata->num;
port->dev = &pdev->dev;
port->mapbase = pdev->resource[0].start;
port->irq = pdev->resource[1].start;
@@ -1433,9 +1433,9 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring));
- if (data->regs)
+ if (pdata->regs)
/* Already mapped by setup code */
- port->membase = data->regs;
+ port->membase = pdata->regs;
else {
port->flags |= UPF_IOREMAP;
port->membase = NULL;
@@ -1450,9 +1450,9 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
/* only enable clock when USART is in use */
}
- atmel_port->use_dma_rx = data->use_dma_rx;
- atmel_port->use_dma_tx = data->use_dma_tx;
- atmel_port->rs485 = data->rs485;
+ atmel_port->use_dma_rx = pdata->use_dma_rx;
+ atmel_port->use_dma_tx = pdata->use_dma_tx;
+ atmel_port->rs485 = pdata->rs485;
/* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */
if (atmel_port->rs485.flags & SER_RS485_ENABLED)
atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
--
1.7.5.4
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2 2/5] tty/serial: atmel_serial: change platform_data variable name
2011-10-12 16:06 ` [PATCH v2 2/5] tty/serial: atmel_serial: change platform_data variable name Nicolas Ferre
@ 2011-10-13 1:01 ` Grant Likely
0 siblings, 0 replies; 11+ messages in thread
From: Grant Likely @ 2011-10-13 1:01 UTC (permalink / raw)
To: Nicolas Ferre
Cc: linux-arm-kernel, devicetree-discuss, robherring2, claudio,
jesper.nilsson, alan, linux-kernel, linux-serial
On Wed, Oct 12, 2011 at 06:06:57PM +0200, Nicolas Ferre wrote:
> Easier to follow if platform_data name is pdata.
>
> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
> ---
> drivers/tty/serial/atmel_serial.c | 14 +++++++-------
> 1 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index c7232a9..a507daa 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -1417,13 +1417,13 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
> struct platform_device *pdev)
> {
> struct uart_port *port = &atmel_port->uart;
> - struct atmel_uart_data *data = pdev->dev.platform_data;
> + struct atmel_uart_data *pdata = pdev->dev.platform_data;
>
> port->iotype = UPIO_MEM;
> port->flags = UPF_BOOT_AUTOCONF;
> port->ops = &atmel_pops;
> port->fifosize = 1;
> - port->line = data->num;
> + port->line = pdata->num;
> port->dev = &pdev->dev;
> port->mapbase = pdev->resource[0].start;
> port->irq = pdev->resource[1].start;
> @@ -1433,9 +1433,9 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
>
> memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring));
>
> - if (data->regs)
> + if (pdata->regs)
> /* Already mapped by setup code */
> - port->membase = data->regs;
> + port->membase = pdata->regs;
> else {
> port->flags |= UPF_IOREMAP;
> port->membase = NULL;
> @@ -1450,9 +1450,9 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
> /* only enable clock when USART is in use */
> }
>
> - atmel_port->use_dma_rx = data->use_dma_rx;
> - atmel_port->use_dma_tx = data->use_dma_tx;
> - atmel_port->rs485 = data->rs485;
> + atmel_port->use_dma_rx = pdata->use_dma_rx;
> + atmel_port->use_dma_tx = pdata->use_dma_tx;
> + atmel_port->rs485 = pdata->rs485;
> /* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */
> if (atmel_port->rs485.flags & SER_RS485_ENABLED)
> atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
> --
> 1.7.5.4
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 3/5] tty/serial: atmel_serial: whitespace and braces modifications
2011-10-12 16:06 ` [PATCH v2 1/5] tty/serial: RS485 bindings for device tree Nicolas Ferre
2011-10-12 16:06 ` [PATCH v2 2/5] tty/serial: atmel_serial: change platform_data variable name Nicolas Ferre
@ 2011-10-12 16:06 ` Nicolas Ferre
2011-10-13 1:02 ` Grant Likely
2011-10-12 16:06 ` [PATCH v2 4/5] tty/serial: atmel_serial: auto-enumerate ports Nicolas Ferre
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Nicolas Ferre @ 2011-10-12 16:06 UTC (permalink / raw)
To: linux-arm-kernel, grant.likely, devicetree-discuss, robherring2,
claudio, jesper.nilsson, alan
Cc: linux-kernel, linux-serial, Nicolas Ferre
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
drivers/tty/serial/atmel_serial.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index a507daa..bb72354 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -1433,10 +1433,10 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring));
- if (pdata->regs)
+ if (pdata->regs) {
/* Already mapped by setup code */
port->membase = pdata->regs;
- else {
+ } else {
port->flags |= UPF_IOREMAP;
port->membase = NULL;
}
@@ -1450,9 +1450,10 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
/* only enable clock when USART is in use */
}
- atmel_port->use_dma_rx = pdata->use_dma_rx;
- atmel_port->use_dma_tx = pdata->use_dma_tx;
+ atmel_port->use_dma_rx = pdata->use_dma_rx;
+ atmel_port->use_dma_tx = pdata->use_dma_tx;
atmel_port->rs485 = pdata->rs485;
+
/* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */
if (atmel_port->rs485.flags & SER_RS485_ENABLED)
atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
--
1.7.5.4
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2 3/5] tty/serial: atmel_serial: whitespace and braces modifications
2011-10-12 16:06 ` [PATCH v2 3/5] tty/serial: atmel_serial: whitespace and braces modifications Nicolas Ferre
@ 2011-10-13 1:02 ` Grant Likely
0 siblings, 0 replies; 11+ messages in thread
From: Grant Likely @ 2011-10-13 1:02 UTC (permalink / raw)
To: Nicolas Ferre
Cc: linux-arm-kernel, devicetree-discuss, robherring2, claudio,
jesper.nilsson, alan, linux-kernel, linux-serial
On Wed, Oct 12, 2011 at 06:06:58PM +0200, Nicolas Ferre wrote:
> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
> ---
> drivers/tty/serial/atmel_serial.c | 9 +++++----
> 1 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index a507daa..bb72354 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -1433,10 +1433,10 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
>
> memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring));
>
> - if (pdata->regs)
> + if (pdata->regs) {
> /* Already mapped by setup code */
> port->membase = pdata->regs;
> - else {
> + } else {
> port->flags |= UPF_IOREMAP;
> port->membase = NULL;
> }
> @@ -1450,9 +1450,10 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
> /* only enable clock when USART is in use */
> }
>
> - atmel_port->use_dma_rx = pdata->use_dma_rx;
> - atmel_port->use_dma_tx = pdata->use_dma_tx;
> + atmel_port->use_dma_rx = pdata->use_dma_rx;
> + atmel_port->use_dma_tx = pdata->use_dma_tx;
> atmel_port->rs485 = pdata->rs485;
> +
> /* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */
> if (atmel_port->rs485.flags & SER_RS485_ENABLED)
> atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
> --
> 1.7.5.4
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 4/5] tty/serial: atmel_serial: auto-enumerate ports
2011-10-12 16:06 ` [PATCH v2 1/5] tty/serial: RS485 bindings for device tree Nicolas Ferre
2011-10-12 16:06 ` [PATCH v2 2/5] tty/serial: atmel_serial: change platform_data variable name Nicolas Ferre
2011-10-12 16:06 ` [PATCH v2 3/5] tty/serial: atmel_serial: whitespace and braces modifications Nicolas Ferre
@ 2011-10-12 16:06 ` Nicolas Ferre
2011-10-13 1:03 ` Grant Likely
2011-10-12 16:07 ` [PATCH v2 5/5] tty/serial: atmel_serial: add device tree support Nicolas Ferre
2011-10-13 1:02 ` [PATCH v2 1/5] tty/serial: RS485 bindings for device tree Grant Likely
4 siblings, 1 reply; 11+ messages in thread
From: Nicolas Ferre @ 2011-10-12 16:06 UTC (permalink / raw)
To: linux-arm-kernel, grant.likely, devicetree-discuss, robherring2,
claudio, jesper.nilsson, alan
Cc: linux-kernel, linux-serial, Nicolas Ferre
If no platform data provided to enumerate ports, use a bit field
to choose port number and check if port is already initialized.
Use this mechanism for both console and plain serial ports.
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
drivers/tty/serial/atmel_serial.c | 44 ++++++++++++++++++++++++++++++------
1 files changed, 36 insertions(+), 8 deletions(-)
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index bb72354..1074329 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -157,6 +157,7 @@ struct atmel_uart_port {
};
static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
+static unsigned long atmel_ports_in_use;
#ifdef SUPPORT_SYSRQ
static struct console atmel_console;
@@ -1423,7 +1424,6 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
port->flags = UPF_BOOT_AUTOCONF;
port->ops = &atmel_pops;
port->fifosize = 1;
- port->line = pdata->num;
port->dev = &pdev->dev;
port->mapbase = pdev->resource[0].start;
port->irq = pdev->resource[1].start;
@@ -1613,10 +1613,15 @@ static struct console atmel_console = {
static int __init atmel_console_init(void)
{
if (atmel_default_console_device) {
- add_preferred_console(ATMEL_DEVICENAME,
- atmel_default_console_device->id, NULL);
- atmel_init_port(&atmel_ports[atmel_default_console_device->id],
- atmel_default_console_device);
+ int id = atmel_default_console_device->id;
+ struct atmel_uart_port *port = &atmel_ports[id];
+
+ set_bit(id, &atmel_ports_in_use);
+ port->backup_imr = 0;
+ port->uart.line = id;
+
+ add_preferred_console(ATMEL_DEVICENAME, id, NULL);
+ atmel_init_port(port, atmel_default_console_device);
register_console(&atmel_console);
}
@@ -1715,12 +1720,33 @@ static int __devinit atmel_serial_probe(struct platform_device *pdev)
struct atmel_uart_port *port;
struct atmel_uart_data *pdata = pdev->dev.platform_data;
void *data;
- int ret;
+ int ret = -ENODEV;
BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1));
- port = &atmel_ports[pdata->num];
+ if (pdata)
+ ret = pdata->num;
+
+ if (ret < 0)
+ /* port id not found in platform data:
+ * auto-enumerate it */
+ ret = find_first_zero_bit(&atmel_ports_in_use,
+ sizeof(atmel_ports_in_use));
+
+ if (ret > ATMEL_MAX_UART) {
+ ret = -ENODEV;
+ goto err;
+ }
+
+ if (test_and_set_bit(ret, &atmel_ports_in_use)) {
+ /* port already in use */
+ ret = -EBUSY;
+ goto err;
+ }
+
+ port = &atmel_ports[ret];
port->backup_imr = 0;
+ port->uart.line = ret;
atmel_init_port(port, pdev);
@@ -1766,7 +1792,7 @@ err_alloc_ring:
clk_put(port->clk);
port->clk = NULL;
}
-
+err:
return ret;
}
@@ -1786,6 +1812,8 @@ static int __devexit atmel_serial_remove(struct platform_device *pdev)
/* "port" is allocated statically, so we shouldn't free it */
+ clear_bit(port->line, &atmel_ports_in_use);
+
clk_put(atmel_port->clk);
return ret;
--
1.7.5.4
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2 4/5] tty/serial: atmel_serial: auto-enumerate ports
2011-10-12 16:06 ` [PATCH v2 4/5] tty/serial: atmel_serial: auto-enumerate ports Nicolas Ferre
@ 2011-10-13 1:03 ` Grant Likely
0 siblings, 0 replies; 11+ messages in thread
From: Grant Likely @ 2011-10-13 1:03 UTC (permalink / raw)
To: Nicolas Ferre
Cc: linux-arm-kernel, devicetree-discuss, robherring2, claudio,
jesper.nilsson, alan, linux-kernel, linux-serial
On Wed, Oct 12, 2011 at 06:06:59PM +0200, Nicolas Ferre wrote:
> If no platform data provided to enumerate ports, use a bit field
> to choose port number and check if port is already initialized.
> Use this mechanism for both console and plain serial ports.
>
> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
> ---
> drivers/tty/serial/atmel_serial.c | 44 ++++++++++++++++++++++++++++++------
> 1 files changed, 36 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index bb72354..1074329 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -157,6 +157,7 @@ struct atmel_uart_port {
> };
>
> static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
> +static unsigned long atmel_ports_in_use;
>
> #ifdef SUPPORT_SYSRQ
> static struct console atmel_console;
> @@ -1423,7 +1424,6 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
> port->flags = UPF_BOOT_AUTOCONF;
> port->ops = &atmel_pops;
> port->fifosize = 1;
> - port->line = pdata->num;
> port->dev = &pdev->dev;
> port->mapbase = pdev->resource[0].start;
> port->irq = pdev->resource[1].start;
> @@ -1613,10 +1613,15 @@ static struct console atmel_console = {
> static int __init atmel_console_init(void)
> {
> if (atmel_default_console_device) {
> - add_preferred_console(ATMEL_DEVICENAME,
> - atmel_default_console_device->id, NULL);
> - atmel_init_port(&atmel_ports[atmel_default_console_device->id],
> - atmel_default_console_device);
> + int id = atmel_default_console_device->id;
> + struct atmel_uart_port *port = &atmel_ports[id];
> +
> + set_bit(id, &atmel_ports_in_use);
> + port->backup_imr = 0;
> + port->uart.line = id;
> +
> + add_preferred_console(ATMEL_DEVICENAME, id, NULL);
> + atmel_init_port(port, atmel_default_console_device);
> register_console(&atmel_console);
> }
>
> @@ -1715,12 +1720,33 @@ static int __devinit atmel_serial_probe(struct platform_device *pdev)
> struct atmel_uart_port *port;
> struct atmel_uart_data *pdata = pdev->dev.platform_data;
> void *data;
> - int ret;
> + int ret = -ENODEV;
>
> BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1));
>
> - port = &atmel_ports[pdata->num];
> + if (pdata)
> + ret = pdata->num;
> +
> + if (ret < 0)
> + /* port id not found in platform data:
> + * auto-enumerate it */
> + ret = find_first_zero_bit(&atmel_ports_in_use,
> + sizeof(atmel_ports_in_use));
> +
> + if (ret > ATMEL_MAX_UART) {
> + ret = -ENODEV;
> + goto err;
> + }
> +
> + if (test_and_set_bit(ret, &atmel_ports_in_use)) {
> + /* port already in use */
> + ret = -EBUSY;
> + goto err;
> + }
> +
> + port = &atmel_ports[ret];
> port->backup_imr = 0;
> + port->uart.line = ret;
>
> atmel_init_port(port, pdev);
>
> @@ -1766,7 +1792,7 @@ err_alloc_ring:
> clk_put(port->clk);
> port->clk = NULL;
> }
> -
> +err:
> return ret;
> }
>
> @@ -1786,6 +1812,8 @@ static int __devexit atmel_serial_remove(struct platform_device *pdev)
>
> /* "port" is allocated statically, so we shouldn't free it */
>
> + clear_bit(port->line, &atmel_ports_in_use);
> +
> clk_put(atmel_port->clk);
>
> return ret;
> --
> 1.7.5.4
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 5/5] tty/serial: atmel_serial: add device tree support
2011-10-12 16:06 ` [PATCH v2 1/5] tty/serial: RS485 bindings for device tree Nicolas Ferre
` (2 preceding siblings ...)
2011-10-12 16:06 ` [PATCH v2 4/5] tty/serial: atmel_serial: auto-enumerate ports Nicolas Ferre
@ 2011-10-12 16:07 ` Nicolas Ferre
2011-10-13 1:04 ` Grant Likely
2011-10-13 1:02 ` [PATCH v2 1/5] tty/serial: RS485 bindings for device tree Grant Likely
4 siblings, 1 reply; 11+ messages in thread
From: Nicolas Ferre @ 2011-10-12 16:07 UTC (permalink / raw)
To: linux-arm-kernel, grant.likely, devicetree-discuss, robherring2,
claudio, jesper.nilsson, alan
Cc: linux-kernel, linux-serial, Nicolas Ferre
Will use aliases to enumerate ports, if available.
Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
drivers/tty/serial/atmel_serial.c | 79 +++++++++++++++++++++++++++++++++----
1 files changed, 71 insertions(+), 8 deletions(-)
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index 1074329..fc4081e 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -33,6 +33,8 @@
#include <linux/sysrq.h>
#include <linux/tty_flip.h>
#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/dma-mapping.h>
#include <linux/atmel_pdc.h>
#include <linux/atmel_serial.h>
@@ -163,6 +165,16 @@ static unsigned long atmel_ports_in_use;
static struct console atmel_console;
#endif
+#if defined(CONFIG_OF)
+static const struct of_device_id atmel_serial_dt_ids[] = {
+ { .compatible = "atmel,at91rm9200-usart" },
+ { .compatible = "atmel,at91sam9260-usart" },
+ { /* sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, atmel_serial_dt_ids);
+#endif
+
static inline struct atmel_uart_port *
to_atmel_uart_port(struct uart_port *uart)
{
@@ -1411,6 +1423,48 @@ static struct uart_ops atmel_pops = {
#endif
};
+static void __devinit atmel_of_init_port(struct atmel_uart_port *atmel_port,
+ struct device_node *np)
+{
+ u32 rs485_delay[2];
+
+ /* DMA/PDC usage specification */
+ if (of_get_property(np, "atmel,use-dma-rx", NULL))
+ atmel_port->use_dma_rx = 1;
+ else
+ atmel_port->use_dma_rx = 0;
+ if (of_get_property(np, "atmel,use-dma-tx", NULL))
+ atmel_port->use_dma_tx = 1;
+ else
+ atmel_port->use_dma_tx = 0;
+
+ /* rs485 properties */
+ if (of_property_read_u32_array(np, "rs485-rts-delay",
+ rs485_delay, 2) == 0) {
+ struct serial_rs485 *rs485conf = &atmel_port->rs485;
+
+ rs485conf->delay_rts_before_send = rs485_delay[0];
+ rs485conf->delay_rts_after_send = rs485_delay[1];
+ rs485conf->flags = 0;
+
+ if (rs485conf->delay_rts_before_send == 0 &&
+ rs485conf->delay_rts_after_send == 0) {
+ rs485conf->flags |= SER_RS485_RTS_ON_SEND;
+ } else {
+ if (rs485conf->delay_rts_before_send)
+ rs485conf->flags |= SER_RS485_RTS_BEFORE_SEND;
+ if (rs485conf->delay_rts_after_send)
+ rs485conf->flags |= SER_RS485_RTS_AFTER_SEND;
+ }
+
+ if (of_get_property(np, "rs485-rx-during-tx", NULL))
+ rs485conf->flags |= SER_RS485_RX_DURING_TX;
+
+ if (of_get_property(np, "linux,rs485-enabled-at-boot-time", NULL))
+ rs485conf->flags |= SER_RS485_ENABLED;
+ }
+}
+
/*
* Configure the port from the platform device resource info.
*/
@@ -1420,6 +1474,14 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
struct uart_port *port = &atmel_port->uart;
struct atmel_uart_data *pdata = pdev->dev.platform_data;
+ if (pdev->dev.of_node) {
+ atmel_of_init_port(atmel_port, pdev->dev.of_node);
+ } else {
+ atmel_port->use_dma_rx = pdata->use_dma_rx;
+ atmel_port->use_dma_tx = pdata->use_dma_tx;
+ atmel_port->rs485 = pdata->rs485;
+ }
+
port->iotype = UPIO_MEM;
port->flags = UPF_BOOT_AUTOCONF;
port->ops = &atmel_pops;
@@ -1433,7 +1495,7 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring));
- if (pdata->regs) {
+ if (pdata && pdata->regs) {
/* Already mapped by setup code */
port->membase = pdata->regs;
} else {
@@ -1450,10 +1512,6 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
/* only enable clock when USART is in use */
}
- atmel_port->use_dma_rx = pdata->use_dma_rx;
- atmel_port->use_dma_tx = pdata->use_dma_tx;
- atmel_port->rs485 = pdata->rs485;
-
/* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */
if (atmel_port->rs485.flags & SER_RS485_ENABLED)
atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
@@ -1718,17 +1776,21 @@ static int atmel_serial_resume(struct platform_device *pdev)
static int __devinit atmel_serial_probe(struct platform_device *pdev)
{
struct atmel_uart_port *port;
+ struct device_node *np = pdev->dev.of_node;
struct atmel_uart_data *pdata = pdev->dev.platform_data;
void *data;
int ret = -ENODEV;
BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1));
- if (pdata)
- ret = pdata->num;
+ if (np)
+ ret = of_alias_get_id(np, "serial");
+ else
+ if (pdata)
+ ret = pdata->num;
if (ret < 0)
- /* port id not found in platform data:
+ /* port id not found in platform data nor device-tree aliases:
* auto-enumerate it */
ret = find_first_zero_bit(&atmel_ports_in_use,
sizeof(atmel_ports_in_use));
@@ -1827,6 +1889,7 @@ static struct platform_driver atmel_serial_driver = {
.driver = {
.name = "atmel_usart",
.owner = THIS_MODULE,
+ .of_match_table = of_match_ptr(atmel_serial_dt_ids),
},
};
--
1.7.5.4
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2 5/5] tty/serial: atmel_serial: add device tree support
2011-10-12 16:07 ` [PATCH v2 5/5] tty/serial: atmel_serial: add device tree support Nicolas Ferre
@ 2011-10-13 1:04 ` Grant Likely
0 siblings, 0 replies; 11+ messages in thread
From: Grant Likely @ 2011-10-13 1:04 UTC (permalink / raw)
To: Nicolas Ferre
Cc: linux-arm-kernel, devicetree-discuss, robherring2, claudio,
jesper.nilsson, alan, linux-kernel, linux-serial
On Wed, Oct 12, 2011 at 06:07:00PM +0200, Nicolas Ferre wrote:
> Will use aliases to enumerate ports, if available.
>
> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
> ---
> drivers/tty/serial/atmel_serial.c | 79 +++++++++++++++++++++++++++++++++----
> 1 files changed, 71 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index 1074329..fc4081e 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -33,6 +33,8 @@
> #include <linux/sysrq.h>
> #include <linux/tty_flip.h>
> #include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> #include <linux/dma-mapping.h>
> #include <linux/atmel_pdc.h>
> #include <linux/atmel_serial.h>
> @@ -163,6 +165,16 @@ static unsigned long atmel_ports_in_use;
> static struct console atmel_console;
> #endif
>
> +#if defined(CONFIG_OF)
> +static const struct of_device_id atmel_serial_dt_ids[] = {
> + { .compatible = "atmel,at91rm9200-usart" },
> + { .compatible = "atmel,at91sam9260-usart" },
> + { /* sentinel */ }
> +};
> +
> +MODULE_DEVICE_TABLE(of, atmel_serial_dt_ids);
> +#endif
> +
> static inline struct atmel_uart_port *
> to_atmel_uart_port(struct uart_port *uart)
> {
> @@ -1411,6 +1423,48 @@ static struct uart_ops atmel_pops = {
> #endif
> };
>
> +static void __devinit atmel_of_init_port(struct atmel_uart_port *atmel_port,
> + struct device_node *np)
> +{
> + u32 rs485_delay[2];
> +
> + /* DMA/PDC usage specification */
> + if (of_get_property(np, "atmel,use-dma-rx", NULL))
> + atmel_port->use_dma_rx = 1;
> + else
> + atmel_port->use_dma_rx = 0;
> + if (of_get_property(np, "atmel,use-dma-tx", NULL))
> + atmel_port->use_dma_tx = 1;
> + else
> + atmel_port->use_dma_tx = 0;
> +
> + /* rs485 properties */
> + if (of_property_read_u32_array(np, "rs485-rts-delay",
> + rs485_delay, 2) == 0) {
> + struct serial_rs485 *rs485conf = &atmel_port->rs485;
> +
> + rs485conf->delay_rts_before_send = rs485_delay[0];
> + rs485conf->delay_rts_after_send = rs485_delay[1];
> + rs485conf->flags = 0;
> +
> + if (rs485conf->delay_rts_before_send == 0 &&
> + rs485conf->delay_rts_after_send == 0) {
> + rs485conf->flags |= SER_RS485_RTS_ON_SEND;
> + } else {
> + if (rs485conf->delay_rts_before_send)
> + rs485conf->flags |= SER_RS485_RTS_BEFORE_SEND;
> + if (rs485conf->delay_rts_after_send)
> + rs485conf->flags |= SER_RS485_RTS_AFTER_SEND;
> + }
> +
> + if (of_get_property(np, "rs485-rx-during-tx", NULL))
> + rs485conf->flags |= SER_RS485_RX_DURING_TX;
> +
> + if (of_get_property(np, "linux,rs485-enabled-at-boot-time", NULL))
> + rs485conf->flags |= SER_RS485_ENABLED;
> + }
> +}
> +
> /*
> * Configure the port from the platform device resource info.
> */
> @@ -1420,6 +1474,14 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
> struct uart_port *port = &atmel_port->uart;
> struct atmel_uart_data *pdata = pdev->dev.platform_data;
>
> + if (pdev->dev.of_node) {
> + atmel_of_init_port(atmel_port, pdev->dev.of_node);
> + } else {
> + atmel_port->use_dma_rx = pdata->use_dma_rx;
> + atmel_port->use_dma_tx = pdata->use_dma_tx;
> + atmel_port->rs485 = pdata->rs485;
> + }
> +
> port->iotype = UPIO_MEM;
> port->flags = UPF_BOOT_AUTOCONF;
> port->ops = &atmel_pops;
> @@ -1433,7 +1495,7 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
>
> memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring));
>
> - if (pdata->regs) {
> + if (pdata && pdata->regs) {
> /* Already mapped by setup code */
> port->membase = pdata->regs;
> } else {
> @@ -1450,10 +1512,6 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
> /* only enable clock when USART is in use */
> }
>
> - atmel_port->use_dma_rx = pdata->use_dma_rx;
> - atmel_port->use_dma_tx = pdata->use_dma_tx;
> - atmel_port->rs485 = pdata->rs485;
> -
> /* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */
> if (atmel_port->rs485.flags & SER_RS485_ENABLED)
> atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
> @@ -1718,17 +1776,21 @@ static int atmel_serial_resume(struct platform_device *pdev)
> static int __devinit atmel_serial_probe(struct platform_device *pdev)
> {
> struct atmel_uart_port *port;
> + struct device_node *np = pdev->dev.of_node;
> struct atmel_uart_data *pdata = pdev->dev.platform_data;
> void *data;
> int ret = -ENODEV;
>
> BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1));
>
> - if (pdata)
> - ret = pdata->num;
> + if (np)
> + ret = of_alias_get_id(np, "serial");
> + else
> + if (pdata)
> + ret = pdata->num;
>
> if (ret < 0)
> - /* port id not found in platform data:
> + /* port id not found in platform data nor device-tree aliases:
> * auto-enumerate it */
> ret = find_first_zero_bit(&atmel_ports_in_use,
> sizeof(atmel_ports_in_use));
> @@ -1827,6 +1889,7 @@ static struct platform_driver atmel_serial_driver = {
> .driver = {
> .name = "atmel_usart",
> .owner = THIS_MODULE,
> + .of_match_table = of_match_ptr(atmel_serial_dt_ids),
> },
> };
>
> --
> 1.7.5.4
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/5] tty/serial: RS485 bindings for device tree
2011-10-12 16:06 ` [PATCH v2 1/5] tty/serial: RS485 bindings for device tree Nicolas Ferre
` (3 preceding siblings ...)
2011-10-12 16:07 ` [PATCH v2 5/5] tty/serial: atmel_serial: add device tree support Nicolas Ferre
@ 2011-10-13 1:02 ` Grant Likely
4 siblings, 0 replies; 11+ messages in thread
From: Grant Likely @ 2011-10-13 1:02 UTC (permalink / raw)
To: Nicolas Ferre
Cc: linux-arm-kernel, devicetree-discuss, robherring2, claudio,
jesper.nilsson, alan, linux-kernel, linux-serial
On Wed, Oct 12, 2011 at 06:06:56PM +0200, Nicolas Ferre wrote:
> Generic bindings for RS485 feature included in some UARTs.
> Those bindings have to be used withing an UART device tree node.
> Documentation updated to link to the bindings definition.
>
> Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
> ---
> Documentation/devicetree/bindings/serial/rs485.txt | 31 ++++++++++++++++++++
> .../devicetree/bindings/tty/serial/atmel-usart.txt | 27 +++++++++++++++++
> Documentation/serial/serial-rs485.txt | 5 +++
> 3 files changed, 63 insertions(+), 0 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/serial/rs485.txt
> create mode 100644 Documentation/devicetree/bindings/tty/serial/atmel-usart.txt
>
> diff --git a/Documentation/devicetree/bindings/serial/rs485.txt b/Documentation/devicetree/bindings/serial/rs485.txt
> new file mode 100644
> index 0000000..1e753c6
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/serial/rs485.txt
> @@ -0,0 +1,31 @@
> +* RS485 serial communications
> +
> +The RTS signal is capable of automatically controlling line direction for
> +the built-in half-duplex mode.
> +The properties described hereafter shall be given to a half-duplex capable
> +UART node.
> +
> +Required properties:
> +- rs485-rts-delay: prop-encoded-array <a b> where:
> + * a is the delay beteween rts signal and beginning of data sent in milliseconds.
> + it corresponds to the delay before sending data.
> + * b is the delay between end of data sent and rts signal in milliseconds
> + it corresponds to the delay after sending data and actual release of the line.
> +
> +Optional properties:
> +- linux,rs485-enabled-at-boot-time: empty property telling to enable the rs485
> + feature at boot time. It can be disabled later with proper ioctl.
> +- rs485-rx-during-tx: empty property that enables the receiving of data even
> + whilst sending data.
> +
> +RS485 example for Atmel USART:
> + usart0: serial@fff8c000 {
> + compatible = "atmel,at91sam9260-usart";
> + reg = <0xfff8c000 0x4000>;
> + interrupts = <7>;
> + atmel,use-dma-rx;
> + atmel,use-dma-tx;
> + linux,rs485-enabled-at-boot-time;
> + rs485-rts-delay = <0 200>; // in milliseconds
> + };
> +
> diff --git a/Documentation/devicetree/bindings/tty/serial/atmel-usart.txt b/Documentation/devicetree/bindings/tty/serial/atmel-usart.txt
> new file mode 100644
> index 0000000..a49d9a1
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/tty/serial/atmel-usart.txt
> @@ -0,0 +1,27 @@
> +* Atmel Universal Synchronous Asynchronous Receiver/Transmitter (USART)
> +
> +Required properties:
> +- compatible: Should be "atmel,<chip>-usart"
> + The compatible <chip> indicated will be the first SoC to support an
> + additional mode or an USART new feature.
> +- reg: Should contain registers location and length
> +- interrupts: Should contain interrupt
> +
> +Optional properties:
> +- atmel,use-dma-rx: use of PDC or DMA for receiving data
> +- atmel,use-dma-tx: use of PDC or DMA for transmitting data
> +
> +<chip> compatible description:
> +- at91rm9200: legacy USART support
> +- at91sam9260: generic USART implementation for SAM9 SoCs
> +
> +Example:
> +
> + usart0: serial@fff8c000 {
> + compatible = "atmel,at91sam9260-usart";
> + reg = <0xfff8c000 0x4000>;
> + interrupts = <7>;
> + atmel,use-dma-rx;
> + atmel,use-dma-tx;
> + };
> +
> diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
> index c8878f8..079cb3d 100644
> --- a/Documentation/serial/serial-rs485.txt
> +++ b/Documentation/serial/serial-rs485.txt
> @@ -28,6 +28,10 @@
> RS485 communications. This data structure is used to set and configure RS485
> parameters in the platform data and in ioctls.
>
> + The device tree can also provide RS485 boot time parameters (see [2]
> + for bindings). The driver is in charge of filling this data structure from
> + the values given by the device tree.
> +
> Any driver for devices capable of working both as RS232 and RS485 should
> provide at least the following ioctls:
>
> @@ -121,3 +125,4 @@
> 5. REFERENCES
>
> [1] include/linux/serial.h
> + [2] Documentation/devicetree/bindings/serial/rs485.txt
> --
> 1.7.5.4
>
^ permalink raw reply [flat|nested] 11+ messages in thread