linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] serial: 8250_fsl: Add ACPI support
@ 2020-08-29 14:43 kuldip dwivedi
  2020-09-02 15:40 ` [EXT] " Vabhav Sharma (OSS)
  0 siblings, 1 reply; 3+ messages in thread
From: kuldip dwivedi @ 2020-08-29 14:43 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Dmitry Safonov, linux-serial
  Cc: Vabhav Sharma, Pankaj Bansal, Varun Sethi, Arokia Samy, kuldip dwivedi

This adds support for ACPI enumerated FSL 16550 UARTs.
For supporting ACPI, I added a wrapper so that this driver
can be used if firmware has exposed the HID "NXP0018" in
DSDT table.

This will be built as object file if config "SERIAL_8250_FSL"
is enabled which depends on config "SERIAL_8250_CONSOLE".

Signed-off-by: kuldip dwivedi <kuldip.dwivedi@puresoftware.com>
---

Notes:
    1. Move Copyright and File description at top of the file
    2. Add ACPI wrapper code within CONFIG_ACPI macro
    3. this change is tested with DT and ACPI boot on LS1046A platform

 drivers/tty/serial/8250/8250_fsl.c | 108 +++++++++++++++++++++++++++--
 1 file changed, 101 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_fsl.c b/drivers/tty/serial/8250/8250_fsl.c
index 0d0c80905c58..68bfbf392281 100644
--- a/drivers/tty/serial/8250/8250_fsl.c
+++ b/drivers/tty/serial/8250/8250_fsl.c
@@ -1,15 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0
-#include <linux/serial_reg.h>
-#include <linux/serial_8250.h>
-
-#include "8250.h"
-
 /*
  * Freescale 16550 UART "driver", Copyright (C) 2011 Paul Gortmaker.
+ * Copyright 2020 NXP
+ * Copyright 2020 Puresoftware Ltd.
  *
  * This isn't a full driver; it just provides an alternate IRQ
- * handler to deal with an errata.  Everything else is just
- * using the bog standard 8250 support.
+ * handler to deal with an errata and provide ACPI wrapper.
+ * Everything else is just using the bog standard 8250 support.
  *
  * We follow code flow of serial8250_default_handle_irq() but add
  * a check for a break and insert a dummy read on the Rx for the
@@ -20,6 +17,16 @@
  * IRQ event to the next one.
  */
 
+#include <linux/acpi.h>
+#include <linux/serial_reg.h>
+#include <linux/serial_8250.h>
+
+#include "8250.h"
+
+struct fsl8250_data {
+	int	line;
+};
+
 int fsl8250_handle_irq(struct uart_port *port)
 {
 	unsigned char lsr, orig_lsr;
@@ -79,3 +86,90 @@ int fsl8250_handle_irq(struct uart_port *port)
 	return 1;
 }
 EXPORT_SYMBOL_GPL(fsl8250_handle_irq);
+
+#ifdef CONFIG_ACPI
+static int fsl8250_acpi_probe(struct platform_device *pdev)
+{
+	struct fsl8250_data *data;
+	struct uart_8250_port port8250;
+	struct device *dev = &pdev->dev;
+	struct resource *regs;
+
+	int ret, irq;
+
+	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!regs) {
+		dev_err(dev, "no registers defined\n");
+		return -EINVAL;
+	}
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		if (irq != -EPROBE_DEFER)
+			dev_err(dev, "cannot get irq\n");
+		return irq;
+	}
+
+	memset(&port8250, 0, sizeof(port8250));
+
+	ret = device_property_read_u32(dev, "clock-frequency",
+					&port8250.port.uartclk);
+	if (ret)
+		return ret;
+
+	spin_lock_init(&port8250.port.lock);
+
+	port8250.port.mapbase           = regs->start;
+	port8250.port.irq               = irq;
+	port8250.port.handle_irq        = fsl8250_handle_irq;
+	port8250.port.type              = PORT_16550A;
+	port8250.port.flags             = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF
+						| UPF_FIXED_PORT | UPF_IOREMAP
+						| UPF_FIXED_TYPE;
+	port8250.port.dev               = dev;
+	port8250.port.mapsize           = resource_size(regs);
+	port8250.port.iotype            = UPIO_MEM;
+	port8250.port.irqflags          = IRQF_SHARED;
+
+	port8250.port.membase = devm_ioremap(dev,  port8250.port.mapbase,
+							port8250.port.mapsize);
+	if (!port8250.port.membase)
+		return -ENOMEM;
+
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->line = serial8250_register_8250_port(&port8250);
+	if (data->line < 0)
+		ret = data->line;
+
+	platform_set_drvdata(pdev, data);
+	return 0;
+}
+
+static int fsl8250_acpi_remove(struct platform_device *pdev)
+{
+	struct fsl8250_data *data = platform_get_drvdata(pdev);
+
+	serial8250_unregister_port(data->line);
+	return 0;
+}
+
+static const struct acpi_device_id fsl_8250_acpi_id[] = {
+	{ "NXP0018", 0 },
+	{ },
+};
+MODULE_DEVICE_TABLE(acpi, fsl_8250_acpi_id);
+
+static struct platform_driver fsl8250_platform_driver = {
+	.driver = {
+		.name			= "fsl-16550-uart",
+		.acpi_match_table	= ACPI_PTR(fsl_8250_acpi_id),
+	},
+	.probe			= fsl8250_acpi_probe,
+	.remove			= fsl8250_acpi_remove,
+};
+
+module_platform_driver(fsl8250_platform_driver);
+#endif
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [EXT] [PATCH v3] serial: 8250_fsl: Add ACPI support
  2020-08-29 14:43 [PATCH v3] serial: 8250_fsl: Add ACPI support kuldip dwivedi
@ 2020-09-02 15:40 ` Vabhav Sharma (OSS)
  2020-09-03 11:37   ` Kuldip Dwivedi
  0 siblings, 1 reply; 3+ messages in thread
From: Vabhav Sharma (OSS) @ 2020-09-02 15:40 UTC (permalink / raw)
  To: kuldip dwivedi, Greg Kroah-Hartman, Jiri Slaby, Dmitry Safonov,
	linux-serial
  Cc: Pankaj Bansal, Varun Sethi, Arokia Samy, kuldip dwivedi


> -----Original Message-----
> From: kuldip dwivedi <kuldip.dwivedi@puresoftware.com>
> Sent: Saturday, August 29, 2020 8:13 PM
> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Jiri Slaby
> <jirislaby@kernel.org>; Dmitry Safonov <0x7f454c46@gmail.com>; linux-
> serial@vger.kernel.org
> Cc: Vabhav Sharma <vabhav.sharma@nxp.com>; Pankaj Bansal
> <pankaj.bansal@nxp.com>; Varun Sethi <V.Sethi@nxp.com>; Arokia Samy
> <arokia.samy@nxp.com>; kuldip dwivedi
> <kuldip.dwivedi@puresoftware.com>
> Subject: [EXT] [PATCH v3] serial: 8250_fsl: Add ACPI support
> 
> Caution: EXT Email
> 
> This adds support for ACPI enumerated FSL 16550 UARTs.
> For supporting ACPI, I added a wrapper so that this driver can be used if
> firmware has exposed the HID "NXP0018" in DSDT table.
> 
> This will be built as object file if config "SERIAL_8250_FSL"
> is enabled which depends on config "SERIAL_8250_CONSOLE".
> 
> Signed-off-by: kuldip dwivedi <kuldip.dwivedi@puresoftware.com>
> ---
> 
> Notes:
>     1. Move Copyright and File description at top of the file
>     2. Add ACPI wrapper code within CONFIG_ACPI macro
>     3. this change is tested with DT and ACPI boot on LS1046A platform
> 
>  drivers/tty/serial/8250/8250_fsl.c | 108 +++++++++++++++++++++++++++--
>  1 file changed, 101 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_fsl.c
> b/drivers/tty/serial/8250/8250_fsl.c
> index 0d0c80905c58..68bfbf392281 100644
> --- a/drivers/tty/serial/8250/8250_fsl.c
> +++ b/drivers/tty/serial/8250/8250_fsl.c
> @@ -1,15 +1,12 @@
>  // SPDX-License-Identifier: GPL-2.0
> -#include <linux/serial_reg.h>
> -#include <linux/serial_8250.h>
> -
> -#include "8250.h"
> -
>  /*
>   * Freescale 16550 UART "driver", Copyright (C) 2011 Paul Gortmaker.
> + * Copyright 2020 NXP
> + * Copyright 2020 Puresoftware Ltd.
>   *
>   * This isn't a full driver; it just provides an alternate IRQ
> - * handler to deal with an errata.  Everything else is just
> - * using the bog standard 8250 support.
> + * handler to deal with an errata and provide ACPI wrapper.
> + * Everything else is just using the bog standard 8250 support.
>   *
>   * We follow code flow of serial8250_default_handle_irq() but add
>   * a check for a break and insert a dummy read on the Rx for the @@ -20,6
> +17,16 @@
>   * IRQ event to the next one.
>   */
> 
> +#include <linux/acpi.h>
> +#include <linux/serial_reg.h>
> +#include <linux/serial_8250.h>
> +
> +#include "8250.h"
> +
> +struct fsl8250_data {
> +       int     line;
> +};
> +
>  int fsl8250_handle_irq(struct uart_port *port)  {
>         unsigned char lsr, orig_lsr;
> @@ -79,3 +86,90 @@ int fsl8250_handle_irq(struct uart_port *port)
>         return 1;
>  }
>  EXPORT_SYMBOL_GPL(fsl8250_handle_irq);
> +
> +#ifdef CONFIG_ACPI
> +static int fsl8250_acpi_probe(struct platform_device *pdev) {
> +       struct fsl8250_data *data;
> +       struct uart_8250_port port8250;
> +       struct device *dev = &pdev->dev;
> +       struct resource *regs;
> +
> +       int ret, irq;
> +
> +       regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +       if (!regs) {
> +               dev_err(dev, "no registers defined\n");
> +               return -EINVAL;
> +       }
> +
> +       irq = platform_get_irq(pdev, 0);
> +       if (irq < 0) {
> +               if (irq != -EPROBE_DEFER)
> +                       dev_err(dev, "cannot get irq\n");
> +               return irq;
> +       }
> +
> +       memset(&port8250, 0, sizeof(port8250));
> +
> +       ret = device_property_read_u32(dev, "clock-frequency",
> +                                       &port8250.port.uartclk);
> +       if (ret)
> +               return ret;
> +
> +       spin_lock_init(&port8250.port.lock);
> +
> +       port8250.port.mapbase           = regs->start;
> +       port8250.port.irq               = irq;
> +       port8250.port.handle_irq        = fsl8250_handle_irq;
> +       port8250.port.type              = PORT_16550A;
> +       port8250.port.flags             = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF
> +                                               | UPF_FIXED_PORT | UPF_IOREMAP
> +                                               | UPF_FIXED_TYPE;
> +       port8250.port.dev               = dev;
> +       port8250.port.mapsize           = resource_size(regs);
> +       port8250.port.iotype            = UPIO_MEM;
> +       port8250.port.irqflags          = IRQF_SHARED;
> +
> +       port8250.port.membase = devm_ioremap(dev,  port8250.port.mapbase,
> +                                                       port8250.port.mapsize);
> +       if (!port8250.port.membase)
> +               return -ENOMEM;
> +
> +       data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> +       if (!data)
> +               return -ENOMEM;
> +
> +       data->line = serial8250_register_8250_port(&port8250);
> +       if (data->line < 0)
> +               ret = data->line;
Would you like to return error here?
> +
> +       platform_set_drvdata(pdev, data);
> +       return 0;
> +}
> +
> +static int fsl8250_acpi_remove(struct platform_device *pdev) {
> +       struct fsl8250_data *data = platform_get_drvdata(pdev);
> +
> +       serial8250_unregister_port(data->line);
> +       return 0;
> +}
> +
> +static const struct acpi_device_id fsl_8250_acpi_id[] = {
> +       { "NXP0018", 0 },
> +       { },
> +};
> +MODULE_DEVICE_TABLE(acpi, fsl_8250_acpi_id);
> +
> +static struct platform_driver fsl8250_platform_driver = {
> +       .driver = {
> +               .name                   = "fsl-16550-uart",
> +               .acpi_match_table       = ACPI_PTR(fsl_8250_acpi_id),
> +       },
> +       .probe                  = fsl8250_acpi_probe,
> +       .remove                 = fsl8250_acpi_remove,
> +};
> +
> +module_platform_driver(fsl8250_platform_driver);
> +#endif
> --
> 2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [EXT] [PATCH v3] serial: 8250_fsl: Add ACPI support
  2020-09-02 15:40 ` [EXT] " Vabhav Sharma (OSS)
@ 2020-09-03 11:37   ` Kuldip Dwivedi
  0 siblings, 0 replies; 3+ messages in thread
From: Kuldip Dwivedi @ 2020-09-03 11:37 UTC (permalink / raw)
  To: Vabhav Sharma (OSS),
	Greg Kroah-Hartman, Jiri Slaby, Dmitry Safonov, linux-serial
  Cc: Pankaj Bansal, Varun Sethi, Arokia Samy

> -----Original Message-----
> From: Vabhav Sharma (OSS) <vabhav.sharma@oss.nxp.com>
> Sent: Wednesday, September 2, 2020 9:10 PM
> To: kuldip dwivedi <kuldip.dwivedi@puresoftware.com>; Greg Kroah-Hartman
> <gregkh@linuxfoundation.org>; Jiri Slaby <jirislaby@kernel.org>; Dmitry
Safonov
> <0x7f454c46@gmail.com>; linux-serial@vger.kernel.org
> Cc: Pankaj Bansal <pankaj.bansal@nxp.com>; Varun Sethi
<V.Sethi@nxp.com>;
> Arokia Samy <arokia.samy@nxp.com>; kuldip dwivedi
> <kuldip.dwivedi@puresoftware.com>
> Subject: RE: [EXT] [PATCH v3] serial: 8250_fsl: Add ACPI support
>
>
> > -----Original Message-----
> > From: kuldip dwivedi <kuldip.dwivedi@puresoftware.com>
> > Sent: Saturday, August 29, 2020 8:13 PM
> > To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Jiri Slaby
> > <jirislaby@kernel.org>; Dmitry Safonov <0x7f454c46@gmail.com>; linux-
> > serial@vger.kernel.org
> > Cc: Vabhav Sharma <vabhav.sharma@nxp.com>; Pankaj Bansal
> > <pankaj.bansal@nxp.com>; Varun Sethi <V.Sethi@nxp.com>; Arokia Samy
> > <arokia.samy@nxp.com>; kuldip dwivedi
> > <kuldip.dwivedi@puresoftware.com>
> > Subject: [EXT] [PATCH v3] serial: 8250_fsl: Add ACPI support
> >
> > Caution: EXT Email
> >
> > This adds support for ACPI enumerated FSL 16550 UARTs.
> > For supporting ACPI, I added a wrapper so that this driver can be used
> > if firmware has exposed the HID "NXP0018" in DSDT table.
> >
> > This will be built as object file if config "SERIAL_8250_FSL"
> > is enabled which depends on config "SERIAL_8250_CONSOLE".
> >
> > Signed-off-by: kuldip dwivedi <kuldip.dwivedi@puresoftware.com>
> > ---
> >
> > Notes:
> >     1. Move Copyright and File description at top of the file
> >     2. Add ACPI wrapper code within CONFIG_ACPI macro
> >     3. this change is tested with DT and ACPI boot on LS1046A platform
> >
> >  drivers/tty/serial/8250/8250_fsl.c | 108
> > +++++++++++++++++++++++++++--
> >  1 file changed, 101 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/tty/serial/8250/8250_fsl.c
> > b/drivers/tty/serial/8250/8250_fsl.c
> > index 0d0c80905c58..68bfbf392281 100644
> > --- a/drivers/tty/serial/8250/8250_fsl.c
> > +++ b/drivers/tty/serial/8250/8250_fsl.c
> > @@ -1,15 +1,12 @@
> >  // SPDX-License-Identifier: GPL-2.0
> > -#include <linux/serial_reg.h>
> > -#include <linux/serial_8250.h>
> > -
> > -#include "8250.h"
> > -
> >  /*
> >   * Freescale 16550 UART "driver", Copyright (C) 2011 Paul Gortmaker.
> > + * Copyright 2020 NXP
> > + * Copyright 2020 Puresoftware Ltd.
> >   *
> >   * This isn't a full driver; it just provides an alternate IRQ
> > - * handler to deal with an errata.  Everything else is just
> > - * using the bog standard 8250 support.
> > + * handler to deal with an errata and provide ACPI wrapper.
> > + * Everything else is just using the bog standard 8250 support.
> >   *
> >   * We follow code flow of serial8250_default_handle_irq() but add
> >   * a check for a break and insert a dummy read on the Rx for the @@
> > -20,6
> > +17,16 @@
> >   * IRQ event to the next one.
> >   */
> >
> > +#include <linux/acpi.h>
> > +#include <linux/serial_reg.h>
> > +#include <linux/serial_8250.h>
> > +
> > +#include "8250.h"
> > +
> > +struct fsl8250_data {
> > +       int     line;
> > +};
> > +
> >  int fsl8250_handle_irq(struct uart_port *port)  {
> >         unsigned char lsr, orig_lsr;
> > @@ -79,3 +86,90 @@ int fsl8250_handle_irq(struct uart_port *port)
> >         return 1;
> >  }
> >  EXPORT_SYMBOL_GPL(fsl8250_handle_irq);
> > +
> > +#ifdef CONFIG_ACPI
> > +static int fsl8250_acpi_probe(struct platform_device *pdev) {
> > +       struct fsl8250_data *data;
> > +       struct uart_8250_port port8250;
> > +       struct device *dev = &pdev->dev;
> > +       struct resource *regs;
> > +
> > +       int ret, irq;
> > +
> > +       regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > +       if (!regs) {
> > +               dev_err(dev, "no registers defined\n");
> > +               return -EINVAL;
> > +       }
> > +
> > +       irq = platform_get_irq(pdev, 0);
> > +       if (irq < 0) {
> > +               if (irq != -EPROBE_DEFER)
> > +                       dev_err(dev, "cannot get irq\n");
> > +               return irq;
> > +       }
> > +
> > +       memset(&port8250, 0, sizeof(port8250));
> > +
> > +       ret = device_property_read_u32(dev, "clock-frequency",
> > +                                       &port8250.port.uartclk);
> > +       if (ret)
> > +               return ret;
> > +
> > +       spin_lock_init(&port8250.port.lock);
> > +
> > +       port8250.port.mapbase           = regs->start;
> > +       port8250.port.irq               = irq;
> > +       port8250.port.handle_irq        = fsl8250_handle_irq;
> > +       port8250.port.type              = PORT_16550A;
> > +       port8250.port.flags             = UPF_SHARE_IRQ |
UPF_BOOT_AUTOCONF
> > +                                               | UPF_FIXED_PORT |
UPF_IOREMAP
> > +                                               | UPF_FIXED_TYPE;
> > +       port8250.port.dev               = dev;
> > +       port8250.port.mapsize           = resource_size(regs);
> > +       port8250.port.iotype            = UPIO_MEM;
> > +       port8250.port.irqflags          = IRQF_SHARED;
> > +
> > +       port8250.port.membase = devm_ioremap(dev,
port8250.port.mapbase,
> > +
port8250.port.mapsize);
> > +       if (!port8250.port.membase)
> > +               return -ENOMEM;
> > +
> > +       data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> > +       if (!data)
> > +               return -ENOMEM;
> > +
> > +       data->line = serial8250_register_8250_port(&port8250);
> > +       if (data->line < 0)
> > +               ret = data->line;
> Would you like to return error here?
Addressed in v4
> > +
> > +       platform_set_drvdata(pdev, data);
> > +       return 0;
> > +}
> > +
> > +static int fsl8250_acpi_remove(struct platform_device *pdev) {
> > +       struct fsl8250_data *data = platform_get_drvdata(pdev);
> > +
> > +       serial8250_unregister_port(data->line);
> > +       return 0;
> > +}
> > +
> > +static const struct acpi_device_id fsl_8250_acpi_id[] = {
> > +       { "NXP0018", 0 },
> > +       { },
> > +};
> > +MODULE_DEVICE_TABLE(acpi, fsl_8250_acpi_id);
> > +
> > +static struct platform_driver fsl8250_platform_driver = {
> > +       .driver = {
> > +               .name                   = "fsl-16550-uart",
> > +               .acpi_match_table       = ACPI_PTR(fsl_8250_acpi_id),
> > +       },
> > +       .probe                  = fsl8250_acpi_probe,
> > +       .remove                 = fsl8250_acpi_remove,
> > +};
> > +
> > +module_platform_driver(fsl8250_platform_driver);
> > +#endif
> > --
> > 2.17.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-03 11:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-29 14:43 [PATCH v3] serial: 8250_fsl: Add ACPI support kuldip dwivedi
2020-09-02 15:40 ` [EXT] " Vabhav Sharma (OSS)
2020-09-03 11:37   ` Kuldip Dwivedi

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).