summaryrefslogtreecommitdiff
path: root/drivers/power/reset/imx-snvs-poweroff.c
blob: 525f8cb397a73b66b42396a6bf1dfb46bcaafd89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Power off driver for i.mx6
 * Copyright (c) 2014, FREESCALE CORPORATION.  All rights reserved.
 *
 * based on msm-poweroff.c
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <linux/err.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>

static void __iomem *snvs_base;

static void do_imx_poweroff(void)
{
	u32 value = readl(snvs_base);

	/* set TOP and DP_EN bit */
	writel(value | 0x60, snvs_base);
}

static int imx_poweroff_probe(struct platform_device *pdev)
{
	snvs_base = of_iomap(pdev->dev.of_node, 0);
	if (!snvs_base) {
		dev_err(&pdev->dev, "failed to get memory\n");
		return -ENODEV;
	}

	/*
	 * The Apalis/Colibri iMX6 modules cannot use PMIC_ON_REQ to shutdown
	 * the PMIC or the module could only be restarted by power cycling
	 * if the SNVS is supplied by a backup battery.
	 * compare with pm-imx6.c, imx6_stop_mode_poweroff()
	 */
	if (!of_machine_is_compatible("toradex,colibri_imx6dl") &&
	    !of_machine_is_compatible("toradex,apalis_imx6q"))
		pm_power_off = do_imx_poweroff;

	return 0;
}

static const struct of_device_id of_imx_poweroff_match[] = {
	{ .compatible = "fsl,sec-v4.0-poweroff", },
	{},
};
MODULE_DEVICE_TABLE(of, of_imx_poweroff_match);

static struct platform_driver imx_poweroff_driver = {
	.probe = imx_poweroff_probe,
	.driver = {
		.name = "imx-snvs-poweroff",
		.of_match_table = of_match_ptr(of_imx_poweroff_match),
	},
};

static int __init imx_poweroff_init(void)
{
	return platform_driver_register(&imx_poweroff_driver);
}
device_initcall(imx_poweroff_init);