Merge branch 'develop-3.0' of ssh://10.10.10.29/rk/kernel into develop-3.0
[firefly-linux-kernel-4.4.55.git] / drivers / mfd / rt5025-misc.c
1 /*
2  *  drivers/mfd/rt5025-misc.c
3  *  Driver foo Richtek RT5025 PMIC Misc Part
4  *
5  *  Copyright (C) 2013 Richtek Electronics
6  *  cy_huang <cy_huang@richtek.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/err.h>
16 #include <linux/i2c.h>
17 #include <linux/platform_device.h>
18 #include <linux/slab.h>
19
20 #include <linux/mfd/rt5025.h>
21 #include <linux/mfd/rt5025-misc.h>
22
23 struct rt5025_misc_info {
24         struct i2c_client *i2c;
25 };
26
27 static struct i2c_client *g_shdn;
28 void rt5025_power_off(void)
29 {
30         rt5025_set_bits(g_shdn, RT5025_SHDNCTRL_REG, RT5025_SHDNCTRL_MASK);
31 }
32 EXPORT_SYMBOL(rt5025_power_off);
33
34 static int __devinit rt5025_misc_reg_init(struct i2c_client *client, struct rt5025_misc_data *md)
35 {
36         int ret = 0;
37         
38         rt5025_reg_write(client, RT5025_RESETCTRL_REG, md->RSTCtrl.val);
39         rt5025_assign_bits(client, RT5025_VSYSULVO_REG, RT5025_VSYSOFF_MASK, md->VSYSCtrl.val);
40         rt5025_reg_write(client, RT5025_PWRONCTRL_REG, md->PwrOnCfg.val);
41         rt5025_reg_write(client, RT5025_SHDNCTRL_REG, md->SHDNCtrl.val);
42         rt5025_reg_write(client, RT5025_PWROFFEN_REG, md->PwrOffCond.val);
43
44         return ret;
45 }
46
47 static int __devinit rt5025_misc_probe(struct platform_device *pdev)
48 {
49         struct rt5025_chip *chip = dev_get_drvdata(pdev->dev.parent);
50         struct rt5025_platform_data *pdata = chip->dev->platform_data;
51         struct rt5025_misc_info *mi;
52
53         mi = kzalloc(sizeof(*mi), GFP_KERNEL);
54         if (!mi)
55                 return -ENOMEM;
56
57         mi->i2c = chip->i2c;
58         rt5025_misc_reg_init(mi->i2c, pdata->misc_data);
59
60         //for shutdown control
61         g_shdn = chip->i2c;
62
63         platform_set_drvdata(pdev, mi);
64         return 0;
65 }
66
67 static int __devexit rt5025_misc_remove(struct platform_device *pdev)
68 {
69         struct rt5025_misc_info *mi = platform_get_drvdata(pdev);
70
71         kfree(mi);
72         platform_set_drvdata(pdev, NULL);
73         return 0;
74 }
75
76 static struct platform_driver rt5025_misc_driver = 
77 {
78         .driver = {
79                 .name = RT5025_DEVICE_NAME "-misc",
80                 .owner = THIS_MODULE,
81         },
82         .probe = rt5025_misc_probe,
83         .remove = __devexit_p(rt5025_misc_remove),
84 };
85
86 static int __init rt5025_misc_init(void)
87 {
88         return platform_driver_register(&rt5025_misc_driver);
89 }
90 subsys_initcall_sync(rt5025_misc_init);
91
92 static void __exit rt5025_misc_exit(void)
93 {
94         platform_driver_unregister(&rt5025_misc_driver);
95 }
96 module_exit(rt5025_misc_exit);
97
98 MODULE_LICENSE("GPL v2");
99 MODULE_AUTHOR("CY Huang <cy_huang@richtek.com");
100 MODULE_DESCRIPTION("Misc driver for RT5025");
101 MODULE_ALIAS("platform:" RT5025_DEVICE_NAME "-misc");