From: Lee Jones <lee.jones@linaro.org>
To: Esben Haabendal <esben@geanix.com>
Cc: linux-serial@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jslaby@suse.com>, Nishanth Menon <nm@ti.com>,
Vignesh R <vigneshr@ti.com>, Tony Lindgren <tony@atomide.com>,
Lokesh Vutla <lokeshvutla@ti.com>,
Florian Fainelli <f.fainelli@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] serial: 8250: Add support for 8250/16550 as MFD function
Date: Tue, 7 May 2019 12:49:05 +0100 [thread overview]
Message-ID: <20190507114905.GB29524@dell> (raw)
In-Reply-To: <20190426084038.6377-3-esben@geanix.com>
On Fri, 26 Apr 2019, Esben Haabendal wrote:
> The serial8250-mfd driver is for adding 8250/16550 UART ports as functions
> to an MFD driver.
>
> When calling mfd_add_device(), platform_data should be a pointer to a
> struct plat_serial8250_port, with proper settings like .flags, .type,
> .iotype, .regshift and .uartclk. Memory (or ioport) and IRQ should be
> passed as cell resources.
What? No, please!
If you *must* create a whole driver just to be able to use
platform_*() helpers (which I don't think you should), then please
call it something else. This doesn't have anything to do with MFD.
> Do not include UPF_BOOT_AUTOCONF in platform_data.flags.
>
> Signed-off-by: Esben Haabendal <esben@geanix.com>
> ---
> drivers/tty/serial/8250/8250_mfd.c | 119 +++++++++++++++++++++++++++++++++++++
> drivers/tty/serial/8250/Kconfig | 12 ++++
> drivers/tty/serial/8250/Makefile | 1 +
> 3 files changed, 132 insertions(+)
> create mode 100644 drivers/tty/serial/8250/8250_mfd.c
>
> diff --git a/drivers/tty/serial/8250/8250_mfd.c b/drivers/tty/serial/8250/8250_mfd.c
> new file mode 100644
> index 0000000..eae1566
> --- /dev/null
> +++ b/drivers/tty/serial/8250/8250_mfd.c
> @@ -0,0 +1,119 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Serial Port driver for 8250/16550-type MFD sub devices
> + *
> + * This mimics the serial8250_probe of 8250_core.c, while allowing
> + * use without UPF_BOOT_AUTOCONF, which is problematic for MFD, as
> + * the request_mem_region() will typically fail as the region is
> + * already requested by the MFD device.
> + *
> + * Memory and irq are passed as platform resources, which allows easy
> + * use together with (devm_)mfd_add_devices().
> + *
> + * Other parameters are passed as struct plat_serial8250_port in
> + * device platform_data.
> + */
> +
> +#include <linux/platform_device.h>
> +#include <linux/module.h>
> +#include <linux/io.h>
> +#include <linux/serial_8250.h>
> +
> +struct serial8250_mfd_data {
> + int line;
> +};
> +
> +static int serial8250_mfd_probe(struct platform_device *pdev)
> +{
> + struct plat_serial8250_port *pdata = dev_get_platdata(&pdev->dev);
> + struct serial8250_mfd_data *data;
> + struct uart_8250_port up;
> + struct resource *r;
> + void __iomem *membase;
> +
> + if (!pdata)
> + return -ENODEV;
> +
> + memset(&up, 0, sizeof(up));
> +
> + switch (pdata->iotype) {
> + case UPIO_AU:
> + case UPIO_TSI:
> + case UPIO_MEM32:
> + case UPIO_MEM32BE:
> + case UPIO_MEM16:
> + case UPIO_MEM:
> + r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (!r)
> + return -ENODEV;
> + membase = devm_ioremap_nocache(&pdev->dev,
> + r->start, resource_size(r));
> + if (!membase)
> + return -ENOMEM;
> + up.port.mapbase = r->start;
> + up.port.membase = membase;
> + break;
> + case UPIO_HUB6:
> + case UPIO_PORT:
> + r = platform_get_resource(pdev, IORESOURCE_IO, 0);
> + if (!r)
> + return -ENODEV;
> + up.port.iobase = r->start;
> + break;
> + }
> +
> + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + up.port.irq = platform_get_irq(pdev, 0);
> + if (up.port.irq < 0)
> + up.port.irq = 0; /* no interrupt -> use polling */
> +
> + /* Register with 8250_core.c */
> + up.port.irqflags = pdata->irqflags;
> + up.port.uartclk = pdata->uartclk;
> + up.port.regshift = pdata->regshift;
> + up.port.iotype = pdata->iotype;
> + up.port.flags = pdata->flags;
> + up.port.hub6 = pdata->hub6;
> + up.port.private_data = pdata->private_data;
> + up.port.type = pdata->type;
> + up.port.serial_in = pdata->serial_in;
> + up.port.serial_out = pdata->serial_out;
> + up.port.handle_irq = pdata->handle_irq;
> + up.port.handle_break = pdata->handle_break;
> + up.port.set_termios = pdata->set_termios;
> + up.port.set_ldisc = pdata->set_ldisc;
> + up.port.get_mctrl = pdata->get_mctrl;
> + up.port.pm = pdata->pm;
> + up.port.dev = &pdev->dev;
> + data->line = __serial8250_register_8250_port(&up, 0);
> + if (data->line < 0)
> + return data->line;
> +
> + platform_set_drvdata(pdev, data);
> + return 0;
> +}
> +
> +static int serial8250_mfd_remove(struct platform_device *pdev)
> +{
> + struct serial8250_mfd_data *data = platform_get_drvdata(pdev);
> +
> + serial8250_unregister_port(data->line);
> + return 0;
> +}
> +
> +static struct platform_driver serial8250_mfd_driver = {
> + .probe = serial8250_mfd_probe,
> + .remove = serial8250_mfd_remove,
> + .driver = {
> + .name = "serial8250-mfd",
> + },
> +};
> +
> +module_platform_driver(serial8250_mfd_driver);
> +
> +MODULE_AUTHOR("Esben Haabendal <esben@geanix.com>");
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("Driver for 8250/16550-type MFD sub devices");
> diff --git a/drivers/tty/serial/8250/Kconfig b/drivers/tty/serial/8250/Kconfig
> index 15c2c54..ef1572b 100644
> --- a/drivers/tty/serial/8250/Kconfig
> +++ b/drivers/tty/serial/8250/Kconfig
> @@ -58,6 +58,18 @@ config SERIAL_8250_PNP
> This builds standard PNP serial support. You may be able to
> disable this feature if you only need legacy serial support.
>
> +config SERIAL_8250_MFD
> + bool "8250/16550 MFD function support"
> + depends on SERIAL_8250 && MFD_CORE
> + default n
> + help
> + This builds support for using 8250/16550-type UARTs as MFD
> + functions.
> +
> + MFD drivers needing this should select it automatically.
> +
> + If unsure, say N.
> +
> config SERIAL_8250_FINTEK
> bool "Support for Fintek F81216A LPC to 4 UART RS485 API"
> depends on SERIAL_8250
> diff --git a/drivers/tty/serial/8250/Makefile b/drivers/tty/serial/8250/Makefile
> index 18751bc..da8e139 100644
> --- a/drivers/tty/serial/8250/Makefile
> +++ b/drivers/tty/serial/8250/Makefile
> @@ -6,6 +6,7 @@
> obj-$(CONFIG_SERIAL_8250) += 8250.o 8250_base.o
> 8250-y := 8250_core.o
> 8250-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o
> +8250-$(CONFIG_SERIAL_8250_MFD) += 8250_mfd.o
> 8250_base-y := 8250_port.o
> 8250_base-$(CONFIG_SERIAL_8250_DMA) += 8250_dma.o
> 8250_base-$(CONFIG_SERIAL_8250_FINTEK) += 8250_fintek.o
--
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
next prev parent reply other threads:[~2019-05-07 11:49 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-26 8:40 [PATCH 0/2] serial: 8250: Add support for 8250/16550 as MFD function Esben Haabendal
2019-04-26 8:40 ` [PATCH 1/2] serial: 8250: Allow port registration without UPF_BOOT_AUTOCONF Esben Haabendal
2019-04-26 14:39 ` Andy Shevchenko
2019-04-26 16:54 ` Esben Haabendal
2019-04-26 21:51 ` Andy Shevchenko
2019-04-27 8:58 ` Esben Haabendal
2019-04-27 11:57 ` Enrico Weigelt, metux IT consult
2019-04-29 6:37 ` Esben Haabendal
2019-04-29 6:37 ` Esben Haabendal
2019-04-27 16:41 ` Andy Shevchenko
2019-04-29 6:27 ` Esben Haabendal
2019-04-29 6:27 ` Esben Haabendal
2019-04-29 8:33 ` Andy Shevchenko
2019-04-29 9:29 ` Esben Haabendal
2019-04-29 9:29 ` Esben Haabendal
2019-04-29 12:56 ` Enrico Weigelt, metux IT consult
2019-04-29 13:35 ` Andy Shevchenko
2019-04-29 14:25 ` Esben Haabendal
2019-04-29 14:25 ` Esben Haabendal
2019-04-26 8:40 ` [PATCH 2/2] serial: 8250: Add support for 8250/16550 as MFD function Esben Haabendal
2019-05-07 11:49 ` Lee Jones [this message]
2019-05-07 12:04 ` Esben Haabendal
2019-05-07 13:38 ` Lee Jones
2019-05-14 8:00 ` Esben Haabendal
2019-05-14 10:47 ` Lee Jones
2019-05-14 12:26 ` Greg Kroah-Hartman
2019-05-14 12:41 ` Esben Haabendal
2019-05-21 10:09 ` Greg Kroah-Hartman
2019-05-21 11:11 ` Esben Haabendal
2019-05-21 11:18 ` Greg Kroah-Hartman
2019-05-21 11:50 ` Esben Haabendal
2019-05-21 12:56 ` Greg Kroah-Hartman
2019-05-21 14:31 ` Esben Haabendal
2019-05-21 14:43 ` Greg Kroah-Hartman
2019-05-27 19:56 ` Enrico Weigelt, metux IT consult
2019-04-26 14:35 ` [PATCH 0/2] " Andy Shevchenko
2019-04-26 16:57 ` Esben Haabendal
2019-04-26 17:21 ` Andy Shevchenko
-- strict thread matches above, loose matches on Subject: below --
2019-04-26 16:55 [PATCH 2/2] " Esben Haabendal
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=20190507114905.GB29524@dell \
--to=lee.jones@linaro.org \
--cc=esben@geanix.com \
--cc=f.fainelli@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=lokeshvutla@ti.com \
--cc=nm@ti.com \
--cc=tony@atomide.com \
--cc=vigneshr@ti.com \
/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.