blob: 96d2c18e051a071de50a490181e88151a310bed8 [file] [log] [blame]
Beomho Seob1917572014-11-12 21:07:59 +09001/*
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
19static 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
26static 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
36static const struct regulator_desc rt5033_supported_regulators[] = {
37 [RT5033_BUCK] = {
38 .name = "BUCK",
Beomho Seo53aebb72014-12-18 20:13:36 +090039 .of_match = of_match_ptr("BUCK"),
40 .regulators_node = of_match_ptr("regulators"),
Beomho Seob1917572014-11-12 21:07:59 +090041 .id = RT5033_BUCK,
42 .ops = &rt5033_buck_ops,
43 .type = REGULATOR_VOLTAGE,
44 .owner = THIS_MODULE,
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,
52 },
53 [RT5033_LDO] = {
54 .name = "LDO",
Beomho Seo53aebb72014-12-18 20:13:36 +090055 .of_match = of_match_ptr("LDO"),
56 .regulators_node = of_match_ptr("regulators"),
Beomho Seob1917572014-11-12 21:07:59 +090057 .id = RT5033_LDO,
58 .ops = &rt5033_buck_ops,
59 .type = REGULATOR_VOLTAGE,
60 .owner = THIS_MODULE,
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,
68 },
69 [RT5033_SAFE_LDO] = {
70 .name = "SAFE_LDO",
Beomho Seo53aebb72014-12-18 20:13:36 +090071 .of_match = of_match_ptr("SAFE_LDO"),
72 .regulators_node = of_match_ptr("regulators"),
Beomho Seob1917572014-11-12 21:07:59 +090073 .id = RT5033_SAFE_LDO,
74 .ops = &rt5033_safe_ldo_ops,
75 .type = REGULATOR_VOLTAGE,
76 .owner = THIS_MODULE,
77 .n_voltages = 1,
78 .min_uV = RT5033_REGULATOR_SAFE_LDO_VOLTAGE,
79 .enable_reg = RT5033_REG_CTRL,
80 .enable_mask = RT5033_CTRL_EN_SAFE_LDO_MASK,
81 },
82};
83
84static int rt5033_regulator_probe(struct platform_device *pdev)
85{
86 struct rt5033_dev *rt5033 = dev_get_drvdata(pdev->dev.parent);
87 int ret, i;
88 struct regulator_config config = {};
89
Beomho Seo53aebb72014-12-18 20:13:36 +090090 config.dev = rt5033->dev;
Beomho Seob1917572014-11-12 21:07:59 +090091 config.driver_data = rt5033;
92
93 for (i = 0; i < ARRAY_SIZE(rt5033_supported_regulators); i++) {
94 struct regulator_dev *regulator;
95
96 config.regmap = rt5033->regmap;
97
98 regulator = devm_regulator_register(&pdev->dev,
99 &rt5033_supported_regulators[i], &config);
100 if (IS_ERR(regulator)) {
101 ret = PTR_ERR(regulator);
102 dev_err(&pdev->dev,
103 "Regulator init failed %d: with error: %d\n",
104 i, ret);
105 return ret;
106 }
107 }
108
109 return 0;
110}
111
112static const struct platform_device_id rt5033_regulator_id[] = {
113 { "rt5033-regulator", },
114 { }
115};
116MODULE_DEVICE_TABLE(platform, rt5033_regulator_id);
117
118static struct platform_driver rt5033_regulator_driver = {
119 .driver = {
120 .name = "rt5033-regulator",
121 },
122 .probe = rt5033_regulator_probe,
123 .id_table = rt5033_regulator_id,
124};
125module_platform_driver(rt5033_regulator_driver);
126
127MODULE_DESCRIPTION("Richtek RT5033 Regulator driver");
128MODULE_AUTHOR("Beomho Seo <beomho.seo@samsung.com>");
129MODULE_LICENSE("GPL");