tps6105x-regulator.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 const 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. .of_match = of_match_ptr("regulator"),
  37. .ops = &tps6105x_regulator_ops,
  38. .type = REGULATOR_VOLTAGE,
  39. .id = 0,
  40. .owner = THIS_MODULE,
  41. .n_voltages = ARRAY_SIZE(tps6105x_voltages),
  42. .volt_table = tps6105x_voltages,
  43. .vsel_reg = TPS6105X_REG_0,
  44. .vsel_mask = TPS6105X_REG0_VOLTAGE_MASK,
  45. .enable_reg = TPS6105X_REG_0,
  46. .enable_mask = TPS6105X_REG0_MODE_MASK,
  47. .enable_val = TPS6105X_REG0_MODE_VOLTAGE <<
  48. TPS6105X_REG0_MODE_SHIFT,
  49. };
  50. /*
  51. * Registers the chip as a voltage regulator
  52. */
  53. static int tps6105x_regulator_probe(struct platform_device *pdev)
  54. {
  55. struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev);
  56. struct tps6105x_platform_data *pdata = tps6105x->pdata;
  57. struct regulator_config config = { };
  58. int ret;
  59. /* This instance is not set for regulator mode so bail out */
  60. if (pdata->mode != TPS6105X_MODE_VOLTAGE) {
  61. dev_info(&pdev->dev,
  62. "chip not in voltage mode mode, exit probe\n");
  63. return 0;
  64. }
  65. config.dev = &tps6105x->client->dev;
  66. config.init_data = pdata->regulator_data;
  67. config.driver_data = tps6105x;
  68. config.of_node = pdev->dev.parent->of_node;
  69. config.regmap = tps6105x->regmap;
  70. /* Register regulator with framework */
  71. tps6105x->regulator = devm_regulator_register(&pdev->dev,
  72. &tps6105x_regulator_desc,
  73. &config);
  74. if (IS_ERR(tps6105x->regulator)) {
  75. ret = PTR_ERR(tps6105x->regulator);
  76. dev_err(&tps6105x->client->dev,
  77. "failed to register regulator\n");
  78. return ret;
  79. }
  80. platform_set_drvdata(pdev, tps6105x);
  81. return 0;
  82. }
  83. static struct platform_driver tps6105x_regulator_driver = {
  84. .driver = {
  85. .name = "tps6105x-regulator",
  86. },
  87. .probe = tps6105x_regulator_probe,
  88. };
  89. static __init int tps6105x_regulator_init(void)
  90. {
  91. return platform_driver_register(&tps6105x_regulator_driver);
  92. }
  93. subsys_initcall(tps6105x_regulator_init);
  94. static __exit void tps6105x_regulator_exit(void)
  95. {
  96. platform_driver_unregister(&tps6105x_regulator_driver);
  97. }
  98. module_exit(tps6105x_regulator_exit);
  99. MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
  100. MODULE_DESCRIPTION("TPS6105x regulator driver");
  101. MODULE_LICENSE("GPL v2");
  102. MODULE_ALIAS("platform:tps6105x-regulator");