drivers/firmware/thead,th1520-aon.c

Source file repositories/reference/linux-study-clean/drivers/firmware/thead,th1520-aon.c

File Facts

System
Linux kernel
Corpus path
drivers/firmware/thead,th1520-aon.c
Extension
.c
Size
7849 bytes
Lines
250
Domain
Driver Families
Bucket
drivers/firmware
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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 th1520_aon_chan {
	struct mbox_chan *ch;
	struct th1520_aon_rpc_ack_common ack_msg;
	struct mbox_client cl;
	struct completion done;

	/* make sure only one RPC is performed at a time */
	struct mutex transaction_lock;
};

struct th1520_aon_msg_req_set_resource_power_mode {
	struct th1520_aon_rpc_msg_hdr hdr;
	u16 resource;
	u16 mode;
	u16 reserved[10];
} __packed __aligned(1);

/*
 * This type is used to indicate error response for most functions.
 */
enum th1520_aon_error_codes {
	LIGHT_AON_ERR_NONE = 0, /* Success */
	LIGHT_AON_ERR_VERSION = 1, /* Incompatible API version */
	LIGHT_AON_ERR_CONFIG = 2, /* Configuration error */
	LIGHT_AON_ERR_PARM = 3, /* Bad parameter */
	LIGHT_AON_ERR_NOACCESS = 4, /* Permission error (no access) */
	LIGHT_AON_ERR_LOCKED = 5, /* Permission error (locked) */
	LIGHT_AON_ERR_UNAVAILABLE = 6, /* Unavailable (out of resources) */
	LIGHT_AON_ERR_NOTFOUND = 7, /* Not found */
	LIGHT_AON_ERR_NOPOWER = 8, /* No power */
	LIGHT_AON_ERR_IPC = 9, /* Generic IPC error */
	LIGHT_AON_ERR_BUSY = 10, /* Resource is currently busy/active */
	LIGHT_AON_ERR_FAIL = 11, /* General I/O failure */
	LIGHT_AON_ERR_LAST
};

static int th1520_aon_linux_errmap[LIGHT_AON_ERR_LAST] = {
	0, /* LIGHT_AON_ERR_NONE */
	-EINVAL, /* LIGHT_AON_ERR_VERSION */
	-EINVAL, /* LIGHT_AON_ERR_CONFIG */
	-EINVAL, /* LIGHT_AON_ERR_PARM */
	-EACCES, /* LIGHT_AON_ERR_NOACCESS */
	-EACCES, /* LIGHT_AON_ERR_LOCKED */
	-ERANGE, /* LIGHT_AON_ERR_UNAVAILABLE */
	-EEXIST, /* LIGHT_AON_ERR_NOTFOUND */
	-EPERM, /* LIGHT_AON_ERR_NOPOWER */
	-EPIPE, /* LIGHT_AON_ERR_IPC */
	-EBUSY, /* LIGHT_AON_ERR_BUSY */
	-EIO, /* LIGHT_AON_ERR_FAIL */
};

static inline int th1520_aon_to_linux_errno(int errno)
{
	if (errno >= LIGHT_AON_ERR_NONE && errno < LIGHT_AON_ERR_LAST)
		return th1520_aon_linux_errmap[errno];

	return -EIO;
}

static void th1520_aon_rx_callback(struct mbox_client *c, void *rx_msg)
{
	struct th1520_aon_chan *aon_chan =
		container_of(c, struct th1520_aon_chan, cl);
	struct th1520_aon_rpc_msg_hdr *hdr =
		(struct th1520_aon_rpc_msg_hdr *)rx_msg;
	u8 recv_size = sizeof(struct th1520_aon_rpc_msg_hdr) + hdr->size;

	if (recv_size != sizeof(struct th1520_aon_rpc_ack_common)) {
		dev_err(c->dev, "Invalid ack size, not completing\n");
		return;
	}

	memcpy(&aon_chan->ack_msg, rx_msg, recv_size);
	complete(&aon_chan->done);
}

/**
 * th1520_aon_call_rpc() - Send an RPC request to the TH1520 AON subsystem
 * @aon_chan: Pointer to the AON channel structure
 * @msg: Pointer to the message (RPC payload) that will be sent
 *
 * This function sends an RPC message to the TH1520 AON subsystem via mailbox.
 * It takes the provided @msg buffer, formats it with version and service flags,
 * then blocks until the RPC completes or times out. The completion is signaled
 * by the `aon_chan->done` completion, which is waited upon for a duration
 * defined by `MAX_RX_TIMEOUT`.
 *
 * Return:
 * * 0 on success
 * * -ETIMEDOUT if the RPC call times out

Annotation

Implementation Notes