Skip to content

Commit 7d78cbe

Browse files
mmindgregkh
authored andcommitted
serial: 8250_dw: add ability to handle the peripheral clock
First try to find the named clock variants then fall back to the already existing handling of a nameless declared baudclk. This also adds the missing documentation for this already existing variant. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d8782c7 commit 7d78cbe

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

Documentation/devicetree/bindings/serial/snps-dw-apb-uart.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ Required properties:
44
- compatible : "snps,dw-apb-uart"
55
- reg : offset and length of the register set for the device.
66
- interrupts : should contain uart interrupt.
7+
8+
Clock handling:
9+
The clock rate of the input clock needs to be supplied by one of
710
- clock-frequency : the input clock frequency for the UART.
11+
- clocks : phandle to the input clock
12+
13+
The supplying peripheral clock can also be handled, needing a second property
14+
- clock-names: tuple listing input clock names.
15+
Required elements: "baudclk", "apb_pclk"
816

917
Optional properties:
1018
- reg-shift : quantity to shift the register offsets by. If this property is
@@ -23,3 +31,26 @@ Example:
2331
reg-shift = <2>;
2432
reg-io-width = <4>;
2533
};
34+
35+
Example with one clock:
36+
37+
uart@80230000 {
38+
compatible = "snps,dw-apb-uart";
39+
reg = <0x80230000 0x100>;
40+
clocks = <&baudclk>;
41+
interrupts = <10>;
42+
reg-shift = <2>;
43+
reg-io-width = <4>;
44+
};
45+
46+
Example with two clocks:
47+
48+
uart@80230000 {
49+
compatible = "snps,dw-apb-uart";
50+
reg = <0x80230000 0x100>;
51+
clocks = <&baudclk>, <&apb_pclk>;
52+
clock-names = "baudclk", "apb_pclk";
53+
interrupts = <10>;
54+
reg-shift = <2>;
55+
reg-io-width = <4>;
56+
};

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct dw8250_data {
5959
int last_mcr;
6060
int line;
6161
struct clk *clk;
62+
struct clk *pclk;
6263
struct uart_8250_dma dma;
6364
};
6465

@@ -359,10 +360,25 @@ static int dw8250_probe(struct platform_device *pdev)
359360
return -ENOMEM;
360361

361362
data->usr_reg = DW_UART_USR;
362-
data->clk = devm_clk_get(&pdev->dev, NULL);
363+
data->clk = devm_clk_get(&pdev->dev, "baudclk");
364+
if (IS_ERR(data->clk))
365+
data->clk = devm_clk_get(&pdev->dev, NULL);
363366
if (!IS_ERR(data->clk)) {
364-
clk_prepare_enable(data->clk);
365-
uart.port.uartclk = clk_get_rate(data->clk);
367+
err = clk_prepare_enable(data->clk);
368+
if (err)
369+
dev_warn(&pdev->dev, "could not enable optional baudclk: %d\n",
370+
err);
371+
else
372+
uart.port.uartclk = clk_get_rate(data->clk);
373+
}
374+
375+
data->pclk = devm_clk_get(&pdev->dev, "apb_pclk");
376+
if (!IS_ERR(data->pclk)) {
377+
err = clk_prepare_enable(data->pclk);
378+
if (err) {
379+
dev_err(&pdev->dev, "could not enable apb_pclk\n");
380+
return err;
381+
}
366382
}
367383

368384
data->dma.rx_chan_id = -1;
@@ -408,6 +424,9 @@ static int dw8250_remove(struct platform_device *pdev)
408424

409425
serial8250_unregister_port(data->line);
410426

427+
if (!IS_ERR(data->pclk))
428+
clk_disable_unprepare(data->pclk);
429+
411430
if (!IS_ERR(data->clk))
412431
clk_disable_unprepare(data->clk);
413432

@@ -445,13 +464,19 @@ static int dw8250_runtime_suspend(struct device *dev)
445464
if (!IS_ERR(data->clk))
446465
clk_disable_unprepare(data->clk);
447466

467+
if (!IS_ERR(data->pclk))
468+
clk_disable_unprepare(data->pclk);
469+
448470
return 0;
449471
}
450472

451473
static int dw8250_runtime_resume(struct device *dev)
452474
{
453475
struct dw8250_data *data = dev_get_drvdata(dev);
454476

477+
if (!IS_ERR(data->pclk))
478+
clk_prepare_enable(data->pclk);
479+
455480
if (!IS_ERR(data->clk))
456481
clk_prepare_enable(data->clk);
457482

0 commit comments

Comments
 (0)