drivers/usb/serial/spcp8x5.c

Source file repositories/reference/linux-study-clean/drivers/usb/serial/spcp8x5.c

File Facts

System
Linux kernel
Corpus path
drivers/usb/serial/spcp8x5.c
Extension
.c
Size
12688 bytes
Lines
481
Domain
Driver Families
Bucket
drivers/usb
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct spcp8x5_private {
	unsigned		quirks;
	spinlock_t		lock;
	u8			line_control;
};

static int spcp8x5_probe(struct usb_serial *serial,
						const struct usb_device_id *id)
{
	usb_set_serial_data(serial, (void *)id);

	return 0;
}

static int spcp8x5_port_probe(struct usb_serial_port *port)
{
	const struct usb_device_id *id = usb_get_serial_data(port->serial);
	struct spcp8x5_private *priv;

	priv = kzalloc_obj(*priv);
	if (!priv)
		return -ENOMEM;

	spin_lock_init(&priv->lock);
	priv->quirks = id->driver_info;

	usb_set_serial_port_data(port, priv);

	port->port.drain_delay = 256;

	return 0;
}

static void spcp8x5_port_remove(struct usb_serial_port *port)
{
	struct spcp8x5_private *priv;

	priv = usb_get_serial_port_data(port);
	kfree(priv);
}

static int spcp8x5_set_ctrl_line(struct usb_serial_port *port, u8 mcr)
{
	struct spcp8x5_private *priv = usb_get_serial_port_data(port);
	struct usb_device *dev = port->serial->dev;
	int retval;

	if (priv->quirks & SPCP825_QUIRK_NO_UART_STATUS)
		return -EPERM;

	retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
				 SET_UART_STATUS_TYPE, SET_UART_STATUS,
				 mcr, 0x04, NULL, 0, 100);
	if (retval != 0) {
		dev_err(&port->dev, "failed to set control lines: %d\n",
								retval);
	}
	return retval;
}

static int spcp8x5_get_msr(struct usb_serial_port *port, u8 *status)
{
	struct spcp8x5_private *priv = usb_get_serial_port_data(port);
	struct usb_device *dev = port->serial->dev;
	u8 *buf;
	int ret;

	if (priv->quirks & SPCP825_QUIRK_NO_UART_STATUS)
		return -EPERM;

	buf = kzalloc(1, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;

	ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
			      GET_UART_STATUS, GET_UART_STATUS_TYPE,
			      0, GET_UART_STATUS_MSR, buf, 1, 100);
	if (ret < 1) {
		dev_err(&port->dev, "failed to get modem status: %d\n", ret);
		if (ret >= 0)
			ret = -EIO;
		goto out;
	}

	dev_dbg(&port->dev, "0xc0:0x22:0:6  %d - 0x02%x\n", ret, *buf);
	*status = *buf;
	ret = 0;
out:
	kfree(buf);

Annotation

Implementation Notes