p1022_ds.c 9.3 KB

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