134f84b5bSTimur Tabi /*
234f84b5bSTimur Tabi  * P1022 RDK board specific routines
334f84b5bSTimur Tabi  *
434f84b5bSTimur Tabi  * Copyright 2012 Freescale Semiconductor, Inc.
534f84b5bSTimur Tabi  *
634f84b5bSTimur Tabi  * Author: Timur Tabi <timur@freescale.com>
734f84b5bSTimur Tabi  *
834f84b5bSTimur Tabi  * Based on p1022_ds.c
934f84b5bSTimur Tabi  *
1034f84b5bSTimur Tabi  * This file is licensed under the terms of the GNU General Public License
1134f84b5bSTimur Tabi  * version 2.  This program is licensed "as is" without any warranty of any
1234f84b5bSTimur Tabi  * kind, whether express or implied.
1334f84b5bSTimur Tabi  */
1434f84b5bSTimur Tabi 
1594848654SScott Wood #include <linux/fsl/guts.h>
1634f84b5bSTimur Tabi #include <linux/pci.h>
17*81d7cac4SRob Herring #include <linux/of.h>
18e6f6390aSChristophe Leroy #include <linux/of_address.h>
1934f84b5bSTimur Tabi #include <asm/div64.h>
2034f84b5bSTimur Tabi #include <asm/mpic.h>
2134f84b5bSTimur Tabi #include <asm/swiotlb.h>
2234f84b5bSTimur Tabi 
2334f84b5bSTimur Tabi #include <sysdev/fsl_soc.h>
2434f84b5bSTimur Tabi #include <sysdev/fsl_pci.h>
2534f84b5bSTimur Tabi #include <asm/udbg.h>
2634f84b5bSTimur Tabi #include "smp.h"
2734f84b5bSTimur Tabi 
2834f84b5bSTimur Tabi #include "mpc85xx.h"
2934f84b5bSTimur Tabi 
3034f84b5bSTimur Tabi #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
3134f84b5bSTimur Tabi 
3234f84b5bSTimur Tabi /* DIU Pixel Clock bits of the CLKDVDR Global Utilities register */
3334f84b5bSTimur Tabi #define CLKDVDR_PXCKEN		0x80000000
3434f84b5bSTimur Tabi #define CLKDVDR_PXCKINV		0x10000000
3534f84b5bSTimur Tabi #define CLKDVDR_PXCKDLY		0x06000000
3634f84b5bSTimur Tabi #define CLKDVDR_PXCLK_MASK	0x00FF0000
3734f84b5bSTimur Tabi 
3834f84b5bSTimur Tabi /**
3934f84b5bSTimur Tabi  * p1022rdk_set_pixel_clock: program the DIU's clock
4034f84b5bSTimur Tabi  *
4134f84b5bSTimur Tabi  * @pixclock: the wavelength, in picoseconds, of the clock
4234f84b5bSTimur Tabi  */
p1022rdk_set_pixel_clock(unsigned int pixclock)4334f84b5bSTimur Tabi void p1022rdk_set_pixel_clock(unsigned int pixclock)
4434f84b5bSTimur Tabi {
4534f84b5bSTimur Tabi 	struct device_node *guts_np = NULL;
4634f84b5bSTimur Tabi 	struct ccsr_guts __iomem *guts;
4734f84b5bSTimur Tabi 	unsigned long freq;
4834f84b5bSTimur Tabi 	u64 temp;
4934f84b5bSTimur Tabi 	u32 pxclk;
5034f84b5bSTimur Tabi 
5134f84b5bSTimur Tabi 	/* Map the global utilities registers. */
5234f84b5bSTimur Tabi 	guts_np = of_find_compatible_node(NULL, NULL, "fsl,p1022-guts");
5334f84b5bSTimur Tabi 	if (!guts_np) {
54d939be3aSMasanari Iida 		pr_err("p1022rdk: missing global utilities device node\n");
5534f84b5bSTimur Tabi 		return;
5634f84b5bSTimur Tabi 	}
5734f84b5bSTimur Tabi 
5834f84b5bSTimur Tabi 	guts = of_iomap(guts_np, 0);
5934f84b5bSTimur Tabi 	of_node_put(guts_np);
6034f84b5bSTimur Tabi 	if (!guts) {
61d939be3aSMasanari Iida 		pr_err("p1022rdk: could not map global utilities device\n");
6234f84b5bSTimur Tabi 		return;
6334f84b5bSTimur Tabi 	}
6434f84b5bSTimur Tabi 
6534f84b5bSTimur Tabi 	/* Convert pixclock from a wavelength to a frequency */
6634f84b5bSTimur Tabi 	temp = 1000000000000ULL;
6734f84b5bSTimur Tabi 	do_div(temp, pixclock);
6834f84b5bSTimur Tabi 	freq = temp;
6934f84b5bSTimur Tabi 
7034f84b5bSTimur Tabi 	/*
7134f84b5bSTimur Tabi 	 * 'pxclk' is the ratio of the platform clock to the pixel clock.
7234f84b5bSTimur Tabi 	 * This number is programmed into the CLKDVDR register, and the valid
7334f84b5bSTimur Tabi 	 * range of values is 2-255.
7434f84b5bSTimur Tabi 	 */
7534f84b5bSTimur Tabi 	pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq);
7634f84b5bSTimur Tabi 	pxclk = clamp_t(u32, pxclk, 2, 255);
7734f84b5bSTimur Tabi 
7834f84b5bSTimur Tabi 	/* Disable the pixel clock, and set it to non-inverted and no delay */
7934f84b5bSTimur Tabi 	clrbits32(&guts->clkdvdr,
8034f84b5bSTimur Tabi 		  CLKDVDR_PXCKEN | CLKDVDR_PXCKDLY | CLKDVDR_PXCLK_MASK);
8134f84b5bSTimur Tabi 
8234f84b5bSTimur Tabi 	/* Enable the clock and set the pxclk */
8334f84b5bSTimur Tabi 	setbits32(&guts->clkdvdr, CLKDVDR_PXCKEN | (pxclk << 16));
8434f84b5bSTimur Tabi 
8534f84b5bSTimur Tabi 	iounmap(guts);
8634f84b5bSTimur Tabi }
8734f84b5bSTimur Tabi 
8834f84b5bSTimur Tabi /**
8934f84b5bSTimur Tabi  * p1022rdk_valid_monitor_port: set the monitor port for sysfs
9034f84b5bSTimur Tabi  */
9134f84b5bSTimur Tabi enum fsl_diu_monitor_port
p1022rdk_valid_monitor_port(enum fsl_diu_monitor_port port)9234f84b5bSTimur Tabi p1022rdk_valid_monitor_port(enum fsl_diu_monitor_port port)
9334f84b5bSTimur Tabi {
9434f84b5bSTimur Tabi 	return FSL_DIU_PORT_DVI;
9534f84b5bSTimur Tabi }
9634f84b5bSTimur Tabi 
9734f84b5bSTimur Tabi #endif
9834f84b5bSTimur Tabi 
p1022_rdk_pic_init(void)9934f84b5bSTimur Tabi void __init p1022_rdk_pic_init(void)
10034f84b5bSTimur Tabi {
10134f84b5bSTimur Tabi 	struct mpic *mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN |
10234f84b5bSTimur Tabi 		MPIC_SINGLE_DEST_CPU,
10334f84b5bSTimur Tabi 		0, 256, " OpenPIC  ");
10434f84b5bSTimur Tabi 	BUG_ON(mpic == NULL);
10534f84b5bSTimur Tabi 	mpic_init(mpic);
10634f84b5bSTimur Tabi }
10734f84b5bSTimur Tabi 
10834f84b5bSTimur Tabi /*
10934f84b5bSTimur Tabi  * Setup the architecture
11034f84b5bSTimur Tabi  */
p1022_rdk_setup_arch(void)11134f84b5bSTimur Tabi static void __init p1022_rdk_setup_arch(void)
11234f84b5bSTimur Tabi {
11334f84b5bSTimur Tabi 	if (ppc_md.progress)
11434f84b5bSTimur Tabi 		ppc_md.progress("p1022_rdk_setup_arch()", 0);
11534f84b5bSTimur Tabi 
11634f84b5bSTimur Tabi #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
11734f84b5bSTimur Tabi 	diu_ops.set_pixel_clock		= p1022rdk_set_pixel_clock;
11834f84b5bSTimur Tabi 	diu_ops.valid_monitor_port	= p1022rdk_valid_monitor_port;
11934f84b5bSTimur Tabi #endif
12034f84b5bSTimur Tabi 
12134f84b5bSTimur Tabi 	mpc85xx_smp_init();
12234f84b5bSTimur Tabi 
123905e75c4SJia Hongtao 	fsl_pci_assign_primary();
124905e75c4SJia Hongtao 
125905e75c4SJia Hongtao 	swiotlb_detect_4g();
12634f84b5bSTimur Tabi 
12734f84b5bSTimur Tabi 	pr_info("Freescale / iVeia P1022 RDK reference board\n");
12834f84b5bSTimur Tabi }
12934f84b5bSTimur Tabi 
130905e75c4SJia Hongtao machine_arch_initcall(p1022_rdk, mpc85xx_common_publish_devices);
13134f84b5bSTimur Tabi 
define_machine(p1022_rdk)13234f84b5bSTimur Tabi define_machine(p1022_rdk) {
13334f84b5bSTimur Tabi 	.name			= "P1022 RDK",
1341c96fcdeSChristophe Leroy 	.compatible		= "fsl,p1022rdk",
13534f84b5bSTimur Tabi 	.setup_arch		= p1022_rdk_setup_arch,
13634f84b5bSTimur Tabi 	.init_IRQ		= p1022_rdk_pic_init,
13734f84b5bSTimur Tabi #ifdef CONFIG_PCI
13834f84b5bSTimur Tabi 	.pcibios_fixup_bus	= fsl_pcibios_fixup_bus,
13948b16180SWang Dongsheng 	.pcibios_fixup_phb      = fsl_pcibios_fixup_phb,
14034f84b5bSTimur Tabi #endif
14134f84b5bSTimur Tabi 	.get_irq		= mpic_get_irq,
14234f84b5bSTimur Tabi 	.progress		= udbg_progress,
14334f84b5bSTimur Tabi };
144