p1022_ds.c 9.6 KB

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