1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (c) 2018 MediaTek Inc. 4 * 5 */ 6 7 #ifndef __MTK_CMDQ_H__ 8 #define __MTK_CMDQ_H__ 9 10 #include <linux/mailbox_client.h> 11 #include <linux/mailbox/mtk-cmdq-mailbox.h> 12 #include <linux/timer.h> 13 14 #define CMDQ_NO_TIMEOUT 0xffffffffu 15 16 /** cmdq event maximum */ 17 #define CMDQ_MAX_EVENT 0x3ff 18 19 struct cmdq_pkt; 20 21 struct cmdq_client { 22 spinlock_t lock; 23 u32 pkt_cnt; 24 struct mbox_client client; 25 struct mbox_chan *chan; 26 struct timer_list timer; 27 u32 timeout_ms; /* in unit of microsecond */ 28 }; 29 30 /** 31 * cmdq_mbox_create() - create CMDQ mailbox client and channel 32 * @dev: device of CMDQ mailbox client 33 * @index: index of CMDQ mailbox channel 34 * @timeout: timeout of a pkt execution by GCE, in unit of microsecond, set 35 * CMDQ_NO_TIMEOUT if a timer is not used. 36 * 37 * Return: CMDQ mailbox client pointer 38 */ 39 struct cmdq_client *cmdq_mbox_create(struct device *dev, int index, 40 u32 timeout); 41 42 /** 43 * cmdq_mbox_destroy() - destroy CMDQ mailbox client and channel 44 * @client: the CMDQ mailbox client 45 */ 46 void cmdq_mbox_destroy(struct cmdq_client *client); 47 48 /** 49 * cmdq_pkt_create() - create a CMDQ packet 50 * @client: the CMDQ mailbox client 51 * @size: required CMDQ buffer size 52 * 53 * Return: CMDQ packet pointer 54 */ 55 struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size); 56 57 /** 58 * cmdq_pkt_destroy() - destroy the CMDQ packet 59 * @pkt: the CMDQ packet 60 */ 61 void cmdq_pkt_destroy(struct cmdq_pkt *pkt); 62 63 /** 64 * cmdq_pkt_write() - append write command to the CMDQ packet 65 * @pkt: the CMDQ packet 66 * @value: the specified target register value 67 * @subsys: the CMDQ sub system code 68 * @offset: register offset from CMDQ sub system 69 * 70 * Return: 0 for success; else the error code is returned 71 */ 72 int cmdq_pkt_write(struct cmdq_pkt *pkt, u32 value, u32 subsys, u32 offset); 73 74 /** 75 * cmdq_pkt_write_mask() - append write command with mask to the CMDQ packet 76 * @pkt: the CMDQ packet 77 * @value: the specified target register value 78 * @subsys: the CMDQ sub system code 79 * @offset: register offset from CMDQ sub system 80 * @mask: the specified target register mask 81 * 82 * Return: 0 for success; else the error code is returned 83 */ 84 int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u32 value, 85 u32 subsys, u32 offset, u32 mask); 86 87 /** 88 * cmdq_pkt_wfe() - append wait for event command to the CMDQ packet 89 * @pkt: the CMDQ packet 90 * @event: the desired event type to "wait and CLEAR" 91 * 92 * Return: 0 for success; else the error code is returned 93 */ 94 int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u32 event); 95 96 /** 97 * cmdq_pkt_clear_event() - append clear event command to the CMDQ packet 98 * @pkt: the CMDQ packet 99 * @event: the desired event to be cleared 100 * 101 * Return: 0 for success; else the error code is returned 102 */ 103 int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u32 event); 104 105 /** 106 * cmdq_pkt_flush_async() - trigger CMDQ to asynchronously execute the CMDQ 107 * packet and call back at the end of done packet 108 * @pkt: the CMDQ packet 109 * @cb: called at the end of done packet 110 * @data: this data will pass back to cb 111 * 112 * Return: 0 for success; else the error code is returned 113 * 114 * Trigger CMDQ to asynchronously execute the CMDQ packet and call back 115 * at the end of done packet. Note that this is an ASYNC function. When the 116 * function returned, it may or may not be finished. 117 */ 118 int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb, 119 void *data); 120 121 /** 122 * cmdq_pkt_flush() - trigger CMDQ to execute the CMDQ packet 123 * @pkt: the CMDQ packet 124 * 125 * Return: 0 for success; else the error code is returned 126 * 127 * Trigger CMDQ to execute the CMDQ packet. Note that this is a 128 * synchronous flush function. When the function returned, the recorded 129 * commands have been done. 130 */ 131 int cmdq_pkt_flush(struct cmdq_pkt *pkt); 132 133 #endif /* __MTK_CMDQ_H__ */ 134