p1022_ds.c 9.1 KB

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