1af873fceSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
22edd3b69SLinus Walleij /*
32edd3b69SLinus Walleij * Driver for TPS61050/61052 boost converters, typically used for white LEDs
42edd3b69SLinus Walleij * or audio amplifiers.
52edd3b69SLinus Walleij *
62edd3b69SLinus Walleij * Copyright (C) 2011 ST-Ericsson SA
72edd3b69SLinus Walleij * Written on behalf of Linaro for ST-Ericsson
82edd3b69SLinus Walleij *
92edd3b69SLinus Walleij * Author: Linus Walleij <linus.walleij@linaro.org>
102edd3b69SLinus Walleij */
112edd3b69SLinus Walleij
122edd3b69SLinus Walleij #include <linux/module.h>
132edd3b69SLinus Walleij #include <linux/kernel.h>
142edd3b69SLinus Walleij #include <linux/init.h>
152edd3b69SLinus Walleij #include <linux/err.h>
167e507119SGrigoryev Denis #include <linux/regmap.h>
172edd3b69SLinus Walleij #include <linux/platform_device.h>
182edd3b69SLinus Walleij #include <linux/regulator/driver.h>
192edd3b69SLinus Walleij #include <linux/mfd/core.h>
202edd3b69SLinus Walleij #include <linux/mfd/tps6105x.h>
212edd3b69SLinus Walleij
22c55979b7SAxel Lin static const unsigned int tps6105x_voltages[] = {
232edd3b69SLinus Walleij 4500000,
242edd3b69SLinus Walleij 5000000,
252edd3b69SLinus Walleij 5250000,
262edd3b69SLinus Walleij 5000000, /* There is an additional 5V */
272edd3b69SLinus Walleij };
282edd3b69SLinus Walleij
2955c81934SRikard Falkeborn static const struct regulator_ops tps6105x_regulator_ops = {
30fad2ba68SAxel Lin .enable = regulator_enable_regmap,
31fad2ba68SAxel Lin .disable = regulator_disable_regmap,
32fad2ba68SAxel Lin .is_enabled = regulator_is_enabled_regmap,
33fad2ba68SAxel Lin .get_voltage_sel = regulator_get_voltage_sel_regmap,
34fad2ba68SAxel Lin .set_voltage_sel = regulator_set_voltage_sel_regmap,
35c55979b7SAxel Lin .list_voltage = regulator_list_voltage_table,
362edd3b69SLinus Walleij };
372edd3b69SLinus Walleij
38d882d73eSAxel Lin static const struct regulator_desc tps6105x_regulator_desc = {
392edd3b69SLinus Walleij .name = "tps6105x-boost",
40f0a19fa8SSven Van Asbroeck .of_match = of_match_ptr("regulator"),
412edd3b69SLinus Walleij .ops = &tps6105x_regulator_ops,
422edd3b69SLinus Walleij .type = REGULATOR_VOLTAGE,
432edd3b69SLinus Walleij .id = 0,
442edd3b69SLinus Walleij .owner = THIS_MODULE,
452edd3b69SLinus Walleij .n_voltages = ARRAY_SIZE(tps6105x_voltages),
46c55979b7SAxel Lin .volt_table = tps6105x_voltages,
47fad2ba68SAxel Lin .vsel_reg = TPS6105X_REG_0,
48fad2ba68SAxel Lin .vsel_mask = TPS6105X_REG0_VOLTAGE_MASK,
49fad2ba68SAxel Lin .enable_reg = TPS6105X_REG_0,
50fad2ba68SAxel Lin .enable_mask = TPS6105X_REG0_MODE_MASK,
51fad2ba68SAxel Lin .enable_val = TPS6105X_REG0_MODE_VOLTAGE <<
52fad2ba68SAxel Lin TPS6105X_REG0_MODE_SHIFT,
532edd3b69SLinus Walleij };
542edd3b69SLinus Walleij
552edd3b69SLinus Walleij /*
562edd3b69SLinus Walleij * Registers the chip as a voltage regulator
572edd3b69SLinus Walleij */
tps6105x_regulator_probe(struct platform_device * pdev)58a5023574SBill Pemberton static int tps6105x_regulator_probe(struct platform_device *pdev)
592edd3b69SLinus Walleij {
60a7c98ce2SSamuel Ortiz struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev);
612edd3b69SLinus Walleij struct tps6105x_platform_data *pdata = tps6105x->pdata;
62c172708dSMark Brown struct regulator_config config = { };
632edd3b69SLinus Walleij int ret;
642edd3b69SLinus Walleij
652edd3b69SLinus Walleij /* This instance is not set for regulator mode so bail out */
662edd3b69SLinus Walleij if (pdata->mode != TPS6105X_MODE_VOLTAGE) {
672edd3b69SLinus Walleij dev_info(&pdev->dev,
682edd3b69SLinus Walleij "chip not in voltage mode mode, exit probe\n");
692edd3b69SLinus Walleij return 0;
702edd3b69SLinus Walleij }
712edd3b69SLinus Walleij
72c172708dSMark Brown config.dev = &tps6105x->client->dev;
73c172708dSMark Brown config.init_data = pdata->regulator_data;
74c172708dSMark Brown config.driver_data = tps6105x;
75f0a19fa8SSven Van Asbroeck config.of_node = pdev->dev.parent->of_node;
76fad2ba68SAxel Lin config.regmap = tps6105x->regmap;
77c172708dSMark Brown
782edd3b69SLinus Walleij /* Register regulator with framework */
796a2b5a93SJingoo Han tps6105x->regulator = devm_regulator_register(&pdev->dev,
806a2b5a93SJingoo Han &tps6105x_regulator_desc,
81c172708dSMark Brown &config);
822edd3b69SLinus Walleij if (IS_ERR(tps6105x->regulator)) {
832edd3b69SLinus Walleij ret = PTR_ERR(tps6105x->regulator);
842edd3b69SLinus Walleij dev_err(&tps6105x->client->dev,
852edd3b69SLinus Walleij "failed to register regulator\n");
862edd3b69SLinus Walleij return ret;
872edd3b69SLinus Walleij }
88f0f060bdSAxel Lin platform_set_drvdata(pdev, tps6105x);
892edd3b69SLinus Walleij
902edd3b69SLinus Walleij return 0;
912edd3b69SLinus Walleij }
922edd3b69SLinus Walleij
932edd3b69SLinus Walleij static struct platform_driver tps6105x_regulator_driver = {
942edd3b69SLinus Walleij .driver = {
952edd3b69SLinus Walleij .name = "tps6105x-regulator",
96*259b93b2SDouglas Anderson .probe_type = PROBE_PREFER_ASYNCHRONOUS,
972edd3b69SLinus Walleij },
982edd3b69SLinus Walleij .probe = tps6105x_regulator_probe,
992edd3b69SLinus Walleij };
1002edd3b69SLinus Walleij
tps6105x_regulator_init(void)1012edd3b69SLinus Walleij static __init int tps6105x_regulator_init(void)
1022edd3b69SLinus Walleij {
1032edd3b69SLinus Walleij return platform_driver_register(&tps6105x_regulator_driver);
1042edd3b69SLinus Walleij }
1052edd3b69SLinus Walleij subsys_initcall(tps6105x_regulator_init);
1062edd3b69SLinus Walleij
tps6105x_regulator_exit(void)1072edd3b69SLinus Walleij static __exit void tps6105x_regulator_exit(void)
1082edd3b69SLinus Walleij {
1092edd3b69SLinus Walleij platform_driver_unregister(&tps6105x_regulator_driver);
1102edd3b69SLinus Walleij }
1112edd3b69SLinus Walleij module_exit(tps6105x_regulator_exit);
1122edd3b69SLinus Walleij
1132edd3b69SLinus Walleij MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
1142edd3b69SLinus Walleij MODULE_DESCRIPTION("TPS6105x regulator driver");
1152edd3b69SLinus Walleij MODULE_LICENSE("GPL v2");
1162edd3b69SLinus Walleij MODULE_ALIAS("platform:tps6105x-regulator");
117