cros_ec_tunnel.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2015 Google, Inc
  3. * Written by Simon Glass <sjg@chromium.org>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <cros_ec.h>
  10. #include <errno.h>
  11. #include <i2c.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. struct cros_ec_i2c_bus {
  14. int remote_bus;
  15. };
  16. static int cros_ec_i2c_set_bus_speed(struct udevice *dev, unsigned int speed)
  17. {
  18. return 0;
  19. }
  20. static int cros_ec_i2c_xfer(struct udevice *dev, struct i2c_msg *msg,
  21. int nmsgs)
  22. {
  23. struct cros_ec_i2c_bus *i2c_bus = dev_get_priv(dev);
  24. return cros_ec_i2c_tunnel(dev->parent, i2c_bus->remote_bus, msg, nmsgs);
  25. }
  26. static int cros_ec_i2c_ofdata_to_platdata(struct udevice *dev)
  27. {
  28. struct cros_ec_i2c_bus *i2c_bus = dev_get_priv(dev);
  29. const void *blob = gd->fdt_blob;
  30. int node = dev->of_offset;
  31. i2c_bus->remote_bus = fdtdec_get_uint(blob, node, "google,remote-bus",
  32. 0);
  33. return 0;
  34. }
  35. static const struct dm_i2c_ops cros_ec_i2c_ops = {
  36. .xfer = cros_ec_i2c_xfer,
  37. .set_bus_speed = cros_ec_i2c_set_bus_speed,
  38. };
  39. static const struct udevice_id cros_ec_i2c_ids[] = {
  40. { .compatible = "google,cros-ec-i2c-tunnel" },
  41. { }
  42. };
  43. U_BOOT_DRIVER(cros_ec_tunnel) = {
  44. .name = "cros_ec_tunnel",
  45. .id = UCLASS_I2C,
  46. .of_match = cros_ec_i2c_ids,
  47. .ofdata_to_platdata = cros_ec_i2c_ofdata_to_platdata,
  48. .priv_auto_alloc_size = sizeof(struct cros_ec_i2c_bus),
  49. .ops = &cros_ec_i2c_ops,
  50. };