p1022_ds.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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 unsigned int p1022ds_get_pixel_format(unsigned int bits_per_pixel,
  88. int monitor_port)
  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(int monitor_port, char *gamma_table_base)
  112. {
  113. }
  114. /**
  115. * p1022ds_set_monitor_port: switch the output to a different monitor port
  116. *
  117. */
  118. static void p1022ds_set_monitor_port(int monitor_port)
  119. {
  120. struct device_node *pixis_node;
  121. u8 __iomem *brdcfg1;
  122. pixis_node = of_find_compatible_node(NULL, NULL, "fsl,p1022ds-pixis");
  123. if (!pixis_node) {
  124. pr_err("p1022ds: missing ngPIXIS node\n");
  125. return;
  126. }
  127. brdcfg1 = of_iomap(pixis_node, 0);
  128. if (!brdcfg1) {
  129. pr_err("p1022ds: could not map ngPIXIS registers\n");
  130. return;
  131. }
  132. brdcfg1 += 9; /* BRDCFG1 is at offset 9 in the ngPIXIS */
  133. switch (monitor_port) {
  134. case 0: /* DVI */
  135. /* Enable the DVI port, disable the DFP and the backlight */
  136. clrsetbits_8(brdcfg1, PX_BRDCFG1_DFPEN | PX_BRDCFG1_BACKLIGHT,
  137. PX_BRDCFG1_DVIEN);
  138. break;
  139. case 1: /* Single link LVDS */
  140. /* Enable the DFP port, disable the DVI and the backlight */
  141. clrsetbits_8(brdcfg1, PX_BRDCFG1_DVIEN | PX_BRDCFG1_BACKLIGHT,
  142. PX_BRDCFG1_DFPEN);
  143. break;
  144. default:
  145. pr_err("p1022ds: unsupported monitor port %i\n", monitor_port);
  146. }
  147. }
  148. /**
  149. * p1022ds_set_pixel_clock: program the DIU's clock
  150. *
  151. * @pixclock: the wavelength, in picoseconds, of the clock
  152. */
  153. void p1022ds_set_pixel_clock(unsigned int pixclock)
  154. {
  155. struct device_node *guts_np = NULL;
  156. struct ccsr_guts_85xx __iomem *guts;
  157. unsigned long freq;
  158. u64 temp;
  159. u32 pxclk;
  160. /* Map the global utilities registers. */
  161. guts_np = of_find_compatible_node(NULL, NULL, "fsl,p1022-guts");
  162. if (!guts_np) {
  163. pr_err("p1022ds: missing global utilties device node\n");
  164. return;
  165. }
  166. guts = of_iomap(guts_np, 0);
  167. of_node_put(guts_np);
  168. if (!guts) {
  169. pr_err("p1022ds: could not map global utilties device\n");
  170. return;
  171. }
  172. /* Convert pixclock from a wavelength to a frequency */
  173. temp = 1000000000000ULL;
  174. do_div(temp, pixclock);
  175. freq = temp;
  176. /* pixclk is the ratio of the platform clock to the pixel clock */
  177. pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq);
  178. /* Disable the pixel clock, and set it to non-inverted and no delay */
  179. clrbits32(&guts->clkdvdr,
  180. CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK);
  181. /* Enable the clock and set the pxclk */
  182. setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16));
  183. }
  184. /**
  185. * p1022ds_show_monitor_port: show the current monitor
  186. *
  187. * This function returns a string indicating whether the current monitor is
  188. * set to DVI or LVDS.
  189. */
  190. ssize_t p1022ds_show_monitor_port(int monitor_port, char *buf)
  191. {
  192. return sprintf(buf, "%c0 - DVI\n%c1 - Single link LVDS\n",
  193. monitor_port == 0 ? '*' : ' ', monitor_port == 1 ? '*' : ' ');
  194. }
  195. /**
  196. * p1022ds_set_sysfs_monitor_port: set the monitor port for sysfs
  197. */
  198. int p1022ds_set_sysfs_monitor_port(int val)
  199. {
  200. return val < 2 ? val : 0;
  201. }
  202. #endif
  203. void __init p1022_ds_pic_init(void)
  204. {
  205. struct mpic *mpic;
  206. struct resource r;
  207. struct device_node *np;
  208. np = of_find_node_by_type(NULL, "open-pic");
  209. if (!np) {
  210. pr_err("Could not find open-pic node\n");
  211. return;
  212. }
  213. if (of_address_to_resource(np, 0, &r)) {
  214. pr_err("Failed to map mpic register space\n");
  215. of_node_put(np);
  216. return;
  217. }
  218. mpic = mpic_alloc(np, r.start,
  219. MPIC_PRIMARY | 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. of_node_put(np);
  225. mpic_init(mpic);
  226. }
  227. #ifdef CONFIG_SMP
  228. void __init mpc85xx_smp_init(void);
  229. #endif
  230. /*
  231. * Setup the architecture
  232. */
  233. static void __init p1022_ds_setup_arch(void)
  234. {
  235. #ifdef CONFIG_PCI
  236. struct device_node *np;
  237. #endif
  238. dma_addr_t max = 0xffffffff;
  239. if (ppc_md.progress)
  240. ppc_md.progress("p1022_ds_setup_arch()", 0);
  241. #ifdef CONFIG_PCI
  242. for_each_compatible_node(np, "pci", "fsl,p1022-pcie") {
  243. struct resource rsrc;
  244. struct pci_controller *hose;
  245. of_address_to_resource(np, 0, &rsrc);
  246. if ((rsrc.start & 0xfffff) == 0x8000)
  247. fsl_add_bridge(np, 1);
  248. else
  249. fsl_add_bridge(np, 0);
  250. hose = pci_find_hose_for_OF_device(np);
  251. max = min(max, hose->dma_window_base_cur +
  252. hose->dma_window_size);
  253. }
  254. #endif
  255. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  256. diu_ops.get_pixel_format = p1022ds_get_pixel_format;
  257. diu_ops.set_gamma_table = p1022ds_set_gamma_table;
  258. diu_ops.set_monitor_port = p1022ds_set_monitor_port;
  259. diu_ops.set_pixel_clock = p1022ds_set_pixel_clock;
  260. diu_ops.show_monitor_port = p1022ds_show_monitor_port;
  261. diu_ops.set_sysfs_monitor_port = p1022ds_set_sysfs_monitor_port;
  262. #endif
  263. #ifdef CONFIG_SMP
  264. mpc85xx_smp_init();
  265. #endif
  266. #ifdef CONFIG_SWIOTLB
  267. if (memblock_end_of_DRAM() > max) {
  268. ppc_swiotlb_enable = 1;
  269. set_pci_dma_ops(&swiotlb_dma_ops);
  270. ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_swiotlb;
  271. }
  272. #endif
  273. pr_info("Freescale P1022 DS reference board\n");
  274. }
  275. static struct of_device_id __initdata p1022_ds_ids[] = {
  276. { .type = "soc", },
  277. { .compatible = "soc", },
  278. { .compatible = "simple-bus", },
  279. { .compatible = "gianfar", },
  280. /* So that the DMA channel nodes can be probed individually: */
  281. { .compatible = "fsl,eloplus-dma", },
  282. {},
  283. };
  284. static int __init p1022_ds_publish_devices(void)
  285. {
  286. return of_platform_bus_probe(NULL, p1022_ds_ids, NULL);
  287. }
  288. machine_device_initcall(p1022_ds, p1022_ds_publish_devices);
  289. machine_arch_initcall(p1022_ds, swiotlb_setup_bus_notifier);
  290. /*
  291. * Called very early, device-tree isn't unflattened
  292. */
  293. static int __init p1022_ds_probe(void)
  294. {
  295. unsigned long root = of_get_flat_dt_root();
  296. return of_flat_dt_is_compatible(root, "fsl,p1022ds");
  297. }
  298. define_machine(p1022_ds) {
  299. .name = "P1022 DS",
  300. .probe = p1022_ds_probe,
  301. .setup_arch = p1022_ds_setup_arch,
  302. .init_IRQ = p1022_ds_pic_init,
  303. #ifdef CONFIG_PCI
  304. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  305. #endif
  306. .get_irq = mpic_get_irq,
  307. .restart = fsl_rstcr_restart,
  308. .calibrate_decr = generic_calibrate_decr,
  309. .progress = udbg_progress,
  310. };