1 // SPDX-License-Identifier: GPL-2.0-only
3 * Regulator driver for the Richtek RT5033
5 * Copyright (C) 2014 Samsung Electronics, Co., Ltd.
6 * Author: Beomho Seo <beomho.seo@samsung.com>
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>
16 static const struct linear_range rt5033_buck_ranges[] = {
17 REGULATOR_LINEAR_RANGE(1000000, 0, 20, 100000),
18 REGULATOR_LINEAR_RANGE(3000000, 21, 31, 0),
21 static const struct linear_range rt5033_ldo_ranges[] = {
22 REGULATOR_LINEAR_RANGE(1200000, 0, 18, 100000),
23 REGULATOR_LINEAR_RANGE(3000000, 19, 31, 0),
26 static const struct regulator_ops rt5033_safe_ldo_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,
33 static const struct regulator_ops rt5033_buck_ops = {
34 .is_enabled = regulator_is_enabled_regmap,
35 .enable = regulator_enable_regmap,
36 .disable = regulator_disable_regmap,
37 .list_voltage = regulator_list_voltage_linear_range,
38 .get_voltage_sel = regulator_get_voltage_sel_regmap,
39 .set_voltage_sel = regulator_set_voltage_sel_regmap,
42 static const struct regulator_desc rt5033_supported_regulators[] = {
45 .of_match = of_match_ptr("BUCK"),
46 .regulators_node = of_match_ptr("regulators"),
48 .ops = &rt5033_buck_ops,
49 .type = REGULATOR_VOLTAGE,
51 .n_voltages = RT5033_REGULATOR_BUCK_VOLTAGE_STEP_NUM,
52 .linear_ranges = rt5033_buck_ranges,
53 .n_linear_ranges = ARRAY_SIZE(rt5033_buck_ranges),
54 .enable_reg = RT5033_REG_CTRL,
55 .enable_mask = RT5033_CTRL_EN_BUCK_MASK,
56 .vsel_reg = RT5033_REG_BUCK_CTRL,
57 .vsel_mask = RT5033_BUCK_CTRL_MASK,
61 .of_match = of_match_ptr("LDO"),
62 .regulators_node = of_match_ptr("regulators"),
64 .ops = &rt5033_buck_ops,
65 .type = REGULATOR_VOLTAGE,
67 .n_voltages = RT5033_REGULATOR_LDO_VOLTAGE_STEP_NUM,
68 .linear_ranges = rt5033_ldo_ranges,
69 .n_linear_ranges = ARRAY_SIZE(rt5033_ldo_ranges),
70 .enable_reg = RT5033_REG_CTRL,
71 .enable_mask = RT5033_CTRL_EN_LDO_MASK,
72 .vsel_reg = RT5033_REG_LDO_CTRL,
73 .vsel_mask = RT5033_LDO_CTRL_MASK,
77 .of_match = of_match_ptr("SAFE_LDO"),
78 .regulators_node = of_match_ptr("regulators"),
79 .id = RT5033_SAFE_LDO,
80 .ops = &rt5033_safe_ldo_ops,
81 .type = REGULATOR_VOLTAGE,
84 .min_uV = RT5033_REGULATOR_SAFE_LDO_VOLTAGE,
85 .enable_reg = RT5033_REG_CTRL,
86 .enable_mask = RT5033_CTRL_EN_SAFE_LDO_MASK,
90 static int rt5033_regulator_probe(struct platform_device *pdev)
92 struct rt5033_dev *rt5033 = dev_get_drvdata(pdev->dev.parent);
94 struct regulator_config config = {};
96 config.dev = rt5033->dev;
97 config.driver_data = rt5033;
99 for (i = 0; i < ARRAY_SIZE(rt5033_supported_regulators); i++) {
100 struct regulator_dev *regulator;
102 config.regmap = rt5033->regmap;
104 regulator = devm_regulator_register(&pdev->dev,
105 &rt5033_supported_regulators[i], &config);
106 if (IS_ERR(regulator)) {
107 ret = PTR_ERR(regulator);
109 "Regulator init failed %d: with error: %d\n",
118 static const struct platform_device_id rt5033_regulator_id[] = {
119 { "rt5033-regulator", },
122 MODULE_DEVICE_TABLE(platform, rt5033_regulator_id);
124 static struct platform_driver rt5033_regulator_driver = {
126 .name = "rt5033-regulator",
127 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
129 .probe = rt5033_regulator_probe,
130 .id_table = rt5033_regulator_id,
132 module_platform_driver(rt5033_regulator_driver);
134 MODULE_DESCRIPTION("Richtek RT5033 Regulator driver");
135 MODULE_AUTHOR("Beomho Seo <beomho.seo@samsung.com>");
136 MODULE_LICENSE("GPL");