cros_ec_tunnel.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. DECLARE_GLOBAL_DATA_PTR;
  12. struct cros_ec_i2c_bus {
  13. int remote_bus;
  14. };
  15. static int cros_ec_i2c_set_bus_speed(struct udevice *dev, unsigned int speed)
  16. {
  17. return 0;
  18. }
  19. static int cros_ec_i2c_xfer(struct udevice *dev, struct i2c_msg *msg,
  20. int nmsgs)
  21. {
  22. struct cros_ec_i2c_bus *i2c_bus = dev_get_priv(dev);
  23. return cros_ec_i2c_tunnel(dev->parent, i2c_bus->remote_bus, msg, nmsgs);
  24. }
  25. static int cros_ec_i2c_ofdata_to_platdata(struct udevice *dev)
  26. {
  27. struct cros_ec_i2c_bus *i2c_bus = dev_get_priv(dev);
  28. const void *blob = gd->fdt_blob;
  29. int node = dev_of_offset(dev);
  30. i2c_bus->remote_bus = fdtdec_get_uint(blob, node, "google,remote-bus",
  31. 0);
  32. return 0;
  33. }
  34. static const struct dm_i2c_ops cros_ec_i2c_ops = {
  35. .xfer = cros_ec_i2c_xfer,
  36. .set_bus_speed = cros_ec_i2c_set_bus_speed,
  37. };
  38. static const struct udevice_id cros_ec_i2c_ids[] = {
  39. { .compatible = "google,cros-ec-i2c-tunnel" },
  40. { }
  41. };
  42. U_BOOT_DRIVER(cros_ec_tunnel) = {
  43. .name = "cros_ec_tunnel",
  44. .id = UCLASS_I2C,
  45. .of_match = cros_ec_i2c_ids,
  46. .ofdata_to_platdata = cros_ec_i2c_ofdata_to_platdata,
  47. .priv_auto_alloc_size = sizeof(struct cros_ec_i2c_bus),
  48. .ops = &cros_ec_i2c_ops,
  49. };