1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2018 MediaTek Inc.
10 #include <linux/mailbox_client.h>
11 #include <linux/mailbox/mtk-cmdq-mailbox.h>
12 #include <linux/timer.h>
14 #define CMDQ_NO_TIMEOUT 0xffffffffu
21 struct mbox_client client;
22 struct mbox_chan *chan;
23 struct timer_list timer;
24 u32 timeout_ms; /* in unit of microsecond */
28 * cmdq_mbox_create() - create CMDQ mailbox client and channel
29 * @dev: device of CMDQ mailbox client
30 * @index: index of CMDQ mailbox channel
31 * @timeout: timeout of a pkt execution by GCE, in unit of microsecond, set
32 * CMDQ_NO_TIMEOUT if a timer is not used.
34 * Return: CMDQ mailbox client pointer
36 struct cmdq_client *cmdq_mbox_create(struct device *dev, int index,
40 * cmdq_mbox_destroy() - destroy CMDQ mailbox client and channel
41 * @client: the CMDQ mailbox client
43 void cmdq_mbox_destroy(struct cmdq_client *client);
46 * cmdq_pkt_create() - create a CMDQ packet
47 * @client: the CMDQ mailbox client
48 * @size: required CMDQ buffer size
50 * Return: CMDQ packet pointer
52 struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size);
55 * cmdq_pkt_destroy() - destroy the CMDQ packet
56 * @pkt: the CMDQ packet
58 void cmdq_pkt_destroy(struct cmdq_pkt *pkt);
61 * cmdq_pkt_write() - append write command to the CMDQ packet
62 * @pkt: the CMDQ packet
63 * @subsys: the CMDQ sub system code
64 * @offset: register offset from CMDQ sub system
65 * @value: the specified target register value
67 * Return: 0 for success; else the error code is returned
69 int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value);
72 * cmdq_pkt_write_mask() - append write command with mask to the CMDQ packet
73 * @pkt: the CMDQ packet
74 * @subsys: the CMDQ sub system code
75 * @offset: register offset from CMDQ sub system
76 * @value: the specified target register value
77 * @mask: the specified target register mask
79 * Return: 0 for success; else the error code is returned
81 int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys,
82 u16 offset, u32 value, u32 mask);
85 * cmdq_pkt_wfe() - append wait for event command to the CMDQ packet
86 * @pkt: the CMDQ packet
87 * @event: the desired event type to "wait and CLEAR"
89 * Return: 0 for success; else the error code is returned
91 int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event);
94 * cmdq_pkt_clear_event() - append clear event command to the CMDQ packet
95 * @pkt: the CMDQ packet
96 * @event: the desired event to be cleared
98 * Return: 0 for success; else the error code is returned
100 int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event);
103 * cmdq_pkt_flush_async() - trigger CMDQ to asynchronously execute the CMDQ
104 * packet and call back at the end of done packet
105 * @pkt: the CMDQ packet
106 * @cb: called at the end of done packet
107 * @data: this data will pass back to cb
109 * Return: 0 for success; else the error code is returned
111 * Trigger CMDQ to asynchronously execute the CMDQ packet and call back
112 * at the end of done packet. Note that this is an ASYNC function. When the
113 * function returned, it may or may not be finished.
115 int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb,
119 * cmdq_pkt_flush() - trigger CMDQ to execute the CMDQ packet
120 * @pkt: the CMDQ packet
122 * Return: 0 for success; else the error code is returned
124 * Trigger CMDQ to execute the CMDQ packet. Note that this is a
125 * synchronous flush function. When the function returned, the recorded
126 * commands have been done.
128 int cmdq_pkt_flush(struct cmdq_pkt *pkt);
130 #endif /* __MTK_CMDQ_H__ */