Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Greybus protocol handling |
| 3 | * |
| 4 | * Copyright 2014 Google Inc. |
Alex Elder | a46e967 | 2014-12-12 12:08:42 -0600 | [diff] [blame] | 5 | * Copyright 2014 Linaro Ltd. |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 6 | * |
| 7 | * Released under the GPLv2 only. |
| 8 | */ |
| 9 | |
| 10 | #ifndef __PROTOCOL_H |
| 11 | #define __PROTOCOL_H |
| 12 | |
Johan Hovold | fed78bf | 2015-05-19 11:22:41 +0200 | [diff] [blame] | 13 | struct gb_connection; |
Alex Elder | f8fb05e | 2014-11-05 16:12:55 -0600 | [diff] [blame] | 14 | struct gb_operation; |
| 15 | |
Alex Elder | 5d9fd7e | 2014-11-05 16:12:54 -0600 | [diff] [blame] | 16 | typedef int (*gb_connection_init_t)(struct gb_connection *); |
| 17 | typedef void (*gb_connection_exit_t)(struct gb_connection *); |
Johan Hovold | 973ccfd | 2015-03-27 12:45:49 +0100 | [diff] [blame] | 18 | typedef int (*gb_request_recv_t)(u8, struct gb_operation *); |
Alex Elder | 5d9fd7e | 2014-11-05 16:12:54 -0600 | [diff] [blame] | 19 | |
Alex Elder | 6ae7fa4 | 2014-11-05 16:12:50 -0600 | [diff] [blame] | 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 | */ |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 25 | struct gb_protocol { |
Alex Elder | 6ae7fa4 | 2014-11-05 16:12:50 -0600 | [diff] [blame] | 26 | u8 id; |
| 27 | u8 major; |
| 28 | u8 minor; |
Alex Elder | 0e44765 | 2014-11-05 16:12:51 -0600 | [diff] [blame] | 29 | u8 count; |
Alex Elder | 6ae7fa4 | 2014-11-05 16:12:50 -0600 | [diff] [blame] | 30 | |
Alex Elder | 6ae7fa4 | 2014-11-05 16:12:50 -0600 | [diff] [blame] | 31 | struct list_head links; /* global list */ |
Alex Elder | 5d9fd7e | 2014-11-05 16:12:54 -0600 | [diff] [blame] | 32 | |
| 33 | gb_connection_init_t connection_init; |
| 34 | gb_connection_exit_t connection_exit; |
Alex Elder | f8fb05e | 2014-11-05 16:12:55 -0600 | [diff] [blame] | 35 | gb_request_recv_t request_recv; |
Greg Kroah-Hartman | 12a5dfc | 2014-12-24 13:01:40 -0800 | [diff] [blame] | 36 | struct module *owner; |
Greg Kroah-Hartman | 7422a1e | 2014-12-24 13:01:45 -0800 | [diff] [blame] | 37 | char *name; |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 38 | }; |
| 39 | |
Greg Kroah-Hartman | 12a5dfc | 2014-12-24 13:01:40 -0800 | [diff] [blame] | 40 | int __gb_protocol_register(struct gb_protocol *protocol, struct module *module); |
Johan Hovold | 7803384 | 2015-10-13 19:10:24 +0200 | [diff] [blame] | 41 | void gb_protocol_deregister(struct gb_protocol *protocol); |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 42 | |
Greg Kroah-Hartman | 12a5dfc | 2014-12-24 13:01:40 -0800 | [diff] [blame] | 43 | #define gb_protocol_register(protocol) \ |
| 44 | __gb_protocol_register(protocol, THIS_MODULE) |
| 45 | |
Alex Elder | 0e44765 | 2014-11-05 16:12:51 -0600 | [diff] [blame] | 46 | struct gb_protocol *gb_protocol_get(u8 id, u8 major, u8 minor); |
Viresh Kumar | 1cb5fa4 | 2015-08-12 11:04:06 +0530 | [diff] [blame] | 47 | int gb_protocol_get_version(struct gb_connection *connection); |
Viresh Kumar | 36e79de | 2015-01-21 18:12:36 +0530 | [diff] [blame] | 48 | |
Alex Elder | 0e44765 | 2014-11-05 16:12:51 -0600 | [diff] [blame] | 49 | void gb_protocol_put(struct gb_protocol *protocol); |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 50 | |
Alex Elder | 19d03de | 2014-11-05 16:12:53 -0600 | [diff] [blame] | 51 | /* |
| 52 | * These are defined in their respective protocol source files. |
| 53 | * Declared here for now. They could be added via modules, or maybe |
| 54 | * just use initcalls (which level?). |
| 55 | */ |
Greg Kroah-Hartman | 7c7d5b9 | 2014-12-23 15:16:51 -0800 | [diff] [blame] | 56 | extern int gb_gpio_protocol_init(void); |
Alex Elder | 19d03de | 2014-11-05 16:12:53 -0600 | [diff] [blame] | 57 | extern void gb_gpio_protocol_exit(void); |
| 58 | |
Greg Kroah-Hartman | 7c7d5b9 | 2014-12-23 15:16:51 -0800 | [diff] [blame] | 59 | extern int gb_pwm_protocol_init(void); |
Matt Porter | 34c6507 | 2014-11-13 09:14:13 -0500 | [diff] [blame] | 60 | extern void gb_pwm_protocol_exit(void); |
| 61 | |
Greg Kroah-Hartman | 7c7d5b9 | 2014-12-23 15:16:51 -0800 | [diff] [blame] | 62 | extern int gb_uart_protocol_init(void); |
Alex Elder | 19d03de | 2014-11-05 16:12:53 -0600 | [diff] [blame] | 63 | extern void gb_uart_protocol_exit(void); |
| 64 | |
Greg Kroah-Hartman | 7c7d5b9 | 2014-12-23 15:16:51 -0800 | [diff] [blame] | 65 | extern int gb_sdio_protocol_init(void); |
Alex Elder | 19d03de | 2014-11-05 16:12:53 -0600 | [diff] [blame] | 66 | extern void gb_sdio_protocol_exit(void); |
| 67 | |
Greg Kroah-Hartman | 7c7d5b9 | 2014-12-23 15:16:51 -0800 | [diff] [blame] | 68 | extern int gb_usb_protocol_init(void); |
Greg Kroah-Hartman | 615772a | 2014-11-25 16:59:21 -0800 | [diff] [blame] | 69 | extern void gb_usb_protocol_exit(void); |
| 70 | |
Greg Kroah-Hartman | 2c07817 | 2014-12-24 13:01:44 -0800 | [diff] [blame] | 71 | extern int gb_i2c_protocol_init(void); |
| 72 | extern void gb_i2c_protocol_exit(void); |
| 73 | |
Viresh Kumar | 15d651b | 2015-01-23 13:07:45 +0530 | [diff] [blame] | 74 | extern int gb_spi_protocol_init(void); |
| 75 | extern void gb_spi_protocol_exit(void); |
| 76 | |
Viresh Kumar | 27551b1 | 2015-05-20 17:20:09 +0530 | [diff] [blame] | 77 | /* __protocol: Pointer to struct gb_protocol */ |
Greg Kroah-Hartman | 900ceba | 2014-12-23 15:16:54 -0800 | [diff] [blame] | 78 | #define gb_protocol_driver(__protocol) \ |
| 79 | static int __init protocol_init(void) \ |
| 80 | { \ |
| 81 | return gb_protocol_register(__protocol); \ |
| 82 | } \ |
| 83 | module_init(protocol_init); \ |
| 84 | static void __exit protocol_exit(void) \ |
| 85 | { \ |
| 86 | gb_protocol_deregister(__protocol); \ |
| 87 | } \ |
Greg Kroah-Hartman | f487c80 | 2015-05-01 21:05:50 +0200 | [diff] [blame] | 88 | module_exit(protocol_exit) |
Greg Kroah-Hartman | 900ceba | 2014-12-23 15:16:54 -0800 | [diff] [blame] | 89 | |
Viresh Kumar | 27551b1 | 2015-05-20 17:20:09 +0530 | [diff] [blame] | 90 | /* __protocol: string matching name of struct gb_protocol */ |
Viresh Kumar | e18822e | 2015-07-01 12:13:52 +0530 | [diff] [blame] | 91 | #define gb_builtin_protocol_driver(__protocol) \ |
Viresh Kumar | 27551b1 | 2015-05-20 17:20:09 +0530 | [diff] [blame] | 92 | int __init gb_##__protocol##_init(void) \ |
| 93 | { \ |
| 94 | return gb_protocol_register(&__protocol); \ |
| 95 | } \ |
Johan Hovold | 8d346df | 2015-05-21 11:47:24 +0200 | [diff] [blame] | 96 | void gb_##__protocol##_exit(void) \ |
Viresh Kumar | 27551b1 | 2015-05-20 17:20:09 +0530 | [diff] [blame] | 97 | { \ |
| 98 | gb_protocol_deregister(&__protocol); \ |
| 99 | } \ |
| 100 | |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 101 | #endif /* __PROTOCOL_H */ |