Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Greybus protocol handling |
| 3 | * |
| 4 | * Copyright 2014 Google Inc. |
| 5 | * |
| 6 | * Released under the GPLv2 only. |
| 7 | */ |
| 8 | |
| 9 | #ifndef __PROTOCOL_H |
| 10 | #define __PROTOCOL_H |
| 11 | |
| 12 | #include "greybus.h" |
| 13 | |
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 *); |
Alex Elder | f8fb05e | 2014-11-05 16:12:55 -0600 | [diff] [blame] | 18 | typedef void (*gb_request_recv_t)(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; |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 36 | }; |
| 37 | |
Alex Elder | 19d03de | 2014-11-05 16:12:53 -0600 | [diff] [blame] | 38 | bool gb_protocol_register(struct gb_protocol *protocol); |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 39 | bool gb_protocol_deregister(struct gb_protocol *protocol); |
| 40 | |
Alex Elder | 0e44765 | 2014-11-05 16:12:51 -0600 | [diff] [blame] | 41 | struct gb_protocol *gb_protocol_get(u8 id, u8 major, u8 minor); |
| 42 | void gb_protocol_put(struct gb_protocol *protocol); |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 43 | |
Alex Elder | 19d03de | 2014-11-05 16:12:53 -0600 | [diff] [blame] | 44 | /* |
| 45 | * These are defined in their respective protocol source files. |
| 46 | * Declared here for now. They could be added via modules, or maybe |
| 47 | * just use initcalls (which level?). |
| 48 | */ |
| 49 | extern bool gb_battery_protocol_init(void); |
| 50 | extern void gb_battery_protocol_exit(void); |
| 51 | |
| 52 | extern bool gb_gpio_protocol_init(void); |
| 53 | extern void gb_gpio_protocol_exit(void); |
| 54 | |
| 55 | extern bool gb_i2c_protocol_init(void); |
| 56 | extern void gb_i2c_protocol_exit(void); |
| 57 | |
| 58 | extern bool gb_uart_protocol_init(void); |
| 59 | extern void gb_uart_protocol_exit(void); |
| 60 | |
| 61 | extern bool gb_sdio_protocol_init(void); |
| 62 | extern void gb_sdio_protocol_exit(void); |
| 63 | |
| 64 | bool gb_protocol_init(void); |
| 65 | void gb_protocol_exit(void); |
| 66 | |
Alex Elder | 4ccb6b7 | 2014-10-28 19:36:00 -0500 | [diff] [blame] | 67 | #endif /* __PROTOCOL_H */ |