cros_ec_ldo.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <cros_ec.h>
  9. #include <errno.h>
  10. #include <i2c.h>
  11. #include <power/tps65090.h>
  12. static int cros_ec_ldo_set_bus_speed(struct udevice *dev, unsigned int speed)
  13. {
  14. return 0;
  15. }
  16. static int cros_ec_ldo_xfer(struct udevice *dev, struct i2c_msg *msg,
  17. int nmsgs)
  18. {
  19. bool is_read = nmsgs > 1;
  20. int fet_id, ret;
  21. /*
  22. * Look for reads and writes of the LDO registers. In either case the
  23. * first message is a write with the register number as the first byte.
  24. */
  25. if (!nmsgs || !msg->len || (msg->flags & I2C_M_RD)) {
  26. debug("%s: Invalid message\n", __func__);
  27. goto err;
  28. }
  29. fet_id = msg->buf[0] - REG_FET_BASE;
  30. if (fet_id < 1 || fet_id > MAX_FET_NUM) {
  31. debug("%s: Invalid FET %d\n", __func__, fet_id);
  32. goto err;
  33. }
  34. if (is_read) {
  35. uint8_t state;
  36. ret = cros_ec_get_ldo(dev->parent, fet_id, &state);
  37. if (!ret)
  38. msg[1].buf[0] = state ?
  39. FET_CTRL_ENFET | FET_CTRL_PGFET : 0;
  40. } else {
  41. bool on = msg->buf[1] & FET_CTRL_ENFET;
  42. ret = cros_ec_set_ldo(dev->parent, fet_id, on);
  43. }
  44. return ret;
  45. err:
  46. /* Indicate that the message is unimplemented */
  47. return -ENOSYS;
  48. }
  49. static const struct dm_i2c_ops cros_ec_i2c_ops = {
  50. .xfer = cros_ec_ldo_xfer,
  51. .set_bus_speed = cros_ec_ldo_set_bus_speed,
  52. };
  53. static const struct udevice_id cros_ec_i2c_ids[] = {
  54. { .compatible = "google,cros-ec-ldo-tunnel" },
  55. { }
  56. };
  57. U_BOOT_DRIVER(cros_ec_ldo) = {
  58. .name = "cros_ec_ldo_tunnel",
  59. .id = UCLASS_I2C,
  60. .of_match = cros_ec_i2c_ids,
  61. .ops = &cros_ec_i2c_ops,
  62. };