2006-01-13 20:19:13 +03: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 20:19:13 +03:00
* This program is free software ; you can redistribute it and / or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation ; either version 2 of the License , or ( at your
* option ) any later version .
*/
# 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 02:24:23 +04:00
# include <linux/export.h>
2006-01-13 20:19:13 +03:00
# include <linux/device.h>
# include <linux/platform_device.h>
2009-02-19 19:02:23 +03:00
# include <linux/of.h>
2007-08-17 17:23:06 +04:00
# include <linux/of_platform.h>
2006-10-20 04:52:26 +04:00
# include <linux/phy.h>
2007-08-23 15:35:56 +04:00
# include <linux/spi/spi.h>
2006-01-13 20:19:13 +03:00
# include <linux/fsl_devices.h>
2006-09-21 17:26:34 +04:00
# include <linux/fs_enet_pd.h>
# include <linux/fs_uart_pd.h>
2016-07-29 02:07:18 +03:00
# include <linux/reboot.h>
2006-01-13 20:19:13 +03:00
2011-07-27 03:09:06 +04:00
# include <linux/atomic.h>
2006-01-13 20:19:13 +03:00
# include <asm/io.h>
# include <asm/irq.h>
2006-09-21 17:26:34 +04:00
# include <asm/time.h>
2006-01-13 20:19:13 +03:00
# include <asm/prom.h>
2009-08-14 20:13:53 +04:00
# include <asm/machdep.h>
2006-01-13 20:19:13 +03: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 17:54:29 +04:00
# include <asm/fsl_hcalls.h> /* For the Freescale hypervisor */
2006-01-13 20:19:13 +03:00
2006-09-21 22:38:05 +04:00
extern void init_fcc_ioports ( struct fs_platform_info * ) ;
2007-01-24 22:41:15 +03:00
extern void init_fec_ioports ( struct fs_platform_info * ) ;
extern void init_smc_ioports ( struct fs_uart_platform_info * ) ;
2006-01-13 20:19:13 +03: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 01:58:04 +03:00
if ( soc ) {
2007-08-20 20:38:12 +04:00
int size ;
2008-01-14 19:29:35 +03:00
u32 naddr ;
2012-12-01 03:35:02 +04:00
const __be32 * prop = of_get_property ( soc , " #address-cells " , & size ) ;
2006-09-21 17:26:34 +04:00
2008-01-14 19:29:35 +03:00
if ( prop & & size = = 4 )
2012-12-01 03:35:02 +04:00
naddr = be32_to_cpup ( prop ) ;
2008-01-14 19:29:35 +03:00
else
naddr = 2 ;
prop = of_get_property ( soc , " ranges " , & size ) ;
2006-09-21 17:26:34 +04:00
if ( prop )
2008-01-14 19:29:35 +03:00
immrbase = of_translate_address ( soc , prop + naddr ) ;
2006-01-13 20:19:13 +03:00
of_node_put ( soc ) ;
2007-08-20 20:38:12 +04:00
}
2006-01-13 20:19:13 +03:00
return immrbase ;
}
2006-01-24 01:58:04 +03:00
EXPORT_SYMBOL ( get_immrbase ) ;
2006-01-13 20:19:13 +03:00
2008-04-15 22:52:34 +04:00
u32 fsl_get_sys_freq ( void )
{
2016-10-29 17:27:14 +03:00
static u32 sysfreq = - 1 ;
2008-04-15 22:52:34 +04: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 17:27:14 +03:00
of_property_read_u32 ( soc , " clock-frequency " , & sysfreq ) ;
if ( sysfreq = = - 1 | | ! sysfreq )
of_property_read_u32 ( soc , " bus-frequency " , & sysfreq ) ;
2008-04-15 22:52:34 +04:00
of_node_put ( soc ) ;
return sysfreq ;
}
EXPORT_SYMBOL ( fsl_get_sys_freq ) ;
2017-08-08 14:58:46 +03:00
# if defined(CONFIG_CPM) || defined(CONFIG_QUICC_ENGINE)
2006-09-21 17:26:34 +04:00
u32 get_brgfreq ( void )
{
2016-10-29 17:28:25 +03:00
static u32 brgfreq = - 1 ;
2006-09-21 17:26:34 +04:00
struct device_node * node ;
if ( brgfreq ! = - 1 )
return brgfreq ;
2007-08-30 00:08:40 +04:00
node = of_find_compatible_node ( NULL , NULL , " fsl,cpm-brg " ) ;
2006-09-21 17:26:34 +04:00
if ( node ) {
2016-10-29 17:28:25 +03:00
of_property_read_u32 ( node , " clock-frequency " , & brgfreq ) ;
2007-08-30 00:08:40 +04:00
of_node_put ( node ) ;
return brgfreq ;
}
2006-09-21 17:26:34 +04:00
2007-08-30 00:08:40 +04: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-30 00:08:40 +04:00
if ( node ) {
2016-10-29 17:28:25 +03: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 20:38:12 +04:00
}
2006-09-21 17:26:34 +04:00
return brgfreq ;
}
EXPORT_SYMBOL ( get_brgfreq ) ;
u32 get_baudrate ( void )
{
2016-10-29 17:29:04 +03: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 17:29:04 +03: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 20:38:12 +04:00
}
2006-09-21 17:26:34 +04:00
return fs_baudrate ;
}
EXPORT_SYMBOL ( get_baudrate ) ;
# endif /* CONFIG_CPM2 */
2009-10-17 03:31:48 +04:00
# if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
2007-10-04 10:04:57 +04:00
static __be32 __iomem * rstcr ;
2016-07-29 02:07:18 +03: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 10:04:57 +04:00
static int __init setup_rstcr ( void )
{
struct device_node * np ;
2010-09-01 02:44:51 +04:00
2016-07-29 02:07:18 +03:00
static struct notifier_block restart_handler = {
. notifier_call = fsl_rstcr_restart ,
. priority = 128 ,
} ;
2010-09-01 02:44:51 +04: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 02:07:18 +03:00
if ( ! rstcr ) {
2010-09-01 02:44:51 +04:00
printk ( KERN_ERR " Error: reset control "
" register not mapped! \n " ) ;
2016-07-29 02:07:18 +03:00
} else {
register_restart_handler ( & restart_handler ) ;
}
2010-09-01 02:44:51 +04:00
break ;
}
}
2014-08-08 14:07:45 +04:00
of_node_put ( np ) ;
2010-09-01 02:44:51 +04:00
2007-10-04 10:04:57 +04:00
return 0 ;
}
arch_initcall ( setup_rstcr ) ;
# endif
2008-04-28 13:15:36 +04:00
# if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
2008-09-23 18:47:01 +04:00
struct platform_diu_data_ops diu_ops ;
2008-04-28 13:15:36 +04:00
EXPORT_SYMBOL ( diu_ops ) ;
# endif
2011-05-19 17:54:29 +04:00
2012-07-03 09:48:55 +04:00
# ifdef CONFIG_EPAPR_PARAVIRT
2011-05-19 17:54:29 +04: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 03:54:52 +03:00
void __noreturn fsl_hv_restart ( char * cmd )
2011-05-19 17:54:29 +04:00
{
pr_info ( " hv restart \n " ) ;
fh_partition_restart ( - 1 ) ;
2016-07-12 03:54:52 +03:00
while ( 1 ) ;
2011-05-19 17:54:29 +04:00
}
/*
* Halt the current partition
*
2014-10-13 18:01:09 +04:00
* This function should be assigned to the pm_power_off and ppc_md . halt
2011-05-19 17:54:29 +04:00
* function pointers , to shut down the partition when we ' re running under
* the Freescale hypervisor .
*/
2016-07-12 03:54:52 +03:00
void __noreturn fsl_hv_halt ( void )
2011-05-19 17:54:29 +04:00
{
pr_info ( " hv exit \n " ) ;
fh_partition_stop ( - 1 ) ;
2016-07-12 03:54:52 +03:00
while ( 1 ) ;
2011-05-19 17:54:29 +04:00
}
2012-07-03 09:48:55 +04:00
# endif