p1022_rdk.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/fsl/guts.h>
  15. #include <linux/pci.h>
  16. #include <linux/of_platform.h>
  17. #include <asm/div64.h>
  18. #include <asm/mpic.h>
  19. #include <asm/swiotlb.h>
  20. #include <sysdev/fsl_soc.h>
  21. #include <sysdev/fsl_pci.h>
  22. #include <asm/udbg.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_pixel_clock: program the DIU's clock
  33. *
  34. * @pixclock: the wavelength, in picoseconds, of the clock
  35. */
  36. void p1022rdk_set_pixel_clock(unsigned int pixclock)
  37. {
  38. struct device_node *guts_np = NULL;
  39. struct ccsr_guts __iomem *guts;
  40. unsigned long freq;
  41. u64 temp;
  42. u32 pxclk;
  43. /* Map the global utilities registers. */
  44. guts_np = of_find_compatible_node(NULL, NULL, "fsl,p1022-guts");
  45. if (!guts_np) {
  46. pr_err("p1022rdk: missing global utilities device node\n");
  47. return;
  48. }
  49. guts = of_iomap(guts_np, 0);
  50. of_node_put(guts_np);
  51. if (!guts) {
  52. pr_err("p1022rdk: could not map global utilities device\n");
  53. return;
  54. }
  55. /* Convert pixclock from a wavelength to a frequency */
  56. temp = 1000000000000ULL;
  57. do_div(temp, pixclock);
  58. freq = temp;
  59. /*
  60. * 'pxclk' is the ratio of the platform clock to the pixel clock.
  61. * This number is programmed into the CLKDVDR register, and the valid
  62. * range of values is 2-255.
  63. */
  64. pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq);
  65. pxclk = clamp_t(u32, pxclk, 2, 255);
  66. /* Disable the pixel clock, and set it to non-inverted and no delay */
  67. clrbits32(&guts->clkdvdr,
  68. CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK);
  69. /* Enable the clock and set the pxclk */
  70. setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16));
  71. iounmap(guts);
  72. }
  73. /**
  74. * p1022rdk_valid_monitor_port: set the monitor port for sysfs
  75. */
  76. enum fsl_diu_monitor_port
  77. p1022rdk_valid_monitor_port(enum fsl_diu_monitor_port port)
  78. {
  79. return FSL_DIU_PORT_DVI;
  80. }
  81. #endif
  82. void __init p1022_rdk_pic_init(void)
  83. {
  84. struct mpic *mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN |
  85. MPIC_SINGLE_DEST_CPU,
  86. 0, 256, " OpenPIC ");
  87. BUG_ON(mpic == NULL);
  88. mpic_init(mpic);
  89. }
  90. /*
  91. * Setup the architecture
  92. */
  93. static void __init p1022_rdk_setup_arch(void)
  94. {
  95. if (ppc_md.progress)
  96. ppc_md.progress("p1022_rdk_setup_arch()", 0);
  97. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  98. diu_ops.set_pixel_clock = p1022rdk_set_pixel_clock;
  99. diu_ops.valid_monitor_port = p1022rdk_valid_monitor_port;
  100. #endif
  101. mpc85xx_smp_init();
  102. fsl_pci_assign_primary();
  103. swiotlb_detect_4g();
  104. pr_info("Freescale / iVeia P1022 RDK reference board\n");
  105. }
  106. machine_arch_initcall(p1022_rdk, mpc85xx_common_publish_devices);
  107. machine_arch_initcall(p1022_rdk, swiotlb_setup_bus_notifier);
  108. /*
  109. * Called very early, device-tree isn't unflattened
  110. */
  111. static int __init p1022_rdk_probe(void)
  112. {
  113. unsigned long root = of_get_flat_dt_root();
  114. return of_flat_dt_is_compatible(root, "fsl,p1022rdk");
  115. }
  116. define_machine(p1022_rdk) {
  117. .name = "P1022 RDK",
  118. .probe = p1022_rdk_probe,
  119. .setup_arch = p1022_rdk_setup_arch,
  120. .init_IRQ = p1022_rdk_pic_init,
  121. #ifdef CONFIG_PCI
  122. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  123. .pcibios_fixup_phb = fsl_pcibios_fixup_phb,
  124. #endif
  125. .get_irq = mpic_get_irq,
  126. .restart = fsl_rstcr_restart,
  127. .calibrate_decr = generic_calibrate_decr,
  128. .progress = udbg_progress,
  129. };