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