Alex Elder | 8c12cde | 2014-10-01 21:54:12 -0500 | [diff] [blame] | 1 | /* |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 2 | * Greybus bundles |
Alex Elder | 8c12cde | 2014-10-01 21:54:12 -0500 | [diff] [blame] | 3 | * |
| 4 | * Copyright 2014 Google Inc. |
Alex Elder | a46e967 | 2014-12-12 12:08:42 -0600 | [diff] [blame] | 5 | * Copyright 2014 Linaro Ltd. |
Alex Elder | 8c12cde | 2014-10-01 21:54:12 -0500 | [diff] [blame] | 6 | * |
| 7 | * Released under the GPLv2 only. |
| 8 | */ |
| 9 | |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 10 | #ifndef __BUNDLE_H |
| 11 | #define __BUNDLE_H |
Alex Elder | 8c12cde | 2014-10-01 21:54:12 -0500 | [diff] [blame] | 12 | |
| 13 | #include <linux/list.h> |
| 14 | |
Alex Elder | 76639ef | 2016-06-03 15:55:30 -0500 | [diff] [blame] | 15 | #define BUNDLE_ID_NONE U8_MAX |
| 16 | |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 17 | /* Greybus "public" definitions" */ |
| 18 | struct gb_bundle { |
Greg Kroah-Hartman | f0f61b9 | 2014-10-24 17:34:46 +0800 | [diff] [blame] | 19 | struct device dev; |
Greg Kroah-Hartman | 4ab9b3c | 2014-12-19 14:56:31 -0800 | [diff] [blame] | 20 | struct gb_interface *intf; |
Johan Hovold | b807aa7 | 2016-01-19 12:51:21 +0100 | [diff] [blame] | 21 | |
Alex Elder | 63cc932 | 2014-10-02 12:30:02 -0500 | [diff] [blame] | 22 | u8 id; |
Viresh Kumar | 88e6d37 | 2015-04-06 15:49:36 +0530 | [diff] [blame] | 23 | u8 class; |
Johan Hovold | b807aa7 | 2016-01-19 12:51:21 +0100 | [diff] [blame] | 24 | u8 class_major; |
| 25 | u8 class_minor; |
| 26 | |
Johan Hovold | 98fdf5a | 2016-01-21 17:34:09 +0100 | [diff] [blame] | 27 | size_t num_cports; |
| 28 | struct greybus_descriptor_cport *cport_desc; |
| 29 | |
Alex Elder | 748e123 | 2014-10-03 14:14:22 -0500 | [diff] [blame] | 30 | struct list_head connections; |
Greg Kroah-Hartman | 75052a5 | 2015-04-13 19:48:37 +0200 | [diff] [blame] | 31 | u8 *state; |
Alex Elder | 8c12cde | 2014-10-01 21:54:12 -0500 | [diff] [blame] | 32 | |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 33 | struct list_head links; /* interface->bundles */ |
Alex Elder | 8c12cde | 2014-10-01 21:54:12 -0500 | [diff] [blame] | 34 | }; |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 35 | #define to_gb_bundle(d) container_of(d, struct gb_bundle, dev) |
Alex Elder | 8c12cde | 2014-10-01 21:54:12 -0500 | [diff] [blame] | 36 | |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 37 | /* Greybus "private" definitions" */ |
Viresh Kumar | 7c183f7 | 2015-04-01 20:32:00 +0530 | [diff] [blame] | 38 | struct gb_bundle *gb_bundle_create(struct gb_interface *intf, u8 bundle_id, |
Viresh Kumar | 88e6d37 | 2015-04-06 15:49:36 +0530 | [diff] [blame] | 39 | u8 class); |
Johan Hovold | a7e36d0 | 2015-12-07 15:05:43 +0100 | [diff] [blame] | 40 | int gb_bundle_add(struct gb_bundle *bundle); |
Alex Elder | fe53b45 | 2015-06-12 10:21:11 -0500 | [diff] [blame] | 41 | void gb_bundle_destroy(struct gb_bundle *bundle); |
Alex Elder | 8c12cde | 2014-10-01 21:54:12 -0500 | [diff] [blame] | 42 | |
David Lin | 61e13db | 2016-07-14 15:13:00 -0500 | [diff] [blame] | 43 | /* Bundle Runtime PM wrappers */ |
Greg Kroah-Hartman | 948c622 | 2016-09-09 09:47:01 +0200 | [diff] [blame] | 44 | #ifdef CONFIG_PM |
David Lin | 61e13db | 2016-07-14 15:13:00 -0500 | [diff] [blame] | 45 | static 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 | |
| 60 | static 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 | |
| 70 | static inline void gb_pm_runtime_get_noresume(struct gb_bundle *bundle) |
| 71 | { |
| 72 | pm_runtime_get_noresume(&bundle->dev); |
| 73 | } |
| 74 | |
| 75 | static inline void gb_pm_runtime_put_noidle(struct gb_bundle *bundle) |
| 76 | { |
| 77 | pm_runtime_put_noidle(&bundle->dev); |
| 78 | } |
| 79 | |
| 80 | #else |
| 81 | static inline int gb_pm_runtime_get_sync(struct gb_bundle *bundle) |
| 82 | { return 0; } |
| 83 | static inline int gb_pm_runtime_put_autosuspend(struct gb_bundle *bundle) |
| 84 | { return 0; } |
| 85 | |
| 86 | static inline void gb_pm_runtime_get_noresume(struct gb_bundle *bundle) {} |
| 87 | static inline void gb_pm_runtime_put_noidle(struct gb_bundle *bundle) {} |
| 88 | #endif |
| 89 | |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 90 | #endif /* __BUNDLE_H */ |