p1022_ds.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*
  2. * P1022DS board specific routines
  3. *
  4. * Authors: Travis Wheatley <travis.wheatley@freescale.com>
  5. * Dave Liu <daveliu@freescale.com>
  6. * Timur Tabi <timur@freescale.com>
  7. *
  8. * Copyright 2010 Freescale Semiconductor, Inc.
  9. *
  10. * This file is taken from the Freescale P1022DS BSP, with modifications:
  11. * 2) No AMP support
  12. * 3) No PCI endpoint support
  13. *
  14. * This file is licensed under the terms of the GNU General Public License
  15. * version 2. This program is licensed "as is" without any warranty of any
  16. * kind, whether express or implied.
  17. */
  18. #include <linux/pci.h>
  19. #include <linux/of_platform.h>
  20. #include <linux/memblock.h>
  21. #include <asm/div64.h>
  22. #include <asm/mpic.h>
  23. #include <asm/swiotlb.h>
  24. #include <sysdev/fsl_soc.h>
  25. #include <sysdev/fsl_pci.h>
  26. #include <asm/udbg.h>
  27. #include <asm/fsl_guts.h>
  28. #include "smp.h"
  29. #include "mpc85xx.h"
  30. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  31. /*
  32. * Board-specific initialization of the DIU. This code should probably be
  33. * executed when the DIU is opened, rather than in arch code, but the DIU
  34. * driver does not have a mechanism for this (yet).
  35. *
  36. * This is especially problematic on the P1022DS because the local bus (eLBC)
  37. * and the DIU video signals share the same pins, which means that enabling the
  38. * DIU will disable access to NOR flash.
  39. */
  40. /* DIU Pixel Clock bits of the CLKDVDR Global Utilities register */
  41. #define CLKDVDR_PXCKEN 0x80000000
  42. #define CLKDVDR_PXCKINV 0x10000000
  43. #define CLKDVDR_PXCKDLY 0x06000000
  44. #define CLKDVDR_PXCLK_MASK 0x00FF0000
  45. /* Some ngPIXIS register definitions */
  46. #define PX_BRDCFG1_DVIEN 0x80
  47. #define PX_BRDCFG1_DFPEN 0x40
  48. #define PX_BRDCFG1_BACKLIGHT 0x20
  49. #define PX_BRDCFG1_DDCEN 0x10
  50. /*
  51. * DIU Area Descriptor
  52. *
  53. * Note that we need to byte-swap the value before it's written to the AD
  54. * register. So even though the registers don't look like they're in the same
  55. * bit positions as they are on the MPC8610, the same value is written to the
  56. * AD register on the MPC8610 and on the P1022.
  57. */
  58. #define AD_BYTE_F 0x10000000
  59. #define AD_ALPHA_C_MASK 0x0E000000
  60. #define AD_ALPHA_C_SHIFT 25
  61. #define AD_BLUE_C_MASK 0x01800000
  62. #define AD_BLUE_C_SHIFT 23
  63. #define AD_GREEN_C_MASK 0x00600000
  64. #define AD_GREEN_C_SHIFT 21
  65. #define AD_RED_C_MASK 0x00180000
  66. #define AD_RED_C_SHIFT 19
  67. #define AD_PALETTE 0x00040000
  68. #define AD_PIXEL_S_MASK 0x00030000
  69. #define AD_PIXEL_S_SHIFT 16
  70. #define AD_COMP_3_MASK 0x0000F000
  71. #define AD_COMP_3_SHIFT 12
  72. #define AD_COMP_2_MASK 0x00000F00
  73. #define AD_COMP_2_SHIFT 8
  74. #define AD_COMP_1_MASK 0x000000F0
  75. #define AD_COMP_1_SHIFT 4
  76. #define AD_COMP_0_MASK 0x0000000F
  77. #define AD_COMP_0_SHIFT 0
  78. #define MAKE_AD(alpha, red, blue, green, size, c0, c1, c2, c3) \
  79. cpu_to_le32(AD_BYTE_F | (alpha << AD_ALPHA_C_SHIFT) | \
  80. (blue << AD_BLUE_C_SHIFT) | (green << AD_GREEN_C_SHIFT) | \
  81. (red << AD_RED_C_SHIFT) | (c3 << AD_COMP_3_SHIFT) | \
  82. (c2 << AD_COMP_2_SHIFT) | (c1 << AD_COMP_1_SHIFT) | \
  83. (c0 << AD_COMP_0_SHIFT) | (size << AD_PIXEL_S_SHIFT))
  84. /**
  85. * p1022ds_get_pixel_format: return the Area Descriptor for a given pixel depth
  86. *
  87. * The Area Descriptor is a 32-bit value that determine which bits in each
  88. * pixel are to be used for each color.
  89. */
  90. static u32 p1022ds_get_pixel_format(enum fsl_diu_monitor_port port,
  91. unsigned int bits_per_pixel)
  92. {
  93. switch (bits_per_pixel) {
  94. case 32:
  95. /* 0x88883316 */
  96. return MAKE_AD(3, 2, 0, 1, 3, 8, 8, 8, 8);
  97. case 24:
  98. /* 0x88082219 */
  99. return MAKE_AD(4, 0, 1, 2, 2, 0, 8, 8, 8);
  100. case 16:
  101. /* 0x65053118 */
  102. return MAKE_AD(4, 2, 1, 0, 1, 5, 6, 5, 0);
  103. default:
  104. pr_err("fsl-diu: unsupported pixel depth %u\n", bits_per_pixel);
  105. return 0;
  106. }
  107. }
  108. /**
  109. * p1022ds_set_gamma_table: update the gamma table, if necessary
  110. *
  111. * On some boards, the gamma table for some ports may need to be modified.
  112. * This is not the case on the P1022DS, so we do nothing.
  113. */
  114. static void p1022ds_set_gamma_table(enum fsl_diu_monitor_port port,
  115. char *gamma_table_base)
  116. {
  117. }
  118. /**
  119. * p1022ds_set_monitor_port: switch the output to a different monitor port
  120. *
  121. */
  122. static void p1022ds_set_monitor_port(enum fsl_diu_monitor_port port)
  123. {
  124. struct device_node *np;
  125. void __iomem *pixis;
  126. u8 __iomem *brdcfg1;
  127. np = of_find_compatible_node(NULL, NULL, "fsl,p1022ds-fpga");
  128. if (!np)
  129. /* older device trees used "fsl,p1022ds-pixis" */
  130. np = of_find_compatible_node(NULL, NULL, "fsl,p1022ds-pixis");
  131. if (!np) {
  132. pr_err("p1022ds: missing ngPIXIS node\n");
  133. return;
  134. }
  135. pixis = of_iomap(np, 0);
  136. if (!pixis) {
  137. pr_err("p1022ds: could not map ngPIXIS registers\n");
  138. return;
  139. }
  140. brdcfg1 = pixis + 9; /* BRDCFG1 is at offset 9 in the ngPIXIS */
  141. switch (port) {
  142. case FSL_DIU_PORT_DVI:
  143. printk(KERN_INFO "%s:%u\n", __func__, __LINE__);
  144. /* Enable the DVI port, disable the DFP and the backlight */
  145. clrsetbits_8(brdcfg1, PX_BRDCFG1_DFPEN | PX_BRDCFG1_BACKLIGHT,
  146. PX_BRDCFG1_DVIEN);
  147. break;
  148. case FSL_DIU_PORT_LVDS:
  149. printk(KERN_INFO "%s:%u\n", __func__, __LINE__);
  150. /* Enable the DFP port, disable the DVI and the backlight */
  151. clrsetbits_8(brdcfg1, PX_BRDCFG1_DVIEN | PX_BRDCFG1_BACKLIGHT,
  152. PX_BRDCFG1_DFPEN);
  153. break;
  154. default:
  155. pr_err("p1022ds: unsupported monitor port %i\n", port);
  156. }
  157. iounmap(pixis);
  158. }
  159. /**
  160. * p1022ds_set_pixel_clock: program the DIU's clock
  161. *
  162. * @pixclock: the wavelength, in picoseconds, of the clock
  163. */
  164. void p1022ds_set_pixel_clock(unsigned int pixclock)
  165. {
  166. struct device_node *guts_np = NULL;
  167. struct ccsr_guts_85xx __iomem *guts;
  168. unsigned long freq;
  169. u64 temp;
  170. u32 pxclk;
  171. /* Map the global utilities registers. */
  172. guts_np = of_find_compatible_node(NULL, NULL, "fsl,p1022-guts");
  173. if (!guts_np) {
  174. pr_err("p1022ds: missing global utilties device node\n");
  175. return;
  176. }
  177. guts = of_iomap(guts_np, 0);
  178. of_node_put(guts_np);
  179. if (!guts) {
  180. pr_err("p1022ds: could not map global utilties device\n");
  181. return;
  182. }
  183. /* Convert pixclock from a wavelength to a frequency */
  184. temp = 1000000000000ULL;
  185. do_div(temp, pixclock);
  186. freq = temp;
  187. /*
  188. * 'pxclk' is the ratio of the platform clock to the pixel clock.
  189. * This number is programmed into the CLKDVDR register, and the valid
  190. * range of values is 2-255.
  191. */
  192. pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq);
  193. pxclk = clamp_t(u32, pxclk, 2, 255);
  194. /* Disable the pixel clock, and set it to non-inverted and no delay */
  195. clrbits32(&guts->clkdvdr,
  196. CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK);
  197. /* Enable the clock and set the pxclk */
  198. setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16));
  199. iounmap(guts);
  200. }
  201. /**
  202. * p1022ds_valid_monitor_port: set the monitor port for sysfs
  203. */
  204. enum fsl_diu_monitor_port
  205. p1022ds_valid_monitor_port(enum fsl_diu_monitor_port port)
  206. {
  207. switch (port) {
  208. case FSL_DIU_PORT_DVI:
  209. case FSL_DIU_PORT_LVDS:
  210. return port;
  211. default:
  212. return FSL_DIU_PORT_DVI; /* Dual-link LVDS is not supported */
  213. }
  214. }
  215. #endif
  216. void __init p1022_ds_pic_init(void)
  217. {
  218. struct mpic *mpic = mpic_alloc(NULL, 0,
  219. MPIC_WANTS_RESET |
  220. MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS |
  221. MPIC_SINGLE_DEST_CPU,
  222. 0, 256, " OpenPIC ");
  223. BUG_ON(mpic == NULL);
  224. mpic_init(mpic);
  225. }
  226. /*
  227. * Setup the architecture
  228. */
  229. static void __init p1022_ds_setup_arch(void)
  230. {
  231. #ifdef CONFIG_PCI
  232. struct device_node *np;
  233. #endif
  234. dma_addr_t max = 0xffffffff;
  235. if (ppc_md.progress)
  236. ppc_md.progress("p1022_ds_setup_arch()", 0);
  237. #ifdef CONFIG_PCI
  238. for_each_compatible_node(np, "pci", "fsl,p1022-pcie") {
  239. struct resource rsrc;
  240. struct pci_controller *hose;
  241. of_address_to_resource(np, 0, &rsrc);
  242. if ((rsrc.start & 0xfffff) == 0x8000)
  243. fsl_add_bridge(np, 1);
  244. else
  245. fsl_add_bridge(np, 0);
  246. hose = pci_find_hose_for_OF_device(np);
  247. max = min(max, hose->dma_window_base_cur +
  248. hose->dma_window_size);
  249. }
  250. #endif
  251. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  252. diu_ops.get_pixel_format = p1022ds_get_pixel_format;
  253. diu_ops.set_gamma_table = p1022ds_set_gamma_table;
  254. diu_ops.set_monitor_port = p1022ds_set_monitor_port;
  255. diu_ops.set_pixel_clock = p1022ds_set_pixel_clock;
  256. diu_ops.valid_monitor_port = p1022ds_valid_monitor_port;
  257. #endif
  258. mpc85xx_smp_init();
  259. #ifdef CONFIG_SWIOTLB
  260. if (memblock_end_of_DRAM() > max) {
  261. ppc_swiotlb_enable = 1;
  262. set_pci_dma_ops(&swiotlb_dma_ops);
  263. ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_swiotlb;
  264. }
  265. #endif
  266. pr_info("Freescale P1022 DS reference board\n");
  267. }
  268. static struct of_device_id __initdata p1022_ds_ids[] = {
  269. /* So that the DMA channel nodes can be probed individually: */
  270. { .compatible = "fsl,eloplus-dma", },
  271. {},
  272. };
  273. static int __init p1022_ds_publish_devices(void)
  274. {
  275. mpc85xx_common_publish_devices();
  276. return of_platform_bus_probe(NULL, p1022_ds_ids, NULL);
  277. }
  278. machine_device_initcall(p1022_ds, p1022_ds_publish_devices);
  279. machine_arch_initcall(p1022_ds, swiotlb_setup_bus_notifier);
  280. /*
  281. * Called very early, device-tree isn't unflattened
  282. */
  283. static int __init p1022_ds_probe(void)
  284. {
  285. unsigned long root = of_get_flat_dt_root();
  286. return of_flat_dt_is_compatible(root, "fsl,p1022ds");
  287. }
  288. define_machine(p1022_ds) {
  289. .name = "P1022 DS",
  290. .probe = p1022_ds_probe,
  291. .setup_arch = p1022_ds_setup_arch,
  292. .init_IRQ = p1022_ds_pic_init,
  293. #ifdef CONFIG_PCI
  294. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  295. #endif
  296. .get_irq = mpic_get_irq,
  297. .restart = fsl_rstcr_restart,
  298. .calibrate_decr = generic_calibrate_decr,
  299. .progress = udbg_progress,
  300. };