18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * P1022 RDK board specific routines 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright 2012 Freescale Semiconductor, Inc. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Author: Timur Tabi <timur@freescale.com> 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Based on p1022_ds.c 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * This file is licensed under the terms of the GNU General Public License 118c2ecf20Sopenharmony_ci * version 2. This program is licensed "as is" without any warranty of any 128c2ecf20Sopenharmony_ci * kind, whether express or implied. 138c2ecf20Sopenharmony_ci */ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/fsl/guts.h> 168c2ecf20Sopenharmony_ci#include <linux/pci.h> 178c2ecf20Sopenharmony_ci#include <linux/of_platform.h> 188c2ecf20Sopenharmony_ci#include <asm/div64.h> 198c2ecf20Sopenharmony_ci#include <asm/mpic.h> 208c2ecf20Sopenharmony_ci#include <asm/swiotlb.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#include <sysdev/fsl_soc.h> 238c2ecf20Sopenharmony_ci#include <sysdev/fsl_pci.h> 248c2ecf20Sopenharmony_ci#include <asm/udbg.h> 258c2ecf20Sopenharmony_ci#include "smp.h" 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#include "mpc85xx.h" 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/* DIU Pixel Clock bits of the CLKDVDR Global Utilities register */ 328c2ecf20Sopenharmony_ci#define CLKDVDR_PXCKEN 0x80000000 338c2ecf20Sopenharmony_ci#define CLKDVDR_PXCKINV 0x10000000 348c2ecf20Sopenharmony_ci#define CLKDVDR_PXCKDLY 0x06000000 358c2ecf20Sopenharmony_ci#define CLKDVDR_PXCLK_MASK 0x00FF0000 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/** 388c2ecf20Sopenharmony_ci * p1022rdk_set_pixel_clock: program the DIU's clock 398c2ecf20Sopenharmony_ci * 408c2ecf20Sopenharmony_ci * @pixclock: the wavelength, in picoseconds, of the clock 418c2ecf20Sopenharmony_ci */ 428c2ecf20Sopenharmony_civoid p1022rdk_set_pixel_clock(unsigned int pixclock) 438c2ecf20Sopenharmony_ci{ 448c2ecf20Sopenharmony_ci struct device_node *guts_np = NULL; 458c2ecf20Sopenharmony_ci struct ccsr_guts __iomem *guts; 468c2ecf20Sopenharmony_ci unsigned long freq; 478c2ecf20Sopenharmony_ci u64 temp; 488c2ecf20Sopenharmony_ci u32 pxclk; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci /* Map the global utilities registers. */ 518c2ecf20Sopenharmony_ci guts_np = of_find_compatible_node(NULL, NULL, "fsl,p1022-guts"); 528c2ecf20Sopenharmony_ci if (!guts_np) { 538c2ecf20Sopenharmony_ci pr_err("p1022rdk: missing global utilities device node\n"); 548c2ecf20Sopenharmony_ci return; 558c2ecf20Sopenharmony_ci } 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci guts = of_iomap(guts_np, 0); 588c2ecf20Sopenharmony_ci of_node_put(guts_np); 598c2ecf20Sopenharmony_ci if (!guts) { 608c2ecf20Sopenharmony_ci pr_err("p1022rdk: could not map global utilities device\n"); 618c2ecf20Sopenharmony_ci return; 628c2ecf20Sopenharmony_ci } 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci /* Convert pixclock from a wavelength to a frequency */ 658c2ecf20Sopenharmony_ci temp = 1000000000000ULL; 668c2ecf20Sopenharmony_ci do_div(temp, pixclock); 678c2ecf20Sopenharmony_ci freq = temp; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci /* 708c2ecf20Sopenharmony_ci * 'pxclk' is the ratio of the platform clock to the pixel clock. 718c2ecf20Sopenharmony_ci * This number is programmed into the CLKDVDR register, and the valid 728c2ecf20Sopenharmony_ci * range of values is 2-255. 738c2ecf20Sopenharmony_ci */ 748c2ecf20Sopenharmony_ci pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq); 758c2ecf20Sopenharmony_ci pxclk = clamp_t(u32, pxclk, 2, 255); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci /* Disable the pixel clock, and set it to non-inverted and no delay */ 788c2ecf20Sopenharmony_ci clrbits32(&guts->clkdvdr, 798c2ecf20Sopenharmony_ci CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK); 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci /* Enable the clock and set the pxclk */ 828c2ecf20Sopenharmony_ci setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16)); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci iounmap(guts); 858c2ecf20Sopenharmony_ci} 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci/** 888c2ecf20Sopenharmony_ci * p1022rdk_valid_monitor_port: set the monitor port for sysfs 898c2ecf20Sopenharmony_ci */ 908c2ecf20Sopenharmony_cienum fsl_diu_monitor_port 918c2ecf20Sopenharmony_cip1022rdk_valid_monitor_port(enum fsl_diu_monitor_port port) 928c2ecf20Sopenharmony_ci{ 938c2ecf20Sopenharmony_ci return FSL_DIU_PORT_DVI; 948c2ecf20Sopenharmony_ci} 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci#endif 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_civoid __init p1022_rdk_pic_init(void) 998c2ecf20Sopenharmony_ci{ 1008c2ecf20Sopenharmony_ci struct mpic *mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN | 1018c2ecf20Sopenharmony_ci MPIC_SINGLE_DEST_CPU, 1028c2ecf20Sopenharmony_ci 0, 256, " OpenPIC "); 1038c2ecf20Sopenharmony_ci BUG_ON(mpic == NULL); 1048c2ecf20Sopenharmony_ci mpic_init(mpic); 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci/* 1088c2ecf20Sopenharmony_ci * Setup the architecture 1098c2ecf20Sopenharmony_ci */ 1108c2ecf20Sopenharmony_cistatic void __init p1022_rdk_setup_arch(void) 1118c2ecf20Sopenharmony_ci{ 1128c2ecf20Sopenharmony_ci if (ppc_md.progress) 1138c2ecf20Sopenharmony_ci ppc_md.progress("p1022_rdk_setup_arch()", 0); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE) 1168c2ecf20Sopenharmony_ci diu_ops.set_pixel_clock = p1022rdk_set_pixel_clock; 1178c2ecf20Sopenharmony_ci diu_ops.valid_monitor_port = p1022rdk_valid_monitor_port; 1188c2ecf20Sopenharmony_ci#endif 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci mpc85xx_smp_init(); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci fsl_pci_assign_primary(); 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci swiotlb_detect_4g(); 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci pr_info("Freescale / iVeia P1022 RDK reference board\n"); 1278c2ecf20Sopenharmony_ci} 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cimachine_arch_initcall(p1022_rdk, mpc85xx_common_publish_devices); 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci/* 1328c2ecf20Sopenharmony_ci * Called very early, device-tree isn't unflattened 1338c2ecf20Sopenharmony_ci */ 1348c2ecf20Sopenharmony_cistatic int __init p1022_rdk_probe(void) 1358c2ecf20Sopenharmony_ci{ 1368c2ecf20Sopenharmony_ci return of_machine_is_compatible("fsl,p1022rdk"); 1378c2ecf20Sopenharmony_ci} 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_cidefine_machine(p1022_rdk) { 1408c2ecf20Sopenharmony_ci .name = "P1022 RDK", 1418c2ecf20Sopenharmony_ci .probe = p1022_rdk_probe, 1428c2ecf20Sopenharmony_ci .setup_arch = p1022_rdk_setup_arch, 1438c2ecf20Sopenharmony_ci .init_IRQ = p1022_rdk_pic_init, 1448c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI 1458c2ecf20Sopenharmony_ci .pcibios_fixup_bus = fsl_pcibios_fixup_bus, 1468c2ecf20Sopenharmony_ci .pcibios_fixup_phb = fsl_pcibios_fixup_phb, 1478c2ecf20Sopenharmony_ci#endif 1488c2ecf20Sopenharmony_ci .get_irq = mpic_get_irq, 1498c2ecf20Sopenharmony_ci .calibrate_decr = generic_calibrate_decr, 1508c2ecf20Sopenharmony_ci .progress = udbg_progress, 1518c2ecf20Sopenharmony_ci}; 152