rk31xx:RT5025:support pmic rt5025
[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         printk("%s,line=%d\n", __func__,__LINE__);      
53
54         mi = kzalloc(sizeof(*mi), GFP_KERNEL);
55         if (!mi)
56                 return -ENOMEM;
57
58         mi->i2c = chip->i2c;
59         rt5025_misc_reg_init(mi->i2c, pdata->misc_data);
60
61         //for shutdown control
62         g_shdn = chip->i2c;
63
64         platform_set_drvdata(pdev, mi);
65         return 0;
66 }
67
68 static int __devexit rt5025_misc_remove(struct platform_device *pdev)
69 {
70         struct rt5025_misc_info *mi = platform_get_drvdata(pdev);
71
72         kfree(mi);
73         platform_set_drvdata(pdev, NULL);
74         return 0;
75 }
76
77 static struct platform_driver rt5025_misc_driver = 
78 {
79         .driver = {
80                 .name = RT5025_DEVICE_NAME "-misc",
81                 .owner = THIS_MODULE,
82         },
83         .probe = rt5025_misc_probe,
84         .remove = __devexit_p(rt5025_misc_remove),
85 };
86
87 static int __init rt5025_misc_init(void)
88 {
89         return platform_driver_register(&rt5025_misc_driver);
90 }
91 subsys_initcall_sync(rt5025_misc_init);
92
93 static void __exit rt5025_misc_exit(void)
94 {
95         platform_driver_unregister(&rt5025_misc_driver);
96 }
97 module_exit(rt5025_misc_exit);
98
99 MODULE_LICENSE("GPL v2");
100 MODULE_AUTHOR("CY Huang <cy_huang@richtek.com");
101 MODULE_DESCRIPTION("Misc driver for RT5025");
102 MODULE_ALIAS("platform:" RT5025_DEVICE_NAME "-misc");