s5m8767.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <fdtdec.h>
  7. #include <errno.h>
  8. #include <dm.h>
  9. #include <i2c.h>
  10. #include <power/pmic.h>
  11. #include <power/regulator.h>
  12. #include <power/s5m8767.h>
  13. static const struct pmic_child_info pmic_children_info[] = {
  14. { .prefix = "LDO", .driver = S5M8767_LDO_DRIVER },
  15. { .prefix = "BUCK", .driver = S5M8767_BUCK_DRIVER },
  16. { },
  17. };
  18. static int s5m8767_reg_count(struct udevice *dev)
  19. {
  20. return S5M8767_NUM_OF_REGS;
  21. }
  22. static int s5m8767_write(struct udevice *dev, uint reg, const uint8_t *buff,
  23. int len)
  24. {
  25. if (dm_i2c_write(dev, reg, buff, len)) {
  26. pr_err("write error to device: %p register: %#x!", dev, reg);
  27. return -EIO;
  28. }
  29. return 0;
  30. }
  31. static int s5m8767_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
  32. {
  33. if (dm_i2c_read(dev, reg, buff, len)) {
  34. pr_err("read error from device: %p register: %#x!", dev, reg);
  35. return -EIO;
  36. }
  37. return 0;
  38. }
  39. int s5m8767_enable_32khz_cp(struct udevice *dev)
  40. {
  41. return pmic_clrsetbits(dev, S5M8767_EN32KHZ_CP, 0, 1 << 1);
  42. }
  43. static int s5m8767_bind(struct udevice *dev)
  44. {
  45. int children;
  46. ofnode node;
  47. node = dev_read_subnode(dev, "regulators");
  48. if (!ofnode_valid(node)) {
  49. debug("%s: %s regulators subnode not found!", __func__,
  50. dev->name);
  51. return -ENXIO;
  52. }
  53. debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
  54. children = pmic_bind_children(dev, node, pmic_children_info);
  55. if (!children)
  56. debug("%s: %s - no child found\n", __func__, dev->name);
  57. /* Always return success for this device */
  58. return 0;
  59. }
  60. static struct dm_pmic_ops s5m8767_ops = {
  61. .reg_count = s5m8767_reg_count,
  62. .read = s5m8767_read,
  63. .write = s5m8767_write,
  64. };
  65. static const struct udevice_id s5m8767_ids[] = {
  66. { .compatible = "samsung,s5m8767-pmic" },
  67. { }
  68. };
  69. U_BOOT_DRIVER(pmic_s5m8767) = {
  70. .name = "s5m8767_pmic",
  71. .id = UCLASS_PMIC,
  72. .of_match = s5m8767_ids,
  73. .bind = s5m8767_bind,
  74. .ops = &s5m8767_ops,
  75. };