Skip to content

Commit e302cd9

Browse files
elopezgregkh
authored andcommitted
serial: 8250_dw: add support for clk api
This commit implements support for using the clk api; this lets us use the "clocks" property with device tree, instead of having to use clock-frequency. Signed-off-by: Emilio López <emilio@elopez.com.ar> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 38adbc5 commit e302cd9

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/platform_device.h>
2727
#include <linux/slab.h>
2828
#include <linux/acpi.h>
29+
#include <linux/clk.h>
2930

3031
#include "8250.h"
3132

@@ -55,8 +56,9 @@
5556

5657

5758
struct dw8250_data {
58-
int last_lcr;
59-
int line;
59+
int last_lcr;
60+
int line;
61+
struct clk *clk;
6062
};
6163

6264
static void dw8250_serial_out(struct uart_port *p, int offset, int value)
@@ -136,8 +138,13 @@ static int dw8250_probe_of(struct uart_port *p)
136138
if (!of_property_read_u32(np, "reg-shift", &val))
137139
p->regshift = val;
138140

141+
/* clock got configured through clk api, all done */
142+
if (p->uartclk)
143+
return 0;
144+
145+
/* try to find out clock frequency from DT as fallback */
139146
if (of_property_read_u32(np, "clock-frequency", &val)) {
140-
dev_err(p->dev, "no clock-frequency property set\n");
147+
dev_err(p->dev, "clk or clock-frequency not defined\n");
141148
return -EINVAL;
142149
}
143150
p->uartclk = val;
@@ -294,9 +301,20 @@ static int dw8250_probe(struct platform_device *pdev)
294301
if (!uart.port.membase)
295302
return -ENOMEM;
296303

304+
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
305+
if (!data)
306+
return -ENOMEM;
307+
308+
data->clk = devm_clk_get(&pdev->dev, NULL);
309+
if (!IS_ERR(data->clk)) {
310+
clk_prepare_enable(data->clk);
311+
uart.port.uartclk = clk_get_rate(data->clk);
312+
}
313+
297314
uart.port.iotype = UPIO_MEM;
298315
uart.port.serial_in = dw8250_serial_in;
299316
uart.port.serial_out = dw8250_serial_out;
317+
uart.port.private_data = data;
300318

301319
dw8250_setup_port(&uart);
302320

@@ -312,12 +330,6 @@ static int dw8250_probe(struct platform_device *pdev)
312330
return -ENODEV;
313331
}
314332

315-
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
316-
if (!data)
317-
return -ENOMEM;
318-
319-
uart.port.private_data = data;
320-
321333
data->line = serial8250_register_8250_port(&uart);
322334
if (data->line < 0)
323335
return data->line;
@@ -333,6 +345,9 @@ static int dw8250_remove(struct platform_device *pdev)
333345

334346
serial8250_unregister_port(data->line);
335347

348+
if (!IS_ERR(data->clk))
349+
clk_disable_unprepare(data->clk);
350+
336351
return 0;
337352
}
338353

0 commit comments

Comments
 (0)