blob: 06059a94f7c658df3ea98451e6ef78aad685e469 [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",
40 .ops = &tps6105x_regulator_ops,
41 .type = REGULATOR_VOLTAGE,
42 .id = 0,
43 .owner = THIS_MODULE,
44 .n_voltages = ARRAY_SIZE(tps6105x_voltages),
Axel Linc55979b2012-05-20 10:37:33 +080045 .volt_table = tps6105x_voltages,
Axel Linfad2ba62015-11-18 16:22:52 +080046 .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,
Linus Walleij2edd3b62011-03-09 12:02:55 +000052};
53
54/*
55 * Registers the chip as a voltage regulator
56 */
Bill Pembertona5023572012-11-19 13:22:22 -050057static int tps6105x_regulator_probe(struct platform_device *pdev)
Linus Walleij2edd3b62011-03-09 12:02:55 +000058{
Samuel Ortiza7c98ce2011-05-11 10:33:25 +020059 struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev);
Linus Walleij2edd3b62011-03-09 12:02:55 +000060 struct tps6105x_platform_data *pdata = tps6105x->pdata;
Mark Brownc1727082012-04-04 00:50:22 +010061 struct regulator_config config = { };
Linus Walleij2edd3b62011-03-09 12:02:55 +000062 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,
Jingoo Han4932e892013-10-14 17:51:51 +090067 "chip not in voltage mode mode, exit probe\n");
Linus Walleij2edd3b62011-03-09 12:02:55 +000068 return 0;
69 }
70
Mark Brownc1727082012-04-04 00:50:22 +010071 config.dev = &tps6105x->client->dev;
72 config.init_data = pdata->regulator_data;
73 config.driver_data = tps6105x;
Axel Linfad2ba62015-11-18 16:22:52 +080074 config.regmap = tps6105x->regmap;
Mark Brownc1727082012-04-04 00:50:22 +010075
Linus Walleij2edd3b62011-03-09 12:02:55 +000076 /* Register regulator with framework */
Jingoo Han6a2b5a92013-09-30 09:57:54 +090077 tps6105x->regulator = devm_regulator_register(&pdev->dev,
78 &tps6105x_regulator_desc,
79 &config);
Linus Walleij2edd3b62011-03-09 12:02:55 +000080 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 }
Axel Linf0f060b2011-03-29 17:54:58 +080086 platform_set_drvdata(pdev, tps6105x);
Linus Walleij2edd3b62011-03-09 12:02:55 +000087
88 return 0;
89}
90
Linus Walleij2edd3b62011-03-09 12:02:55 +000091static struct platform_driver tps6105x_regulator_driver = {
92 .driver = {
93 .name = "tps6105x-regulator",
Linus Walleij2edd3b62011-03-09 12:02:55 +000094 },
95 .probe = tps6105x_regulator_probe,
Linus Walleij2edd3b62011-03-09 12:02:55 +000096};
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");