Skip to content

Commit a7260c8

Browse files
Heikki Krogerusgregkh
authored andcommitted
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 <[email protected]> Reviewed-by: Jamie Iles <[email protected]> Acked-by: Alan Cox <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f93366f commit a7260c8

File tree

1 file changed

+47
-31
lines changed

1 file changed

+47
-31
lines changed

drivers/tty/serial/8250/8250_dw.c

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,51 @@ static int dw8250_handle_irq(struct uart_port *p)
8787
return 0;
8888
}
8989

90+
static int dw8250_probe_of(struct uart_port *p)
91+
{
92+
struct device_node *np = p->dev->of_node;
93+
u32 val;
94+
95+
if (!of_property_read_u32(np, "reg-io-width", &val)) {
96+
switch (val) {
97+
case 1:
98+
break;
99+
case 4:
100+
p->iotype = UPIO_MEM32;
101+
p->serial_in = dw8250_serial_in32;
102+
p->serial_out = dw8250_serial_out32;
103+
break;
104+
default:
105+
dev_err(p->dev, "unsupported reg-io-width (%u)\n", val);
106+
return -EINVAL;
107+
}
108+
}
109+
110+
if (!of_property_read_u32(np, "reg-shift", &val))
111+
p->regshift = val;
112+
113+
if (of_property_read_u32(np, "clock-frequency", &val)) {
114+
dev_err(p->dev, "no clock-frequency property set\n");
115+
return -EINVAL;
116+
}
117+
p->uartclk = val;
118+
119+
return 0;
120+
}
121+
90122
static int dw8250_probe(struct platform_device *pdev)
91123
{
92124
struct uart_8250_port uart = {};
93125
struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
94126
struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
95-
struct device_node *np = pdev->dev.of_node;
96-
u32 val;
97127
struct dw8250_data *data;
128+
int err;
98129

99130
if (!regs || !irq) {
100131
dev_err(&pdev->dev, "no registers/irq defined\n");
101132
return -EINVAL;
102133
}
103134

104-
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
105-
if (!data)
106-
return -ENOMEM;
107-
uart.port.private_data = data;
108-
109135
spin_lock_init(&uart.port.lock);
110136
uart.port.mapbase = regs->start;
111137
uart.port.irq = irq->start;
@@ -121,30 +147,20 @@ static int dw8250_probe(struct platform_device *pdev)
121147
uart.port.iotype = UPIO_MEM;
122148
uart.port.serial_in = dw8250_serial_in;
123149
uart.port.serial_out = dw8250_serial_out;
124-
if (!of_property_read_u32(np, "reg-io-width", &val)) {
125-
switch (val) {
126-
case 1:
127-
break;
128-
case 4:
129-
uart.port.iotype = UPIO_MEM32;
130-
uart.port.serial_in = dw8250_serial_in32;
131-
uart.port.serial_out = dw8250_serial_out32;
132-
break;
133-
default:
134-
dev_err(&pdev->dev, "unsupported reg-io-width (%u)\n",
135-
val);
136-
return -EINVAL;
137-
}
150+
151+
if (pdev->dev.of_node) {
152+
err = dw8250_probe_of(&uart.port);
153+
if (err)
154+
return err;
155+
} else {
156+
return -ENODEV;
138157
}
139158

140-
if (!of_property_read_u32(np, "reg-shift", &val))
141-
uart.port.regshift = val;
159+
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
160+
if (!data)
161+
return -ENOMEM;
142162

143-
if (of_property_read_u32(np, "clock-frequency", &val)) {
144-
dev_err(&pdev->dev, "no clock-frequency property set\n");
145-
return -EINVAL;
146-
}
147-
uart.port.uartclk = val;
163+
uart.port.private_data = data;
148164

149165
data->line = serial8250_register_8250_port(&uart);
150166
if (data->line < 0)
@@ -187,17 +203,17 @@ static int dw8250_resume(struct platform_device *pdev)
187203
#define dw8250_resume NULL
188204
#endif /* CONFIG_PM */
189205

190-
static const struct of_device_id dw8250_match[] = {
206+
static const struct of_device_id dw8250_of_match[] = {
191207
{ .compatible = "snps,dw-apb-uart" },
192208
{ /* Sentinel */ }
193209
};
194-
MODULE_DEVICE_TABLE(of, dw8250_match);
210+
MODULE_DEVICE_TABLE(of, dw8250_of_match);
195211

196212
static struct platform_driver dw8250_platform_driver = {
197213
.driver = {
198214
.name = "dw-apb-uart",
199215
.owner = THIS_MODULE,
200-
.of_match_table = dw8250_match,
216+
.of_match_table = dw8250_of_match,
201217
},
202218
.probe = dw8250_probe,
203219
.remove = dw8250_remove,

0 commit comments

Comments
 (0)