Home | History | Annotate | Line # | Download | only in usb
ucomvar.h revision 1.22
      1 /*	$NetBSD: ucomvar.h,v 1.22 2019/05/04 08:04:13 mrg Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson (lennart (at) augustsson.net) at
      9  * Carlstedt Research & Technology.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 
     34 /* just for ucom_attach_args, not in the config namespace */
     35 #define UCOM_UNK_PORTNO (-1)
     36 
     37 struct	ucom_softc;
     38 
     39 /*
     40  * The first argument to the ucom callbacks is the passed in ucaa_arg
     41  * member of the attach args, typically the parent softc pointer.
     42  *
     43  * All of these are optional.
     44  */
     45 struct ucom_methods {
     46 	/*
     47 	 * arg2: port number
     48 	 * arg3: pointer to lsr (always non NULL)
     49 	 * arg4: pointer to msr (always non NULL)
     50 	 */
     51 	void (*ucom_get_status)(void *, int, u_char *, u_char *);
     52 	/*
     53 	 * arg2: port number
     54 	 * arg3: value to turn on or off (DTR, RTS, BREAK)
     55 	 * arg4: onoff
     56 	 */
     57 	void (*ucom_set)(void *, int, int, int);
     58 #define UCOM_SET_DTR 1
     59 #define UCOM_SET_RTS 2
     60 #define UCOM_SET_BREAK 3
     61 	/*
     62 	 * arg2: port number
     63 	 * arg3: termios structure to set parameters from
     64 	 */
     65 	int (*ucom_param)(void *, int, struct termios *);
     66 	/*
     67 	 * arg2: port number
     68 	 * arg3: ioctl command
     69 	 * arg4: ioctl data
     70 	 * arg5: ioctl flags
     71 	 * arg6: process calling ioctl
     72 	 */
     73 	int (*ucom_ioctl)(void *, int, u_long, void *, int, proc_t *);
     74 	/* arg2: port number */
     75 	int (*ucom_open)(void *, int);
     76 	/* arg2: port number */
     77 	void (*ucom_close)(void *, int);
     78 	/*
     79 	 * arg2: port number
     80 	 * arg3: pointer to buffer pointer
     81 	 * arg4: pointer to buffer count
     82 	 *
     83 	 * Note: The 'ptr' (3nd arg) and 'count' (4rd arg) pointers can be
     84 	 * adjusted as follows:
     85 	 *
     86 	 *  ptr:	If consuming characters from the start of the buffer,
     87 	 *		advance '*ptr' to skip the data consumed.
     88 	 *
     89 	 *  count:	If consuming characters at the end of the buffer,
     90 	 *		decrement '*count' by the number of characters
     91 	 *		consumed.
     92 	 *
     93 	 * If consuming all characters, set '*count' to zero.
     94 	 */
     95 	void (*ucom_read)(void *, int, u_char **, uint32_t *);
     96 	/*
     97 	 * arg2: port number
     98 	 * arg3: pointer to source buffer
     99 	 * arg4: pointer to destination buffer
    100 	 * arg5: pointer to buffer count
    101 	 */
    102 	void (*ucom_write)(void *, int, u_char *, u_char *, uint32_t *);
    103 };
    104 
    105 /* modem control register */
    106 #define	UMCR_RTS	0x02	/* Request To Send */
    107 #define	UMCR_DTR	0x01	/* Data Terminal Ready */
    108 
    109 /* line status register */
    110 #define	ULSR_RCV_FIFO	0x80
    111 #define	ULSR_TSRE	0x40	/* Transmitter empty: byte sent */
    112 #define	ULSR_TXRDY	0x20	/* Transmitter buffer empty */
    113 #define	ULSR_BI		0x10	/* Break detected */
    114 #define	ULSR_FE		0x08	/* Framing error: bad stop bit */
    115 #define	ULSR_PE		0x04	/* Parity error */
    116 #define	ULSR_OE		0x02	/* Overrun, lost incoming byte */
    117 #define	ULSR_RXRDY	0x01	/* Byte ready in Receive Buffer */
    118 #define	ULSR_RCV_MASK	0x1f	/* Mask for incoming data or error */
    119 
    120 /* modem status register */
    121 /* All deltas are from the last read of the MSR. */
    122 #define	UMSR_DCD	0x80	/* Current Data Carrier Detect */
    123 #define	UMSR_RI		0x40	/* Current Ring Indicator */
    124 #define	UMSR_DSR	0x20	/* Current Data Set Ready */
    125 #define	UMSR_CTS	0x10	/* Current Clear to Send */
    126 #define	UMSR_DDCD	0x08	/* DCD has changed state */
    127 #define	UMSR_TERI	0x04	/* RI has toggled low to high */
    128 #define	UMSR_DDSR	0x02	/* DSR has changed state */
    129 #define	UMSR_DCTS	0x01	/* CTS has changed state */
    130 
    131 struct ucom_attach_args {
    132 	int ucaa_portno;
    133 	int ucaa_bulkin;
    134 	int ucaa_bulkout;
    135 	u_int ucaa_ibufsize;
    136 	u_int ucaa_ibufsizepad;
    137 	u_int ucaa_obufsize;
    138 	u_int ucaa_opkthdrlen;
    139 	const char *ucaa_info;	/* attach message */
    140 	struct usbd_device *ucaa_device;
    141 	struct usbd_interface *ucaa_iface;
    142 	const struct ucom_methods *ucaa_methods;
    143 	void *ucaa_arg;
    144 };
    145 
    146 int ucomprint(void *, const char *);
    147 int ucomsubmatch(device_t t, cfdata_t, const int *, void *);
    148 void ucom_status_change(struct ucom_softc *);
    149