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/slab.h> |
15 | |
16 | struct as3722_poweroff { |
17 | struct device *dev; |
18 | struct as3722 *as3722; |
19 | }; |
20 | |
21 | static struct as3722_poweroff *as3722_pm_poweroff; |
22 | |
23 | static void as3722_pm_power_off(void) |
24 | { |
25 | int ret; |
26 | |
27 | if (!as3722_pm_poweroff) { |
28 | pr_err("AS3722 poweroff is not initialised\n" ); |
29 | return; |
30 | } |
31 | |
32 | ret = as3722_update_bits(as3722: as3722_pm_poweroff->as3722, |
33 | AS3722_RESET_CONTROL_REG, AS3722_POWER_OFF, AS3722_POWER_OFF); |
34 | if (ret < 0) |
35 | dev_err(as3722_pm_poweroff->dev, |
36 | "RESET_CONTROL_REG update failed, %d\n" , ret); |
37 | } |
38 | |
39 | static int as3722_poweroff_probe(struct platform_device *pdev) |
40 | { |
41 | struct as3722_poweroff *as3722_poweroff; |
42 | struct device_node *np = pdev->dev.parent->of_node; |
43 | |
44 | if (!np) |
45 | return -EINVAL; |
46 | |
47 | if (!of_property_read_bool(np, propname: "ams,system-power-controller" )) |
48 | return 0; |
49 | |
50 | as3722_poweroff = devm_kzalloc(dev: &pdev->dev, size: sizeof(*as3722_poweroff), |
51 | GFP_KERNEL); |
52 | if (!as3722_poweroff) |
53 | return -ENOMEM; |
54 | |
55 | as3722_poweroff->as3722 = dev_get_drvdata(dev: pdev->dev.parent); |
56 | as3722_poweroff->dev = &pdev->dev; |
57 | as3722_pm_poweroff = as3722_poweroff; |
58 | if (!pm_power_off) |
59 | pm_power_off = as3722_pm_power_off; |
60 | |
61 | return 0; |
62 | } |
63 | |
64 | static int as3722_poweroff_remove(struct platform_device *pdev) |
65 | { |
66 | if (pm_power_off == as3722_pm_power_off) |
67 | pm_power_off = NULL; |
68 | as3722_pm_poweroff = NULL; |
69 | |
70 | return 0; |
71 | } |
72 | |
73 | static struct platform_driver as3722_poweroff_driver = { |
74 | .driver = { |
75 | .name = "as3722-power-off" , |
76 | }, |
77 | .probe = as3722_poweroff_probe, |
78 | .remove = as3722_poweroff_remove, |
79 | }; |
80 | |
81 | module_platform_driver(as3722_poweroff_driver); |
82 | |
83 | MODULE_DESCRIPTION("Power off driver for ams AS3722 PMIC Device" ); |
84 | MODULE_ALIAS("platform:as3722-power-off" ); |
85 | MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>" ); |
86 | |