serial: 8250_dw: Move device tree code to separate function
Trivial cleanup. This makes it easier to add different methods to enumerate the device, for example ACPI 5.0 enumeration. Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Reviewed-by: Jamie Iles <jamie@jamieiles.com> Acked-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
f93366ff9a
commit
a7260c8ce0
|
@ -87,25 +87,51 @@ static int dw8250_handle_irq(struct uart_port *p)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int dw8250_probe_of(struct uart_port *p)
|
||||||
|
{
|
||||||
|
struct device_node *np = p->dev->of_node;
|
||||||
|
u32 val;
|
||||||
|
|
||||||
|
if (!of_property_read_u32(np, "reg-io-width", &val)) {
|
||||||
|
switch (val) {
|
||||||
|
case 1:
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
p->iotype = UPIO_MEM32;
|
||||||
|
p->serial_in = dw8250_serial_in32;
|
||||||
|
p->serial_out = dw8250_serial_out32;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dev_err(p->dev, "unsupported reg-io-width (%u)\n", val);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!of_property_read_u32(np, "reg-shift", &val))
|
||||||
|
p->regshift = val;
|
||||||
|
|
||||||
|
if (of_property_read_u32(np, "clock-frequency", &val)) {
|
||||||
|
dev_err(p->dev, "no clock-frequency property set\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
p->uartclk = val;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int dw8250_probe(struct platform_device *pdev)
|
static int dw8250_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct uart_8250_port uart = {};
|
struct uart_8250_port uart = {};
|
||||||
struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
||||||
struct device_node *np = pdev->dev.of_node;
|
|
||||||
u32 val;
|
|
||||||
struct dw8250_data *data;
|
struct dw8250_data *data;
|
||||||
|
int err;
|
||||||
|
|
||||||
if (!regs || !irq) {
|
if (!regs || !irq) {
|
||||||
dev_err(&pdev->dev, "no registers/irq defined\n");
|
dev_err(&pdev->dev, "no registers/irq defined\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
|
|
||||||
if (!data)
|
|
||||||
return -ENOMEM;
|
|
||||||
uart.port.private_data = data;
|
|
||||||
|
|
||||||
spin_lock_init(&uart.port.lock);
|
spin_lock_init(&uart.port.lock);
|
||||||
uart.port.mapbase = regs->start;
|
uart.port.mapbase = regs->start;
|
||||||
uart.port.irq = irq->start;
|
uart.port.irq = irq->start;
|
||||||
|
@ -121,30 +147,20 @@ static int dw8250_probe(struct platform_device *pdev)
|
||||||
uart.port.iotype = UPIO_MEM;
|
uart.port.iotype = UPIO_MEM;
|
||||||
uart.port.serial_in = dw8250_serial_in;
|
uart.port.serial_in = dw8250_serial_in;
|
||||||
uart.port.serial_out = dw8250_serial_out;
|
uart.port.serial_out = dw8250_serial_out;
|
||||||
if (!of_property_read_u32(np, "reg-io-width", &val)) {
|
|
||||||
switch (val) {
|
if (pdev->dev.of_node) {
|
||||||
case 1:
|
err = dw8250_probe_of(&uart.port);
|
||||||
break;
|
if (err)
|
||||||
case 4:
|
return err;
|
||||||
uart.port.iotype = UPIO_MEM32;
|
} else {
|
||||||
uart.port.serial_in = dw8250_serial_in32;
|
return -ENODEV;
|
||||||
uart.port.serial_out = dw8250_serial_out32;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dev_err(&pdev->dev, "unsupported reg-io-width (%u)\n",
|
|
||||||
val);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!of_property_read_u32(np, "reg-shift", &val))
|
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
|
||||||
uart.port.regshift = val;
|
if (!data)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
if (of_property_read_u32(np, "clock-frequency", &val)) {
|
uart.port.private_data = data;
|
||||||
dev_err(&pdev->dev, "no clock-frequency property set\n");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
uart.port.uartclk = val;
|
|
||||||
|
|
||||||
data->line = serial8250_register_8250_port(&uart);
|
data->line = serial8250_register_8250_port(&uart);
|
||||||
if (data->line < 0)
|
if (data->line < 0)
|
||||||
|
@ -187,17 +203,17 @@ static int dw8250_resume(struct platform_device *pdev)
|
||||||
#define dw8250_resume NULL
|
#define dw8250_resume NULL
|
||||||
#endif /* CONFIG_PM */
|
#endif /* CONFIG_PM */
|
||||||
|
|
||||||
static const struct of_device_id dw8250_match[] = {
|
static const struct of_device_id dw8250_of_match[] = {
|
||||||
{ .compatible = "snps,dw-apb-uart" },
|
{ .compatible = "snps,dw-apb-uart" },
|
||||||
{ /* Sentinel */ }
|
{ /* Sentinel */ }
|
||||||
};
|
};
|
||||||
MODULE_DEVICE_TABLE(of, dw8250_match);
|
MODULE_DEVICE_TABLE(of, dw8250_of_match);
|
||||||
|
|
||||||
static struct platform_driver dw8250_platform_driver = {
|
static struct platform_driver dw8250_platform_driver = {
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "dw-apb-uart",
|
.name = "dw-apb-uart",
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.of_match_table = dw8250_match,
|
.of_match_table = dw8250_of_match,
|
||||||
},
|
},
|
||||||
.probe = dw8250_probe,
|
.probe = dw8250_probe,
|
||||||
.remove = dw8250_remove,
|
.remove = dw8250_remove,
|
||||||
|
|
Loading…
Reference in New Issue