43#include <sys/stdint.h>
44#include <sys/stddef.h>
49#include <sys/kernel.h>
51#include <sys/module.h>
54#include <sys/condvar.h>
55#include <sys/sysctl.h>
57#include <sys/unistd.h>
58#include <sys/callout.h>
59#include <sys/malloc.h>
61#include <sys/syslog.h>
62#include <sys/selinfo.h>
72#define USB_DEBUG_VAR ulpt_debug
77static int ulpt_debug = 0;
79static SYSCTL_NODE(_hw_usb, OID_AUTO, ulpt, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
82 &ulpt_debug, 0,
"Debug level");
85#define ULPT_BSIZE (1<<15)
86#define ULPT_IFQ_MAXLEN 2
88#define UR_GET_DEVICE_ID 0x00
89#define UR_GET_PORT_STATUS 0x01
90#define UR_SOFT_RESET 0x02
93#define LPS_SELECT 0x10
94#define LPS_NOPAPER 0x20
95#define LPS_INVERT (LPS_SELECT|LPS_NERR)
96#define LPS_MASK (LPS_SELECT|LPS_NERR|LPS_NOPAPER)
154 .basename[0] =
"ulpt",
165 .basename[0] =
"unlpt",
314 new_status = cur_status & ~sc->sc_last_status;
318 log(LOG_NOTICE,
"%s: offline\n",
319 device_get_nameunit(sc->
sc_dev));
321 log(LOG_NOTICE,
"%s: out of paper\n",
322 device_get_nameunit(sc->
sc_dev));
324 log(LOG_NOTICE,
"%s: output error\n",
325 device_get_nameunit(sc->
sc_dev));
360 .flags = {.pipe_bof = 1,.proxy_buffer = 1},
369 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,.proxy_buffer = 1},
438 if (fflags & FREAD) {
451 if (fflags & FWRITE) {
464 sc->
sc_fflags |= fflags & (FREAD | FWRITE);
473 sc->
sc_fflags &= ~(fflags & (FREAD | FWRITE));
475 if (fflags & (FREAD | FWRITE)) {
519 return (BUS_PROBE_GENERIC);
528 int unit = device_get_unit(
dev);
533 DPRINTFN(11,
"sc=%p\n", sc);
540 mtx_init(&sc->
sc_mtx,
"ulpt lock", NULL, MTX_DEF | MTX_RECURSE);
553 (
id->bLength >=
sizeof(*
id))) {
573 "config number: %d\n", alt_index);
577 (uaa->
device, iface_index, alt_index);
580 DPRINTF(
"could not set alternate "
594 device_printf(sc->
sc_dev,
"using bi-directional mode\n");
610 USETW2(
req.wIndex,
id->bInterfaceNumber,
id->bAlternateSetting);
611 USETW(
req.wLength,
sizeof devinfo - 1);
615 device_printf(sc->
sc_dev,
"cannot get device id\n");
616 }
else if (alen <= 2) {
617 device_printf(sc->
sc_dev,
"empty device id, no "
618 "printer connected?\n");
621 len = ((devinfo[0] & 0xff) << 8) | (devinfo[1] & 0xff);
622 if (
len >
sizeof devinfo - 3)
623 len =
sizeof devinfo - 3;
625 printf(
"%s: device id <", device_get_nameunit(sc->
sc_dev));
626 ieee1284_print_id(devinfo + 2);
635 UID_ROOT, GID_OPERATOR, 0644);
642 UID_ROOT, GID_OPERATOR, 0644);
687ieee1284_compare(
const char *a,
const char *b)
706ieee1284_print_id(
char *str)
710 for (p = str - 1; p; p = strchr(p,
';')) {
712 if (ieee1284_compare(p,
"MFG:") == 0 ||
713 ieee1284_compare(p,
"MANUFACTURER:") == 0 ||
714 ieee1284_compare(p,
"MDL:") == 0 ||
715 ieee1284_compare(p,
"MODEL:") == 0) {
718 printf(
"%.*s", (
int)(q - p + 1), p);
730 mtx_assert(&sc->
sc_mtx, MA_OWNED);
static SYSCTL_NODE(_hw_usb, OID_AUTO, dwc_otg, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "USB DWC OTG")
SYSCTL_INT(_hw_usb_dwc_otg, OID_AUTO, phy_type, CTLFLAG_RDTUN, &dwc_otg_phy_type, 0, "DWC OTG PHY TYPE - 0/1/2/3 - ULPI/HSIC/INTERNAL/UTMI+")
struct usb_fifo_sc sc_fifo
struct usb_fifo * sc_fifo_open[2]
struct usb_fifo_sc sc_fifo_noreset
struct usb_device * sc_udev
struct usb_callout sc_watchdog
struct usb_xfer * sc_xfer[ULPT_N_TRANSFER]
enum usb_hc_mode usb_mode
struct usbd_lookup_info info
struct usb_interface * iface
struct usb_device * device
uByte bConfigurationValue
usb_fifo_close_t * f_close
USB_PNP_HOST_INFO(ulpt_devs)
static usb_fifo_close_t ulpt_close
static usb_fifo_ioctl_t ulpt_ioctl
static usb_fifo_cmd_t ulpt_start_read
static usb_callback_t ulpt_write_callback
static usb_fifo_cmd_t ulpt_start_write
static struct usb_fifo_methods unlpt_fifo_methods
static void ulpt_watchdog(void *)
static void ulpt_reset(struct ulpt_softc *)
static const STRUCT_USB_HOST_ID ulpt_devs[]
static device_attach_t ulpt_attach
static driver_t ulpt_driver
static const struct usb_config ulpt_config[ULPT_N_TRANSFER]
static usb_fifo_cmd_t ulpt_stop_read
static device_detach_t ulpt_detach
static usb_fifo_open_t unlpt_open
static usb_fifo_cmd_t ulpt_stop_write
DRIVER_MODULE(ulpt, uhub, ulpt_driver, ulpt_devclass, NULL, 0)
static device_method_t ulpt_methods[]
#define UR_GET_PORT_STATUS
MODULE_DEPEND(ulpt, usb, 1, 1, 1)
static usb_callback_t ulpt_status_callback
static usb_callback_t ulpt_read_callback
static usb_fifo_open_t ulpt_open
static device_probe_t ulpt_probe
static struct usb_fifo_methods ulpt_fifo_methods
static devclass_t ulpt_devclass
#define UIPROTO_PRINTER_1284
#define UT_WRITE_CLASS_OTHER
#define UISUBCLASS_PRINTER
#define UIPROTO_PRINTER_BI
#define UT_READ_CLASS_INTERFACE
#define UT_WRITE_CLASS_INTERFACE
#define UIPROTO_PRINTER_UNI
void usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset, const void *ptr, usb_frlength_t len)
void usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset, void *ptr, usb_frlength_t len)
usb_error_t usbd_set_alt_interface_index(struct usb_device *udev, uint8_t iface_index, uint8_t alt_index)
struct usb_interface_descriptor * usbd_get_interface_descriptor(struct usb_interface *iface)
struct usb_config_descriptor * usbd_get_config_descriptor(struct usb_device *udev)
#define USETW2(w, b1, b0)
const char * usbd_errstr(usb_error_t err)
int usbd_lookup_id_by_uaa(const struct usb_device_id *id, usb_size_t sizeof_id, struct usb_attach_arg *uaa)
struct usb_descriptor * usb_desc_foreach(struct usb_config_descriptor *cd, struct usb_descriptor *_desc)
usb_error_t usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx, struct usb_device_request *req, void *data, uint16_t flags, uint16_t *actlen, usb_timeout_t timeout)
void usbd_transfer_submit(struct usb_xfer *xfer)
void usbd_xfer_set_frames(struct usb_xfer *xfer, usb_frcount_t n)
void usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup)
void usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex, usb_frlength_t len)
struct usb_page_cache * usbd_xfer_get_frame(struct usb_xfer *xfer, usb_frcount_t frindex)
usb_error_t usbd_transfer_setup(struct usb_device *udev, const uint8_t *ifaces, struct usb_xfer **ppxfer, const struct usb_config *setup_start, uint16_t n_setup, void *priv_sc, struct mtx *xfer_mtx)
void usbd_transfer_start(struct usb_xfer *xfer)
void * usbd_xfer_softc(struct usb_xfer *xfer)
void usbd_xfer_set_stall(struct usb_xfer *xfer)
void usbd_xfer_set_interval(struct usb_xfer *xfer, int i)
void usbd_transfer_stop(struct usb_xfer *xfer)
void usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen, int *aframes, int *nframes)
usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer)
void device_set_usb_desc(device_t dev)
int usb_fifo_alloc_buffer(struct usb_fifo *f, uint32_t bufsize, uint16_t nbuf)
#define USB_DEFAULT_TIMEOUT
int() usb_fifo_ioctl_t(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags)
#define USB_IFACE_SUBCLASS(isc)
void * usb_fifo_softc(struct usb_fifo *fifo)
void() usb_fifo_close_t(struct usb_fifo *fifo, int fflags)
#define usb_callout_init_mtx(c, m, f)
void usb_fifo_detach(struct usb_fifo_sc *f_sc)
void usb_fifo_put_data(struct usb_fifo *fifo, struct usb_page_cache *pc, usb_frlength_t offset, usb_frlength_t len, uint8_t what)
int usb_fifo_attach(struct usb_device *udev, void *priv_sc, struct mtx *priv_mtx, struct usb_fifo_methods *pm, struct usb_fifo_sc *f_sc, uint16_t unit, int16_t subunit, uint8_t iface_index, uid_t uid, gid_t gid, int mode)
#define usb_callout_reset(c,...)
void() usb_fifo_cmd_t(struct usb_fifo *fifo)
void usb_fifo_free_buffer(struct usb_fifo *f)
#define USB_IFACE_CLASS(ic)
uint8_t usb_fifo_get_data(struct usb_fifo *fifo, struct usb_page_cache *pc, usb_frlength_t offset, usb_frlength_t len, usb_frlength_t *actlen, uint8_t what)
#define USB_SHORT_XFER_OK
#define usb_callout_drain(c)
#define USB_ST_TRANSFERRED
#define USB_IFACE_PROTOCOL(ip)
void() usb_callback_t(struct usb_xfer *, usb_error_t)
int() usb_fifo_open_t(struct usb_fifo *fifo, int fflags)
#define STRUCT_USB_HOST_ID
#define usb_callout_stop(c)
#define USB_GET_STATE(xfer)
uint32_t usb_fifo_put_bytes_max(struct usb_fifo *fifo)