sky81452-regulator.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * sky81452-regulator.c SKY81452 regulator driver
  3. *
  4. * Copyright 2014 Skyworks Solutions Inc.
  5. * Author : Gyungoh Yoo <jack.yoo@skyworksinc.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/init.h>
  23. #include <linux/err.h>
  24. #include <linux/of.h>
  25. #include <linux/regulator/driver.h>
  26. #include <linux/regulator/of_regulator.h>
  27. /* registers */
  28. #define SKY81452_REG1 0x01
  29. #define SKY81452_REG3 0x03
  30. /* bit mask */
  31. #define SKY81452_LEN 0x40
  32. #define SKY81452_LOUT 0x1F
  33. static struct regulator_ops sky81452_reg_ops = {
  34. .list_voltage = regulator_list_voltage_linear_range,
  35. .map_voltage = regulator_map_voltage_linear_range,
  36. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  37. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  38. .enable = regulator_enable_regmap,
  39. .disable = regulator_disable_regmap,
  40. .is_enabled = regulator_is_enabled_regmap,
  41. };
  42. static const struct regulator_linear_range sky81452_reg_ranges[] = {
  43. REGULATOR_LINEAR_RANGE(4500000, 0, 14, 250000),
  44. REGULATOR_LINEAR_RANGE(9000000, 15, 31, 1000000),
  45. };
  46. static const struct regulator_desc sky81452_reg = {
  47. .name = "LOUT",
  48. .of_match = of_match_ptr("lout"),
  49. .regulators_node = of_match_ptr("regulator"),
  50. .ops = &sky81452_reg_ops,
  51. .type = REGULATOR_VOLTAGE,
  52. .owner = THIS_MODULE,
  53. .n_voltages = SKY81452_LOUT + 1,
  54. .linear_ranges = sky81452_reg_ranges,
  55. .n_linear_ranges = ARRAY_SIZE(sky81452_reg_ranges),
  56. .vsel_reg = SKY81452_REG3,
  57. .vsel_mask = SKY81452_LOUT,
  58. .enable_reg = SKY81452_REG1,
  59. .enable_mask = SKY81452_LEN,
  60. };
  61. static int sky81452_reg_probe(struct platform_device *pdev)
  62. {
  63. struct device *dev = &pdev->dev;
  64. const struct regulator_init_data *init_data = dev_get_platdata(dev);
  65. struct regulator_config config = { };
  66. struct regulator_dev *rdev;
  67. config.dev = dev->parent;
  68. config.init_data = init_data;
  69. config.of_node = dev->of_node;
  70. config.regmap = dev_get_drvdata(dev->parent);
  71. rdev = devm_regulator_register(dev, &sky81452_reg, &config);
  72. if (IS_ERR(rdev)) {
  73. dev_err(dev, "failed to register. err=%ld\n", PTR_ERR(rdev));
  74. return PTR_ERR(rdev);
  75. }
  76. platform_set_drvdata(pdev, rdev);
  77. return 0;
  78. }
  79. static struct platform_driver sky81452_reg_driver = {
  80. .driver = {
  81. .name = "sky81452-regulator",
  82. },
  83. .probe = sky81452_reg_probe,
  84. };
  85. module_platform_driver(sky81452_reg_driver);
  86. MODULE_DESCRIPTION("Skyworks SKY81452 Regulator driver");
  87. MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>");
  88. MODULE_LICENSE("GPL v2");