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