1/*
2 * arch/powerpc/platforms/83xx/mpc834x_mds.c
3 *
4 * MPC834x MDS board specific routines
5 *
6 * Maintainer: Kumar Gala <galak@kernel.crashing.org>
7 *
8 * This program is free software; you can redistribute  it and/or modify it
9 * under  the terms of  the GNU General  Public License as published by the
10 * Free Software Foundation;  either version 2 of the  License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/stddef.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/errno.h>
18#include <linux/reboot.h>
19#include <linux/pci.h>
20#include <linux/kdev_t.h>
21#include <linux/major.h>
22#include <linux/console.h>
23#include <linux/delay.h>
24#include <linux/seq_file.h>
25#include <linux/root_dev.h>
26
27#include <asm/system.h>
28#include <asm/atomic.h>
29#include <asm/time.h>
30#include <asm/io.h>
31#include <asm/machdep.h>
32#include <asm/ipic.h>
33#include <asm/bootinfo.h>
34#include <asm/irq.h>
35#include <asm/prom.h>
36#include <asm/udbg.h>
37#include <sysdev/fsl_soc.h>
38
39#include "mpc83xx.h"
40
41#ifndef CONFIG_PCI
42unsigned long isa_io_base = 0;
43unsigned long isa_mem_base = 0;
44#endif
45
46#define BCSR5_INT_USB		0x02
47/* Note: This is only for PB, not for PB+PIB
48 * On PB only port0 is connected using ULPI */
49static int mpc834x_usb_cfg(void)
50{
51	unsigned long sccr, sicrl;
52	void __iomem *immap;
53	void __iomem *bcsr_regs = NULL;
54	u8 bcsr5;
55	struct device_node *np = NULL;
56	int port0_is_dr = 0;
57
58	if ((np = of_find_compatible_node(NULL, "usb", "fsl-usb2-dr")) != NULL)
59		port0_is_dr = 1;
60	if ((np = of_find_compatible_node(NULL, "usb", "fsl-usb2-mph")) != NULL){
61		if (port0_is_dr) {
62			printk(KERN_WARNING
63				"There is only one USB port on PB board! \n");
64			return -1;
65		} else if (!port0_is_dr)
66			/* No usb port enabled */
67			return -1;
68	}
69
70	immap = ioremap(get_immrbase(), 0x1000);
71	if (!immap)
72		return -1;
73
74	/* Configure clock */
75	sccr = in_be32(immap + MPC83XX_SCCR_OFFS);
76	if (port0_is_dr)
77		sccr |= MPC83XX_SCCR_USB_DRCM_11;  /* 1:3 */
78	else
79		sccr |= MPC83XX_SCCR_USB_MPHCM_11; /* 1:3 */
80	out_be32(immap + MPC83XX_SCCR_OFFS, sccr);
81
82	/* Configure Pin */
83	sicrl = in_be32(immap + MPC83XX_SICRL_OFFS);
84	/* set port0 only */
85	if (port0_is_dr)
86		sicrl |= MPC83XX_SICRL_USB0;
87	else
88		sicrl &= ~(MPC83XX_SICRL_USB0);
89	out_be32(immap + MPC83XX_SICRL_OFFS, sicrl);
90
91	iounmap(immap);
92
93	/* Map BCSR area */
94	np = of_find_node_by_name(NULL, "bcsr");
95	if (np != 0) {
96		struct resource res;
97
98		of_address_to_resource(np, 0, &res);
99		bcsr_regs = ioremap(res.start, res.end - res.start + 1);
100		of_node_put(np);
101	}
102	if (!bcsr_regs)
103		return -1;
104
105	/*
106	 * if Processor Board is plugged into PIB board,
107	 * force to use the PHY on Processor Board
108	 */
109	bcsr5 = in_8(bcsr_regs + 5);
110	if (!(bcsr5 & BCSR5_INT_USB))
111		out_8(bcsr_regs + 5, (bcsr5 | BCSR5_INT_USB));
112	iounmap(bcsr_regs);
113	return 0;
114}
115
116/* ************************************************************************
117 *
118 * Setup the architecture
119 *
120 */
121static void __init mpc834x_mds_setup_arch(void)
122{
123#ifdef CONFIG_PCI
124	struct device_node *np;
125#endif
126
127	if (ppc_md.progress)
128		ppc_md.progress("mpc834x_mds_setup_arch()", 0);
129
130#ifdef CONFIG_PCI
131	for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
132		add_bridge(np);
133
134	ppc_md.pci_exclude_device = mpc83xx_exclude_device;
135#endif
136
137	mpc834x_usb_cfg();
138}
139
140static void __init mpc834x_mds_init_IRQ(void)
141{
142	struct device_node *np;
143
144	np = of_find_node_by_type(NULL, "ipic");
145	if (!np)
146		return;
147
148	ipic_init(np, 0);
149
150	/* Initialize the default interrupt mapping priorities,
151	 * in case the boot rom changed something on us.
152	 */
153	ipic_set_default_priority();
154}
155
156#if defined(CONFIG_I2C_MPC) && defined(CONFIG_SENSORS_DS1374)
157extern ulong ds1374_get_rtc_time(void);
158extern int ds1374_set_rtc_time(ulong);
159
160static int __init mpc834x_rtc_hookup(void)
161{
162	struct timespec tv;
163
164	if (!machine_is(mpc834x_mds))
165		return 0;
166
167	ppc_md.get_rtc_time = ds1374_get_rtc_time;
168	ppc_md.set_rtc_time = ds1374_set_rtc_time;
169
170	tv.tv_nsec = 0;
171	tv.tv_sec = (ppc_md.get_rtc_time) ();
172	do_settimeofday(&tv);
173
174	return 0;
175}
176
177late_initcall(mpc834x_rtc_hookup);
178#endif
179
180/*
181 * Called very early, MMU is off, device-tree isn't unflattened
182 */
183static int __init mpc834x_mds_probe(void)
184{
185        unsigned long root = of_get_flat_dt_root();
186
187        return of_flat_dt_is_compatible(root, "MPC834xMDS");
188}
189
190define_machine(mpc834x_mds) {
191	.name			= "MPC834x MDS",
192	.probe			= mpc834x_mds_probe,
193	.setup_arch		= mpc834x_mds_setup_arch,
194	.init_IRQ		= mpc834x_mds_init_IRQ,
195	.get_irq		= ipic_get_irq,
196	.restart		= mpc83xx_restart,
197	.time_init		= mpc83xx_time_init,
198	.calibrate_decr		= generic_calibrate_decr,
199	.progress		= udbg_progress,
200};
201