serial: 8250: 8250_dw changes and dynamic capabilities
Subsystems (3)
cover serial: 8250: 8250_dw changes and dynamic capabilities
Hi,
These are mainly small changes to 8250_dw.c. The interesting patch is probable the addition to 8250.c that would allow the drivers to deliver their UART's capabilities when they are registering ports.
Heikki Krogerus (5):
serial: 8250: Allow drivers to deliver capabilities
serial: 8250_dw: Don't use UPF_FIXED_TYPE
serial: 8250_dw: Map IO memory
serial: 8250_dw: Move device tree code to separate function
serial: 8250_dw: Set FIFO size dynamically
drivers/tty/serial/8250/8250.c | 22 ++++-- drivers/tty/serial/8250/8250_dw.c | 140 +++++++++++++++++++++++++++---------- 2 files changed, 120 insertions(+), 42 deletions(-)
Signature · 1 line
1.7.10.4
PATCH 1/5 serial: 8250: Allow drivers to deliver capabilities
Modern UARTs are able to provide information about their capabilities such as FIFO size. This allows the drivers to deliver this information to 8250.c when they are registering ports.
--- drivers/tty/serial/8250/8250.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/tty/serial/8250/8250.c +16 -6
@@ -1906,9 +1906,12 @@ static int serial8250_startup(struct uart_port *port)if (port->type ==PORT_8250_CIR )return -ENODEV ; - port->fifosize = uart_config[up->port.type].fifo_size; - up->tx_loadsz = uart_config[up->port.type].tx_loadsz; - up->capabilities = uart_config[up->port.type].flags; +if (!port->fifosize) + port->fifosize = uart_config[port->type].fifo_size; +if (!up->tx_loadsz) + up->tx_loadsz = uart_config[port->type].tx_loadsz; +if (!up->capabilities) + up->capabilities = uart_config[port->type].flags; up->mcr =0 ;if (port->iotype != up->cur_iotype)
@@ -2739,9 +2742,12 @@ static void serial8250_init_fixed_type_port(struct uart_8250_port *up, unsigned int type) { up->port.type = type; - up->port.fifosize = uart_config[type].fifo_size; - up->capabilities = uart_config[type].flags; - up->tx_loadsz = uart_config[type].tx_loadsz; +if (!up->port.fifosize) + up->port.fifosize = uart_config[type].fifo_size; +if (!up->tx_loadsz) + up->tx_loadsz = uart_config[type].tx_loadsz; +if (!up->capabilities) + up->capabilities = uart_config[type].flags; } static void __init
@@ -3175,6 +3181,10 @@ int serial8250_register_8250_port(struct uart_8250_port *up) uart->bugs = up->bugs; uart->port.mapbase = up->port.mapbase; uart->port.private_data = up->port.private_data; + uart->port.fifosize = up->port.fifosize; + uart->tx_loadsz = up->tx_loadsz; + uart->capabilities = up->capabilities; +if (up->port.dev) uart->port.dev = up->port.dev;
Signature · 1 line
1.7.10.4
PATCH 2/5 serial: 8250_dw: Don't use UPF_FIXED_TYPE
In reply to Heikki KrogerusAllow 8250.c to determine the port type for us. This allows the driver take advantage of FIFO on Designware UARTs that have it.
--- drivers/tty/serial/8250/8250_dw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/8250/8250_dw.c +1 -1
@@ -112,7 +112,7 @@ static int __devinit dw8250_probe(struct platform_device *pdev) uart.port.handle_irq = dw8250_handle_irq; uart.port.type =PORT_8250 ; uart.port.flags =UPF_SHARE_IRQ |UPF_BOOT_AUTOCONF |UPF_IOREMAP | -UPF_FIXED_PORT |UPF_FIXED_TYPE ; +UPF_FIXED_PORT ; uart.port.dev = &pdev->dev; uart.port.iotype =UPIO_MEM ;
Signature · 1 line
1.7.10.4
PATCH 3/5 serial: 8250_dw: Map IO memory
In reply to Heikki KrogerusThis needs to be done in order to later access the Designware specific registers.
--- drivers/tty/serial/8250/8250_dw.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_dw.c +5 -2
@@ -111,10 +111,13 @@ static int __devinit dw8250_probe(struct platform_device *pdev) uart.port.irq = irq->start; uart.port.handle_irq = dw8250_handle_irq; uart.port.type =PORT_8250 ; - uart.port.flags =UPF_SHARE_IRQ |UPF_BOOT_AUTOCONF |UPF_IOREMAP | -UPF_FIXED_PORT ; + uart.port.flags =UPF_SHARE_IRQ |UPF_BOOT_AUTOCONF |UPF_FIXED_PORT ; uart.port.dev = &pdev->dev; + uart.port.membase =ioremap (regs->start, regs->end - regs->start); +if (!uart.port.membase) +return -ENOMEM ; + uart.port.iotype =UPIO_MEM ; uart.port.serial_in = dw8250_serial_in; uart.port.serial_out = dw8250_serial_out;
Signature · 1 line
1.7.10.4
PATCH 4/5 serial: 8250_dw: Move device tree code to separate function
In reply to Heikki KrogerusTrivial cleanup. This makes it easier to add different methods to enumerate the device, for example ACPI 5.0 enumeration.
--- drivers/tty/serial/8250/8250_dw.c | 76 ++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 30 deletions(-)
drivers/tty/serial/8250/8250_dw.c +46 -30
@@ -87,25 +87,51 @@ static int dw8250_handle_irq(struct uart_port *p)return 0 ; } +static int __devinit dw8250_probe_of (struct uart_port *p) +{ +struct device_node *np = p->dev->of_node; +u32 val; + +if (!of_property_read_u32 (np,"reg-io-width" , &val)) { +switch (val) { +case 1 : +break ; +case 4 : + p->iotype =UPIO_MEM32 ; + p->serial_in = dw8250_serial_in32; + p->serial_out = dw8250_serial_out32; +break ; +default : +dev_err (p->dev,"unsupported reg-io-width (%u)\n" , val); +return -EINVAL ; + } + } + +if (!of_property_read_u32 (np,"reg-shift" , &val)) + p->regshift = val; + +if (of_property_read_u32 (np,"clock-frequency" , &val)) { +dev_err (p->dev,"no clock-frequency property set\n" ); +return -EINVAL ; + } + p->uartclk = val; + +return 0 ; +} +static int __devinit dw8250_probe (struct platform_device *pdev) {struct uart_8250_port uart = {};struct resource *regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 );struct resource *irq =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); -struct device_node *np = pdev->dev.of_node; -u32 val;struct dw8250_data *data; +int err;if (!regs || !irq) {dev_err (&pdev->dev,"no registers/irq defined\n" );return -EINVAL ; } - data =devm_kzalloc (&pdev->dev,sizeof (*data),GFP_KERNEL ); -if (!data) -return -ENOMEM ; - uart.port.private_data = data; -spin_lock_init (&uart.port.lock); uart.port.mapbase = regs->start; uart.port.irq = irq->start;
@@ -121,30 +147,20 @@ static int __devinit dw8250_probe(struct platform_device *pdev) uart.port.iotype =UPIO_MEM ; uart.port.serial_in = dw8250_serial_in; uart.port.serial_out = dw8250_serial_out; -if (!of_property_read_u32 (np,"reg-io-width" , &val)) { -switch (val) { -case 1 : -break ; -case 4 : - uart.port.iotype =UPIO_MEM32 ; - uart.port.serial_in = dw8250_serial_in32; - uart.port.serial_out = dw8250_serial_out32; -break ; -default : -dev_err (&pdev->dev,"unsupported reg-io-width (%u)\n" , - val); -return -EINVAL ; - } + +if (pdev->dev.of_node) { + err =dw8250_probe_of (&uart.port); +if (err) +return err; + }else { +return -ENODEV ; } -if (!of_property_read_u32 (np,"reg-shift" , &val)) - uart.port.regshift = val; + data =devm_kzalloc (&pdev->dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; -if (of_property_read_u32 (np,"clock-frequency" , &val)) { -dev_err (&pdev->dev,"no clock-frequency property set\n" ); -return -EINVAL ; - } - uart.port.uartclk = val; + uart.port.private_data = data; data->line =serial8250_register_8250_port (&uart);if (data->line <0 )
@@ -164,7 +180,7 @@ static int __devexit dw8250_remove(struct platform_device *pdev)return 0 ; } -static const struct of_device_id dw8250_match[] = { +static const struct of_device_id dw8250_of_match[] = { { .compatible ="snps,dw-apb-uart" }, {/* Sentinel */ } };
@@ -174,7 +190,7 @@ static struct platform_driver dw8250_platform_driver = { .driver = { .name = "dw-apb-uart", .owner = THIS_MODULE, - .of_match_table = dw8250_match, + .of_match_table = dw8250_of_match, }, .probe = dw8250_probe, .remove = __devexit_p(dw8250_remove),
Signature · 1 line
1.7.10.4
PATCH 5/5 serial: 8250_dw: Set FIFO size dynamically
In reply to Heikki KrogerusDesignware UART provides optional Component Parameter Register that lists most of the capabilities of the UART, including FIFO size. This uses that register to set FIFO size for the port before registering it.
--- drivers/tty/serial/8250/8250_dw.c | 57 ++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-)
drivers/tty/serial/8250/8250_dw.c +53 -4
@@ -25,6 +25,28 @@#include <linux/platform_device.h> #include <linux/slab.h> +/* Offsets for the DesignWare specific registers */ +#define DW_UART_USR 0x1f/* UART Status Register */ +#define DW_UART_CPR 0xf4/* Component Parameter Register */ +#define DW_UART_UCV 0xf8/* UART Component Version */ + +/* Component Parameter Register bits */ +#define DW_UART_CPR_ABP_DATA_WIDTH (3 << 0) +#define DW_UART_CPR_AFCE_MODE (1 << 4) +#define DW_UART_CPR_THRE_MODE (1 << 5) +#define DW_UART_CPR_SIR_MODE (1 << 6) +#define DW_UART_CPR_SIR_LP_MODE (1 << 7) +#define DW_UART_CPR_ADDITIONAL_FEATURES (1 << 8) +#define DW_UART_CPR_FIFO_ACCESS (1 << 9) +#define DW_UART_CPR_FIFO_STAT (1 << 10) +#define DW_UART_CPR_SHADOW (1 << 11) +#define DW_UART_CPR_ENCODED_PARMS (1 << 12) +#define DW_UART_CPR_DMA_EXTRA (1 << 13) +#define DW_UART_CPR_FIFO_MODE (0xff << 16) +/* Helper for fifo size calculation */ +#define DW_UART_CPR_FIFO_SIZE (a) (((a >> 16) & 0xff) * 16) + +struct dw8250_data {int last_lcr;int line;
@@ -66,9 +88,6 @@ static unsigned int dw8250_serial_in32(struct uart_port *p, int offset)return readl (p->membase + offset); } -/* Offset for the DesignWare's UART Status Register. */ -#define UART_USR 0x1f -static int dw8250_handle_irq (struct uart_port *p) {struct dw8250_data *d = p->private_data;
@@ -78,7 +97,7 @@ static int dw8250_handle_irq(struct uart_port *p)return 1 ; }else if ((iir &UART_IIR_BUSY ) ==UART_IIR_BUSY ) {/* Clear the USR and write the LCR again. */ - (void )p->serial_in (p,UART_USR ); + (void )p->serial_in (p,DW_UART_USR ); p->serial_out (p, d->last_lcr,UART_LCR );return 1 ;
@@ -119,6 +138,34 @@ static int __devinit dw8250_probe_of(struct uart_port *p)return 0 ; } +static void __devinit dw8250_setup_port (struct uart_8250_port *up) +{ +struct uart_port *p = &up->port; +u32 reg =readl (p->membase +DW_UART_UCV ); + +/* +* If the Component Version Register returns zero, we know that +* ADDITIONAL_FEATURES are not enabled. No need to go any further. +*/ +if (!reg || (reg &0xff ) !='*' ) +return ; + +dev_dbg_ratelimited (p->dev,"Designware UART version %c.%c%c\n" , + (reg >>24 ) &0xff , (reg >>16 ) &0xff , (reg >>8 ) &0xff ); + + reg =readl (p->membase +DW_UART_CPR ); +if (!reg) +return ; + +/* Select the type based on fifo */ +if (reg &DW_UART_CPR_FIFO_MODE ) { + p->type =PORT_16550A ; + p->flags |=UPF_FIXED_TYPE ; + p->fifosize =DW_UART_CPR_FIFO_SIZE (reg); + up->tx_loadsz = p->fifosize; + } +} +static int __devinit dw8250_probe (struct platform_device *pdev) {struct uart_8250_port uart = {};
@@ -156,6 +203,8 @@ static int __devinit dw8250_probe(struct platform_device *pdev)return -ENODEV ; } +dw8250_setup_port (&uart); + data =devm_kzalloc (&pdev->dev,sizeof (*data),GFP_KERNEL );if (!data)return -ENOMEM ;
Signature · 1 line
1.7.10.4
Re: [PATCH 5/5] serial: 8250_dw: Set FIFO size dynamically
drivers/tty/serial/8250/8250_dw.c static int __devinit dw8250_probe_of(struct uart_port *p) · line 152
Quoted 3 lines
drivers/tty/serial/8250/8250_dw.c +3
-0+if (!reg || (reg &0xff ) !='*' ) +return ; +
That looks bogus. If reg == 0 then reg & 0xFF != '*'
So why the double test ?
Re: [PATCH 5/5] serial: 8250_dw: Set FIFO size dynamically
Quoted 7 lines · Alan Cox
drivers/tty/serial/8250/8250_dw.c static int __devinit dw8250_probe_of(struct uart_port *p) · line 152
Quoted 3 lines
drivers/tty/serial/8250/8250_dw.c +3
-0+if (!reg || (reg &0xff ) !='*' ) +return ; +That looks bogus. If reg == 0 then reg &
0xFF!= '*'So why the double test ?
No reason. It is something I forgot to cleanup. I'll resend this.
Thanks!
Signature · 1 line
heikki
PATCH 5/5 serial: 8250_dw: Set FIFO size dynamically
Designware UART provides optional Component Parameter Register that lists most of the capabilities of the UART, including FIFO size. This uses that register to set FIFO size for the port before registering it.
--- drivers/tty/serial/8250/8250_dw.c | 57 ++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-)
drivers/tty/serial/8250/8250_dw.c +53 -4
@@ -25,6 +25,28 @@#include <linux/platform_device.h> #include <linux/slab.h> +/* Offsets for the DesignWare specific registers */ +#define DW_UART_USR 0x1f/* UART Status Register */ +#define DW_UART_CPR 0xf4/* Component Parameter Register */ +#define DW_UART_UCV 0xf8/* UART Component Version */ + +/* Component Parameter Register bits */ +#define DW_UART_CPR_ABP_DATA_WIDTH (3 << 0) +#define DW_UART_CPR_AFCE_MODE (1 << 4) +#define DW_UART_CPR_THRE_MODE (1 << 5) +#define DW_UART_CPR_SIR_MODE (1 << 6) +#define DW_UART_CPR_SIR_LP_MODE (1 << 7) +#define DW_UART_CPR_ADDITIONAL_FEATURES (1 << 8) +#define DW_UART_CPR_FIFO_ACCESS (1 << 9) +#define DW_UART_CPR_FIFO_STAT (1 << 10) +#define DW_UART_CPR_SHADOW (1 << 11) +#define DW_UART_CPR_ENCODED_PARMS (1 << 12) +#define DW_UART_CPR_DMA_EXTRA (1 << 13) +#define DW_UART_CPR_FIFO_MODE (0xff << 16) +/* Helper for fifo size calculation */ +#define DW_UART_CPR_FIFO_SIZE (a) (((a >> 16) & 0xff) * 16) + +struct dw8250_data {int last_lcr;int line;
@@ -66,9 +88,6 @@ static unsigned int dw8250_serial_in32(struct uart_port *p, int offset)return readl (p->membase + offset); } -/* Offset for the DesignWare's UART Status Register. */ -#define UART_USR 0x1f -static int dw8250_handle_irq (struct uart_port *p) {struct dw8250_data *d = p->private_data;
@@ -78,7 +97,7 @@ static int dw8250_handle_irq(struct uart_port *p)return 1 ; }else if ((iir &UART_IIR_BUSY ) ==UART_IIR_BUSY ) {/* Clear the USR and write the LCR again. */ - (void )p->serial_in (p,UART_USR ); + (void )p->serial_in (p,DW_UART_USR ); p->serial_out (p, d->last_lcr,UART_LCR );return 1 ;
@@ -119,6 +138,34 @@ static int __devinit dw8250_probe_of(struct uart_port *p)return 0 ; } +static void __devinit dw8250_setup_port (struct uart_8250_port *up) +{ +struct uart_port *p = &up->port; +u32 reg =readl (p->membase +DW_UART_UCV ); + +/* +* If the Component Version Register returns zero, we know that +* ADDITIONAL_FEATURES are not enabled. No need to go any further. +*/ +if (!reg) +return ; + +dev_dbg_ratelimited (p->dev,"Designware UART version %c.%c%c\n" , + (reg >>24 ) &0xff , (reg >>16 ) &0xff , (reg >>8 ) &0xff ); + + reg =readl (p->membase +DW_UART_CPR ); +if (!reg) +return ; + +/* Select the type based on fifo */ +if (reg &DW_UART_CPR_FIFO_MODE ) { + p->type =PORT_16550A ; + p->flags |=UPF_FIXED_TYPE ; + p->fifosize =DW_UART_CPR_FIFO_SIZE (reg); + up->tx_loadsz = p->fifosize; + } +} +static int __devinit dw8250_probe (struct platform_device *pdev) {struct uart_8250_port uart = {};
@@ -156,6 +203,8 @@ static int __devinit dw8250_probe(struct platform_device *pdev)return -ENODEV ; } +dw8250_setup_port (&uart); + data =devm_kzalloc (&pdev->dev,sizeof (*data),GFP_KERNEL );if (!data)return -ENOMEM ;
Signature · 1 line
1.7.10.4
Quoted 5 lines · Heikki Krogerus
Hi,
These are mainly small changes to
8250_dw.c. The interesting patch is probable the addition to 8250.c that would allow the drivers to deliver their UART's capabilities when they are registering ports.
These don't apply on top of tty-next so I need to make version two. I'll send it next week in case somebody has comments.
Signature · 1 line
heikki