cros_ec_ldo.c 1.6 KB

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