sky81452-regulator.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // sky81452-regulator.c SKY81452 regulator driver
  4. //
  5. // Copyright 2014 Skyworks Solutions Inc.
  6. // Author : Gyungoh Yoo <jack.yoo@skyworksinc.com>
  7. #include <linux/module.h>
  8. #include <linux/kernel.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/init.h>
  11. #include <linux/err.h>
  12. #include <linux/of.h>
  13. #include <linux/regulator/driver.h>
  14. #include <linux/regulator/of_regulator.h>
  15. /* registers */
  16. #define SKY81452_REG1 0x01
  17. #define SKY81452_REG3 0x03
  18. /* bit mask */
  19. #define SKY81452_LEN 0x40
  20. #define SKY81452_LOUT 0x1F
  21. static const struct regulator_ops sky81452_reg_ops = {
  22. .list_voltage = regulator_list_voltage_linear_range,
  23. .map_voltage = regulator_map_voltage_linear_range,
  24. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  25. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  26. .enable = regulator_enable_regmap,
  27. .disable = regulator_disable_regmap,
  28. .is_enabled = regulator_is_enabled_regmap,
  29. };
  30. static const struct regulator_linear_range sky81452_reg_ranges[] = {
  31. REGULATOR_LINEAR_RANGE(4500000, 0, 14, 250000),
  32. REGULATOR_LINEAR_RANGE(9000000, 15, 31, 1000000),
  33. };
  34. static const struct regulator_desc sky81452_reg = {
  35. .name = "LOUT",
  36. .of_match = of_match_ptr("lout"),
  37. .regulators_node = of_match_ptr("regulator"),
  38. .ops = &sky81452_reg_ops,
  39. .type = REGULATOR_VOLTAGE,
  40. .owner = THIS_MODULE,
  41. .n_voltages = SKY81452_LOUT + 1,
  42. .linear_ranges = sky81452_reg_ranges,
  43. .n_linear_ranges = ARRAY_SIZE(sky81452_reg_ranges),
  44. .vsel_reg = SKY81452_REG3,
  45. .vsel_mask = SKY81452_LOUT,
  46. .enable_reg = SKY81452_REG1,
  47. .enable_mask = SKY81452_LEN,
  48. };
  49. static int sky81452_reg_probe(struct platform_device *pdev)
  50. {
  51. struct device *dev = &pdev->dev;
  52. const struct regulator_init_data *init_data = dev_get_platdata(dev);
  53. struct regulator_config config = { };
  54. struct regulator_dev *rdev;
  55. config.dev = dev->parent;
  56. config.init_data = init_data;
  57. config.of_node = dev->of_node;
  58. config.regmap = dev_get_drvdata(dev->parent);
  59. rdev = devm_regulator_register(dev, &sky81452_reg, &config);
  60. if (IS_ERR(rdev)) {
  61. dev_err(dev, "failed to register. err=%ld\n", PTR_ERR(rdev));
  62. return PTR_ERR(rdev);
  63. }
  64. platform_set_drvdata(pdev, rdev);
  65. return 0;
  66. }
  67. static struct platform_driver sky81452_reg_driver = {
  68. .driver = {
  69. .name = "sky81452-regulator",
  70. },
  71. .probe = sky81452_reg_probe,
  72. };
  73. module_platform_driver(sky81452_reg_driver);
  74. MODULE_DESCRIPTION("Skyworks SKY81452 Regulator driver");
  75. MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>");
  76. MODULE_LICENSE("GPL v2");