1// SPDX-License-Identifier: GPL-2.0-only 2/* Copyright (c) 2013, The Linux Foundation. All rights reserved. 3 */ 4 5#include <linux/delay.h> 6#include <linux/err.h> 7#include <linux/init.h> 8#include <linux/kernel.h> 9#include <linux/io.h> 10#include <linux/of.h> 11#include <linux/platform_device.h> 12#include <linux/module.h> 13#include <linux/reboot.h> 14#include <linux/pm.h> 15 16static void __iomem *msm_ps_hold; 17 18static int do_msm_poweroff(struct sys_off_data *data) 19{ 20 writel(0, msm_ps_hold); 21 mdelay(10000); 22 23 return NOTIFY_DONE; 24} 25 26static int msm_restart_probe(struct platform_device *pdev) 27{ 28 msm_ps_hold = devm_platform_ioremap_resource(pdev, 0); 29 if (IS_ERR(msm_ps_hold)) 30 return PTR_ERR(msm_ps_hold); 31 32 devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_RESTART, 33 128, do_msm_poweroff, NULL); 34 35 devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_POWER_OFF, 36 SYS_OFF_PRIO_DEFAULT, do_msm_poweroff, 37 NULL); 38 39 return 0; 40} 41 42static const struct of_device_id of_msm_restart_match[] = { 43 { .compatible = "qcom,pshold", }, 44 {}, 45}; 46MODULE_DEVICE_TABLE(of, of_msm_restart_match); 47 48static struct platform_driver msm_restart_driver = { 49 .probe = msm_restart_probe, 50 .driver = { 51 .name = "msm-restart", 52 .of_match_table = of_match_ptr(of_msm_restart_match), 53 }, 54}; 55builtin_platform_driver(msm_restart_driver); 56