^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Driver for TPS61050/61052 boost converters, typically used for white LEDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * or audio amplifiers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2011 ST-Ericsson SA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Written on behalf of Linaro for ST-Ericsson
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Author: Linus Walleij <linus.walleij@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mfd/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/mfd/tps6105x.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static const unsigned int tps6105x_voltages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 4500000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 5000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 5250000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 5000000, /* There is an additional 5V */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static const struct regulator_ops tps6105x_regulator_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .list_voltage = regulator_list_voltage_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static const struct regulator_desc tps6105x_regulator_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .name = "tps6105x-boost",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .of_match = of_match_ptr("regulator"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .ops = &tps6105x_regulator_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .id = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .n_voltages = ARRAY_SIZE(tps6105x_voltages),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .volt_table = tps6105x_voltages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .vsel_reg = TPS6105X_REG_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .vsel_mask = TPS6105X_REG0_VOLTAGE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .enable_reg = TPS6105X_REG_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .enable_mask = TPS6105X_REG0_MODE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .enable_val = TPS6105X_REG0_MODE_VOLTAGE <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) TPS6105X_REG0_MODE_SHIFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Registers the chip as a voltage regulator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static int tps6105x_regulator_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct tps6105x_platform_data *pdata = tps6105x->pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* This instance is not set for regulator mode so bail out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (pdata->mode != TPS6105X_MODE_VOLTAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) dev_info(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) "chip not in voltage mode mode, exit probe\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) config.dev = &tps6105x->client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) config.init_data = pdata->regulator_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) config.driver_data = tps6105x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) config.of_node = pdev->dev.parent->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) config.regmap = tps6105x->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* Register regulator with framework */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) tps6105x->regulator = devm_regulator_register(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) &tps6105x_regulator_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (IS_ERR(tps6105x->regulator)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ret = PTR_ERR(tps6105x->regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) dev_err(&tps6105x->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) "failed to register regulator\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) platform_set_drvdata(pdev, tps6105x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static struct platform_driver tps6105x_regulator_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .name = "tps6105x-regulator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .probe = tps6105x_regulator_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static __init int tps6105x_regulator_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return platform_driver_register(&tps6105x_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) subsys_initcall(tps6105x_regulator_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static __exit void tps6105x_regulator_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) platform_driver_unregister(&tps6105x_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) module_exit(tps6105x_regulator_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) MODULE_DESCRIPTION("TPS6105x regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) MODULE_ALIAS("platform:tps6105x-regulator");