^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * USB ZyXEL omni.net LCD PLUS driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2013,2017 Johan Hovold <johan@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * See Documentation/usb/usb-serial.rst for more information on using this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Please report both successes and troubles to the author at omninet@kroah.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/tty_driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/tty_flip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/usb/serial.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define DRIVER_AUTHOR "Alessandro Zummo"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define DRIVER_DESC "USB ZyXEL omni.net LCD PLUS Driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define ZYXEL_VENDOR_ID 0x0586
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define ZYXEL_OMNINET_ID 0x1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define ZYXEL_OMNI_56K_PLUS_ID 0x1500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* This one seems to be a re-branded ZyXEL device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define BT_IGNITIONPRO_ID 0x2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* function prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static void omninet_process_read_urb(struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int omninet_prepare_write_buffer(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) void *buf, size_t count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static int omninet_calc_num_ports(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct usb_serial_endpoints *epds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int omninet_port_probe(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static int omninet_port_remove(struct usb_serial_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static const struct usb_device_id id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNI_56K_PLUS_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) { USB_DEVICE(ZYXEL_VENDOR_ID, BT_IGNITIONPRO_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) { } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) MODULE_DEVICE_TABLE(usb, id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static struct usb_serial_driver zyxel_omninet_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .name = "omninet",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .description = "ZyXEL - omni.net lcd plus usb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .id_table = id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .num_bulk_out = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .calc_num_ports = omninet_calc_num_ports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .port_probe = omninet_port_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .port_remove = omninet_port_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .process_read_urb = omninet_process_read_urb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .prepare_write_buffer = omninet_prepare_write_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static struct usb_serial_driver * const serial_drivers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) &zyxel_omninet_device, NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * The protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * The omni.net always exchange 64 bytes of data with the host. The first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * four bytes are the control header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * oh_seq is a sequence number. Don't know if/how it's used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * oh_len is the length of the data bytes in the packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * oh_xxx Bit-mapped, related to handshaking and status info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * I normally set it to 0x03 in transmitted frames.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * 7: Active when the TA is in a CONNECTed state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * 6: unknown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * 5: handshaking, unknown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * 4: handshaking, unknown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * 3: unknown, usually 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * 2: unknown, usually 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * 1: handshaking, unknown, usually set to 1 in transmitted frames
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * 0: handshaking, unknown, usually set to 1 in transmitted frames
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * oh_pad Probably a pad byte.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * After the header you will find data bytes if oh_len was greater than zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct omninet_header {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) __u8 oh_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) __u8 oh_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) __u8 oh_xxx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) __u8 oh_pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct omninet_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) __u8 od_outseq; /* Sequence number for bulk_out URBs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int omninet_calc_num_ports(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct usb_serial_endpoints *epds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* We need only the second bulk-out for our single-port device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) epds->bulk_out[0] = epds->bulk_out[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) epds->num_bulk_out = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int omninet_port_probe(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct omninet_data *od;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) od = kzalloc(sizeof(*od), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (!od)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) usb_set_serial_port_data(port, od);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static int omninet_port_remove(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct omninet_data *od;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) od = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) kfree(od);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #define OMNINET_HEADERLEN 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #define OMNINET_BULKOUTSIZE 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #define OMNINET_PAYLOADSIZE (OMNINET_BULKOUTSIZE - OMNINET_HEADERLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static void omninet_process_read_urb(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct usb_serial_port *port = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) const struct omninet_header *hdr = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) const unsigned char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) size_t data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (urb->actual_length <= OMNINET_HEADERLEN || !hdr->oh_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) data = (char *)urb->transfer_buffer + OMNINET_HEADERLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) data_len = min_t(size_t, urb->actual_length - OMNINET_HEADERLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) hdr->oh_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) tty_insert_flip_string(&port->port, data, data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) tty_flip_buffer_push(&port->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int omninet_prepare_write_buffer(struct usb_serial_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) void *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct omninet_data *od = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct omninet_header *header = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) count = min_t(size_t, count, OMNINET_PAYLOADSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) count = kfifo_out_locked(&port->write_fifo, buf + OMNINET_HEADERLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) count, &port->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) header->oh_seq = od->od_outseq++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) header->oh_len = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) header->oh_xxx = 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) header->oh_pad = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* always 64 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return OMNINET_BULKOUTSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) module_usb_serial_driver(serial_drivers, id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) MODULE_AUTHOR(DRIVER_AUTHOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) MODULE_LICENSE("GPL v2");