Commit | Line | Data |
---|---|---|
baeeb02c | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
c8a797a9 GKH |
2 | /* |
3 | * Greybus driver and device API | |
4 | * | |
4441f475 AE |
5 | * Copyright 2014-2015 Google Inc. |
6 | * Copyright 2014-2015 Linaro Ltd. | |
c8a797a9 GKH |
7 | */ |
8 | ||
9 | #ifndef __LINUX_GREYBUS_H | |
10 | #define __LINUX_GREYBUS_H | |
11 | ||
12 | #ifdef __KERNEL__ | |
13 | ||
e1e9dbdd | 14 | #include <linux/kernel.h> |
6dca7b97 | 15 | #include <linux/types.h> |
c8a797a9 | 16 | #include <linux/list.h> |
e1e9dbdd | 17 | #include <linux/slab.h> |
c8a797a9 GKH |
18 | #include <linux/device.h> |
19 | #include <linux/module.h> | |
30a3bf7b | 20 | #include <linux/pm_runtime.h> |
177404bd | 21 | #include <linux/idr.h> |
e1e9dbdd | 22 | |
ec0ad868 GKH |
23 | #include <linux/greybus/greybus_id.h> |
24 | #include <linux/greybus/greybus_manifest.h> | |
25 | #include <linux/greybus/greybus_protocols.h> | |
26 | #include <linux/greybus/manifest.h> | |
27 | #include <linux/greybus/hd.h> | |
28 | #include <linux/greybus/svc.h> | |
29 | #include <linux/greybus/control.h> | |
30 | #include <linux/greybus/module.h> | |
31 | #include <linux/greybus/interface.h> | |
32 | #include <linux/greybus/bundle.h> | |
33 | #include <linux/greybus/connection.h> | |
34 | #include <linux/greybus/operation.h> | |
c8a797a9 | 35 | |
8c53e073 | 36 | /* Matches up with the Greybus Protocol specification document */ |
52adb563 MP |
37 | #define GREYBUS_VERSION_MAJOR 0x00 |
38 | #define GREYBUS_VERSION_MINOR 0x01 | |
8c53e073 | 39 | |
358e9400 JH |
40 | #define GREYBUS_ID_MATCH_DEVICE \ |
41 | (GREYBUS_ID_MATCH_VENDOR | GREYBUS_ID_MATCH_PRODUCT) | |
c8a797a9 | 42 | |
6dca7b97 | 43 | #define GREYBUS_DEVICE(v, p) \ |
358e9400 | 44 | .match_flags = GREYBUS_ID_MATCH_DEVICE, \ |
6dca7b97 GKH |
45 | .vendor = (v), \ |
46 | .product = (p), | |
c8a797a9 | 47 | |
3823c614 JH |
48 | #define GREYBUS_DEVICE_CLASS(c) \ |
49 | .match_flags = GREYBUS_ID_MATCH_CLASS, \ | |
50 | .class = (c), | |
51 | ||
1dc53922 JH |
52 | /* Maximum number of CPorts */ |
53 | #define CPORT_ID_MAX 4095 /* UniPro max id is 4095 */ | |
54 | #define CPORT_ID_BAD U16_MAX | |
c8a797a9 | 55 | |
c8a797a9 GKH |
56 | struct greybus_driver { |
57 | const char *name; | |
58 | ||
9f5f30e7 VK |
59 | int (*probe)(struct gb_bundle *bundle, |
60 | const struct greybus_bundle_id *id); | |
61 | void (*disconnect)(struct gb_bundle *bundle); | |
c8a797a9 | 62 | |
9f5f30e7 | 63 | const struct greybus_bundle_id *id_table; |
c8a797a9 GKH |
64 | |
65 | struct device_driver driver; | |
66 | }; | |
67 | #define to_greybus_driver(d) container_of(d, struct greybus_driver, driver) | |
68 | ||
13da9e11 JH |
69 | static inline void greybus_set_drvdata(struct gb_bundle *bundle, void *data) |
70 | { | |
71 | dev_set_drvdata(&bundle->dev, data); | |
72 | } | |
73 | ||
74 | static inline void *greybus_get_drvdata(struct gb_bundle *bundle) | |
75 | { | |
76 | return dev_get_drvdata(&bundle->dev); | |
77 | } | |
78 | ||
c8a797a9 GKH |
79 | /* Don't call these directly, use the module_greybus_driver() macro instead */ |
80 | int greybus_register_driver(struct greybus_driver *driver, | |
81 | struct module *module, const char *mod_name); | |
fd1c2e54 | 82 | void greybus_deregister_driver(struct greybus_driver *driver); |
c8a797a9 GKH |
83 | |
84 | /* define to get proper THIS_MODULE and KBUILD_MODNAME values */ | |
85 | #define greybus_register(driver) \ | |
86 | greybus_register_driver(driver, THIS_MODULE, KBUILD_MODNAME) | |
fd1c2e54 AE |
87 | #define greybus_deregister(driver) \ |
88 | greybus_deregister_driver(driver) | |
c8a797a9 GKH |
89 | |
90 | /** | |
91 | * module_greybus_driver() - Helper macro for registering a Greybus driver | |
92 | * @__greybus_driver: greybus_driver structure | |
93 | * | |
94 | * Helper macro for Greybus drivers to set up proper module init / exit | |
95 | * functions. Replaces module_init() and module_exit() and keeps people from | |
96 | * printing pointless things to the kernel log when their driver is loaded. | |
97 | */ | |
98 | #define module_greybus_driver(__greybus_driver) \ | |
99 | module_driver(__greybus_driver, greybus_register, greybus_deregister) | |
100 | ||
c8a797a9 GKH |
101 | int greybus_disabled(void); |
102 | ||
3d0421e0 | 103 | void gb_debugfs_init(void); |
de536e30 | 104 | void gb_debugfs_cleanup(void); |
e8f824b6 | 105 | struct dentry *gb_debugfs_get(void); |
de536e30 | 106 | |
f0f61b90 | 107 | extern struct bus_type greybus_bus_type; |
06340efb | 108 | |
2adaefb1 | 109 | extern struct device_type greybus_hd_type; |
b15d97d7 | 110 | extern struct device_type greybus_module_type; |
4ab9b3c2 | 111 | extern struct device_type greybus_interface_type; |
a6e5b014 | 112 | extern struct device_type greybus_control_type; |
1db0a5ff | 113 | extern struct device_type greybus_bundle_type; |
88f7b96d | 114 | extern struct device_type greybus_svc_type; |
0ac5a838 | 115 | |
2adaefb1 JH |
116 | static inline int is_gb_host_device(const struct device *dev) |
117 | { | |
118 | return dev->type == &greybus_hd_type; | |
119 | } | |
120 | ||
b15d97d7 JH |
121 | static inline int is_gb_module(const struct device *dev) |
122 | { | |
123 | return dev->type == &greybus_module_type; | |
124 | } | |
125 | ||
4ab9b3c2 | 126 | static inline int is_gb_interface(const struct device *dev) |
0ac5a838 | 127 | { |
4ab9b3c2 | 128 | return dev->type == &greybus_interface_type; |
0ac5a838 GKH |
129 | } |
130 | ||
a6e5b014 JH |
131 | static inline int is_gb_control(const struct device *dev) |
132 | { | |
133 | return dev->type == &greybus_control_type; | |
134 | } | |
135 | ||
1db0a5ff | 136 | static inline int is_gb_bundle(const struct device *dev) |
0ac5a838 | 137 | { |
1db0a5ff | 138 | return dev->type == &greybus_bundle_type; |
0ac5a838 GKH |
139 | } |
140 | ||
88f7b96d JH |
141 | static inline int is_gb_svc(const struct device *dev) |
142 | { | |
143 | return dev->type == &greybus_svc_type; | |
144 | } | |
145 | ||
2537636a | 146 | static inline bool cport_id_valid(struct gb_host_device *hd, u16 cport_id) |
821c620a | 147 | { |
144670c2 | 148 | return cport_id != CPORT_ID_BAD && cport_id < hd->num_cports; |
821c620a AE |
149 | } |
150 | ||
c8a797a9 GKH |
151 | #endif /* __KERNEL__ */ |
152 | #endif /* __LINUX_GREYBUS_H */ |