serial: 8250: dw: Create a generic platform data structure

Use device tree match data rather than multiple calls to
of_device_is_compatible() by introducing a platform data structure and
adding a quirks mask.

Provide a stub to the compatibles without quirks to simplify the
handling of the upcoming changes.

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
[<miquel.raynal@bootlin.com: Minor changes + creation of a real pdata structure]
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20220422180615.9098-3-miquel.raynal@bootlin.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Emil Renner Berthing 2022-04-22 20:06:08 +02:00 committed by Greg Kroah-Hartman
parent d9666dfb31
commit 4a218b277f
2 changed files with 39 additions and 8 deletions

View File

@ -19,6 +19,7 @@
#include <linux/of_irq.h> #include <linux/of_irq.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/slab.h> #include <linux/slab.h>
@ -37,6 +38,11 @@
/* DesignWare specific register fields */ /* DesignWare specific register fields */
#define DW_UART_MCR_SIRE BIT(6) #define DW_UART_MCR_SIRE BIT(6)
/* Quirks */
#define DW_UART_QUIRK_OCTEON BIT(0)
#define DW_UART_QUIRK_ARMADA_38X BIT(1)
#define DW_UART_QUIRK_SKIP_SET_RATE BIT(2)
static inline struct dw8250_data *clk_to_dw8250_data(struct notifier_block *nb) static inline struct dw8250_data *clk_to_dw8250_data(struct notifier_block *nb)
{ {
return container_of(nb, struct dw8250_data, clk_notifier); return container_of(nb, struct dw8250_data, clk_notifier);
@ -366,6 +372,7 @@ static bool dw8250_idma_filter(struct dma_chan *chan, void *param)
static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data) static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
{ {
struct device_node *np = p->dev->of_node; struct device_node *np = p->dev->of_node;
unsigned int quirks = data->pdata->quirks;
if (np) { if (np) {
int id; int id;
@ -375,7 +382,7 @@ static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
if (id >= 0) if (id >= 0)
p->line = id; p->line = id;
#ifdef CONFIG_64BIT #ifdef CONFIG_64BIT
if (of_device_is_compatible(np, "cavium,octeon-3860-uart")) { if (quirks & DW_UART_QUIRK_OCTEON) {
p->serial_in = dw8250_serial_inq; p->serial_in = dw8250_serial_inq;
p->serial_out = dw8250_serial_outq; p->serial_out = dw8250_serial_outq;
p->flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE; p->flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE;
@ -391,9 +398,9 @@ static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
p->serial_out = dw8250_serial_out32be; p->serial_out = dw8250_serial_out32be;
} }
if (of_device_is_compatible(np, "marvell,armada-38x-uart")) if (quirks & DW_UART_QUIRK_ARMADA_38X)
p->serial_out = dw8250_serial_out38x; p->serial_out = dw8250_serial_out38x;
if (of_device_is_compatible(np, "starfive,jh7100-uart")) if (quirks & DW_UART_QUIRK_SKIP_SET_RATE)
p->set_termios = dw8250_do_set_termios; p->set_termios = dw8250_do_set_termios;
} else if (acpi_dev_present("APMC0D08", NULL, -1)) { } else if (acpi_dev_present("APMC0D08", NULL, -1)) {
@ -456,6 +463,7 @@ static int dw8250_probe(struct platform_device *pdev)
data->data.dma.fn = dw8250_fallback_dma_filter; data->data.dma.fn = dw8250_fallback_dma_filter;
data->usr_reg = DW_UART_USR; data->usr_reg = DW_UART_USR;
data->pdata = device_get_match_data(p->dev);
p->private_data = &data->data; p->private_data = &data->data;
data->uart_16550_compatible = device_property_read_bool(dev, data->uart_16550_compatible = device_property_read_bool(dev,
@ -672,12 +680,30 @@ static const struct dev_pm_ops dw8250_pm_ops = {
SET_RUNTIME_PM_OPS(dw8250_runtime_suspend, dw8250_runtime_resume, NULL) SET_RUNTIME_PM_OPS(dw8250_runtime_suspend, dw8250_runtime_resume, NULL)
}; };
static const struct dw8250_platform_data dw8250_dw_apb = {
};
static const struct dw8250_platform_data dw8250_octeon_3860_data = {
.quirks = DW_UART_QUIRK_OCTEON,
};
static const struct dw8250_platform_data dw8250_armada_38x_data = {
.quirks = DW_UART_QUIRK_ARMADA_38X,
};
static const struct dw8250_platform_data dw8250_renesas_rzn1_data = {
};
static const struct dw8250_platform_data dw8250_starfive_jh7100_data = {
.quirks = DW_UART_QUIRK_SKIP_SET_RATE,
};
static const struct of_device_id dw8250_of_match[] = { static const struct of_device_id dw8250_of_match[] = {
{ .compatible = "snps,dw-apb-uart" }, { .compatible = "snps,dw-apb-uart", .data = &dw8250_dw_apb },
{ .compatible = "cavium,octeon-3860-uart" }, { .compatible = "cavium,octeon-3860-uart", .data = &dw8250_octeon_3860_data },
{ .compatible = "marvell,armada-38x-uart" }, { .compatible = "marvell,armada-38x-uart", .data = &dw8250_armada_38x_data },
{ .compatible = "renesas,rzn1-uart" }, { .compatible = "renesas,rzn1-uart", .data = &dw8250_renesas_rzn1_data },
{ .compatible = "starfive,jh7100-uart" }, { .compatible = "starfive,jh7100-uart", .data = &dw8250_starfive_jh7100_data },
{ /* Sentinel */ } { /* Sentinel */ }
}; };
MODULE_DEVICE_TABLE(of, dw8250_of_match); MODULE_DEVICE_TABLE(of, dw8250_of_match);

View File

@ -21,8 +21,13 @@ struct dw8250_port_data {
u8 dlf_size; u8 dlf_size;
}; };
struct dw8250_platform_data {
unsigned int quirks;
};
struct dw8250_data { struct dw8250_data {
struct dw8250_port_data data; struct dw8250_port_data data;
const struct dw8250_platform_data *pdata;
u8 usr_reg; u8 usr_reg;
int msr_mask_on; int msr_mask_on;