2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2006-01-14 01:19:13 +08:00
|
|
|
/*
|
|
|
|
* FSL SoC setup code
|
|
|
|
*
|
|
|
|
* Maintained by Kumar Gala (see MAINTAINERS for contact information)
|
|
|
|
*
|
2006-09-21 21:26:34 +08:00
|
|
|
* 2006 (c) MontaVista Software, Inc.
|
|
|
|
* Vitaly Bordug <vbordug@ru.mvista.com>
|
2006-01-14 01:19:13 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/stddef.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/irq.h>
|
2011-07-23 06:24:23 +08:00
|
|
|
#include <linux/export.h>
|
2006-01-14 01:19:13 +08:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/platform_device.h>
|
2009-02-20 00:02:23 +08:00
|
|
|
#include <linux/of.h>
|
2007-08-17 21:23:06 +08:00
|
|
|
#include <linux/of_platform.h>
|
2006-10-20 08:52:26 +08:00
|
|
|
#include <linux/phy.h>
|
2007-08-23 19:35:56 +08:00
|
|
|
#include <linux/spi/spi.h>
|
2006-01-14 01:19:13 +08:00
|
|
|
#include <linux/fsl_devices.h>
|
2006-09-21 21:26:34 +08:00
|
|
|
#include <linux/fs_enet_pd.h>
|
|
|
|
#include <linux/fs_uart_pd.h>
|
2016-07-29 07:07:18 +08:00
|
|
|
#include <linux/reboot.h>
|
2006-01-14 01:19:13 +08:00
|
|
|
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2006-01-14 01:19:13 +08:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/irq.h>
|
2006-09-21 21:26:34 +08:00
|
|
|
#include <asm/time.h>
|
2006-01-14 01:19:13 +08:00
|
|
|
#include <asm/prom.h>
|
2009-08-15 00:13:53 +08:00
|
|
|
#include <asm/machdep.h>
|
2006-01-14 01:19:13 +08:00
|
|
|
#include <sysdev/fsl_soc.h>
|
|
|
|
#include <mm/mmu_decl.h>
|
2006-09-21 21:26:34 +08:00
|
|
|
#include <asm/cpm2.h>
|
2011-05-19 21:54:29 +08:00
|
|
|
#include <asm/fsl_hcalls.h> /* For the Freescale hypervisor */
|
2006-01-14 01:19:13 +08:00
|
|
|
|
2006-09-22 02:38:05 +08:00
|
|
|
extern void init_fcc_ioports(struct fs_platform_info*);
|
2007-01-25 03:41:15 +08:00
|
|
|
extern void init_fec_ioports(struct fs_platform_info*);
|
|
|
|
extern void init_smc_ioports(struct fs_uart_platform_info*);
|
2006-01-14 01:19:13 +08:00
|
|
|
static phys_addr_t immrbase = -1;
|
|
|
|
|
|
|
|
phys_addr_t get_immrbase(void)
|
|
|
|
{
|
|
|
|
struct device_node *soc;
|
|
|
|
|
|
|
|
if (immrbase != -1)
|
|
|
|
return immrbase;
|
|
|
|
|
|
|
|
soc = of_find_node_by_type(NULL, "soc");
|
2006-01-24 06:58:04 +08:00
|
|
|
if (soc) {
|
2007-08-21 00:38:12 +08:00
|
|
|
int size;
|
2008-01-15 00:29:35 +08:00
|
|
|
u32 naddr;
|
2012-12-01 07:35:02 +08:00
|
|
|
const __be32 *prop = of_get_property(soc, "#address-cells", &size);
|
2006-09-21 21:26:34 +08:00
|
|
|
|
2008-01-15 00:29:35 +08:00
|
|
|
if (prop && size == 4)
|
2012-12-01 07:35:02 +08:00
|
|
|
naddr = be32_to_cpup(prop);
|
2008-01-15 00:29:35 +08:00
|
|
|
else
|
|
|
|
naddr = 2;
|
|
|
|
|
|
|
|
prop = of_get_property(soc, "ranges", &size);
|
2006-09-21 21:26:34 +08:00
|
|
|
if (prop)
|
2008-01-15 00:29:35 +08:00
|
|
|
immrbase = of_translate_address(soc, prop + naddr);
|
|
|
|
|
2006-01-14 01:19:13 +08:00
|
|
|
of_node_put(soc);
|
2007-08-21 00:38:12 +08:00
|
|
|
}
|
2006-01-14 01:19:13 +08:00
|
|
|
|
|
|
|
return immrbase;
|
|
|
|
}
|
|
|
|
|
2006-01-24 06:58:04 +08:00
|
|
|
EXPORT_SYMBOL(get_immrbase);
|
2006-01-14 01:19:13 +08:00
|
|
|
|
2008-04-16 02:52:34 +08:00
|
|
|
u32 fsl_get_sys_freq(void)
|
|
|
|
{
|
2016-10-29 22:27:14 +08:00
|
|
|
static u32 sysfreq = -1;
|
2008-04-16 02:52:34 +08:00
|
|
|
struct device_node *soc;
|
|
|
|
|
|
|
|
if (sysfreq != -1)
|
|
|
|
return sysfreq;
|
|
|
|
|
|
|
|
soc = of_find_node_by_type(NULL, "soc");
|
|
|
|
if (!soc)
|
|
|
|
return -1;
|
|
|
|
|
2016-10-29 22:27:14 +08:00
|
|
|
of_property_read_u32(soc, "clock-frequency", &sysfreq);
|
|
|
|
if (sysfreq == -1 || !sysfreq)
|
|
|
|
of_property_read_u32(soc, "bus-frequency", &sysfreq);
|
2008-04-16 02:52:34 +08:00
|
|
|
|
|
|
|
of_node_put(soc);
|
|
|
|
return sysfreq;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(fsl_get_sys_freq);
|
|
|
|
|
2017-08-08 19:58:46 +08:00
|
|
|
#if defined(CONFIG_CPM) || defined(CONFIG_QUICC_ENGINE)
|
2006-09-21 21:26:34 +08:00
|
|
|
|
|
|
|
u32 get_brgfreq(void)
|
|
|
|
{
|
2016-10-29 22:28:25 +08:00
|
|
|
static u32 brgfreq = -1;
|
2006-09-21 21:26:34 +08:00
|
|
|
struct device_node *node;
|
|
|
|
|
|
|
|
if (brgfreq != -1)
|
|
|
|
return brgfreq;
|
|
|
|
|
2007-08-30 04:08:40 +08:00
|
|
|
node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
|
2006-09-21 21:26:34 +08:00
|
|
|
if (node) {
|
2016-10-29 22:28:25 +08:00
|
|
|
of_property_read_u32(node, "clock-frequency", &brgfreq);
|
2007-08-30 04:08:40 +08:00
|
|
|
of_node_put(node);
|
|
|
|
return brgfreq;
|
|
|
|
}
|
2006-09-21 21:26:34 +08:00
|
|
|
|
2007-08-30 04:08:40 +08:00
|
|
|
/* Legacy device binding -- will go away when no users are left. */
|
|
|
|
node = of_find_node_by_type(NULL, "cpm");
|
2008-01-24 23:40:03 +08:00
|
|
|
if (!node)
|
|
|
|
node = of_find_compatible_node(NULL, NULL, "fsl,qe");
|
|
|
|
if (!node)
|
|
|
|
node = of_find_node_by_type(NULL, "qe");
|
|
|
|
|
2007-08-30 04:08:40 +08:00
|
|
|
if (node) {
|
2016-10-29 22:28:25 +08:00
|
|
|
of_property_read_u32(node, "brg-frequency", &brgfreq);
|
|
|
|
if (brgfreq == -1 || !brgfreq)
|
|
|
|
if (!of_property_read_u32(node, "bus-frequency",
|
|
|
|
&brgfreq))
|
|
|
|
brgfreq /= 2;
|
2006-09-21 21:26:34 +08:00
|
|
|
of_node_put(node);
|
2007-08-21 00:38:12 +08:00
|
|
|
}
|
2006-09-21 21:26:34 +08:00
|
|
|
|
|
|
|
return brgfreq;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(get_brgfreq);
|
|
|
|
|
|
|
|
u32 get_baudrate(void)
|
|
|
|
{
|
2016-10-29 22:29:04 +08:00
|
|
|
static u32 fs_baudrate = -1;
|
2006-09-21 21:26:34 +08:00
|
|
|
struct device_node *node;
|
|
|
|
|
|
|
|
if (fs_baudrate != -1)
|
|
|
|
return fs_baudrate;
|
|
|
|
|
|
|
|
node = of_find_node_by_type(NULL, "serial");
|
|
|
|
if (node) {
|
2016-10-29 22:29:04 +08:00
|
|
|
of_property_read_u32(node, "current-speed", &fs_baudrate);
|
2006-09-21 21:26:34 +08:00
|
|
|
of_node_put(node);
|
2007-08-21 00:38:12 +08:00
|
|
|
}
|
2006-09-21 21:26:34 +08:00
|
|
|
|
|
|
|
return fs_baudrate;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(get_baudrate);
|
|
|
|
#endif /* CONFIG_CPM2 */
|
|
|
|
|
2009-10-17 07:31:48 +08:00
|
|
|
#if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
|
2007-10-04 14:04:57 +08:00
|
|
|
static __be32 __iomem *rstcr;
|
|
|
|
|
2016-07-29 07:07:18 +08:00
|
|
|
static int fsl_rstcr_restart(struct notifier_block *this,
|
|
|
|
unsigned long mode, void *cmd)
|
|
|
|
{
|
|
|
|
local_irq_disable();
|
|
|
|
/* set reset control register */
|
|
|
|
out_be32(rstcr, 0x2); /* HRESET_REQ */
|
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
2007-10-04 14:04:57 +08:00
|
|
|
static int __init setup_rstcr(void)
|
|
|
|
{
|
|
|
|
struct device_node *np;
|
2010-09-01 06:44:51 +08:00
|
|
|
|
2016-07-29 07:07:18 +08:00
|
|
|
static struct notifier_block restart_handler = {
|
|
|
|
.notifier_call = fsl_rstcr_restart,
|
|
|
|
.priority = 128,
|
|
|
|
};
|
|
|
|
|
2010-09-01 06:44:51 +08:00
|
|
|
for_each_node_by_name(np, "global-utilities") {
|
|
|
|
if ((of_get_property(np, "fsl,has-rstcr", NULL))) {
|
|
|
|
rstcr = of_iomap(np, 0) + 0xb0;
|
2016-07-29 07:07:18 +08:00
|
|
|
if (!rstcr) {
|
2010-09-01 06:44:51 +08:00
|
|
|
printk (KERN_ERR "Error: reset control "
|
|
|
|
"register not mapped!\n");
|
2016-07-29 07:07:18 +08:00
|
|
|
} else {
|
|
|
|
register_restart_handler(&restart_handler);
|
|
|
|
}
|
2010-09-01 06:44:51 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-08 18:07:45 +08:00
|
|
|
of_node_put(np);
|
2010-09-01 06:44:51 +08:00
|
|
|
|
2007-10-04 14:04:57 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
arch_initcall(setup_rstcr);
|
|
|
|
|
|
|
|
#endif
|
2008-04-28 17:15:36 +08:00
|
|
|
|
|
|
|
#if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
|
2008-09-23 22:47:01 +08:00
|
|
|
struct platform_diu_data_ops diu_ops;
|
2008-04-28 17:15:36 +08:00
|
|
|
EXPORT_SYMBOL(diu_ops);
|
|
|
|
#endif
|
2011-05-19 21:54:29 +08:00
|
|
|
|
2012-07-03 13:48:55 +08:00
|
|
|
#ifdef CONFIG_EPAPR_PARAVIRT
|
2011-05-19 21:54:29 +08:00
|
|
|
/*
|
|
|
|
* Restart the current partition
|
|
|
|
*
|
|
|
|
* This function should be assigned to the ppc_md.restart function pointer,
|
|
|
|
* to initiate a partition restart when we're running under the Freescale
|
|
|
|
* hypervisor.
|
|
|
|
*/
|
2016-07-12 08:54:52 +08:00
|
|
|
void __noreturn fsl_hv_restart(char *cmd)
|
2011-05-19 21:54:29 +08:00
|
|
|
{
|
|
|
|
pr_info("hv restart\n");
|
|
|
|
fh_partition_restart(-1);
|
2016-07-12 08:54:52 +08:00
|
|
|
while (1) ;
|
2011-05-19 21:54:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Halt the current partition
|
|
|
|
*
|
2014-10-13 22:01:09 +08:00
|
|
|
* This function should be assigned to the pm_power_off and ppc_md.halt
|
2011-05-19 21:54:29 +08:00
|
|
|
* function pointers, to shut down the partition when we're running under
|
|
|
|
* the Freescale hypervisor.
|
|
|
|
*/
|
2016-07-12 08:54:52 +08:00
|
|
|
void __noreturn fsl_hv_halt(void)
|
2011-05-19 21:54:29 +08:00
|
|
|
{
|
|
|
|
pr_info("hv exit\n");
|
|
|
|
fh_partition_stop(-1);
|
2016-07-12 08:54:52 +08:00
|
|
|
while (1) ;
|
2011-05-19 21:54:29 +08:00
|
|
|
}
|
2012-07-03 13:48:55 +08:00
|
|
|
#endif
|