tps6105x-regulator.c 3.1 KB

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