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