feaba01717862e8c64c120c2b6100400323910c5
[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                                 unsigned long flags);
24         int (*cport_disable)(struct gb_host_device *hd, u16 cport_id);
25         int (*cport_connected)(struct gb_host_device *hd, u16 cport_id);
26         int (*cport_flush)(struct gb_host_device *hd, u16 cport_id);
27         int (*cport_ping)(struct gb_host_device *hd, u16 cport_id);
28         int (*cport_quiesce)(struct gb_host_device *hd, u16 cport_id,
29                                 size_t peer_space, unsigned int timeout);
30         int (*message_send)(struct gb_host_device *hd, u16 dest_cport_id,
31                         struct gb_message *message, gfp_t gfp_mask);
32         void (*message_cancel)(struct gb_message *message);
33         int (*latency_tag_enable)(struct gb_host_device *hd, u16 cport_id);
34         int (*latency_tag_disable)(struct gb_host_device *hd, u16 cport_id);
35         int (*output)(struct gb_host_device *hd, void *req, u16 size, u8 cmd,
36                       bool async);
37         int (*cport_features_enable)(struct gb_host_device *hd, u16 cport_id);
38         int (*cport_features_disable)(struct gb_host_device *hd, u16 cport_id);
39         int (*timesync_enable)(struct gb_host_device *hd, u8 count,
40                                u64 frame_time, u32 strobe_delay, u32 refclk);
41         int (*timesync_disable)(struct gb_host_device *hd);
42         int (*timesync_authoritative)(struct gb_host_device *hd,
43                                       u64 *frame_time);
44         int (*timesync_get_last_event)(struct gb_host_device *hd,
45                                        u64 *frame_time);
46 };
47
48 struct gb_host_device {
49         struct device dev;
50         int bus_id;
51         const struct gb_hd_driver *driver;
52
53         struct list_head modules;
54         struct list_head connections;
55         struct ida cport_id_map;
56
57         /* Number of CPorts supported by the UniPro IP */
58         size_t num_cports;
59
60         /* Host device buffer constraints */
61         size_t buffer_size_max;
62
63         struct gb_svc *svc;
64         /* Private data for the host driver */
65         unsigned long hd_priv[0] __aligned(sizeof(s64));
66 };
67 #define to_gb_host_device(d) container_of(d, struct gb_host_device, dev)
68
69 int gb_hd_cport_reserve(struct gb_host_device *hd, u16 cport_id);
70 void gb_hd_cport_release_reserved(struct gb_host_device *hd, u16 cport_id);
71 int gb_hd_cport_allocate(struct gb_host_device *hd, int cport_id,
72                                         unsigned long flags);
73 void gb_hd_cport_release(struct gb_host_device *hd, u16 cport_id);
74
75 struct gb_host_device *gb_hd_create(struct gb_hd_driver *driver,
76                                         struct device *parent,
77                                         size_t buffer_size_max,
78                                         size_t num_cports);
79 int gb_hd_add(struct gb_host_device *hd);
80 void gb_hd_del(struct gb_host_device *hd);
81 void gb_hd_shutdown(struct gb_host_device *hd);
82 void gb_hd_put(struct gb_host_device *hd);
83 int gb_hd_output(struct gb_host_device *hd, void *req, u16 size, u8 cmd,
84                  bool in_irq);
85
86 int gb_hd_init(void);
87 void gb_hd_exit(void);
88
89 #endif  /* __HD_H */