1 #ifndef __LINUX_TAPI_H__
2 #define __LINUX_TAPI_H__
4 #include <linux/kernel.h>
5 #include <linux/device.h>
6 #include <linux/mutex.h>
8 #include <linux/input.h>
10 #include <asm/atomic.h>
11 #include <linux/list.h>
13 #include <linux/cdev.h>
15 #include <linux/skbuff.h>
16 #include <linux/wait.h>
18 #include <linux/tapi/tapi-event.h>
22 struct tapi_char_device
{
23 struct tapi_device
*tdev
;
28 static inline struct tapi_char_device
*cdev_to_tapi_char_device(struct cdev
*cdev
)
30 return container_of(cdev
, struct tapi_char_device
, cdev
);
33 int tapi_char_device_register(struct tapi_device
*tdev
,
34 struct tapi_char_device
*tchrdev
, const struct file_operations
*fops
);
37 struct tapi_endpoint
{
42 static inline void tapi_endpoint_set_data(struct tapi_endpoint
*ep
, void *data
)
47 static inline void *tapi_endpoint_get_data(struct tapi_endpoint
*ep
)
54 struct tapi_endpoint ep
;
55 struct input_dev
*input
;
56 struct tapi_char_device chrdev
;
61 struct list_head head
;
62 struct tapi_endpoint ep
;
64 struct sk_buff_head recv_queue
;
65 wait_queue_head_t recv_wait
;
66 struct sk_buff_head send_queue
;
71 struct list_head head
;
78 struct tapi_stream_config
{
79 enum tapi_codec codec
;
80 unsigned int buffer_size
;
84 int (*send_dtmf_events
)(struct tapi_device
*, struct tapi_port
*port
,
85 struct tapi_dtmf_event
*, size_t num_events
, unsigned int dealy
);
86 int (*send_dtmf_event
)(struct tapi_device
*, struct tapi_port
*port
,
87 struct tapi_dtmf_event
*);
88 int (*ring
)(struct tapi_device
*, struct tapi_port
*port
, bool ring
);
90 struct tapi_stream
*(*stream_alloc
)(struct tapi_device
*);
91 void (*stream_free
)(struct tapi_device
*, struct tapi_stream
*);
92 int (*stream_configure
)(struct tapi_device
*, struct tapi_stream
*,
93 struct tapi_stream_config
*);
94 int (*stream_start
)(struct tapi_device
*, struct tapi_stream
*);
95 int (*stream_stop
)(struct tapi_device
*, struct tapi_stream
*);
96 int (*stream_send
)(struct tapi_device
*, struct tapi_stream
*,
99 struct tapi_link
*(*link_alloc
)(struct tapi_device
*,
100 struct tapi_endpoint
*ep1
, struct tapi_endpoint
*ep2
);
101 void (*link_free
)(struct tapi_device
*, struct tapi_link
*);
102 int (*link_enable
)(struct tapi_device
*, struct tapi_link
*);
103 int (*link_disable
)(struct tapi_device
*, struct tapi_link
*);
105 int (*sync
)(struct tapi_device
*);
108 int tapi_stream_recv(struct tapi_device
*, struct tapi_stream
*, struct sk_buff
*);
113 const struct tapi_ops
*ops
;
114 unsigned int num_ports
;
120 struct tapi_port
*ports
;
121 struct list_head streams
;
122 struct list_head links
;
126 struct tapi_char_device stream_dev
;
127 struct tapi_char_device control_dev
;
130 static inline struct tapi_device
*dev_to_tapi(struct device
*dev
)
132 return container_of(dev
, struct tapi_device
, dev
);
135 static inline struct tapi_stream
*tapi_stream_from_id(struct tapi_device
*tdev
,
138 struct tapi_stream
*stream
;
140 mutex_lock(&tdev
->lock
);
142 list_for_each_entry(stream
, &tdev
->streams
, head
) {
143 if (stream
->id
== id
)
149 mutex_unlock(&tdev
->lock
);
153 struct tapi_link
*tapi_link_alloc(struct tapi_device
*, struct tapi_endpoint
*,
154 struct tapi_endpoint
*);
155 void tapi_link_free(struct tapi_device
*, struct tapi_link
*);
157 struct tapi_stream
*tapi_stream_alloc(struct tapi_device
*tdev
);
158 void tapi_stream_free(struct tapi_device
*tdev
, struct tapi_stream
*stream
);
160 static inline int tapi_sync(struct tapi_device
*tdev
)
162 if (!tdev
->ops
|| !tdev
->ops
->sync
)
165 return tdev
->ops
->sync(tdev
);
168 static inline int tapi_link_enable(struct tapi_device
*tdev
,
169 struct tapi_link
*link
)
171 if (!tdev
->ops
|| !tdev
->ops
->link_enable
)
174 return tdev
->ops
->link_enable(tdev
, link
);
177 static inline int tapi_link_disable(struct tapi_device
*tdev
,
178 struct tapi_link
*link
)
180 if (!tdev
->ops
|| !tdev
->ops
->link_disable
)
183 return tdev
->ops
->link_disable(tdev
, link
);
186 static inline int tapi_port_send_dtmf(struct tapi_device
*tdev
,
187 struct tapi_port
*port
, struct tapi_dtmf_event
*dtmf
)
189 if (!tdev
->ops
|| !tdev
->ops
->send_dtmf_event
)
192 return tdev
->ops
->send_dtmf_event(tdev
, port
, dtmf
);
195 static inline int tapi_port_set_ring(struct tapi_device
*tdev
,
196 struct tapi_port
*port
, bool ring
)
198 if (!tdev
->ops
|| !tdev
->ops
->ring
)
201 return tdev
->ops
->ring(tdev
, port
, ring
);
204 static inline int tapi_stream_start(struct tapi_device
*tdev
,
205 struct tapi_stream
*stream
)
207 if (!tdev
->ops
|| !tdev
->ops
->stream_start
)
210 return tdev
->ops
->stream_start(tdev
, stream
);
213 static inline int tapi_stream_stop(struct tapi_device
*tdev
,
214 struct tapi_stream
*stream
)
216 if (!tdev
->ops
|| !tdev
->ops
->stream_stop
)
219 return tdev
->ops
->stream_stop(tdev
, stream
);
222 int tapi_device_register(struct tapi_device
*tdev
, const char *name
,
223 struct device
*parent
);
224 void tapi_device_unregister(struct tapi_device
*tdev
);
226 struct tapi_sysfs_port
;
228 struct tapi_sysfs_port
*tapi_port_alloc(struct tapi_device
*tdev
, unsigned int id
);
229 void tapi_port_delete(struct tapi_sysfs_port
*);