t1042rdb_diu.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * T1042 platform DIU operation
  3. *
  4. * Copyright 2014 Freescale Semiconductor Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/io.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <sysdev/fsl_soc.h>
  18. /*DIU Pixel ClockCR offset in scfg*/
  19. #define CCSR_SCFG_PIXCLKCR 0x28
  20. /* DIU Pixel Clock bits of the PIXCLKCR */
  21. #define PIXCLKCR_PXCKEN 0x80000000
  22. #define PIXCLKCR_PXCKINV 0x40000000
  23. #define PIXCLKCR_PXCKDLY 0x0000FF00
  24. #define PIXCLKCR_PXCLK_MASK 0x00FF0000
  25. /* Some CPLD register definitions */
  26. #define CPLD_DIUCSR 0x16
  27. #define CPLD_DIUCSR_DVIEN 0x80
  28. #define CPLD_DIUCSR_BACKLIGHT 0x0f
  29. struct device_node *cpld_node;
  30. /**
  31. * t1042rdb_set_monitor_port: switch the output to a different monitor port
  32. */
  33. static void t1042rdb_set_monitor_port(enum fsl_diu_monitor_port port)
  34. {
  35. static void __iomem *cpld_base;
  36. cpld_base = of_iomap(cpld_node, 0);
  37. if (!cpld_base) {
  38. pr_err("%s: Could not map cpld registers\n", __func__);
  39. goto exit;
  40. }
  41. switch (port) {
  42. case FSL_DIU_PORT_DVI:
  43. /* Enable the DVI(HDMI) port, disable the DFP and
  44. * the backlight
  45. */
  46. clrbits8(cpld_base + CPLD_DIUCSR, CPLD_DIUCSR_DVIEN);
  47. break;
  48. case FSL_DIU_PORT_LVDS:
  49. /*
  50. * LVDS also needs backlight enabled, otherwise the display
  51. * will be blank.
  52. */
  53. /* Enable the DFP port, disable the DVI*/
  54. setbits8(cpld_base + CPLD_DIUCSR, 0x01 << 8);
  55. setbits8(cpld_base + CPLD_DIUCSR, 0x01 << 4);
  56. setbits8(cpld_base + CPLD_DIUCSR, CPLD_DIUCSR_BACKLIGHT);
  57. break;
  58. default:
  59. pr_err("%s: Unsupported monitor port %i\n", __func__, port);
  60. }
  61. iounmap(cpld_base);
  62. exit:
  63. of_node_put(cpld_node);
  64. }
  65. /**
  66. * t1042rdb_set_pixel_clock: program the DIU's clock
  67. * @pixclock: pixel clock in ps (pico seconds)
  68. */
  69. static void t1042rdb_set_pixel_clock(unsigned int pixclock)
  70. {
  71. struct device_node *scfg_np;
  72. void __iomem *scfg;
  73. unsigned long freq;
  74. u64 temp;
  75. u32 pxclk;
  76. scfg_np = of_find_compatible_node(NULL, NULL, "fsl,t1040-scfg");
  77. if (!scfg_np) {
  78. pr_err("%s: Missing scfg node. Can not display video.\n",
  79. __func__);
  80. return;
  81. }
  82. scfg = of_iomap(scfg_np, 0);
  83. of_node_put(scfg_np);
  84. if (!scfg) {
  85. pr_err("%s: Could not map device. Can not display video.\n",
  86. __func__);
  87. return;
  88. }
  89. /* Convert pixclock into frequency */
  90. temp = 1000000000000ULL;
  91. do_div(temp, pixclock);
  92. freq = temp;
  93. /*
  94. * 'pxclk' is the ratio of the platform clock to the pixel clock.
  95. * This number is programmed into the PIXCLKCR register, and the valid
  96. * range of values is 2-255.
  97. */
  98. pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq);
  99. pxclk = clamp_t(u32, pxclk, 2, 255);
  100. /* Disable the pixel clock, and set it to non-inverted and no delay */
  101. clrbits32(scfg + CCSR_SCFG_PIXCLKCR,
  102. PIXCLKCR_PXCKEN | PIXCLKCR_PXCKDLY | PIXCLKCR_PXCLK_MASK);
  103. /* Enable the clock and set the pxclk */
  104. setbits32(scfg + CCSR_SCFG_PIXCLKCR, PIXCLKCR_PXCKEN | (pxclk << 16));
  105. iounmap(scfg);
  106. }
  107. /**
  108. * t1042rdb_valid_monitor_port: set the monitor port for sysfs
  109. */
  110. static enum fsl_diu_monitor_port
  111. t1042rdb_valid_monitor_port(enum fsl_diu_monitor_port port)
  112. {
  113. switch (port) {
  114. case FSL_DIU_PORT_DVI:
  115. case FSL_DIU_PORT_LVDS:
  116. return port;
  117. default:
  118. return FSL_DIU_PORT_DVI; /* Dual-link LVDS is not supported */
  119. }
  120. }
  121. static int __init t1042rdb_diu_init(void)
  122. {
  123. cpld_node = of_find_compatible_node(NULL, NULL, "fsl,t1042rdb-cpld");
  124. if (!cpld_node)
  125. return 0;
  126. diu_ops.set_monitor_port = t1042rdb_set_monitor_port;
  127. diu_ops.set_pixel_clock = t1042rdb_set_pixel_clock;
  128. diu_ops.valid_monitor_port = t1042rdb_valid_monitor_port;
  129. return 0;
  130. }
  131. early_initcall(t1042rdb_diu_init);
  132. MODULE_LICENSE("GPL");