Linux Audio

Check our new training course

Loading...
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * Power off driver for ams AS3722 device.
 4 *
 5 * Copyright (c) 2013, NVIDIA CORPORATION.  All rights reserved.
 6 *
 7 * Author: Laxman Dewangan <ldewangan@nvidia.com>
 8 */
 9
10#include <linux/mfd/as3722.h>
11#include <linux/module.h>
12#include <linux/of.h>
 
13#include <linux/platform_device.h>
14#include <linux/reboot.h>
15#include <linux/slab.h>
16
17struct as3722_poweroff {
18	struct device *dev;
19	struct as3722 *as3722;
20};
21
22static int as3722_pm_power_off(struct sys_off_data *data)
 
 
23{
24	struct as3722_poweroff *as3722_pm_poweroff = data->cb_data;
25	int ret;
26
 
 
 
 
 
27	ret = as3722_update_bits(as3722_pm_poweroff->as3722,
28		AS3722_RESET_CONTROL_REG, AS3722_POWER_OFF, AS3722_POWER_OFF);
29	if (ret < 0)
30		dev_err(as3722_pm_poweroff->dev,
31			"RESET_CONTROL_REG update failed, %d\n", ret);
32
33	return NOTIFY_DONE;
34}
35
36static int as3722_poweroff_probe(struct platform_device *pdev)
37{
38	struct as3722_poweroff *as3722_poweroff;
39	struct device_node *np = pdev->dev.parent->of_node;
40
41	if (!np)
42		return -EINVAL;
43
44	if (!of_property_read_bool(np, "ams,system-power-controller"))
45		return 0;
46
47	as3722_poweroff = devm_kzalloc(&pdev->dev, sizeof(*as3722_poweroff),
48				GFP_KERNEL);
49	if (!as3722_poweroff)
50		return -ENOMEM;
51
52	as3722_poweroff->as3722 = dev_get_drvdata(pdev->dev.parent);
53	as3722_poweroff->dev = &pdev->dev;
 
 
 
54
55	return devm_register_sys_off_handler(as3722_poweroff->dev,
56					     SYS_OFF_MODE_POWER_OFF,
57					     SYS_OFF_PRIO_DEFAULT,
58					     as3722_pm_power_off,
59					     as3722_poweroff);
 
 
 
60
61	return 0;
62}
63
64static struct platform_driver as3722_poweroff_driver = {
65	.driver = {
66		.name = "as3722-power-off",
67	},
68	.probe = as3722_poweroff_probe,
 
69};
70
71module_platform_driver(as3722_poweroff_driver);
72
73MODULE_DESCRIPTION("Power off driver for ams AS3722 PMIC Device");
74MODULE_ALIAS("platform:as3722-power-off");
75MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
v5.4
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * Power off driver for ams AS3722 device.
 4 *
 5 * Copyright (c) 2013, NVIDIA CORPORATION.  All rights reserved.
 6 *
 7 * Author: Laxman Dewangan <ldewangan@nvidia.com>
 8 */
 9
10#include <linux/mfd/as3722.h>
11#include <linux/module.h>
12#include <linux/of.h>
13#include <linux/of_device.h>
14#include <linux/platform_device.h>
 
15#include <linux/slab.h>
16
17struct as3722_poweroff {
18	struct device *dev;
19	struct as3722 *as3722;
20};
21
22static struct as3722_poweroff *as3722_pm_poweroff;
23
24static void as3722_pm_power_off(void)
25{
 
26	int ret;
27
28	if (!as3722_pm_poweroff) {
29		pr_err("AS3722 poweroff is not initialised\n");
30		return;
31	}
32
33	ret = as3722_update_bits(as3722_pm_poweroff->as3722,
34		AS3722_RESET_CONTROL_REG, AS3722_POWER_OFF, AS3722_POWER_OFF);
35	if (ret < 0)
36		dev_err(as3722_pm_poweroff->dev,
37			"RESET_CONTROL_REG update failed, %d\n", ret);
 
 
38}
39
40static int as3722_poweroff_probe(struct platform_device *pdev)
41{
42	struct as3722_poweroff *as3722_poweroff;
43	struct device_node *np = pdev->dev.parent->of_node;
44
45	if (!np)
46		return -EINVAL;
47
48	if (!of_property_read_bool(np, "ams,system-power-controller"))
49		return 0;
50
51	as3722_poweroff = devm_kzalloc(&pdev->dev, sizeof(*as3722_poweroff),
52				GFP_KERNEL);
53	if (!as3722_poweroff)
54		return -ENOMEM;
55
56	as3722_poweroff->as3722 = dev_get_drvdata(pdev->dev.parent);
57	as3722_poweroff->dev = &pdev->dev;
58	as3722_pm_poweroff = as3722_poweroff;
59	if (!pm_power_off)
60		pm_power_off = as3722_pm_power_off;
61
62	return 0;
63}
64
65static int as3722_poweroff_remove(struct platform_device *pdev)
66{
67	if (pm_power_off == as3722_pm_power_off)
68		pm_power_off = NULL;
69	as3722_pm_poweroff = NULL;
70
71	return 0;
72}
73
74static struct platform_driver as3722_poweroff_driver = {
75	.driver = {
76		.name = "as3722-power-off",
77	},
78	.probe = as3722_poweroff_probe,
79	.remove = as3722_poweroff_remove,
80};
81
82module_platform_driver(as3722_poweroff_driver);
83
84MODULE_DESCRIPTION("Power off driver for ams AS3722 PMIC Device");
85MODULE_ALIAS("platform:as3722-power-off");
86MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
87MODULE_LICENSE("GPL v2");