1 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 and
5  * only version 2 as published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  */
12 
13 #ifndef __DPU_CORE_IRQ_H__
14 #define __DPU_CORE_IRQ_H__
15 
16 #include "dpu_kms.h"
17 #include "dpu_hw_interrupts.h"
18 
19 /**
20  * dpu_core_irq_preinstall - perform pre-installation of core IRQ handler
21  * @dpu_kms:		DPU handle
22  * @return:		none
23  */
24 void dpu_core_irq_preinstall(struct dpu_kms *dpu_kms);
25 
26 /**
27  * dpu_core_irq_postinstall - perform post-installation of core IRQ handler
28  * @dpu_kms:		DPU handle
29  * @return:		0 if success; error code otherwise
30  */
31 int dpu_core_irq_postinstall(struct dpu_kms *dpu_kms);
32 
33 /**
34  * dpu_core_irq_uninstall - uninstall core IRQ handler
35  * @dpu_kms:		DPU handle
36  * @return:		none
37  */
38 void dpu_core_irq_uninstall(struct dpu_kms *dpu_kms);
39 
40 /**
41  * dpu_core_irq - core IRQ handler
42  * @dpu_kms:		DPU handle
43  * @return:		interrupt handling status
44  */
45 irqreturn_t dpu_core_irq(struct dpu_kms *dpu_kms);
46 
47 /**
48  * dpu_core_irq_idx_lookup - IRQ helper function for lookup irq_idx from HW
49  *                      interrupt mapping table.
50  * @dpu_kms:		DPU handle
51  * @intr_type:		DPU HW interrupt type for lookup
52  * @instance_idx:	DPU HW block instance defined in dpu_hw_mdss.h
53  * @return:		irq_idx or -EINVAL when fail to lookup
54  */
55 int dpu_core_irq_idx_lookup(
56 		struct dpu_kms *dpu_kms,
57 		enum dpu_intr_type intr_type,
58 		uint32_t instance_idx);
59 
60 /**
61  * dpu_core_irq_enable - IRQ helper function for enabling one or more IRQs
62  * @dpu_kms:		DPU handle
63  * @irq_idxs:		Array of irq index
64  * @irq_count:		Number of irq_idx provided in the array
65  * @return:		0 for success enabling IRQ, otherwise failure
66  *
67  * This function increments count on each enable and decrements on each
68  * disable.  Interrupts is enabled if count is 0 before increment.
69  */
70 int dpu_core_irq_enable(
71 		struct dpu_kms *dpu_kms,
72 		int *irq_idxs,
73 		uint32_t irq_count);
74 
75 /**
76  * dpu_core_irq_disable - IRQ helper function for disabling one of more IRQs
77  * @dpu_kms:		DPU handle
78  * @irq_idxs:		Array of irq index
79  * @irq_count:		Number of irq_idx provided in the array
80  * @return:		0 for success disabling IRQ, otherwise failure
81  *
82  * This function increments count on each enable and decrements on each
83  * disable.  Interrupts is disabled if count is 0 after decrement.
84  */
85 int dpu_core_irq_disable(
86 		struct dpu_kms *dpu_kms,
87 		int *irq_idxs,
88 		uint32_t irq_count);
89 
90 /**
91  * dpu_core_irq_read - IRQ helper function for reading IRQ status
92  * @dpu_kms:		DPU handle
93  * @irq_idx:		irq index
94  * @clear:		True to clear the irq after read
95  * @return:		non-zero if irq detected; otherwise no irq detected
96  */
97 u32 dpu_core_irq_read(
98 		struct dpu_kms *dpu_kms,
99 		int irq_idx,
100 		bool clear);
101 
102 /**
103  * dpu_core_irq_register_callback - For registering callback function on IRQ
104  *                             interrupt
105  * @dpu_kms:		DPU handle
106  * @irq_idx:		irq index
107  * @irq_cb:		IRQ callback structure, containing callback function
108  *			and argument. Passing NULL for irq_cb will unregister
109  *			the callback for the given irq_idx
110  *			This must exist until un-registration.
111  * @return:		0 for success registering callback, otherwise failure
112  *
113  * This function supports registration of multiple callbacks for each interrupt.
114  */
115 int dpu_core_irq_register_callback(
116 		struct dpu_kms *dpu_kms,
117 		int irq_idx,
118 		struct dpu_irq_callback *irq_cb);
119 
120 /**
121  * dpu_core_irq_unregister_callback - For unregistering callback function on IRQ
122  *                             interrupt
123  * @dpu_kms:		DPU handle
124  * @irq_idx:		irq index
125  * @irq_cb:		IRQ callback structure, containing callback function
126  *			and argument. Passing NULL for irq_cb will unregister
127  *			the callback for the given irq_idx
128  *			This must match with registration.
129  * @return:		0 for success registering callback, otherwise failure
130  *
131  * This function supports registration of multiple callbacks for each interrupt.
132  */
133 int dpu_core_irq_unregister_callback(
134 		struct dpu_kms *dpu_kms,
135 		int irq_idx,
136 		struct dpu_irq_callback *irq_cb);
137 
138 /**
139  * dpu_debugfs_core_irq_init - register core irq debugfs
140  * @dpu_kms: pointer to kms
141  * @parent: debugfs directory root
142  * @Return: 0 on success
143  */
144 int dpu_debugfs_core_irq_init(struct dpu_kms *dpu_kms,
145 		struct dentry *parent);
146 
147 /**
148  * dpu_debugfs_core_irq_destroy - deregister core irq debugfs
149  * @dpu_kms: pointer to kms
150  */
151 void dpu_debugfs_core_irq_destroy(struct dpu_kms *dpu_kms);
152 
153 #endif /* __DPU_CORE_IRQ_H__ */
154