Blame view
include/linux/greybus.h
4.14 KB
baeeb02cc
|
1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
c8a797a98
|
2 3 4 |
/* * Greybus driver and device API * |
4441f4759
|
5 6 |
* Copyright 2014-2015 Google Inc. * Copyright 2014-2015 Linaro Ltd. |
c8a797a98
|
7 8 9 10 11 12 |
*/ #ifndef __LINUX_GREYBUS_H #define __LINUX_GREYBUS_H #ifdef __KERNEL__ |
e1e9dbddf
|
13 |
#include <linux/kernel.h> |
6dca7b97c
|
14 |
#include <linux/types.h> |
c8a797a98
|
15 |
#include <linux/list.h> |
e1e9dbddf
|
16 |
#include <linux/slab.h> |
c8a797a98
|
17 18 |
#include <linux/device.h> #include <linux/module.h> |
30a3bf7b3
|
19 |
#include <linux/pm_runtime.h> |
177404bd2
|
20 |
#include <linux/idr.h> |
e1e9dbddf
|
21 |
|
ec0ad8681
|
22 23 24 25 26 27 28 29 30 31 32 33 |
#include <linux/greybus/greybus_id.h> #include <linux/greybus/greybus_manifest.h> #include <linux/greybus/greybus_protocols.h> #include <linux/greybus/manifest.h> #include <linux/greybus/hd.h> #include <linux/greybus/svc.h> #include <linux/greybus/control.h> #include <linux/greybus/module.h> #include <linux/greybus/interface.h> #include <linux/greybus/bundle.h> #include <linux/greybus/connection.h> #include <linux/greybus/operation.h> |
c8a797a98
|
34 |
|
8c53e073f
|
35 |
/* Matches up with the Greybus Protocol specification document */ |
52adb5634
|
36 37 |
#define GREYBUS_VERSION_MAJOR 0x00 #define GREYBUS_VERSION_MINOR 0x01 |
8c53e073f
|
38 |
|
358e9400f
|
39 40 |
#define GREYBUS_ID_MATCH_DEVICE \ (GREYBUS_ID_MATCH_VENDOR | GREYBUS_ID_MATCH_PRODUCT) |
c8a797a98
|
41 |
|
6dca7b97c
|
42 |
#define GREYBUS_DEVICE(v, p) \ |
358e9400f
|
43 |
.match_flags = GREYBUS_ID_MATCH_DEVICE, \ |
6dca7b97c
|
44 45 |
.vendor = (v), \ .product = (p), |
c8a797a98
|
46 |
|
3823c6147
|
47 48 49 |
#define GREYBUS_DEVICE_CLASS(c) \ .match_flags = GREYBUS_ID_MATCH_CLASS, \ .class = (c), |
1dc539226
|
50 51 52 |
/* Maximum number of CPorts */ #define CPORT_ID_MAX 4095 /* UniPro max id is 4095 */ #define CPORT_ID_BAD U16_MAX |
c8a797a98
|
53 |
|
c8a797a98
|
54 55 |
struct greybus_driver { const char *name; |
9f5f30e71
|
56 57 58 |
int (*probe)(struct gb_bundle *bundle, const struct greybus_bundle_id *id); void (*disconnect)(struct gb_bundle *bundle); |
c8a797a98
|
59 |
|
9f5f30e71
|
60 |
const struct greybus_bundle_id *id_table; |
c8a797a98
|
61 62 63 64 |
struct device_driver driver; }; #define to_greybus_driver(d) container_of(d, struct greybus_driver, driver) |
13da9e11e
|
65 66 67 68 69 70 71 72 73 |
static inline void greybus_set_drvdata(struct gb_bundle *bundle, void *data) { dev_set_drvdata(&bundle->dev, data); } static inline void *greybus_get_drvdata(struct gb_bundle *bundle) { return dev_get_drvdata(&bundle->dev); } |
c8a797a98
|
74 75 76 |
/* Don't call these directly, use the module_greybus_driver() macro instead */ int greybus_register_driver(struct greybus_driver *driver, struct module *module, const char *mod_name); |
fd1c2e541
|
77 |
void greybus_deregister_driver(struct greybus_driver *driver); |
c8a797a98
|
78 79 80 81 |
/* define to get proper THIS_MODULE and KBUILD_MODNAME values */ #define greybus_register(driver) \ greybus_register_driver(driver, THIS_MODULE, KBUILD_MODNAME) |
fd1c2e541
|
82 83 |
#define greybus_deregister(driver) \ greybus_deregister_driver(driver) |
c8a797a98
|
84 85 86 87 88 89 90 91 92 93 94 |
/** * module_greybus_driver() - Helper macro for registering a Greybus driver * @__greybus_driver: greybus_driver structure * * Helper macro for Greybus drivers to set up proper module init / exit * functions. Replaces module_init() and module_exit() and keeps people from * printing pointless things to the kernel log when their driver is loaded. */ #define module_greybus_driver(__greybus_driver) \ module_driver(__greybus_driver, greybus_register, greybus_deregister) |
c8a797a98
|
95 |
int greybus_disabled(void); |
3d0421e0a
|
96 |
void gb_debugfs_init(void); |
de536e309
|
97 |
void gb_debugfs_cleanup(void); |
e8f824b65
|
98 |
struct dentry *gb_debugfs_get(void); |
de536e309
|
99 |
|
f0f61b904
|
100 |
extern struct bus_type greybus_bus_type; |
06340efb7
|
101 |
|
2adaefb14
|
102 |
extern struct device_type greybus_hd_type; |
b15d97d77
|
103 |
extern struct device_type greybus_module_type; |
4ab9b3c24
|
104 |
extern struct device_type greybus_interface_type; |
a6e5b014b
|
105 |
extern struct device_type greybus_control_type; |
1db0a5ff3
|
106 |
extern struct device_type greybus_bundle_type; |
88f7b96da
|
107 |
extern struct device_type greybus_svc_type; |
0ac5a8388
|
108 |
|
2adaefb14
|
109 110 111 112 |
static inline int is_gb_host_device(const struct device *dev) { return dev->type == &greybus_hd_type; } |
b15d97d77
|
113 114 115 116 |
static inline int is_gb_module(const struct device *dev) { return dev->type == &greybus_module_type; } |
4ab9b3c24
|
117 |
static inline int is_gb_interface(const struct device *dev) |
0ac5a8388
|
118 |
{ |
4ab9b3c24
|
119 |
return dev->type == &greybus_interface_type; |
0ac5a8388
|
120 |
} |
a6e5b014b
|
121 122 123 124 |
static inline int is_gb_control(const struct device *dev) { return dev->type == &greybus_control_type; } |
1db0a5ff3
|
125 |
static inline int is_gb_bundle(const struct device *dev) |
0ac5a8388
|
126 |
{ |
1db0a5ff3
|
127 |
return dev->type == &greybus_bundle_type; |
0ac5a8388
|
128 |
} |
88f7b96da
|
129 130 131 132 |
static inline int is_gb_svc(const struct device *dev) { return dev->type == &greybus_svc_type; } |
2537636ab
|
133 |
static inline bool cport_id_valid(struct gb_host_device *hd, u16 cport_id) |
821c620af
|
134 |
{ |
144670c2a
|
135 |
return cport_id != CPORT_ID_BAD && cport_id < hd->num_cports; |
821c620af
|
136 |
} |
c8a797a98
|
137 138 |
#endif /* __KERNEL__ */ #endif /* __LINUX_GREYBUS_H */ |