Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Driver for TPS61050/61052 boost converters, typically used for white LEDs
0004  * or audio amplifiers.
0005  *
0006  * Copyright (C) 2011 ST-Ericsson SA
0007  * Written on behalf of Linaro for ST-Ericsson
0008  *
0009  * Author: Linus Walleij <linus.walleij@linaro.org>
0010  */
0011 
0012 #include <linux/module.h>
0013 #include <linux/kernel.h>
0014 #include <linux/init.h>
0015 #include <linux/err.h>
0016 #include <linux/regmap.h>
0017 #include <linux/platform_device.h>
0018 #include <linux/regulator/driver.h>
0019 #include <linux/mfd/core.h>
0020 #include <linux/mfd/tps6105x.h>
0021 
0022 static const unsigned int tps6105x_voltages[] = {
0023     4500000,
0024     5000000,
0025     5250000,
0026     5000000, /* There is an additional 5V */
0027 };
0028 
0029 static const struct regulator_ops tps6105x_regulator_ops = {
0030     .enable     = regulator_enable_regmap,
0031     .disable    = regulator_disable_regmap,
0032     .is_enabled = regulator_is_enabled_regmap,
0033     .get_voltage_sel = regulator_get_voltage_sel_regmap,
0034     .set_voltage_sel = regulator_set_voltage_sel_regmap,
0035     .list_voltage   = regulator_list_voltage_table,
0036 };
0037 
0038 static const struct regulator_desc tps6105x_regulator_desc = {
0039     .name       = "tps6105x-boost",
0040     .of_match   = of_match_ptr("regulator"),
0041     .ops        = &tps6105x_regulator_ops,
0042     .type       = REGULATOR_VOLTAGE,
0043     .id     = 0,
0044     .owner      = THIS_MODULE,
0045     .n_voltages = ARRAY_SIZE(tps6105x_voltages),
0046     .volt_table = tps6105x_voltages,
0047     .vsel_reg   = TPS6105X_REG_0,
0048     .vsel_mask  = TPS6105X_REG0_VOLTAGE_MASK,
0049     .enable_reg = TPS6105X_REG_0,
0050     .enable_mask    = TPS6105X_REG0_MODE_MASK,
0051     .enable_val = TPS6105X_REG0_MODE_VOLTAGE <<
0052               TPS6105X_REG0_MODE_SHIFT,
0053 };
0054 
0055 /*
0056  * Registers the chip as a voltage regulator
0057  */
0058 static int tps6105x_regulator_probe(struct platform_device *pdev)
0059 {
0060     struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev);
0061     struct tps6105x_platform_data *pdata = tps6105x->pdata;
0062     struct regulator_config config = { };
0063     int ret;
0064 
0065     /* This instance is not set for regulator mode so bail out */
0066     if (pdata->mode != TPS6105X_MODE_VOLTAGE) {
0067         dev_info(&pdev->dev,
0068             "chip not in voltage mode mode, exit probe\n");
0069         return 0;
0070     }
0071 
0072     config.dev = &tps6105x->client->dev;
0073     config.init_data = pdata->regulator_data;
0074     config.driver_data = tps6105x;
0075     config.of_node = pdev->dev.parent->of_node;
0076     config.regmap = tps6105x->regmap;
0077 
0078     /* Register regulator with framework */
0079     tps6105x->regulator = devm_regulator_register(&pdev->dev,
0080                               &tps6105x_regulator_desc,
0081                               &config);
0082     if (IS_ERR(tps6105x->regulator)) {
0083         ret = PTR_ERR(tps6105x->regulator);
0084         dev_err(&tps6105x->client->dev,
0085             "failed to register regulator\n");
0086         return ret;
0087     }
0088     platform_set_drvdata(pdev, tps6105x);
0089 
0090     return 0;
0091 }
0092 
0093 static struct platform_driver tps6105x_regulator_driver = {
0094     .driver = {
0095         .name  = "tps6105x-regulator",
0096     },
0097     .probe = tps6105x_regulator_probe,
0098 };
0099 
0100 static __init int tps6105x_regulator_init(void)
0101 {
0102     return platform_driver_register(&tps6105x_regulator_driver);
0103 }
0104 subsys_initcall(tps6105x_regulator_init);
0105 
0106 static __exit void tps6105x_regulator_exit(void)
0107 {
0108     platform_driver_unregister(&tps6105x_regulator_driver);
0109 }
0110 module_exit(tps6105x_regulator_exit);
0111 
0112 MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
0113 MODULE_DESCRIPTION("TPS6105x regulator driver");
0114 MODULE_LICENSE("GPL v2");
0115 MODULE_ALIAS("platform:tps6105x-regulator");