p1022_rdk.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * P1022 RDK board specific routines
  3. *
  4. * Copyright 2012 Freescale Semiconductor, Inc.
  5. *
  6. * Author: Timur Tabi <timur@freescale.com>
  7. *
  8. * Based on p1022_ds.c
  9. *
  10. * This file is licensed under the terms of the GNU General Public License
  11. * version 2. This program is licensed "as is" without any warranty of any
  12. * kind, whether express or implied.
  13. */
  14. #include <linux/pci.h>
  15. #include <linux/of_platform.h>
  16. #include <asm/div64.h>
  17. #include <asm/mpic.h>
  18. #include <asm/swiotlb.h>
  19. #include <sysdev/fsl_soc.h>
  20. #include <sysdev/fsl_pci.h>
  21. #include <asm/udbg.h>
  22. #include <asm/fsl_guts.h>
  23. #include "smp.h"
  24. #include "mpc85xx.h"
  25. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  26. /* DIU Pixel Clock bits of the CLKDVDR Global Utilities register */
  27. #define CLKDVDR_PXCKEN 0x80000000
  28. #define CLKDVDR_PXCKINV 0x10000000
  29. #define CLKDVDR_PXCKDLY 0x06000000
  30. #define CLKDVDR_PXCLK_MASK 0x00FF0000
  31. /**
  32. * p1022rdk_set_monitor_port: switch the output to a different monitor port
  33. */
  34. static void p1022rdk_set_monitor_port(enum fsl_diu_monitor_port port)
  35. {
  36. if (port != FSL_DIU_PORT_DVI) {
  37. pr_err("p1022rdk: unsupported monitor port %i\n", port);
  38. return;
  39. }
  40. }
  41. /**
  42. * p1022rdk_set_pixel_clock: program the DIU's clock
  43. *
  44. * @pixclock: the wavelength, in picoseconds, of the clock
  45. */
  46. void p1022rdk_set_pixel_clock(unsigned int pixclock)
  47. {
  48. struct device_node *guts_np = NULL;
  49. struct ccsr_guts __iomem *guts;
  50. unsigned long freq;
  51. u64 temp;
  52. u32 pxclk;
  53. /* Map the global utilities registers. */
  54. guts_np = of_find_compatible_node(NULL, NULL, "fsl,p1022-guts");
  55. if (!guts_np) {
  56. pr_err("p1022rdk: missing global utilties device node\n");
  57. return;
  58. }
  59. guts = of_iomap(guts_np, 0);
  60. of_node_put(guts_np);
  61. if (!guts) {
  62. pr_err("p1022rdk: could not map global utilties device\n");
  63. return;
  64. }
  65. /* Convert pixclock from a wavelength to a frequency */
  66. temp = 1000000000000ULL;
  67. do_div(temp, pixclock);
  68. freq = temp;
  69. /*
  70. * 'pxclk' is the ratio of the platform clock to the pixel clock.
  71. * This number is programmed into the CLKDVDR register, and the valid
  72. * range of values is 2-255.
  73. */
  74. pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq);
  75. pxclk = clamp_t(u32, pxclk, 2, 255);
  76. /* Disable the pixel clock, and set it to non-inverted and no delay */
  77. clrbits32(&guts->clkdvdr,
  78. CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK);
  79. /* Enable the clock and set the pxclk */
  80. setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16));
  81. iounmap(guts);
  82. }
  83. /**
  84. * p1022rdk_valid_monitor_port: set the monitor port for sysfs
  85. */
  86. enum fsl_diu_monitor_port
  87. p1022rdk_valid_monitor_port(enum fsl_diu_monitor_port port)
  88. {
  89. return FSL_DIU_PORT_DVI;
  90. }
  91. #endif
  92. void __init p1022_rdk_pic_init(void)
  93. {
  94. struct mpic *mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN |
  95. MPIC_SINGLE_DEST_CPU,
  96. 0, 256, " OpenPIC ");
  97. BUG_ON(mpic == NULL);
  98. mpic_init(mpic);
  99. }
  100. /*
  101. * Setup the architecture
  102. */
  103. static void __init p1022_rdk_setup_arch(void)
  104. {
  105. if (ppc_md.progress)
  106. ppc_md.progress("p1022_rdk_setup_arch()", 0);
  107. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  108. diu_ops.set_monitor_port = p1022rdk_set_monitor_port;
  109. diu_ops.set_pixel_clock = p1022rdk_set_pixel_clock;
  110. diu_ops.valid_monitor_port = p1022rdk_valid_monitor_port;
  111. #endif
  112. mpc85xx_smp_init();
  113. fsl_pci_assign_primary();
  114. swiotlb_detect_4g();
  115. pr_info("Freescale / iVeia P1022 RDK reference board\n");
  116. }
  117. machine_arch_initcall(p1022_rdk, mpc85xx_common_publish_devices);
  118. machine_arch_initcall(p1022_rdk, swiotlb_setup_bus_notifier);
  119. /*
  120. * Called very early, device-tree isn't unflattened
  121. */
  122. static int __init p1022_rdk_probe(void)
  123. {
  124. unsigned long root = of_get_flat_dt_root();
  125. return of_flat_dt_is_compatible(root, "fsl,p1022rdk");
  126. }
  127. define_machine(p1022_rdk) {
  128. .name = "P1022 RDK",
  129. .probe = p1022_rdk_probe,
  130. .setup_arch = p1022_rdk_setup_arch,
  131. .init_IRQ = p1022_rdk_pic_init,
  132. #ifdef CONFIG_PCI
  133. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  134. #endif
  135. .get_irq = mpic_get_irq,
  136. .restart = fsl_rstcr_restart,
  137. .calibrate_decr = generic_calibrate_decr,
  138. .progress = udbg_progress,
  139. };