FreeBSD kernel usb device Code
uplcom.c File Reference
#include <sys/cdefs.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usb_cdc.h>
#include "usbdevs.h"
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/serial/usb_serial.h>
Include dependency graph for uplcom.c:

Go to the source code of this file.

Data Structures

struct  uplcom_softc
 

Macros

#define USB_DEBUG_VAR   uplcom_debug
 
#define UPLCOM_MODVER   1 /* module version */
 
#define UPLCOM_CONFIG_INDEX   0
 
#define UPLCOM_IFACE_INDEX   0
 
#define UPLCOM_SECOND_IFACE_INDEX   1
 
#define UPLCOM_INTR_INTERVAL   0 /* default */
 
#define UPLCOM_BULK_BUF_SIZE   1024 /* bytes */
 
#define UPLCOM_SET_REQUEST   0x01
 
#define UPLCOM_SET_REQUEST_PL2303HXN   0x80
 
#define UPLCOM_SET_CRTSCTS   0x41
 
#define UPLCOM_SET_CRTSCTS_PL2303X   0x61
 
#define UPLCOM_SET_CRTSCTS_PL2303HXN   0xFA
 
#define UPLCOM_CLEAR_CRTSCTS_PL2303HXN   0xFF
 
#define UPLCOM_CRTSCTS_REG_PL2303HXN   0x0A
 
#define UPLCOM_STATUS_REG_PL2303HX   0x8080
 
#define RSAQ_STATUS_CTS   0x80
 
#define RSAQ_STATUS_OVERRUN_ERROR   0x40
 
#define RSAQ_STATUS_PARITY_ERROR   0x20
 
#define RSAQ_STATUS_FRAME_ERROR   0x10
 
#define RSAQ_STATUS_RING   0x08
 
#define RSAQ_STATUS_BREAK_ERROR   0x04
 
#define RSAQ_STATUS_DSR   0x02
 
#define RSAQ_STATUS_DCD   0x01
 
#define TYPE_PL2303   0
 
#define TYPE_PL2303HX   1
 
#define TYPE_PL2303HXD   2
 
#define TYPE_PL2303HXN   3
 
#define UPLCOM_STATE_INDEX   8
 
#define UPLCOM_DEV(v, p)    { USB_VENDOR(USB_VENDOR_##v), USB_PRODUCT(USB_PRODUCT_##v##_##p) }
 
#define N_UPLCOM_RATES   nitems(uplcom_rates)
 

Enumerations

enum  { UPLCOM_BULK_DT_WR , UPLCOM_BULK_DT_RD , UPLCOM_INTR_DT_RD , UPLCOM_N_TRANSFER }
 

Functions

 __FBSDID ("$FreeBSD$")
 
static usb_error_t uplcom_reset (struct uplcom_softc *, struct usb_device *)
 
static usb_error_t uplcom_pl2303_do (struct usb_device *, uint8_t, uint8_t, uint16_t, uint16_t, uint16_t)
 
static int uplcom_pl2303_init (struct usb_device *, uint8_t)
 
static void uplcom_free (struct ucom_softc *)
 
static void uplcom_cfg_set_dtr (struct ucom_softc *, uint8_t)
 
static void uplcom_cfg_set_rts (struct ucom_softc *, uint8_t)
 
static void uplcom_cfg_set_break (struct ucom_softc *, uint8_t)
 
static int uplcom_pre_param (struct ucom_softc *, struct termios *)
 
static void uplcom_cfg_param (struct ucom_softc *, struct termios *)
 
static void uplcom_start_read (struct ucom_softc *)
 
static void uplcom_stop_read (struct ucom_softc *)
 
static void uplcom_start_write (struct ucom_softc *)
 
static void uplcom_stop_write (struct ucom_softc *)
 
static void uplcom_cfg_get_status (struct ucom_softc *, uint8_t *, uint8_t *)
 
static void uplcom_poll (struct ucom_softc *ucom)
 
static void uplcom_free_softc (struct uplcom_softc *)
 
 DRIVER_MODULE (uplcom, uhub, uplcom_driver, uplcom_devclass, NULL, 0)
 
 MODULE_DEPEND (uplcom, ucom, 1, 1, 1)
 
 MODULE_DEPEND (uplcom, usb, 1, 1, 1)
 
 MODULE_VERSION (uplcom, UPLCOM_MODVER)
 
 USB_PNP_HOST_INFO (uplcom_devs)
 
static int uplcom_probe (device_t dev)
 
static int uplcom_attach (device_t dev)
 
static int uplcom_detach (device_t dev)
 
 UCOM_UNLOAD_DRAIN (uplcom)
 
static int uplcom_baud_supported (unsigned int speed)
 
static unsigned int uplcom_encode_baud_rate_divisor (uint8_t *buf, unsigned int baud)
 
static void uplcom_intr_callback (struct usb_xfer *xfer, usb_error_t error)
 
static void uplcom_write_callback (struct usb_xfer *xfer, usb_error_t error)
 
static void uplcom_read_callback (struct usb_xfer *xfer, usb_error_t error)
 

Variables

static device_probe_t uplcom_probe
 
static device_attach_t uplcom_attach
 
static device_detach_t uplcom_detach
 
static usb_callback_t uplcom_intr_callback
 
static usb_callback_t uplcom_write_callback
 
static usb_callback_t uplcom_read_callback
 
static const struct usb_config uplcom_config_data [UPLCOM_N_TRANSFER]
 
static struct ucom_callback uplcom_callback
 
static const STRUCT_USB_HOST_ID uplcom_devs []
 
static device_method_t uplcom_methods []
 
static devclass_t uplcom_devclass
 
static driver_t uplcom_driver
 
static const uint32_t uplcom_rates []
 

Macro Definition Documentation

◆ N_UPLCOM_RATES

#define N_UPLCOM_RATES   nitems(uplcom_rates)

Definition at line 762 of file uplcom.c.

◆ RSAQ_STATUS_BREAK_ERROR

#define RSAQ_STATUS_BREAK_ERROR   0x04

Definition at line 147 of file uplcom.c.

◆ RSAQ_STATUS_CTS

#define RSAQ_STATUS_CTS   0x80

Definition at line 142 of file uplcom.c.

◆ RSAQ_STATUS_DCD

#define RSAQ_STATUS_DCD   0x01

Definition at line 149 of file uplcom.c.

◆ RSAQ_STATUS_DSR

#define RSAQ_STATUS_DSR   0x02

Definition at line 148 of file uplcom.c.

◆ RSAQ_STATUS_FRAME_ERROR

#define RSAQ_STATUS_FRAME_ERROR   0x10

Definition at line 145 of file uplcom.c.

◆ RSAQ_STATUS_OVERRUN_ERROR

#define RSAQ_STATUS_OVERRUN_ERROR   0x40

Definition at line 143 of file uplcom.c.

◆ RSAQ_STATUS_PARITY_ERROR

#define RSAQ_STATUS_PARITY_ERROR   0x20

Definition at line 144 of file uplcom.c.

◆ RSAQ_STATUS_RING

#define RSAQ_STATUS_RING   0x08

Definition at line 146 of file uplcom.c.

◆ TYPE_PL2303

#define TYPE_PL2303   0

Definition at line 151 of file uplcom.c.

◆ TYPE_PL2303HX

#define TYPE_PL2303HX   1

Definition at line 152 of file uplcom.c.

◆ TYPE_PL2303HXD

#define TYPE_PL2303HXD   2

Definition at line 153 of file uplcom.c.

◆ TYPE_PL2303HXN

#define TYPE_PL2303HXN   3

Definition at line 154 of file uplcom.c.

◆ UPLCOM_BULK_BUF_SIZE

#define UPLCOM_BULK_BUF_SIZE   1024 /* bytes */

Definition at line 132 of file uplcom.c.

◆ UPLCOM_CLEAR_CRTSCTS_PL2303HXN

#define UPLCOM_CLEAR_CRTSCTS_PL2303HXN   0xFF

Definition at line 139 of file uplcom.c.

◆ UPLCOM_CONFIG_INDEX

#define UPLCOM_CONFIG_INDEX   0

Definition at line 124 of file uplcom.c.

◆ UPLCOM_CRTSCTS_REG_PL2303HXN

#define UPLCOM_CRTSCTS_REG_PL2303HXN   0x0A

Definition at line 140 of file uplcom.c.

◆ UPLCOM_DEV

#define UPLCOM_DEV (   v,
 
)     { USB_VENDOR(USB_VENDOR_##v), USB_PRODUCT(USB_PRODUCT_##v##_##p) }

Definition at line 259 of file uplcom.c.

◆ UPLCOM_IFACE_INDEX

#define UPLCOM_IFACE_INDEX   0

Definition at line 125 of file uplcom.c.

◆ UPLCOM_INTR_INTERVAL

#define UPLCOM_INTR_INTERVAL   0 /* default */

Definition at line 129 of file uplcom.c.

◆ UPLCOM_MODVER

#define UPLCOM_MODVER   1 /* module version */

Definition at line 122 of file uplcom.c.

◆ UPLCOM_SECOND_IFACE_INDEX

#define UPLCOM_SECOND_IFACE_INDEX   1

Definition at line 126 of file uplcom.c.

◆ UPLCOM_SET_CRTSCTS

#define UPLCOM_SET_CRTSCTS   0x41

Definition at line 136 of file uplcom.c.

◆ UPLCOM_SET_CRTSCTS_PL2303HXN

#define UPLCOM_SET_CRTSCTS_PL2303HXN   0xFA

Definition at line 138 of file uplcom.c.

◆ UPLCOM_SET_CRTSCTS_PL2303X

#define UPLCOM_SET_CRTSCTS_PL2303X   0x61

Definition at line 137 of file uplcom.c.

◆ UPLCOM_SET_REQUEST

#define UPLCOM_SET_REQUEST   0x01

Definition at line 134 of file uplcom.c.

◆ UPLCOM_SET_REQUEST_PL2303HXN

#define UPLCOM_SET_REQUEST_PL2303HXN   0x80

Definition at line 135 of file uplcom.c.

◆ UPLCOM_STATE_INDEX

#define UPLCOM_STATE_INDEX   8

Definition at line 156 of file uplcom.c.

◆ UPLCOM_STATUS_REG_PL2303HX

#define UPLCOM_STATUS_REG_PL2303HX   0x8080

Definition at line 141 of file uplcom.c.

◆ USB_DEBUG_VAR

#define USB_DEBUG_VAR   uplcom_debug

Definition at line 107 of file uplcom.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
UPLCOM_BULK_DT_WR 
UPLCOM_BULK_DT_RD 
UPLCOM_INTR_DT_RD 
UPLCOM_N_TRANSFER 

Definition at line 158 of file uplcom.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DRIVER_MODULE()

DRIVER_MODULE ( uplcom  ,
uhub  ,
uplcom_driver  ,
uplcom_devclass  ,
NULL  ,
 
)

◆ MODULE_DEPEND() [1/2]

MODULE_DEPEND ( uplcom  ,
ucom  ,
,
,
 
)

◆ MODULE_DEPEND() [2/2]

MODULE_DEPEND ( uplcom  ,
usb  ,
,
,
 
)

◆ MODULE_VERSION()

MODULE_VERSION ( uplcom  ,
UPLCOM_MODVER   
)

◆ UCOM_UNLOAD_DRAIN()

UCOM_UNLOAD_DRAIN ( uplcom  )

◆ uplcom_attach()

◆ uplcom_baud_supported()

static int uplcom_baud_supported ( unsigned int  speed)
static

Definition at line 765 of file uplcom.c.

References N_UPLCOM_RATES, and uplcom_rates.

Referenced by uplcom_cfg_param(), and uplcom_pre_param().

Here is the caller graph for this function:

◆ uplcom_cfg_get_status()

static void uplcom_cfg_get_status ( struct ucom_softc ucom,
uint8_t *  lsr,
uint8_t *  msr 
)
static

Definition at line 1010 of file uplcom.c.

References DPRINTF, uplcom_softc::sc_lsr, uplcom_softc::sc_msr, and ucom_softc::sc_parent.

◆ uplcom_cfg_param()

◆ uplcom_cfg_set_break()

static void uplcom_cfg_set_break ( struct ucom_softc ucom,
uint8_t  onoff 
)
static

◆ uplcom_cfg_set_dtr()

◆ uplcom_cfg_set_rts()

◆ uplcom_detach()

static int uplcom_detach ( device_t  dev)
static

◆ uplcom_encode_baud_rate_divisor()

static unsigned int uplcom_encode_baud_rate_divisor ( uint8_t *  buf,
unsigned int  baud 
)
static

Definition at line 818 of file uplcom.c.

References DPRINTF.

Referenced by uplcom_cfg_param().

Here is the caller graph for this function:

◆ uplcom_free()

static void uplcom_free ( struct ucom_softc ucom)
static

Definition at line 584 of file uplcom.c.

References ucom_softc::sc_parent, and uplcom_free_softc().

Here is the call graph for this function:

◆ uplcom_free_softc()

static void uplcom_free_softc ( struct uplcom_softc sc)
static

Definition at line 575 of file uplcom.c.

References uplcom_softc::sc_mtx, uplcom_softc::sc_super_ucom, and ucom_unref().

Referenced by uplcom_detach(), and uplcom_free().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uplcom_intr_callback()

◆ uplcom_pl2303_do()

static usb_error_t uplcom_pl2303_do ( struct usb_device udev,
uint8_t  req_type,
uint8_t  request,
uint16_t  value,
uint16_t  index,
uint16_t  length 
)
static

Definition at line 610 of file uplcom.c.

References DPRINTF, index, req, usbd_do_request, usbd_errstr(), USETW, and value.

Referenced by uplcom_attach(), and uplcom_pl2303_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uplcom_pl2303_init()

static int uplcom_pl2303_init ( struct usb_device udev,
uint8_t  chiptype 
)
static

Definition at line 632 of file uplcom.c.

References TYPE_PL2303, TYPE_PL2303HXN, uplcom_pl2303_do(), UPLCOM_SET_REQUEST, UT_READ_VENDOR_DEVICE, and UT_WRITE_VENDOR_DEVICE.

Referenced by uplcom_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uplcom_poll()

static void uplcom_poll ( struct ucom_softc ucom)
static

Definition at line 1148 of file uplcom.c.

References ucom_softc::sc_parent, uplcom_softc::sc_xfer, UPLCOM_N_TRANSFER, and usbd_transfer_poll().

Here is the call graph for this function:

◆ uplcom_pre_param()

static int uplcom_pre_param ( struct ucom_softc ucom,
struct termios *  t 
)
static

Check requested baud rate.

The PL2303 can only set specific baud rates, up to 1228800 baud. The PL2303HX can set any baud rate up to 6Mb. The PL2303HX rev. D and PL2303HXN can set any baud rate up to 12Mb.

Definition at line 776 of file uplcom.c.

References DPRINTF, uplcom_softc::sc_chiptype, ucom_softc::sc_parent, TYPE_PL2303HX, TYPE_PL2303HXD, TYPE_PL2303HXN, and uplcom_baud_supported().

Here is the call graph for this function:

◆ uplcom_probe()

static int uplcom_probe ( device_t  dev)
static

◆ uplcom_read_callback()

static void uplcom_read_callback ( struct usb_xfer xfer,
usb_error_t  error 
)
static

◆ uplcom_reset()

static usb_error_t uplcom_reset ( struct uplcom_softc sc,
struct usb_device udev 
)
static

Definition at line 590 of file uplcom.c.

References req, uplcom_softc::sc_chiptype, uplcom_softc::sc_data_iface_no, TYPE_PL2303HXN, UPLCOM_SET_REQUEST, usbd_do_request, USETW, and UT_WRITE_VENDOR_DEVICE.

Referenced by uplcom_attach().

Here is the caller graph for this function:

◆ uplcom_start_read()

static void uplcom_start_read ( struct ucom_softc ucom)
static

Definition at line 970 of file uplcom.c.

References ucom_softc::sc_parent, uplcom_softc::sc_xfer, UPLCOM_BULK_DT_RD, UPLCOM_INTR_DT_RD, and usbd_transfer_start().

Here is the call graph for this function:

◆ uplcom_start_write()

static void uplcom_start_write ( struct ucom_softc ucom)
static

Definition at line 994 of file uplcom.c.

References ucom_softc::sc_parent, uplcom_softc::sc_xfer, UPLCOM_BULK_DT_WR, and usbd_transfer_start().

Here is the call graph for this function:

◆ uplcom_stop_read()

static void uplcom_stop_read ( struct ucom_softc ucom)
static

Definition at line 982 of file uplcom.c.

References ucom_softc::sc_parent, uplcom_softc::sc_xfer, UPLCOM_BULK_DT_RD, UPLCOM_INTR_DT_RD, and usbd_transfer_stop().

Here is the call graph for this function:

◆ uplcom_stop_write()

static void uplcom_stop_write ( struct ucom_softc ucom)
static

Definition at line 1002 of file uplcom.c.

References ucom_softc::sc_parent, uplcom_softc::sc_xfer, UPLCOM_BULK_DT_WR, and usbd_transfer_stop().

Here is the call graph for this function:

◆ uplcom_write_callback()

static void uplcom_write_callback ( struct usb_xfer xfer,
usb_error_t  error 
)
static

◆ USB_PNP_HOST_INFO()

USB_PNP_HOST_INFO ( uplcom_devs  )

Variable Documentation

◆ uplcom_attach

device_attach_t uplcom_attach
static

Definition at line 204 of file uplcom.c.

◆ uplcom_callback

struct ucom_callback uplcom_callback
static
Initial value:
= {
.ucom_cfg_get_status = &uplcom_cfg_get_status,
.ucom_cfg_set_dtr = &uplcom_cfg_set_dtr,
.ucom_cfg_set_rts = &uplcom_cfg_set_rts,
.ucom_cfg_set_break = &uplcom_cfg_set_break,
.ucom_cfg_param = &uplcom_cfg_param,
.ucom_pre_param = &uplcom_pre_param,
.ucom_start_read = &uplcom_start_read,
.ucom_stop_read = &uplcom_stop_read,
.ucom_start_write = &uplcom_start_write,
.ucom_stop_write = &uplcom_stop_write,
.ucom_poll = &uplcom_poll,
.ucom_free = &uplcom_free,
}
static void uplcom_poll(struct ucom_softc *ucom)
Definition: uplcom.c:1148
static int uplcom_pre_param(struct ucom_softc *, struct termios *)
Definition: uplcom.c:776
static void uplcom_start_write(struct ucom_softc *)
Definition: uplcom.c:994
static void uplcom_stop_read(struct ucom_softc *)
Definition: uplcom.c:982
static void uplcom_cfg_set_rts(struct ucom_softc *, uint8_t)
Definition: uplcom.c:688
static void uplcom_stop_write(struct ucom_softc *)
Definition: uplcom.c:1002
static void uplcom_cfg_set_break(struct ucom_softc *, uint8_t)
Definition: uplcom.c:712
static void uplcom_free(struct ucom_softc *)
Definition: uplcom.c:584
static void uplcom_start_read(struct ucom_softc *)
Definition: uplcom.c:970
static void uplcom_cfg_set_dtr(struct ucom_softc *, uint8_t)
Definition: uplcom.c:664
static void uplcom_cfg_get_status(struct ucom_softc *, uint8_t *, uint8_t *)
Definition: uplcom.c:1010
static void uplcom_cfg_param(struct ucom_softc *, struct termios *)
Definition: uplcom.c:860

Definition at line 244 of file uplcom.c.

Referenced by uplcom_attach().

◆ uplcom_config_data

const struct usb_config uplcom_config_data[UPLCOM_N_TRANSFER]
static

Definition at line 212 of file uplcom.c.

Referenced by uplcom_attach().

◆ uplcom_detach

device_detach_t uplcom_detach
static

Definition at line 205 of file uplcom.c.

Referenced by uplcom_attach().

◆ uplcom_devclass

devclass_t uplcom_devclass
static

Definition at line 340 of file uplcom.c.

◆ uplcom_devs

const STRUCT_USB_HOST_ID uplcom_devs[]
static

Definition at line 262 of file uplcom.c.

Referenced by uplcom_probe().

◆ uplcom_driver

driver_t uplcom_driver
static
Initial value:
= {
.name = "uplcom",
.methods = uplcom_methods,
.size = sizeof(struct uplcom_softc),
}
static device_method_t uplcom_methods[]
Definition: uplcom.c:333

Definition at line 342 of file uplcom.c.

◆ uplcom_intr_callback

usb_callback_t uplcom_intr_callback
static

Definition at line 208 of file uplcom.c.

◆ uplcom_methods

device_method_t uplcom_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, uplcom_probe),
DEVMETHOD(device_attach, uplcom_attach),
DEVMETHOD(device_detach, uplcom_detach),
DEVMETHOD_END
}
static device_probe_t uplcom_probe
Definition: uplcom.c:203
static device_detach_t uplcom_detach
Definition: uplcom.c:205
static device_attach_t uplcom_attach
Definition: uplcom.c:204

Definition at line 333 of file uplcom.c.

◆ uplcom_probe

device_probe_t uplcom_probe
static

Definition at line 203 of file uplcom.c.

◆ uplcom_rates

const uint32_t uplcom_rates[]
static
Initial value:
= {
75, 150, 300, 600, 900, 1200, 1800, 2400, 3600, 4800, 7200, 9600, 14400,
19200, 28800, 38400, 56000, 57600, 115200,
128000, 134400, 161280, 201600, 230400, 268800, 403200, 460800, 614400,
806400, 921600, 1228800, 2457600, 3000000, 6000000,
12000000
}

Definition at line 743 of file uplcom.c.

Referenced by uplcom_baud_supported().

◆ uplcom_read_callback

usb_callback_t uplcom_read_callback
static

Definition at line 210 of file uplcom.c.

◆ uplcom_write_callback

usb_callback_t uplcom_write_callback
static

Definition at line 209 of file uplcom.c.