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 292edd3b69SLinus Walleij static 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", 402edd3b69SLinus Walleij .ops = &tps6105x_regulator_ops, 412edd3b69SLinus Walleij .type = REGULATOR_VOLTAGE, 422edd3b69SLinus Walleij .id = 0, 432edd3b69SLinus Walleij .owner = THIS_MODULE, 442edd3b69SLinus Walleij .n_voltages = ARRAY_SIZE(tps6105x_voltages), 45c55979b7SAxel Lin .volt_table = tps6105x_voltages, 46fad2ba68SAxel Lin .vsel_reg = TPS6105X_REG_0, 47fad2ba68SAxel Lin .vsel_mask = TPS6105X_REG0_VOLTAGE_MASK, 48fad2ba68SAxel Lin .enable_reg = TPS6105X_REG_0, 49fad2ba68SAxel Lin .enable_mask = TPS6105X_REG0_MODE_MASK, 50fad2ba68SAxel Lin .enable_val = TPS6105X_REG0_MODE_VOLTAGE << 51fad2ba68SAxel Lin TPS6105X_REG0_MODE_SHIFT, 522edd3b69SLinus Walleij }; 532edd3b69SLinus Walleij 542edd3b69SLinus Walleij /* 552edd3b69SLinus Walleij * Registers the chip as a voltage regulator 562edd3b69SLinus Walleij */ 57a5023574SBill Pemberton static int tps6105x_regulator_probe(struct platform_device *pdev) 582edd3b69SLinus Walleij { 59a7c98ce2SSamuel Ortiz struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev); 602edd3b69SLinus Walleij struct tps6105x_platform_data *pdata = tps6105x->pdata; 61c172708dSMark Brown struct regulator_config config = { }; 622edd3b69SLinus Walleij int ret; 632edd3b69SLinus Walleij 642edd3b69SLinus Walleij /* This instance is not set for regulator mode so bail out */ 652edd3b69SLinus Walleij if (pdata->mode != TPS6105X_MODE_VOLTAGE) { 662edd3b69SLinus Walleij dev_info(&pdev->dev, 672edd3b69SLinus Walleij "chip not in voltage mode mode, exit probe\n"); 682edd3b69SLinus Walleij return 0; 692edd3b69SLinus Walleij } 702edd3b69SLinus Walleij 71c172708dSMark Brown config.dev = &tps6105x->client->dev; 72c172708dSMark Brown config.init_data = pdata->regulator_data; 73c172708dSMark Brown config.driver_data = tps6105x; 74fad2ba68SAxel Lin config.regmap = tps6105x->regmap; 75c172708dSMark Brown 762edd3b69SLinus Walleij /* Register regulator with framework */ 776a2b5a93SJingoo Han tps6105x->regulator = devm_regulator_register(&pdev->dev, 786a2b5a93SJingoo Han &tps6105x_regulator_desc, 79c172708dSMark Brown &config); 802edd3b69SLinus Walleij if (IS_ERR(tps6105x->regulator)) { 812edd3b69SLinus Walleij ret = PTR_ERR(tps6105x->regulator); 822edd3b69SLinus Walleij dev_err(&tps6105x->client->dev, 832edd3b69SLinus Walleij "failed to register regulator\n"); 842edd3b69SLinus Walleij return ret; 852edd3b69SLinus Walleij } 86f0f060bdSAxel Lin platform_set_drvdata(pdev, tps6105x); 872edd3b69SLinus Walleij 882edd3b69SLinus Walleij return 0; 892edd3b69SLinus Walleij } 902edd3b69SLinus Walleij 912edd3b69SLinus Walleij static struct platform_driver tps6105x_regulator_driver = { 922edd3b69SLinus Walleij .driver = { 932edd3b69SLinus Walleij .name = "tps6105x-regulator", 942edd3b69SLinus Walleij }, 952edd3b69SLinus Walleij .probe = tps6105x_regulator_probe, 962edd3b69SLinus Walleij }; 972edd3b69SLinus Walleij 982edd3b69SLinus Walleij static __init int tps6105x_regulator_init(void) 992edd3b69SLinus Walleij { 1002edd3b69SLinus Walleij return platform_driver_register(&tps6105x_regulator_driver); 1012edd3b69SLinus Walleij } 1022edd3b69SLinus Walleij subsys_initcall(tps6105x_regulator_init); 1032edd3b69SLinus Walleij 1042edd3b69SLinus Walleij static __exit void tps6105x_regulator_exit(void) 1052edd3b69SLinus Walleij { 1062edd3b69SLinus Walleij platform_driver_unregister(&tps6105x_regulator_driver); 1072edd3b69SLinus Walleij } 1082edd3b69SLinus Walleij module_exit(tps6105x_regulator_exit); 1092edd3b69SLinus Walleij 1102edd3b69SLinus Walleij MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>"); 1112edd3b69SLinus Walleij MODULE_DESCRIPTION("TPS6105x regulator driver"); 1122edd3b69SLinus Walleij MODULE_LICENSE("GPL v2"); 1132edd3b69SLinus Walleij MODULE_ALIAS("platform:tps6105x-regulator"); 114