0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/mfd/as3722.h>
0011 #include <linux/module.h>
0012 #include <linux/of.h>
0013 #include <linux/of_device.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/slab.h>
0016
0017 struct as3722_poweroff {
0018 struct device *dev;
0019 struct as3722 *as3722;
0020 };
0021
0022 static struct as3722_poweroff *as3722_pm_poweroff;
0023
0024 static void as3722_pm_power_off(void)
0025 {
0026 int ret;
0027
0028 if (!as3722_pm_poweroff) {
0029 pr_err("AS3722 poweroff is not initialised\n");
0030 return;
0031 }
0032
0033 ret = as3722_update_bits(as3722_pm_poweroff->as3722,
0034 AS3722_RESET_CONTROL_REG, AS3722_POWER_OFF, AS3722_POWER_OFF);
0035 if (ret < 0)
0036 dev_err(as3722_pm_poweroff->dev,
0037 "RESET_CONTROL_REG update failed, %d\n", ret);
0038 }
0039
0040 static int as3722_poweroff_probe(struct platform_device *pdev)
0041 {
0042 struct as3722_poweroff *as3722_poweroff;
0043 struct device_node *np = pdev->dev.parent->of_node;
0044
0045 if (!np)
0046 return -EINVAL;
0047
0048 if (!of_property_read_bool(np, "ams,system-power-controller"))
0049 return 0;
0050
0051 as3722_poweroff = devm_kzalloc(&pdev->dev, sizeof(*as3722_poweroff),
0052 GFP_KERNEL);
0053 if (!as3722_poweroff)
0054 return -ENOMEM;
0055
0056 as3722_poweroff->as3722 = dev_get_drvdata(pdev->dev.parent);
0057 as3722_poweroff->dev = &pdev->dev;
0058 as3722_pm_poweroff = as3722_poweroff;
0059 if (!pm_power_off)
0060 pm_power_off = as3722_pm_power_off;
0061
0062 return 0;
0063 }
0064
0065 static int as3722_poweroff_remove(struct platform_device *pdev)
0066 {
0067 if (pm_power_off == as3722_pm_power_off)
0068 pm_power_off = NULL;
0069 as3722_pm_poweroff = NULL;
0070
0071 return 0;
0072 }
0073
0074 static struct platform_driver as3722_poweroff_driver = {
0075 .driver = {
0076 .name = "as3722-power-off",
0077 },
0078 .probe = as3722_poweroff_probe,
0079 .remove = as3722_poweroff_remove,
0080 };
0081
0082 module_platform_driver(as3722_poweroff_driver);
0083
0084 MODULE_DESCRIPTION("Power off driver for ams AS3722 PMIC Device");
0085 MODULE_ALIAS("platform:as3722-power-off");
0086 MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
0087 MODULE_LICENSE("GPL v2");