root/include/linux/soc/mediatek/mtk-cmdq.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   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 struct cmdq_pkt;
  17 
  18 struct cmdq_client {
  19         spinlock_t lock;
  20         u32 pkt_cnt;
  21         struct mbox_client client;
  22         struct mbox_chan *chan;
  23         struct timer_list timer;
  24         u32 timeout_ms; /* in unit of microsecond */
  25 };
  26 
  27 /**
  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.
  33  *
  34  * Return: CMDQ mailbox client pointer
  35  */
  36 struct cmdq_client *cmdq_mbox_create(struct device *dev, int index,
  37                                      u32 timeout);
  38 
  39 /**
  40  * cmdq_mbox_destroy() - destroy CMDQ mailbox client and channel
  41  * @client:     the CMDQ mailbox client
  42  */
  43 void cmdq_mbox_destroy(struct cmdq_client *client);
  44 
  45 /**
  46  * cmdq_pkt_create() - create a CMDQ packet
  47  * @client:     the CMDQ mailbox client
  48  * @size:       required CMDQ buffer size
  49  *
  50  * Return: CMDQ packet pointer
  51  */
  52 struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size);
  53 
  54 /**
  55  * cmdq_pkt_destroy() - destroy the CMDQ packet
  56  * @pkt:        the CMDQ packet
  57  */
  58 void cmdq_pkt_destroy(struct cmdq_pkt *pkt);
  59 
  60 /**
  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
  66  *
  67  * Return: 0 for success; else the error code is returned
  68  */
  69 int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value);
  70 
  71 /**
  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
  78  *
  79  * Return: 0 for success; else the error code is returned
  80  */
  81 int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys,
  82                         u16 offset, u32 value, u32 mask);
  83 
  84 /**
  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"
  88  *
  89  * Return: 0 for success; else the error code is returned
  90  */
  91 int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event);
  92 
  93 /**
  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
  97  *
  98  * Return: 0 for success; else the error code is returned
  99  */
 100 int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event);
 101 
 102 /**
 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
 108  *
 109  * Return: 0 for success; else the error code is returned
 110  *
 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.
 114  */
 115 int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb,
 116                          void *data);
 117 
 118 /**
 119  * cmdq_pkt_flush() - trigger CMDQ to execute the CMDQ packet
 120  * @pkt:        the CMDQ packet
 121  *
 122  * Return: 0 for success; else the error code is returned
 123  *
 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.
 127  */
 128 int cmdq_pkt_flush(struct cmdq_pkt *pkt);
 129 
 130 #endif  /* __MTK_CMDQ_H__ */

/* [<][>][^][v][top][bottom][index][help] */