2 * Regulator driver for the Richtek RT5033
4 * Copyright (C) 2014 Samsung Electronics, Co., Ltd.
5 * Author: Beomho Seo <beomho.seo@samsung.com>
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.
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>
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
,
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
,
36 static const struct regulator_desc rt5033_supported_regulators
[] = {
39 .of_match
= of_match_ptr("BUCK"),
40 .regulators_node
= of_match_ptr("regulators"),
42 .ops
= &rt5033_buck_ops
,
43 .type
= REGULATOR_VOLTAGE
,
45 .n_voltages
= RT5033_REGULATOR_BUCK_VOLTAGE_STEP_NUM
,
46 .min_uV
= RT5033_REGULATOR_BUCK_VOLTAGE_MIN
,
47 .uV_step
= RT5033_REGULATOR_BUCK_VOLTAGE_STEP
,
48 .enable_reg
= RT5033_REG_CTRL
,
49 .enable_mask
= RT5033_CTRL_EN_BUCK_MASK
,
50 .vsel_reg
= RT5033_REG_BUCK_CTRL
,
51 .vsel_mask
= RT5033_BUCK_CTRL_MASK
,
55 .of_match
= of_match_ptr("LDO"),
56 .regulators_node
= of_match_ptr("regulators"),
58 .ops
= &rt5033_buck_ops
,
59 .type
= REGULATOR_VOLTAGE
,
61 .n_voltages
= RT5033_REGULATOR_LDO_VOLTAGE_STEP_NUM
,
62 .min_uV
= RT5033_REGULATOR_LDO_VOLTAGE_MIN
,
63 .uV_step
= RT5033_REGULATOR_LDO_VOLTAGE_STEP
,
64 .enable_reg
= RT5033_REG_CTRL
,
65 .enable_mask
= RT5033_CTRL_EN_LDO_MASK
,
66 .vsel_reg
= RT5033_REG_LDO_CTRL
,
67 .vsel_mask
= RT5033_LDO_CTRL_MASK
,
71 .of_match
= of_match_ptr("SAFE_LDO"),
72 .regulators_node
= of_match_ptr("regulators"),
73 .id
= RT5033_SAFE_LDO
,
74 .ops
= &rt5033_safe_ldo_ops
,
75 .type
= REGULATOR_VOLTAGE
,
78 .min_uV
= RT5033_REGULATOR_SAFE_LDO_VOLTAGE
,
79 .enable_reg
= RT5033_REG_CTRL
,
80 .enable_mask
= RT5033_CTRL_EN_SAFE_LDO_MASK
,
84 static int rt5033_regulator_probe(struct platform_device
*pdev
)
86 struct rt5033_dev
*rt5033
= dev_get_drvdata(pdev
->dev
.parent
);
88 struct regulator_config config
= {};
90 config
.dev
= rt5033
->dev
;
91 config
.driver_data
= rt5033
;
93 for (i
= 0; i
< ARRAY_SIZE(rt5033_supported_regulators
); i
++) {
94 struct regulator_dev
*regulator
;
96 config
.regmap
= rt5033
->regmap
;
98 regulator
= devm_regulator_register(&pdev
->dev
,
99 &rt5033_supported_regulators
[i
], &config
);
100 if (IS_ERR(regulator
)) {
101 ret
= PTR_ERR(regulator
);
103 "Regulator init failed %d: with error: %d\n",
112 static const struct platform_device_id rt5033_regulator_id
[] = {
113 { "rt5033-regulator", },
116 MODULE_DEVICE_TABLE(platform
, rt5033_regulator_id
);
118 static struct platform_driver rt5033_regulator_driver
= {
120 .name
= "rt5033-regulator",
122 .probe
= rt5033_regulator_probe
,
123 .id_table
= rt5033_regulator_id
,
125 module_platform_driver(rt5033_regulator_driver
);
127 MODULE_DESCRIPTION("Richtek RT5033 Regulator driver");
128 MODULE_AUTHOR("Beomho Seo <beomho.seo@samsung.com>");
129 MODULE_LICENSE("GPL");