linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: grant.likely@secretlab.ca (Grant Likely)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] tty: serial: support device tree in pxa
Date: Sun, 10 Jul 2011 14:11:10 +0900	[thread overview]
Message-ID: <20110710051110.GC10912@ponder.secretlab.ca> (raw)
In-Reply-To: <1310120428-22700-5-git-send-email-haojian.zhuang@marvell.com>

On Fri, Jul 08, 2011 at 06:20:21PM +0800, Haojian Zhuang wrote:
> Support both normal platform driver and device tree driver in serial pxa.
> 
> Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
> ---
>  drivers/tty/serial/Kconfig     |    4 +-
>  drivers/tty/serial/of_serial.c |   12 +++++
>  drivers/tty/serial/pxa.c       |   91 ++++++++++++++++++++++++++++++++++------
>  include/linux/serial_pxa.h     |   17 +++++++
>  4 files changed, 110 insertions(+), 14 deletions(-)
>  create mode 100644 include/linux/serial_pxa.h
> 
> diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
> index 636144c..3f75e0d 100644
> --- a/drivers/tty/serial/Kconfig
> +++ b/drivers/tty/serial/Kconfig
> @@ -663,6 +663,8 @@ config SERIAL_MPSC_CONSOLE
>  config SERIAL_PXA
>  	bool "PXA serial port support"
>  	depends on ARCH_PXA || ARCH_MMP
> +	select SERIAL_OF_PLATFORM
> +	select SERIAL_CORE_CONSOLE
>  	select SERIAL_CORE
>  	help
>  	  If you have a machine based on an Intel XScale PXA2xx CPU you
> @@ -1340,7 +1342,7 @@ config SERIAL_NETX_CONSOLE
>  config SERIAL_OF_PLATFORM
>  	tristate "Serial port on Open Firmware platform bus"
>  	depends on OF
> -	depends on SERIAL_8250 || SERIAL_OF_PLATFORM_NWPSERIAL
> +	depends on SERIAL_8250 || SERIAL_OF_PLATFORM_NWPSERIAL || SERIAL_PXA
>  	help
>  	  If you have a PowerPC based system that has serial ports
>  	  on a platform specific bus, you should enable this option.
> diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
> index e65f1e8..383bff3 100644
> --- a/drivers/tty/serial/of_serial.c
> +++ b/drivers/tty/serial/of_serial.c
> @@ -14,6 +14,7 @@
>  #include <linux/slab.h>
>  #include <linux/serial_core.h>
>  #include <linux/serial_8250.h>
> +#include <linux/serial_pxa.h>
>  #include <linux/of_address.h>
>  #include <linux/of_irq.h>
>  #include <linux/of_platform.h>
> @@ -126,6 +127,11 @@ static int __devinit of_platform_serial_probe(struct platform_device *ofdev)
>  		ret = nwpserial_register_port(&port);
>  		break;
>  #endif
> +#ifdef CONFIG_SERIAL_PXA
> +	case PORT_PXA:
> +		ret = serial_pxa_register_port(&port);
> +		break;
> +#endif
>  	default:
>  		/* need to add code for these */
>  	case PORT_UNKNOWN:
> @@ -163,6 +169,11 @@ static int of_platform_serial_remove(struct platform_device *ofdev)
>  		nwpserial_unregister_port(info->line);
>  		break;
>  #endif
> +#ifdef CONFIG_SERIAL_PXA
> +	case PORT_PXA:
> +		serial_pxa_unregister_port(info->line);
> +		break;
> +#endif
>  	default:
>  		/* need to add code for these */
>  		break;
> @@ -186,6 +197,7 @@ static struct of_device_id __devinitdata of_platform_serial_table[] = {
>  	{ .compatible = "ibm,qpace-nwp-serial",
>  		.data = (void *)PORT_NWPSERIAL, },
>  #endif
> +	{ .compatible = "pxa,serial", .data = (void *)PORT_PXA, },

compatible values should be in the form: "<vendor>,<soc>-<part>", so
in this case it would be "marvel,pxa270-serial" or something similar.

>  	{ .type = "serial",         .data = (void *)PORT_UNKNOWN, },
>  	{ /* end of list */ },
>  };
> diff --git a/drivers/tty/serial/pxa.c b/drivers/tty/serial/pxa.c
> index 4302e6e..fb80fb3 100644
> --- a/drivers/tty/serial/pxa.c
> +++ b/drivers/tty/serial/pxa.c
> @@ -36,10 +36,12 @@
>  #include <linux/circ_buf.h>
>  #include <linux/delay.h>
>  #include <linux/interrupt.h>
> +#include <linux/of.h>
>  #include <linux/platform_device.h>
>  #include <linux/tty.h>
>  #include <linux/tty_flip.h>
>  #include <linux/serial_core.h>
> +#include <linux/serial_pxa.h>
>  #include <linux/clk.h>
>  #include <linux/io.h>
>  #include <linux/slab.h>
> @@ -51,9 +53,14 @@ struct uart_pxa_port {
>  	unsigned char           mcr;
>  	unsigned int            lsr_break_flag;
>  	struct clk		*clk;
> -	char			*name;
> +	char			name[32];

What's the reason for the change to a static array instead of a
pointer?

> +	int			id;
>  };
>  
> +#define PXA_SERIAL_NR		4
> +
> +static DEFINE_MUTEX(serial_pxa_mutex);
> +
>  static inline unsigned int serial_in(struct uart_pxa_port *up, int offset)
>  {
>  	offset <<= 2;
> @@ -346,8 +353,6 @@ static int serial_pxa_startup(struct uart_port *port)
>  	else
>  		up->mcr = 0;
>  
> -	up->port.uartclk = clk_get_rate(up->clk);
> -
>  	/*
>  	 * Allocate the IRQ
>  	 */
> @@ -593,7 +598,7 @@ serial_pxa_type(struct uart_port *port)
>  	return up->name;
>  }
>  
> -static struct uart_pxa_port *serial_pxa_ports[4];
> +static struct uart_pxa_port serial_pxa_ports[PXA_SERIAL_NR];

Why is this being changed into a static array instead of sticking with
the dynamic allocation of uart_pxa_port?

>  static struct uart_driver serial_pxa_reg;
>  
>  #ifdef CONFIG_SERIAL_PXA_CONSOLE
> @@ -645,7 +650,7 @@ static void serial_pxa_console_putchar(struct uart_port *port, int ch)
>  static void
>  serial_pxa_console_write(struct console *co, const char *s, unsigned int count)
>  {
> -	struct uart_pxa_port *up = serial_pxa_ports[co->index];
> +	struct uart_pxa_port *up = &serial_pxa_ports[co->index];
>  	unsigned int ier;
>  
>  	clk_enable(up->clk);
> @@ -679,7 +684,7 @@ serial_pxa_console_setup(struct console *co, char *options)
>  
>  	if (co->index == -1 || co->index >= serial_pxa_reg.nr)
>  		co->index = 0;
> -	up = serial_pxa_ports[co->index];
> +	up = &serial_pxa_ports[co->index];
>  	if (!up)
>  		return -ENODEV;
>  
> @@ -761,6 +766,68 @@ static const struct dev_pm_ops serial_pxa_pm_ops = {
>  };
>  #endif
>  
> +static int serial_pxa_port_size(struct uart_pxa_port *sport)
> +{
> +	return 8 << sport->port.regshift;
> +}
> +
> +int serial_pxa_register_port(struct uart_port *port)
> +{
> +	struct uart_pxa_port *sport = NULL;
> +	char name[32];
> +	int i, ret;
> +
> +	mutex_lock(&serial_pxa_mutex);
> +	for (i = 0; i < PXA_SERIAL_NR; i++) {
> +		if (serial_pxa_ports[i].id == 0) {
> +			sport = &serial_pxa_ports[i];
> +			sprintf(sport->name, "UART%d", i);
> +			sport->id = i + 1;
> +			break;
> +		}
> +	}
> +	sprintf(name, "pxa2xx-uart.%d", i);
> +	sport->clk = clk_get_sys(name, NULL);
> +	if (IS_ERR(sport->clk)) {
> +		ret = PTR_ERR(sport->clk);
> +		goto out;
> +	}
> +	memcpy(&sport->port, port, sizeof(struct uart_port));
> +	sport->port.line = i;
> +	sport->port.fifosize = 64;
> +	sport->port.ops = &serial_pxa_pops;
> +
> +	sport->port.membase = ioremap(sport->port.mapbase,
> +				serial_pxa_port_size(sport));
> +	if (!sport->port.membase) {
> +		ret = -ENOMEM;
> +		goto out_membase;
> +	}
> +
> +	uart_add_one_port(&serial_pxa_reg, &sport->port);
> +	mutex_unlock(&serial_pxa_mutex);
> +
> +	return sport->port.line;
> +
> +out_membase:
> +	clk_put(sport->clk);
> +out:
> +	mutex_unlock(&serial_pxa_mutex);
> +	return ret;
> +}
> +EXPORT_SYMBOL(serial_pxa_register_port);
> +
> +void serial_pxa_unregister_port(int line)
> +{
> +	struct uart_pxa_port *sport = &serial_pxa_ports[line];
> +
> +	mutex_lock(&serial_pxa_mutex);
> +	uart_remove_one_port(&serial_pxa_reg, &sport->port);
> +	sport->port.type = PORT_UNKNOWN;
> +	clk_put(sport->clk);
> +	mutex_unlock(&serial_pxa_mutex);
> +}
> +
>  static int serial_pxa_probe(struct platform_device *dev)
>  {
>  	struct uart_pxa_port *sport;
> @@ -794,12 +861,12 @@ static int serial_pxa_probe(struct platform_device *dev)
>  	sport->port.uartclk = clk_get_rate(sport->clk);
>  
>  	switch (dev->id) {
> -	case 0: sport->name = "FFUART"; break;
> -	case 1: sport->name = "BTUART"; break;
> -	case 2: sport->name = "STUART"; break;
> -	case 3: sport->name = "HWUART"; break;
> +	case 0: strcpy(sport->name, "FFUART"); break;
> +	case 1: strcpy(sport->name, "BTUART"); break;
> +	case 2: strcpy(sport->name, "STUART"); break;
> +	case 3: strcpy(sport->name, "HWUART"); break;
>  	default:
> -		sport->name = "???";
> +		strcpy(sport->name, "???");
>  		break;
>  	}
>  
> @@ -809,8 +876,6 @@ static int serial_pxa_probe(struct platform_device *dev)
>  		goto err_clk;
>  	}
>  
> -	serial_pxa_ports[dev->id] = sport;
> -
>  	uart_add_one_port(&serial_pxa_reg, &sport->port);
>  	platform_set_drvdata(dev, sport);
>  
> diff --git a/include/linux/serial_pxa.h b/include/linux/serial_pxa.h
> new file mode 100644
> index 0000000..565e510
> --- /dev/null
> +++ b/include/linux/serial_pxa.h
> @@ -0,0 +1,17 @@
> +/*
> + *  linux/include/linux/serial_8250.h
> + *
> + *  Marvell Semiconductor Inc.
> + *  Copyright (C) 2011
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + */
> +#ifndef _LINUX_SERIAL_PXA_H
> +#define _LINUX_SERIAL_PXA_H
> +
> +extern int serial_pxa_register_port(struct uart_port *);
> +extern void serial_pxa_unregister_port(int);
> +#endif
> -- 
> 1.5.6.5
> 

  parent reply	other threads:[~2011-07-10  5:11 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-08 10:20 [PATCH] ARM: mmp: remove SPARSE_IRQ for mmp Haojian Zhuang
2011-07-08 10:20 ` [PATCH] ARM: mmp: remove builtin gpio driver support Haojian Zhuang
2011-07-08 10:20   ` [PATCH] ARM: mmp: parse irq from DT Haojian Zhuang
2011-07-08 10:20     ` [PATCH] ARM: mmp: support OF by default Haojian Zhuang
2011-07-08 10:20       ` [PATCH] tty: serial: support device tree in pxa Haojian Zhuang
2011-07-08 10:20         ` [PATCH] tty: serial: check ops before registering console Haojian Zhuang
2011-07-08 10:20           ` [PATCH] i2c: pxa: create dynamic platform device from device tree Haojian Zhuang
2011-07-08 10:20             ` [PATCH] of: add devicetree API for regulator Haojian Zhuang
2011-07-08 10:20               ` [PATCH] regulator: convert devicetree to platform data on max8649 Haojian Zhuang
2011-07-08 10:20                 ` [PATCH] mfd: convert devicetree to platform data on max8925 Haojian Zhuang
2011-07-08 10:20                   ` [PATCH] mfd: convert devicetree to platform on 88pm860x Haojian Zhuang
2011-07-08 10:20                     ` [PATCH] ARM: mmp: add DTS file Haojian Zhuang
2011-07-10  7:35                       ` Grant Likely
2011-07-11  5:21                         ` Haojian Zhuang
2011-07-10  7:21                     ` [PATCH] mfd: convert devicetree to platform on 88pm860x Grant Likely
2011-07-10  7:20                   ` [PATCH] mfd: convert devicetree to platform data on max8925 Grant Likely
2011-07-10  9:17                     ` Mark Brown
2011-07-10 10:40                       ` Grant Likely
2011-07-08 14:51               ` [PATCH] of: add devicetree API for regulator Grant Likely
2011-07-09  1:14                 ` Mark Brown
2011-07-08 18:32               ` Liam Girdwood
2011-07-09  2:03               ` Mark Brown
2011-07-10  5:26             ` [PATCH] i2c: pxa: create dynamic platform device from device tree Grant Likely
2011-07-10  5:11         ` Grant Likely [this message]
2011-07-10  4:34     ` [PATCH] ARM: mmp: parse irq from DT Grant Likely
2011-07-10  4:02   ` [PATCH] ARM: mmp: remove builtin gpio driver support Grant Likely
2011-07-11  5:05     ` Haojian Zhuang
2011-07-11 11:44       ` Eric Miao
2011-07-08 14:46 ` [PATCH] ARM: mmp: remove SPARSE_IRQ for mmp Grant Likely

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=20110710051110.GC10912@ponder.secretlab.ca \
    --to=grant.likely@secretlab.ca \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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).