greybus: gpbridge.h: move protocol init/exit prototypes
[cascardo/linux.git] / drivers / staging / greybus / protocol.h
1 /*
2  * Greybus protocol handling
3  *
4  * Copyright 2014 Google Inc.
5  * Copyright 2014 Linaro Ltd.
6  *
7  * Released under the GPLv2 only.
8  */
9
10 #ifndef __PROTOCOL_H
11 #define __PROTOCOL_H
12
13 struct gb_connection;
14 struct gb_operation;
15
16 typedef int (*gb_connection_init_t)(struct gb_connection *);
17 typedef void (*gb_connection_exit_t)(struct gb_connection *);
18 typedef int (*gb_request_recv_t)(u8, struct gb_operation *);
19
20 /*
21  * Protocols having the same id but different major and/or minor
22  * version numbers are treated as distinct protocols.  If it makes
23  * sense someday we could group protocols having the same id.
24  */
25 struct gb_protocol {
26         u8                      id;
27         u8                      major;
28         u8                      minor;
29         u8                      count;
30
31         struct list_head        links;          /* global list */
32
33         gb_connection_init_t    connection_init;
34         gb_connection_exit_t    connection_exit;
35         gb_request_recv_t       request_recv;
36         struct module           *owner;
37         char                    *name;
38 };
39
40 int __gb_protocol_register(struct gb_protocol *protocol, struct module *module);
41 void gb_protocol_deregister(struct gb_protocol *protocol);
42
43 #define gb_protocol_register(protocol) \
44         __gb_protocol_register(protocol, THIS_MODULE)
45
46 struct gb_protocol *gb_protocol_get(u8 id, u8 major, u8 minor);
47 int gb_protocol_get_version(struct gb_connection *connection);
48
49 void gb_protocol_put(struct gb_protocol *protocol);
50
51 /* __protocol: Pointer to struct gb_protocol */
52 #define gb_protocol_driver(__protocol)                  \
53 static int __init protocol_init(void)                   \
54 {                                                       \
55         return gb_protocol_register(__protocol);        \
56 }                                                       \
57 module_init(protocol_init);                             \
58 static void __exit protocol_exit(void)                  \
59 {                                                       \
60         gb_protocol_deregister(__protocol);             \
61 }                                                       \
62 module_exit(protocol_exit)
63
64 /* __protocol: string matching name of struct gb_protocol */
65 #define gb_builtin_protocol_driver(__protocol)          \
66 int __init gb_##__protocol##_init(void)                 \
67 {                                                       \
68         return gb_protocol_register(&__protocol);       \
69 }                                                       \
70 void gb_##__protocol##_exit(void)                       \
71 {                                                       \
72         gb_protocol_deregister(&__protocol);            \
73 }                                                       \
74
75 #endif /* __PROTOCOL_H */