1 /* 2 * Copyright (c) 2007-2008 by Michael Lotz 3 * Heavily based on the original usb_serial driver which is: 4 * 5 * Copyright (c) 2003 by Siarzhuk Zharski <imker@gmx.li> 6 * Distributed under the terms of the MIT License. 7 */ 8 #ifndef _PC_SERIAL_DRIVER_H_ 9 #define _PC_SERIAL_DRIVER_H_ 10 11 #include <OS.h> 12 #include <KernelExport.h> 13 #include <Drivers.h> 14 #include <string.h> 15 16 #ifdef __HAIKU__ 17 #include <lock.h> 18 #else 19 #include "BeOSCompatibility.h" 20 #endif 21 #include "kernel_cpp.h" 22 #include "Tracing.h" 23 24 extern "C" { 25 #include <ttylayer.h> 26 } 27 28 #define DRIVER_NAME "pc_serial" // driver name for debug output 29 #define DEVICES_COUNT 20 // max simultaneously open devices 30 31 /* Some usefull helper defines ... */ 32 #define SIZEOF(array) (sizeof(array) / sizeof(array[0])) /* size of array */ 33 /* This one rounds the size to integral count of segs (segments) */ 34 #define ROUNDUP(size, seg) (((size) + (seg) - 1) & ~((seg) - 1)) 35 /* Default device buffer size */ 36 #define DEF_BUFFER_SIZE 0x200 37 38 /* line coding defines ... Come from CDC USB specs? */ 39 #define LC_STOP_BIT_1 0 40 #define LC_STOP_BIT_2 2 41 42 #define LC_PARITY_NONE 0 43 #define LC_PARITY_ODD 1 44 #define LC_PARITY_EVEN 2 45 46 /* struct that represents line coding */ 47 typedef struct pc_serial_line_coding_s { 48 uint32 speed; 49 uint8 stopbits; 50 uint8 parity; 51 uint8 databits; 52 } pc_serial_line_coding; 53 54 /* control line states */ 55 #define CLS_LINE_DTR 0x0001 56 #define CLS_LINE_RTS 0x0002 57 58 /* attributes etc ...*/ 59 #ifndef USB_EP_ADDR_DIR_IN 60 #define USB_EP_ADDR_DIR_IN 0x80 61 #define USB_EP_ADDR_DIR_OUT 0x00 62 #endif 63 64 #ifndef USB_EP_ATTR_CONTROL 65 #define USB_EP_ATTR_CONTROL 0x00 66 #define USB_EP_ATTR_ISOCHRONOUS 0x01 67 #define USB_EP_ATTR_BULK 0x02 68 #define USB_EP_ATTR_INTERRUPT 0x03 69 #endif 70 71 /* USB class - communication devices */ 72 #define USB_DEV_CLASS_COMM 0x02 73 #define USB_INT_CLASS_CDC 0x02 74 #define USB_INT_SUBCLASS_ACM 0x02 75 #define USB_INT_CLASS_CDC_DATA 0x0a 76 #define USB_INT_SUBCLASS_DATA 0x00 77 78 // communication device subtypes 79 #define FUNCTIONAL_SUBTYPE_UNION 0x06 80 81 extern isa_module_info *gISAModule; 82 extern pci_module_info *gPCIModule; 83 extern tty_module_info *gTTYModule; 84 extern struct ddomain gSerialDomain; 85 86 extern "C" { 87 status_t pc_serial_device_added(pc_device device, void **cookie); 88 status_t pc_serial_device_removed(void *cookie); 89 90 status_t init_hardware(); 91 void uninit_driver(); 92 93 bool pc_serial_service(struct tty *ptty, struct ddrover *ddr, uint flags); 94 95 status_t pc_serial_open(const char *name, uint32 flags, void **cookie); 96 status_t pc_serial_read(void *cookie, off_t position, void *buffer, size_t *numBytes); 97 status_t pc_serial_write(void *cookie, off_t position, const void *buffer, size_t *numBytes); 98 status_t pc_serial_control(void *cookie, uint32 op, void *arg, size_t length); 99 status_t pc_serial_select(void *cookie, uint8 event, uint32 ref, selectsync *sync); 100 status_t pc_serial_deselect(void *coookie, uint8 event, selectsync *sync); 101 status_t pc_serial_close(void *cookie); 102 status_t pc_serial_free(void *cookie); 103 104 const char **publish_devices(); 105 device_hooks *find_device(const char *name); 106 } 107 108 #endif //_PC_SERIAL_DRIVER_H_ 109