819-uart-0001-tty-serial-lpuart-add-power-domain-support.patch 2.7 KB

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