Skip to content

Commit 1117a6f

Browse files
andy-shevgregkh
authored andcommitted
serial: 8250_of: Switch to use uart_read_port_properties()
Since we have now a common helper to read port properties use it instead of sparse home grown solution. Reviewed-by: Andi Shyti <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Tested-by: Florian Fainelli <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0087b9e commit 1117a6f

File tree

1 file changed

+19
-80
lines changed

1 file changed

+19
-80
lines changed

drivers/tty/serial/8250/8250_of.c

Lines changed: 19 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -69,37 +69,22 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
6969
struct device *dev = &ofdev->dev;
7070
struct device_node *np = dev->of_node;
7171
struct uart_port *port = &up->port;
72-
u32 clk, spd, prop;
73-
int ret, irq;
72+
u32 spd;
73+
int ret;
7474

7575
memset(port, 0, sizeof *port);
7676

7777
pm_runtime_enable(&ofdev->dev);
7878
pm_runtime_get_sync(&ofdev->dev);
7979

80-
if (of_property_read_u32(np, "clock-frequency", &clk)) {
81-
82-
/* Get clk rate through clk driver if present */
83-
info->clk = devm_clk_get_enabled(dev, NULL);
84-
if (IS_ERR(info->clk)) {
85-
ret = dev_err_probe(dev, PTR_ERR(info->clk), "failed to get clock\n");
86-
goto err_pmruntime;
87-
}
88-
89-
clk = clk_get_rate(info->clk);
90-
}
91-
/* If current-speed was set, then try not to change it. */
92-
if (of_property_read_u32(np, "current-speed", &spd) == 0)
93-
port->custom_divisor = clk / (16 * spd);
94-
9580
ret = of_address_to_resource(np, 0, &resource);
9681
if (ret) {
9782
dev_err_probe(dev, ret, "invalid address\n");
9883
goto err_pmruntime;
9984
}
10085

101-
port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_FIXED_PORT |
102-
UPF_FIXED_TYPE;
86+
port->dev = &ofdev->dev;
87+
port->flags = UPF_BOOT_AUTOCONF | UPF_FIXED_PORT | UPF_FIXED_TYPE;
10388
spin_lock_init(&port->lock);
10489

10590
if (resource_type(&resource) == IORESOURCE_IO) {
@@ -108,70 +93,31 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
10893
} else {
10994
port->mapbase = resource.start;
11095
port->mapsize = resource_size(&resource);
96+
port->flags |= UPF_IOREMAP;
97+
}
11198

112-
/* Check for shifted address mapping */
113-
if (of_property_read_u32(np, "reg-offset", &prop) == 0) {
114-
if (prop >= port->mapsize) {
115-
ret = dev_err_probe(dev, -EINVAL, "reg-offset %u exceeds region size %pa\n",
116-
prop, &port->mapsize);
117-
goto err_pmruntime;
118-
}
99+
ret = uart_read_and_validate_port_properties(port);
100+
if (ret)
101+
goto err_pmruntime;
119102

120-
port->mapbase += prop;
121-
port->mapsize -= prop;
103+
/* Get clk rate through clk driver if present */
104+
if (!port->uartclk) {
105+
info->clk = devm_clk_get_enabled(dev, NULL);
106+
if (IS_ERR(info->clk)) {
107+
ret = dev_err_probe(dev, PTR_ERR(info->clk), "failed to get clock\n");
108+
goto err_pmruntime;
122109
}
123110

124-
port->iotype = UPIO_MEM;
125-
if (of_property_read_u32(np, "reg-io-width", &prop) == 0) {
126-
switch (prop) {
127-
case 1:
128-
port->iotype = UPIO_MEM;
129-
break;
130-
case 2:
131-
port->iotype = UPIO_MEM16;
132-
break;
133-
case 4:
134-
port->iotype = of_device_is_big_endian(np) ?
135-
UPIO_MEM32BE : UPIO_MEM32;
136-
break;
137-
default:
138-
ret = dev_err_probe(dev, -EINVAL, "unsupported reg-io-width (%u)\n",
139-
prop);
140-
goto err_pmruntime;
141-
}
142-
}
143-
port->flags |= UPF_IOREMAP;
111+
port->uartclk = clk_get_rate(info->clk);
144112
}
113+
/* If current-speed was set, then try not to change it. */
114+
if (of_property_read_u32(np, "current-speed", &spd) == 0)
115+
port->custom_divisor = port->uartclk / (16 * spd);
145116

146117
/* Compatibility with the deprecated pxa driver and 8250_pxa drivers. */
147118
if (of_device_is_compatible(np, "mrvl,mmp-uart"))
148119
port->regshift = 2;
149120

150-
/* Check for registers offset within the devices address range */
151-
if (of_property_read_u32(np, "reg-shift", &prop) == 0)
152-
port->regshift = prop;
153-
154-
/* Check for fifo size */
155-
if (of_property_read_u32(np, "fifo-size", &prop) == 0)
156-
port->fifosize = prop;
157-
158-
/* Check for a fixed line number */
159-
ret = of_alias_get_id(np, "serial");
160-
if (ret >= 0)
161-
port->line = ret;
162-
163-
irq = of_irq_get(np, 0);
164-
if (irq < 0) {
165-
if (irq == -EPROBE_DEFER) {
166-
ret = -EPROBE_DEFER;
167-
goto err_pmruntime;
168-
}
169-
/* IRQ support not mandatory */
170-
irq = 0;
171-
}
172-
173-
port->irq = irq;
174-
175121
info->rst = devm_reset_control_get_optional_shared(&ofdev->dev, NULL);
176122
if (IS_ERR(info->rst)) {
177123
ret = PTR_ERR(info->rst);
@@ -183,12 +129,6 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
183129
goto err_pmruntime;
184130

185131
port->type = type;
186-
port->uartclk = clk;
187-
188-
if (of_property_read_bool(np, "no-loopback-test"))
189-
port->flags |= UPF_SKIP_TEST;
190-
191-
port->dev = &ofdev->dev;
192132
port->rs485_config = serial8250_em485_config;
193133
port->rs485_supported = serial8250_em485_supported;
194134
up->rs485_start_tx = serial8250_em485_start_tx;
@@ -280,7 +220,6 @@ static int of_platform_serial_probe(struct platform_device *ofdev)
280220
platform_set_drvdata(ofdev, info);
281221
return 0;
282222
err_dispose:
283-
irq_dispose_mapping(port8250.port.irq);
284223
pm_runtime_put_sync(&ofdev->dev);
285224
pm_runtime_disable(&ofdev->dev);
286225
err_free:

0 commit comments

Comments
 (0)