cros_ec.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
  3. * Use of this source code is governed by a BSD-style license that can be
  4. * found in the LICENSE file.
  5. *
  6. * Alternatively, this software may be distributed under the terms of the
  7. * GNU General Public License ("GPL") version 2 as published by the Free
  8. * Software Foundation.
  9. */
  10. #include <common.h>
  11. #include <cros_ec.h>
  12. #include <dm.h>
  13. #include <errno.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. #ifndef CONFIG_DM_CROS_EC
  16. struct local_info {
  17. struct cros_ec_dev *cros_ec_dev; /* Pointer to cros_ec device */
  18. int cros_ec_err; /* Error for cros_ec, 0 if ok */
  19. };
  20. static struct local_info local;
  21. #endif
  22. struct cros_ec_dev *board_get_cros_ec_dev(void)
  23. {
  24. #ifdef CONFIG_DM_CROS_EC
  25. struct udevice *dev;
  26. int ret;
  27. ret = uclass_get_device(UCLASS_CROS_EC, 0, &dev);
  28. if (ret) {
  29. debug("%s: Error %d\n", __func__, ret);
  30. return NULL;
  31. }
  32. return dev->uclass_priv;
  33. #else
  34. return local.cros_ec_dev;
  35. #endif
  36. }
  37. static int board_init_cros_ec_devices(const void *blob)
  38. {
  39. #ifndef CONFIG_DM_CROS_EC
  40. local.cros_ec_err = cros_ec_init(blob, &local.cros_ec_dev);
  41. if (local.cros_ec_err)
  42. return -1; /* Will report in board_late_init() */
  43. #endif
  44. return 0;
  45. }
  46. int cros_ec_board_init(void)
  47. {
  48. return board_init_cros_ec_devices(gd->fdt_blob);
  49. }
  50. int cros_ec_get_error(void)
  51. {
  52. #ifdef CONFIG_DM_CROS_EC
  53. struct udevice *dev;
  54. int ret;
  55. ret = uclass_get_device(UCLASS_CROS_EC, 0, &dev);
  56. if (ret && ret != -ENODEV)
  57. return ret;
  58. return 0;
  59. #else
  60. return local.cros_ec_err;
  61. #endif
  62. }