2019-06-04 10:11:33 +02:00
// SPDX-License-Identifier: GPL-2.0-only
2015-07-15 11:25:58 +08:00
/*
* ZTE zx296702 SoC reset code
*
* Copyright ( c ) 2015 Linaro Ltd .
*
* Author : Jun Nie < jun . nie @ linaro . org >
*/
# include <linux/delay.h>
# include <linux/io.h>
# include <linux/module.h>
# include <linux/notifier.h>
# include <linux/of_address.h>
# include <linux/platform_device.h>
# include <linux/reboot.h>
static void __iomem * base ;
static void __iomem * pcu_base ;
static int zx_restart_handler ( struct notifier_block * this ,
unsigned long mode , void * cmd )
{
writel_relaxed ( 1 , base + 0xb0 ) ;
writel_relaxed ( 1 , pcu_base + 0x34 ) ;
mdelay ( 50 ) ;
pr_emerg ( " Unable to restart system \n " ) ;
return NOTIFY_DONE ;
}
static struct notifier_block zx_restart_nb = {
. notifier_call = zx_restart_handler ,
. priority = 128 ,
} ;
static int zx_reboot_probe ( struct platform_device * pdev )
{
struct device_node * np = pdev - > dev . of_node ;
int err ;
base = of_iomap ( np , 0 ) ;
if ( ! base ) {
WARN ( 1 , " failed to map base address " ) ;
return - ENODEV ;
}
np = of_find_compatible_node ( NULL , NULL , " zte,zx296702-pcu " ) ;
pcu_base = of_iomap ( np , 0 ) ;
2018-06-03 01:22:05 +03:00
of_node_put ( np ) ;
2015-07-15 11:25:58 +08:00
if ( ! pcu_base ) {
iounmap ( base ) ;
WARN ( 1 , " failed to map pcu_base address " ) ;
return - ENODEV ;
}
err = register_restart_handler ( & zx_restart_nb ) ;
2016-09-14 16:35:31 +05:30
if ( err ) {
iounmap ( base ) ;
iounmap ( pcu_base ) ;
2015-07-15 11:25:58 +08:00
dev_err ( & pdev - > dev , " Register restart handler failed(err=%d) \n " ,
err ) ;
2016-09-14 16:35:31 +05:30
}
2015-07-15 11:25:58 +08:00
return err ;
}
static const struct of_device_id zx_reboot_of_match [ ] = {
{ . compatible = " zte,sysctrl " } ,
{ }
} ;
2016-10-17 15:36:15 -03:00
MODULE_DEVICE_TABLE ( of , zx_reboot_of_match ) ;
2015-07-15 11:25:58 +08:00
static struct platform_driver zx_reboot_driver = {
. probe = zx_reboot_probe ,
. driver = {
. name = " zx-reboot " ,
. of_match_table = zx_reboot_of_match ,
} ,
} ;
module_platform_driver ( zx_reboot_driver ) ;
2017-11-20 12:58:27 -08:00
MODULE_DESCRIPTION ( " ZTE SoCs reset driver " ) ;
MODULE_AUTHOR ( " Jun Nie <jun.nie@linaro.org> " ) ;
MODULE_LICENSE ( " GPL v2 " ) ;