armada_510.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (C) 2012 Russell King
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * Armada 510 (aka Dove) variant support
  9. */
  10. #include <linux/clk.h>
  11. #include <linux/io.h>
  12. #include <drm/drm_crtc_helper.h>
  13. #include "armada_crtc.h"
  14. #include "armada_drm.h"
  15. #include "armada_hw.h"
  16. static int armada510_crtc_init(struct armada_crtc *dcrtc, struct device *dev)
  17. {
  18. struct clk *clk;
  19. clk = devm_clk_get(dev, "ext_ref_clk1");
  20. if (IS_ERR(clk))
  21. return PTR_ERR(clk) == -ENOENT ? -EPROBE_DEFER : PTR_ERR(clk);
  22. dcrtc->extclk[0] = clk;
  23. /* Lower the watermark so to eliminate jitter at higher bandwidths */
  24. armada_updatel(0x20, (1 << 11) | 0xff, dcrtc->base + LCD_CFG_RDREG4F);
  25. /* Initialise SPU register */
  26. writel_relaxed(ADV_HWC32ENABLE | ADV_HWC32ARGB | ADV_HWC32BLEND,
  27. dcrtc->base + LCD_SPU_ADV_REG);
  28. return 0;
  29. }
  30. /*
  31. * Armada510 specific SCLK register selection.
  32. * This gets called with sclk = NULL to test whether the mode is
  33. * supportable, and again with sclk != NULL to set the clocks up for
  34. * that. The former can return an error, but the latter is expected
  35. * not to.
  36. *
  37. * We currently are pretty rudimentary here, always selecting
  38. * EXT_REF_CLK_1 for LCD0 and erroring LCD1. This needs improvement!
  39. */
  40. static int armada510_crtc_compute_clock(struct armada_crtc *dcrtc,
  41. const struct drm_display_mode *mode, uint32_t *sclk)
  42. {
  43. struct clk *clk = dcrtc->extclk[0];
  44. int ret;
  45. if (dcrtc->num == 1)
  46. return -EINVAL;
  47. if (IS_ERR(clk))
  48. return PTR_ERR(clk);
  49. if (dcrtc->clk != clk) {
  50. ret = clk_prepare_enable(clk);
  51. if (ret)
  52. return ret;
  53. dcrtc->clk = clk;
  54. }
  55. if (sclk) {
  56. uint32_t rate, ref, div;
  57. rate = mode->clock * 1000;
  58. ref = clk_round_rate(clk, rate);
  59. div = DIV_ROUND_UP(ref, rate);
  60. if (div < 1)
  61. div = 1;
  62. clk_set_rate(clk, ref);
  63. *sclk = div | SCLK_510_EXTCLK1;
  64. }
  65. return 0;
  66. }
  67. static void armada510_crtc_disable(struct armada_crtc *dcrtc)
  68. {
  69. if (!IS_ERR(dcrtc->clk)) {
  70. clk_disable_unprepare(dcrtc->clk);
  71. dcrtc->clk = ERR_PTR(-EINVAL);
  72. }
  73. }
  74. static void armada510_crtc_enable(struct armada_crtc *dcrtc,
  75. const struct drm_display_mode *mode)
  76. {
  77. if (IS_ERR(dcrtc->clk)) {
  78. dcrtc->clk = dcrtc->extclk[0];
  79. WARN_ON(clk_prepare_enable(dcrtc->clk));
  80. }
  81. }
  82. const struct armada_variant armada510_ops = {
  83. .has_spu_adv_reg = true,
  84. .init = armada510_crtc_init,
  85. .compute_clock = armada510_crtc_compute_clock,
  86. .disable = armada510_crtc_disable,
  87. .enable = armada510_crtc_enable,
  88. };