Merge tag 'driver-core-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[firefly-linux-kernel-4.4.55.git] / drivers / regulator / rt5033-regulator.c
1 /*
2  * Regulator driver for the Richtek RT5033
3  *
4  * Copyright (C) 2014 Samsung Electronics, Co., Ltd.
5  * Author: Beomho Seo <beomho.seo@samsung.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published bythe Free Software Foundation.
10  */
11
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/regulator/driver.h>
15 #include <linux/mfd/rt5033.h>
16 #include <linux/mfd/rt5033-private.h>
17 #include <linux/regulator/of_regulator.h>
18
19 static struct regulator_ops rt5033_safe_ldo_ops = {
20         .is_enabled             = regulator_is_enabled_regmap,
21         .enable                 = regulator_enable_regmap,
22         .disable                = regulator_disable_regmap,
23         .list_voltage           = regulator_list_voltage_linear,
24 };
25
26 static struct regulator_ops rt5033_buck_ops = {
27         .is_enabled             = regulator_is_enabled_regmap,
28         .enable                 = regulator_enable_regmap,
29         .disable                = regulator_disable_regmap,
30         .list_voltage           = regulator_list_voltage_linear,
31         .map_voltage            = regulator_map_voltage_linear,
32         .get_voltage_sel        = regulator_get_voltage_sel_regmap,
33         .set_voltage_sel        = regulator_set_voltage_sel_regmap,
34 };
35
36 static const struct regulator_desc rt5033_supported_regulators[] = {
37         [RT5033_BUCK] = {
38                 .name           = "BUCK",
39                 .id             = RT5033_BUCK,
40                 .ops            = &rt5033_buck_ops,
41                 .type           = REGULATOR_VOLTAGE,
42                 .owner          = THIS_MODULE,
43                 .n_voltages     = RT5033_REGULATOR_BUCK_VOLTAGE_STEP_NUM,
44                 .min_uV         = RT5033_REGULATOR_BUCK_VOLTAGE_MIN,
45                 .uV_step        = RT5033_REGULATOR_BUCK_VOLTAGE_STEP,
46                 .enable_reg     = RT5033_REG_CTRL,
47                 .enable_mask    = RT5033_CTRL_EN_BUCK_MASK,
48                 .vsel_reg       = RT5033_REG_BUCK_CTRL,
49                 .vsel_mask      = RT5033_BUCK_CTRL_MASK,
50         },
51         [RT5033_LDO] = {
52                 .name           = "LDO",
53                 .id             = RT5033_LDO,
54                 .ops            = &rt5033_buck_ops,
55                 .type           = REGULATOR_VOLTAGE,
56                 .owner          = THIS_MODULE,
57                 .n_voltages     = RT5033_REGULATOR_LDO_VOLTAGE_STEP_NUM,
58                 .min_uV         = RT5033_REGULATOR_LDO_VOLTAGE_MIN,
59                 .uV_step        = RT5033_REGULATOR_LDO_VOLTAGE_STEP,
60                 .enable_reg     = RT5033_REG_CTRL,
61                 .enable_mask    = RT5033_CTRL_EN_LDO_MASK,
62                 .vsel_reg       = RT5033_REG_LDO_CTRL,
63                 .vsel_mask      = RT5033_LDO_CTRL_MASK,
64         },
65         [RT5033_SAFE_LDO] = {
66                 .name           = "SAFE_LDO",
67                 .id             = RT5033_SAFE_LDO,
68                 .ops            = &rt5033_safe_ldo_ops,
69                 .type           = REGULATOR_VOLTAGE,
70                 .owner          = THIS_MODULE,
71                 .n_voltages     = 1,
72                 .min_uV         = RT5033_REGULATOR_SAFE_LDO_VOLTAGE,
73                 .enable_reg     = RT5033_REG_CTRL,
74                 .enable_mask    = RT5033_CTRL_EN_SAFE_LDO_MASK,
75         },
76 };
77
78 static int rt5033_regulator_probe(struct platform_device *pdev)
79 {
80         struct rt5033_dev *rt5033 = dev_get_drvdata(pdev->dev.parent);
81         int ret, i;
82         struct regulator_config config = {};
83
84         config.dev = &pdev->dev;
85         config.driver_data = rt5033;
86
87         for (i = 0; i < ARRAY_SIZE(rt5033_supported_regulators); i++) {
88                 struct regulator_dev *regulator;
89
90                 config.regmap = rt5033->regmap;
91
92                 regulator = devm_regulator_register(&pdev->dev,
93                                 &rt5033_supported_regulators[i], &config);
94                 if (IS_ERR(regulator)) {
95                         ret = PTR_ERR(regulator);
96                         dev_err(&pdev->dev,
97                                 "Regulator init failed %d: with error: %d\n",
98                                 i, ret);
99                         return ret;
100                 }
101         }
102
103         return 0;
104 }
105
106 static const struct platform_device_id rt5033_regulator_id[] = {
107         { "rt5033-regulator", },
108         { }
109 };
110 MODULE_DEVICE_TABLE(platform, rt5033_regulator_id);
111
112 static struct platform_driver rt5033_regulator_driver = {
113         .driver = {
114                 .name = "rt5033-regulator",
115         },
116         .probe          = rt5033_regulator_probe,
117         .id_table       = rt5033_regulator_id,
118 };
119 module_platform_driver(rt5033_regulator_driver);
120
121 MODULE_DESCRIPTION("Richtek RT5033 Regulator driver");
122 MODULE_AUTHOR("Beomho Seo <beomho.seo@samsung.com>");
123 MODULE_LICENSE("GPL");