p1022_ds.c 15 KB

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