ath79/mikrotik: use routerbootpart partitions
[oweals/openwrt.git] / target / linux / layerscape / patches-5.4 / 819-uart-0001-tty-serial-lpuart-add-power-domain-support.patch
1 From e8730a6bd02cf4f6a3e2d11585d91c0417ed92e5 Mon Sep 17 00:00:00 2001
2 From: Fugang Duan <fugang.duan@nxp.com>
3 Date: Wed, 10 Jul 2019 14:20:45 +0800
4 Subject: [PATCH] tty: serial: lpuart: add power domain support
5
6 lpuart dma mode depends on dma channel's power domain like:
7 power-domains = <&pd IMX_SC_R_UART_1>,
8                 <&pd IMX_SC_R_DMA_2_CH10>,
9                 <&pd IMX_SC_R_DMA_2_CH11>;
10 power-domain-names = "uart", "rxdma", "txdma";
11
12 So define the multiple power domain for lpuart.
13
14 Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
15 ---
16  drivers/tty/serial/fsl_lpuart.c | 54 +++++++++++++++++++++++++++++++++++++++++
17  1 file changed, 54 insertions(+)
18
19 --- a/drivers/tty/serial/fsl_lpuart.c
20 +++ b/drivers/tty/serial/fsl_lpuart.c
21 @@ -20,6 +20,8 @@
22  #include <linux/of.h>
23  #include <linux/of_device.h>
24  #include <linux/of_dma.h>
25 +#include <linux/pm_domain.h>
26 +#include <linux/pm_runtime.h>
27  #include <linux/serial_core.h>
28  #include <linux/slab.h>
29  #include <linux/tty_flip.h>
30 @@ -2369,6 +2371,54 @@ static struct uart_driver lpuart_reg = {
31         .cons           = LPUART_CONSOLE,
32  };
33  
34 +static int lpuart_attach_pd(struct device *dev)
35 +{
36 +       struct device *pd_uart;
37 +       struct device *pd_txdma, *pd_rxdma;
38 +       struct device_link *link;
39 +
40 +       if (dev->pm_domain)
41 +               return 0;
42 +
43 +       pd_uart = dev_pm_domain_attach_by_name(dev, "uart");
44 +       if (IS_ERR(pd_uart))
45 +               return PTR_ERR(pd_uart);
46 +       link = device_link_add(dev, pd_uart, DL_FLAG_STATELESS |
47 +                                            DL_FLAG_PM_RUNTIME |
48 +                                            DL_FLAG_RPM_ACTIVE);
49 +       if (IS_ERR(link)) {
50 +               dev_err(dev, "Failed to add device_link to uart pd: %ld\n",
51 +                       PTR_ERR(link));
52 +               return PTR_ERR(link);
53 +       }
54 +
55 +       pd_txdma = dev_pm_domain_attach_by_name(dev, "txdma");
56 +       if (IS_ERR(pd_txdma))
57 +               return PTR_ERR(pd_txdma);
58 +       link = device_link_add(dev, pd_txdma, DL_FLAG_STATELESS |
59 +                                            DL_FLAG_PM_RUNTIME |
60 +                                            DL_FLAG_RPM_ACTIVE);
61 +       if (IS_ERR(link)) {
62 +               dev_err(dev, "Failed to add device_link to uart pd: %ld\n",
63 +                       PTR_ERR(link));
64 +               return PTR_ERR(link);
65 +       }
66 +
67 +       pd_rxdma = dev_pm_domain_attach_by_name(dev, "rxdma");
68 +       if (IS_ERR(pd_rxdma))
69 +               return PTR_ERR(pd_rxdma);
70 +       link = device_link_add(dev, pd_rxdma, DL_FLAG_STATELESS |
71 +                                            DL_FLAG_PM_RUNTIME |
72 +                                            DL_FLAG_RPM_ACTIVE);
73 +       if (IS_ERR(link)) {
74 +               dev_err(dev, "Failed to add device_link to uart pd: %ld\n",
75 +                       PTR_ERR(link));
76 +               return PTR_ERR(link);
77 +       }
78 +
79 +       return 0;
80 +}
81 +
82  static int lpuart_probe(struct platform_device *pdev)
83  {
84         const struct of_device_id *of_id = of_match_device(lpuart_dt_ids,
85 @@ -2406,6 +2456,10 @@ static int lpuart_probe(struct platform_
86  
87         sport->port.rs485_config = lpuart_config_rs485;
88  
89 +       ret = lpuart_attach_pd(&pdev->dev);
90 +       if (ret)
91 +               return ret;
92 +
93         sport->ipg_clk = devm_clk_get(&pdev->dev, "ipg");
94         if (IS_ERR(sport->ipg_clk)) {
95                 ret = PTR_ERR(sport->ipg_clk);