]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - drivers/regulator/tps6105x-regulator.c
Merge tag 'backlight-next-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/lee...
[mirror_ubuntu-focal-kernel.git] / drivers / regulator / tps6105x-regulator.c
CommitLineData
af873fce 1// SPDX-License-Identifier: GPL-2.0-only
2edd3b69
LW
2/*
3 * Driver for TPS61050/61052 boost converters, typically used for white LEDs
4 * or audio amplifiers.
5 *
6 * Copyright (C) 2011 ST-Ericsson SA
7 * Written on behalf of Linaro for ST-Ericsson
8 *
9 * Author: Linus Walleij <linus.walleij@linaro.org>
2edd3b69
LW
10 */
11
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/err.h>
7e507119 16#include <linux/regmap.h>
2edd3b69
LW
17#include <linux/platform_device.h>
18#include <linux/regulator/driver.h>
19#include <linux/mfd/core.h>
20#include <linux/mfd/tps6105x.h>
21
c55979b7 22static const unsigned int tps6105x_voltages[] = {
2edd3b69
LW
23 4500000,
24 5000000,
25 5250000,
26 5000000, /* There is an additional 5V */
27};
28
2edd3b69 29static struct regulator_ops tps6105x_regulator_ops = {
fad2ba68
AL
30 .enable = regulator_enable_regmap,
31 .disable = regulator_disable_regmap,
32 .is_enabled = regulator_is_enabled_regmap,
33 .get_voltage_sel = regulator_get_voltage_sel_regmap,
34 .set_voltage_sel = regulator_set_voltage_sel_regmap,
c55979b7 35 .list_voltage = regulator_list_voltage_table,
2edd3b69
LW
36};
37
d882d73e 38static const struct regulator_desc tps6105x_regulator_desc = {
2edd3b69
LW
39 .name = "tps6105x-boost",
40 .ops = &tps6105x_regulator_ops,
41 .type = REGULATOR_VOLTAGE,
42 .id = 0,
43 .owner = THIS_MODULE,
44 .n_voltages = ARRAY_SIZE(tps6105x_voltages),
c55979b7 45 .volt_table = tps6105x_voltages,
fad2ba68
AL
46 .vsel_reg = TPS6105X_REG_0,
47 .vsel_mask = TPS6105X_REG0_VOLTAGE_MASK,
48 .enable_reg = TPS6105X_REG_0,
49 .enable_mask = TPS6105X_REG0_MODE_MASK,
50 .enable_val = TPS6105X_REG0_MODE_VOLTAGE <<
51 TPS6105X_REG0_MODE_SHIFT,
2edd3b69
LW
52};
53
54/*
55 * Registers the chip as a voltage regulator
56 */
a5023574 57static int tps6105x_regulator_probe(struct platform_device *pdev)
2edd3b69 58{
a7c98ce2 59 struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev);
2edd3b69 60 struct tps6105x_platform_data *pdata = tps6105x->pdata;
c172708d 61 struct regulator_config config = { };
2edd3b69
LW
62 int ret;
63
64 /* This instance is not set for regulator mode so bail out */
65 if (pdata->mode != TPS6105X_MODE_VOLTAGE) {
66 dev_info(&pdev->dev,
4932e89d 67 "chip not in voltage mode mode, exit probe\n");
2edd3b69
LW
68 return 0;
69 }
70
c172708d
MB
71 config.dev = &tps6105x->client->dev;
72 config.init_data = pdata->regulator_data;
73 config.driver_data = tps6105x;
fad2ba68 74 config.regmap = tps6105x->regmap;
c172708d 75
2edd3b69 76 /* Register regulator with framework */
6a2b5a93
JH
77 tps6105x->regulator = devm_regulator_register(&pdev->dev,
78 &tps6105x_regulator_desc,
79 &config);
2edd3b69
LW
80 if (IS_ERR(tps6105x->regulator)) {
81 ret = PTR_ERR(tps6105x->regulator);
82 dev_err(&tps6105x->client->dev,
83 "failed to register regulator\n");
84 return ret;
85 }
f0f060bd 86 platform_set_drvdata(pdev, tps6105x);
2edd3b69
LW
87
88 return 0;
89}
90
2edd3b69
LW
91static struct platform_driver tps6105x_regulator_driver = {
92 .driver = {
93 .name = "tps6105x-regulator",
2edd3b69
LW
94 },
95 .probe = tps6105x_regulator_probe,
2edd3b69
LW
96};
97
98static __init int tps6105x_regulator_init(void)
99{
100 return platform_driver_register(&tps6105x_regulator_driver);
101}
102subsys_initcall(tps6105x_regulator_init);
103
104static __exit void tps6105x_regulator_exit(void)
105{
106 platform_driver_unregister(&tps6105x_regulator_driver);
107}
108module_exit(tps6105x_regulator_exit);
109
110MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
111MODULE_DESCRIPTION("TPS6105x regulator driver");
112MODULE_LICENSE("GPL v2");
113MODULE_ALIAS("platform:tps6105x-regulator");