#ifndef _USB_SERIAL_H_
#define _USB_SERIAL_H_
#include <sys/tty.h>
#include <sys/ttydefaults.h>
#include <sys/fcntl.h>
#include <sys/sysctl.h>
#include <sys/timepps.h>
#define SET(t, f) (t) |= (f)
#define CLR(t, f) (t) &= ~((unsigned)(f))
#define ISSET(t, f) ((t) & (f))
#define UCOM_MODVER 1
#define UCOM_MINVER 1
#define UCOM_PREFVER UCOM_MODVER
#define UCOM_MAXVER 1
#define UCOM_JITTERBUF_SIZE 128
struct usb_device;
struct ucom_softc;
struct usb_device_request;
struct thread;
struct ucom_callback {
void (*ucom_cfg_get_status) (struct ucom_softc *, uint8_t *plsr, uint8_t *pmsr);
void (*ucom_cfg_set_dtr) (struct ucom_softc *, uint8_t);
void (*ucom_cfg_set_rts) (struct ucom_softc *, uint8_t);
void (*ucom_cfg_set_break) (struct ucom_softc *, uint8_t);
void (*ucom_cfg_set_ring) (struct ucom_softc *, uint8_t);
void (*ucom_cfg_param) (struct ucom_softc *, struct termios *);
void (*ucom_cfg_open) (struct ucom_softc *);
void (*ucom_cfg_close) (struct ucom_softc *);
int (*ucom_pre_open) (struct ucom_softc *);
int (*ucom_pre_param) (struct ucom_softc *, struct termios *);
int (*ucom_ioctl) (struct ucom_softc *, uint32_t, caddr_t, int, struct thread *);
void (*ucom_start_read) (struct ucom_softc *);
void (*ucom_stop_read) (struct ucom_softc *);
void (*ucom_start_write) (struct ucom_softc *);
void (*ucom_stop_write) (struct ucom_softc *);
void (*ucom_tty_name) (struct ucom_softc *, char *pbuf, uint16_t buflen, uint16_t unit, uint16_t subunit);
void (*ucom_poll) (struct ucom_softc *);
void (*ucom_free) (struct ucom_softc *);
};
#define ULSR_RCV_FIFO 0x80
#define ULSR_TSRE 0x40
#define ULSR_TXRDY 0x20
#define ULSR_BI 0x10
#define ULSR_FE 0x08
#define ULSR_PE 0x04
#define ULSR_OE 0x02
#define ULSR_RXRDY 0x01
#define ULSR_RCV_MASK 0x1f
struct ucom_cfg_task {
struct usb_proc_msg hdr;
struct ucom_softc *sc;
};
struct ucom_param_task {
struct usb_proc_msg hdr;
struct ucom_softc *sc;
struct termios termios_copy;
};
struct ucom_super_softc {
struct usb_process sc_tq;
int sc_unit;
int sc_subunits;
int sc_refs;
int sc_flag;
struct sysctl_oid *sc_sysctl_ttyname;
struct sysctl_oid *sc_sysctl_ttyports;
char sc_ttyname[16];
};
struct ucom_softc {
struct ucom_cfg_task sc_start_task[2];
struct ucom_cfg_task sc_open_task[2];
struct ucom_cfg_task sc_close_task[2];
struct ucom_cfg_task sc_line_state_task[2];
struct ucom_cfg_task sc_status_task[2];
struct ucom_param_task sc_param_task[2];
struct pps_state sc_pps;
struct usb_proc_msg *sc_last_start_xfer;
const struct ucom_callback *sc_callback;
struct ucom_super_softc *sc_super;
struct tty *sc_tty;
struct dev *sc_dev;
cdev_t sc_cdev;
cdev_t sc_cdev_init;
cdev_t sc_cdev_lock;
cdev_t sc_cdev2;
cdev_t sc_cdev2_init;
cdev_t sc_cdev2_lock;
struct termios sc_it_in;
struct termios sc_it_out;
struct termios sc_lt_in;
struct termios sc_lt_out;
struct lock *sc_lock;
void *sc_parent;
int sc_subunit;
uint16_t sc_jitterbuf_in;
uint16_t sc_jitterbuf_out;
uint16_t sc_portno;
uint16_t sc_flag;
#define UCOM_FLAG_RTS_IFLOW 0x01
#define UCOM_FLAG_GONE 0x02
#define UCOM_FLAG_ATTACHED 0x04
#define UCOM_FLAG_GP_DATA 0x08
#define UCOM_FLAG_LL_READY 0x20
#define UCOM_FLAG_HL_READY 0x40
#define UCOM_FLAG_CONSOLE 0x80
#define UCOM_FLAG_WAIT_REFS 0x0100
#define UCOM_FLAG_FREE_UNIT 0x0200
#define UCOM_FLAG_INWAKEUP 0x0400
uint8_t sc_lsr;
uint8_t sc_msr;
uint8_t sc_mcr;
uint8_t sc_pls_set;
uint8_t sc_pls_clr;
uint8_t sc_pls_curr;
#define UCOM_LS_DTR 0x01
#define UCOM_LS_RTS 0x02
#define UCOM_LS_BREAK 0x04
#define UCOM_LS_RING 0x08
u_char hotchar;
uint8_t sc_jitterbuf[UCOM_JITTERBUF_SIZE];
};
#define UCOM_MTX_ASSERT(sc, what) KKASSERT(lockowned((sc)->sc_lock))
#define UCOM_MTX_LOCK(sc) lockmgr((sc)->sc_lock, LK_EXCLUSIVE)
#define UCOM_MTX_UNLOCK(sc) lockmgr((sc)->sc_lock, LK_RELEASE)
#define UCOM_UNLOAD_DRAIN(x) \
SYSUNINIT(var, SI_SUB_KLD - 3, SI_ORDER_ANY, ucom_drain_all, 0)
#define ucom_cfg_do_request(udev,com,req,ptr,flags,timo) \
usbd_do_request_proc(udev,&(com)->sc_super->sc_tq,req,ptr,flags,NULL,timo)
int ucom_attach(struct ucom_super_softc *,
struct ucom_softc *, int, void *,
const struct ucom_callback *callback, struct lock *);
void ucom_detach(struct ucom_super_softc *, struct ucom_softc *);
void ucom_set_pnpinfo_usb(struct ucom_super_softc *, device_t);
void ucom_status_change(struct ucom_softc *);
uint8_t ucom_get_data(struct ucom_softc *, struct usb_page_cache *,
uint32_t, uint32_t, uint32_t *);
void ucom_put_data(struct ucom_softc *, struct usb_page_cache *,
uint32_t, uint32_t);
uint8_t ucom_cfg_is_gone(struct ucom_softc *);
void ucom_drain(struct ucom_super_softc *);
void ucom_drain_all(void *);
void ucom_ref(struct ucom_super_softc *);
int ucom_unref(struct ucom_super_softc *);
#endif