blob: 0c3491def96c29f22390319eb5703986c7047c2c [file] [log] [blame]
Alex Elder8c12cde2014-10-01 21:54:12 -05001/*
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -05002 * Greybus bundles
Alex Elder8c12cde2014-10-01 21:54:12 -05003 *
4 * Copyright 2014 Google Inc.
Alex Eldera46e9672014-12-12 12:08:42 -06005 * Copyright 2014 Linaro Ltd.
Alex Elder8c12cde2014-10-01 21:54:12 -05006 *
7 * Released under the GPLv2 only.
8 */
9
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -050010#ifndef __BUNDLE_H
11#define __BUNDLE_H
Alex Elder8c12cde2014-10-01 21:54:12 -050012
13#include <linux/list.h>
14
Alex Elder76639ef2016-06-03 15:55:30 -050015#define BUNDLE_ID_NONE U8_MAX
16
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -050017/* Greybus "public" definitions" */
18struct gb_bundle {
Greg Kroah-Hartmanf0f61b92014-10-24 17:34:46 +080019 struct device dev;
Greg Kroah-Hartman4ab9b3c2014-12-19 14:56:31 -080020 struct gb_interface *intf;
Johan Hovoldb807aa72016-01-19 12:51:21 +010021
Alex Elder63cc9322014-10-02 12:30:02 -050022 u8 id;
Viresh Kumar88e6d372015-04-06 15:49:36 +053023 u8 class;
Johan Hovoldb807aa72016-01-19 12:51:21 +010024 u8 class_major;
25 u8 class_minor;
26
Johan Hovold98fdf5a2016-01-21 17:34:09 +010027 size_t num_cports;
28 struct greybus_descriptor_cport *cport_desc;
29
Alex Elder748e1232014-10-03 14:14:22 -050030 struct list_head connections;
Greg Kroah-Hartman75052a52015-04-13 19:48:37 +020031 u8 *state;
Alex Elder8c12cde2014-10-01 21:54:12 -050032
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -050033 struct list_head links; /* interface->bundles */
Alex Elder8c12cde2014-10-01 21:54:12 -050034};
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -050035#define to_gb_bundle(d) container_of(d, struct gb_bundle, dev)
Alex Elder8c12cde2014-10-01 21:54:12 -050036
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -050037/* Greybus "private" definitions" */
Viresh Kumar7c183f72015-04-01 20:32:00 +053038struct gb_bundle *gb_bundle_create(struct gb_interface *intf, u8 bundle_id,
Viresh Kumar88e6d372015-04-06 15:49:36 +053039 u8 class);
Johan Hovolda7e36d02015-12-07 15:05:43 +010040int gb_bundle_add(struct gb_bundle *bundle);
Alex Elderfe53b452015-06-12 10:21:11 -050041void gb_bundle_destroy(struct gb_bundle *bundle);
Alex Elder8c12cde2014-10-01 21:54:12 -050042
David Lin61e13db2016-07-14 15:13:00 -050043/* Bundle Runtime PM wrappers */
Greg Kroah-Hartman948c6222016-09-09 09:47:01 +020044#ifdef CONFIG_PM
David Lin61e13db2016-07-14 15:13:00 -050045static 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
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
70static inline void gb_pm_runtime_get_noresume(struct gb_bundle *bundle)
71{
72 pm_runtime_get_noresume(&bundle->dev);
73}
74
75static inline void gb_pm_runtime_put_noidle(struct gb_bundle *bundle)
76{
77 pm_runtime_put_noidle(&bundle->dev);
78}
79
80#else
81static inline int gb_pm_runtime_get_sync(struct gb_bundle *bundle)
82{ return 0; }
83static inline int gb_pm_runtime_put_autosuspend(struct gb_bundle *bundle)
84{ return 0; }
85
86static inline void gb_pm_runtime_get_noresume(struct gb_bundle *bundle) {}
87static inline void gb_pm_runtime_put_noidle(struct gb_bundle *bundle) {}
88#endif
89
Greg Kroah-Hartman1db0a5f2014-12-12 17:10:17 -050090#endif /* __BUNDLE_H */