155-media-atmel-properly-get-pm_runtime.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. From c7660cc977621c4a14d870d523918df067f0db39 Mon Sep 17 00:00:00 2001
  2. From: Mauro Carvalho Chehab <[email protected]>
  3. Date: Fri, 23 Apr 2021 16:47:42 +0200
  4. Subject: [PATCH 155/247] media: atmel: properly get pm_runtime
  5. There are several issues in the way the atmel driver handles
  6. pm_runtime_get_sync():
  7. - it doesn't check return codes;
  8. - it doesn't properly decrement the usage_count on all places;
  9. - it starts streaming even if pm_runtime_get_sync() fails.
  10. - while it tries to get pm_runtime at the clock enable logic,
  11. it doesn't check if the operation was suceeded.
  12. Replace all occurrences of it to use the new kAPI:
  13. pm_runtime_resume_and_get(), which ensures that, if the
  14. return code is not negative, the usage_count was incremented.
  15. With that, add additional checks when this is called, in order
  16. to ensure that errors will be properly addressed.
  17. Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  18. ---
  19. drivers/media/platform/atmel/atmel-isc-base.c | 30 ++++++++++++++-----
  20. drivers/media/platform/atmel/atmel-isi.c | 19 +++++++++---
  21. 2 files changed, 38 insertions(+), 11 deletions(-)
  22. --- a/drivers/media/platform/atmel/atmel-isc-base.c
  23. +++ b/drivers/media/platform/atmel/atmel-isc-base.c
  24. @@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct cl
  25. static int isc_clk_prepare(struct clk_hw *hw)
  26. {
  27. struct isc_clk *isc_clk = to_isc_clk(hw);
  28. + int ret;
  29. - if (isc_clk->id == ISC_ISPCK)
  30. - pm_runtime_get_sync(isc_clk->dev);
  31. + if (isc_clk->id == ISC_ISPCK) {
  32. + ret = pm_runtime_resume_and_get(isc_clk->dev);
  33. + if (ret < 0)
  34. + return ret;
  35. + }
  36. return isc_wait_clk_stable(hw);
  37. }
  38. @@ -353,9 +357,13 @@ static int isc_clk_is_enabled(struct clk
  39. {
  40. struct isc_clk *isc_clk = to_isc_clk(hw);
  41. u32 status;
  42. + int ret;
  43. - if (isc_clk->id == ISC_ISPCK)
  44. - pm_runtime_get_sync(isc_clk->dev);
  45. + if (isc_clk->id == ISC_ISPCK) {
  46. + ret = pm_runtime_resume_and_get(isc_clk->dev);
  47. + if (ret < 0)
  48. + return 0;
  49. + }
  50. regmap_read(isc_clk->regmap, ISC_CLKSR, &status);
  51. @@ -807,7 +815,12 @@ static int isc_start_streaming(struct vb
  52. goto err_start_stream;
  53. }
  54. - pm_runtime_get_sync(isc->dev);
  55. + ret = pm_runtime_resume_and_get(isc->dev);
  56. + if (ret < 0) {
  57. + v4l2_err(&isc->v4l2_dev, "RPM resume failed in subdev %d\n",
  58. + ret);
  59. + goto err_pm_get;
  60. + }
  61. ret = isc_configure(isc);
  62. if (unlikely(ret))
  63. @@ -838,7 +851,7 @@ static int isc_start_streaming(struct vb
  64. err_configure:
  65. pm_runtime_put_sync(isc->dev);
  66. -
  67. +err_pm_get:
  68. v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0);
  69. err_start_stream:
  70. @@ -1809,6 +1822,7 @@ static void isc_awb_work(struct work_str
  71. u32 baysel;
  72. unsigned long flags;
  73. u32 min, max;
  74. + int ret;
  75. /* streaming is not active anymore */
  76. if (isc->stop)
  77. @@ -1831,7 +1845,9 @@ static void isc_awb_work(struct work_str
  78. ctrls->hist_id = hist_id;
  79. baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT;
  80. - pm_runtime_get_sync(isc->dev);
  81. + ret = pm_runtime_resume_and_get(isc->dev);
  82. + if (ret < 0)
  83. + return;
  84. /*
  85. * only update if we have all the required histograms and controls
  86. --- a/drivers/media/platform/atmel/atmel-isi.c
  87. +++ b/drivers/media/platform/atmel/atmel-isi.c
  88. @@ -423,7 +423,9 @@ static int start_streaming(struct vb2_qu
  89. struct frame_buffer *buf, *node;
  90. int ret;
  91. - pm_runtime_get_sync(isi->dev);
  92. + ret = pm_runtime_resume_and_get(isi->dev);
  93. + if (ret < 0)
  94. + return ret;
  95. /* Enable stream on the sub device */
  96. ret = v4l2_subdev_call(isi->entity.subdev, video, s_stream, 1);
  97. @@ -783,9 +785,10 @@ static int isi_enum_frameintervals(struc
  98. return 0;
  99. }
  100. -static void isi_camera_set_bus_param(struct atmel_isi *isi)
  101. +static int isi_camera_set_bus_param(struct atmel_isi *isi)
  102. {
  103. u32 cfg1 = 0;
  104. + int ret;
  105. /* set bus param for ISI */
  106. if (isi->pdata.hsync_act_low)
  107. @@ -802,12 +805,16 @@ static void isi_camera_set_bus_param(str
  108. cfg1 |= ISI_CFG1_THMASK_BEATS_16;
  109. /* Enable PM and peripheral clock before operate isi registers */
  110. - pm_runtime_get_sync(isi->dev);
  111. + ret = pm_runtime_resume_and_get(isi->dev);
  112. + if (ret < 0)
  113. + return ret;
  114. isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
  115. isi_writel(isi, ISI_CFG1, cfg1);
  116. pm_runtime_put(isi->dev);
  117. +
  118. + return 0;
  119. }
  120. /* -----------------------------------------------------------------------*/
  121. @@ -1086,7 +1093,11 @@ static int isi_graph_notify_complete(str
  122. dev_err(isi->dev, "No supported mediabus format found\n");
  123. return ret;
  124. }
  125. - isi_camera_set_bus_param(isi);
  126. + ret = isi_camera_set_bus_param(isi);
  127. + if (ret) {
  128. + dev_err(isi->dev, "Can't wake up device\n");
  129. + return ret;
  130. + }
  131. ret = isi_set_default_fmt(isi);
  132. if (ret) {