p1022_ds.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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. #define PMUXCR_ELBCDIU_MASK 0xc0000000
  32. #define PMUXCR_ELBCDIU_NOR16 0x80000000
  33. #define PMUXCR_ELBCDIU_DIU 0x40000000
  34. /*
  35. * Board-specific initialization of the DIU. This code should probably be
  36. * executed when the DIU is opened, rather than in arch code, but the DIU
  37. * driver does not have a mechanism for this (yet).
  38. *
  39. * This is especially problematic on the P1022DS because the local bus (eLBC)
  40. * and the DIU video signals share the same pins, which means that enabling the
  41. * DIU will disable access to NOR flash.
  42. */
  43. /* DIU Pixel Clock bits of the CLKDVDR Global Utilities register */
  44. #define CLKDVDR_PXCKEN 0x80000000
  45. #define CLKDVDR_PXCKINV 0x10000000
  46. #define CLKDVDR_PXCKDLY 0x06000000
  47. #define CLKDVDR_PXCLK_MASK 0x00FF0000
  48. /* Some ngPIXIS register definitions */
  49. #define PX_CTL 3
  50. #define PX_BRDCFG0 8
  51. #define PX_BRDCFG1 9
  52. #define PX_BRDCFG0_ELBC_SPI_MASK 0xc0
  53. #define PX_BRDCFG0_ELBC_SPI_ELBC 0x00
  54. #define PX_BRDCFG0_ELBC_SPI_NULL 0xc0
  55. #define PX_BRDCFG0_ELBC_DIU 0x02
  56. #define PX_BRDCFG1_DVIEN 0x80
  57. #define PX_BRDCFG1_DFPEN 0x40
  58. #define PX_BRDCFG1_BACKLIGHT 0x20
  59. #define PX_BRDCFG1_DDCEN 0x10
  60. #define PX_CTL_ALTACC 0x80
  61. /*
  62. * DIU Area Descriptor
  63. *
  64. * Note that we need to byte-swap the value before it's written to the AD
  65. * register. So even though the registers don't look like they're in the same
  66. * bit positions as they are on the MPC8610, the same value is written to the
  67. * AD register on the MPC8610 and on the P1022.
  68. */
  69. #define AD_BYTE_F 0x10000000
  70. #define AD_ALPHA_C_MASK 0x0E000000
  71. #define AD_ALPHA_C_SHIFT 25
  72. #define AD_BLUE_C_MASK 0x01800000
  73. #define AD_BLUE_C_SHIFT 23
  74. #define AD_GREEN_C_MASK 0x00600000
  75. #define AD_GREEN_C_SHIFT 21
  76. #define AD_RED_C_MASK 0x00180000
  77. #define AD_RED_C_SHIFT 19
  78. #define AD_PALETTE 0x00040000
  79. #define AD_PIXEL_S_MASK 0x00030000
  80. #define AD_PIXEL_S_SHIFT 16
  81. #define AD_COMP_3_MASK 0x0000F000
  82. #define AD_COMP_3_SHIFT 12
  83. #define AD_COMP_2_MASK 0x00000F00
  84. #define AD_COMP_2_SHIFT 8
  85. #define AD_COMP_1_MASK 0x000000F0
  86. #define AD_COMP_1_SHIFT 4
  87. #define AD_COMP_0_MASK 0x0000000F
  88. #define AD_COMP_0_SHIFT 0
  89. #define MAKE_AD(alpha, red, blue, green, size, c0, c1, c2, c3) \
  90. cpu_to_le32(AD_BYTE_F | (alpha << AD_ALPHA_C_SHIFT) | \
  91. (blue << AD_BLUE_C_SHIFT) | (green << AD_GREEN_C_SHIFT) | \
  92. (red << AD_RED_C_SHIFT) | (c3 << AD_COMP_3_SHIFT) | \
  93. (c2 << AD_COMP_2_SHIFT) | (c1 << AD_COMP_1_SHIFT) | \
  94. (c0 << AD_COMP_0_SHIFT) | (size << AD_PIXEL_S_SHIFT))
  95. /**
  96. * p1022ds_get_pixel_format: return the Area Descriptor for a given pixel depth
  97. *
  98. * The Area Descriptor is a 32-bit value that determine which bits in each
  99. * pixel are to be used for each color.
  100. */
  101. static u32 p1022ds_get_pixel_format(enum fsl_diu_monitor_port port,
  102. unsigned int bits_per_pixel)
  103. {
  104. switch (bits_per_pixel) {
  105. case 32:
  106. /* 0x88883316 */
  107. return MAKE_AD(3, 2, 0, 1, 3, 8, 8, 8, 8);
  108. case 24:
  109. /* 0x88082219 */
  110. return MAKE_AD(4, 0, 1, 2, 2, 0, 8, 8, 8);
  111. case 16:
  112. /* 0x65053118 */
  113. return MAKE_AD(4, 2, 1, 0, 1, 5, 6, 5, 0);
  114. default:
  115. pr_err("fsl-diu: unsupported pixel depth %u\n", bits_per_pixel);
  116. return 0;
  117. }
  118. }
  119. /**
  120. * p1022ds_set_gamma_table: update the gamma table, if necessary
  121. *
  122. * On some boards, the gamma table for some ports may need to be modified.
  123. * This is not the case on the P1022DS, so we do nothing.
  124. */
  125. static void p1022ds_set_gamma_table(enum fsl_diu_monitor_port port,
  126. char *gamma_table_base)
  127. {
  128. }
  129. /**
  130. * p1022ds_set_monitor_port: switch the output to a different monitor port
  131. *
  132. */
  133. static void p1022ds_set_monitor_port(enum fsl_diu_monitor_port port)
  134. {
  135. struct device_node *guts_node;
  136. struct device_node *indirect_node = NULL;
  137. struct ccsr_guts_85xx __iomem *guts;
  138. u8 __iomem *lbc_lcs0_ba = NULL;
  139. u8 __iomem *lbc_lcs1_ba = NULL;
  140. u8 b;
  141. /* Map the global utilities registers. */
  142. guts_node = of_find_compatible_node(NULL, NULL, "fsl,p1022-guts");
  143. if (!guts_node) {
  144. pr_err("p1022ds: missing global utilties device node\n");
  145. return;
  146. }
  147. guts = of_iomap(guts_node, 0);
  148. if (!guts) {
  149. pr_err("p1022ds: could not map global utilties device\n");
  150. goto exit;
  151. }
  152. indirect_node = of_find_compatible_node(NULL, NULL,
  153. "fsl,p1022ds-indirect-pixis");
  154. if (!indirect_node) {
  155. pr_err("p1022ds: missing pixis indirect mode node\n");
  156. goto exit;
  157. }
  158. lbc_lcs0_ba = of_iomap(indirect_node, 0);
  159. if (!lbc_lcs0_ba) {
  160. pr_err("p1022ds: could not map localbus chip select 0\n");
  161. goto exit;
  162. }
  163. lbc_lcs1_ba = of_iomap(indirect_node, 1);
  164. if (!lbc_lcs1_ba) {
  165. pr_err("p1022ds: could not map localbus chip select 1\n");
  166. goto exit;
  167. }
  168. /* Make sure we're in indirect mode first. */
  169. if ((in_be32(&guts->pmuxcr) & PMUXCR_ELBCDIU_MASK) !=
  170. PMUXCR_ELBCDIU_DIU) {
  171. struct device_node *pixis_node;
  172. void __iomem *pixis;
  173. pixis_node =
  174. of_find_compatible_node(NULL, NULL, "fsl,p1022ds-fpga");
  175. if (!pixis_node) {
  176. pr_err("p1022ds: missing pixis node\n");
  177. goto exit;
  178. }
  179. pixis = of_iomap(pixis_node, 0);
  180. of_node_put(pixis_node);
  181. if (!pixis) {
  182. pr_err("p1022ds: could not map pixis registers\n");
  183. goto exit;
  184. }
  185. /* Enable indirect PIXIS mode. */
  186. setbits8(pixis + PX_CTL, PX_CTL_ALTACC);
  187. iounmap(pixis);
  188. /* Switch the board mux to the DIU */
  189. out_8(lbc_lcs0_ba, PX_BRDCFG0); /* BRDCFG0 */
  190. b = in_8(lbc_lcs1_ba);
  191. b |= PX_BRDCFG0_ELBC_DIU;
  192. out_8(lbc_lcs1_ba, b);
  193. /* Set the chip mux to DIU mode. */
  194. clrsetbits_be32(&guts->pmuxcr, PMUXCR_ELBCDIU_MASK,
  195. PMUXCR_ELBCDIU_DIU);
  196. in_be32(&guts->pmuxcr);
  197. }
  198. switch (port) {
  199. case FSL_DIU_PORT_DVI:
  200. /* Enable the DVI port, disable the DFP and the backlight */
  201. out_8(lbc_lcs0_ba, PX_BRDCFG1);
  202. b = in_8(lbc_lcs1_ba);
  203. b &= ~(PX_BRDCFG1_DFPEN | PX_BRDCFG1_BACKLIGHT);
  204. b |= PX_BRDCFG1_DVIEN;
  205. out_8(lbc_lcs1_ba, b);
  206. break;
  207. case FSL_DIU_PORT_LVDS:
  208. /*
  209. * LVDS also needs backlight enabled, otherwise the display
  210. * will be blank.
  211. */
  212. /* Enable the DFP port, disable the DVI and the backlight */
  213. out_8(lbc_lcs0_ba, PX_BRDCFG1);
  214. b = in_8(lbc_lcs1_ba);
  215. b &= ~PX_BRDCFG1_DVIEN;
  216. b |= PX_BRDCFG1_DFPEN | PX_BRDCFG1_BACKLIGHT;
  217. out_8(lbc_lcs1_ba, b);
  218. break;
  219. default:
  220. pr_err("p1022ds: unsupported monitor port %i\n", port);
  221. }
  222. exit:
  223. if (lbc_lcs1_ba)
  224. iounmap(lbc_lcs1_ba);
  225. if (lbc_lcs0_ba)
  226. iounmap(lbc_lcs0_ba);
  227. if (guts)
  228. iounmap(guts);
  229. of_node_put(indirect_node);
  230. of_node_put(guts_node);
  231. }
  232. /**
  233. * p1022ds_set_pixel_clock: program the DIU's clock
  234. *
  235. * @pixclock: the wavelength, in picoseconds, of the clock
  236. */
  237. void p1022ds_set_pixel_clock(unsigned int pixclock)
  238. {
  239. struct device_node *guts_np = NULL;
  240. struct ccsr_guts_85xx __iomem *guts;
  241. unsigned long freq;
  242. u64 temp;
  243. u32 pxclk;
  244. /* Map the global utilities registers. */
  245. guts_np = of_find_compatible_node(NULL, NULL, "fsl,p1022-guts");
  246. if (!guts_np) {
  247. pr_err("p1022ds: missing global utilties device node\n");
  248. return;
  249. }
  250. guts = of_iomap(guts_np, 0);
  251. of_node_put(guts_np);
  252. if (!guts) {
  253. pr_err("p1022ds: could not map global utilties device\n");
  254. return;
  255. }
  256. /* Convert pixclock from a wavelength to a frequency */
  257. temp = 1000000000000ULL;
  258. do_div(temp, pixclock);
  259. freq = temp;
  260. /*
  261. * 'pxclk' is the ratio of the platform clock to the pixel clock.
  262. * This number is programmed into the CLKDVDR register, and the valid
  263. * range of values is 2-255.
  264. */
  265. pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq);
  266. pxclk = clamp_t(u32, pxclk, 2, 255);
  267. /* Disable the pixel clock, and set it to non-inverted and no delay */
  268. clrbits32(&guts->clkdvdr,
  269. CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK);
  270. /* Enable the clock and set the pxclk */
  271. setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16));
  272. iounmap(guts);
  273. }
  274. /**
  275. * p1022ds_valid_monitor_port: set the monitor port for sysfs
  276. */
  277. enum fsl_diu_monitor_port
  278. p1022ds_valid_monitor_port(enum fsl_diu_monitor_port port)
  279. {
  280. switch (port) {
  281. case FSL_DIU_PORT_DVI:
  282. case FSL_DIU_PORT_LVDS:
  283. return port;
  284. default:
  285. return FSL_DIU_PORT_DVI; /* Dual-link LVDS is not supported */
  286. }
  287. }
  288. #endif
  289. void __init p1022_ds_pic_init(void)
  290. {
  291. struct mpic *mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN |
  292. MPIC_SINGLE_DEST_CPU,
  293. 0, 256, " OpenPIC ");
  294. BUG_ON(mpic == NULL);
  295. mpic_init(mpic);
  296. }
  297. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  298. /*
  299. * Disables a node in the device tree.
  300. *
  301. * This function is called before kmalloc() is available, so the 'new' object
  302. * should be allocated in the global area. The easiest way is to do that is
  303. * to allocate one static local variable for each call to this function.
  304. */
  305. static void __init disable_one_node(struct device_node *np, struct property *new)
  306. {
  307. struct property *old;
  308. old = of_find_property(np, new->name, NULL);
  309. if (old)
  310. prom_update_property(np, new, old);
  311. else
  312. prom_add_property(np, new);
  313. }
  314. /* TRUE if there is a "video=fslfb" command-line parameter. */
  315. static bool fslfb;
  316. /*
  317. * Search for a "video=fslfb" command-line parameter, and set 'fslfb' to
  318. * true if we find it.
  319. *
  320. * We need to use early_param() instead of __setup() because the normal
  321. * __setup() gets called to late. However, early_param() gets called very
  322. * early, before the device tree is unflattened, so all we can do now is set a
  323. * global variable. Later on, p1022_ds_setup_arch() will use that variable
  324. * to determine if we need to update the device tree.
  325. */
  326. static int __init early_video_setup(char *options)
  327. {
  328. fslfb = (strncmp(options, "fslfb:", 6) == 0);
  329. return 0;
  330. }
  331. early_param("video", early_video_setup);
  332. #endif
  333. /*
  334. * Setup the architecture
  335. */
  336. static void __init p1022_ds_setup_arch(void)
  337. {
  338. #ifdef CONFIG_PCI
  339. struct device_node *np;
  340. #endif
  341. dma_addr_t max = 0xffffffff;
  342. if (ppc_md.progress)
  343. ppc_md.progress("p1022_ds_setup_arch()", 0);
  344. #ifdef CONFIG_PCI
  345. for_each_compatible_node(np, "pci", "fsl,p1022-pcie") {
  346. struct resource rsrc;
  347. struct pci_controller *hose;
  348. of_address_to_resource(np, 0, &rsrc);
  349. if ((rsrc.start & 0xfffff) == 0x8000)
  350. fsl_add_bridge(np, 1);
  351. else
  352. fsl_add_bridge(np, 0);
  353. hose = pci_find_hose_for_OF_device(np);
  354. max = min(max, hose->dma_window_base_cur +
  355. hose->dma_window_size);
  356. }
  357. #endif
  358. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  359. diu_ops.get_pixel_format = p1022ds_get_pixel_format;
  360. diu_ops.set_gamma_table = p1022ds_set_gamma_table;
  361. diu_ops.set_monitor_port = p1022ds_set_monitor_port;
  362. diu_ops.set_pixel_clock = p1022ds_set_pixel_clock;
  363. diu_ops.valid_monitor_port = p1022ds_valid_monitor_port;
  364. /*
  365. * Disable the NOR flash node if there is video=fslfb... command-line
  366. * parameter. When the DIU is active, NOR flash is unavailable, so we
  367. * have to disable the node before the MTD driver loads.
  368. */
  369. if (fslfb) {
  370. struct device_node *np =
  371. of_find_compatible_node(NULL, NULL, "fsl,p1022-elbc");
  372. if (np) {
  373. np = of_find_compatible_node(np, NULL, "cfi-flash");
  374. if (np) {
  375. static struct property nor_status = {
  376. .name = "status",
  377. .value = "disabled",
  378. .length = sizeof("disabled"),
  379. };
  380. pr_info("p1022ds: disabling %s node",
  381. np->full_name);
  382. disable_one_node(np, &nor_status);
  383. of_node_put(np);
  384. }
  385. }
  386. }
  387. #endif
  388. mpc85xx_smp_init();
  389. #ifdef CONFIG_SWIOTLB
  390. if (memblock_end_of_DRAM() > max) {
  391. ppc_swiotlb_enable = 1;
  392. set_pci_dma_ops(&swiotlb_dma_ops);
  393. ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_swiotlb;
  394. }
  395. #endif
  396. pr_info("Freescale P1022 DS reference board\n");
  397. }
  398. static struct of_device_id __initdata p1022_ds_ids[] = {
  399. /* So that the DMA channel nodes can be probed individually: */
  400. { .compatible = "fsl,eloplus-dma", },
  401. {},
  402. };
  403. static int __init p1022_ds_publish_devices(void)
  404. {
  405. mpc85xx_common_publish_devices();
  406. return of_platform_bus_probe(NULL, p1022_ds_ids, NULL);
  407. }
  408. machine_device_initcall(p1022_ds, p1022_ds_publish_devices);
  409. machine_arch_initcall(p1022_ds, swiotlb_setup_bus_notifier);
  410. /*
  411. * Called very early, device-tree isn't unflattened
  412. */
  413. static int __init p1022_ds_probe(void)
  414. {
  415. unsigned long root = of_get_flat_dt_root();
  416. return of_flat_dt_is_compatible(root, "fsl,p1022ds");
  417. }
  418. define_machine(p1022_ds) {
  419. .name = "P1022 DS",
  420. .probe = p1022_ds_probe,
  421. .setup_arch = p1022_ds_setup_arch,
  422. .init_IRQ = p1022_ds_pic_init,
  423. #ifdef CONFIG_PCI
  424. .pcibios_fixup_bus = fsl_pcibios_fixup_bus,
  425. #endif
  426. .get_irq = mpic_get_irq,
  427. .restart = fsl_rstcr_restart,
  428. .calibrate_decr = generic_calibrate_decr,
  429. .progress = udbg_progress,
  430. };