blob: a236401b48abfc7c433e31d6fec73064d08f1b4d [file] [log] [blame]
Alex Elder4ccb6b72014-10-28 19:36:00 -05001/*
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 Elderf8fb05e2014-11-05 16:12:55 -060014struct gb_operation;
15
Alex Elder5d9fd7e2014-11-05 16:12:54 -060016typedef int (*gb_connection_init_t)(struct gb_connection *);
17typedef void (*gb_connection_exit_t)(struct gb_connection *);
Alex Elderf8fb05e2014-11-05 16:12:55 -060018typedef void (*gb_request_recv_t)(struct gb_operation *);
Alex Elder5d9fd7e2014-11-05 16:12:54 -060019
Alex Elder6ae7fa42014-11-05 16:12:50 -060020/*
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 Elder4ccb6b72014-10-28 19:36:00 -050025struct gb_protocol {
Alex Elder6ae7fa42014-11-05 16:12:50 -060026 u8 id;
27 u8 major;
28 u8 minor;
Alex Elder0e447652014-11-05 16:12:51 -060029 u8 count;
Alex Elder6ae7fa42014-11-05 16:12:50 -060030
Alex Elder6ae7fa42014-11-05 16:12:50 -060031 struct list_head links; /* global list */
Alex Elder5d9fd7e2014-11-05 16:12:54 -060032
33 gb_connection_init_t connection_init;
34 gb_connection_exit_t connection_exit;
Alex Elderf8fb05e2014-11-05 16:12:55 -060035 gb_request_recv_t request_recv;
Alex Elder4ccb6b72014-10-28 19:36:00 -050036};
37
Alex Elder19d03de2014-11-05 16:12:53 -060038bool gb_protocol_register(struct gb_protocol *protocol);
Alex Elder4ccb6b72014-10-28 19:36:00 -050039bool gb_protocol_deregister(struct gb_protocol *protocol);
40
Alex Elder0e447652014-11-05 16:12:51 -060041struct gb_protocol *gb_protocol_get(u8 id, u8 major, u8 minor);
42void gb_protocol_put(struct gb_protocol *protocol);
Alex Elder4ccb6b72014-10-28 19:36:00 -050043
Alex Elder19d03de2014-11-05 16:12:53 -060044/*
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 */
49extern bool gb_battery_protocol_init(void);
50extern void gb_battery_protocol_exit(void);
51
52extern bool gb_gpio_protocol_init(void);
53extern void gb_gpio_protocol_exit(void);
54
55extern bool gb_i2c_protocol_init(void);
56extern void gb_i2c_protocol_exit(void);
57
58extern bool gb_uart_protocol_init(void);
59extern void gb_uart_protocol_exit(void);
60
61extern bool gb_sdio_protocol_init(void);
62extern void gb_sdio_protocol_exit(void);
63
64bool gb_protocol_init(void);
65void gb_protocol_exit(void);
66
Alex Elder4ccb6b72014-10-28 19:36:00 -050067#endif /* __PROTOCOL_H */