bundle.h 2.0 KB

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