fixed.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Samsung Electronics
  4. *
  5. * Przemyslaw Marczak <p.marczak@samsung.com>
  6. */
  7. #include <common.h>
  8. #include <errno.h>
  9. #include <dm.h>
  10. #include <log.h>
  11. #include <power/pmic.h>
  12. #include <power/regulator.h>
  13. #include "regulator_common.h"
  14. static int fixed_regulator_of_to_plat(struct udevice *dev)
  15. {
  16. struct dm_regulator_uclass_plat *uc_pdata;
  17. struct regulator_common_plat *dev_pdata;
  18. dev_pdata = dev_get_plat(dev);
  19. uc_pdata = dev_get_uclass_plat(dev);
  20. if (!uc_pdata)
  21. return -ENXIO;
  22. uc_pdata->type = REGULATOR_TYPE_FIXED;
  23. return regulator_common_of_to_plat(dev, dev_pdata, "gpio");
  24. }
  25. static int fixed_regulator_get_value(struct udevice *dev)
  26. {
  27. struct dm_regulator_uclass_plat *uc_pdata;
  28. uc_pdata = dev_get_uclass_plat(dev);
  29. if (!uc_pdata)
  30. return -ENXIO;
  31. if (uc_pdata->min_uV != uc_pdata->max_uV) {
  32. debug("Invalid constraints for: %s\n", uc_pdata->name);
  33. return -EINVAL;
  34. }
  35. return uc_pdata->min_uV;
  36. }
  37. static int fixed_regulator_get_current(struct udevice *dev)
  38. {
  39. struct dm_regulator_uclass_plat *uc_pdata;
  40. uc_pdata = dev_get_uclass_plat(dev);
  41. if (!uc_pdata)
  42. return -ENXIO;
  43. if (uc_pdata->min_uA != uc_pdata->max_uA) {
  44. debug("Invalid constraints for: %s\n", uc_pdata->name);
  45. return -EINVAL;
  46. }
  47. return uc_pdata->min_uA;
  48. }
  49. static int fixed_regulator_get_enable(struct udevice *dev)
  50. {
  51. return regulator_common_get_enable(dev, dev_get_plat(dev));
  52. }
  53. static int fixed_regulator_set_enable(struct udevice *dev, bool enable)
  54. {
  55. return regulator_common_set_enable(dev, dev_get_plat(dev), enable);
  56. }
  57. static const struct dm_regulator_ops fixed_regulator_ops = {
  58. .get_value = fixed_regulator_get_value,
  59. .get_current = fixed_regulator_get_current,
  60. .get_enable = fixed_regulator_get_enable,
  61. .set_enable = fixed_regulator_set_enable,
  62. };
  63. static const struct udevice_id fixed_regulator_ids[] = {
  64. { .compatible = "regulator-fixed" },
  65. { },
  66. };
  67. U_BOOT_DRIVER(regulator_fixed) = {
  68. .name = "regulator_fixed",
  69. .id = UCLASS_REGULATOR,
  70. .ops = &fixed_regulator_ops,
  71. .of_match = fixed_regulator_ids,
  72. .of_to_plat = fixed_regulator_of_to_plat,
  73. .plat_auto = sizeof(struct regulator_common_plat),
  74. };