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