Tizen 2.1 base
[platform/upstream/hplip.git] / io / hpmud / musb.h
1 /*****************************************************************************\
2
3   musb.h - USB support for multi-point transport driver
4  
5   (c) 2010 Copyright Hewlett-Packard Development Company, LP
6
7   Permission is hereby granted, free of charge, to any person obtaining a copy 
8   of this software and associated documentation files (the "Software"), to deal 
9   in the Software without restriction, including without limitation the rights 
10   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
11   of the Software, and to permit persons to whom the Software is furnished to do 
12   so, subject to the following conditions:
13
14   The above copyright notice and this permission notice shall be included in all
15   copies or substantial portions of the Software.
16
17   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
18   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 
19   FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
20   COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
21   IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
22   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24   Author: Naga Samrat Chowdary Narla
25 \*****************************************************************************/
26
27 #ifndef _MUSB_H
28 #define _MUSB_H
29
30 #include <usb.h>
31 #include "hpmud.h"
32 #include "hpmudi.h"
33
34 #define LIBUSB_TIMEOUT 30000              /* milliseconds */
35 #define LIBUSB_CONTROL_REQ_TIMEOUT 5000
36
37 enum FD_ID
38 {
39    FD_NA=0,
40    FD_7_1_2,         /* bi-di interface */
41    FD_7_1_3,         /* 1284.4 interface */
42    FD_ff_1_1,        /* HP EWS interface */
43    FD_ff_2_1,        /* HP Soap Scan interface */
44    FD_ff_3_1,        /* HP Soap Fax interface */
45    FD_ff_ff_ff,        /* HP dot4 interface */
46    FD_ff_d4_0,        /* HP dot4 interface */
47    FD_ff_4_1,        /* orblite scan / rest scan interface */
48    FD_ff_1_0,        /* Marvell fax support*/
49    FD_ff_cc_0,
50    FD_ff_2_10,
51    MAX_FD
52 };
53
54 enum BRIGE_REG_ID
55 {
56    ECRR=2,
57    CCTR=3,
58    ATAA=8
59 };
60
61 /* USB file descriptor, one for each USB protocol. */
62 typedef struct
63 {
64    usb_dev_handle *hd;
65    enum FD_ID fd;
66    int config;
67    int interface;
68    int alt_setting;
69
70    /* Write thread definitions. */
71    int write_active;             /* 0=no, 1=yes */
72    const void *write_buf;
73    int write_size;
74    int write_return;             /* return value, normally number bytes written */
75    pthread_t tid;
76    pthread_mutex_t mutex;
77    pthread_cond_t write_done_cond;
78
79    unsigned char ubuf[HPMUD_BUFFER_SIZE];           /* usb read packet buffer */     
80    int uindex;
81    int ucnt;             
82 } file_descriptor;
83
84 struct _mud_device;
85 struct _mud_channel;
86
87 extern struct _mud_device_vf __attribute__ ((visibility ("hidden"))) musb_mud_device_vf;
88
89 int __attribute__ ((visibility ("hidden"))) musb_write(int fd, const void *buf, int size, int usec_timout);    
90 int __attribute__ ((visibility ("hidden"))) musb_read(int fd, void *buf, int size, int usec_timout); 
91 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_open(struct _mud_device *pd);                 
92 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_close(struct _mud_device *pd);                 
93 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_get_device_id(struct _mud_device *pd, char *buf, int size, int *len);
94 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_get_device_status(struct _mud_device *pd, unsigned int *status);
95 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_channel_open(struct _mud_device *pd, const char *sn, HPMUD_CHANNEL *cd);
96 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_channel_close(struct _mud_device *pd, struct _mud_channel *pc);
97 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_channel_write(struct _mud_device *pd, struct _mud_channel *pc, const void *buf, int length, int timeout, int *bytes_wrote);
98 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_channel_read(struct _mud_device *pd, struct _mud_channel *pc, void *buf, int length, int timeout, int *bytes_read);
99
100 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_raw_channel_open(struct _mud_channel *pc);
101 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_raw_channel_close(struct _mud_channel *pc);
102 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_raw_channel_write(struct _mud_channel *pc, const void *buf, int length, int timeout, int *bytes_wrote);
103 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_raw_channel_read(struct _mud_channel *pc, void *buf, int length, int timeout, int *bytes_wrote);
104
105 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_comp_channel_open(struct _mud_channel *pc);
106
107 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_mlc_channel_open(struct _mud_channel *pc);
108 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_mlc_channel_close(struct _mud_channel *pc);
109 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_mlc_channel_write(struct _mud_channel *pc, const void *buf, int length, int timeout, int *bytes_wrote);
110 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_mlc_channel_read(struct _mud_channel *pc, void *buf, int length, int timeout, int *bytes_wrote);
111
112 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_dot4_channel_open(struct _mud_channel *pc);
113 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_dot4_channel_close(struct _mud_channel *pc);
114 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_dot4_channel_write(struct _mud_channel *pc, const void *buf, int length, int sec_timeout, int *bytes_wrote);
115 enum HPMUD_RESULT __attribute__ ((visibility ("hidden"))) musb_dot4_channel_read(struct _mud_channel *pc, void *buf, int length, int sec_timeout, int *bytes_read);
116
117 int __attribute__ ((visibility ("hidden"))) musb_probe_devices(char *lst, int lst_size, int *cnt);
118 int __attribute__ ((visibility ("hidden"))) power_up(struct _mud_device *pd, int fd);
119
120 #endif // _MUSB_H
121