5136d0c9ecc802cb1a19da8a3cb1817970a86086
[cascardo/linux.git] / drivers / staging / greybus / hd.h
1 /*
2  * Greybus Host Device
3  *
4  * Copyright 2014-2015 Google Inc.
5  * Copyright 2014-2015 Linaro Ltd.
6  *
7  * Released under the GPLv2 only.
8  */
9
10 #ifndef __HD_H
11 #define __HD_H
12
13 struct gb_host_device;
14 struct gb_message;
15
16 struct gb_hd_driver {
17         size_t  hd_priv_size;
18
19         int (*cport_allocate)(struct gb_host_device *hd, int cport_id,
20                                 unsigned long flags);
21         void (*cport_release)(struct gb_host_device *hd, u16 cport_id);
22         int (*cport_enable)(struct gb_host_device *hd, u16 cport_id);
23         int (*cport_disable)(struct gb_host_device *hd, u16 cport_id);
24         int (*cport_flush)(struct gb_host_device *hd, u16 cport_id);
25         int (*cport_ping)(struct gb_host_device *hd, u16 cport_id);
26         int (*message_send)(struct gb_host_device *hd, u16 dest_cport_id,
27                         struct gb_message *message, gfp_t gfp_mask);
28         void (*message_cancel)(struct gb_message *message);
29         int (*latency_tag_enable)(struct gb_host_device *hd, u16 cport_id);
30         int (*latency_tag_disable)(struct gb_host_device *hd, u16 cport_id);
31         int (*output)(struct gb_host_device *hd, void *req, u16 size, u8 cmd,
32                       bool async);
33         int (*cport_features_enable)(struct gb_host_device *hd, u16 cport_id);
34         int (*cport_features_disable)(struct gb_host_device *hd, u16 cport_id);
35         int (*timesync_enable)(struct gb_host_device *hd, u8 count,
36                                u64 frame_time, u32 strobe_delay, u32 refclk);
37         int (*timesync_disable)(struct gb_host_device *hd);
38         int (*timesync_authoritative)(struct gb_host_device *hd,
39                                       u64 *frame_time);
40         int (*timesync_get_last_event)(struct gb_host_device *hd,
41                                        u64 *frame_time);
42 };
43
44 struct gb_host_device {
45         struct device dev;
46         int bus_id;
47         const struct gb_hd_driver *driver;
48
49         struct list_head modules;
50         struct list_head connections;
51         struct ida cport_id_map;
52
53         /* Number of CPorts supported by the UniPro IP */
54         size_t num_cports;
55
56         /* Host device buffer constraints */
57         size_t buffer_size_max;
58
59         struct gb_svc *svc;
60         /* Private data for the host driver */
61         unsigned long hd_priv[0] __aligned(sizeof(s64));
62 };
63 #define to_gb_host_device(d) container_of(d, struct gb_host_device, dev)
64
65 int gb_hd_cport_reserve(struct gb_host_device *hd, u16 cport_id);
66 void gb_hd_cport_release_reserved(struct gb_host_device *hd, u16 cport_id);
67 int gb_hd_cport_allocate(struct gb_host_device *hd, int cport_id,
68                                         unsigned long flags);
69 void gb_hd_cport_release(struct gb_host_device *hd, u16 cport_id);
70
71 struct gb_host_device *gb_hd_create(struct gb_hd_driver *driver,
72                                         struct device *parent,
73                                         size_t buffer_size_max,
74                                         size_t num_cports);
75 int gb_hd_add(struct gb_host_device *hd);
76 void gb_hd_del(struct gb_host_device *hd);
77 void gb_hd_put(struct gb_host_device *hd);
78 int gb_hd_output(struct gb_host_device *hd, void *req, u16 size, u8 cmd,
79                  bool in_irq);
80
81 int gb_hd_init(void);
82 void gb_hd_exit(void);
83
84 #endif  /* __HD_H */