0096-drm-sun4i-dsi-Add-a-variant-structure.patch 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. From 28e64e830ef487b400b3b943fa3bda83dfb2a937 Mon Sep 17 00:00:00 2001
  2. From: Samuel Holland <[email protected]>
  3. Date: Tue, 9 Aug 2022 22:03:42 -0500
  4. Subject: [PATCH 096/117] drm/sun4i: dsi: Add a variant structure
  5. Replace the ad-hoc calls to of_device_is_compatible() with a structure
  6. describing the differences between variants. This is in preparation for
  7. adding more variants to the driver.
  8. Series-changes: 2
  9. - Add the variant check to the probe error path
  10. Reviewed-by: Jernej Skrabec <[email protected]>
  11. Signed-off-by: Samuel Holland <[email protected]>
  12. ---
  13. drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c | 53 +++++++++++++++++---------
  14. drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h | 7 ++++
  15. 2 files changed, 42 insertions(+), 18 deletions(-)
  16. --- a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c
  17. +++ b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c
  18. @@ -1101,12 +1101,16 @@ static const struct component_ops sun6i_
  19. static int sun6i_dsi_probe(struct platform_device *pdev)
  20. {
  21. + const struct sun6i_dsi_variant *variant;
  22. struct device *dev = &pdev->dev;
  23. - const char *bus_clk_name = NULL;
  24. struct sun6i_dsi *dsi;
  25. void __iomem *base;
  26. int ret;
  27. + variant = device_get_match_data(dev);
  28. + if (!variant)
  29. + return -EINVAL;
  30. +
  31. dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
  32. if (!dsi)
  33. return -ENOMEM;
  34. @@ -1114,10 +1118,7 @@ static int sun6i_dsi_probe(struct platfo
  35. dsi->dev = dev;
  36. dsi->host.ops = &sun6i_dsi_host_ops;
  37. dsi->host.dev = dev;
  38. -
  39. - if (of_device_is_compatible(dev->of_node,
  40. - "allwinner,sun6i-a31-mipi-dsi"))
  41. - bus_clk_name = "bus";
  42. + dsi->variant = variant;
  43. base = devm_platform_ioremap_resource(pdev, 0);
  44. if (IS_ERR(base)) {
  45. @@ -1142,7 +1143,7 @@ static int sun6i_dsi_probe(struct platfo
  46. return PTR_ERR(dsi->regs);
  47. }
  48. - dsi->bus_clk = devm_clk_get(dev, bus_clk_name);
  49. + dsi->bus_clk = devm_clk_get(dev, variant->has_mod_clk ? "bus" : NULL);
  50. if (IS_ERR(dsi->bus_clk))
  51. return dev_err_probe(dev, PTR_ERR(dsi->bus_clk),
  52. "Couldn't get the DSI bus clock\n");
  53. @@ -1151,21 +1152,21 @@ static int sun6i_dsi_probe(struct platfo
  54. if (ret)
  55. return ret;
  56. - if (of_device_is_compatible(dev->of_node,
  57. - "allwinner,sun6i-a31-mipi-dsi")) {
  58. + if (variant->has_mod_clk) {
  59. dsi->mod_clk = devm_clk_get(dev, "mod");
  60. if (IS_ERR(dsi->mod_clk)) {
  61. dev_err(dev, "Couldn't get the DSI mod clock\n");
  62. ret = PTR_ERR(dsi->mod_clk);
  63. goto err_attach_clk;
  64. }
  65. - }
  66. - /*
  67. - * In order to operate properly, that clock seems to be always
  68. - * set to 297MHz.
  69. - */
  70. - clk_set_rate_exclusive(dsi->mod_clk, 297000000);
  71. + /*
  72. + * In order to operate properly, the module clock on the
  73. + * A31 variant always seems to be set to 297MHz.
  74. + */
  75. + if (variant->set_mod_clk)
  76. + clk_set_rate_exclusive(dsi->mod_clk, 297000000);
  77. + }
  78. dsi->dphy = devm_phy_get(dev, "dphy");
  79. if (IS_ERR(dsi->dphy)) {
  80. @@ -1191,7 +1192,8 @@ static int sun6i_dsi_probe(struct platfo
  81. err_remove_dsi_host:
  82. mipi_dsi_host_unregister(&dsi->host);
  83. err_unprotect_clk:
  84. - clk_rate_exclusive_put(dsi->mod_clk);
  85. + if (dsi->variant->has_mod_clk && dsi->variant->set_mod_clk)
  86. + clk_rate_exclusive_put(dsi->mod_clk);
  87. err_attach_clk:
  88. regmap_mmio_detach_clk(dsi->regs);
  89. @@ -1205,16 +1207,31 @@ static int sun6i_dsi_remove(struct platf
  90. component_del(&pdev->dev, &sun6i_dsi_ops);
  91. mipi_dsi_host_unregister(&dsi->host);
  92. - clk_rate_exclusive_put(dsi->mod_clk);
  93. + if (dsi->variant->has_mod_clk && dsi->variant->set_mod_clk)
  94. + clk_rate_exclusive_put(dsi->mod_clk);
  95. regmap_mmio_detach_clk(dsi->regs);
  96. return 0;
  97. }
  98. +static const struct sun6i_dsi_variant sun6i_a31_mipi_dsi_variant = {
  99. + .has_mod_clk = true,
  100. + .set_mod_clk = true,
  101. +};
  102. +
  103. +static const struct sun6i_dsi_variant sun50i_a64_mipi_dsi_variant = {
  104. +};
  105. +
  106. static const struct of_device_id sun6i_dsi_of_table[] = {
  107. - { .compatible = "allwinner,sun6i-a31-mipi-dsi" },
  108. - { .compatible = "allwinner,sun50i-a64-mipi-dsi" },
  109. + {
  110. + .compatible = "allwinner,sun6i-a31-mipi-dsi",
  111. + .data = &sun6i_a31_mipi_dsi_variant,
  112. + },
  113. + {
  114. + .compatible = "allwinner,sun50i-a64-mipi-dsi",
  115. + .data = &sun50i_a64_mipi_dsi_variant,
  116. + },
  117. { }
  118. };
  119. MODULE_DEVICE_TABLE(of, sun6i_dsi_of_table);
  120. --- a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h
  121. +++ b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h
  122. @@ -15,6 +15,11 @@
  123. #define SUN6I_DSI_TCON_DIV 4
  124. +struct sun6i_dsi_variant {
  125. + bool has_mod_clk;
  126. + bool set_mod_clk;
  127. +};
  128. +
  129. struct sun6i_dsi {
  130. struct drm_connector connector;
  131. struct drm_encoder encoder;
  132. @@ -31,6 +36,8 @@ struct sun6i_dsi {
  133. struct mipi_dsi_device *device;
  134. struct drm_device *drm;
  135. struct drm_panel *panel;
  136. +
  137. + const struct sun6i_dsi_variant *variant;
  138. };
  139. static inline struct sun6i_dsi *host_to_sun6i_dsi(struct mipi_dsi_host *host)