All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 7/9] serial: lpuart: Add driver model serial support
Date: Thu, 14 Jan 2016 13:44:03 +0530	[thread overview]
Message-ID: <569758CB.9060602@toradex.com> (raw)
In-Reply-To: <1452742746-31746-8-git-send-email-bmeng.cn@gmail.com>

On 01/14/2016 09:09 AM, Bin Meng wrote:
> This adds driver model support to lpuart serial driver.

Tested on Toradex Colibri VF50/VF61 h/w with legacy and DT, works fine 
as expected.

>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

Acked-by: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>
also
Tested-by: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>

>
> ---
>
> Changes in v2:
> - Split to use two separate U_BOOT_DRIVER()
>
>   doc/driver-model/serial-howto.txt |   1 -
>   drivers/serial/serial_lpuart.c    | 167 ++++++++++++++++++++++++++++++++++++++
>   2 files changed, 167 insertions(+), 1 deletion(-)
>
> diff --git a/doc/driver-model/serial-howto.txt b/doc/driver-model/serial-howto.txt
> index 4706d56..c933b90 100644
> --- a/doc/driver-model/serial-howto.txt
> +++ b/doc/driver-model/serial-howto.txt
> @@ -11,7 +11,6 @@ is time for maintainers to start converting over the remaining serial drivers:
>      opencores_yanu.c
>      serial_bfin.c
>      serial_imx.c
> -   serial_lpuart.c
>      serial_max3100.c
>      serial_pxa.c
>      serial_s3c24x0.c
> diff --git a/drivers/serial/serial_lpuart.c b/drivers/serial/serial_lpuart.c
> index 5cc1997..3f9c4d1 100644
> --- a/drivers/serial/serial_lpuart.c
> +++ b/drivers/serial/serial_lpuart.c
> @@ -5,6 +5,7 @@
>    */
>
>   #include <common.h>
> +#include <dm.h>
>   #include <watchdog.h>
>   #include <asm/io.h>
>   #include <serial.h>
> @@ -49,6 +50,10 @@ DECLARE_GLOBAL_DATA_PTR;
>
>   struct lpuart_fsl *base = (struct lpuart_fsl *)LPUART_BASE;
>
> +struct lpuart_serial_platdata {
> +	struct lpuart_fsl *reg;
> +};
> +
>   #ifndef CONFIG_LPUART_32B_REG
>   static void _lpuart_serial_setbrg(struct lpuart_fsl *base, int baudrate)
>   {
> @@ -122,6 +127,7 @@ static int _lpuart_serial_init(struct lpuart_fsl *base)
>   	return 0;
>   }
>
> +#ifndef CONFIG_DM_SERIAL
>   static void lpuart_serial_setbrg(void)
>   {
>   	_lpuart_serial_setbrg(base, gd->baudrate);
> @@ -157,6 +163,54 @@ static struct serial_device lpuart_serial_drv = {
>   	.getc = lpuart_serial_getc,
>   	.tstc = lpuart_serial_tstc,
>   };
> +#else /* CONFIG_DM_SERIAL */
> +static int lpuart_serial_setbrg(struct udevice *dev, int baudrate)
> +{
> +	struct lpuart_serial_platdata *plat = dev->platdata;
> +	struct lpuart_fsl *reg = plat->reg;
> +
> +	_lpuart_serial_setbrg(reg, baudrate);
> +
> +	return 0;
> +}
> +
> +static int lpuart_serial_getc(struct udevice *dev)
> +{
> +	struct lpuart_serial_platdata *plat = dev->platdata;
> +	struct lpuart_fsl *reg = plat->reg;
> +
> +	return _lpuart_serial_getc(reg);
> +}
> +
> +static int lpuart_serial_putc(struct udevice *dev, const char c)
> +{
> +	struct lpuart_serial_platdata *plat = dev->platdata;
> +	struct lpuart_fsl *reg = plat->reg;
> +
> +	_lpuart_serial_putc(reg, c);
> +
> +	return 0;
> +}
> +
> +static int lpuart_serial_pending(struct udevice *dev, bool input)
> +{
> +	struct lpuart_serial_platdata *plat = dev->platdata;
> +	struct lpuart_fsl *reg = plat->reg;
> +
> +	if (input)
> +		return _lpuart_serial_tstc(reg);
> +	else
> +		return __raw_readb(&reg->us1) & US1_TDRE ? 0 : 1;
> +}
> +
> +static int lpuart_serial_probe(struct udevice *dev)
> +{
> +	struct lpuart_serial_platdata *plat = dev->platdata;
> +	struct lpuart_fsl *reg = plat->reg;
> +
> +	return _lpuart_serial_init(reg);
> +}
> +#endif /* CONFIG_DM_SERIAL */
>   #else
>   static void _lpuart32_serial_setbrg(struct lpuart_fsl *base, int baudrate)
>   {
> @@ -227,6 +281,7 @@ static int _lpuart32_serial_init(struct lpuart_fsl *base)
>   	return 0;
>   }
>
> +#ifndef CONFIG_DM_SERIAL
>   static void lpuart32_serial_setbrg(void)
>   {
>   	_lpuart32_serial_setbrg(base, gd->baudrate);
> @@ -262,8 +317,57 @@ static struct serial_device lpuart32_serial_drv = {
>   	.getc = lpuart32_serial_getc,
>   	.tstc = lpuart32_serial_tstc,
>   };
> +#else /* CONFIG_DM_SERIAL */
> +static int lpuart32_serial_setbrg(struct udevice *dev, int baudrate)
> +{
> +	struct lpuart_serial_platdata *plat = dev->platdata;
> +	struct lpuart_fsl *reg = plat->reg;
> +
> +	_lpuart32_serial_setbrg(reg, baudrate);
> +
> +	return 0;
> +}
> +
> +static int lpuart32_serial_getc(struct udevice *dev)
> +{
> +	struct lpuart_serial_platdata *plat = dev->platdata;
> +	struct lpuart_fsl *reg = plat->reg;
> +
> +	return _lpuart32_serial_getc(reg);
> +}
> +
> +static int lpuart32_serial_putc(struct udevice *dev, const char c)
> +{
> +	struct lpuart_serial_platdata *plat = dev->platdata;
> +	struct lpuart_fsl *reg = plat->reg;
> +
> +	_lpuart32_serial_putc(reg, c);
> +
> +	return 0;
> +}
> +
> +static int lpuart32_serial_pending(struct udevice *dev, bool input)
> +{
> +	struct lpuart_serial_platdata *plat = dev->platdata;
> +	struct lpuart_fsl *reg = plat->reg;
> +
> +	if (input)
> +		return _lpuart32_serial_tstc(reg);
> +	else
> +		return in_be32(&reg->stat) & STAT_TDRE ? 0 : 1;
> +}
> +
> +static int lpuart32_serial_probe(struct udevice *dev)
> +{
> +	struct lpuart_serial_platdata *plat = dev->platdata;
> +	struct lpuart_fsl *reg = plat->reg;
> +
> +	return _lpuart32_serial_init(reg);
> +}
> +#endif /* CONFIG_DM_SERIAL */
>   #endif
>
> +#ifndef CONFIG_DM_SERIAL
>   void lpuart_serial_initialize(void)
>   {
>   #ifdef CONFIG_LPUART_32B_REG
> @@ -281,3 +385,66 @@ __weak struct serial_device *default_serial_console(void)
>   	return &lpuart_serial_drv;
>   #endif
>   }
> +#else /* CONFIG_DM_SERIAL */
> +static int lpuart_serial_ofdata_to_platdata(struct udevice *dev)
> +{
> +	struct lpuart_serial_platdata *plat = dev->platdata;
> +	fdt_addr_t addr;
> +
> +	addr = dev_get_addr(dev);
> +	if (addr == FDT_ADDR_T_NONE)
> +		return -EINVAL;
> +
> +	plat->reg = (struct lpuart_fsl *)addr;
> +
> +	return 0;
> +}
> +
> +#ifndef CONFIG_LPUART_32B_REG
> +static const struct dm_serial_ops lpuart_serial_ops = {
> +	.putc = lpuart_serial_putc,
> +	.pending = lpuart_serial_pending,
> +	.getc = lpuart_serial_getc,
> +	.setbrg = lpuart_serial_setbrg,
> +};
> +
> +static const struct udevice_id lpuart_serial_ids[] = {
> +	{ .compatible = "fsl,vf610-lpuart" },
> +	{ }
> +};
> +
> +U_BOOT_DRIVER(serial_lpuart) = {
> +	.name	= "serial_lpuart",
> +	.id	= UCLASS_SERIAL,
> +	.of_match = lpuart_serial_ids,
> +	.ofdata_to_platdata = lpuart_serial_ofdata_to_platdata,
> +	.platdata_auto_alloc_size = sizeof(struct lpuart_serial_platdata),
> +	.probe = lpuart_serial_probe,
> +	.ops	= &lpuart_serial_ops,
> +	.flags = DM_FLAG_PRE_RELOC,
> +};
> +#else /* CONFIG_LPUART_32B_REG */
> +static const struct dm_serial_ops lpuart32_serial_ops = {
> +	.putc = lpuart32_serial_putc,
> +	.pending = lpuart32_serial_pending,
> +	.getc = lpuart32_serial_getc,
> +	.setbrg = lpuart32_serial_setbrg,
> +};
> +
> +static const struct udevice_id lpuart32_serial_ids[] = {
> +	{ .compatible = "fsl,ls1021a-lpuart" },
> +	{ }
> +};
> +
> +U_BOOT_DRIVER(serial_lpuart32) = {
> +	.name	= "serial_lpuart32",
> +	.id	= UCLASS_SERIAL,
> +	.of_match = lpuart32_serial_ids,
> +	.ofdata_to_platdata = lpuart_serial_ofdata_to_platdata,
> +	.platdata_auto_alloc_size = sizeof(struct lpuart_serial_platdata),
> +	.probe = lpuart32_serial_probe,
> +	.ops	= &lpuart32_serial_ops,
> +	.flags = DM_FLAG_PRE_RELOC,
> +};
> +#endif /* CONFIG_LPUART_32B_REG */
> +#endif /* CONFIG_DM_SERIAL */
>

-- 
Best regards,
Bhuvan

  reply	other threads:[~2016-01-14  8:14 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-14  3:38 [U-Boot] [PATCH v2 0/9] arm: ls1021atwr: Convert to driver model and enable serial support Bin Meng
2016-01-14  3:38 ` [U-Boot] [PATCH v2 1/9] Revert "fdt_support: Add multi-serial support for stdout fixup" Bin Meng
2016-01-20 20:26   ` Simon Glass
2016-01-21 15:18     ` Simon Glass
2016-01-14  3:38 ` [U-Boot] [PATCH v2 2/9] arm: ls1021atwr: Convert to driver model and enable serial support Bin Meng
2016-01-20 20:26   ` Simon Glass
2016-01-21 15:18     ` Simon Glass
2016-01-14  3:39 ` [U-Boot] [PATCH v2 3/9] serial: lpuart: Move CONFIG_FSL_LPUART to Kconfig Bin Meng
2016-01-15 21:11   ` Stefan Agner
2016-01-20 20:26     ` Simon Glass
2016-01-21 15:18       ` Simon Glass
2016-01-14  3:39 ` [U-Boot] [PATCH v2 4/9] serial: lpuart: Fix several cosmetic issues Bin Meng
2016-01-20 20:27   ` Simon Glass
2016-01-21 15:18     ` Simon Glass
2016-01-14  3:39 ` [U-Boot] [PATCH v2 5/9] serial: lpuart: Call local version of setbrg and putc directly Bin Meng
2016-01-20 20:27   ` Simon Glass
2016-01-21 15:18     ` Simon Glass
2016-01-14  3:39 ` [U-Boot] [PATCH v2 6/9] serial: lpuart: Prepare the driver for DM conversion Bin Meng
2016-01-20 20:27   ` Simon Glass
2016-01-21 15:18     ` Simon Glass
2016-01-14  3:39 ` [U-Boot] [PATCH v2 7/9] serial: lpuart: Add driver model serial support Bin Meng
2016-01-14  8:14   ` Bhuvanchandra DV [this message]
2016-01-20 20:27   ` Simon Glass
2016-01-21 15:18     ` Simon Glass
2016-01-14  3:39 ` [U-Boot] [PATCH v2 8/9] arm: ls1021atwr: Split off board device tree Bin Meng
2016-01-20 20:27   ` Simon Glass
2016-01-21 15:18     ` Simon Glass
2016-01-14  3:39 ` [U-Boot] [PATCH v2 9/9] arm: ls1021atwr: Enable driver model lpuart serial driver Bin Meng
2016-01-18  9:39   ` Huan Wang
2016-01-20 20:27     ` Simon Glass
2016-01-21 15:18       ` Simon Glass

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=569758CB.9060602@toradex.com \
    --to=bhuvanchandra.dv@toradex.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.