bundle.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Greybus bundles
  3. *
  4. * Copyright 2014 Google Inc.
  5. * Copyright 2014 Linaro Ltd.
  6. *
  7. * Released under the GPLv2 only.
  8. */
  9. #ifndef __BUNDLE_H
  10. #define __BUNDLE_H
  11. #include <linux/list.h>
  12. #define BUNDLE_ID_NONE U8_MAX
  13. /* Greybus "public" definitions" */
  14. struct gb_bundle {
  15. struct device dev;
  16. struct gb_interface *intf;
  17. u8 id;
  18. u8 class;
  19. u8 class_major;
  20. u8 class_minor;
  21. size_t num_cports;
  22. struct greybus_descriptor_cport *cport_desc;
  23. struct list_head connections;
  24. u8 *state;
  25. struct list_head links; /* interface->bundles */
  26. };
  27. #define to_gb_bundle(d) container_of(d, struct gb_bundle, dev)
  28. /* Greybus "private" definitions" */
  29. struct gb_bundle *gb_bundle_create(struct gb_interface *intf, u8 bundle_id,
  30. u8 class);
  31. int gb_bundle_add(struct gb_bundle *bundle);
  32. void gb_bundle_destroy(struct gb_bundle *bundle);
  33. /* Bundle Runtime PM wrappers */
  34. #ifdef CONFIG_PM
  35. static inline int gb_pm_runtime_get_sync(struct gb_bundle *bundle)
  36. {
  37. int retval;
  38. retval = pm_runtime_get_sync(&bundle->dev);
  39. if (retval < 0) {
  40. dev_err(&bundle->dev,
  41. "pm_runtime_get_sync failed: %d\n", retval);
  42. pm_runtime_put_noidle(&bundle->dev);
  43. return retval;
  44. }
  45. return 0;
  46. }
  47. static inline int gb_pm_runtime_put_autosuspend(struct gb_bundle *bundle)
  48. {
  49. int retval;
  50. pm_runtime_mark_last_busy(&bundle->dev);
  51. retval = pm_runtime_put_autosuspend(&bundle->dev);
  52. return retval;
  53. }
  54. static inline void gb_pm_runtime_get_noresume(struct gb_bundle *bundle)
  55. {
  56. pm_runtime_get_noresume(&bundle->dev);
  57. }
  58. static inline void gb_pm_runtime_put_noidle(struct gb_bundle *bundle)
  59. {
  60. pm_runtime_put_noidle(&bundle->dev);
  61. }
  62. #else
  63. static inline int gb_pm_runtime_get_sync(struct gb_bundle *bundle)
  64. { return 0; }
  65. static inline int gb_pm_runtime_put_autosuspend(struct gb_bundle *bundle)
  66. { return 0; }
  67. static inline void gb_pm_runtime_get_noresume(struct gb_bundle *bundle) {}
  68. static inline void gb_pm_runtime_put_noidle(struct gb_bundle *bundle) {}
  69. #endif
  70. #endif /* __BUNDLE_H */