blob: f8939af0bd2ce3af1ceb72d44b2c5fbd18c2f3e2 [file] [log] [blame]
Thomas Gleixneraf873fc2019-05-28 09:57:21 -07001// SPDX-License-Identifier: GPL-2.0-only
Linus Walleij2edd3b62011-03-09 12:02:55 +00002/*
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>
Linus Walleij2edd3b62011-03-09 12:02:55 +000010 */
11
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/err.h>
Grigoryev Denis7e507112015-10-02 16:14:41 +000016#include <linux/regmap.h>
Linus Walleij2edd3b62011-03-09 12:02:55 +000017#include <linux/platform_device.h>
18#include <linux/regulator/driver.h>
19#include <linux/mfd/core.h>
20#include <linux/mfd/tps6105x.h>
21
Axel Linc55979b2012-05-20 10:37:33 +080022static const unsigned int tps6105x_voltages[] = {
Linus Walleij2edd3b62011-03-09 12:02:55 +000023 4500000,
24 5000000,
25 5250000,
26 5000000, /* There is an additional 5V */
27};
28
Linus Walleij2edd3b62011-03-09 12:02:55 +000029static struct regulator_ops tps6105x_regulator_ops = {
Axel Linfad2ba62015-11-18 16:22:52 +080030 .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,
Axel Linc55979b2012-05-20 10:37:33 +080035 .list_voltage = regulator_list_voltage_table,
Linus Walleij2edd3b62011-03-09 12:02:55 +000036};
37
Axel Lind882d732012-04-06 08:30:42 +080038static const struct regulator_desc tps6105x_regulator_desc = {
Linus Walleij2edd3b62011-03-09 12:02:55 +000039 .name = "tps6105x-boost",
Sven Van Asbroeckf0a19fa2019-11-19 10:46:09 -050040 .of_match = of_match_ptr("regulator"),
Linus Walleij2edd3b62011-03-09 12:02:55 +000041 .ops = &tps6105x_regulator_ops,
42 .type = REGULATOR_VOLTAGE,
43 .id = 0,
44 .owner = THIS_MODULE,
45 .n_voltages = ARRAY_SIZE(tps6105x_voltages),
Axel Linc55979b2012-05-20 10:37:33 +080046 .volt_table = tps6105x_voltages,
Axel Linfad2ba62015-11-18 16:22:52 +080047 .vsel_reg = TPS6105X_REG_0,
48 .vsel_mask = TPS6105X_REG0_VOLTAGE_MASK,
49 .enable_reg = TPS6105X_REG_0,
50 .enable_mask = TPS6105X_REG0_MODE_MASK,
51 .enable_val = TPS6105X_REG0_MODE_VOLTAGE <<
52 TPS6105X_REG0_MODE_SHIFT,
Linus Walleij2edd3b62011-03-09 12:02:55 +000053};
54
55/*
56 * Registers the chip as a voltage regulator
57 */
Bill Pembertona5023572012-11-19 13:22:22 -050058static int tps6105x_regulator_probe(struct platform_device *pdev)
Linus Walleij2edd3b62011-03-09 12:02:55 +000059{
Samuel Ortiza7c98ce2011-05-11 10:33:25 +020060 struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev);
Linus Walleij2edd3b62011-03-09 12:02:55 +000061 struct tps6105x_platform_data *pdata = tps6105x->pdata;
Mark Brownc172708d2012-04-04 00:50:22 +010062 struct regulator_config config = { };
Linus Walleij2edd3b62011-03-09 12:02:55 +000063 int ret;
64
65 /* This instance is not set for regulator mode so bail out */
66 if (pdata->mode != TPS6105X_MODE_VOLTAGE) {
67 dev_info(&pdev->dev,
Jingoo Han4932e892013-10-14 17:51:51 +090068 "chip not in voltage mode mode, exit probe\n");
Linus Walleij2edd3b62011-03-09 12:02:55 +000069 return 0;
70 }
71
Mark Brownc172708d2012-04-04 00:50:22 +010072 config.dev = &tps6105x->client->dev;
73 config.init_data = pdata->regulator_data;
74 config.driver_data = tps6105x;
Sven Van Asbroeckf0a19fa2019-11-19 10:46:09 -050075 config.of_node = pdev->dev.parent->of_node;
Axel Linfad2ba62015-11-18 16:22:52 +080076 config.regmap = tps6105x->regmap;
Mark Brownc172708d2012-04-04 00:50:22 +010077
Linus Walleij2edd3b62011-03-09 12:02:55 +000078 /* Register regulator with framework */
Jingoo Han6a2b5a92013-09-30 09:57:54 +090079 tps6105x->regulator = devm_regulator_register(&pdev->dev,
80 &tps6105x_regulator_desc,
81 &config);
Linus Walleij2edd3b62011-03-09 12:02:55 +000082 if (IS_ERR(tps6105x->regulator)) {
83 ret = PTR_ERR(tps6105x->regulator);
84 dev_err(&tps6105x->client->dev,
85 "failed to register regulator\n");
86 return ret;
87 }
Axel Linf0f060b2011-03-29 17:54:58 +080088 platform_set_drvdata(pdev, tps6105x);
Linus Walleij2edd3b62011-03-09 12:02:55 +000089
90 return 0;
91}
92
Linus Walleij2edd3b62011-03-09 12:02:55 +000093static struct platform_driver tps6105x_regulator_driver = {
94 .driver = {
95 .name = "tps6105x-regulator",
Linus Walleij2edd3b62011-03-09 12:02:55 +000096 },
97 .probe = tps6105x_regulator_probe,
Linus Walleij2edd3b62011-03-09 12:02:55 +000098};
99
100static __init int tps6105x_regulator_init(void)
101{
102 return platform_driver_register(&tps6105x_regulator_driver);
103}
104subsys_initcall(tps6105x_regulator_init);
105
106static __exit void tps6105x_regulator_exit(void)
107{
108 platform_driver_unregister(&tps6105x_regulator_driver);
109}
110module_exit(tps6105x_regulator_exit);
111
112MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
113MODULE_DESCRIPTION("TPS6105x regulator driver");
114MODULE_LICENSE("GPL v2");
115MODULE_ALIAS("platform:tps6105x-regulator");