drivers/nfc/s3fwrn5/uart.c

Source file repositories/reference/linux-study-clean/drivers/nfc/s3fwrn5/uart.c

File Facts

System
Linux kernel
Corpus path
drivers/nfc/s3fwrn5/uart.c
Extension
.c
Size
4156 bytes
Lines
177
Domain
Driver Families
Bucket
drivers/nfc
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 s3fwrn82_uart_phy {
	struct phy_common common;
	struct serdev_device *ser_dev;
	struct sk_buff *recv_skb;
};

static int s3fwrn82_uart_write(void *phy_id, struct sk_buff *out)
{
	struct s3fwrn82_uart_phy *phy = phy_id;
	int err;

	err = serdev_device_write(phy->ser_dev,
				  out->data, out->len,
				  MAX_SCHEDULE_TIMEOUT);
	if (err < 0)
		return err;

	return 0;
}

static const struct s3fwrn5_phy_ops uart_phy_ops = {
	.set_wake = s3fwrn5_phy_set_wake,
	.set_mode = s3fwrn5_phy_set_mode,
	.get_mode = s3fwrn5_phy_get_mode,
	.write = s3fwrn82_uart_write,
};

static size_t s3fwrn82_uart_read(struct serdev_device *serdev,
				 const u8 *data, size_t count)
{
	struct s3fwrn82_uart_phy *phy = serdev_device_get_drvdata(serdev);
	size_t i;

	for (i = 0; i < count; i++) {
		if (!phy->recv_skb) {
			phy->recv_skb = alloc_skb(NCI_SKB_BUFF_LEN, GFP_KERNEL);
			if (!phy->recv_skb)
				return i;
		}

		skb_put_u8(phy->recv_skb, *data++);

		if (phy->recv_skb->len < S3FWRN82_NCI_HEADER)
			continue;

		if ((phy->recv_skb->len - S3FWRN82_NCI_HEADER)
				< phy->recv_skb->data[S3FWRN82_NCI_IDX])
			continue;

		s3fwrn5_recv_frame(phy->common.ndev, phy->recv_skb,
				   phy->common.mode);
		phy->recv_skb = NULL;
	}

	return i;
}

static const struct serdev_device_ops s3fwrn82_serdev_ops = {
	.receive_buf = s3fwrn82_uart_read,
	.write_wakeup = serdev_device_write_wakeup,
};

static const struct of_device_id s3fwrn82_uart_of_match[] = {
	{ .compatible = "samsung,s3fwrn82", },
	{},
};
MODULE_DEVICE_TABLE(of, s3fwrn82_uart_of_match);

static int s3fwrn82_uart_probe(struct serdev_device *serdev)
{
	struct s3fwrn82_uart_phy *phy;
	int ret = -ENOMEM;

	phy = devm_kzalloc(&serdev->dev, sizeof(*phy), GFP_KERNEL);
	if (!phy)
		goto err_exit;

	phy->recv_skb = alloc_skb(NCI_SKB_BUFF_LEN, GFP_KERNEL);
	if (!phy->recv_skb)
		goto err_exit;

	mutex_init(&phy->common.mutex);
	phy->common.mode = S3FWRN5_MODE_COLD;

	phy->ser_dev = serdev;
	serdev_device_set_drvdata(serdev, phy);
	serdev_device_set_client_ops(serdev, &s3fwrn82_serdev_ops);
	ret = serdev_device_open(serdev);
	if (ret) {
		dev_err(&serdev->dev, "Unable to open device\n");

Annotation

Implementation Notes